__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
#! /usr/bin/env python
"""Python 3.x buffer-handling (currently just for bytes/bytearray types)
"""
import ctypes, sys
if sys.version_info[:2] < (2, 6):
raise ImportError('Buffer interface only usable on Python 2.6+')
from ._arrayconstants import *
PyBUF_SIMPLE = 0
PyBUF_WRITABLE = PyBUF_WRITEABLE = 0x0001
PyBUF_ND = 0x0008
PyBUF_STRIDES = 0x0010 | PyBUF_ND
PyBUF_CONTIG = PyBUF_ND | PyBUF_WRITABLE
PyBUF_CONTIG_RO = PyBUF_ND
PyBUF_C_CONTIGUOUS = 0x0020 | PyBUF_STRIDES
PyBUF_FORMAT = 0x0004
# Python 2.6 doesn't define this...
c_ssize_t = getattr(ctypes, 'c_ssize_t', ctypes.c_ulong)
_fields_ = [
('buf', ctypes.c_void_p),
('obj', ctypes.c_void_p),
('len', c_ssize_t),
('itemsize', c_ssize_t),
('readonly', ctypes.c_int),
('ndim', ctypes.c_int),
('format', ctypes.c_char_p),
('shape', ctypes.POINTER(c_ssize_t)),
('strides', ctypes.POINTER(c_ssize_t)),
('suboffsets', ctypes.POINTER(c_ssize_t)),
]
if sys.version_info[:2] <= (2, 6) or sys.version_info[:2] >= (3, 3):
# Original structure was eventually restored in 3.3, so just
# 2.7 through 3.2 uses the "enhanced" structure below
_fields_.extend(
[
('internal', ctypes.c_void_p),
]
)
else:
# Sigh, this structure seems to have changed with Python 3.x...
_fields_.extend(
[
('smalltable', ctypes.c_size_t * 2),
('internal', ctypes.c_void_p),
]
)
class Py_buffer(ctypes.Structure):
"""Wrapper around the Python buffer structure..."""
@classmethod
def from_object(
cls, object, flags=PyBUF_STRIDES | PyBUF_FORMAT | PyBUF_C_CONTIGUOUS
):
"""Create a new Py_buffer referencing ram of object"""
if not CheckBuffer(object):
raise TypeError(
"%s type does not support Buffer Protocol" % (object.__class__,)
)
buf = cls()
# deallocation of the buf causes glibc abort :(
result = GetBuffer(object, buf, flags)
if result != 0:
raise ValueError("Unable to retrieve Buffer from %s" % (object,))
if not buf.buf:
raise ValueError("Null pointer result from %s" % (object,))
return buf
_fields_ = _fields_
@property
def dims(self):
return self.shape[: self.ndim]
def __len__(self):
return self.shape[0]
@property
def dim_strides(self):
if self.strides:
return self.strides[: self.ndim]
return None
def __enter__(self):
pass
def __exit__(self, exc_type=None, exc_value=None, traceback=None):
if self.obj:
ReleaseBuffer(self)
def __del__(self):
if self.obj:
ReleaseBuffer(self)
BUFFER_POINTER = ctypes.POINTER(Py_buffer)
try:
CheckBuffer = ctypes.pythonapi.PyObject_CheckBuffer
CheckBuffer.argtypes = [ctypes.py_object]
CheckBuffer.restype = ctypes.c_int
except AttributeError as err:
# Python 2.6 doesn't appear to have CheckBuffer support...
def CheckBuffer(x):
True
IncRef = ctypes.pythonapi.Py_IncRef
IncRef.argtypes = [ctypes.py_object]
GetBuffer = ctypes.pythonapi.PyObject_GetBuffer
GetBuffer.argtypes = [ctypes.py_object, BUFFER_POINTER, ctypes.c_int]
GetBuffer.restype = ctypes.c_int
ReleaseBuffer = ctypes.pythonapi.PyBuffer_Release
ReleaseBuffer.argtypes = [BUFFER_POINTER]
ReleaseBuffer.restype = None
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| __pycache__ | Folder | 0755 |
|
|
| __init__.py | File | 637 B | 0644 |
|
| _arrayconstants.py | File | 1.41 KB | 0644 |
|
| _buffers.py | File | 3.34 KB | 0644 |
|
| _strings.py | File | 2.25 KB | 0644 |
|
| arraydatatype.py | File | 13.64 KB | 0644 |
|
| arrayhelpers.py | File | 7 KB | 0644 |
|
| buffers.py | File | 4.29 KB | 0644 |
|
| ctypesarrays.py | File | 5.26 KB | 0644 |
|
| ctypesparameters.py | File | 5.42 KB | 0644 |
|
| ctypespointers.py | File | 3.36 KB | 0644 |
|
| formathandler.py | File | 3.78 KB | 0644 |
|
| lists.py | File | 7.66 KB | 0644 |
|
| nones.py | File | 2.42 KB | 0644 |
|
| numbers.py | File | 3.63 KB | 0644 |
|
| numpybuffers.py | File | 4.69 KB | 0644 |
|
| numpymodule.py | File | 10.4 KB | 0644 |
|
| strings.py | File | 3.58 KB | 0644 |
|
| vbo.py | File | 19.01 KB | 0644 |
|