o
    oĎi                     @   s   d dl Z d dlmZ d dlmZ d dlmZmZ ddlm	Z	m
Z
 ddlmZ ddlmZ G d	d
 d
eZee
 ee deee jf dee
ef fddZdS )    N)ABC)Path)AnyUnion   )InvalidPrefixError	CloudPath)AnyPathTypeError)path_from_fileurlc                   @   s|   e Zd ZdZdeeef fddZede	fddZ
ededeeef fd	d
Zedd Zedeeef fddZdS )AnyPatha  Polymorphic virtual superclass for CloudPath and pathlib.Path. Constructing an instance will
    automatically dispatch to CloudPath or Path based on the input. It also supports both
    isinstance and issubclass checks.

    This class also integrates with Pydantic. When used as a type declaration for a Pydantic
    BaseModel, the Pydantic validation process will appropriately run inputs through this class'
    constructor and dispatch to CloudPath or Path.
    returnc                 O   s   zt |i |W S  tym } zYz>t|d trA|d  drAt|d fi |}|dd  D ]}|| }q1|W W  Y d }~S t|i |W W  Y d }~S  tyh } zt	dt
| dt
| d }~ww d }~ww )Nr   zfile:r   z@Invalid input for both CloudPath and Path. CloudPath exception: z Path exception: )r   r   
isinstancestrlower
startswithr
   r   	TypeErrorr	   repr)clsargskwargscloudpath_exceptionpathpartpath_exception r   P/home/jeff/fluffinator/venv/lib/python3.10/site-packages/cloudpathlib/anypath.py__new__   s,    
zAnyPath.__new___source_typec                 C   s6   zddl m} || j| W S  ty   Y dS w )VPydantic special method. See
        https://docs.pydantic.dev/2.0/usage/types/custom/r   )core_schemaN)pydantic_corer    no_info_after_validator_functionvalidate
any_schemaImportError)r   r   _handlerr   r   r   r   __get_pydantic_core_schema__)   s   z$AnyPath.__get_pydantic_core_schema__vc              
   C   s0   z|  | |W S  ty } zt|d}~ww )r   N)r   r	   
ValueError)r   r'   er   r   r   r"   7   s   zAnyPath.validatec                 c   s    | j V  dS )zgPydantic special method. See
        https://pydantic-docs.helpmanual.io/usage/types/#custom-data-typesN)	_validate)r   r   r   r   __get_validators__B   s   zAnyPath.__get_validators__c                 C   s   |  | |S )zlUsed as a Pydantic validator. See
        https://pydantic-docs.helpmanual.io/usage/types/#custom-data-types)r   )r   valuer   r   r   r*   H   s   zAnyPath._validateN)__name__
__module____qualname____doc__r   r   r   r   classmethodr   r&   r   r"   r+   r*   r   r   r   r   r      s    	

r   sr   c                 C   s   t | ttfr	| S t| S )zqConvenience method to convert a str or os.PathLike to the
    proper Path or CloudPath object using AnyPath.
    )r   r   r   r   )r2   r   r   r   
to_anypathT   s   r3   )osabcr   pathlibr   typingr   r   	cloudpathr   r   
exceptionsr	   	url_utilsr
   r   registerr   PathLiker3   r   r   r   r   <module>   s    
E
(