
    #HJjG                       d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl	Z	ddl
ZddlmZmZmZmZmZmZmZmZ ddlmZ ddlmZ ddlmZ ddlmZm Z  erddl!m"Z" ddl#m$Z$ ddl%m&Z&m'Z'm(Z(  ejR                  e*      Z+ ejX                  d	
      Z-ddZ.ddZ/e/Z0e1Z2e	 	 	 	 	 	 	 	 	 	 d 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d!d       Z1e	 d"ddddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d#d       Z1e	 	 	 	 	 	 	 	 	 	 d 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d$d       Z1dddddddejf                  ddf
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d$dZ1d%dZ4	 	 	 	 d&	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d'dZ5d(dZ6	 	 	 d)	 	 	 	 	 	 	 	 	 	 	 d*dZ7 G d d      Z8d+dZ9	  ejt                  e1        ejv                  e/       y# e<$ r e+j{                  d       Y yw xY w),z6Implements the majority of smart_open's top-level API.    )annotationsN)IOTYPE_CHECKINGAnyBinaryIOLiteralTextIOcastoverload)doctools	transport)Callable)Self)CompressionKwargsTransportParamsUriF)do_setlocalec                    t         j                  dk(  r	d| vrd| z   } t        j                  j	                  |       j
                  S )z0Returns the scheme of the URL only, as a string.ntz://zfile://)osnameurllibparseurlsplitscheme)uri_as_strings    c/Users/ahmed/devFolder/claude-voice/.venv/lib/python3.12/site-packages/smart_open/smart_open_lib.py_sniff_schemer   ,   s;     
ww$55!M1<<  /666    c                    t        |       }t        j                  |      }|j                  |       }t	        j
                  dt        |j                                     } |di |S )zParse the given URI from a string.

    Args:
        uri_as_string: The URI to parse.

    Returns:
        The parsed URI as a ``collections.namedtuple``.

    smart_open/doctools.py magic goes here
    r    )r   r   get_transport	parse_uricollections
namedtuplesortedkeys)r   r   	submoduleas_dictr   s        r   r#   r#   8   sY     =)F''/I!!-0G 
 
 w||~(>
?C>>r   .c                     y Nr!   urimode	bufferingencodingerrorsnewlineclosefdopenercompressioncompression_kwargstransport_paramss              r   openr8   W   s     r   )r0   r1   r2   r3   r4   r5   r6   r7   c                    y r+   r!   r,   s              r   r8   r8   g   s     r   c                     y r+   r!   r,   s              r   r8   r8   x   s     r   rTc           
        t         j                  dt                      t        |t              sd}t        |      |t        j                         vrd| }t        |      |
i }
t        | ||||||      }||S |d|v r|j                  dd      }t        | t        j                        rt	        |       } |}|xs t        }	 t        |      }t#        | ||
      }t%        |d	d      }t        |t              r|nt        | t              r| nd}t        j&                  |||||	
      }d|vs|t)        |||||      }n|}||k7  rCdg}|D ];  }t+        j,                  t.              5  t1        ||t%        ||             ddd       = t3        dt5        j6                  ||            S # t        $ r}t        |j                   d         |d}~ww xY w# 1 sw Y   xY w)a	  Open the URI object, returning a file-like object.

    The URI is usually a string in a variety of formats.
    For a full list of examples, see the :func:`parse_uri` function.

    The URI may also be one of:

    - an instance of the pathlib.Path class
    - a stream (anything that implements io.IOBase-like functionality)

    Args:
        uri: The object to open.
        mode: Mimicks built-in open parameter of the same name.
        buffering: Mimicks built-in open parameter of the same name.
        encoding: Mimicks built-in open parameter of the same name.
        errors: Mimicks built-in open parameter of the same name.
        newline: Mimicks built-in open parameter of the same name.
        closefd: Mimicks built-in open parameter of the same name.  Ignored.
        opener: Mimicks built-in open parameter of the same name.  Ignored.
        compression: Explicitly specify the compression/decompression behavior.
            See ``smart_open.compression.get_supported_compression_types``.
        compression_kwargs: Keyword arguments forwarded to the registered
            compressor callback. Examples of each library's max-compression
            option: ``{'compresslevel': 9}`` for .gz/.bz2, ``{'preset': 9}`` for
            .xz, ``{'level': 22}`` for .zst, ``{'compression_level': 12}`` for
            .lz4. Ignored when compression is 'disable' or the URI's extension
            doesn't match a registered compressor.
        transport_params: Additional parameters for the transport layer (see
            notes below).

    Returns:
        A file-like object.

    Raises:
        TypeError: If ``mode`` is not a string or if the URI type is not
            recognized.
        ValueError: If ``compression`` is not a supported value.
        NotImplementedError: If ``mode`` cannot be parsed into a valid binary
            mode.

    Note:
        smart_open has several implementations for its transport layer
        (e.g. S3, HTTP). Each transport layer has a different set of keyword
        arguments for overriding default behavior. If you specify a keyword
        argument that is *not* supported by the transport layer being used,
        smart_open will ignore that argument and log a warning message.

    smart_open/doctools.py magic goes here

    See Also:
        - `Standard library reference <https://docs.python.org/3.14/library/functions.html#open>`__
        - `smart_open README.md
          <https://github.com/piskvorky/smart_open/blob/master/README.md>`__
    z%rzmode should be a stringzinvalid compression type: N)r5   r/   r0   r1   r2   b r   r   )filenamer6   )r0   r1   r2   to_boto3IO[Any])loggerdebuglocals
