
û“\d  ã               @   s:  d  Z  d d l m Z m Z m Z d d l m Z d d d d d d	 d
 d d d d d d d d d g Z d Z d Z	 d Z
 d Z d Z e
 e Be BZ d Z d Z d Z d Z d Z d Z d Z d Z e e d  ƒ ƒ Z e j Z e e e g e _ e e _ e j Z e e g e _ e e _ e d! d „ Z d" d „  Z d# S)$aˆ  
vis.py
======

Ctypes based module to access libbsd's strvis & strunvis functions.

The `vis` function is the equivalent of strvis.
The `unvis` function is the equivalent of strunvis.
All functions accept unicode string as input and return a unicode string.

Constants:
----------

* to select alternate encoding format
  `VIS_OCTAL`:      use octal \ddd format
  `VIS_CSTYLE`:     use \[nrft0..] where appropiate

* to alter set of characters encoded
  (default is to encode all non-graphic except space, tab, and newline).
  `VIS_SP`:         also encode space
  `VIS_TAB`:        also encode tab
  `VIS_NL`:         also encode newline
  `VIS_WHITE`:      same as (VIS_SP | VIS_TAB | VIS_NL)
  `VIS_SAFE`:       only encode "unsafe" characters

* other
  `VIS_NOSLASH`:    inhibit printing ''
  `VIS_HTTP1808`:   http-style escape % hex hex
  `VIS_HTTPSTYLE`:  http-style escape % hex hex
  `VIS_MIMESTYLE`:  mime-style escape = HEX HEX
  `VIS_HTTP1866`:   http-style &#num; or &string;
  `VIS_NOESCAPE`:   don't decode `'
  `VIS_GLOB`:       encode glob(3) magic characters

:Authors:
    - ju1ius (http://github.com/ju1ius)
:Version: 1
:Date: 2014-01-05
é    )ÚCDLLÚc_char_pÚc_int)Úfind_libraryÚvisÚunvisÚ	VIS_OCTALÚ
VIS_CSTYLEÚVIS_SPÚVIS_TABÚVIS_NLÚ	VIS_WHITEÚVIS_SAFEÚVIS_NOSLASHÚVIS_HTTP1808ÚVIS_HTTPSTYLEÚVIS_MIMESTYLEÚVIS_HTTP1866ÚVIS_NOESCAPEÚVIS_GLOBé   é   é   é   é   é    é@   é€   é   i   i   i   Zbsdc             C   s†   t  |  d ƒ }  t t  t |  ƒ d ƒ ƒ } t |  ƒ } t | ƒ } t | | | ƒ } d | k rv t d j |  ƒ ƒ ‚ | j j d ƒ S)z±
    Encodes the string `src` into libbsd's vis encoding.
    `flags` must be one of the VIS_* constants

    C definition:
    int strvis(char *dst, char *src, int flags);
    zutf-8r   r   z vis failed to encode string "{}"éÿÿÿÿ)	Úbytesr   Úlenr   Ú_strvisÚRuntimeErrorÚformatÚvalueÚdecode)ÚsrcÚflagsÚdst_pÚsrc_pÚbytes_written© r,   úE/home/www/bushmediatt.com/demo/pos/vendor/psy/psysh/test/tools/vis.pyr   [   s    c             C   ss   t  |  d ƒ }  t t  t |  ƒ ƒ ƒ } t |  ƒ } t | | ƒ } d | k rc t d j |  ƒ ƒ ‚ | j j d ƒ S)ze
    Decodes a string encoded by vis.

    C definition:
    int strunvis(char *dst, char *src);
    zutf-8r   z"unvis failed to decode string "{}"r   )r    r   r!   Ú	_strunvisr#   r$   r%   r&   )r'   r)   r*   r+   r,   r,   r-   r   o   s    N)Ú__doc__Zctypesr   r   r   Zctypes.utilr   Ú__all__r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   Z_libbsdZstrvisr"   ZargtypesZrestypeZstrunvisr.   r   r   r,   r,   r,   r-   Ú<module>'   s<   					