$71 GRAYBYTE WORDPRESS FILE MANAGER $30

SERVER : premium201.web-hosting.com #1 SMP Wed Mar 26 12:08:09 UTC 2025
SERVER IP : 172.67.217.254 | ADMIN IP 216.73.216.180
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : mail

/opt/imunify360/venv/lib/python3.11/site-packages/Crypto/Util/

HOME
Current File : /opt/imunify360/venv/lib/python3.11/site-packages/Crypto/Util//py3compat.py
# -*- coding: utf-8 -*-
#
#  Util/py3compat.py : Compatibility code for handling Py3k / Python 2.x
#
# Written in 2010 by Thorsten Behrens
#
# ===================================================================
# The contents of this file are dedicated to the public domain.  To
# the extent that dedication to the public domain is not available,
# everyone is granted a worldwide, perpetual, royalty-free,
# non-exclusive license to exercise all rights associated with the
# contents of this file for any purpose whatsoever.
# No rights are reserved.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# ===================================================================

"""Compatibility code for handling string/bytes changes from Python 2.x to Py3k

In Python 2.x, strings (of type ''str'') contain binary data, including encoded
Unicode text (e.g. UTF-8).  The separate type ''unicode'' holds Unicode text.
Unicode literals are specified via the u'...' prefix.  Indexing or slicing
either type always produces a string of the same type as the original.
Data read from a file is always of '''str'' type.

In Python 3.x, strings (type ''str'') may only contain Unicode text. The u'...'
prefix and the ''unicode'' type are now redundant.  A new type (called
''bytes'') has to be used for binary data (including any particular
''encoding'' of a string).  The b'...' prefix allows one to specify a binary
literal.  Indexing or slicing a string produces another string.  Slicing a byte
string produces another byte string, but the indexing operation produces an
integer.  Data read from a file is of '''str'' type if the file was opened in
text mode, or of ''bytes'' type otherwise.

Since PyCrypto aims at supporting both Python 2.x and 3.x, the following helper
functions are used to keep the rest of the library as independent as possible
from the actual Python version.

In general, the code should always deal with binary strings, and use integers
instead of 1-byte character strings.

b(s)
    Take a text string literal (with no prefix or with u'...' prefix) and
    make a byte string.
bchr(c)
    Take an integer and make a 1-character byte string.
bord(c)
    Take the result of indexing on a byte string and make an integer.
tobytes(s)
    Take a text string, a byte string, or a sequence of character taken from
    a byte string and make a byte string.
"""

import sys
import abc


if sys.version_info[0] == 2:
    def b(s):
        return s
    def bchr(s):
        return chr(s)
    def bstr(s):
        return str(s)
    def bord(s):
        return ord(s)
    def tobytes(s, encoding="latin-1"):
        if isinstance(s, unicode):
            return s.encode(encoding)
        elif isinstance(s, str):
            return s
        elif isinstance(s, bytearray):
            return bytes(s)
        elif isinstance(s, memoryview):
            return s.tobytes()
        else:
            return ''.join(s)
    def tostr(bs):
        return bs
    def byte_string(s):
        return isinstance(s, str)

    from StringIO import StringIO
    BytesIO = StringIO

    from sys import maxint

    iter_range = xrange

    def is_native_int(x):
        return isinstance(x, (int, long))

    def is_string(x):
        return isinstance(x, basestring)

    def is_bytes(x):
        return isinstance(x, str) or \
                isinstance(x, bytearray) or \
                isinstance(x, memoryview)

    ABC = abc.ABCMeta('ABC', (object,), {'__slots__': ()})

    FileNotFoundError = IOError

else:
    def b(s):
       return s.encode("latin-1") # utf-8 would cause some side-effects we don't want
    def bchr(s):
        return bytes([s])
    def bstr(s):
        if isinstance(s,str):
            return bytes(s,"latin-1")
        else:
            return bytes(s)
    def bord(s):
        return s
    def tobytes(s, encoding="latin-1"):
        if isinstance(s, bytes):
            return s
        elif isinstance(s, bytearray):
            return bytes(s)
        elif isinstance(s,str):
            return s.encode(encoding)
        elif isinstance(s, memoryview):
            return s.tobytes()
        else:
            return bytes([s])
    def tostr(bs):
        return bs.decode("latin-1")
    def byte_string(s):
        return isinstance(s, bytes)

    from io import BytesIO
    from io import StringIO
    from sys import maxsize as maxint

    iter_range = range

    def is_native_int(x):
        return isinstance(x, int)

    def is_string(x):
        return isinstance(x, str)

    def is_bytes(x):
        return isinstance(x, bytes) or \
                isinstance(x, bytearray) or \
                isinstance(x, memoryview)

    from abc import ABC

    FileNotFoundError = FileNotFoundError


def _copy_bytes(start, end, seq):
    """Return an immutable copy of a sequence (byte string, byte array, memoryview)
    in a certain interval [start:seq]"""

    if isinstance(seq, memoryview):
        return seq[start:end].tobytes()
    elif isinstance(seq, bytearray):
        return bytes(seq[start:end])
    else:
        return seq[start:end]

del sys
del abc


Current_dir [ NOT WRITEABLE ] Document_root [ NOT WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
3 Mar 2026 8.59 AM
root / root
0755
__pycache__
--
3 Mar 2026 8.59 AM
root / root
0755
Counter.py
3.037 KB
13 Feb 2026 12.40 PM
root / root
0644
Counter.pyi
0.283 KB
13 Feb 2026 12.40 PM
root / root
0644
Padding.py
4.212 KB
13 Feb 2026 12.40 PM
root / root
0644
Padding.pyi
0.232 KB
13 Feb 2026 12.40 PM
root / root
0644
RFC1751.py
20.695 KB
13 Feb 2026 12.40 PM
root / root
0644
RFC1751.pyi
0.155 KB
13 Feb 2026 12.40 PM
root / root
0644
__init__.py
1.882 KB
13 Feb 2026 12.40 PM
root / root
0644
_cpu_features.py
1.942 KB
13 Feb 2026 12.40 PM
root / root
0644
_cpu_features.pyi
0.058 KB
13 Feb 2026 12.40 PM
root / root
0644
_cpuid_c.abi3.so
15.328 KB
13 Feb 2026 12.41 PM
root / root
0755
_file_system.py
2.12 KB
13 Feb 2026 12.40 PM
root / root
0644
_file_system.pyi
0.098 KB
13 Feb 2026 12.40 PM
root / root
0644
_raw_api.py
9.986 KB
13 Feb 2026 12.40 PM
root / root
0644
_raw_api.pyi
0.885 KB
13 Feb 2026 12.40 PM
root / root
0644
_strxor.abi3.so
15.32 KB
13 Feb 2026 12.41 PM
root / root
0755
asn1.py
35.321 KB
13 Feb 2026 12.40 PM
root / root
0644
asn1.pyi
3.716 KB
13 Feb 2026 12.40 PM
root / root
0644
number.py
94.112 KB
13 Feb 2026 12.40 PM
root / root
0644
number.pyi
0.952 KB
13 Feb 2026 12.40 PM
root / root
0644
py3compat.py
5.396 KB
13 Feb 2026 12.40 PM
root / root
0644
py3compat.pyi
0.817 KB
13 Feb 2026 12.40 PM
root / root
0644
strxor.py
5.313 KB
13 Feb 2026 12.40 PM
root / root
0644
strxor.pyi
0.237 KB
13 Feb 2026 12.40 PM
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2025 CONTACT ME
Static GIF