isinstancestr	TypeErrorso_compressionget_supported_compression_types
ValueError_shortcut_openreplacepathlibPathDEFAULT_ENCODING_get_binary_modeNotImplementedErrorargs_open_binary_streamgetattrcompression_wrapper_encoding_wrapper
contextlibsuppressAttributeErrorsetattrr
   so_utilsFileLikeProxy)r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   msgfobjexplicit_encodingbinary_modevebinaryr   r@   decompresseddecodedpromoted_attrsattrs                          r   r8   r8      s   F LLvx dC 'n.HHJJ*;-8oD  t||C$#w||$#h  4$4H6&t, !k3CDF664(D!$,tC9M#SWH!55-L $+7#
  &$"D$$^4wvt'<= 54 # 	811'6BCCK  6!"''!*-256D 54s$   F, *G,	G5GGG	c                B   t        |       g dv rdv rd}t        |      dD cg c]  }j                  |       }}t        |      dkD  rd}t        |      dfd}dv r	 |d       n'd	v r	 |d	       nd
v r	 |d
       nd}t        |      dv r	 |d       nGdv r2j	                  j                  d             j                  d       nj                  d       dv r |d       rd| }t        |      dj                        S c c}w )Ntr>   z'can't have text and binary mode at oncerwa   z6must have exactly one of create/read/write/append modec                d    j                  j                  j                  |                    y r+   )appendpopindex)charbinmoder.   s    r   transferz"_get_binary_mode.<locals>.transfer?  s!    txx

4 012r   awr;   zKMust have exactly one of create/read/write/append mode and at most one plus+zinvalid mode: r?   )rp   rG   returnNone)listrK   countsumrn   ro   rm   join)mode_strr^   xcountsrr   rq   r.   s        @@r   rQ   rQ   ,  s$    >DG
d{sd{7o%*+UdjjmUF+
6{QFo3 d{		[o
d{	C!ss
d{ xl+o777M ,s   Dc                   t        | t              syt        |       }|t        j                  t
        j                  fvryt        j                  |       }|t        j                  k(  r6t        j                  |      j                  }	|	t        j                         v ry|t        j                  k7  ryi }
|||
d<   |j                  dd      }|||
d<   |r	d|vr||
d<   t!        ||fd|i|
S )a  Try to open the URI using the standard library io.open function.

    This can be much faster than the alternative of opening in binary mode and
    then decoding.

    This is only possible under the following conditions:

        1. Opening a local file; and
        2. Compression is disabled

    If it is not possible to use the built-in open for the specified URI,
    returns None.

    Args:
        uri: A string indicating what to open.
        mode: The mode to pass to the open function.
        compression: The compression type selected.
        buffering: Mimicks built-in open parameter of the same name.
        encoding: Mimicks built-in open parameter of the same name.
        errors: Mimicks built-in open parameter of the same name.
        newline: Mimicks built-in open parameter of the same name.

    Returns:
        The opened file, or None if no shortcut is possible.
    Nr0   r>   r?   r2   r1   r/   )rF   rG   r   r   	NO_SCHEMEso_fileSCHEMEextract_local_pathrI   INFER_FROM_EXTENSIONrN   rO   suffixget_supported_extensionsNO_COMPRESSIONrM   _builtin_open)r-   r.   r5   r/   r0   r1   r2   r   
