|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
""" |
|
all Python Standard Library objects (currently: CH 1-15 @ 2.7) |
|
and some other common objects (i.e. numpy.ndarray) |
|
""" |
|
|
|
__all__ = ['registered','failures','succeeds'] |
|
|
|
|
|
import warnings; warnings.filterwarnings("ignore", category=DeprecationWarning) |
|
import sys |
|
import queue as Queue |
|
import dbm as anydbm |
|
from io import BytesIO as StringIO |
|
import re |
|
import array |
|
import collections |
|
import codecs |
|
import struct |
|
import dataclasses |
|
import datetime |
|
import calendar |
|
import weakref |
|
import pprint |
|
import decimal |
|
import numbers |
|
import functools |
|
import itertools |
|
import operator |
|
import tempfile |
|
import shelve |
|
import zlib |
|
import gzip |
|
import zipfile |
|
import tarfile |
|
import csv |
|
import hashlib |
|
import hmac |
|
import os |
|
import logging |
|
import logging.handlers |
|
import optparse |
|
|
|
import threading |
|
import socket |
|
import contextlib |
|
try: |
|
import bz2 |
|
import sqlite3 |
|
import dbm.ndbm as dbm |
|
HAS_ALL = True |
|
except ImportError: |
|
HAS_ALL = False |
|
try: |
|
|
|
|
|
HAS_CURSES = True |
|
except ImportError: |
|
HAS_CURSES = False |
|
try: |
|
import ctypes |
|
HAS_CTYPES = True |
|
|
|
IS_PYPY = not hasattr(ctypes, 'pythonapi') |
|
except ImportError: |
|
HAS_CTYPES = False |
|
IS_PYPY = False |
|
|
|
|
|
class _class: |
|
def _method(self): |
|
pass |
|
|
|
|
|
|
|
|
|
|
|
|
|
class _class2: |
|
def __call__(self): |
|
pass |
|
_instance2 = _class2() |
|
class _newclass(object): |
|
def _method(self): |
|
pass |
|
|
|
|
|
|
|
|
|
|
|
|
|
class _newclass2(object): |
|
__slots__ = ['descriptor'] |
|
def _function(x): yield x |
|
def _function2(): |
|
try: raise |
|
except Exception: |
|
from sys import exc_info |
|
e, er, tb = exc_info() |
|
return er, tb |
|
if HAS_CTYPES: |
|
class _Struct(ctypes.Structure): |
|
pass |
|
_Struct._fields_ = [("_field", ctypes.c_int),("next", ctypes.POINTER(_Struct))] |
|
_filedescrip, _tempfile = tempfile.mkstemp('r') |
|
if sys.hexversion < 0x30d00a1: |
|
_tmpf = tempfile.TemporaryFile('w') |
|
else: |
|
_tmpf = tempfile.NamedTemporaryFile('w').file |
|
|
|
|
|
registered = d = {} |
|
|
|
failures = x = {} |
|
|
|
succeeds = a = {} |
|
|
|
|
|
a['BooleanType'] = bool(1) |
|
a['BuiltinFunctionType'] = len |
|
a['BuiltinMethodType'] = a['BuiltinFunctionType'] |
|
a['BytesType'] = _bytes = codecs.latin_1_encode('\x00')[0] |
|
a['ClassType'] = _class |
|
a['ComplexType'] = complex(1) |
|
a['DictType'] = _dict = {} |
|
a['DictionaryType'] = a['DictType'] |
|
a['FloatType'] = float(1) |
|
a['FunctionType'] = _function |
|
a['InstanceType'] = _instance = _class() |
|
a['IntType'] = _int = int(1) |
|
a['ListType'] = _list = [] |
|
a['NoneType'] = None |
|
a['ObjectType'] = object() |
|
a['StringType'] = _str = str(1) |
|
a['TupleType'] = _tuple = () |
|
a['TypeType'] = type |
|
a['LongType'] = _int |
|
a['UnicodeType'] = _str |
|
|
|
a['CopyrightType'] = copyright |
|
|
|
a['ClassObjectType'] = _newclass |
|
a['ClassInstanceType'] = _newclass() |
|
a['SetType'] = _set = set() |
|
a['FrozenSetType'] = frozenset() |
|
|
|
a['ExceptionType'] = _exception = _function2()[0] |
|
|
|
a['SREPatternType'] = _srepattern = re.compile('') |
|
|
|
a['ArrayType'] = array.array("f") |
|
a['DequeType'] = collections.deque([0]) |
|
a['DefaultDictType'] = collections.defaultdict(_function, _dict) |
|
a['TZInfoType'] = datetime.tzinfo() |
|
a['DateTimeType'] = datetime.datetime.today() |
|
a['CalendarType'] = calendar.Calendar() |
|
|
|
a['DecimalType'] = decimal.Decimal(1) |
|
a['CountType'] = itertools.count(0) |
|
|
|
a['TarInfoType'] = tarfile.TarInfo() |
|
|
|
a['LoggerType'] = _logger = logging.getLogger() |
|
a['FormatterType'] = logging.Formatter() |
|
a['FilterType'] = logging.Filter() |
|
a['LogRecordType'] = logging.makeLogRecord(_dict) |
|
a['OptionParserType'] = _oparser = optparse.OptionParser() |
|
a['OptionGroupType'] = optparse.OptionGroup(_oparser,"foo") |
|
a['OptionType'] = optparse.Option('--foo') |
|
if HAS_CTYPES: |
|
z = x if IS_PYPY else a |
|
z['CCharType'] = _cchar = ctypes.c_char() |
|
z['CWCharType'] = ctypes.c_wchar() |
|
z['CByteType'] = ctypes.c_byte() |
|
z['CUByteType'] = ctypes.c_ubyte() |
|
z['CShortType'] = ctypes.c_short() |
|
z['CUShortType'] = ctypes.c_ushort() |
|
z['CIntType'] = ctypes.c_int() |
|
z['CUIntType'] = ctypes.c_uint() |
|
z['CLongType'] = ctypes.c_long() |
|
z['CULongType'] = ctypes.c_ulong() |
|
z['CLongLongType'] = ctypes.c_longlong() |
|
z['CULongLongType'] = ctypes.c_ulonglong() |
|
z['CFloatType'] = ctypes.c_float() |
|
z['CDoubleType'] = ctypes.c_double() |
|
z['CSizeTType'] = ctypes.c_size_t() |
|
del z |
|
a['CLibraryLoaderType'] = ctypes.cdll |
|
a['StructureType'] = _Struct |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import fractions |
|
import io |
|
from io import StringIO as TextIO |
|
|
|
a['ByteArrayType'] = bytearray([1]) |
|
|
|
a['FractionType'] = fractions.Fraction() |
|
a['NumberType'] = numbers.Number() |
|
|
|
a['IOBaseType'] = io.IOBase() |
|
a['RawIOBaseType'] = io.RawIOBase() |
|
a['TextIOBaseType'] = io.TextIOBase() |
|
a['BufferedIOBaseType'] = io.BufferedIOBase() |
|
a['UnicodeIOType'] = TextIO() |
|
a['LoggerAdapterType'] = logging.LoggerAdapter(_logger,_dict) |
|
if HAS_CTYPES: |
|
z = x if IS_PYPY else a |
|
z['CBoolType'] = ctypes.c_bool(1) |
|
z['CLongDoubleType'] = ctypes.c_longdouble() |
|
del z |
|
import argparse |
|
|
|
a['OrderedDictType'] = collections.OrderedDict(_dict) |
|
a['CounterType'] = collections.Counter(_dict) |
|
if HAS_CTYPES: |
|
z = x if IS_PYPY else a |
|
z['CSSizeTType'] = ctypes.c_ssize_t() |
|
del z |
|
|
|
a['NullHandlerType'] = logging.NullHandler() |
|
a['ArgParseFileType'] = argparse.FileType() |
|
|
|
|
|
|
|
a['CodeType'] = compile('','','exec') |
|
a['DictProxyType'] = type.__dict__ |
|
a['DictProxyType2'] = _newclass.__dict__ |
|
a['EllipsisType'] = Ellipsis |
|
a['ClosedFileType'] = open(os.devnull, 'wb', buffering=0).close() |
|
a['GetSetDescriptorType'] = array.array.typecode |
|
a['LambdaType'] = _lambda = lambda x: lambda y: x |
|
a['MemberDescriptorType'] = _newclass2.descriptor |
|
if not IS_PYPY: |
|
a['MemberDescriptorType2'] = datetime.timedelta.days |
|
a['MethodType'] = _method = _class()._method |
|
a['ModuleType'] = datetime |
|
a['NotImplementedType'] = NotImplemented |
|
a['SliceType'] = slice(1) |
|
a['UnboundMethodType'] = _class._method |
|
d['TextWrapperType'] = open(os.devnull, 'r') |
|
d['BufferedRandomType'] = open(os.devnull, 'r+b') |
|
d['BufferedReaderType'] = open(os.devnull, 'rb') |
|
d['BufferedWriterType'] = open(os.devnull, 'wb') |
|
try: |
|
from _pyio import open as _open |
|
d['PyTextWrapperType'] = _open(os.devnull, 'r', buffering=-1) |
|
d['PyBufferedRandomType'] = _open(os.devnull, 'r+b', buffering=-1) |
|
d['PyBufferedReaderType'] = _open(os.devnull, 'rb', buffering=-1) |
|
d['PyBufferedWriterType'] = _open(os.devnull, 'wb', buffering=-1) |
|
except ImportError: |
|
pass |
|
|
|
z = d if sys.hexversion < 0x30800a2 else a |
|
z['CellType'] = (_lambda)(0).__closure__[0] |
|
del z |
|
a['XRangeType'] = _xrange = range(1) |
|
a['MethodDescriptorType'] = type.__dict__['mro'] |
|
a['WrapperDescriptorType'] = type.__repr__ |
|
|
|
a['ClassMethodDescriptorType'] = type.__dict__['__prepare__'] |
|
|
|
_methodwrap = (1).__lt__ |
|
a['MethodWrapperType'] = _methodwrap |
|
a['StaticMethodType'] = staticmethod(_method) |
|
a['ClassMethodType'] = classmethod(_method) |
|
a['PropertyType'] = property() |
|
d['SuperType'] = super(Exception, _exception) |
|
|
|
_in = _bytes |
|
a['InputType'] = _cstrI = StringIO(_in) |
|
a['OutputType'] = _cstrO = StringIO() |
|
|
|
a['WeakKeyDictionaryType'] = weakref.WeakKeyDictionary() |
|
a['WeakValueDictionaryType'] = weakref.WeakValueDictionary() |
|
a['ReferenceType'] = weakref.ref(_instance) |
|
a['DeadReferenceType'] = weakref.ref(_class()) |
|
a['ProxyType'] = weakref.proxy(_instance) |
|
a['DeadProxyType'] = weakref.proxy(_class()) |
|
a['CallableProxyType'] = weakref.proxy(_instance2) |
|
a['DeadCallableProxyType'] = weakref.proxy(_class2()) |
|
a['QueueType'] = Queue.Queue() |
|
|
|
d['PartialType'] = functools.partial(int,base=2) |
|
a['IzipType'] = zip('0','1') |
|
a['ChainType'] = itertools.chain('0','1') |
|
d['ItemGetterType'] = operator.itemgetter(0) |
|
d['AttrGetterType'] = operator.attrgetter('__repr__') |
|
|
|
_fileW = _cstrO |
|
|
|
if HAS_ALL: |
|
x['ConnectionType'] = _conn = sqlite3.connect(':memory:') |
|
x['CursorType'] = _conn.cursor() |
|
a['ShelveType'] = shelve.Shelf({}) |
|
|
|
if HAS_ALL: |
|
x['BZ2FileType'] = bz2.BZ2File(os.devnull) |
|
x['BZ2CompressorType'] = bz2.BZ2Compressor() |
|
x['BZ2DecompressorType'] = bz2.BZ2Decompressor() |
|
|
|
|
|
|
|
a['TarFileType'] = tarfile.open(fileobj=_fileW,mode='w') |
|
|
|
x['DialectType'] = csv.get_dialect('excel') |
|
if sys.hexversion < 0x30d00a1: |
|
import xdrlib |
|
a['PackerType'] = xdrlib.Packer() |
|
|
|
a['LockType'] = threading.Lock() |
|
a['RLockType'] = threading.RLock() |
|
|
|
a['NamedLoggerType'] = _logger = logging.getLogger(__name__) |
|
|
|
|
|
x['SocketType'] = _socket = socket.socket() |
|
x['SocketPairType'] = socket.socketpair()[0] |
|
|
|
a['GeneratorContextManagerType'] = contextlib.contextmanager(max)([1]) |
|
|
|
try: |
|
__IPYTHON__ is True |
|
except NameError: |
|
|
|
a['QuitterType'] = quit |
|
d['ExitType'] = a['QuitterType'] |
|
try: |
|
from numpy import ufunc as _numpy_ufunc |
|
from numpy import array as _numpy_array |
|
from numpy import int32 as _numpy_int32 |
|
a['NumpyUfuncType'] = _numpy_ufunc |
|
a['NumpyArrayType'] = _numpy_array |
|
a['NumpyInt32Type'] = _numpy_int32 |
|
except ImportError: |
|
pass |
|
|
|
a['ProductType'] = itertools.product('0','1') |
|
|
|
a['FileHandlerType'] = logging.FileHandler(os.devnull) |
|
a['RotatingFileHandlerType'] = logging.handlers.RotatingFileHandler(os.devnull) |
|
a['SocketHandlerType'] = logging.handlers.SocketHandler('localhost',514) |
|
a['MemoryHandlerType'] = logging.handlers.MemoryHandler(1) |
|
|
|
a['WeakSetType'] = weakref.WeakSet() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
d['FileType'] = open(os.devnull, 'rb', buffering=0) |
|
|
|
|
|
a['ListIteratorType'] = iter(_list) |
|
a['SetIteratorType'] = iter(_set) |
|
a['TupleIteratorType']= iter(_tuple) |
|
a['XRangeIteratorType'] = iter(_xrange) |
|
a["BytesIteratorType"] = iter(b'') |
|
a["BytearrayIteratorType"] = iter(bytearray(b'')) |
|
z = x if IS_PYPY else a |
|
z["CallableIteratorType"] = iter(iter, None) |
|
del z |
|
x["MemoryIteratorType"] = iter(memoryview(b'')) |
|
a["ListReverseiteratorType"] = reversed([]) |
|
X = a['OrderedDictType'] |
|
d["OdictKeysType"] = X.keys() |
|
d["OdictValuesType"] = X.values() |
|
d["OdictItemsType"] = X.items() |
|
a["OdictIteratorType"] = iter(X.keys()) |
|
del X |
|
|
|
a['DictionaryItemIteratorType'] = iter(type.__dict__.items()) |
|
a['DictionaryKeyIteratorType'] = iter(type.__dict__.keys()) |
|
a['DictionaryValueIteratorType'] = iter(type.__dict__.values()) |
|
if sys.hexversion >= 0x30800a0: |
|
a["DictReversekeyiteratorType"] = reversed({}.keys()) |
|
a["DictReversevalueiteratorType"] = reversed({}.values()) |
|
a["DictReverseitemiteratorType"] = reversed({}.items()) |
|
|
|
try: |
|
import symtable |
|
|
|
x["SymtableEntryType"] = symtable.symtable("", "string", "exec")._table |
|
except ImportError: |
|
pass |
|
|
|
if sys.hexversion >= 0x30a00a0 and not IS_PYPY: |
|
x['LineIteratorType'] = compile('3', '', 'eval').co_lines() |
|
|
|
if sys.hexversion >= 0x30b00b0: |
|
from types import GenericAlias |
|
d["GenericAliasIteratorType"] = iter(GenericAlias(list, (int,))) |
|
x['PositionsIteratorType'] = compile('3', '', 'eval').co_positions() |
|
|
|
|
|
a['PrettyPrinterType'] = pprint.PrettyPrinter() |
|
|
|
a['CycleType'] = itertools.cycle('0') |
|
|
|
a['TemporaryFileType'] = _tmpf |
|
|
|
x['GzipFileType'] = gzip.GzipFile(fileobj=_fileW) |
|
|
|
a['StreamHandlerType'] = logging.StreamHandler() |
|
|
|
a['PermutationsType'] = itertools.permutations('0') |
|
a['CombinationsType'] = itertools.combinations('0',1) |
|
a['RepeatType'] = itertools.repeat(0) |
|
a['CompressType'] = itertools.compress('0',[1]) |
|
|
|
|
|
|
|
|
|
x['GeneratorType'] = _generator = _function(1) |
|
x['FrameType'] = _generator.gi_frame |
|
x['TracebackType'] = _function2()[1] |
|
|
|
|
|
|
|
|
|
|
|
x['StructType'] = struct.Struct('c') |
|
x['CallableIteratorType'] = _srepattern.finditer('') |
|
x['SREMatchType'] = _srepattern.match('') |
|
x['SREScannerType'] = _srepattern.scanner('') |
|
x['StreamReader'] = codecs.StreamReader(_cstrI) |
|
|
|
|
|
if HAS_ALL: |
|
z = a if IS_PYPY else x |
|
z['DbmType'] = dbm.open(_tempfile,'n') |
|
del z |
|
|
|
|
|
|
|
x['ZlibCompressType'] = zlib.compressobj() |
|
x['ZlibDecompressType'] = zlib.decompressobj() |
|
|
|
x['CSVReaderType'] = csv.reader(_cstrI) |
|
x['CSVWriterType'] = csv.writer(_cstrO) |
|
x['CSVDictReaderType'] = csv.DictReader(_cstrI) |
|
x['CSVDictWriterType'] = csv.DictWriter(_cstrO,{}) |
|
|
|
x['HashType'] = hashlib.md5() |
|
if (sys.hexversion < 0x30800a1): |
|
x['HMACType'] = hmac.new(_in) |
|
else: |
|
x['HMACType'] = hmac.new(_in, digestmod='md5') |
|
|
|
if HAS_CURSES: pass |
|
|
|
|
|
|
|
if HAS_CTYPES: |
|
x['CCharPType'] = ctypes.c_char_p() |
|
x['CWCharPType'] = ctypes.c_wchar_p() |
|
x['CVoidPType'] = ctypes.c_void_p() |
|
if sys.platform[:3] == 'win': |
|
x['CDLLType'] = _cdll = ctypes.cdll.msvcrt |
|
else: |
|
x['CDLLType'] = _cdll = ctypes.CDLL(None) |
|
if not IS_PYPY: |
|
x['PyDLLType'] = _pydll = ctypes.pythonapi |
|
x['FuncPtrType'] = _cdll._FuncPtr() |
|
x['CCharArrayType'] = ctypes.create_string_buffer(1) |
|
x['CWCharArrayType'] = ctypes.create_unicode_buffer(1) |
|
x['CParamType'] = ctypes.byref(_cchar) |
|
x['LPCCharType'] = ctypes.pointer(_cchar) |
|
x['LPCCharObjType'] = _lpchar = ctypes.POINTER(ctypes.c_char) |
|
x['NullPtrType'] = _lpchar() |
|
x['NullPyObjectType'] = ctypes.py_object() |
|
x['PyObjectType'] = ctypes.py_object(lambda :None) |
|
z = a if IS_PYPY else x |
|
z['FieldType'] = _field = _Struct._field |
|
z['CFUNCTYPEType'] = _cfunc = ctypes.CFUNCTYPE(ctypes.c_char) |
|
if sys.hexversion < 0x30c00b3: |
|
x['CFunctionType'] = _cfunc(str) |
|
del z |
|
|
|
a['MethodCallerType'] = operator.methodcaller('mro') |
|
|
|
x['MemoryType'] = memoryview(_in) |
|
x['MemoryType2'] = memoryview(bytearray(_in)) |
|
d['DictItemsType'] = _dict.items() |
|
d['DictKeysType'] = _dict.keys() |
|
d['DictValuesType'] = _dict.values() |
|
|
|
a['RawTextHelpFormatterType'] = argparse.RawTextHelpFormatter('PROG') |
|
a['RawDescriptionHelpFormatterType'] = argparse.RawDescriptionHelpFormatter('PROG') |
|
a['ArgDefaultsHelpFormatterType'] = argparse.ArgumentDefaultsHelpFormatter('PROG') |
|
z = a if IS_PYPY else x |
|
z['CmpKeyType'] = _cmpkey = functools.cmp_to_key(_methodwrap) |
|
z['CmpKeyObjType'] = _cmpkey('0') |
|
del z |
|
|
|
x['BufferType'] = x['MemoryType'] |
|
|
|
from dill._dill import _testcapsule |
|
if _testcapsule is not None: |
|
d['PyCapsuleType'] = _testcapsule |
|
del _testcapsule |
|
|
|
if hasattr(dataclasses, '_HAS_DEFAULT_FACTORY'): |
|
a['DataclassesHasDefaultFactoryType'] = dataclasses._HAS_DEFAULT_FACTORY |
|
|
|
if hasattr(dataclasses, 'MISSING'): |
|
a['DataclassesMissingType'] = dataclasses.MISSING |
|
|
|
if hasattr(dataclasses, 'KW_ONLY'): |
|
a['DataclassesKWOnlyType'] = dataclasses.KW_ONLY |
|
|
|
if hasattr(dataclasses, '_FIELD_BASE'): |
|
a['DataclassesFieldBaseType'] = dataclasses._FIELD |
|
|
|
|
|
a.update(d) |
|
if sys.platform[:3] == 'win': |
|
os.close(_filedescrip) |
|
os.remove(_tempfile) |
|
|
|
|
|
|
|
|