Dre4m Shell
Server IP : 127.0.0.2  /  Your IP : 3.128.24.183
Web Server : Apache/2.4.18 (Ubuntu)
System :
User : www-data ( )
PHP Version : 7.0.33-0ubuntu0.16.04.16
Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /var/www/html/vendor/psy/psysh/test/tools/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /var/www/html/vendor/psy/psysh/test/tools/vis.py
"""
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
"""
from ctypes import CDLL, c_char_p, c_int
from ctypes.util import find_library


__all__ = [
    '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'
]


#############################################################
# Constants from bsd/vis.h
#############################################################

#to select alternate encoding format
VIS_OCTAL = 0x0001
VIS_CSTYLE = 0x0002
# to alter set of characters encoded
# (default is to encode all non-graphic except space, tab, and newline).
VIS_SP = 0x0004
VIS_TAB = 0x0008
VIS_NL = 0x0010
VIS_WHITE = VIS_SP | VIS_TAB | VIS_NL
VIS_SAFE = 0x0020
# other
VIS_NOSLASH = 0x0040
VIS_HTTP1808 = 0x0080
VIS_HTTPSTYLE = 0x0080
VIS_MIMESTYLE = 0x0100
VIS_HTTP1866 = 0x0200
VIS_NOESCAPE = 0x0400
VIS_GLOB = 0x1000

#############################################################
# Import libbsd/vis functions
#############################################################

_libbsd = CDLL(find_library('bsd'))

_strvis = _libbsd.strvis
_strvis.argtypes = [c_char_p, c_char_p, c_int]
_strvis.restype = c_int

_strunvis = _libbsd.strunvis
_strvis.argtypes = [c_char_p, c_char_p]
_strvis.restype = c_int


def vis(src, flags=VIS_WHITE):
    """
    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);
    """
    src = bytes(src, 'utf-8')
    dst_p = c_char_p(bytes(len(src) * 4))
    src_p = c_char_p(src)
    flags = c_int(flags)

    bytes_written = _strvis(dst_p, src_p, flags)
    if -1 == bytes_written:
        raise RuntimeError('vis failed to encode string "{}"'.format(src))

    return dst_p.value.decode('utf-8')


def unvis(src):
    """
    Decodes a string encoded by vis.

    C definition:
    int strunvis(char *dst, char *src);
    """
    src = bytes(src, 'utf-8')
    dst_p = c_char_p(bytes(len(src)))
    src_p = c_char_p(src)

    bytes_written = _strunvis(dst_p, src_p)
    if -1 == bytes_written:
        raise RuntimeError('unvis failed to decode string "{}"'.format(src))

    return dst_p.value.decode('utf-8')

Anon7 - 2022
AnonSec Team