local_path	extensionopen_kwargss              r   rL   rL   c  s    D c33Fi))7>>::++C0Jn999LL,33	??AA	55	5"$K"*J||C$!(I
 #T/ &HTNYN+NNr   c                6   |dvrd|}t        |      t        | t              rt        | |d      S t        | t              sd| }t        |      t        |       }t        j                  |      }|j                  | ||      }t        |d      s| |_        |S )a   Open an arbitrary URI in the specified binary mode.

    Not all modes are supported for all protocols.

    Args:
        uri: The URI to open.  May be a string, or something else.
        mode: The mode to open with.  Must be rb, wb or ab.
        transport_params: Keyword arguments for the transport layer.

    Returns:
        A file-like object with a ``.name`` attribute.

    Raises:
        NotImplementedError: If ``mode`` is not a supported binary mode.
        TypeError: If ``uri`` is not a string or integer file descriptor.
    )rbzrb+wbzwb+abzab+zunsupported mode: F)r3   zdon't know how to handle uri r   )rR   rF   intr   rG   rH   r   r   r"   open_urihasattrr   )r-   r.   r7   r^   r   r(   r_   s          r   rT   rT     s    " ::
 #4(+!#&&#s S$66c3-cW5n3F''/Ic4)9:D4 	Kr   c                    t         j                  dt                      d|v r|| S |t        }t	        j
                  | |||d      S )a  Decode bytes into text, if necessary.

    If mode specifies binary access, does nothing, unless the encoding is
    specified.  A non-null encoding implies text mode.

    Args:
        fileobj: Must quack like a filehandle object.
        mode: The mode which was originally requested by the user.
        encoding: The text encoding to use.  If mode is binary, overrides mode.
        errors: The method to use when handling encoding/decoding errors.
        newline: Forwarded to the text wrapper.

    Returns:
        A file object.
    zencoding_wrapper: %rr>   T)r0   r1   r2   write_through)rC   rD   rE   rP   r\   TextIOWrapper)fileobjr.   r0   r1   r2   s        r   rW   rW     sU    , LL'2 d{x'#!! r   c                  (    e Zd ZdZddZddZddZy)	patch_pathlibz+Replace `Path.open` with `smart_open.open`.c                ,    t        t              | _        y r+   )_patch_pathlibr8   old_implselfs    r   __init__zpatch_pathlib.__init__  s    &t,r   c                    | S r+   r!   r   s    r   	__enter__zpatch_pathlib.__enter__
  s    r   c                .    t        | j                         y r+   )r   r   )r   exc_typeexc_valexc_tbs       r   __exit__zpatch_pathlib.__exit__  s    t}}%r   N)rv   rw   )rv   r   )r   objectr   r   r   r   rv   rw   )__name__
__module____qualname____doc__r   r   r   r!   r   r   r   r     s    5-&r   r   c                d    t         j                  j                  }| t         j                  _        |S )z Replace `Path.open` with `func`.)rN   rO   r8   )funcr   s     r   r   r     s"    ||  HGLLOr   zEncountered a non-fatal error while building docstrings (see below). help(smart_open) will provide incomplete information as a result. For full help text, see <https://github.com/piskvorky/smart_open/blob/master/help.txt>.)r   rG   rv   rG   )r   rG   rv   ztuple[Any, ...])
..........)r-   r   r.   zELiteral['r', 'w', 'a', 'x', 'r+', 'w+', 'a+', 'rt', 'wt', 'at', 'xt']r/   r   r0   
str | Noner1   r   r2   r   r3   boolr4    Callable[[str, int], int] | Noner5   rG   r6   CompressionKwargs | Noner7   TransportParams | Nonerv   r	   ).)r-   r   r.   zFLiteral['rb', 'wb', 'ab', 'xb', 'rb+', 'wb+', 'ab+', 'br', 'bw', 'ba']r/   r   r0   rw   r1   r   r2   r   r3   r   r4   r   r5   rG   r6   r   r7   r   rv   r   )r-   r   r.   rG   r/   r   r0   r   r1   r   r2   r   r3   r   r4   r   r5   rG   r6   r   r7   r   rv   rB   )r|   rG   rv   rG   )r<   NNN)r-   r   r.   rG   r5   rG   r/   r   r0   r   r1   r   r2   r   rv   zIO[Any] | None)r-   r   r.   rG   r7   r   rv   z	IO[bytes])NNN)r   rB   r.   rG   r0   r   r1   r   r2   r   rv   rB   )r   Callable[..., Any]rv   r   )>r   
__future__r   r$   rX   localeloggingr   os.pathrN   urllib.parser   typingr   r   r   r   r   r	   r
   r   smart_open.compressionr5   rI   smart_open.local_file
local_filer   smart_open.utilsutilsr\   
smart_openr   r   collections.abcr   typing_extensionsr   smart_open._typingr   r   r   	getLoggerr   rC   getpreferredencodingrP   r   r#   
_parse_urir8   r   r   rQ   rL   rT   rW   r   r   tweak_open_docstringtweak_parse_uri_docstring	Exception	exceptionr!   r   r   <module>r      sS   = "     	    T T T / ( # *(&JJ			8	$.6..EB 	74 
 
 SV/236/2	
O  	
    -  1 -  
 
 
 /236/2	
P 
     -  1 -  
  
 /236/2	
  	
    -  1 -  
" /3%::37/3aD	aD
aD aD 	aD
 aD aD aD -aD aD 1aD -aD aDH4v >O	>O
>O >O 	>O
 >O >O >O >OB-f  --
- - 	-
 - -`
& 
&	!H!!$'&H&&y1 
	Js   $F9 9GG