
    i                     d    d Z ddlmZ ddlmZ ddlmZ ddlZddZddZddZdd	Z	dd
Z
d ZdS )zCA module for dealing with unknown string and environment encodings.    )absolute_import)division)unicode_literalsNc                     ~| S )zEncode the text string to a byte string.

  Args:
    string: str, The text string to encode.
    encoding: The suggested encoding if known.

  Returns:
    str, The binary string.
   )stringencodings     \/home/ubuntu/.hermes/hermes-agent/venv/lib/python3.11/site-packages/fire/console/encoding.pyEncoder      s     	-    c                    | dS t          | t                    st          | t                    r| }nt          |           }t          |t                    r|S 	 |                    d          S # t          $ r Y nw xY w|r&	 |                    |          S # t          $ r Y nw xY w	 |                    d          S # t          $ r Y nw xY w	 |                    t          j                              S # t          $ r Y nw xY w	 |                    t          j                              S # t          $ r Y nw xY w|                    d          S )a  Returns string with non-ascii characters decoded to UNICODE.

  UTF-8, the suggested encoding, and the usual suspects will be attempted in
  order.

  Args:
    data: A string or object that has str() and unicode() methods that may
      contain an encoding incompatible with the standard output encoding.
    encoding: The suggested encoding if known.

  Returns:
    A text string representing the decoded byte string.
  Nasciiutf8z
iso-8859-1)
isinstancestrbytesdecodeUnicodeErrorsysgetfilesystemencodinggetdefaultencoding)datar	   r   s      r
   Decoder   (   s    
\4 c ju55 FF YYF M	==!!!	 	 	 	D	
  ]]8$$$   
d	==   	 	 	 	D	
	==244555	 	 	 	D	
	==/11222	 	 	 	D	& 
|	$	$$sZ   A. .
A;:A;B 
B#"B#'B< <
C	C	%C3 3
D ?D %D* *
D76D7c                 p    t          |          }|                     |          }||S t          |          S )zReturns the decoded value of the env var name.

  Args:
    env: {str: str}, The env dict.
    name: str, The env var name.
    default: The value to return if name is not in env.

  Returns:
    The decoded value of the env var name.
  )r   getr   )envnamedefaultvalues       r
   GetEncodedValuer    |   s6     
$
''$--%
]N 
r   c                     t          ||          }||                     |d           dS t          ||          | |<   dS )a!  Sets the value of name in env to an encoded value.

  Args:
    env: {str: str}, The env dict.
    name: str, The env var name.
    value: str or unicode, The value for name. If None then name is removed from
      env.
    encoding: str, The encoding to use or None to try to infer it.
  r	   N)r   pop)r   r   r   r	   s       r
   SetEncodedValuer$      sN    & 
x	(	(	($
]GGD$
FUX...#d)))r   c                 d    pt                      fd|                                 D             S )a%  Encodes all the key value pairs in env in preparation for subprocess.

  Args:
    env: {str: str}, The environment you are going to pass to subprocess.
    encoding: str, The encoding to use or None to use the default.

  Returns:
    {bytes: bytes}, The environment to pass to subprocess.
  c                 X    i | ]&\  }}t          |           t          |           'S )r"   )r   ).0kvr	   s      r
   
<dictcomp>zEncodeEnv.<locals>.<dictcomp>   sI     
 
 

!Q Q"""F1x$@$@$@
 
 
r   )_GetEncodingitems)r   r	   s    `r
   	EncodeEnvr-      sF     '(
 
 
 
))++
 
 
 r   c                  N    t          j                    pt          j                    S )z!Gets the default encoding to use.)r   r   r   r   r   r
   r+   r+      s    		"	$	$	@(>(@(@@r   )N)__doc__
__future__r   r   r   r   r   r   r    r$   r-   r+   r   r   r
   <module>r1      s   " J I & & & & & &       ' ' ' ' ' ' 



   Q% Q% Q% Q%h   (/ / / /4   "A A A A Ar   