+
    O(iI                     ~  a  R t;0 t R t^ RIt^ RIt^ RIt^ RIt^ RIt^ RIH	t	 ^ RI
HtHt ^ RIHt ^ RIHtHt ^RIHtHtHtHt ^RIHtHtHtHt ^RIHtHtHtHt ^R	I H!t!H"t" ^R
I#H$t$H%t% ^RI&H't'H(t(H)t)H*t*H+t+ ^RI,H-t-H.t. ]P^                  ! R]P`                  ! ]Pb                  4      R R2]Pd                  4      t3] ^ k ]P^                  ! R]P`                  ! ]Ph                  4      R R2]Pd                  4      t5] ^k  ! R R]4      t6 ! R R]4      t7R]RRRR3R R llt8R]RRRR3R R llt9RR R llt:R# )zA
.. codeauthor:: Tsuyoshi Hombashi <tsuyoshi.hombashi@gmail.com>
N)Sequence)PathPurePath)Pattern)FinalOptional)AbstractSanitizerAbstractValidatorBaseFileBaseValidator)findall_to_stris_nt_abspathto_strvalidate_pathtype)_NTFS_RESERVED_FILE_NAMESDEFAULT_MIN_LENINVALID_CHAR_ERR_MSG_TMPLPlatform)FileNameSanitizerFileNameValidator)PathTypePlatformType)ErrorAttrKeyErrorReasonInvalidCharErrorReservedNameErrorValidationError)ReservedNameHandlerValidationErrorHandler[s]c                   |   a a ] tR t^t oR
V3R lV 3R llltRV3R lR lltV3R lR ltV3R lR ltR	tVt	V ;t
# )FilePathSanitizerc                   < V ^8  d   QhRS[ RS[S[,          RS[S[,          RS[S[,          RS[S[,          RS[S[S[,          ,          RS[RS[R	S[S[,          R
R/
# )   max_lenfs_encodingplatformnull_value_handlerreserved_name_handleradditional_reserved_names	normalizevalidate_after_sanitize	validatorreturnN)intr   strr   r   r   boolr	   )format__classdict__s   "\/Users/agent/.openclaw/workspace/venv/lib/python3.14/site-packages/pathvalidate/_filepath.py__annotate__FilePathSanitizer.__annotate__   s     16 1616 c]16 <(	16
 %%;<16  ((>?16 $,HSM#:16 16 "&16 -.16 
16    c
                  < V	'       d   T	p
M\        \        VVR VVR7      p
\        SV `  VVV
VVVVVR7       V P	                  4       V n        \        V P                  VVVVV P                  VR7      V n	        Wpn
        V P                  R R7      '       d   \        P                  V n        R# \        P                  V n        R# )Tmin_lenr&   r'   check_reservedr+   r(   )r&   r'   r.   r)   r*   r+   r(   r-   )r&   r'   r)   r*   r+   r(   r-   include_universalN)FilePathValidatorr   super__init___get_sanitize_regexp_sanitize_regexpr   r&   r(   #_FilePathSanitizer__fname_sanitizer_FilePathSanitizer__normalize_is_windowsntpath
splitdrive_FilePathSanitizer__split_drive	posixpath)selfr&   r'   r(   r)   r*   r+   r,   r-   r.   fpath_validator	__class__s   &&&&&&&&&& r5   rA   FilePathSanitizer.__init__   s     'O/''#*C!O 	#%1"7&?$; 	 		
 !% 9 9 ;!2LL#1"7&?]]$;"
 %d33!'!2!2D!*!5!5Dr8   c                ,   < V ^8  d   QhRS[ RS[RS[ /# )r%   valuereplacement_textr/   )r   r1   )r3   r4   s   "r5   r6   r7   R   s"     1 1h 1# 1x 1r8   c                    \        WP                  R R7      '       * R7       \        T4      pT P                  T4      w  rTT P                  P                  Y$4      pT P                  '       d(   T'       d    \        P                  P!                  T4      pTp. pT'       d   TP#                  T4       TP%                  RR4      P'                  R4       F}  pT\(        9   d   TP#                  T R24       K$  \+        T P,                  P/                  YR7      4      p	T	'       g   T'       g   TP#                  R4       Kl  TP#                  T	4       K  	  T P1                  4       P3                  T4      p T P4                  P7                  T4       T P8                  '       d   T P4                  P7                  T4       \        T\        4      '       d   \;        T4      # T#   \         dS   pTP                  \        P
                  8X  d.   \        T\        4      '       d   h T P                  T4      u Rp?# h Rp?ii ; i  \         d;   pTP                  \        P
                  8X  d   T P                  T4      p Rp?LRp?ii ; i)	Tr=   allow_whitespacesN\/_)rQ    )r   rF   r   reasonr   	NULL_NAME
isinstancer   _null_value_handlerr   rI   rC   subrE   ospathnormpathappendreplacesplitr   r1   rD   sanitize&_FilePathSanitizer__get_path_separatorjoin
_validatorvalidate_validate_after_sanitizer   )
rK   rP   rQ   eunicode_filepathdrivesanitized_pathsanitized_entriesentrysanitized_entrys
   &&&       r5   rd   FilePathSanitizer.sanitizeR   s   	e;K;K^b;K;c7cd "%="&"4"45E"F00445EX 0!ww//0@A)')$$U+#++D#6<<SAE11!((E7!5!&&///YO #(%,,R0$$_5 B 22499:KL	=OO$$^4
 (((OO$$^4eX&&'']  	xx;000eX..//22	H  	=xx;000!%!9!9!!<	=s<   !G 4H? H<*AH70H<6H77H<?J
0I??Jc                0   < V ^8  d   QhRS[ S[,          /# r%   r/   )r   r1   )r3   r4   s   "r5   r6   r7      s        gcl  r8   c                J    V P                  R R7      '       d   \        # \        # )Tr=   )rF   _RE_INVALID_WIN_PATH_RE_INVALID_PATHrK   s   &r5   rB   &FilePathSanitizer._get_sanitize_regexp   s"    d33''r8   c                    < V ^8  d   QhRS[ /# rs   r1   )r3   r4   s   "r5   r6   r7      s      c r8   c                6    V P                  4       '       d   R # R# )rU   rV   )rF   rw   s   &r5   __get_path_separator&FilePathSanitizer.__get_path_separator   s    r8   )__fname_sanitizer__normalize__split_driverC   )	NNNNNTFN)rX   )__name__
__module____qualname____firstlineno__rA   rd   rB   re   __static_attributes____classdictcell____classcell__rM   r4   s   @@r5   r#   r#      s4     16 16f1 1f     r8   r#   c                   .  a a ] tR t^t o]P
                  ! RP                  R ] 4       4      ]P                  4      t	Rt
]V3R lV 3R ll4       t]RRRRR3V3R lV 3R llltV3R	 lR
 ltV3R lR ltV3R lR ltV3R lR ltV3R ltRtVtV ;t# )r?   |c              #  V   "   T F  pR \         P                  ! V4       R2x  K!  	  R# 5i)z^/$N)reescape).0patterns   & r5   	<genexpr>FilePathValidator.<genexpr>   s%     U;T2bii()+;Ts   ')c                4   < V ^8  d   QhRS[ S[R3,          /# )r%   r/   .)tupler1   )r3   r4   s   "r5   r6   FilePathValidator.__annotate__   s     	 	5c? 	r8   c                   < \         SV `  p\        V P                  4       V P	                  4       V P                  4       .4      '       d   WP                  ,           # V P                  4       '       d
   VR,           # V# )rV   )rV   )r@   reserved_keywordsany_is_universal	_is_posix	_is_macos_MACOS_RESERVED_FILE_PATHS	_is_linux)rK   common_keywordsrM   s   & r5   r   #FilePathValidator.reserved_keywords   sc    '3""$dnn&68HIJJ"%D%DDD>>"V++r8   NTc                   < V ^8  d   QhRS[ RS[ RS[S[,          RS[S[,          RS[RS[S[S[,          ,          RR/# )	r%   r;   r&   r'   r(   r<   r+   r/   N)r0   r   r1   r   r2   r   )r3   r4   s   "r5   r6   r      sc     6 66 6 c]	6
 <(6 6 $,HSM#:6 
6r8   c           	        < \         SV `  VVVVVVR 7       \        VV P                  VVVVR 7      V n        V P                  RR7      '       d   \        P                  V n        R# \        P                  V n        R# )r:   Tr=   N)
r@   rA   r   r&   #_FilePathValidator__fname_validatorrF   rG   rH   _FilePathValidator__split_driverJ   )rK   r;   r&   r'   r(   r<   r+   rM   s   &&&&&&&r5   rA   FilePathValidator.__init__   s     	#)&? 	 	
 "3LL#)&?"
 d33!'!2!2D!*!5!5Dr8   c                $   < V ^8  d   QhRS[ RR/# r%   rP   r/   Nr   )r3   r4   s   "r5   r6   r      s     .< .<h .<4 .<r8   c           
        \        WP                  R R7      '       * R7       V P                  V4       V P                  V4      w  r#V'       g   R# \	        V4      p\        VP                  V P                  4      4      p\        P                  \        P                  \        P                  V P                  \        P                  V P                  \        P                  V\        P                   V/pWPP"                  8  d!   \%        RV P"                  R RVR R2.3/ VB hWPP&                  8  d(   \%        RP)                  V P&                  V4      .3/ VB hV P+                  V4       VP-                  R	R
4      pVP/                  R
4       F/  pV'       d   VR9   d   K  V P0                  P3                  V4       K1  	  V P                  R R7      '       d   V P5                  V4       R# V P7                  V4       R# )Tr=   rS   Nz!file path is too long: expected<=dz bytes, actual=z bytesz?file path is too short: expected>={:d} bytes, actual={:d} bytesrU   rV   ).z..)r   rF   validate_abspathr   r   lenencode_fs_encodingr   REASONr   INVALID_LENGTHPLATFORMr(   FS_ENCODING
BYTE_COUNTVALUEr&   r   r;   r3   _validate_reserved_keywordsrb   rc   r   rh   )_FilePathValidator__validate_win_filepath*_FilePathValidator__validate_unix_filepath)rK   rP   _drivetailrk   byte_ct
err_kwargsro   s   &&      r5   rh   FilePathValidator.validate   s   %7G7GZ^7G7_3_`e$))%0!$<&--d.?.?@A!;!;!!4==$$d&7&7##W 0

 \\!!7Q7GW^_`Vaagh 	  \\!!U\\g   	(()9:+33D#>%++C0EE[0""++E2	 1 d33(()9:))*:;r8   c                $   < V ^8  d   QhRS[ RR/# r   r   )r3   r4   s   "r5   r6   r      s     ! !h !4 !r8   c                   \         P                  ! V4      p\        \        V4      4      p\	        V P                  4       ;'       d    TV P                  4       ;'       d    T.4      '       d   R # V P                  4       '       d9   \	        W2.4      '       d'   \        RV P                  \        P                  R7       \        RV: RV P                  P                   R2R,           R,           V P                  \        P                  R7      pV P                  R	R
7      '       d   V'       d   VhV P                  4       '       g/   \        P                  ! V4      w  rVV'       d   V'       d   VhR # R # R # )Nz8platform-independent absolute file path is not supported)r(   rY   zan invalid absolute file path (z) for the platform (z).zE to avoid the error, specify an appropriate platform corresponding toz the path format or 'auto'.)descriptionr(   rY   Tr=   )rJ   isabsr   r   r   rF   r   r   r   r(   r   MALFORMED_ABS_PATHrP   rG   rH   )rK   rP   is_posix_abs	is_nt_abs
err_objectrl   _tails   &&     r5   r   "FilePathValidator.validate_abspath   s,    u-!&-0	  "00y$..2B2S2S|TUUC(A$B$BJ"55 %1%:Nt}}ObObNccefYZ/0 ]]11

 d33!!!,,U3LE   #u "r8   c                $   < V ^8  d   QhRS[ RR/# r%   rk   r/   Nrz   )r3   r4   s   "r5   r6   r     s        r8   c                    \         P                  V4      pV'       d,   \        \        P                  ! \        V4      R 7      VR7      hR# )invalid)rP   N)rv   findallr   r   r3   r   )rK   rk   matchs   && r5   __validate_unix_filepath*FilePathValidator.__validate_unix_filepath  s>     (()9:")009NO&  r8   c                $   < V ^8  d   QhRS[ RR/# r   rz   )r3   r4   s   "r5   r6   r     s        r8   c                   \         P                  V4      pV'       d;   \        \        P                  ! \        V4      R 7      \        P                  VR7      hV P                  V4      w  r4V'       dS   V P                  P                  V4      pV'       d.   VP                  4       p\        RV R2RVV P                  R7      hR# R# )r   )r(   rP   'z' is a reserved nameF)reusable_namereserved_namer(   N)ru   r   r   r   r3   r   r   WINDOWSr   _RE_NTFS_RESERVEDsearchgroupr   r(   )rK   rk   r   r   rP   match_reservedr   s   &&     r5   __validate_win_filepath)FilePathValidator.__validate_win_filepath  s    $,,-=>")009NO!))&  **+;<!33::5AN . 4 4 6'&:;"'"/!]]	   r8   c                2   < V ^8  d   Qh/ S[ ;R&   S[ ;R&   # )r%   r   r   )r   )r3   r4   s   "r5   r6   r      s       
 !&2 r8   )__fname_validatorr   )rV   :r   )r   r   r   r   r   compilerf   r   
IGNORECASEr   r   propertyr   r   rA   rh   r   r   r   __annotate_func__r   r   r   r   s   @@r5   r?   r?      s     !zzU;TUU
  )3	 	 	 '%)+/#=A6 6@.< .<`! !@  W  r8   r?   Tc                    V ^8  d   QhR\         R\        \        ,          R\        R\        \        ,          R\        \        ,          R\
        R\        \        \        ,          ,          RR	/# )
r%   	file_pathr(   r;   r&   r'   r<   r+   r/   Nr   r   r   r0   r1   r2   r   )r3   s   "r5   r6   r6   3  sx     @ @@|$@ @ c]	@
 #@ @  (6@ 
@r8   c           	     R    \        TTVf   RMTVVVR7      P                  V 4       R# )a  Verifying whether the ``file_path`` is a valid file path or not.

Args:
    file_path (PathType):
        File path to be validated.
    platform (Optional[PlatformType], optional):
        Target platform name of the file path.

        .. include:: platform.txt
    min_len (int, optional):
        Minimum byte length of the ``file_path``. The value must be greater or equal to one.
        Defaults to ``1``.
    max_len (Optional[int], optional):
        Maximum byte length of the ``file_path``. If the value is |None| or minus,
        automatically determined by the ``platform``:

            - ``Linux``: 4096
            - ``macOS``: 1024
            - ``Windows``: 260
            - ``universal``: 260
    fs_encoding (Optional[str], optional):
        Filesystem encoding that is used to calculate the byte length of the file path.
        If |None|, get the encoding from the execution environment.
    check_reserved (bool, optional):
        If |True|, check the reserved names of the ``platform``.
        Defaults to |True|.
    additional_reserved_names (Optional[Sequence[str]], optional):
        Additional reserved names to check.

Raises:
    ValidationError (ErrorReason.INVALID_CHARACTER):
        If the ``file_path`` includes invalid char(s):
        |invalid_file_path_chars|.
        The following characters are also invalid for Windows platforms:
        |invalid_win_file_path_chars|
    ValidationError (ErrorReason.INVALID_LENGTH):
        If the ``file_path`` is longer than ``max_len`` characters.
    ValidationError:
        If ``file_path`` includes invalid values.

Example:
    :ref:`example-validate-file-path`

See Also:
    `Naming Files, Paths, and Namespaces - Win32 apps | Microsoft Docs
    <https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file>`__
Nr(   r;   r&   r'   r<   r+   r   )r?   rh   r   r(   r;   r&   r'   r<   r+   s   &&&&&&&r5   validate_filepathr   3  s1    r o7%"; hyr8   c                    V ^8  d   QhR\         R\        \        ,          R\        R\        \        ,          R\        \        ,          R\
        R\        \        \        ,          ,          R\
        /# )	r%   r   r(   r;   r&   r'   r<   r+   r/   r   )r3   s   "r5   r6   r6   v  sn      |$  c]	
 #   (6 
r8   c           	     N    \        TTVf   RMTVVVR7      P                  V 4      # )a  Check whether the ``file_path`` is a valid name or not.

Args:
    file_path:
        A filepath to be checked.
    platform:
        Target platform name of the file path.

Example:
    :ref:`example-is-valid-filepath`

See Also:
    :py:func:`.validate_filepath()`
r   r   )r?   is_validr   s   &&&&&&&r5   is_valid_filepathr   v  s5    0 o7%"; hyr8   c                X   V ^8  d   QhR\         R\        R\        \        ,          R\        \        ,          R\        \        ,          R\        \
        ,          R\        \        ,          R\        \        ,          R	\        \        \        ,          ,          R
\
        R\
        R\         /# )r%   r   rQ   r(   r&   r'   r<   r)   r*   r+   r,   r-   r/   )r   r1   r   r   r0   r2   r   r   )r3   s   "r5   r6   r6     s     l, l,l,l, |$l, c]	l,
 #l, TNl, !!78l, $$:;l,  (6l, l, "l, l,r8   c                    Ve2   \         P                  ! R\        4       VRJ d   \        P                  p\        TVf   RMTVV	VVVV
R7      P                  W4      # )a
  Make a valid file path from a string.

To make a valid file path, the function does the following:

    - Replace invalid characters for a file path within the ``file_path``
      with the ``replacement_text``. Invalid characters are as follows:

        - unprintable characters
        - |invalid_file_path_chars|
        - for Windows (or universal) only: |invalid_win_file_path_chars|

    - Replace a value if a sanitized value is a reserved name by operating systems
      with a specified handler by ``reserved_name_handler``.

Args:
    file_path:
        File path to sanitize.
    replacement_text:
        Replacement text for invalid characters.
        Defaults to ``""``.
    platform:
        Target platform name of the file path.

        .. include:: platform.txt
    max_len:
        Maximum byte length of the file path.
        Truncate the path if the value length exceeds the `max_len`.
        If the value is |None| or minus, ``max_len`` will automatically determined by the ``platform``:

            - ``Linux``: 4096
            - ``macOS``: 1024
            - ``Windows``: 260
            - ``universal``: 260
    fs_encoding:
        Filesystem encoding that is used to calculate the byte length of the file path.
        If |None|, get the encoding from the execution environment.
    check_reserved:
        [Deprecated] Use 'reserved_name_handler' instead.
    null_value_handler:
        Function called when a value after sanitization is an empty string.
        You can specify predefined handlers:

            - :py:func:`.handler.NullValueHandler.return_null_string`
            - :py:func:`.handler.NullValueHandler.return_timestamp`
            - :py:func:`.handler.raise_error`

        Defaults to :py:func:`.handler.NullValueHandler.return_null_string` that just return ``""``.
    reserved_name_handler:
        Function called when a value after sanitization is one of the reserved names.
        You can specify predefined handlers:

            - :py:meth:`~.handler.ReservedNameHandler.add_leading_underscore`
            - :py:meth:`~.handler.ReservedNameHandler.add_trailing_underscore`
            - :py:meth:`~.handler.ReservedNameHandler.as_is`
            - :py:func:`~.handler.raise_error`

        Defaults to :py:func:`.handler.add_trailing_underscore`.
    additional_reserved_names:
        Additional reserved names to sanitize.
        Case insensitive.
    normalize:
        If |True|, normalize the the file path.
    validate_after_sanitize:
        Execute validation after sanitization to the file path.

Returns:
    Same type as the argument (str or PathLike object):
        Sanitized filepath.

Raises:
    ValueError:
        If the ``file_path`` is an invalid file path.

Example:
    :ref:`example-sanitize-file-path`
zD'check_reserved' is deprecated. Use 'reserved_name_handler' instead.F)r(   r&   r'   r,   r)   r*   r+   r-   r   )warningswarnDeprecationWarningr   as_isr#   rd   )r   rQ   r(   r&   r'   r<   r)   r*   r+   r,   r-   s   &&&&&&&&&&&r5   sanitize_filepathr     sj    t !R	

 U"$7$=$=!o7-3"; 7	 hy+	,r8   c                h    V ^8  d   Qh/ ^ \         9   d
   \        ;R&   ^\         9   d
   \        ;R&   # )r%   rv   ru   )__conditional_annotations__r   )r3   s   "r5   r6   r6      s5      . c b% b/0 e 1r8   )
rX   NNNNNNNTF)<r   __doc__rG   os.pathr^   rJ   r   r   collections.abcr   pathlibr   r   r   typingr   r   _baser   r	   r
   r   _commonr   r   r   r   _constr   r   r   r   	_filenamer   r   _typesr   r   errorr   r   r   r   r   handlerr   r   r   r   _INVALID_PATH_CHARSUNICODErv   _INVALID_WIN_PATH_CHARSru   r#   r?   r   r   r   r6   )r   s   @r5   <module>r     s      	  $ "  " P P M M c c ; * b b @ **q83O3O)PQR(SST%UWYWaWab  b jj		(223A6a8"**  
q) qh^ ^F (,"!!%9=@J (,"!!%9=Dl, l,r8   