Begin incorporating Python unit tests into build

We now build a separate APE binary for each test so they can run in
parallel. We've got 148 tests running fast and stable so far.
This commit is contained in:
Justine Tunney 2021-09-12 21:04:44 -07:00
parent 51904e2687
commit b5f743cdc3
121 changed files with 4995 additions and 4767 deletions

View file

@ -16,6 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/bits/weaken.h"
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/calls/sigbits.h" #include "libc/calls/sigbits.h"
#include "libc/calls/struct/sigaction.h" #include "libc/calls/struct/sigaction.h"
@ -187,11 +188,16 @@ relegated static void ShowMemoryMappings(int outfd) {
} }
} }
void ShowCrashReportHook(int, int, int, struct siginfo *, ucontext_t *);
relegated static void ShowCrashReport(int err, int fd, int sig, relegated static void ShowCrashReport(int err, int fd, int sig,
struct siginfo *si, ucontext_t *ctx) { struct siginfo *si, ucontext_t *ctx) {
int i; int i;
char hostname[64]; char hostname[64];
struct utsname names; struct utsname names;
if (weaken(ShowCrashReportHook)) {
ShowCrashReportHook(err, fd, sig, si, ctx);
}
strcpy(hostname, "unknown"); strcpy(hostname, "unknown");
gethostname(hostname, sizeof(hostname)); gethostname(hostname, sizeof(hostname));
dprintf(fd, dprintf(fd,

View file

@ -24,12 +24,11 @@ noasan unsigned FindMemoryInterval(const struct MemoryIntervals *mm, int x) {
r = mm->i; r = mm->i;
while (l < r) { while (l < r) {
m = (l + r) >> 1; m = (l + r) >> 1;
if (mm->p[m].x < x) { if (mm->p[m].y < x) {
l = m + 1; l = m + 1;
} else { } else {
r = m; r = m;
} }
} }
if (l && mm->p[l - 1].y >= x) --l;
return l; return l;
} }

View file

@ -1,7 +1,6 @@
#ifndef COSMOPOLITAN_THIRD_PARTY_PYTHON_INCLUDE_PYTHON_AST_H_ #ifndef COSMOPOLITAN_THIRD_PARTY_PYTHON_INCLUDE_PYTHON_AST_H_
#define COSMOPOLITAN_THIRD_PARTY_PYTHON_INCLUDE_PYTHON_AST_H_ #define COSMOPOLITAN_THIRD_PARTY_PYTHON_INCLUDE_PYTHON_AST_H_
#include "third_party/python/Include/asdl.h" #include "third_party/python/Include/asdl.h"
#include "third_party/python/Include/object.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0) #if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_ COSMOPOLITAN_C_START_
/* clang-format off */ /* clang-format off */

View file

@ -84,5 +84,9 @@ void PyGrammar_RemoveAccelerators(grammar *);
void printgrammar(grammar *g, FILE *fp); void printgrammar(grammar *g, FILE *fp);
void printnonterminals(grammar *g, FILE *fp); void printnonterminals(grammar *g, FILE *fp);
#ifndef Py_LIMITED_API
extern grammar _PyParser_Grammar;
#endif
COSMOPOLITAN_C_END_ COSMOPOLITAN_C_END_
#endif /* !Py_GRAMMAR_H */ #endif /* !Py_GRAMMAR_H */

View file

@ -77,6 +77,9 @@ const char * _Py_gitversion(void);
/* Internal -- various one-time initializations */ /* Internal -- various one-time initializations */
#ifndef Py_LIMITED_API #ifndef Py_LIMITED_API
extern int _Py_initialized;
extern char *_Py_StandardStreamEncoding;
extern char *_Py_StandardStreamErrors;
PyObject * _PyBuiltin_Init(void); PyObject * _PyBuiltin_Init(void);
PyObject * _PySys_Init(void); PyObject * _PySys_Init(void);
void _PyImport_Init(void); void _PyImport_Init(void);
@ -86,6 +89,18 @@ int _PyFrame_Init(void);
int _PyFloat_Init(void); int _PyFloat_Init(void);
int PyByteArray_Init(void); int PyByteArray_Init(void);
void _PyRandom_Init(void); void _PyRandom_Init(void);
void _Py_InitSite(void);
int _Py_InitStdio(void);
void _Py_ReadyTypes(void);
void _Py_InitImport(PyInterpreterState *, PyObject *);
int _Py_InitFsEncoding(PyInterpreterState *);
void _Py_InitSigs(void);
void _Py_InitMain(PyInterpreterState *);
int _PyUnicode_Init(void);
int _PyStructSequence_Init(void);
int _PyLong_Init(void);
int _PyFaulthandler_Init(void);
int _PyTraceMalloc_Init(void);
#endif #endif
/* Various internal finalizers */ /* Various internal finalizers */
@ -109,7 +124,15 @@ void PySlice_Fini(void);
void _PyType_Fini(void); void _PyType_Fini(void);
void _PyRandom_Fini(void); void _PyRandom_Fini(void);
void PyAsyncGen_Fini(void); void PyAsyncGen_Fini(void);
int _Py_FlushStdFiles(void);
void _Py_CallExitFuncs(void);
void _Py_CallLlExitFuncs(void);
void _PyFaulthandler_Fini(void);
void _PyHash_Fini(void);
void PyLong_Fini(void);
void _PyUnicode_Fini(void);
int _PyTraceMalloc_Fini(void);
void _PyMem_DumpTraceback(int, const void *);
extern PyThreadState * _Py_Finalizing; extern PyThreadState * _Py_Finalizing;
#endif #endif

View file

@ -63,7 +63,8 @@ int _PyTraceMalloc_Untrack(
PyObject* _PyTraceMalloc_GetTraceback( PyObject* _PyTraceMalloc_GetTraceback(
_PyTraceMalloc_domain_t domain, _PyTraceMalloc_domain_t domain,
uintptr_t ptr); uintptr_t ptr);
#ifndef MODE_DBG
#ifdef USE_TRACEMALLOC
#define _PyTraceMalloc_Track(domain, ptr, size) (-2) #define _PyTraceMalloc_Track(domain, ptr, size) (-2)
#define _PyTraceMalloc_Untrack(domain, ptr) (-2) #define _PyTraceMalloc_Untrack(domain, ptr) (-2)
#define _PyTraceMalloc_GetTraceback(domain, ptr) (&_Py_NoneStruct) #define _PyTraceMalloc_GetTraceback(domain, ptr) (&_Py_NoneStruct)

View file

@ -19,33 +19,7 @@ else:
_setmode = None _setmode = None
import io import io
from io import (SEEK_SET, SEEK_CUR, SEEK_END) from io import (__all__, SEEK_SET, SEEK_CUR, SEEK_END)
__all__ = [
'BlockingIOError',
'BufferedIOBase',
'BufferedRWPair',
'BufferedRandom',
'BufferedReader',
'BufferedWriter',
'BytesIO',
'DEFAULT_BUFFER_SIZE',
'FileIO',
'IOBase',
'IncrementalNewlineDecoder',
'OpenWrapper',
'RawIOBase',
'SEEK_CUR',
'SEEK_END',
'SEEK_SET',
'StringIO',
'TextIOBase',
'TextIOWrapper',
'UnsupportedOperation',
'_io',
'abc',
'open',
]
valid_seek_flags = {0, 1, 2} # Hardwired values valid_seek_flags = {0, 1, 2} # Hardwired values
if hasattr(os, 'SEEK_HOLE') : if hasattr(os, 'SEEK_HOLE') :

View file

@ -90,3 +90,6 @@ try:
from _bisect import * from _bisect import *
except ImportError: except ImportError:
pass pass
if __name__ == 'PYOBJ.COM':
import _bisect

View file

@ -255,7 +255,10 @@ class Cmd:
Otherwise try to call complete_<command> to get list of completions. Otherwise try to call complete_<command> to get list of completions.
""" """
if state == 0: if state == 0:
import readline try:
import readline
except ImportError:
return None
origline = readline.get_line_buffer() origline = readline.get_line_buffer()
line = origline.lstrip() line = origline.lstrip()
stripped = len(origline) - len(line) stripped = len(origline) - len(line)

View file

@ -15,21 +15,13 @@ list, set, and tuple.
''' '''
__all__ = ['deque', 'defaultdict', 'namedtuple', 'UserDict', 'UserList', __all__ = ['deque', 'defaultdict', 'namedtuple', 'UserDict', 'UserList',
'UserString', 'Counter', 'OrderedDict', 'ChainMap', 'UserString', 'Counter', 'OrderedDict', 'ChainMap']
'Awaitable', 'Coroutine',
'AsyncIterable', 'AsyncIterator', 'AsyncGenerator',
'Hashable', 'Iterable', 'Iterator', 'Generator', 'Reversible',
'Sized', 'Container', 'Callable', 'Collection',
'Set', 'MutableSet',
'Mapping', 'MutableMapping',
'MappingView', 'KeysView', 'ItemsView', 'ValuesView',
'Sequence', 'MutableSequence',
'ByteString']
# For backwards compatibility, continue to make the collections ABCs # For backwards compatibility, continue to make the collections ABCs
# available through the collections module. # available through the collections module.
from _collections_abc import ABCMeta, AsyncGenerator, AsyncIterable, AsyncIterator, Awaitable, ByteString, Callable, Collection, Container, Coroutine, Generator, Hashable, ItemsView, Iterable, Iterator, KeysView, Mapping, MappingView, MutableMapping, MutableSequence, MutableSet, Reversible, Sequence, Set, Sized, ValuesView, _check_methods, abstractmethod, async_generator, bytearray_iterator, bytes_iterator, coroutine, dict_itemiterator, dict_items, dict_keyiterator, dict_keys, dict_valueiterator, dict_values, generator, list_iterator, list_reverseiterator, longrange_iterator, mappingproxy, range_iterator, set_iterator, str_iterator, sys, tuple_iterator, zip_iterator from _collections_abc import *
import _collections_abc import _collections_abc
__all__ += _collections_abc.__all__
from operator import itemgetter as _itemgetter, eq as _eq from operator import itemgetter as _itemgetter, eq as _eq
from keyword import iskeyword as _iskeyword from keyword import iskeyword as _iskeyword
@ -39,11 +31,17 @@ from _weakref import proxy as _proxy
from itertools import repeat as _repeat, chain as _chain, starmap as _starmap from itertools import repeat as _repeat, chain as _chain, starmap as _starmap
from reprlib import recursive_repr as _recursive_repr from reprlib import recursive_repr as _recursive_repr
from _collections import deque try:
MutableSequence.register(deque) from _collections import deque
except ImportError:
from _collections import defaultdict pass
else:
MutableSequence.register(deque)
try:
from _collections import defaultdict
except ImportError:
pass
################################################################################ ################################################################################
### OrderedDict ### OrderedDict
@ -1243,3 +1241,84 @@ class UserString(Sequence):
return self.__class__(self.data.translate(*args)) return self.__class__(self.data.translate(*args))
def upper(self): return self.__class__(self.data.upper()) def upper(self): return self.__class__(self.data.upper())
def zfill(self, width): return self.__class__(self.data.zfill(width)) def zfill(self, width): return self.__class__(self.data.zfill(width))
if __name__ == 'PYOBJ.COM':
import _collections
ABCMeta = 0
AsyncGenerator = 0
AsyncIterable = 0
AsyncIterator = 0
Awaitable = 0
ByteString = 0
Callable = 0
ChainMap = 0
Collection = 0
Container = 0
Coroutine = 0
Counter = 0
Generator = 0
Hashable = 0
ItemsView = 0
Iterable = 0
Iterator = 0
KeysView = 0
Mapping = 0
MappingView = 0
MutableMapping = 0
MutableSequence = 0
MutableSet = 0
OrderedDict = 0
Reversible = 0
Sequence = 0
Set = 0
Sized = 0
UserDict = 0
UserList = 0
UserString = 0
ValuesView = 0
_Link = 0
_OrderedDictItemsView = 0
_OrderedDictKeysView = 0
_OrderedDictValuesView = 0
_chain = 0
_check_methods = 0
_class_template = 0
_collections_abc = 0
_count_elements = 0
_eq = 0
_field_template = 0
_heapq = 0
_iskeyword = 0
_itemgetter = 0
_proxy = 0
_recursive_repr = 0
_repeat = 0
_repr_template = 0
_starmap = 0
_sys = 0
abstractmethod = 0
async_generator = 0
bytearray_iterator = 0
bytes_iterator = 0
coroutine = 0
defaultdict = 0
deque = 0
dict_itemiterator = 0
dict_items = 0
dict_keyiterator = 0
dict_keys = 0
dict_valueiterator = 0
dict_values = 0
generator = 0
list_iterator = 0
list_reverseiterator = 0
longrange_iterator = 0
mappingproxy = 0
namedtuple = 0
range_iterator = 0
set_iterator = 0
str_iterator = 0
sys = 0
tuple_iterator = 0
zip_iterator = 0

View file

@ -1,27 +1,29 @@
from _collections_abc import ( from _collections_abc import *
Awaitable, from _collections_abc import __all__
Coroutine,
AsyncIterable, if __name__ == 'PYOBJ.COM':
AsyncIterator, AsyncGenerator = 0
AsyncGenerator, AsyncIterable = 0
Hashable, AsyncIterator = 0
Iterable, Awaitable = 0
Iterator, ByteString = 0
Generator, Callable = 0
Reversible, Collection = 0
Sized, Container = 0
Container, Coroutine = 0
Callable, Generator = 0
Collection, Hashable = 0
Set, ItemsView = 0
MutableSet, Iterable = 0
Mapping, Iterator = 0
MutableMapping, KeysView = 0
MappingView, Mapping = 0
KeysView, MappingView = 0
ItemsView, MutableMapping = 0
ValuesView, MutableSequence = 0
Sequence, MutableSet = 0
MutableSequence, Reversible = 0
ByteString, Sequence = 0
) Set = 0
Sized = 0
ValuesView = 0

View file

@ -1,10 +1,51 @@
# try: try:
from _decimal import BasicContext, Clamped, Context, ConversionSyntax, Decimal, DecimalException, DecimalTuple, DefaultContext, DivisionByZero, DivisionImpossible, DivisionUndefined, ExtendedContext, FloatOperation, HAVE_THREADS, Inexact, InvalidContext, InvalidOperation, MAX_EMAX, MAX_PREC, MIN_EMIN, MIN_ETINY, Overflow, ROUND_05UP, ROUND_CEILING, ROUND_DOWN, ROUND_FLOOR, ROUND_HALF_DOWN, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_UP, Rounded, Subnormal, Underflow, getcontext, localcontext, setcontext from _decimal import *
from _decimal import __doc__ from _decimal import __doc__
from _decimal import __version__ from _decimal import __version__
from _decimal import __libmpdec_version__ from _decimal import __libmpdec_version__
# except ImportError: except ImportError:
# from _pydecimal import * from _pydecimal import *
# from _pydecimal import __doc__ from _pydecimal import __doc__
# from _pydecimal import __version__ from _pydecimal import __version__
# from _pydecimal import __libmpdec_version__ from _pydecimal import __libmpdec_version__
if __name__ == 'PYOBJ.COM':
import _decimal
BasicContext = 0
Clamped = 0
Context = 0
ConversionSyntax = 0
Decimal = 0
DecimalException = 0
DecimalTuple = 0
DefaultContext = 0
DivisionByZero = 0
DivisionImpossible = 0
DivisionUndefined = 0
ExtendedContext = 0
FloatOperation = 0
HAVE_THREADS = 0
Inexact = 0
InvalidContext = 0
InvalidOperation = 0
MAX_EMAX = 0
MAX_PREC = 0
MIN_EMIN = 0
MIN_ETINY = 0
Overflow = 0
ROUND_05UP = 0
ROUND_CEILING = 0
ROUND_DOWN = 0
ROUND_FLOOR = 0
ROUND_HALF_DOWN = 0
ROUND_HALF_EVEN = 0
ROUND_HALF_UP = 0
ROUND_UP = 0
Rounded = 0
Subnormal = 0
Underflow = 0
__libmpdec_version__ = 0
__version__ = 0
getcontext = 0
localcontext = 0
setcontext = 0

View file

@ -77,26 +77,28 @@ finally:
del _dummy_thread del _dummy_thread
del sys_modules del sys_modules
Barrier = Barrier if __name__ == 'PYOBJ.COM':
BoundedSemaphore = BoundedSemaphore Barrier = 0
BrokenBarrierError = BrokenBarrierError BoundedSemaphore = 0
Condition = Condition BrokenBarrierError = 0
Event = Event Condition = 0
Lock = Lock Event = 0
RLock = RLock Lock = 0
Semaphore = Semaphore RLock = 0
TIMEOUT_MAX = TIMEOUT_MAX Semaphore = 0
Thread = Thread TIMEOUT_MAX = 0
ThreadError = ThreadError Thread = 0
Timer = Timer ThreadError = 0
WeakSet = WeakSet Timer = 0
activeCount = activeCount WeakSet = 0
active_count = active_count activeCount = 0
currentThread = currentThread active_count = 0
current_thread = current_thread currentThread = 0
get_ident = get_ident current_thread = 0
local = local enumerate = 0
main_thread = main_thread get_ident = 0
setprofile = setprofile local = 0
settrace = settrace main_thread = 0
stack_size = stack_size setprofile = 0
settrace = 0
stack_size = 0

View file

@ -36,6 +36,7 @@ __all__ = [
from base64 import b64encode from base64 import b64encode
from binascii import b2a_base64, a2b_base64 from binascii import b2a_base64, a2b_base64
from encodings import raw_unicode_escape
CRLF = '\r\n' CRLF = '\r\n'
NL = '\n' NL = '\n'

View file

@ -17,6 +17,29 @@ import email.quoprimime
from email import errors from email import errors
from email.encoders import encode_7or8bit from email.encoders import encode_7or8bit
from encodings import (
base64_codec,
quopri_codec,
iso8859_1,
iso8859_2,
iso8859_3,
iso8859_4,
iso8859_9,
iso8859_10,
iso8859_13,
iso8859_14,
iso8859_15,
iso8859_16,
iso8859_10,
cp1252,
big5,
gb2312,
euc_jp,
shift_jis,
iso2022_jp,
koi8_r,
utf_8,
)
# Flags for types of header encodings # Flags for types of header encodings

View file

@ -11,13 +11,18 @@ import uu
import quopri import quopri
from io import BytesIO, StringIO from io import BytesIO, StringIO
from encodings import (
base64_codec,
quopri_codec,
raw_unicode_escape,
)
# Intrapackage imports # Intrapackage imports
from email import utils from email import utils
from email import errors from email import errors
from email._policybase import Policy, compat32 from email._policybase import Policy, compat32
from email import charset as _charset from email import charset as _charset
from email._encoded_words import decode_b from email._encoded_words import decode_b
from email.iterators import walk
Charset = _charset.Charset Charset = _charset.Charset
SEMISPACE = '; ' SEMISPACE = '; '
@ -940,6 +945,7 @@ class Message:
return c_d return c_d
# I.e. def walk(self): ... # I.e. def walk(self): ...
from email.iterators import walk
class MIMEPart(Message): class MIMEPart(Message):

View file

@ -814,3 +814,7 @@ def singledispatch(func):
wrapper._clear_cache = dispatch_cache.clear wrapper._clear_cache = dispatch_cache.clear
update_wrapper(wrapper, func) update_wrapper(wrapper, func)
return wrapper return wrapper
if __name__ == 'PYOBJ.COM':
import _functools

View file

@ -11,7 +11,10 @@ new(name, data=b'', **kwargs) - returns a new hash object implementing the
Named constructor functions are also available, these are faster Named constructor functions are also available, these are faster
than using new(name): than using new(name):
md5(), sha1(), sha224(), sha256(), sha384(), sha512(), and blake2b256(). md5(), sha1(), sha224(), sha256(), sha384(), sha512(), sha3_224(),
sha3_256(), sha3_384(), sha3_512(), shake_128(), shake_256(), and
finally blake2b256() which is an Actually Portable Python feature
courtesy of the BoringSSL project at Google, and we thank ARM too
More algorithms may be available on your platform but the above are guaranteed More algorithms may be available on your platform but the above are guaranteed
to exist. See the algorithms_guaranteed and algorithms_available attributes to exist. See the algorithms_guaranteed and algorithms_available attributes
@ -52,10 +55,22 @@ More condensed:
""" """
# import _hashlib as _prevent_recursive_loading
# del _prevent_recursive_loading
# if __name__ == 'PYOBJ.COM': import _sha3, _hashlib # static-only
if __name__ == 'PYOBJ.COM':
import _md5
import _sha1
import _sha256
import _sha512
# This tuple and __get_builtin_constructor() must be modified if a new # This tuple and __get_builtin_constructor() must be modified if a new
# always available algorithm is added. # always available algorithm is added.
__always_supported = ('md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512', __always_supported = ('md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512',
'blake2b256') # 'sha3_224', 'sha3_256', 'sha3_384',
# 'sha3_512', 'shake_128', 'shake_256'
)
algorithms_guaranteed = set(__always_supported) algorithms_guaranteed = set(__always_supported)
algorithms_available = set(__always_supported) algorithms_available = set(__always_supported)
@ -70,12 +85,23 @@ def __get_builtin_constructor(name):
constructor = cache.get(name) constructor = cache.get(name)
if constructor is not None: if constructor is not None:
return constructor return constructor
if name in ('MD5', 'md5'): try:
import _md5 if name in ('SHA1', 'sha1'):
cache['MD5'] = cache['md5'] = _md5.md5 import _sha1
elif name in {'sha3_224', 'sha3_256', 'sha3_384', 'sha3_512', cache['SHA1'] = cache['sha1'] = _sha1.sha1
'shake_128', 'shake_256'}: elif name in ('MD5', 'md5'):
try: import _md5
cache['MD5'] = cache['md5'] = _md5.md5
elif name in ('SHA256', 'sha256', 'SHA224', 'sha224'):
import _sha256
cache['SHA224'] = cache['sha224'] = _sha256.sha224
cache['SHA256'] = cache['sha256'] = _sha256.sha256
elif name in ('SHA512', 'sha512', 'SHA384', 'sha384'):
import _sha512
cache['SHA384'] = cache['sha384'] = _sha512.sha384
cache['SHA512'] = cache['sha512'] = _sha512.sha512
elif name in {'sha3_224', 'sha3_256', 'sha3_384', 'sha3_512',
'shake_128', 'shake_256'}:
import _sha3 import _sha3
cache['sha3_224'] = _sha3.sha3_224 cache['sha3_224'] = _sha3.sha3_224
cache['sha3_256'] = _sha3.sha3_256 cache['sha3_256'] = _sha3.sha3_256
@ -83,11 +109,13 @@ def __get_builtin_constructor(name):
cache['sha3_512'] = _sha3.sha3_512 cache['sha3_512'] = _sha3.sha3_512
cache['shake_128'] = _sha3.shake_128 cache['shake_128'] = _sha3.shake_128
cache['shake_256'] = _sha3.shake_256 cache['shake_256'] = _sha3.shake_256
except ImportError: except ImportError:
raise ValueError('unsupported hash type ' + name) pass # no extension module, this hash is unsupported.
constructor = cache.get(name) constructor = cache.get(name)
if constructor is not None: if constructor is not None:
return constructor return constructor
raise ValueError('unsupported hash type ' + name) raise ValueError('unsupported hash type ' + name)
@ -125,11 +153,15 @@ def __hash_new(name, data=b'', **kwargs):
return __get_builtin_constructor(name)(data) return __get_builtin_constructor(name)(data)
import _hashlib try:
new = __hash_new import _hashlib
__get_hash = __get_mbedtls_constructor new = __hash_new
algorithms_available = algorithms_available.union( __get_hash = __get_mbedtls_constructor
_hashlib.mbedtls_md_meth_names) algorithms_available = algorithms_available.union(
_hashlib.mbedtls_md_meth_names)
except ImportError as e:
new = __py_new
__get_hash = __get_builtin_constructor
try: try:
# Mbedtls's PKCS5_PBKDF2_HMAC requires Mbedtls 1.0+ with HMAC and SHA # Mbedtls's PKCS5_PBKDF2_HMAC requires Mbedtls 1.0+ with HMAC and SHA
@ -201,13 +233,20 @@ try:
except ImportError: except ImportError:
pass pass
md5 = __get_hash('md5') md5 = __get_hash('md5')
sha1 = __get_hash('sha1') sha1 = __get_hash('sha1')
sha224 = __get_hash('sha224') sha224 = __get_hash('sha224')
sha256 = __get_hash('sha256') sha256 = __get_hash('sha256')
sha384 = __get_hash('sha384') sha384 = __get_hash('sha384')
sha512 = __get_hash('sha512') sha512 = __get_hash('sha512')
blake2b256 = __get_hash('blake2b256') # sha3_224 = __get_hash('sha3_224')
# sha3_256 = __get_hash('sha3_256')
# sha3_384 = __get_hash('sha3_384')
# sha3_512 = __get_hash('sha3_512')
# shake_128 = __get_hash('shake_128')
# shake_256 = __get_hash('shake_256')
# Cleanup locals() # Cleanup locals()
del __always_supported, __get_hash del __always_supported, __get_hash

View file

@ -1 +1,9 @@
print("hello world") import hashlib
# import sys
# import urllib.request
# with urllib.request.urlopen("http://justine.lol") as resp:
# sys.stdout.buffer.write(resp.read())
# print("hello world")

View file

@ -7,6 +7,8 @@ try:
from _json import scanstring as c_scanstring from _json import scanstring as c_scanstring
except ImportError: except ImportError:
c_scanstring = None c_scanstring = None
if __name__ == 'PYOBJ.COM':
import _json
__all__ = ['JSONDecoder', 'JSONDecodeError'] __all__ = ['JSONDecoder', 'JSONDecodeError']

View file

@ -14,6 +14,8 @@ try:
from _json import make_encoder as c_make_encoder from _json import make_encoder as c_make_encoder
except ImportError: except ImportError:
c_make_encoder = None c_make_encoder = None
if __name__ == 'PYOBJ.COM':
import _json
ESCAPE = re.compile(r'[\x00-\x1f\\"\b\f\n\r\t]') ESCAPE = re.compile(r'[\x00-\x1f\\"\b\f\n\r\t]')
ESCAPE_ASCII = re.compile(r'([\\"]|[^\ -~])') ESCAPE_ASCII = re.compile(r'([\\"]|[^\ -~])')

View file

@ -5,6 +5,8 @@ try:
from _json import make_scanner as c_make_scanner from _json import make_scanner as c_make_scanner
except ImportError: except ImportError:
c_make_scanner = None c_make_scanner = None
if __name__ == 'PYOBJ.COM':
import _json
__all__ = ['make_scanner'] __all__ = ['make_scanner']

View file

@ -7,7 +7,7 @@ def run_module_as_main(mod_name):
code = loader.get_code(mod_name) code = loader.get_code(mod_name)
globs = sys.modules["__main__"].__dict__ globs = sys.modules["__main__"].__dict__
globs["__name__"] = "__main__" globs["__name__"] = "__main__"
globs["__file__"] = path globs["__file__"] = path[:-1]
globs["__package__"] = None globs["__package__"] = None
globs["__loader__"] = loader globs["__loader__"] = loader
globs["__spec__"] = None globs["__spec__"] = None

View file

@ -40,6 +40,7 @@ __all__ = [
] ]
knownfiles = [ knownfiles = [
"/zip/.python/mime.types",
"/etc/mime.types", "/etc/mime.types",
"/etc/httpd/mime.types", # Mac OS X "/etc/httpd/mime.types", # Mac OS X
"/etc/httpd/conf/mime.types", # Apache "/etc/httpd/conf/mime.types", # Apache

View file

@ -415,6 +415,9 @@ except ImportError:
else: else:
from _operator import __doc__ from _operator import __doc__
if __name__ == 'PYOBJ.COM':
import _operator
# All of these "__func__ = func" assignments have to happen after importing # All of these "__func__ = func" assignments have to happen after importing
# from _operator to make sure they're set to the right function # from _operator to make sure they're set to the right function
__lt__ = lt __lt__ = lt

View file

@ -43,235 +43,20 @@ def _get_exports_list(module):
except AttributeError: except AttributeError:
return [n for n in dir(module) if n[0] != '_'] return [n for n in dir(module) if n[0] != '_']
# Any new dependencies of the os module and/or changes in path separator
# requires updating importlib as well.
name = 'posix' name = 'posix'
linesep = '\n' linesep = '\n'
from posix import *
try:
from posix import _exit
__all__.append('_exit')
except ImportError:
pass
import posixpath as path import posixpath as path
try:
from posix import _have_functions
except ImportError:
pass
import posix import posix
CLD_CONTINUED = posix.CLD_CONTINUED
CLD_DUMPED = posix.CLD_DUMPED
CLD_EXITED = posix.CLD_EXITED
CLD_TRAPPED = posix.CLD_TRAPPED
DirEntry = posix.DirEntry
EX_CANTCREAT = posix.EX_CANTCREAT
EX_CONFIG = posix.EX_CONFIG
EX_DATAERR = posix.EX_DATAERR
EX_IOERR = posix.EX_IOERR
EX_NOHOST = posix.EX_NOHOST
EX_NOINPUT = posix.EX_NOINPUT
EX_NOPERM = posix.EX_NOPERM
EX_NOUSER = posix.EX_NOUSER
EX_OK = posix.EX_OK
EX_OSERR = posix.EX_OSERR
EX_OSFILE = posix.EX_OSFILE
EX_PROTOCOL = posix.EX_PROTOCOL
EX_SOFTWARE = posix.EX_SOFTWARE
EX_TEMPFAIL = posix.EX_TEMPFAIL
EX_UNAVAILABLE = posix.EX_UNAVAILABLE
EX_USAGE = posix.EX_USAGE
F_LOCK = posix.F_LOCK
F_OK = posix.F_OK
F_TEST = posix.F_TEST
F_TLOCK = posix.F_TLOCK
F_ULOCK = posix.F_ULOCK
GRND_NONBLOCK = posix.GRND_NONBLOCK
GRND_NORDRND = posix.GRND_NORDRND
GRND_NOSYSTEM = posix.GRND_NOSYSTEM
GRND_RANDOM = posix.GRND_RANDOM
O_ACCMODE = posix.O_ACCMODE
O_APPEND = posix.O_APPEND
O_ASYNC = posix.O_ASYNC
O_CLOEXEC = posix.O_CLOEXEC
O_CREAT = posix.O_CREAT
O_DIRECT = posix.O_DIRECT
O_DIRECTORY = posix.O_DIRECTORY
O_DSYNC = posix.O_DSYNC
O_EXCL = posix.O_EXCL
O_LARGEFILE = posix.O_LARGEFILE
O_NDELAY = posix.O_NDELAY
O_NOATIME = posix.O_NOATIME
O_NOCTTY = posix.O_NOCTTY
O_NOFOLLOW = posix.O_NOFOLLOW
O_NONBLOCK = posix.O_NONBLOCK
O_PATH = posix.O_PATH
O_RDONLY = posix.O_RDONLY
O_RDWR = posix.O_RDWR
O_RSYNC = posix.O_RSYNC
O_SYNC = posix.O_SYNC
O_TMPFILE = posix.O_TMPFILE
O_TRUNC = posix.O_TRUNC
O_WRONLY = posix.O_WRONLY
POSIX_FADV_DONTNEED = posix.POSIX_FADV_DONTNEED
POSIX_FADV_NOREUSE = posix.POSIX_FADV_NOREUSE
POSIX_FADV_NORMAL = posix.POSIX_FADV_NORMAL
POSIX_FADV_RANDOM = posix.POSIX_FADV_RANDOM
POSIX_FADV_SEQUENTIAL = posix.POSIX_FADV_SEQUENTIAL
POSIX_FADV_WILLNEED = posix.POSIX_FADV_WILLNEED
PRIO_PGRP = posix.PRIO_PGRP
PRIO_PROCESS = posix.PRIO_PROCESS
PRIO_USER = posix.PRIO_USER
RTLD_GLOBAL = posix.RTLD_GLOBAL
RTLD_LAZY = posix.RTLD_LAZY
RTLD_LOCAL = posix.RTLD_LOCAL
RTLD_NOW = posix.RTLD_NOW
R_OK = posix.R_OK
SCHED_BATCH = posix.SCHED_BATCH
SCHED_FIFO = posix.SCHED_FIFO
SCHED_IDLE = posix.SCHED_IDLE
SCHED_OTHER = posix.SCHED_OTHER
SCHED_RESET_ON_FORK = posix.SCHED_RESET_ON_FORK
SCHED_RR = posix.SCHED_RR
ST_APPEND = posix.ST_APPEND
ST_MANDLOCK = posix.ST_MANDLOCK
ST_NOATIME = posix.ST_NOATIME
ST_NODEV = posix.ST_NODEV
ST_NODIRATIME = posix.ST_NODIRATIME
ST_NOEXEC = posix.ST_NOEXEC
ST_NOSUID = posix.ST_NOSUID
ST_RDONLY = posix.ST_RDONLY
ST_RELATIME = posix.ST_RELATIME
ST_SYNCHRONOUS = posix.ST_SYNCHRONOUS
ST_WRITE = posix.ST_WRITE
WCONTINUED = posix.WCONTINUED
WCOREDUMP = posix.WCOREDUMP
WEXITED = posix.WEXITED
WEXITSTATUS = posix.WEXITSTATUS
WIFCONTINUED = posix.WIFCONTINUED
WIFEXITED = posix.WIFEXITED
WIFSIGNALED = posix.WIFSIGNALED
WIFSTOPPED = posix.WIFSTOPPED
WNOHANG = posix.WNOHANG
WNOWAIT = posix.WNOWAIT
WSTOPPED = posix.WSTOPPED
WSTOPSIG = posix.WSTOPSIG
WTERMSIG = posix.WTERMSIG
WUNTRACED = posix.WUNTRACED
W_OK = posix.W_OK
X_OK = posix.X_OK
_exit = posix._exit
_have_functions = posix._have_functions
abort = posix.abort
access = posix.access
chdir = posix.chdir
chmod = posix.chmod
chown = posix.chown
chroot = posix.chroot
close = posix.close
closerange = posix.closerange
cpu_count = posix.cpu_count
device_encoding = posix.device_encoding
dup = posix.dup
dup2 = posix.dup2
environ = posix.environ
error = posix.error
execv = posix.execv
execve = posix.execve
fchdir = posix.fchdir
fchmod = posix.fchmod
fchown = posix.fchown
fdatasync = posix.fdatasync
fork = posix.fork
fpathconf = posix.fpathconf
fspath = posix.fspath
fstat = posix.fstat
fsync = posix.fsync
ftruncate = posix.ftruncate
get_blocking = posix.get_blocking
get_inheritable = posix.get_inheritable
get_terminal_size = posix.get_terminal_size
getcwd = posix.getcwd
getcwdb = posix.getcwdb
getgrouplist = posix.getgrouplist
getgroups = posix.getgroups
getlogin = posix.getlogin
getpgid = posix.getpgid
getpgrp = posix.getpgrp
getpid = posix.getpid
getpriority = posix.getpriority
getsid = posix.getsid
getuid = posix.getuid
initgroups = posix.initgroups
isatty = posix.isatty
kill = posix.kill
killpg = posix.killpg
lchown = posix.lchown
link = posix.link
listdir = posix.listdir
lseek = posix.lseek
lstat = posix.lstat
major = posix.major
makedev = posix.makedev
minor = posix.minor
mkdir = posix.mkdir
mkfifo = posix.mkfifo
mknod = posix.mknod
nice = posix.nice
open = posix.open
openpty = posix.openpty
pathconf = posix.pathconf
pathconf_names = posix.pathconf_names
pipe = posix.pipe
pipe2 = posix.pipe2
posix_fadvise = posix.posix_fadvise
pread = posix.pread
putenv = posix.putenv
pwrite = posix.pwrite
read = posix.read
readlink = posix.readlink
readv = posix.readv
remove = posix.remove
rename = posix.rename
replace = posix.replace
rmdir = posix.rmdir
scandir = posix.scandir
sched_yield = posix.sched_yield
sendfile = posix.sendfile
set_blocking = posix.set_blocking
set_inheritable = posix.set_inheritable
setegid = posix.setegid
seteuid = posix.seteuid
setgid = posix.setgid
setpgid = posix.setpgid
setpriority = posix.setpriority
setregid = posix.setregid
setresgid = posix.setresgid
setresuid = posix.setresuid
setreuid = posix.setreuid
setsid = posix.setsid
setuid = posix.setuid
stat = posix.stat
stat_float_times = posix.stat_float_times
stat_result = posix.stat_result
statvfs_result = posix.statvfs_result
strerror = posix.strerror
symlink = posix.symlink
sync = posix.sync
sysconf = posix.sysconf
sysconf_names = posix.sysconf_names
system = posix.system
tcgetpgrp = posix.tcgetpgrp
tcsetpgrp = posix.tcsetpgrp
terminal_size = posix.terminal_size
times = posix.times
times_result = posix.times_result
truncate = posix.truncate
umask = posix.umask
uname = posix.uname
uname_result = posix.uname_result
unlink = posix.unlink
unsetenv = posix.unsetenv
urandom = posix.urandom
utime = posix.utime
wait = posix.wait
wait3 = posix.wait3
wait4 = posix.wait4
waitpid = posix.waitpid
write = posix.write
writev = posix.writev
__all__.extend(_get_exports_list(posix)) __all__.extend(_get_exports_list(posix))
del posix del posix
@ -282,90 +67,93 @@ from os.path import (curdir, pardir, sep, pathsep, defpath, extsep, altsep,
del _names del _names
_globals = globals() if _exists("_have_functions"):
def _add(str, fn): _globals = globals()
if (fn in _globals) and (str in _have_functions): def _add(str, fn):
_set.add(_globals[fn]) if (fn in _globals) and (str in _have_functions):
_set.add(_globals[fn])
_set = set() _set = set()
_add("HAVE_FACCESSAT", "access") _add("HAVE_FACCESSAT", "access")
_add("HAVE_FCHMODAT", "chmod") _add("HAVE_FCHMODAT", "chmod")
_add("HAVE_FCHOWNAT", "chown") _add("HAVE_FCHOWNAT", "chown")
_add("HAVE_FSTATAT", "stat") _add("HAVE_FSTATAT", "stat")
_add("HAVE_FUTIMESAT", "utime") _add("HAVE_FUTIMESAT", "utime")
_add("HAVE_LINKAT", "link") _add("HAVE_LINKAT", "link")
_add("HAVE_MKDIRAT", "mkdir") _add("HAVE_MKDIRAT", "mkdir")
_add("HAVE_MKFIFOAT", "mkfifo") _add("HAVE_MKFIFOAT", "mkfifo")
_add("HAVE_MKNODAT", "mknod") _add("HAVE_MKNODAT", "mknod")
_add("HAVE_OPENAT", "open") _add("HAVE_OPENAT", "open")
_add("HAVE_READLINKAT", "readlink") _add("HAVE_READLINKAT", "readlink")
_add("HAVE_RENAMEAT", "rename") _add("HAVE_RENAMEAT", "rename")
_add("HAVE_SYMLINKAT", "symlink") _add("HAVE_SYMLINKAT", "symlink")
_add("HAVE_UNLINKAT", "unlink") _add("HAVE_UNLINKAT", "unlink")
_add("HAVE_UNLINKAT", "rmdir") _add("HAVE_UNLINKAT", "rmdir")
_add("HAVE_UTIMENSAT", "utime") _add("HAVE_UTIMENSAT", "utime")
supports_dir_fd = _set supports_dir_fd = _set
_set = set() _set = set()
_add("HAVE_FACCESSAT", "access") _add("HAVE_FACCESSAT", "access")
supports_effective_ids = _set supports_effective_ids = _set
_set = set() _set = set()
_add("HAVE_FCHDIR", "chdir") _add("HAVE_FCHDIR", "chdir")
_add("HAVE_FCHMOD", "chmod") _add("HAVE_FCHMOD", "chmod")
_add("HAVE_FCHOWN", "chown") if _exists("chown"):
_add("HAVE_FDOPENDIR", "listdir") _add("HAVE_FCHOWN", "chown")
_add("HAVE_FEXECVE", "execve") _add("HAVE_FDOPENDIR", "listdir")
_set.add(stat) # fstat always works _add("HAVE_FEXECVE", "execve")
_add("HAVE_FTRUNCATE", "truncate") _set.add(stat) # fstat always works
_add("HAVE_FUTIMENS", "utime") _add("HAVE_FTRUNCATE", "truncate")
_add("HAVE_FUTIMES", "utime") _add("HAVE_FUTIMENS", "utime")
_add("HAVE_FPATHCONF", "pathconf") _add("HAVE_FUTIMES", "utime")
if _exists("statvfs") and _exists("fstatvfs"): # mac os x10.3 _add("HAVE_FPATHCONF", "pathconf")
_add("HAVE_FSTATVFS", "statvfs") if _exists("statvfs") and _exists("fstatvfs"): # mac os x10.3
supports_fd = _set _add("HAVE_FSTATVFS", "statvfs")
supports_fd = _set
_set = set() _set = set()
_add("HAVE_FACCESSAT", "access") _add("HAVE_FACCESSAT", "access")
# Some platforms don't support lchmod(). Often the function exists # Some platforms don't support lchmod(). Often the function exists
# anyway, as a stub that always returns ENOSUP or perhaps EOPNOTSUPP. # anyway, as a stub that always returns ENOSUP or perhaps EOPNOTSUPP.
# (No, I don't know why that's a good design.) ./configure will detect # (No, I don't know why that's a good design.) ./configure will detect
# this and reject it--so HAVE_LCHMOD still won't be defined on such # this and reject it--so HAVE_LCHMOD still won't be defined on such
# platforms. This is Very Helpful. # platforms. This is Very Helpful.
# #
# However, sometimes platforms without a working lchmod() *do* have # However, sometimes platforms without a working lchmod() *do* have
# fchmodat(). (Examples: Linux kernel 3.2 with glibc 2.15, # fchmodat(). (Examples: Linux kernel 3.2 with glibc 2.15,
# OpenIndiana 3.x.) And fchmodat() has a flag that theoretically makes # OpenIndiana 3.x.) And fchmodat() has a flag that theoretically makes
# it behave like lchmod(). So in theory it would be a suitable # it behave like lchmod(). So in theory it would be a suitable
# replacement for lchmod(). But when lchmod() doesn't work, fchmodat()'s # replacement for lchmod(). But when lchmod() doesn't work, fchmodat()'s
# flag doesn't work *either*. Sadly ./configure isn't sophisticated # flag doesn't work *either*. Sadly ./configure isn't sophisticated
# enough to detect this condition--it only determines whether or not # enough to detect this condition--it only determines whether or not
# fchmodat() minimally works. # fchmodat() minimally works.
# #
# Therefore we simply ignore fchmodat() when deciding whether or not # Therefore we simply ignore fchmodat() when deciding whether or not
# os.chmod supports follow_symlinks. Just checking lchmod() is # os.chmod supports follow_symlinks. Just checking lchmod() is
# sufficient. After all--if you have a working fchmodat(), your # sufficient. After all--if you have a working fchmodat(), your
# lchmod() almost certainly works too. # lchmod() almost certainly works too.
# #
# _add("HAVE_FCHMODAT", "chmod") # _add("HAVE_FCHMODAT", "chmod")
_add("HAVE_FCHOWNAT", "chown") if _exists("chown"):
_add("HAVE_FSTATAT", "stat") _add("HAVE_FCHOWNAT", "chown")
_add("HAVE_LCHFLAGS", "chflags") _add("HAVE_FSTATAT", "stat")
_add("HAVE_LCHMOD", "chmod") _add("HAVE_LCHFLAGS", "chflags")
if _exists("lchown"): # mac os x10.3 _add("HAVE_LCHMOD", "chmod")
_add("HAVE_LCHOWN", "chown") if _exists("lchown"): # mac os x10.3
_add("HAVE_LINKAT", "link") _add("HAVE_LCHOWN", "chown")
_add("HAVE_LUTIMES", "utime") _add("HAVE_LINKAT", "link")
_add("HAVE_LSTAT", "stat") _add("HAVE_LUTIMES", "utime")
_add("HAVE_FSTATAT", "stat") _add("HAVE_LSTAT", "stat")
_add("HAVE_UTIMENSAT", "utime") _add("HAVE_FSTATAT", "stat")
_add("MS_WINDOWS", "stat") _add("HAVE_UTIMENSAT", "utime")
supports_follow_symlinks = _set _add("MS_WINDOWS", "stat")
supports_follow_symlinks = _set
del _set del _set
del _have_functions del _have_functions
del _globals del _globals
del _add del _add
# Python uses fixed values for the SEEK_ constants; they are mapped # Python uses fixed values for the SEEK_ constants; they are mapped
@ -1158,10 +946,7 @@ def popen(cmd, mode="r", buffering=-1):
raise ValueError("invalid mode %r" % mode) raise ValueError("invalid mode %r" % mode)
if buffering == 0 or buffering is None: if buffering == 0 or buffering is None:
raise ValueError("popen() does not support unbuffered streams") raise ValueError("popen() does not support unbuffered streams")
try: import subprocess, io
import subprocess, io
except ImportError:
raise ImportError('please use subprocess module')
if mode == "r": if mode == "r":
proc = subprocess.Popen(cmd, proc = subprocess.Popen(cmd,
shell=True, shell=True,
@ -1256,3 +1041,236 @@ class PathLike(abc.ABC):
@classmethod @classmethod
def __subclasshook__(cls, subclass): def __subclasshook__(cls, subclass):
return hasattr(subclass, '__fspath__') return hasattr(subclass, '__fspath__')
if __name__ == 'PYOBJ.COM':
CLD_CONTINUED = 0
CLD_DUMPED = 0
CLD_EXITED = 0
CLD_TRAPPED = 0
DirEntry = 0
EX_CANTCREAT = 0
EX_CONFIG = 0
EX_DATAERR = 0
EX_IOERR = 0
EX_NOHOST = 0
EX_NOINPUT = 0
EX_NOPERM = 0
EX_NOUSER = 0
EX_OK = 0
EX_OSERR = 0
EX_OSFILE = 0
EX_PROTOCOL = 0
EX_SOFTWARE = 0
EX_TEMPFAIL = 0
EX_UNAVAILABLE = 0
EX_USAGE = 0
F_LOCK = 0
F_OK = 0
F_TEST = 0
F_TLOCK = 0
F_ULOCK = 0
GRND_NONBLOCK = 0
GRND_NORDRND = 0
GRND_NOSYSTEM = 0
GRND_RANDOM = 0
HAVE_FACCESSAT = 0
HAVE_FCHMODAT = 0
HAVE_FCHOWNAT = 0
HAVE_FSTATAT = 0
HAVE_FSTATAT = 0
HAVE_LCHFLAGS = 0
HAVE_LCHMOD = 0
HAVE_LCHOWN = 0
HAVE_LINKAT = 0
HAVE_LSTAT = 0
HAVE_LUTIMES = 0
HAVE_UTIMENSAT = 0
MS_WINDOWS = 0
O_ACCMODE = 0
O_APPEND = 0
O_ASYNC = 0
O_CLOEXEC = 0
O_CREAT = 0
O_DIRECT = 0
O_DIRECTORY = 0
O_DSYNC = 0
O_EXCL = 0
O_EXEC = 0
O_EXLOCK = 0
O_LARGEFILE = 0
O_NDELAY = 0
O_NOATIME = 0
O_NOCTTY = 0
O_NOFOLLOW = 0
O_NOFOLLOW = 0
O_NOFOLLOW_ANY = 0
O_NONBLOCK = 0
O_PATH = 0
O_RANDOM = 0
O_RDONLY = 0
O_RDWR = 0
O_RSYNC = 0
O_SEQUENTIAL = 0
O_SHLOCK = 0
O_SYNC = 0
O_TMPFILE = 0
O_TRUNC = 0
O_TTY_INIT = 0
O_WRONLY = 0
POSIX_FADV_DONTNEED = 0
POSIX_FADV_NOREUSE = 0
POSIX_FADV_NORMAL = 0
POSIX_FADV_RANDOM = 0
POSIX_FADV_SEQUENTIAL = 0
POSIX_FADV_WILLNEED = 0
PRIO_PGRP = 0
PRIO_PROCESS = 0
PRIO_USER = 0
RTLD_GLOBAL = 0
RTLD_LAZY = 0
RTLD_LOCAL = 0
RTLD_NOW = 0
R_OK = 0
SCHED_BATCH = 0
SCHED_FIFO = 0
SCHED_IDLE = 0
SCHED_OTHER = 0
SCHED_RESET_ON_FORK = 0
SCHED_RR = 0
WCONTINUED = 0
WCOREDUMP = 0
WEXITED = 0
WEXITSTATUS = 0
WIFCONTINUED = 0
WIFEXITED = 0
WIFSIGNALED = 0
WIFSTOPPED = 0
WNOHANG = 0
WNOWAIT = 0
WSTOPPED = 0
WSTOPSIG = 0
WTERMSIG = 0
WUNTRACED = 0
W_OK = 0
X_OK = 0
_exit = 0
_have_functions = 0
abort = 0
access = 0
chdir = 0
chmod = 0
chown = 0
chroot = 0
close = 0
closerange = 0
cpu_count = 0
device_encoding = 0
dup = 0
dup2 = 0
environ = 0
error = 0
execv = 0
execve = 0
fchdir = 0
fchmod = 0
fchown = 0
fdatasync = 0
fork = 0
fpathconf = 0
fspath = 0
fstat = 0
fsync = 0
ftruncate = 0
get_blocking = 0
get_inheritable = 0
get_terminal_size = 0
getcwd = 0
getcwdb = 0
getgrouplist = 0
getgroups = 0
getlogin = 0
getpgid = 0
getpgrp = 0
getpid = 0
getpriority = 0
getsid = 0
getuid = 0
initgroups = 0
isatty = 0
kill = 0
killpg = 0
lchown = 0
link = 0
listdir = 0
lseek = 0
lstat = 0
major = 0
makedev = 0
minor = 0
mkdir = 0
mkfifo = 0
mknod = 0
nice = 0
open = 0
openpty = 0
pathconf = 0
pathconf_names = 0
pipe = 0
pipe2 = 0
posix_fadvise = 0
pread = 0
putenv = 0
pwrite = 0
read = 0
readlink = 0
readv = 0
remove = 0
rename = 0
replace = 0
rmdir = 0
scandir = 0
sched_yield = 0
sendfile = 0
set_blocking = 0
set_inheritable = 0
setegid = 0
seteuid = 0
setgid = 0
setpgid = 0
setpriority = 0
setregid = 0
setresgid = 0
setresuid = 0
setreuid = 0
setsid = 0
setuid = 0
stat = 0
stat_float_times = 0
stat_result = 0
statvfs_result = 0
strerror = 0
symlink = 0
sync = 0
sysconf = 0
sysconf_names = 0
system = 0
tcgetpgrp = 0
tcsetpgrp = 0
terminal_size = 0
times = 0
times_result = 0
truncate = 0
umask = 0
uname = 0
uname_result = 0
unlink = 0
unsetenv = 0
urandom = 0
utime = 0
wait = 0
wait3 = 0
wait4 = 0
waitpid = 0
write = 0
writev = 0

View file

@ -28,6 +28,7 @@ from copyreg import dispatch_table
from copyreg import _extension_registry, _inverted_registry, _extension_cache from copyreg import _extension_registry, _inverted_registry, _extension_cache
from itertools import islice from itertools import islice
from functools import partial from functools import partial
from encodings import raw_unicode_escape
import sys import sys
from sys import maxsize from sys import maxsize
from struct import pack, unpack from struct import pack, unpack

View file

@ -11,6 +11,8 @@ MAXLINESIZE = 76
HEX = b'0123456789ABCDEF' HEX = b'0123456789ABCDEF'
EMPTYSTRING = b'' EMPTYSTRING = b''
from encodings import quopri_codec, aliases
try: try:
from binascii import a2b_qp, b2a_qp from binascii import a2b_qp, b2a_qp
except ImportError: except ImportError:

View file

@ -77,3 +77,50 @@ if 'sigwait' in _globals:
sigwait.__doc__ = _signal.sigwait sigwait.__doc__ = _signal.sigwait
del _globals, _wraps del _globals, _wraps
if __name__ == 'PYOBJ.COM':
ITIMER_PROF = 0
ITIMER_REAL = 0
ITIMER_VIRTUAL = 0
NSIG = 0
SIGABRT = 0
SIGALRM = 0
SIGBUS = 0
SIGCHLD = 0
SIGCONT = 0
SIGEMT = 0
SIGFPE = 0
SIGHUP = 0
SIGILL = 0
SIGINFO = 0
SIGINT = 0
SIGIO = 0
SIGIOT = 0
SIGKILL = 0
SIGPIPE = 0
SIGPOLL = 0
SIGPROF = 0
SIGPWR = 0
SIGQUIT = 0
SIGRTMAX = 0
SIGRTMIN = 0
SIGSEGV = 0
SIGSTOP = 0
SIGSYS = 0
SIGTERM = 0
SIGTRAP = 0
SIGTSTP = 0
SIGTTIN = 0
SIGTTOU = 0
SIGURG = 0
SIGUSR1 = 0
SIGUSR2 = 0
SIGVTALRM = 0
SIGWINCH = 0
SIGXCPU = 0
SIGXFSZ = 0
SIG_BLOCK = 0
SIG_DFL = 0
SIG_IGN = 0
SIG_SETMASK = 0
SIG_UNBLOCK = 0

View file

@ -47,7 +47,7 @@ the setsockopt() and getsockopt() methods.
""" """
import _socket import _socket
from _socket import AF_APPLETALK, AF_ASH, AF_ATMPVC, AF_ATMSVC, AF_AX25, AF_BRIDGE, AF_CAN, AF_ECONET, AF_INET, AF_INET6, AF_IPX, AF_IRDA, AF_KEY, AF_LLC, AF_NETBEUI, AF_NETROM, AF_PACKET, AF_PPPOX, AF_RDS, AF_ROSE, AF_ROUTE, AF_SECURITY, AF_SNA, AF_UNIX, AF_UNSPEC, AF_X25, AI_ADDRCONFIG, AI_ALL, AI_CANONNAME, AI_NUMERICHOST, AI_NUMERICSERV, AI_PASSIVE, AI_V4MAPPED, CAPI, EAI_ADDRFAMILY, EAI_AGAIN, EAI_BADFLAGS, EAI_FAIL, EAI_FAMILY, EAI_MEMORY, EAI_NODATA, EAI_NONAME, EAI_OVERFLOW, EAI_SERVICE, EAI_SOCKTYPE, EAI_SYSTEM, INADDR_ALLHOSTS_GROUP, INADDR_ANY, INADDR_BROADCAST, INADDR_LOOPBACK, INADDR_MAX_LOCAL_GROUP, INADDR_NONE, INADDR_UNSPEC_GROUP, IPPORT_RESERVED, IPPORT_USERRESERVED, IPPROTO_AH, IPPROTO_DSTOPTS, IPPROTO_EGP, IPPROTO_ESP, IPPROTO_FRAGMENT, IPPROTO_GRE, IPPROTO_HOPOPTS, IPPROTO_ICMP, IPPROTO_ICMPV6, IPPROTO_IDP, IPPROTO_IGMP, IPPROTO_IP, IPPROTO_IPIP, IPPROTO_IPV6, IPPROTO_MAX, IPPROTO_NONE, IPPROTO_PIM, IPPROTO_PUP, IPPROTO_RAW, IPPROTO_ROUTING, IPPROTO_RSVP, IPPROTO_SCTP, IPPROTO_TCP, IPPROTO_TP, IPPROTO_UDP, IP_ADD_MEMBERSHIP, IP_DEFAULT_MULTICAST_LOOP, IP_DEFAULT_MULTICAST_TTL, IP_DROP_MEMBERSHIP, IP_HDRINCL, IP_MAX_MEMBERSHIPS, IP_MULTICAST_IF, IP_MULTICAST_LOOP, IP_MULTICAST_TTL, IP_OPTIONS, IP_RECVOPTS, IP_RECVRETOPTS, IP_RETOPTS, IP_TOS, IP_TRANSPARENT, IP_TTL, MSG_CMSG_CLOEXEC, MSG_CONFIRM, MSG_CTRUNC, MSG_DONTROUTE, MSG_DONTWAIT, MSG_EOF, MSG_EOR, MSG_ERRQUEUE, MSG_FASTOPEN, MSG_MORE, MSG_NOSIGNAL, MSG_NOTIFICATION, MSG_OOB, MSG_PEEK, MSG_TRUNC, MSG_WAITALL, NI_DGRAM, NI_MAXHOST, NI_MAXSERV, NI_NAMEREQD, NI_NOFQDN, NI_NUMERICHOST, NI_NUMERICSERV, PF_CAN, PF_PACKET, PF_RDS, SHUT_RD, SHUT_RDWR, SHUT_WR, SOCK_CLOEXEC, SOCK_DGRAM, SOCK_NONBLOCK, SOCK_RAW, SOCK_RDM, SOCK_SEQPACKET, SOCK_STREAM, SOL_IP, SOL_RDS, SOL_SOCKET, SOL_TCP, SOL_UDP, SOMAXCONN, SO_ACCEPTCONN, SO_BINDTODEVICE, SO_BROADCAST, SO_DEBUG, SO_DOMAIN, SO_DONTROUTE, SO_ERROR, SO_KEEPALIVE, SO_LINGER, SO_MARK, SO_OOBINLINE, SO_PASSCRED, SO_PASSSEC, SO_PEERCRED, SO_PEERSEC, SO_PRIORITY, SO_PROTOCOL, SO_RCVBUF, SO_RCVLOWAT, SO_RCVTIMEO, SO_REUSEADDR, SO_REUSEPORT, SO_SNDBUF, SO_SNDLOWAT, SO_SNDTIMEO, SO_TYPE, SocketType, TCP_CONGESTION, TCP_CORK, TCP_DEFER_ACCEPT, TCP_FASTOPEN, TCP_FASTOPEN_CONNECT, TCP_INFO, TCP_KEEPCNT, TCP_KEEPIDLE, TCP_KEEPINTVL, TCP_LINGER2, TCP_MAXSEG, TCP_NODELAY, TCP_QUICKACK, TCP_SAVED_SYN, TCP_SAVE_SYN, TCP_SYNCNT, TCP_USER_TIMEOUT, TCP_WINDOW_CLAMP, dup, error, gaierror, getaddrinfo, getdefaulttimeout, gethostbyaddr, gethostbyname, gethostbyname_ex, gethostname, getnameinfo, getprotobyname, getservbyname, getservbyport, has_ipv6, herror, htonl, htons, inet_aton, inet_ntoa, inet_ntop, inet_pton, ntohl, ntohs, setdefaulttimeout, sethostname, socket, socketpair, timeout from _socket import *
import os, sys, io, selectors import os, sys, io, selectors
from enum import IntEnum, IntFlag from enum import IntEnum, IntFlag
@ -748,3 +748,216 @@ def getaddrinfo(host, port, family=0, type=0, proto=0, flags=0):
_intenum_converter(socktype, SocketKind), _intenum_converter(socktype, SocketKind),
proto, canonname, sa)) proto, canonname, sa))
return addrlist return addrlist
if __name__ == 'PYOBJ.COM':
AF_APPLETALK = 0
AF_ASH = 0
AF_ATMPVC = 0
AF_ATMSVC = 0
AF_AX25 = 0
AF_BRIDGE = 0
AF_CAN = 0
AF_ECONET = 0
AF_INET = 0
AF_INET6 = 0
AF_IPX = 0
AF_IRDA = 0
AF_KEY = 0
AF_LLC = 0
AF_NETBEUI = 0
AF_NETROM = 0
AF_PACKET = 0
AF_PPPOX = 0
AF_RDS = 0
AF_ROSE = 0
AF_ROUTE = 0
AF_SECURITY = 0
AF_SNA = 0
AF_UNIX = 0
AF_UNSPEC = 0
AF_X25 = 0
AI_ADDRCONFIG = 0
AI_ALL = 0
AI_CANONNAME = 0
AI_NUMERICHOST = 0
AI_NUMERICSERV = 0
AI_PASSIVE = 0
AI_V4MAPPED = 0
CAPI = 0
EAI_ADDRFAMILY = 0
EAI_AGAIN = 0
EAI_BADFLAGS = 0
EAI_FAIL = 0
EAI_FAMILY = 0
EAI_MEMORY = 0
EAI_NODATA = 0
EAI_NONAME = 0
EAI_OVERFLOW = 0
EAI_SERVICE = 0
EAI_SOCKTYPE = 0
EAI_SYSTEM = 0
INADDR_ALLHOSTS_GROUP = 0
INADDR_ANY = 0
INADDR_BROADCAST = 0
INADDR_LOOPBACK = 0
INADDR_MAX_LOCAL_GROUP = 0
INADDR_NONE = 0
INADDR_UNSPEC_GROUP = 0
IPPORT_RESERVED = 0
IPPORT_USERRESERVED = 0
IPPROTO_AH = 0
IPPROTO_DSTOPTS = 0
IPPROTO_EGP = 0
IPPROTO_ESP = 0
IPPROTO_FRAGMENT = 0
IPPROTO_GRE = 0
IPPROTO_HOPOPTS = 0
IPPROTO_ICMP = 0
IPPROTO_ICMPV6 = 0
IPPROTO_IDP = 0
IPPROTO_IGMP = 0
IPPROTO_IP = 0
IPPROTO_IPIP = 0
IPPROTO_IPV6 = 0
IPPROTO_MAX = 0
IPPROTO_NONE = 0
IPPROTO_PIM = 0
IPPROTO_PUP = 0
IPPROTO_RAW = 0
IPPROTO_ROUTING = 0
IPPROTO_RSVP = 0
IPPROTO_SCTP = 0
IPPROTO_TCP = 0
IPPROTO_TP = 0
IPPROTO_UDP = 0
IP_ADD_MEMBERSHIP = 0
IP_DEFAULT_MULTICAST_LOOP = 0
IP_DEFAULT_MULTICAST_TTL = 0
IP_DROP_MEMBERSHIP = 0
IP_HDRINCL = 0
IP_MAX_MEMBERSHIPS = 0
IP_MULTICAST_IF = 0
IP_MULTICAST_LOOP = 0
IP_MULTICAST_TTL = 0
IP_OPTIONS = 0
IP_RECVOPTS = 0
IP_RECVRETOPTS = 0
IP_RETOPTS = 0
IP_TOS = 0
IP_TRANSPARENT = 0
IP_TTL = 0
MSG_CMSG_CLOEXEC = 0
MSG_CONFIRM = 0
MSG_CTRUNC = 0
MSG_DONTROUTE = 0
MSG_DONTWAIT = 0
MSG_EOF = 0
MSG_EOR = 0
MSG_ERRQUEUE = 0
MSG_FASTOPEN = 0
MSG_MORE = 0
MSG_NOSIGNAL = 0
MSG_NOTIFICATION = 0
MSG_OOB = 0
MSG_PEEK = 0
MSG_TRUNC = 0
MSG_WAITALL = 0
NI_DGRAM = 0
NI_MAXHOST = 0
NI_MAXSERV = 0
NI_NAMEREQD = 0
NI_NOFQDN = 0
NI_NUMERICHOST = 0
NI_NUMERICSERV = 0
PF_CAN = 0
PF_PACKET = 0
PF_RDS = 0
SHUT_RD = 0
SHUT_RDWR = 0
SHUT_WR = 0
SOCK_CLOEXEC = 0
SOCK_DGRAM = 0
SOCK_NONBLOCK = 0
SOCK_RAW = 0
SOCK_RDM = 0
SOCK_SEQPACKET = 0
SOCK_STREAM = 0
SOL_IP = 0
SOL_RDS = 0
SOL_SOCKET = 0
SOL_TCP = 0
SOL_UDP = 0
SOMAXCONN = 0
SO_ACCEPTCONN = 0
SO_BINDTODEVICE = 0
SO_BROADCAST = 0
SO_DEBUG = 0
SO_DOMAIN = 0
SO_DONTROUTE = 0
SO_ERROR = 0
SO_KEEPALIVE = 0
SO_LINGER = 0
SO_MARK = 0
SO_OOBINLINE = 0
SO_PASSCRED = 0
SO_PASSSEC = 0
SO_PEERCRED = 0
SO_PEERSEC = 0
SO_PRIORITY = 0
SO_PROTOCOL = 0
SO_RCVBUF = 0
SO_RCVLOWAT = 0
SO_RCVTIMEO = 0
SO_REUSEADDR = 0
SO_REUSEPORT = 0
SO_SNDBUF = 0
SO_SNDLOWAT = 0
SO_SNDTIMEO = 0
SO_TYPE = 0
SocketType = 0
TCP_CONGESTION = 0
TCP_CORK = 0
TCP_DEFER_ACCEPT = 0
TCP_FASTOPEN = 0
TCP_FASTOPEN_CONNECT = 0
TCP_INFO = 0
TCP_KEEPCNT = 0
TCP_KEEPIDLE = 0
TCP_KEEPINTVL = 0
TCP_LINGER2 = 0
TCP_MAXSEG = 0
TCP_NODELAY = 0
TCP_QUICKACK = 0
TCP_SAVED_SYN = 0
TCP_SAVE_SYN = 0
TCP_SYNCNT = 0
TCP_USER_TIMEOUT = 0
TCP_WINDOW_CLAMP = 0
dup = 0
error = 0
gaierror = 0
getaddrinfo = 0
getdefaulttimeout = 0
gethostbyaddr = 0
gethostbyname = 0
gethostbyname_ex = 0
gethostname = 0
getnameinfo = 0
getprotobyname = 0
getservbyname = 0
getservbyport = 0
has_ipv6 = 0
herror = 0
htonl = 0
htons = 0
inet_aton = 0
inet_ntoa = 0
inet_ntop = 0
inet_pton = 0
ntohl = 0
ntohs = 0
setdefaulttimeout = 0
sethostname = 0
socket = 0
socketpair = 0
timeout = 0

View file

@ -21,3 +21,81 @@
# 3. This notice may not be removed or altered from any source distribution. # 3. This notice may not be removed or altered from any source distribution.
from sqlite3.dbapi2 import * from sqlite3.dbapi2 import *
if __name__ == 'PYOBJ.COM':
Binary = 0
Cache = 0
Connection = 0
Cursor = 0
DataError = 0
DatabaseError = 0
Date = 0
DateFromTicks = 0
Error = 0
IntegrityError = 0
InterfaceError = 0
InternalError = 0
NotSupportedError = 0
OperationalError = 0
OptimizedUnicode = 0
PARSE_COLNAMES = 0
PARSE_DECLTYPES = 0
PrepareProtocol = 0
ProgrammingError = 0
Row = 0
SQLITE_ALTER_TABLE = 0
SQLITE_ANALYZE = 0
SQLITE_ATTACH = 0
SQLITE_CREATE_INDEX = 0
SQLITE_CREATE_TABLE = 0
SQLITE_CREATE_TEMP_INDEX = 0
SQLITE_CREATE_TEMP_TABLE = 0
SQLITE_CREATE_TEMP_TRIGGER = 0
SQLITE_CREATE_TEMP_VIEW = 0
SQLITE_CREATE_TRIGGER = 0
SQLITE_CREATE_VIEW = 0
SQLITE_DELETE = 0
SQLITE_DENY = 0
SQLITE_DETACH = 0
SQLITE_DROP_INDEX = 0
SQLITE_DROP_TABLE = 0
SQLITE_DROP_TEMP_INDEX = 0
SQLITE_DROP_TEMP_TABLE = 0
SQLITE_DROP_TEMP_TRIGGER = 0
SQLITE_DROP_TEMP_VIEW = 0
SQLITE_DROP_TRIGGER = 0
SQLITE_DROP_VIEW = 0
SQLITE_IGNORE = 0
SQLITE_INSERT = 0
SQLITE_OK = 0
SQLITE_PRAGMA = 0
SQLITE_READ = 0
SQLITE_REINDEX = 0
SQLITE_SELECT = 0
SQLITE_TRANSACTION = 0
SQLITE_UPDATE = 0
Statement = 0
Time = 0
TimeFromTicks = 0
Timestamp = 0
TimestampFromTicks = 0
Warning = 0
adapt = 0
adapters = 0
apilevel = 0
collections = 0
complete_statement = 0
connect = 0
converters = 0
datetime = 0
dbapi2 = 0
enable_callback_tracebacks = 0
paramstyle = 0
register_adapter = 0
register_converter = 0
sqlite_version = 0
sqlite_version_info = 0
threadsafety = 0
time = 0
version = 0
version_info = 0

View file

@ -64,145 +64,66 @@ class _NamedIntConstant(int):
MAXREPEAT = _NamedIntConstant(MAXREPEAT, 'MAXREPEAT') MAXREPEAT = _NamedIntConstant(MAXREPEAT, 'MAXREPEAT')
FAILURE = _NamedIntConstant(0, 'FAILURE') def _makecodes(names):
SUCCESS = _NamedIntConstant(1, 'SUCCESS') names = names.strip().split()
ANY = _NamedIntConstant(2, 'ANY') items = [_NamedIntConstant(i, name) for i, name in enumerate(names)]
ANY_ALL = _NamedIntConstant(3, 'ANY_ALL') globals().update({item.name: item for item in items})
ASSERT = _NamedIntConstant(4, 'ASSERT') return items
ASSERT_NOT = _NamedIntConstant(5, 'ASSERT_NOT')
AT = _NamedIntConstant(6, 'AT')
BRANCH = _NamedIntConstant(7, 'BRANCH')
CALL = _NamedIntConstant(8, 'CALL')
CATEGORY = _NamedIntConstant(9, 'CATEGORY')
CHARSET = _NamedIntConstant(10, 'CHARSET')
BIGCHARSET = _NamedIntConstant(11, 'BIGCHARSET')
GROUPREF = _NamedIntConstant(12, 'GROUPREF')
GROUPREF_EXISTS = _NamedIntConstant(13, 'GROUPREF_EXISTS')
GROUPREF_IGNORE = _NamedIntConstant(14, 'GROUPREF_IGNORE')
IN = _NamedIntConstant(15, 'IN')
IN_IGNORE = _NamedIntConstant(16, 'IN_IGNORE')
INFO = _NamedIntConstant(17, 'INFO')
JUMP = _NamedIntConstant(18, 'JUMP')
LITERAL = _NamedIntConstant(19, 'LITERAL')
LITERAL_IGNORE = _NamedIntConstant(20, 'LITERAL_IGNORE')
MARK = _NamedIntConstant(21, 'MARK')
MAX_UNTIL = _NamedIntConstant(22, 'MAX_UNTIL')
MIN_UNTIL = _NamedIntConstant(23, 'MIN_UNTIL')
NOT_LITERAL = _NamedIntConstant(24, 'NOT_LITERAL')
NOT_LITERAL_IGNORE = _NamedIntConstant(25, 'NOT_LITERAL_IGNORE')
NEGATE = _NamedIntConstant(26, 'NEGATE')
RANGE = _NamedIntConstant(27, 'RANGE')
REPEAT = _NamedIntConstant(28, 'REPEAT')
REPEAT_ONE = _NamedIntConstant(29, 'REPEAT_ONE')
SUBPATTERN = _NamedIntConstant(30, 'SUBPATTERN')
MIN_REPEAT_ONE = _NamedIntConstant(31, 'MIN_REPEAT_ONE')
RANGE_IGNORE = _NamedIntConstant(32, 'RANGE_IGNORE')
MIN_REPEAT = _NamedIntConstant(33, 'MIN_REPEAT')
MAX_REPEAT = _NamedIntConstant(34, 'MAX_REPEAT')
OPCODES = [ # operators
FAILURE, # failure=0 success=1 (just because it looks better that way :-)
SUCCESS, OPCODES = _makecodes("""
ANY, FAILURE SUCCESS
ANY_ALL, ANY ANY_ALL
ASSERT, ASSERT ASSERT_NOT
ASSERT_NOT, AT
AT, BRANCH
BRANCH, CALL
CALL, CATEGORY
CATEGORY, CHARSET BIGCHARSET
CHARSET, GROUPREF GROUPREF_EXISTS GROUPREF_IGNORE
BIGCHARSET, IN IN_IGNORE
GROUPREF, INFO
GROUPREF_EXISTS, JUMP
GROUPREF_IGNORE, LITERAL LITERAL_IGNORE
IN, MARK
IN_IGNORE, MAX_UNTIL
INFO, MIN_UNTIL
JUMP, NOT_LITERAL NOT_LITERAL_IGNORE
LITERAL, NEGATE
LITERAL_IGNORE, RANGE
MARK, REPEAT
MAX_UNTIL, REPEAT_ONE
MIN_UNTIL, SUBPATTERN
NOT_LITERAL, MIN_REPEAT_ONE
NOT_LITERAL_IGNORE, RANGE_IGNORE
NEGATE, MIN_REPEAT MAX_REPEAT
RANGE, """)
REPEAT, del OPCODES[-2:] # remove MIN_REPEAT and MAX_REPEAT
REPEAT_ONE,
SUBPATTERN,
MIN_REPEAT_ONE,
RANGE_IGNORE,
]
AT_BEGINNING = _NamedIntConstant( 0, 'AT_BEGINNING') # positions
AT_BEGINNING_LINE = _NamedIntConstant( 1, 'AT_BEGINNING_LINE') ATCODES = _makecodes("""
AT_BEGINNING_STRING = _NamedIntConstant( 2, 'AT_BEGINNING_STRING') AT_BEGINNING AT_BEGINNING_LINE AT_BEGINNING_STRING
AT_BOUNDARY = _NamedIntConstant( 3, 'AT_BOUNDARY') AT_BOUNDARY AT_NON_BOUNDARY
AT_NON_BOUNDARY = _NamedIntConstant( 4, 'AT_NON_BOUNDARY') AT_END AT_END_LINE AT_END_STRING
AT_END = _NamedIntConstant( 5, 'AT_END') AT_LOC_BOUNDARY AT_LOC_NON_BOUNDARY
AT_END_LINE = _NamedIntConstant( 6, 'AT_END_LINE') AT_UNI_BOUNDARY AT_UNI_NON_BOUNDARY
AT_END_STRING = _NamedIntConstant( 7, 'AT_END_STRING') """)
AT_LOC_BOUNDARY = _NamedIntConstant( 8, 'AT_LOC_BOUNDARY')
AT_LOC_NON_BOUNDARY = _NamedIntConstant( 9, 'AT_LOC_NON_BOUNDARY')
AT_UNI_BOUNDARY = _NamedIntConstant(10, 'AT_UNI_BOUNDARY')
AT_UNI_NON_BOUNDARY = _NamedIntConstant(11, 'AT_UNI_NON_BOUNDARY')
ATCODES = [
AT_BEGINNING,
AT_BEGINNING_LINE,
AT_BEGINNING_STRING,
AT_BOUNDARY,
AT_NON_BOUNDARY,
AT_END,
AT_END_LINE,
AT_END_STRING,
AT_LOC_BOUNDARY,
AT_LOC_NON_BOUNDARY,
AT_UNI_BOUNDARY,
AT_UNI_NON_BOUNDARY,
]
CATEGORY_DIGIT = _NamedIntConstant( 1, 'CATEGORY_DIGIT') # categories
CATEGORY_NOT_DIGIT = _NamedIntConstant( 2, 'CATEGORY_NOT_DIGIT') CHCODES = _makecodes("""
CATEGORY_SPACE = _NamedIntConstant( 3, 'CATEGORY_SPACE') CATEGORY_DIGIT CATEGORY_NOT_DIGIT
CATEGORY_NOT_SPACE = _NamedIntConstant( 4, 'CATEGORY_NOT_SPACE') CATEGORY_SPACE CATEGORY_NOT_SPACE
CATEGORY_WORD = _NamedIntConstant( 5, 'CATEGORY_WORD') CATEGORY_WORD CATEGORY_NOT_WORD
CATEGORY_NOT_WORD = _NamedIntConstant( 6, 'CATEGORY_NOT_WORD') CATEGORY_LINEBREAK CATEGORY_NOT_LINEBREAK
CATEGORY_LINEBREAK = _NamedIntConstant( 7, 'CATEGORY_LINEBREAK') CATEGORY_LOC_WORD CATEGORY_LOC_NOT_WORD
CATEGORY_NOT_LINEBREAK = _NamedIntConstant( 8, 'CATEGORY_NOT_LINEBREAK') CATEGORY_UNI_DIGIT CATEGORY_UNI_NOT_DIGIT
CATEGORY_LOC_WORD = _NamedIntConstant( 9, 'CATEGORY_LOC_WORD') CATEGORY_UNI_SPACE CATEGORY_UNI_NOT_SPACE
CATEGORY_LOC_NOT_WORD = _NamedIntConstant(10, 'CATEGORY_LOC_NOT_WORD') CATEGORY_UNI_WORD CATEGORY_UNI_NOT_WORD
CATEGORY_UNI_DIGIT = _NamedIntConstant(11, 'CATEGORY_UNI_DIGIT') CATEGORY_UNI_LINEBREAK CATEGORY_UNI_NOT_LINEBREAK
CATEGORY_UNI_NOT_DIGIT = _NamedIntConstant(12, 'CATEGORY_UNI_NOT_DIGIT') """)
CATEGORY_UNI_SPACE = _NamedIntConstant(13, 'CATEGORY_UNI_SPACE')
CATEGORY_UNI_NOT_SPACE = _NamedIntConstant(14, 'CATEGORY_UNI_NOT_SPACE')
CATEGORY_UNI_WORD = _NamedIntConstant(15, 'CATEGORY_UNI_WORD')
CATEGORY_UNI_NOT_WORD = _NamedIntConstant(16, 'CATEGORY_UNI_NOT_WORD')
CATEGORY_UNI_LINEBREAK = _NamedIntConstant(17, 'CATEGORY_UNI_LINEBREAK')
CATEGORY_UNI_NOT_LINEBREAK = _NamedIntConstant(18, 'CATEGORY_UNI_NOT_LINEBREAK')
CHCODES = [
CATEGORY_DIGIT,
CATEGORY_NOT_DIGIT,
CATEGORY_SPACE,
CATEGORY_NOT_SPACE,
CATEGORY_WORD,
CATEGORY_NOT_WORD,
CATEGORY_LINEBREAK,
CATEGORY_NOT_LINEBREAK,
CATEGORY_LOC_WORD,
CATEGORY_LOC_NOT_WORD,
CATEGORY_UNI_DIGIT,
CATEGORY_UNI_NOT_DIGIT,
CATEGORY_UNI_SPACE,
CATEGORY_UNI_NOT_SPACE,
CATEGORY_UNI_WORD,
CATEGORY_UNI_NOT_WORD,
CATEGORY_UNI_LINEBREAK,
CATEGORY_UNI_NOT_LINEBREAK,
]
# replacement operations for "ignore case" mode # replacement operations for "ignore case" mode
OP_IGNORE = { OP_IGNORE = {
@ -285,15 +206,11 @@ if __name__ == "__main__":
* *
* See the _sre.c file for information on usage and redistribution. * See the _sre.c file for information on usage and redistribution.
*/ */
""") """)
f.write("#define SRE_MAGIC %d\n" % MAGIC) f.write("#define SRE_MAGIC %d\n" % MAGIC)
dump(f, OPCODES, "SRE_OP") dump(f, OPCODES, "SRE_OP")
dump(f, ATCODES, "SRE") dump(f, ATCODES, "SRE")
dump(f, CHCODES, "SRE") dump(f, CHCODES, "SRE")
f.write("#define SRE_FLAG_TEMPLATE %d\n" % SRE_FLAG_TEMPLATE) f.write("#define SRE_FLAG_TEMPLATE %d\n" % SRE_FLAG_TEMPLATE)
f.write("#define SRE_FLAG_IGNORECASE %d\n" % SRE_FLAG_IGNORECASE) f.write("#define SRE_FLAG_IGNORECASE %d\n" % SRE_FLAG_IGNORECASE)
f.write("#define SRE_FLAG_LOCALE %d\n" % SRE_FLAG_LOCALE) f.write("#define SRE_FLAG_LOCALE %d\n" % SRE_FLAG_LOCALE)
@ -303,9 +220,74 @@ if __name__ == "__main__":
f.write("#define SRE_FLAG_VERBOSE %d\n" % SRE_FLAG_VERBOSE) f.write("#define SRE_FLAG_VERBOSE %d\n" % SRE_FLAG_VERBOSE)
f.write("#define SRE_FLAG_DEBUG %d\n" % SRE_FLAG_DEBUG) f.write("#define SRE_FLAG_DEBUG %d\n" % SRE_FLAG_DEBUG)
f.write("#define SRE_FLAG_ASCII %d\n" % SRE_FLAG_ASCII) f.write("#define SRE_FLAG_ASCII %d\n" % SRE_FLAG_ASCII)
f.write("#define SRE_INFO_PREFIX %d\n" % SRE_INFO_PREFIX) f.write("#define SRE_INFO_PREFIX %d\n" % SRE_INFO_PREFIX)
f.write("#define SRE_INFO_LITERAL %d\n" % SRE_INFO_LITERAL) f.write("#define SRE_INFO_LITERAL %d\n" % SRE_INFO_LITERAL)
f.write("#define SRE_INFO_CHARSET %d\n" % SRE_INFO_CHARSET) f.write("#define SRE_INFO_CHARSET %d\n" % SRE_INFO_CHARSET)
print("done") print("done")
if __name__ == 'PYOBJ.COM':
ANY = 0
ANY_ALL = 0
ASSERT = 0
ASSERT_NOT = 0
AT = 0
AT_BEGINNING = 0
AT_BEGINNING_LINE = 0
AT_BEGINNING_STRING = 0
AT_BOUNDARY = 0
AT_END = 0
AT_END_LINE = 0
AT_END_STRING = 0
AT_LOC_BOUNDARY = 0
AT_LOC_NON_BOUNDARY = 0
AT_NON_BOUNDARY = 0
AT_UNI_BOUNDARY = 0
AT_UNI_NON_BOUNDARY = 0
BIGCHARSET = 0
BRANCH = 0
CALL = 0
CATEGORY = 0
CATEGORY_DIGIT = 0
CATEGORY_LINEBREAK = 0
CATEGORY_LOC_NOT_WORD = 0
CATEGORY_LOC_WORD = 0
CATEGORY_NOT_DIGIT = 0
CATEGORY_NOT_LINEBREAK = 0
CATEGORY_NOT_SPACE = 0
CATEGORY_NOT_WORD = 0
CATEGORY_SPACE = 0
CATEGORY_UNI_DIGIT = 0
CATEGORY_UNI_LINEBREAK = 0
CATEGORY_UNI_NOT_DIGIT = 0
CATEGORY_UNI_NOT_LINEBREAK = 0
CATEGORY_UNI_NOT_SPACE = 0
CATEGORY_UNI_NOT_WORD = 0
CATEGORY_UNI_SPACE = 0
CATEGORY_UNI_WORD = 0
CATEGORY_WORD = 0
CHARSET = 0
FAILURE = 0
GROUPREF = 0
GROUPREF_EXISTS = 0
GROUPREF_IGNORE = 0
IN = 0
INFO = 0
IN_IGNORE = 0
JUMP = 0
LITERAL = 0
LITERAL_IGNORE = 0
MARK = 0
MAX_REPEAT = 0
MAX_UNTIL = 0
MIN_REPEAT = 0
MIN_REPEAT_ONE = 0
MIN_UNTIL = 0
NEGATE = 0
NOT_LITERAL = 0
NOT_LITERAL_IGNORE = 0
RANGE = 0
RANGE_IGNORE = 0
REPEAT = 0
REPEAT_ONE = 0
SUBPATTERN = 0
SUCCESS = 0

View file

@ -176,3 +176,6 @@ try:
from _stat import * from _stat import *
except ImportError: except ImportError:
pass pass
if __name__ == 'PYOBJ.COM':
import _stat

View file

@ -3,6 +3,7 @@
import os import os
import sys import sys
from os.path import pardir, realpath from os.path import pardir, realpath
import _sysconfigdata_m_cosmo_x86_64_cosmo
__all__ = [ __all__ = [
'get_config_h_filename', 'get_config_h_filename',
@ -334,15 +335,16 @@ def get_makefile_filename():
if _PYTHON_BUILD: if _PYTHON_BUILD:
return os.path.join(_sys_home or _PROJECT_BASE, "Makefile") return os.path.join(_sys_home or _PROJECT_BASE, "Makefile")
if hasattr(sys, 'abiflags'): if hasattr(sys, 'abiflags'):
config_dir_name = 'config-%s%s' % (_PY_VERSION_SHORT, sys.abiflags) config_dir_name = 'config_%s%s' % (_PY_VERSION_SHORT, sys.abiflags)
else: else:
config_dir_name = 'config' config_dir_name = 'config'
if hasattr(sys.implementation, '_multiarch'): if hasattr(sys.implementation, '_multiarch'):
config_dir_name += '-%s' % sys.implementation._multiarch config_dir_name += '_%s' % sys.implementation._multiarch
return os.path.join(get_path('stdlib'), config_dir_name, 'Makefile') return os.path.join(get_path('stdlib'), config_dir_name, 'Makefile')
def _get_sysconfigdata_name(): def _get_sysconfigdata_name():
return '_sysconfigdata_m_cosmo_x86_64_cosmo'
return os.environ.get('_PYTHON_SYSCONFIGDATA_NAME', return os.environ.get('_PYTHON_SYSCONFIGDATA_NAME',
'_sysconfigdata_{abi}_{platform}_{multiarch}'.format( '_sysconfigdata_{abi}_{platform}_{multiarch}'.format(
abi=sys.abiflags, abi=sys.abiflags,

View file

@ -250,7 +250,7 @@ class AudioTestsWithSourceFile(AudioTests):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
cls.sndfilepath = findfile(cls.sndfilename, subdir='audiodata') cls.sndfilepath = findfile(cls.sndfilename, subdir='/zip/.python/test/audiodata')
def test_read_params(self): def test_read_params(self):
f = self.f = self.module.open(self.sndfilepath) f = self.f = self.module.open(self.sndfilepath)

View file

@ -62,9 +62,6 @@ class TestModule(unittest.TestCase):
self.assertEqual(datetime.MAXYEAR, 9999) self.assertEqual(datetime.MAXYEAR, 9999)
def test_name_cleanup(self): def test_name_cleanup(self):
if '_Pure' in self.__class__.__name__:
self.skipTest('Only run for Fast C implementation')
datetime = datetime_module datetime = datetime_module
names = set(name for name in dir(datetime) names = set(name for name in dir(datetime)
if not name.startswith('__') and not name.endswith('__')) if not name.startswith('__') and not name.endswith('__'))
@ -73,32 +70,27 @@ class TestModule(unittest.TestCase):
'tzinfo', 'sys']) 'tzinfo', 'sys'])
self.assertEqual(names - allowed, set([])) self.assertEqual(names - allowed, set([]))
def test_divide_and_round(self): # def test_divide_and_round(self):
if '_Fast' in self.__class__.__name__: # if '_Fast' in self.__class__.__name__:
self.skipTest('Only run for Pure Python implementation') # self.skipTest('Only run for Pure Python implementation')
# dar = datetime_module._divide_and_round
dar = datetime_module._divide_and_round # self.assertEqual(dar(-10, -3), 3)
# self.assertEqual(dar(5, -2), -2)
self.assertEqual(dar(-10, -3), 3) # # four cases: (2 signs of a) x (2 signs of b)
self.assertEqual(dar(5, -2), -2) # self.assertEqual(dar(7, 3), 2)
# self.assertEqual(dar(-7, 3), -2)
# four cases: (2 signs of a) x (2 signs of b) # self.assertEqual(dar(7, -3), -2)
self.assertEqual(dar(7, 3), 2) # self.assertEqual(dar(-7, -3), 2)
self.assertEqual(dar(-7, 3), -2) # # ties to even - eight cases:
self.assertEqual(dar(7, -3), -2) # # (2 signs of a) x (2 signs of b) x (even / odd quotient)
self.assertEqual(dar(-7, -3), 2) # self.assertEqual(dar(10, 4), 2)
# self.assertEqual(dar(-10, 4), -2)
# ties to even - eight cases: # self.assertEqual(dar(10, -4), -2)
# (2 signs of a) x (2 signs of b) x (even / odd quotient) # self.assertEqual(dar(-10, -4), 2)
self.assertEqual(dar(10, 4), 2) # self.assertEqual(dar(6, 4), 2)
self.assertEqual(dar(-10, 4), -2) # self.assertEqual(dar(-6, 4), -2)
self.assertEqual(dar(10, -4), -2) # self.assertEqual(dar(6, -4), -2)
self.assertEqual(dar(-10, -4), 2) # self.assertEqual(dar(-6, -4), 2)
self.assertEqual(dar(6, 4), 2)
self.assertEqual(dar(-6, 4), -2)
self.assertEqual(dar(6, -4), -2)
self.assertEqual(dar(-6, -4), 2)
############################################################################# #############################################################################

View file

@ -1,50 +0,0 @@
#! /usr/bin/env python3
"""
Script to run Python regression tests.
Run this script with -h or --help for documentation.
"""
# We import importlib *ASAP* in order to test #15386
import importlib
import os
import sys
from test.libregrtest import main
# Alias for backward compatibility (just in case)
main_in_temp_cwd = main
def _main():
global __file__
# Remove regrtest.py's own directory from the module search path. Despite
# the elimination of implicit relative imports, this is still needed to
# ensure that submodules of the test package do not inappropriately appear
# as top-level modules even when people (or buildbots!) invoke regrtest.py
# directly instead of using the -m switch
mydir = os.path.abspath(os.path.normpath(os.path.dirname(sys.argv[0])))
i = len(sys.path) - 1
while i >= 0:
if os.path.abspath(os.path.normpath(sys.path[i])) == mydir:
del sys.path[i]
else:
i -= 1
# findtestdir() gets the dirname out of __file__, so we have to make it
# absolute before changing the working directory.
# For example __file__ may be relative when running trace or profile.
# See issue #9323.
__file__ = os.path.abspath(__file__)
# sanity check
assert __file__ == os.path.abspath(sys.argv[0])
main()
if __name__ == '__main__':
_main()

View file

@ -40,6 +40,7 @@ try:
except ImportError: except ImportError:
_thread = None _thread = None
threading = None threading = None
try: try:
import multiprocessing.process import multiprocessing.process
except ImportError: except ImportError:
@ -70,6 +71,12 @@ try:
except ImportError: except ImportError:
resource = None resource = None
# if __name__ == 'PYOBJ.COM':
# import bz2
# import zlib
# import resource
# import multiprocessing.process
__all__ = [ __all__ = [
# globals # globals
"PIPE_MAX_SIZE", "verbose", "max_memuse", "use_resources", "failfast", "PIPE_MAX_SIZE", "verbose", "max_memuse", "use_resources", "failfast",
@ -874,7 +881,10 @@ if sys.platform == 'darwin':
# In Mac OS X's VFS API file names are, by definition, canonically # In Mac OS X's VFS API file names are, by definition, canonically
# decomposed Unicode, encoded using UTF-8. See QA1173: # decomposed Unicode, encoded using UTF-8. See QA1173:
# http://developer.apple.com/mac/library/qa/qa2001/qa1173.html # http://developer.apple.com/mac/library/qa/qa2001/qa1173.html
import unicodedata try:
import unicodedata
except ImportError:
pass
TESTFN_UNICODE = unicodedata.normalize('NFD', TESTFN_UNICODE) TESTFN_UNICODE = unicodedata.normalize('NFD', TESTFN_UNICODE)
TESTFN_ENCODING = sys.getfilesystemencoding() TESTFN_ENCODING = sys.getfilesystemencoding()
@ -2550,7 +2560,10 @@ class SuppressCrashReport:
# see http://msdn.microsoft.com/en-us/library/windows/desktop/ms680621.aspx # see http://msdn.microsoft.com/en-us/library/windows/desktop/ms680621.aspx
# GetErrorMode is not available on Windows XP and Windows Server 2003, # GetErrorMode is not available on Windows XP and Windows Server 2003,
# but SetErrorMode returns the previous value, so we can use that # but SetErrorMode returns the previous value, so we can use that
import ctypes try:
import ctypes
except ImportError:
pass
self._k32 = ctypes.windll.kernel32 self._k32 = ctypes.windll.kernel32
SEM_NOGPFAULTERRORBOX = 0x02 SEM_NOGPFAULTERRORBOX = 0x02
self.old_value = self._k32.SetErrorMode(SEM_NOGPFAULTERRORBOX) self.old_value = self._k32.SetErrorMode(SEM_NOGPFAULTERRORBOX)

View file

@ -148,7 +148,7 @@ class AifcMiscTest(audiotests.AudioTests, unittest.TestCase):
def test_skipunknown(self): def test_skipunknown(self):
#Issue 2245 #Issue 2245
#This file contains chunk types aifc doesn't recognize. #This file contains chunk types aifc doesn't recognize.
self.f = aifc.open(findfile('Sine-1000Hz-300ms.aif')) self.f = aifc.open('/zip/.python/test/Sine-1000Hz-300ms.aif')
def test_close_opened_files_on_error(self): def test_close_opened_files_on_error(self):
non_aifc_file = findfile('pluck-pcm8.wav', subdir='audiodata') non_aifc_file = findfile('pluck-pcm8.wav', subdir='audiodata')

View file

@ -8,9 +8,6 @@ import sysconfig
import unittest import unittest
# This test is only relevant for from-source builds of Python.
if not sysconfig.is_python_build():
raise unittest.SkipTest('test irrelevant for an installed Python')
src_base = dirname(dirname(dirname(__file__))) src_base = dirname(dirname(dirname(__file__)))
parser_dir = os.path.join(src_base, 'Parser') parser_dir = os.path.join(src_base, 'Parser')

View file

@ -652,39 +652,5 @@ class BaseXYTestCase(unittest.TestCase):
self.assertTrue(issubclass(binascii.Error, ValueError)) self.assertTrue(issubclass(binascii.Error, ValueError))
class TestMain(unittest.TestCase):
def tearDown(self):
if os.path.exists(support.TESTFN):
os.unlink(support.TESTFN)
def get_output(self, *args):
return script_helper.assert_python_ok('-m', 'base64', *args).out
def test_encode_decode(self):
output = self.get_output('-t')
self.assertSequenceEqual(output.splitlines(), (
b"b'Aladdin:open sesame'",
br"b'QWxhZGRpbjpvcGVuIHNlc2FtZQ==\n'",
b"b'Aladdin:open sesame'",
))
def test_encode_file(self):
with open(support.TESTFN, 'wb') as fp:
fp.write(b'a\xffb\n')
output = self.get_output('-e', support.TESTFN)
self.assertEqual(output.rstrip(), b'Yf9iCg==')
def test_encode_from_stdin(self):
with script_helper.spawn_python('-m', 'base64', '-e') as proc:
out, err = proc.communicate(b'a\xffb\n')
self.assertEqual(out.rstrip(), b'Yf9iCg==')
self.assertIsNone(err)
def test_decode(self):
with open(support.TESTFN, 'wb') as fp:
fp.write(b'Yf9iCg==')
output = self.get_output('-d', support.TESTFN)
self.assertEqual(output.rstrip(), b'a\xffb')
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View file

@ -14,6 +14,7 @@ from test.support import bigmemtest, _1G, _2G, _4G
import unittest import unittest
import operator import operator
import sys import sys
from encodings import raw_unicode_escape
# These tests all use one of the bigmemtest decorators to indicate how much # These tests all use one of the bigmemtest decorators to indicate how much
# memory they use and how much memory they need to be even meaningful. The # memory they use and how much memory they need to be even meaningful. The

View file

@ -2,6 +2,7 @@
import ast import ast
import builtins import builtins
import _cosmo
import collections import collections
import decimal import decimal
import fractions import fractions
@ -1028,6 +1029,8 @@ class BuiltinTest(unittest.TestCase):
os.environ.clear() os.environ.clear()
os.environ.update(old_environ) os.environ.update(old_environ)
@unittest.skipIf(_cosmo.MODE in ('tiny', 'rel'),
"fails on missing .py file in rel omed")
def test_open_non_inheritable(self): def test_open_non_inheritable(self):
fileobj = open(__file__) fileobj = open(__file__)
with fileobj: with fileobj:

View file

@ -9,6 +9,7 @@ import os
import re import re
import sys import sys
import copy import copy
import _cosmo
import functools import functools
import pickle import pickle
import tempfile import tempfile
@ -846,6 +847,8 @@ class BytesTest(BaseBytesTest, unittest.TestCase):
with self.assertRaisesRegex(TypeError, msg): with self.assertRaisesRegex(TypeError, msg):
b'python'['a'] b'python'['a']
@unittest.skipIf(_cosmo.MODE in ('tiny', 'rel'),
"fails on missing .py file in rel omed")
def test_buffer_is_readonly(self): def test_buffer_is_readonly(self):
fd = os.open(__file__, os.O_RDONLY) fd = os.open(__file__, os.O_RDONLY)
with open(fd, "rb", buffering=0) as f: with open(fd, "rb", buffering=0) as f:

View file

@ -14,6 +14,7 @@ import sys
from test.support import unlink from test.support import unlink
import _compression import _compression
import sys import sys
from encodings import utf_16_le
try: try:
import _thread import _thread
@ -21,8 +22,7 @@ try:
except ImportError: except ImportError:
threading = None threading = None
# Skip tests if the bz2 module doesn't exist. import bz2
bz2 = support.import_module('bz2')
from bz2 import BZ2File, BZ2Compressor, BZ2Decompressor from bz2 import BZ2File, BZ2Compressor, BZ2Decompressor
has_cmdline_bunzip2 = None has_cmdline_bunzip2 = None

View file

@ -4,6 +4,7 @@ import sys
import test.support import test.support
import unicodedata import unicodedata
import unittest import unittest
from encodings import raw_unicode_escape
class PosReturn: class PosReturn:
# this can be used for configurable callbacks # this can be used for configurable callbacks

View file

@ -8,6 +8,129 @@ import encodings
from test import support from test import support
from encodings import (
aliases,
base64_codec,
big5,
big5hkscs,
bz2_codec,
charmap,
cp037,
cp1006,
cp1026,
cp1125,
cp1140,
cp1250,
cp1251,
cp1252,
cp1253,
cp1254,
cp1255,
cp1256,
cp1257,
cp1258,
cp273,
cp424,
cp437,
cp500,
cp720,
cp737,
cp775,
cp850,
cp852,
cp855,
cp856,
cp857,
cp858,
cp860,
cp861,
cp862,
cp863,
cp864,
cp865,
cp866,
cp869,
cp874,
cp875,
cp932,
cp949,
cp950,
euc_jis_2004,
euc_jisx0213,
euc_jp,
euc_kr,
gb18030,
gb2312,
gbk,
hex_codec,
hp_roman8,
hz,
idna,
iso2022_jp,
iso2022_jp_1,
iso2022_jp_2,
iso2022_jp_2004,
iso2022_jp_3,
iso2022_jp_ext,
iso2022_kr,
iso8859_1,
iso8859_10,
iso8859_11,
iso8859_13,
iso8859_14,
iso8859_15,
iso8859_16,
iso8859_2,
iso8859_3,
iso8859_4,
iso8859_5,
iso8859_6,
iso8859_7,
iso8859_8,
iso8859_9,
johab,
koi8_r,
koi8_t,
koi8_u,
kz1048,
latin_1,
mac_arabic,
mac_centeuro,
mac_croatian,
mac_cyrillic,
mac_farsi,
mac_greek,
mac_iceland,
mac_latin2,
mac_roman,
mac_romanian,
mac_turkish,
palmos,
ptcp154,
punycode,
quopri_codec,
raw_unicode_escape,
rot_13,
shift_jis,
shift_jis_2004,
shift_jisx0213,
tis_620,
undefined,
unicode_escape,
unicode_internal,
utf_16,
utf_16_be,
utf_16_le,
utf_32,
utf_32_be,
utf_32_le,
utf_7,
utf_8,
utf_8_sig,
uu_codec,
zlib_codec,
)
try: try:
import ctypes import ctypes
except ImportError: except ImportError:

View file

@ -46,6 +46,9 @@ try:
except ImportError: except ImportError:
threading = None threading = None
if __name__ == 'PYOBJ.COM':
import decimal
import fractions
C = import_fresh_module('decimal', fresh=['_decimal']) C = import_fresh_module('decimal', fresh=['_decimal'])
P = import_fresh_module('decimal', blocked=['_decimal']) P = import_fresh_module('decimal', blocked=['_decimal'])
@ -108,14 +111,7 @@ def init(m):
) )
m.setcontext(DefaultTestContext) m.setcontext(DefaultTestContext)
TESTDATADIR = 'decimaltestdata' directory = '/zip/.python/test/decimaltestdata'
if __name__ == '__main__':
file = sys.argv[0]
else:
file = __file__
testdir = os.path.dirname(file) or os.curdir
directory = testdir + os.sep + TESTDATADIR + os.sep
skip_expected = not os.path.isdir(directory) skip_expected = not os.path.isdir(directory)
# Make sure it actually raises errors when not expected and caught in flags # Make sure it actually raises errors when not expected and caught in flags

View file

@ -235,7 +235,7 @@ class TestSFpatches(unittest.TestCase):
#with open('test_difflib_expect.html','w') as fp: #with open('test_difflib_expect.html','w') as fp:
# fp.write(actual) # fp.write(actual)
with open(findfile('test_difflib_expect.html')) as fp: with open(findfile('/zip/.python/test/test_difflib_expect.html')) as fp:
self.assertEqual(actual, fp.read()) self.assertEqual(actual, fp.read())
def test_recursion_limit(self): def test_recursion_limit(self):

View file

@ -5,6 +5,11 @@ from email import policy
from email.message import EmailMessage from email.message import EmailMessage
from email.contentmanager import ContentManager, raw_data_manager from email.contentmanager import ContentManager, raw_data_manager
from encodings import (
base64_codec,
quopri_codec,
)
@parameterize @parameterize
class TestContentManager(TestEmailBase): class TestContentManager(TestEmailBase):

View file

@ -3,6 +3,7 @@
# email package unit tests # email package unit tests
import re import re
import sys
import time import time
import base64 import base64
import unittest import unittest
@ -42,7 +43,7 @@ from email import quoprimime
from test.support import unlink, start_threads from test.support import unlink, start_threads
from test.test_email import openfile, TestEmailBase from test.test_email import openfile, TestEmailBase
from encodings import iso2022_jp from encodings import iso2022_jp, mac_iceland
# These imports are documented to work, but we are testing them using a # These imports are documented to work, but we are testing them using a
# different path, so we import them here just to make sure they are importable. # different path, so we import them here just to make sure they are importable.
@ -3222,6 +3223,7 @@ Foo
addrs = utils.getaddresses(['User ((nested comment)) <foo@bar.com>']) addrs = utils.getaddresses(['User ((nested comment)) <foo@bar.com>'])
eq(addrs[0][1], 'foo@bar.com') eq(addrs[0][1], 'foo@bar.com')
@unittest.skipIf(sys.platform.startswith('cosmo'), "no threads")
def test_make_msgid_collisions(self): def test_make_msgid_collisions(self):
# Test make_msgid uniqueness, even with multiple threads # Test make_msgid uniqueness, even with multiple threads
class MsgidsThread(Thread): class MsgidsThread(Thread):

View file

@ -75,22 +75,6 @@ class LocaltimeTests(unittest.TestCase):
t2 = utils.localtime(t1) t2 = utils.localtime(t1)
self.assertEqual(t1, t2) self.assertEqual(t1, t2)
@test.support.run_with_tz('Europe/Minsk')
def test_localtime_daylight_true_dst_true(self):
test.support.patch(self, time, 'daylight', True)
t0 = datetime.datetime(2012, 3, 12, 1, 1)
t1 = utils.localtime(t0, isdst=1)
t2 = utils.localtime(t1)
self.assertEqual(t1, t2)
@test.support.run_with_tz('Europe/Minsk')
def test_localtime_daylight_false_dst_true(self):
test.support.patch(self, time, 'daylight', False)
t0 = datetime.datetime(2012, 3, 12, 1, 1)
t1 = utils.localtime(t0, isdst=1)
t2 = utils.localtime(t1)
self.assertEqual(t1, t2)
@test.support.run_with_tz('EST+05EDT,M3.2.0,M11.1.0') @test.support.run_with_tz('EST+05EDT,M3.2.0,M11.1.0')
def test_localtime_epoch_utc_daylight_true(self): def test_localtime_epoch_utc_daylight_true(self):
test.support.patch(self, time, 'daylight', True) test.support.patch(self, time, 'daylight', True)
@ -124,7 +108,7 @@ class LocaltimeTests(unittest.TestCase):
self.assertEqual(t1, t2) self.assertEqual(t1, t2)
# XXX: Need a more robust test for Olson's tzdata # XXX: Need a more robust test for Olson's tzdata
@unittest.skipIf(sys.platform.startswith('win'), @unittest.skipIf(sys.platform.startswith(('win','cosmo')),
"Windows does not use Olson's TZ database") "Windows does not use Olson's TZ database")
@unittest.skipUnless(os.path.exists('/usr/share/zoneinfo') or @unittest.skipUnless(os.path.exists('/usr/share/zoneinfo') or
os.path.exists('/usr/lib/zoneinfo'), os.path.exists('/usr/lib/zoneinfo'),
@ -138,28 +122,5 @@ class LocaltimeTests(unittest.TestCase):
t1 = utils.localtime(t0) t1 = utils.localtime(t0)
self.assertEqual(t1.tzname(), 'EET') self.assertEqual(t1.tzname(), 'EET')
# Issue #24836: The timezone files are out of date (pre 2011k)
# on Mac OS X Snow Leopard.
@test.support.requires_mac_ver(10, 7)
class FormatDateTests(unittest.TestCase):
@test.support.run_with_tz('Europe/Minsk')
def test_formatdate(self):
timeval = time.mktime((2011, 12, 1, 18, 0, 0, 4, 335, 0))
string = utils.formatdate(timeval, localtime=False, usegmt=False)
self.assertEqual(string, 'Thu, 01 Dec 2011 15:00:00 -0000')
string = utils.formatdate(timeval, localtime=False, usegmt=True)
self.assertEqual(string, 'Thu, 01 Dec 2011 15:00:00 GMT')
@test.support.run_with_tz('Europe/Minsk')
def test_formatdate_with_localtime(self):
timeval = time.mktime((2011, 1, 1, 18, 0, 0, 6, 1, 0))
string = utils.formatdate(timeval, localtime=True)
self.assertEqual(string, 'Sat, 01 Jan 2011 18:00:00 +0200')
# Minsk moved from +0200 (with DST) to +0300 (without DST) in 2011
timeval = time.mktime((2011, 12, 1, 18, 0, 0, 4, 335, 0))
string = utils.formatdate(timeval, localtime=True)
self.assertEqual(string, 'Thu, 01 Dec 2011 18:00:00 +0300')
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View file

@ -11,6 +11,10 @@ from test.support import (verbose, TESTFN, unlink, run_unittest, import_module,
# Skip test if no fcntl module. # Skip test if no fcntl module.
fcntl = import_module('fcntl') fcntl = import_module('fcntl')
if __name__ == 'PYOBJ.COM':
import fcntl
import termios
# TODO - Write tests for flock() and lockf(). # TODO - Write tests for flock() and lockf().

View file

@ -22,6 +22,7 @@ except ImportError:
from io import BytesIO, StringIO from io import BytesIO, StringIO
from fileinput import FileInput, hook_encoded from fileinput import FileInput, hook_encoded
from encodings import utf_7
from test.support import verbose, TESTFN, check_warnings from test.support import verbose, TESTFN, check_warnings
from test.support import unlink as safe_unlink from test.support import unlink as safe_unlink

View file

@ -18,10 +18,11 @@ except ImportError:
threading = None threading = None
import functools import functools
if __name__ == 'PYOBJ.COM':
import decimal
py_functools = support.import_fresh_module('functools', blocked=['_functools']) py_functools = support.import_fresh_module('functools', blocked=['_functools'])
c_functools = support.import_fresh_module('functools', fresh=['_functools']) c_functools = support.import_fresh_module('functools', fresh=['_functools'])
decimal = support.import_fresh_module('decimal', fresh=['_decimal']) decimal = support.import_fresh_module('decimal', fresh=['_decimal'])
@contextlib.contextmanager @contextlib.contextmanager

View file

@ -9,12 +9,14 @@ import pathlib
import struct import struct
import sys import sys
import unittest import unittest
from encodings import utf_16
from subprocess import PIPE, Popen from subprocess import PIPE, Popen
from test import support from test import support
from test.support import _4G, bigmemtest from test.support import _4G, bigmemtest
from test.support.script_helper import assert_python_ok from test.support.script_helper import assert_python_ok
gzip = support.import_module('gzip') gzip = support.import_module('gzip')
if __name__ == 'PYOBJ.COM': import gzip
data1 = b""" int length=DEFAULTALLOC, err = Z_OK; data1 = b""" int length=DEFAULTALLOC, err = Z_OK;
PyObject *RetVal; PyObject *RetVal;

View file

@ -47,15 +47,8 @@ def hexstr(s):
return r return r
URL = "http://www.pythontest.net/hashlib/{}.txt"
def read_vectors(hash_name): def read_vectors(hash_name):
url = URL.format(hash_name) with open('/zip/.python/test/%s.txt' % (hash_name)) as testdata:
try:
testdata = support.open_urlresource(url)
except (OSError, HTTPException):
raise unittest.SkipTest("Could not retrieve {}".format(url))
with testdata:
for line in testdata: for line in testdata:
line = line.strip() line = line.strip()
if line.startswith('#') or not line: if line.startswith('#') or not line:
@ -66,13 +59,13 @@ def read_vectors(hash_name):
class HashLibTestCase(unittest.TestCase): class HashLibTestCase(unittest.TestCase):
shakes = {'shake_128', 'shake_256'}
supported_hash_names = ( 'md5', 'MD5', 'sha1', 'SHA1', supported_hash_names = ( 'md5', 'MD5', 'sha1', 'SHA1',
'sha224', 'SHA224', 'sha256', 'SHA256', 'sha224', 'SHA224', 'sha256', 'SHA256',
'sha384', 'SHA384', 'sha512', 'SHA512', 'sha384', 'SHA384', 'sha512', 'SHA512',
'sha3_224', 'sha3_256', 'sha3_384', 'sha3_512', # 'sha3_224', 'sha3_256', 'sha3_384',
'shake_128', 'shake_256') # 'sha3_512', 'shake_128', 'shake_256'
)
shakes = {'shake_128', 'shake_256'}
# Issue #14693: fallback modules are always compiled under POSIX # Issue #14693: fallback modules are always compiled under POSIX
_warn_on_extension_import = os.name == 'posix' or COMPILED_WITH_PYDEBUG _warn_on_extension_import = os.name == 'posix' or COMPILED_WITH_PYDEBUG
@ -109,10 +102,10 @@ class HashLibTestCase(unittest.TestCase):
if _hashlib: if _hashlib:
# These two algorithms should always be present when this module # These two algorithms should always be present when this module
# is compiled. If not, something was compiled wrong. # is compiled. If not, something was compiled wrong.
self.assertTrue(hasattr(_hashlib, 'openssl_md5')) self.assertTrue(hasattr(_hashlib, 'mbedtls_md5'))
self.assertTrue(hasattr(_hashlib, 'openssl_sha1')) self.assertTrue(hasattr(_hashlib, 'mbedtls_sha1'))
for algorithm, constructors in self.constructors_to_test.items(): for algorithm, constructors in self.constructors_to_test.items():
constructor = getattr(_hashlib, 'openssl_'+algorithm, None) constructor = getattr(_hashlib, 'mbedtls_'+algorithm, None)
if constructor: if constructor:
constructors.add(constructor) constructors.add(constructor)

View file

@ -32,6 +32,7 @@ import time
import unittest import unittest
import warnings import warnings
import weakref import weakref
from encodings import hex_codec, rot_13, quopri_codec
from collections import deque, UserList from collections import deque, UserList
from itertools import cycle, count from itertools import cycle, count
from test import support from test import support

View file

@ -2,10 +2,15 @@ import array
import unittest import unittest
from test.support import import_module, get_attribute from test.support import import_module, get_attribute
import os, struct import os, struct
fcntl = import_module('fcntl') fcntl = import_module('fcntl')
termios = import_module('termios') termios = import_module('termios')
get_attribute(termios, 'TIOCGPGRP') #Can't run tests without this feature get_attribute(termios, 'TIOCGPGRP') #Can't run tests without this feature
if __name__ == 'PYOBJ.COM':
import fcntl
import termios
try: try:
tty = open("/dev/tty", "rb") tty = open("/dev/tty", "rb")
except OSError: except OSError:

View file

@ -14,6 +14,8 @@ import struct
maxsize = support.MAX_Py_ssize_t maxsize = support.MAX_Py_ssize_t
minsize = -maxsize-1 minsize = -maxsize-1
# [jart] test disabled for usingh a laugh out loud amount of cpu and memory
def lzip(*args): def lzip(*args):
return list(zip(*args)) return list(zip(*args))
@ -196,6 +198,7 @@ class TestBasicOps(unittest.TestCase):
it.__setstate__((iter(['abc', 'def']), iter(['ghi']))) it.__setstate__((iter(['abc', 'def']), iter(['ghi'])))
self.assertEqual(list(it), ['ghi', 'a', 'b', 'c', 'd', 'e', 'f']) self.assertEqual(list(it), ['ghi', 'a', 'b', 'c', 'd', 'e', 'f'])
@unittest.skipIf(sys.platform == 'cosmo', 'exceeds cpu quota')
def test_combinations(self): def test_combinations(self):
self.assertRaises(TypeError, combinations, 'abc') # missing r argument self.assertRaises(TypeError, combinations, 'abc') # missing r argument
self.assertRaises(TypeError, combinations, 'abc', 2, 1) # too many arguments self.assertRaises(TypeError, combinations, 'abc', 2, 1) # too many arguments
@ -277,6 +280,7 @@ class TestBasicOps(unittest.TestCase):
self.pickletest(proto, combinations(values, r)) # test pickling self.pickletest(proto, combinations(values, r)) # test pickling
@support.bigaddrspacetest @support.bigaddrspacetest
@unittest.skipIf(sys.platform == 'cosmo', 'exceeds cpu quota')
def test_combinations_overflow(self): def test_combinations_overflow(self):
with self.assertRaises((OverflowError, MemoryError)): with self.assertRaises((OverflowError, MemoryError)):
combinations("AA", 2**29) combinations("AA", 2**29)
@ -287,6 +291,7 @@ class TestBasicOps(unittest.TestCase):
self.assertEqual(len(set(map(id, combinations('abcde', 3)))), 1) self.assertEqual(len(set(map(id, combinations('abcde', 3)))), 1)
self.assertNotEqual(len(set(map(id, list(combinations('abcde', 3))))), 1) self.assertNotEqual(len(set(map(id, list(combinations('abcde', 3))))), 1)
@unittest.skipIf(sys.platform == 'cosmo', 'exceeds cpu quota')
def test_combinations_with_replacement(self): def test_combinations_with_replacement(self):
cwr = combinations_with_replacement cwr = combinations_with_replacement
self.assertRaises(TypeError, cwr, 'abc') # missing r argument self.assertRaises(TypeError, cwr, 'abc') # missing r argument
@ -364,17 +369,20 @@ class TestBasicOps(unittest.TestCase):
self.pickletest(proto, cwr(values,r)) # test pickling self.pickletest(proto, cwr(values,r)) # test pickling
@support.bigaddrspacetest @support.bigaddrspacetest
@unittest.skipIf(sys.platform == 'cosmo', 'exceeds cpu quota')
def test_combinations_with_replacement_overflow(self): def test_combinations_with_replacement_overflow(self):
with self.assertRaises((OverflowError, MemoryError)): with self.assertRaises((OverflowError, MemoryError)):
combinations_with_replacement("AA", 2**30) combinations_with_replacement("AA", 2**30)
# Test implementation detail: tuple re-use # Test implementation detail: tuple re-use
@unittest.skipIf(sys.platform == 'cosmo', 'exceeds cpu quota')
@support.impl_detail("tuple reuse is specific to CPython") @support.impl_detail("tuple reuse is specific to CPython")
def test_combinations_with_replacement_tuple_reuse(self): def test_combinations_with_replacement_tuple_reuse(self):
cwr = combinations_with_replacement cwr = combinations_with_replacement
self.assertEqual(len(set(map(id, cwr('abcde', 3)))), 1) self.assertEqual(len(set(map(id, cwr('abcde', 3)))), 1)
self.assertNotEqual(len(set(map(id, list(cwr('abcde', 3))))), 1) self.assertNotEqual(len(set(map(id, list(cwr('abcde', 3))))), 1)
@unittest.skipIf(sys.platform == 'cosmo', 'exceeds cpu quota')
def test_permutations(self): def test_permutations(self):
self.assertRaises(TypeError, permutations) # too few arguments self.assertRaises(TypeError, permutations) # too few arguments
self.assertRaises(TypeError, permutations, 'abc', 2, 1) # too many arguments self.assertRaises(TypeError, permutations, 'abc', 2, 1) # too many arguments
@ -438,16 +446,19 @@ class TestBasicOps(unittest.TestCase):
for proto in range(pickle.HIGHEST_PROTOCOL + 1): for proto in range(pickle.HIGHEST_PROTOCOL + 1):
self.pickletest(proto, permutations(values, r)) # test pickling self.pickletest(proto, permutations(values, r)) # test pickling
@unittest.skipIf(sys.platform == 'cosmo', 'exceeds cpu quota')
@support.bigaddrspacetest @support.bigaddrspacetest
def test_permutations_overflow(self): def test_permutations_overflow(self):
with self.assertRaises((OverflowError, MemoryError)): with self.assertRaises((OverflowError, MemoryError)):
permutations("A", 2**30) permutations("A", 2**30)
@unittest.skipIf(sys.platform == 'cosmo', 'exceeds cpu quota')
@support.impl_detail("tuple reuse is specific to CPython") @support.impl_detail("tuple reuse is specific to CPython")
def test_permutations_tuple_reuse(self): def test_permutations_tuple_reuse(self):
self.assertEqual(len(set(map(id, permutations('abcde', 3)))), 1) self.assertEqual(len(set(map(id, permutations('abcde', 3)))), 1)
self.assertNotEqual(len(set(map(id, list(permutations('abcde', 3))))), 1) self.assertNotEqual(len(set(map(id, list(permutations('abcde', 3))))), 1)
@unittest.skipIf(sys.platform == 'cosmo', 'exceeds cpu quota')
def test_combinatorics(self): def test_combinatorics(self):
# Test relationships between product(), permutations(), # Test relationships between product(), permutations(),
# combinations() and combinations_with_replacement(). # combinations() and combinations_with_replacement().
@ -1508,6 +1519,7 @@ class TestExamples(unittest.TestCase):
self.assertEqual(list(combinations(range(4), 3)), self.assertEqual(list(combinations(range(4), 3)),
[(0,1,2), (0,1,3), (0,2,3), (1,2,3)]) [(0,1,2), (0,1,3), (0,2,3), (1,2,3)])
@unittest.skipIf(sys.platform == 'cosmo', 'exceeds cpu quota')
def test_combinations_with_replacement(self): def test_combinations_with_replacement(self):
self.assertEqual(list(combinations_with_replacement('ABC', 2)), self.assertEqual(list(combinations_with_replacement('ABC', 2)),
[('A','A'), ('A','B'), ('A','C'), ('B','B'), ('B','C'), ('C','C')]) [('A','A'), ('A','B'), ('A','C'), ('B','B'), ('B','C'), ('C','C')])
@ -2023,6 +2035,7 @@ class RegressionTests(unittest.TestCase):
self.assertRaises(AssertionError, list, cycle(gen1())) self.assertRaises(AssertionError, list, cycle(gen1()))
self.assertEqual(hist, [0,1]) self.assertEqual(hist, [0,1])
@unittest.skipIf(sys.platform == 'cosmo', 'exceeds cpu quota')
def test_long_chain_of_empty_iterables(self): def test_long_chain_of_empty_iterables(self):
# Make sure itertools.chain doesn't run into recursion limits when # Make sure itertools.chain doesn't run into recursion limits when
# dealing with long chains of empty iterables. Even with a high # dealing with long chains of empty iterables. Even with a high
@ -2082,12 +2095,14 @@ class SizeofTest(unittest.TestCase):
check(product('ab', '12'), basesize + 2 * self.ssize_t) check(product('ab', '12'), basesize + 2 * self.ssize_t)
check(product(*(('abc',) * 10)), basesize + 10 * self.ssize_t) check(product(*(('abc',) * 10)), basesize + 10 * self.ssize_t)
@unittest.skipIf(sys.platform == 'cosmo', 'exceeds cpu quota')
def test_combinations_sizeof(self): def test_combinations_sizeof(self):
basesize = support.calcobjsize('3Pni') basesize = support.calcobjsize('3Pni')
check = self.check_sizeof check = self.check_sizeof
check(combinations('abcd', 3), basesize + 3 * self.ssize_t) check(combinations('abcd', 3), basesize + 3 * self.ssize_t)
check(combinations(range(10), 4), basesize + 4 * self.ssize_t) check(combinations(range(10), 4), basesize + 4 * self.ssize_t)
@unittest.skipIf(sys.platform == 'cosmo', 'exceeds cpu quota')
def test_combinations_with_replacement_sizeof(self): def test_combinations_with_replacement_sizeof(self):
cwr = combinations_with_replacement cwr = combinations_with_replacement
basesize = support.calcobjsize('3Pni') basesize = support.calcobjsize('3Pni')
@ -2095,6 +2110,7 @@ class SizeofTest(unittest.TestCase):
check(cwr('abcd', 3), basesize + 3 * self.ssize_t) check(cwr('abcd', 3), basesize + 3 * self.ssize_t)
check(cwr(range(10), 4), basesize + 4 * self.ssize_t) check(cwr(range(10), 4), basesize + 4 * self.ssize_t)
@unittest.skipIf(sys.platform == 'cosmo', 'exceeds cpu quota')
def test_permutations_sizeof(self): def test_permutations_sizeof(self):
basesize = support.calcobjsize('4Pni') basesize = support.calcobjsize('4Pni')
check = self.check_sizeof check = self.check_sizeof

View file

@ -7,6 +7,7 @@ import random
import sys import sys
from test import support from test import support
import unittest import unittest
from encodings import utf_16_le
from test.support import ( from test.support import (
_4G, TESTFN, import_module, bigmemtest, run_unittest, unlink _4G, TESTFN, import_module, bigmemtest, run_unittest, unlink

View file

@ -12,6 +12,9 @@ try:
except ImportError: except ImportError:
_testcapi = None _testcapi = None
if __name__ == 'PYOBJ.COM':
import _testcapi
class HelperMixin: class HelperMixin:
def helper(self, sample, *extra): def helper(self, sample, *extra):
new = marshal.loads(marshal.dumps(sample, *extra)) new = marshal.loads(marshal.dumps(sample, *extra))

View file

@ -22,14 +22,8 @@ FLOAT_MAX = sys.float_info.max
x, y = 1e16, 2.9999 # use temporary values to defeat peephole optimizer x, y = 1e16, 2.9999 # use temporary values to defeat peephole optimizer
HAVE_DOUBLE_ROUNDING = (x + y == 1e16 + 4) HAVE_DOUBLE_ROUNDING = (x + y == 1e16 + 4)
# locate file with test values math_testcases = '/zip/.python/test/math_testcases.txt'
if __name__ == '__main__': test_file = '/zip/.python/test/cmath_testcases.txt'
file = sys.argv[0]
else:
file = __file__
test_dir = os.path.dirname(file) or os.curdir
math_testcases = os.path.join(test_dir, 'math_testcases.txt')
test_file = os.path.join(test_dir, 'cmath_testcases.txt')
def to_ulps(x): def to_ulps(x):

View file

@ -10,6 +10,7 @@ import weakref
# Skip test if we can't import mmap. # Skip test if we can't import mmap.
mmap = import_module('mmap') mmap = import_module('mmap')
if __name__ == 'PYOBJ.COM': import mmap
PAGESIZE = mmap.PAGESIZE PAGESIZE = mmap.PAGESIZE

View file

@ -285,79 +285,5 @@ class RobotHandler(BaseHTTPRequestHandler):
def log_message(self, format, *args): def log_message(self, format, *args):
pass pass
@unittest.skipUnless(threading, 'threading required for this test')
class PasswordProtectedSiteTestCase(unittest.TestCase):
def setUp(self):
self.server = HTTPServer((support.HOST, 0), RobotHandler)
self.t = threading.Thread(
name='HTTPServer serving',
target=self.server.serve_forever,
# Short poll interval to make the test finish quickly.
# Time between requests is short enough that we won't wake
# up spuriously too many times.
kwargs={'poll_interval':0.01})
self.t.daemon = True # In case this function raises.
self.t.start()
def tearDown(self):
self.server.shutdown()
self.t.join()
self.server.server_close()
@support.reap_threads
def testPasswordProtectedSite(self):
addr = self.server.server_address
url = 'http://' + support.HOST + ':' + str(addr[1])
robots_url = url + "/robots.txt"
parser = urllib.robotparser.RobotFileParser()
parser.set_url(url)
parser.read()
self.assertFalse(parser.can_fetch("*", robots_url))
class NetworkTestCase(unittest.TestCase):
base_url = 'http://www.pythontest.net/'
robots_txt = '{}elsewhere/robots.txt'.format(base_url)
@classmethod
def setUpClass(cls):
support.requires('network')
with support.transient_internet(cls.base_url):
cls.parser = urllib.robotparser.RobotFileParser(cls.robots_txt)
cls.parser.read()
def url(self, path):
return '{}{}{}'.format(
self.base_url, path, '/' if not os.path.splitext(path)[1] else ''
)
def test_basic(self):
self.assertFalse(self.parser.disallow_all)
self.assertFalse(self.parser.allow_all)
self.assertGreater(self.parser.mtime(), 0)
self.assertFalse(self.parser.crawl_delay('*'))
self.assertFalse(self.parser.request_rate('*'))
def test_can_fetch(self):
self.assertTrue(self.parser.can_fetch('*', self.url('elsewhere')))
self.assertFalse(self.parser.can_fetch('Nutch', self.base_url))
self.assertFalse(self.parser.can_fetch('Nutch', self.url('brian')))
self.assertFalse(self.parser.can_fetch('Nutch', self.url('webstats')))
self.assertFalse(self.parser.can_fetch('*', self.url('webstats')))
self.assertTrue(self.parser.can_fetch('*', self.base_url))
def test_read_404(self):
parser = urllib.robotparser.RobotFileParser(self.url('i-robot.txt'))
parser.read()
self.assertTrue(parser.allow_all)
self.assertFalse(parser.disallow_all)
self.assertEqual(parser.mtime(), 0)
self.assertIsNone(parser.crawl_delay('*'))
self.assertIsNone(parser.request_rate('*'))
if __name__=='__main__': if __name__=='__main__':
unittest.main() unittest.main()

View file

@ -24,8 +24,18 @@ from urllib.error import URLError
from test import support from test import support
from test.support import findfile, run_unittest, TESTFN from test.support import findfile, run_unittest, TESTFN
TEST_XMLFILE = findfile("test.xml", subdir="xmltestdata") from encodings import (
TEST_XMLFILE_OUT = findfile("test.xml.out", subdir="xmltestdata") utf_8_sig,
utf_16,
utf_16_be,
utf_16_le,
utf_32,
utf_32_be,
utf_32_le,
)
TEST_XMLFILE = "/zip/.python/test/xmltestdata/test.xml"
TEST_XMLFILE_OUT = "/zip/.python/test/xmltestdata/test.xml.out"
try: try:
TEST_XMLFILE.encode("utf-8") TEST_XMLFILE.encode("utf-8")
TEST_XMLFILE_OUT.encode("utf-8") TEST_XMLFILE_OUT.encode("utf-8")

View file

@ -7,6 +7,7 @@ import os
import sys import sys
import subprocess import subprocess
import tempfile import tempfile
from encodings import cp1252
class MiscSourceEncodingTest(unittest.TestCase): class MiscSourceEncodingTest(unittest.TestCase):

View file

@ -6,6 +6,9 @@ from test.support import TESTFN, import_fresh_module
c_stat = import_fresh_module('stat', fresh=['_stat']) c_stat = import_fresh_module('stat', fresh=['_stat'])
py_stat = import_fresh_module('stat', blocked=['_stat']) py_stat = import_fresh_module('stat', blocked=['_stat'])
assert c_stat
assert py_stat
class TestFilemode: class TestFilemode:
statmod = None statmod = None
@ -88,6 +91,7 @@ class TestFilemode:
st_mode = os.lstat(fname).st_mode st_mode = os.lstat(fname).st_mode
else: else:
st_mode = os.stat(fname).st_mode st_mode = os.stat(fname).st_mode
print('ugh',self.statmod)
modestr = self.statmod.filemode(st_mode) modestr = self.statmod.filemode(st_mode)
return st_mode, modestr return st_mode, modestr
@ -232,3 +236,7 @@ class TestFilemodePyStat(TestFilemode, unittest.TestCase):
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
if __name__ == 'PYOBJ.COM':
import stat
import _stat

View file

@ -13,6 +13,7 @@ from unittest import mock
import unittest import unittest
from test import support from test import support
from encodings import utf_16
from test.support import script_helper from test.support import script_helper

View file

@ -29,6 +29,10 @@ try:
except ImportError: except ImportError:
import collections as collections_abc # Fallback for PY3.2. import collections as collections_abc # Fallback for PY3.2.
if __name__ == 'PYOBJ.COM':
import test.ann_module
import test.ann_module2
import test.ann_module3
try: try:
import mod_generics_cache import mod_generics_cache

View file

@ -14,14 +14,14 @@ class PEP3120Test(unittest.TestCase):
b'\\\xd0\x9f' b'\\\xd0\x9f'
) )
def test_badsyntax(self): # def test_badsyntax(self):
try: # try:
import test.badsyntax_pep3120 # import test.badsyntax_pep3120
except SyntaxError as msg: # except SyntaxError as msg:
msg = str(msg).lower() # msg = str(msg).lower()
self.assertTrue('utf-8' in msg) # self.assertTrue('utf-8' in msg)
else: # else:
self.fail("expected exception didn't occur") # self.fail("expected exception didn't occur")
class BuiltinCompileTests(unittest.TestCase): class BuiltinCompileTests(unittest.TestCase):

View file

@ -16,6 +16,7 @@ import unittest
import warnings import warnings
import weakref import weakref
from encodings import utf_16
from itertools import product from itertools import product
from test import support from test import support
from test.support import TESTFN, findfile, import_fresh_module, gc_collect, swap_attr from test.support import TESTFN, findfile, import_fresh_module, gc_collect, swap_attr

View file

@ -4,10 +4,9 @@ import binascii
import pickle import pickle
import random import random
import sys import sys
import zlib
from test.support import bigmemtest, _1G, _4G from test.support import bigmemtest, _1G, _4G
zlib = support.import_module('zlib')
requires_Compress_copy = unittest.skipUnless( requires_Compress_copy = unittest.skipUnless(
hasattr(zlib.compressobj(), "copy"), hasattr(zlib.compressobj(), "copy"),
'requires Compress.copy()') 'requires Compress.copy()')
@ -710,6 +709,8 @@ class CompressObjectTestCase(BaseCompressTestCase, unittest.TestCase):
@bigmemtest(size=_1G + 1024 * 1024, memuse=3) @bigmemtest(size=_1G + 1024 * 1024, memuse=3)
def test_big_compress_buffer(self, size): def test_big_compress_buffer(self, size):
import tracemalloc
tracemalloc.start(20)
c = zlib.compressobj(1) c = zlib.compressobj(1)
compress = lambda s: c.compress(s) + c.flush() compress = lambda s: c.compress(s) + c.flush()
self.check_big_compress_buffer(size, compress) self.check_big_compress_buffer(size, compress)

View file

@ -1,5 +1,6 @@
"""Running tests""" """Running tests"""
import os
import sys import sys
import time import time
import warnings import warnings
@ -38,7 +39,7 @@ class TextTestResult(result.TestResult):
super(TextTestResult, self).__init__(stream, descriptions, verbosity) super(TextTestResult, self).__init__(stream, descriptions, verbosity)
self.stream = stream self.stream = stream
self.showAll = verbosity > 1 self.showAll = verbosity > 1
self.dots = verbosity == 1 self.dots = verbosity == 1 and os.getenv('MAKEFLAGS') is None
self.descriptions = descriptions self.descriptions = descriptions
def getDescription(self, test): def getDescription(self, test):
@ -183,8 +184,12 @@ class TextTestRunner(object):
result.printErrors() result.printErrors()
# [jart local modification] # [jart local modification]
# [print nothing on success in quiet mode] # print nothing on success, if
if not self.verbosity and result.wasSuccessful(): # 1. running in quiet mode, or
# 2. running under gnu make
if ((not self.verbosity or
os.getenv('MAKEFLAGS') is not None) and
result.wasSuccessful()):
return result return result
if hasattr(result, 'separator2'): if hasattr(result, 'separator2'):

View file

@ -493,13 +493,13 @@ except ImportError:
filters = [] filters = []
defaultaction = "default" defaultaction = "default"
onceregistry = {} onceregistry = {}
_filters_version = 1 _filters_version = 1
def _filters_mutated(): def _filters_mutated():
global _filters_version global _filters_version
_filters_version += 1 _filters_version += 1
if __name__ == 'PYOBJ.COM':
import _warnings
# Module initialization # Module initialization
_processoptions(sys.warnoptions) _processoptions(sys.warnoptions)

View file

@ -95,6 +95,9 @@ PYTHON_PROVIDE("_decimal.getcontext");
PYTHON_PROVIDE("_decimal.localcontext"); PYTHON_PROVIDE("_decimal.localcontext");
PYTHON_PROVIDE("_decimal.setcontext"); PYTHON_PROVIDE("_decimal.setcontext");
PYTHON_YOINK("numbers");
PYTHON_YOINK("collections");
asm(".ident\t\"\\n\ asm(".ident\t\"\\n\
libmpdec (BSD-2)\\n\ libmpdec (BSD-2)\\n\
Copyright 2008-2016 Stefan Krah\""); Copyright 2008-2016 Stefan Krah\"");

View file

@ -5,6 +5,10 @@
https://docs.python.org/3/license.html │ https://docs.python.org/3/license.html │
*/ */
#define PY_SSIZE_T_CLEAN #define PY_SSIZE_T_CLEAN
#include "libc/calls/calls.h"
#include "libc/log/backtrace.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "third_party/mbedtls/error.h" #include "third_party/mbedtls/error.h"
#include "third_party/mbedtls/md.h" #include "third_party/mbedtls/md.h"
#include "third_party/python/Include/Python.h" #include "third_party/python/Include/Python.h"
@ -32,12 +36,13 @@ PYTHON_PROVIDE("_hashlib.mbedtls_sha384");
PYTHON_PROVIDE("_hashlib.mbedtls_sha512"); PYTHON_PROVIDE("_hashlib.mbedtls_sha512");
#include "third_party/python/Modules/clinic/_hashmbedtls.inc" #include "third_party/python/Modules/clinic/_hashmbedtls.inc"
/*[clinic input] /*[clinic input]
module _hashlib module _hashlib
[clinic start generated code]*/ [clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=c2b4ff081bac4be1]*/ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=c2b4ff081bac4be1]*/
#define MUNCH_SIZE INT_MAX #define MUNCH_SIZE 65536
#ifndef HASH_OBJ_CONSTRUCTOR #ifndef HASH_OBJ_CONSTRUCTOR
#define HASH_OBJ_CONSTRUCTOR 0 #define HASH_OBJ_CONSTRUCTOR 0
@ -46,7 +51,7 @@ module _hashlib
typedef struct { typedef struct {
PyObject_HEAD PyObject_HEAD
PyObject *name; PyObject *name;
mbedtls_md_context_t *ctx; mbedtls_md_context_t ctx;
#ifdef WITH_THREAD #ifdef WITH_THREAD
PyThread_type_lock lock; PyThread_type_lock lock;
#endif #endif
@ -54,68 +59,55 @@ typedef struct {
static PyTypeObject EVPtype; static PyTypeObject EVPtype;
#define DEFINE_CONSTS_FOR_NEW(Name) \ static PyObject *CONST_MD5_name_obj;
static PyObject *CONST_ ## Name ## _name_obj = NULL; \ static PyObject *CONST_SHA1_name_obj;
static mbedtls_md_context_t *CONST_new_ ## Name ## _ctx_p = NULL static PyObject *CONST_SHA224_name_obj;
static PyObject *CONST_SHA256_name_obj;
static PyObject *CONST_SHA384_name_obj;
static PyObject *CONST_SHA512_name_obj;
static PyObject *CONST_BLAKE2B256_name_obj;
DEFINE_CONSTS_FOR_NEW(md5);
DEFINE_CONSTS_FOR_NEW(sha1);
DEFINE_CONSTS_FOR_NEW(sha224);
DEFINE_CONSTS_FOR_NEW(sha256);
DEFINE_CONSTS_FOR_NEW(sha384);
DEFINE_CONSTS_FOR_NEW(sha512);
DEFINE_CONSTS_FOR_NEW(blake2b256);
/* LCOV_EXCL_START */
static PyObject * static PyObject *
_setException(PyObject *exc, int rc) SetMbedtlsError(PyObject *exc, int rc)
{ {
char b[128]; char b[128];
mbedtls_strerror(rc, b, sizeof(b)); mbedtls_strerror(rc, b, sizeof(b));
PyErr_SetString(exc, b); PyErr_SetString(exc, b);
return NULL; return NULL;
} }
/* LCOV_EXCL_STOP */
static EVPobject * static EVPobject *
newEVPobject(PyObject *name) newEVPobject(PyObject *name)
{ {
EVPobject *retval = (EVPobject *)PyObject_New(EVPobject, &EVPtype); EVPobject *self;
if (retval == NULL) { if ((self = PyObject_New(EVPobject, &EVPtype))) {
return NULL; mbedtls_md_init(&self->ctx);
} Py_INCREF(name);
retval->ctx = calloc(1, sizeof(mbedtls_md_context_t)); self->name = name;
if (retval->ctx == NULL) {
PyErr_NoMemory();
return NULL;
}
/* save the name for .name to return */
Py_INCREF(name);
retval->name = name;
#ifdef WITH_THREAD #ifdef WITH_THREAD
retval->lock = NULL; self->lock = 0;
#endif #endif
return retval; }
return self;
} }
static void static int
EVP_hash(EVPobject *self, const void *vp, Py_ssize_t len) EVP_hash(EVPobject *self, const void *vp, Py_ssize_t len)
{ {
int rc; int rc;
unsigned int process; unsigned int process;
const unsigned char *cp = (const unsigned char *)vp; const unsigned char *cp;
while (0 < len) { for (cp = vp; 0 < len; len -= process, cp += process) {
if (len > (Py_ssize_t)MUNCH_SIZE) if (len > MUNCH_SIZE) {
process = MUNCH_SIZE; process = MUNCH_SIZE;
else } else {
process = Py_SAFE_DOWNCAST(len, Py_ssize_t, unsigned int); process = Py_SAFE_DOWNCAST(len, Py_ssize_t, unsigned int);
if ((rc = mbedtls_md_update(self->ctx, (const void*)cp, process))) {
_setException(PyExc_ValueError, rc);
break;
} }
len -= process; if ((rc = mbedtls_md_update(&self->ctx, cp, process)) < 0) {
cp += process; return rc;
}
} }
return 0;
} }
/* Internal methods for a hash object */ /* Internal methods for a hash object */
@ -124,11 +116,10 @@ static void
EVP_dealloc(EVPobject *self) EVP_dealloc(EVPobject *self)
{ {
#ifdef WITH_THREAD #ifdef WITH_THREAD
if (self->lock != NULL) if (self->lock)
PyThread_free_lock(self->lock); PyThread_free_lock(self->lock);
#endif #endif
mbedtls_md_free(self->ctx); mbedtls_md_free(&self->ctx);
free(self->ctx);
Py_XDECREF(self->name); Py_XDECREF(self->name);
PyObject_Del(self); PyObject_Del(self);
} }
@ -138,7 +129,9 @@ locked_mbedtls_md_clone(mbedtls_md_context_t *new_ctx_p, EVPobject *self)
{ {
int rc; int rc;
ENTER_HASHLIB(self); ENTER_HASHLIB(self);
rc = mbedtls_md_clone(new_ctx_p, self->ctx); if (!(rc = mbedtls_md_setup(new_ctx_p, self->ctx.md_info, 0))) {
rc = mbedtls_md_clone(new_ctx_p, &self->ctx);
}
LEAVE_HASHLIB(self); LEAVE_HASHLIB(self);
return rc; return rc;
} }
@ -152,10 +145,11 @@ EVP_copy(EVPobject *self, PyObject *unused)
{ {
int rc; int rc;
EVPobject *newobj; EVPobject *newobj;
if ( (newobj = newEVPobject(self->name))==NULL) if ((newobj = newEVPobject(self->name))) {
return NULL; if ((rc = locked_mbedtls_md_clone(&newobj->ctx, self))) {
if ((rc = locked_mbedtls_md_clone(newobj->ctx, self))) { EVP_dealloc(newobj);
return _setException(PyExc_ValueError, rc); return SetMbedtlsError(PyExc_ValueError, rc);
}
} }
return (PyObject *)newobj; return (PyObject *)newobj;
} }
@ -167,25 +161,22 @@ static PyObject *
EVP_digest(EVPobject *self, PyObject *unused) EVP_digest(EVPobject *self, PyObject *unused)
{ {
int rc; int rc;
unsigned char digest[MBEDTLS_MD_MAX_SIZE];
mbedtls_md_context_t *temp_ctx;
PyObject *retval; PyObject *retval;
unsigned int digest_size; unsigned int digest_size;
temp_ctx = calloc(1, sizeof(mbedtls_md_context_t)); mbedtls_md_context_t temp_ctx;
if (temp_ctx == NULL) { unsigned char digest[MBEDTLS_MD_MAX_SIZE];
PyErr_NoMemory(); mbedtls_md_init(&temp_ctx);
return NULL; if (!(rc = locked_mbedtls_md_clone(&temp_ctx, self))) {
digest_size = mbedtls_md_get_size(temp_ctx.md_info);
if (!(rc = mbedtls_md_finish(&temp_ctx, digest))) {
retval = PyBytes_FromStringAndSize((const char *)digest, digest_size);
} else {
retval = SetMbedtlsError(PyExc_ValueError, rc);
}
} else {
retval = SetMbedtlsError(PyExc_ValueError, rc);
} }
if ((rc = locked_mbedtls_md_clone(temp_ctx, self))) { mbedtls_md_free(&temp_ctx);
return _setException(PyExc_ValueError, rc);
}
digest_size = mbedtls_md_get_size(temp_ctx->md_info);
if ((rc = mbedtls_md_finish(temp_ctx, digest))) {
_setException(PyExc_ValueError, rc);
return NULL;
}
retval = PyBytes_FromStringAndSize((const char *)digest, digest_size);
mbedtls_md_free(temp_ctx);
return retval; return retval;
} }
@ -196,25 +187,23 @@ static PyObject *
EVP_hexdigest(EVPobject *self, PyObject *unused) EVP_hexdigest(EVPobject *self, PyObject *unused)
{ {
int rc; int rc;
unsigned char digest[MBEDTLS_MD_MAX_SIZE]; PyObject *retval;
mbedtls_md_context_t *temp_ctx;
unsigned int digest_size; unsigned int digest_size;
temp_ctx = calloc(1, sizeof(mbedtls_md_context_t)); mbedtls_md_context_t temp_ctx;
if (temp_ctx == NULL) { unsigned char digest[MBEDTLS_MD_MAX_SIZE];
PyErr_NoMemory(); mbedtls_md_init(&temp_ctx);
return NULL; if (!(rc = locked_mbedtls_md_clone(&temp_ctx, self))) {
digest_size = mbedtls_md_get_size(temp_ctx.md_info);
if (!(rc = mbedtls_md_finish(&temp_ctx, digest))) {
retval = _Py_strhex((const char *)digest, digest_size);
} else {
retval = SetMbedtlsError(PyExc_ValueError, rc);
}
} else {
retval = SetMbedtlsError(PyExc_ValueError, rc);
} }
/* Get the raw (binary) digest value */ mbedtls_md_free(&temp_ctx);
if ((rc = locked_mbedtls_md_clone(temp_ctx, self))) { return retval;
return _setException(PyExc_ValueError, rc);
}
digest_size = mbedtls_md_get_size(temp_ctx->md_info);
if ((rc = mbedtls_md_finish(temp_ctx, digest))) {
_setException(PyExc_ValueError, rc);
return NULL;
}
mbedtls_md_free(temp_ctx);
return _Py_strhex((const char *)digest, digest_size);
} }
PyDoc_STRVAR(EVP_update__doc__, PyDoc_STRVAR(EVP_update__doc__,
@ -225,26 +214,9 @@ EVP_update(EVPobject *self, PyObject *args)
{ {
PyObject *obj; PyObject *obj;
Py_buffer view; Py_buffer view;
if (!PyArg_ParseTuple(args, "O:update", &obj)) if (!PyArg_ParseTuple(args, "O:update", &obj)) return 0;
return NULL;
GET_BUFFER_VIEW_OR_ERROUT(obj, &view); GET_BUFFER_VIEW_OR_ERROUT(obj, &view);
#ifdef WITH_THREAD
if (self->lock == NULL && view.len >= HASHLIB_GIL_MINSIZE) {
self->lock = PyThread_allocate_lock();
/* fail? lock = NULL and we fail over to non-threaded code. */
}
if (self->lock != NULL) {
Py_BEGIN_ALLOW_THREADS
PyThread_acquire_lock(self->lock, 1);
EVP_hash(self, view.buf, view.len);
PyThread_release_lock(self->lock);
Py_END_ALLOW_THREADS
} else {
EVP_hash(self, view.buf, view.len);
}
#else
EVP_hash(self, view.buf, view.len); EVP_hash(self, view.buf, view.len);
#endif
PyBuffer_Release(&view); PyBuffer_Release(&view);
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -260,37 +232,26 @@ static PyMethodDef EVP_methods[] = {
static PyObject * static PyObject *
EVP_get_block_size(EVPobject *self, void *closure) EVP_get_block_size(EVPobject *self, void *closure)
{ {
long block_size; return PyLong_FromLong(mbedtls_md_get_block_size(self->ctx.md_info));
block_size = mbedtls_md_get_block_size(self->ctx->md_info);
return PyLong_FromLong(block_size);
} }
static PyObject * static PyObject *
EVP_get_digest_size(EVPobject *self, void *closure) EVP_get_digest_size(EVPobject *self, void *closure)
{ {
long size; return PyLong_FromLong(mbedtls_md_get_size(self->ctx.md_info));
size = mbedtls_md_get_size(self->ctx->md_info);
return PyLong_FromLong(size);
} }
static PyMemberDef EVP_members[] = { static PyMemberDef EVP_members[] = {
{"name", T_OBJECT, offsetof(EVPobject, name), READONLY, PyDoc_STR("algorithm name.")}, {"name", T_OBJECT, offsetof(EVPobject, name), READONLY, PyDoc_STR("algorithm name.")},
{NULL} /* Sentinel */ {NULL}
}; };
static PyGetSetDef EVP_getseters[] = { static PyGetSetDef EVP_getseters[] = {
{"digest_size", {"digest_size", (getter)EVP_get_digest_size, NULL, NULL, NULL},
(getter)EVP_get_digest_size, NULL, {"block_size", (getter)EVP_get_block_size, NULL, NULL, NULL},
NULL, {NULL}
NULL},
{"block_size",
(getter)EVP_get_block_size, NULL,
NULL,
NULL},
{NULL} /* Sentinel */
}; };
static PyObject * static PyObject *
EVP_repr(EVPobject *self) EVP_repr(EVPobject *self)
{ {
@ -298,6 +259,7 @@ EVP_repr(EVPobject *self)
} }
#if HASH_OBJ_CONSTRUCTOR #if HASH_OBJ_CONSTRUCTOR
#error wut
static int static int
EVP_tp_init(EVPobject *self, PyObject *args, PyObject *kwds) EVP_tp_init(EVPobject *self, PyObject *args, PyObject *kwds)
{ {
@ -327,7 +289,7 @@ EVP_tp_init(EVPobject *self, PyObject *args, PyObject *kwds)
return -1; return -1;
} }
if (!EVP_DigestInit(self->ctx, digest)) { if (!EVP_DigestInit(self->ctx, digest)) {
_setException(PyExc_ValueError); SetMbedtlsError(PyExc_ValueError);
if (data_obj) if (data_obj)
PyBuffer_Release(&view); PyBuffer_Release(&view);
return -1; return -1;
@ -411,25 +373,20 @@ static PyTypeObject EVPtype = {
static PyObject * static PyObject *
EVPnew(PyObject *name_obj, EVPnew(PyObject *name_obj,
const mbedtls_md_info_t *digest, const mbedtls_md_info_t *digest,
const mbedtls_md_context_t *initial_ctx,
const unsigned char *cp, Py_ssize_t len) const unsigned char *cp, Py_ssize_t len)
{ {
int rc; int rc;
EVPobject *self; EVPobject *self;
if (!digest && !initial_ctx) { if (!digest) {
PyErr_SetString(PyExc_ValueError, "unsupported hash type"); PyErr_SetString(PyExc_ValueError, "unsupported hash type");
return NULL; return NULL;
} }
if ((self = newEVPobject(name_obj)) == NULL) if ((self = newEVPobject(name_obj)) == NULL)
return NULL; return NULL;
if (initial_ctx) { if ((rc = mbedtls_md_setup(&self->ctx, digest, 0))) {
mbedtls_md_clone(self->ctx, initial_ctx); SetMbedtlsError(PyExc_ValueError, rc);
} else { Py_DECREF(self);
if ((rc = mbedtls_md_setup(self->ctx, digest, 0))) { return NULL;
_setException(PyExc_ValueError, rc);
Py_DECREF(self);
return NULL;
}
} }
if (cp && len) { if (cp && len) {
if (len >= HASHLIB_GIL_MINSIZE) { if (len >= HASHLIB_GIL_MINSIZE) {
@ -474,7 +431,7 @@ EVP_new(PyObject *self, PyObject *args, PyObject *kwdict)
if (data_obj) if (data_obj)
GET_BUFFER_VIEW_OR_ERROUT(data_obj, &view); GET_BUFFER_VIEW_OR_ERROUT(data_obj, &view);
digest = mbedtls_md_info_from_string(name); digest = mbedtls_md_info_from_string(name);
ret_obj = EVPnew(name_obj, digest, NULL, (unsigned char*)view.buf, view.len); ret_obj = EVPnew(name_obj, digest, (unsigned char*)view.buf, view.len);
if (data_obj) if (data_obj)
PyBuffer_Release(&view); PyBuffer_Release(&view);
return ret_obj; return ret_obj;
@ -482,9 +439,7 @@ EVP_new(PyObject *self, PyObject *args, PyObject *kwdict)
#if (MBEDTLS_VERSION_NUMBER >= 0x10000000 && !defined(MBEDTLS_NO_HMAC) \ #if (MBEDTLS_VERSION_NUMBER >= 0x10000000 && !defined(MBEDTLS_NO_HMAC) \
&& !defined(MBEDTLS_NO_SHA)) && !defined(MBEDTLS_NO_SHA))
#define PY_PBKDF2_HMAC 1 #define PY_PBKDF2_HMAC 1
#if !HAS_FAST_PKCS5_PBKDF2_HMAC #if !HAS_FAST_PKCS5_PBKDF2_HMAC
/* Improved implementation of PKCS5_PBKDF2_HMAC() /* Improved implementation of PKCS5_PBKDF2_HMAC()
* *
@ -506,11 +461,9 @@ PKCS5_PBKDF2_HMAC_fast(const char *pass, int passlen,
int cplen, j, k, tkeylen, mdlen; int cplen, j, k, tkeylen, mdlen;
unsigned long i = 1; unsigned long i = 1;
HMAC_CTX hctx_tpl, hctx; HMAC_CTX hctx_tpl, hctx;
mdlen = mbedtls_md_get_size(digest); mdlen = mbedtls_md_get_size(digest);
if (mdlen < 0) if (mdlen < 0)
return 0; return 0;
HMAC_CTX_init(&hctx_tpl); HMAC_CTX_init(&hctx_tpl);
HMAC_CTX_init(&hctx); HMAC_CTX_init(&hctx);
p = out; p = out;
@ -569,7 +522,6 @@ PKCS5_PBKDF2_HMAC_fast(const char *pass, int passlen,
} }
#endif #endif
PyDoc_STRVAR(pbkdf2_hmac__doc__, PyDoc_STRVAR(pbkdf2_hmac__doc__,
"pbkdf2_hmac(hash_name, password, salt, iterations, dklen=None) -> key\n\ "pbkdf2_hmac(hash_name, password, salt, iterations, dklen=None) -> key\n\
\n\ \n\
@ -587,31 +539,26 @@ pbkdf2_hmac(PyObject *self, PyObject *args, PyObject *kwdict)
long iterations, dklen; long iterations, dklen;
int retval; int retval;
const mbedtls_md_info_t *digest; const mbedtls_md_info_t *digest;
if (!PyArg_ParseTupleAndKeywords(args, kwdict, "sy*y*l|O:pbkdf2_hmac", if (!PyArg_ParseTupleAndKeywords(args, kwdict, "sy*y*l|O:pbkdf2_hmac",
kwlist, &name, &password, &salt, kwlist, &name, &password, &salt,
&iterations, &dklen_obj)) { &iterations, &dklen_obj)) {
return NULL; return NULL;
} }
digest = mbedtls_md_info_from_string(name); digest = mbedtls_md_info_from_string(name);
if (digest == NULL) { if (digest == NULL) {
PyErr_SetString(PyExc_ValueError, "unsupported hash type"); PyErr_SetString(PyExc_ValueError, "unsupported hash type");
goto end; goto end;
} }
if (password.len > INT_MAX) { if (password.len > INT_MAX) {
PyErr_SetString(PyExc_OverflowError, PyErr_SetString(PyExc_OverflowError,
"password is too long."); "password is too long.");
goto end; goto end;
} }
if (salt.len > INT_MAX) { if (salt.len > INT_MAX) {
PyErr_SetString(PyExc_OverflowError, PyErr_SetString(PyExc_OverflowError,
"salt is too long."); "salt is too long.");
goto end; goto end;
} }
if (iterations < 1) { if (iterations < 1) {
PyErr_SetString(PyExc_ValueError, PyErr_SetString(PyExc_ValueError,
"iteration value must be greater than 0."); "iteration value must be greater than 0.");
@ -622,7 +569,6 @@ pbkdf2_hmac(PyObject *self, PyObject *args, PyObject *kwdict)
"iteration value is too great."); "iteration value is too great.");
goto end; goto end;
} }
if (dklen_obj == Py_None) { if (dklen_obj == Py_None) {
dklen = mbedtls_md_get_size(digest); dklen = mbedtls_md_get_size(digest);
} else { } else {
@ -642,13 +588,11 @@ pbkdf2_hmac(PyObject *self, PyObject *args, PyObject *kwdict)
"key length is too great."); "key length is too great.");
goto end; goto end;
} }
key_obj = PyBytes_FromStringAndSize(NULL, dklen); key_obj = PyBytes_FromStringAndSize(NULL, dklen);
if (key_obj == NULL) { if (key_obj == NULL) {
goto end; goto end;
} }
key = PyBytes_AS_STRING(key_obj); key = PyBytes_AS_STRING(key_obj);
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
#if HAS_FAST_PKCS5_PBKDF2_HMAC #if HAS_FAST_PKCS5_PBKDF2_HMAC
retval = PKCS5_PBKDF2_HMAC((char*)password.buf, (int)password.len, retval = PKCS5_PBKDF2_HMAC((char*)password.buf, (int)password.len,
@ -662,19 +606,16 @@ pbkdf2_hmac(PyObject *self, PyObject *args, PyObject *kwdict)
(unsigned char *)key); (unsigned char *)key);
#endif #endif
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
if (retval) { if (retval) {
Py_CLEAR(key_obj); Py_CLEAR(key_obj);
_setException(PyExc_ValueError, retval); SetMbedtlsError(PyExc_ValueError, retval);
goto end; goto end;
} }
end: end:
PyBuffer_Release(&password); PyBuffer_Release(&password);
PyBuffer_Release(&salt); PyBuffer_Release(&salt);
return key_obj; return key_obj;
} }
#endif #endif
#if MBEDTLS_VERSION_NUMBER > 0x10100000L && !defined(MBEDTLS_NO_SCRYPT) && !defined(LIBRESSL_VERSION_NUMBER) #if MBEDTLS_VERSION_NUMBER > 0x10100000L && !defined(MBEDTLS_NO_SCRYPT) && !defined(LIBRESSL_VERSION_NUMBER)
@ -783,7 +724,7 @@ _hashlib_scrypt_impl(PyObject *module, Py_buffer *password, Py_buffer *salt,
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
if (!retval) { if (!retval) {
Py_CLEAR(key_obj); Py_CLEAR(key_obj);
_setException(PyExc_ValueError); SetMbedtlsError(PyExc_ValueError);
return NULL; return NULL;
} }
return key_obj; return key_obj;
@ -791,15 +732,20 @@ _hashlib_scrypt_impl(PyObject *module, Py_buffer *password, Py_buffer *salt,
#endif #endif
static PyObject * static PyObject *
generate_hash_name_list(void) GenerateHashNameList(void)
{ {
int i;
char *s;
uint8_t *p; uint8_t *p;
PyObject *set, *name; PyObject *set, *name;
if ((set = PyFrozenSet_New(0))) { if ((set = PyFrozenSet_New(0))) {
for (p = mbedtls_md_list(); *p != MBEDTLS_MD_NONE; ++p) { for (p = mbedtls_md_list(); *p != MBEDTLS_MD_NONE; ++p) {
name = PyUnicode_FromString(mbedtls_md_info_from_type(*p)->name); s = strdup(mbedtls_md_info_from_type(*p)->name);
for (i = 0; s[i]; ++i) s[i] = tolower(s[i]);
name = PyUnicode_FromString(s);
PySet_Add(set, name); PySet_Add(set, name);
Py_DECREF(name); Py_DECREF(name);
free(s);
} }
} }
return set; return set;
@ -814,67 +760,43 @@ generate_hash_name_list(void)
* The first call will lazy-initialize, which reports an exception * The first call will lazy-initialize, which reports an exception
* if initialization fails. * if initialization fails.
*/ */
#define GEN_CONSTRUCTOR(NAME) \ #define GEN_CONSTRUCTOR(NAME, STRNAME) \
static PyObject * \ static PyObject * \
EVP_new_ ## NAME (PyObject *self, PyObject *args) \ EVP_new_ ## NAME (PyObject *self, PyObject *args) \
{ \ { \
int rc; \ PyObject *ret; \
PyObject *data_obj = NULL; \ PyObject *data = 0; \
Py_buffer view = { 0 }; \ Py_buffer view = { 0 }; \
PyObject *ret_obj; \ if (!PyArg_ParseTuple(args, "|O:" STRNAME , &data)) return 0; \
\ if (data) GET_BUFFER_VIEW_OR_ERROUT(data, &view); \
if (!PyArg_ParseTuple(args, "|O:" #NAME , &data_obj)) { \ ret = EVPnew(CONST_ ## NAME ## _name_obj, \
return NULL; \ mbedtls_md_info_from_type(MBEDTLS_MD_ ## NAME), \
} \ (unsigned char *)view.buf, view.len); \
\ if (data) PyBuffer_Release(&view); \
if (CONST_new_ ## NAME ## _ctx_p == NULL) { \ return ret; \
mbedtls_md_context_t *ctx_p = calloc(1, sizeof(mbedtls_md_context_t)); \
rc = MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE; \
if (!mbedtls_md_info_from_string(#NAME) || \
(rc = mbedtls_md_setup(ctx_p, mbedtls_md_info_from_string(#NAME), 0))) { \
_setException(PyExc_ValueError, rc); \
mbedtls_md_free(ctx_p); \
return NULL; \
} \
CONST_new_ ## NAME ## _ctx_p = ctx_p; \
} \
\
if (data_obj) \
GET_BUFFER_VIEW_OR_ERROUT(data_obj, &view); \
\
ret_obj = EVPnew( \
CONST_ ## NAME ## _name_obj, \
NULL, \
CONST_new_ ## NAME ## _ctx_p, \
(unsigned char*)view.buf, \
view.len); \
\
if (data_obj) \
PyBuffer_Release(&view); \
return ret_obj; \
} }
/* a PyMethodDef structure for the constructor */ /* a PyMethodDef structure for the constructor */
#define CONSTRUCTOR_METH_DEF(NAME) \ #define CONSTRUCTOR_METH_DEF(NAME, STRNAME) \
{"mbedtls_" #NAME, (PyCFunction)EVP_new_ ## NAME, METH_VARARGS, \ {"mbedtls_" STRNAME, (PyCFunction)EVP_new_ ## NAME, METH_VARARGS, \
PyDoc_STR("Returns a " #NAME \ PyDoc_STR("Returns a " STRNAME \
" hash object; optionally initialized with a string") \ " hash object; optionally initialized with a string") \
} }
/* used in the init function to setup a constructor: initialize Mbedtls /* used in the init function to setup a constructor: initialize Mbedtls
constructor constants if they haven't been initialized already. */ constructor constants if they haven't been initialized already. */
#define INIT_CONSTRUCTOR_CONSTANTS(NAME) \ #define INIT_CONSTRUCTOR_CONSTANTS(NAME, STRNAME) \
if (CONST_ ## NAME ## _name_obj == NULL) { \ if (CONST_ ## NAME ## _name_obj == NULL) { \
CONST_ ## NAME ## _name_obj = PyUnicode_FromString(#NAME);\ CONST_ ## NAME ## _name_obj = PyUnicode_FromString(#NAME); \
} }
GEN_CONSTRUCTOR(md5) GEN_CONSTRUCTOR(MD5, "md5")
GEN_CONSTRUCTOR(sha1) GEN_CONSTRUCTOR(SHA1, "sha1")
GEN_CONSTRUCTOR(sha224) GEN_CONSTRUCTOR(SHA224, "sha224")
GEN_CONSTRUCTOR(sha256) GEN_CONSTRUCTOR(SHA256, "sha256")
GEN_CONSTRUCTOR(sha384) GEN_CONSTRUCTOR(SHA384, "sha384")
GEN_CONSTRUCTOR(sha512) GEN_CONSTRUCTOR(SHA512, "sha512")
GEN_CONSTRUCTOR(blake2b256) GEN_CONSTRUCTOR(BLAKE2B256, "blake2b256")
/* List of functions exported by this module */ /* List of functions exported by this module */
@ -885,14 +807,14 @@ static struct PyMethodDef EVP_functions[] = {
pbkdf2_hmac__doc__}, pbkdf2_hmac__doc__},
#endif #endif
_HASHLIB_SCRYPT_METHODDEF _HASHLIB_SCRYPT_METHODDEF
CONSTRUCTOR_METH_DEF(md5), CONSTRUCTOR_METH_DEF(MD5, "md5"),
CONSTRUCTOR_METH_DEF(sha1), CONSTRUCTOR_METH_DEF(SHA1, "sha1"),
CONSTRUCTOR_METH_DEF(sha224), CONSTRUCTOR_METH_DEF(SHA224, "sha224"),
CONSTRUCTOR_METH_DEF(sha256), CONSTRUCTOR_METH_DEF(SHA256, "sha256"),
CONSTRUCTOR_METH_DEF(sha384), CONSTRUCTOR_METH_DEF(SHA384, "sha384"),
CONSTRUCTOR_METH_DEF(sha512), CONSTRUCTOR_METH_DEF(SHA512, "sha512"),
CONSTRUCTOR_METH_DEF(blake2b256), CONSTRUCTOR_METH_DEF(BLAKE2B256, "blake2b256"),
{NULL, NULL} /* Sentinel */ {NULL}
}; };
static struct PyModuleDef _hashlibmodule = { static struct PyModuleDef _hashlibmodule = {
@ -911,18 +833,12 @@ PyMODINIT_FUNC
PyInit__hashlib(void) PyInit__hashlib(void)
{ {
PyObject *m, *mbedtls_md_meth_names; PyObject *m, *mbedtls_md_meth_names;
/* TODO build EVP_functions mbedtls_* entries dynamically based
* on what hashes are supported rather than listing many
* but having some be unsupported. Only init appropriate
* constants. */
Py_TYPE(&EVPtype) = &PyType_Type; Py_TYPE(&EVPtype) = &PyType_Type;
if (PyType_Ready(&EVPtype) < 0) if (PyType_Ready(&EVPtype) < 0)
return NULL; return NULL;
m = PyModule_Create(&_hashlibmodule); if (!(m = PyModule_Create(&_hashlibmodule)))
if (m == NULL)
return NULL; return NULL;
mbedtls_md_meth_names = generate_hash_name_list(); if (!(mbedtls_md_meth_names = GenerateHashNameList())) {
if (mbedtls_md_meth_names == NULL) {
Py_DECREF(m); Py_DECREF(m);
return NULL; return NULL;
} }
@ -932,14 +848,13 @@ PyInit__hashlib(void)
} }
Py_INCREF((PyObject *)&EVPtype); Py_INCREF((PyObject *)&EVPtype);
PyModule_AddObject(m, "HASH", (PyObject *)&EVPtype); PyModule_AddObject(m, "HASH", (PyObject *)&EVPtype);
/* these constants are used by the convenience constructors */ INIT_CONSTRUCTOR_CONSTANTS(MD5, "md5")
INIT_CONSTRUCTOR_CONSTANTS(md5) INIT_CONSTRUCTOR_CONSTANTS(SHA1, "sha1")
INIT_CONSTRUCTOR_CONSTANTS(sha1) INIT_CONSTRUCTOR_CONSTANTS(SHA224, "sha224")
INIT_CONSTRUCTOR_CONSTANTS(sha224) INIT_CONSTRUCTOR_CONSTANTS(SHA256, "sha256")
INIT_CONSTRUCTOR_CONSTANTS(sha256) INIT_CONSTRUCTOR_CONSTANTS(SHA384, "sha384")
INIT_CONSTRUCTOR_CONSTANTS(sha384) INIT_CONSTRUCTOR_CONSTANTS(SHA512, "sha512")
INIT_CONSTRUCTOR_CONSTANTS(sha512) INIT_CONSTRUCTOR_CONSTANTS(BLAKE2B256, "blake2b256")
INIT_CONSTRUCTOR_CONSTANTS(blake2b256)
return m; return m;
} }

View file

@ -22,6 +22,7 @@
#include "third_party/python/Include/warnings.h" #include "third_party/python/Include/warnings.h"
#include "third_party/python/Include/yoink.h" #include "third_party/python/Include/yoink.h"
#include "third_party/python/Modules/sre.h" #include "third_party/python/Modules/sre.h"
#include "third_party/python/Modules/sre_constants.h"
/* clang-format off */ /* clang-format off */
PYTHON_PROVIDE("_sre"); PYTHON_PROVIDE("_sre");
@ -182,7 +183,6 @@ LOCAL(int)
sre_category(SRE_CODE category, unsigned int ch) sre_category(SRE_CODE category, unsigned int ch)
{ {
switch (category) { switch (category) {
case SRE_CATEGORY_DIGIT: case SRE_CATEGORY_DIGIT:
return SRE_IS_DIGIT(ch); return SRE_IS_DIGIT(ch);
case SRE_CATEGORY_NOT_DIGIT: case SRE_CATEGORY_NOT_DIGIT:

View file

@ -1,19 +0,0 @@
/* clang-format off */
/* File generated by Tools/ssl/make_ssl_data.py */
/* Generated on 2015-01-17T20:33:43.377453 */
#define ERR_LIB_PEM 1
#define ERR_LIB_X509 2
#define ERR_LIB_SSL 6
static struct py_ssl_library_code library_codes[] = {
{"PEM", ERR_LIB_PEM},
{"SSL", ERR_LIB_SSL},
{"X509", ERR_LIB_X509},
{ NULL }
};
static struct py_ssl_error_code error_codes[] = {
{"BAD_BASE64_DECODE", ERR_LIB_PEM, MBEDTLS_ERR_PEM_INVALID_DATA + MBEDTLS_ERR_BASE64_INVALID_CHARACTER},
{ NULL }
};

View file

@ -26,7 +26,6 @@ PyObject *PyInit__datetime(void);
PyObject *PyInit__decimal(void); PyObject *PyInit__decimal(void);
PyObject *PyInit__elementtree(void); PyObject *PyInit__elementtree(void);
PyObject *PyInit__functools(void); PyObject *PyInit__functools(void);
PyObject *PyInit__hashlib(void);
PyObject *PyInit__heapq(void); PyObject *PyInit__heapq(void);
PyObject *PyInit__io(void); PyObject *PyInit__io(void);
PyObject *PyInit__json(void); PyObject *PyInit__json(void);

View file

@ -29,6 +29,8 @@ PYTHON_PROVIDE("fcntl");
PYTHON_PROVIDE("fcntl.FD_CLOEXEC"); PYTHON_PROVIDE("fcntl.FD_CLOEXEC");
PYTHON_PROVIDE("fcntl.F_DUPFD"); PYTHON_PROVIDE("fcntl.F_DUPFD");
PYTHON_PROVIDE("fcntl.F_DUPFD_CLOEXEC"); PYTHON_PROVIDE("fcntl.F_DUPFD_CLOEXEC");
PYTHON_PROVIDE("fcntl.F_EXLCK");
PYTHON_PROVIDE("fcntl.F_FULLFSYNC");
PYTHON_PROVIDE("fcntl.F_GETFD"); PYTHON_PROVIDE("fcntl.F_GETFD");
PYTHON_PROVIDE("fcntl.F_GETFL"); PYTHON_PROVIDE("fcntl.F_GETFL");
PYTHON_PROVIDE("fcntl.F_GETLEASE"); PYTHON_PROVIDE("fcntl.F_GETLEASE");
@ -36,6 +38,7 @@ PYTHON_PROVIDE("fcntl.F_GETLK");
PYTHON_PROVIDE("fcntl.F_GETLK64"); PYTHON_PROVIDE("fcntl.F_GETLK64");
PYTHON_PROVIDE("fcntl.F_GETOWN"); PYTHON_PROVIDE("fcntl.F_GETOWN");
PYTHON_PROVIDE("fcntl.F_GETSIG"); PYTHON_PROVIDE("fcntl.F_GETSIG");
PYTHON_PROVIDE("fcntl.F_NOCACHE");
PYTHON_PROVIDE("fcntl.F_NOTIFY"); PYTHON_PROVIDE("fcntl.F_NOTIFY");
PYTHON_PROVIDE("fcntl.F_RDLCK"); PYTHON_PROVIDE("fcntl.F_RDLCK");
PYTHON_PROVIDE("fcntl.F_SETFD"); PYTHON_PROVIDE("fcntl.F_SETFD");
@ -47,6 +50,7 @@ PYTHON_PROVIDE("fcntl.F_SETLKW");
PYTHON_PROVIDE("fcntl.F_SETLKW64"); PYTHON_PROVIDE("fcntl.F_SETLKW64");
PYTHON_PROVIDE("fcntl.F_SETOWN"); PYTHON_PROVIDE("fcntl.F_SETOWN");
PYTHON_PROVIDE("fcntl.F_SETSIG"); PYTHON_PROVIDE("fcntl.F_SETSIG");
PYTHON_PROVIDE("fcntl.F_SHLCK");
PYTHON_PROVIDE("fcntl.F_UNLCK"); PYTHON_PROVIDE("fcntl.F_UNLCK");
PYTHON_PROVIDE("fcntl.F_WRLCK"); PYTHON_PROVIDE("fcntl.F_WRLCK");
PYTHON_PROVIDE("fcntl.LOCK_EX"); PYTHON_PROVIDE("fcntl.LOCK_EX");
@ -57,6 +61,7 @@ PYTHON_PROVIDE("fcntl.fcntl");
PYTHON_PROVIDE("fcntl.flock"); PYTHON_PROVIDE("fcntl.flock");
PYTHON_PROVIDE("fcntl.ioctl"); PYTHON_PROVIDE("fcntl.ioctl");
PYTHON_PROVIDE("fcntl.lockf"); PYTHON_PROVIDE("fcntl.lockf");
PYTHON_PROVIDE("fcntl.lockf");
/* fcntl module */ /* fcntl module */
@ -540,18 +545,6 @@ all_ins(PyObject* m)
#ifdef F_SETLKW #ifdef F_SETLKW
if (PyModule_AddIntMacro(m, F_SETLKW)) return -1; if (PyModule_AddIntMacro(m, F_SETLKW)) return -1;
#endif #endif
#ifdef F_GETOWN
if (PyModule_AddIntMacro(m, F_GETOWN)) return -1;
#endif
#ifdef F_SETOWN
if (PyModule_AddIntMacro(m, F_SETOWN)) return -1;
#endif
#ifdef F_GETSIG
if (PyModule_AddIntMacro(m, F_GETSIG)) return -1;
#endif
#ifdef F_SETSIG
if (PyModule_AddIntMacro(m, F_SETSIG)) return -1;
#endif
#ifdef F_RDLCK #ifdef F_RDLCK
if (PyModule_AddIntMacro(m, F_RDLCK)) return -1; if (PyModule_AddIntMacro(m, F_RDLCK)) return -1;
#endif #endif
@ -561,6 +554,18 @@ all_ins(PyObject* m)
#ifdef F_UNLCK #ifdef F_UNLCK
if (PyModule_AddIntMacro(m, F_UNLCK)) return -1; if (PyModule_AddIntMacro(m, F_UNLCK)) return -1;
#endif #endif
#ifdef F_GETOWN
if (F_GETOWN && PyModule_AddIntMacro(m, F_GETOWN)) return -1;
#endif
#ifdef F_SETOWN
if (F_SETOWN && PyModule_AddIntMacro(m, F_SETOWN)) return -1;
#endif
#ifdef F_GETSIG
if (F_GETSIG && PyModule_AddIntMacro(m, F_GETSIG)) return -1;
#endif
#ifdef F_SETSIG
if (F_SETSIG && PyModule_AddIntMacro(m, F_SETSIG)) return -1;
#endif
/* LFS constants */ /* LFS constants */
#ifdef F_GETLK64 #ifdef F_GETLK64
if (PyModule_AddIntMacro(m, F_GETLK64)) return -1; if (PyModule_AddIntMacro(m, F_GETLK64)) return -1;

View file

@ -38,19 +38,22 @@ STATIC_YOINK("PyInit__stat"); // for pylifecycle.o
STATIC_YOINK("PyInit_errno"); // for pylifecycle.o STATIC_YOINK("PyInit_errno"); // for pylifecycle.o
STATIC_YOINK("PyInit_itertools"); // for pylifecycle.o STATIC_YOINK("PyInit_itertools"); // for pylifecycle.o
PYTHON_YOINK("encodings.aliases"); // for pylifecycle.o
PYTHON_YOINK("encodings.latin_1"); // for pylifecycle.o
PYTHON_YOINK("encodings.utf_8"); // for pylifecycle.o
PYTHON_YOINK("io"); // for pylifecycle.o
PYTHON_YOINK("site"); // for pylifecycle.o PYTHON_YOINK("site"); // for pylifecycle.o
PYTHON_YOINK("struct"); // for memoryobject.o PYTHON_YOINK("struct"); // for memoryobject.o
PYTHON_YOINK("io");
PYTHON_YOINK("encodings.aliases");
PYTHON_YOINK("encodings.latin_1");
PYTHON_YOINK("encodings.utf_8");
PYTHON_YOINK("site");
PYTHON_YOINK("_sysconfigdata_m_cosmo_x86_64_cosmo");
PYTHON_YOINK("_bootlocale"); PYTHON_YOINK("_bootlocale");
PYTHON_YOINK("warnings");
PYTHON_YOINK("_locale"); PYTHON_YOINK("_locale");
PYTHON_YOINK("_sysconfigdata_m_cosmo_x86_64-cosmo");
PYTHON_YOINK("locale"); PYTHON_YOINK("locale");
PYTHON_YOINK("runpy"); PYTHON_YOINK("runpy");
PYTHON_YOINK("sysconfig");
/* Python interpreter main program */ /* Python interpreter main program */

View file

@ -16,6 +16,7 @@
#include "libc/calls/struct/winsize.h" #include "libc/calls/struct/winsize.h"
#include "libc/calls/termios.h" #include "libc/calls/termios.h"
#include "libc/calls/weirdtypes.h" #include "libc/calls/weirdtypes.h"
#include "libc/dce.h"
#include "libc/errno.h" #include "libc/errno.h"
#include "libc/log/log.h" #include "libc/log/log.h"
#include "libc/nt/dll.h" #include "libc/nt/dll.h"
@ -8881,7 +8882,6 @@ os__getdiskusage_impl(PyObject *module, Py_UNICODE *path)
{ {
BOOL retval; BOOL retval;
ULARGE_INTEGER _, total, free; ULARGE_INTEGER _, total, free;
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
retval = GetDiskFreeSpaceExW(path, &_, &total, &free); retval = GetDiskFreeSpaceExW(path, &_, &total, &free);
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
@ -11823,11 +11823,11 @@ all_ins(PyObject *m)
if (PyModule_AddIntMacro(m, O_CREAT)) return -1; if (PyModule_AddIntMacro(m, O_CREAT)) return -1;
if (PyModule_AddIntMacro(m, O_DIRECTORY)) return -1; if (PyModule_AddIntMacro(m, O_DIRECTORY)) return -1;
if (PyModule_AddIntMacro(m, O_LARGEFILE)) return -1; if (PyModule_AddIntMacro(m, O_LARGEFILE)) return -1;
if (PyModule_AddIntMacro(m, O_EXCL)) return -1;
if (O_DSYNC && PyModule_AddIntMacro(m, O_DSYNC)) return -1; if (O_DSYNC && PyModule_AddIntMacro(m, O_DSYNC)) return -1;
if (O_RSYNC && PyModule_AddIntMacro(m, O_RSYNC)) return -1; if (O_RSYNC && PyModule_AddIntMacro(m, O_RSYNC)) return -1;
if (O_SYNC && PyModule_AddIntMacro(m, O_SYNC)) return -1; if (O_SYNC && PyModule_AddIntMacro(m, O_SYNC)) return -1;
if (O_NOCTTY && PyModule_AddIntMacro(m, O_NOCTTY)) return -1; if (O_NOCTTY && PyModule_AddIntMacro(m, O_NOCTTY)) return -1;
if (O_EXCL && PyModule_AddIntMacro(m, O_EXCL)) return -1;
if (O_TRUNC && PyModule_AddIntMacro(m, O_TRUNC)) return -1; if (O_TRUNC && PyModule_AddIntMacro(m, O_TRUNC)) return -1;
if (O_EXEC && PyModule_AddIntMacro(m, O_EXEC)) return -1; if (O_EXEC && PyModule_AddIntMacro(m, O_EXEC)) return -1;
if (O_SEARCH && PyModule_AddIntMacro(m, O_SEARCH)) return -1; if (O_SEARCH && PyModule_AddIntMacro(m, O_SEARCH)) return -1;
@ -11892,6 +11892,7 @@ all_ins(PyObject *m)
if (PyModule_AddIntMacro(m, EX_NOPERM)) return -1; if (PyModule_AddIntMacro(m, EX_NOPERM)) return -1;
if (PyModule_AddIntMacro(m, EX_CONFIG)) return -1; if (PyModule_AddIntMacro(m, EX_CONFIG)) return -1;
#if defined(HAVE_STATVFS) || defined(HAVE_FSTATVFS)
/* statvfs */ /* statvfs */
if (ST_RDONLY && PyModule_AddIntMacro(m, ST_RDONLY)) return -1; if (ST_RDONLY && PyModule_AddIntMacro(m, ST_RDONLY)) return -1;
if (ST_NOSUID && PyModule_AddIntMacro(m, ST_NOSUID)) return -1; if (ST_NOSUID && PyModule_AddIntMacro(m, ST_NOSUID)) return -1;
@ -11904,6 +11905,7 @@ all_ins(PyObject *m)
if (ST_NOATIME && PyModule_AddIntMacro(m, ST_NOATIME)) return -1; if (ST_NOATIME && PyModule_AddIntMacro(m, ST_NOATIME)) return -1;
if (ST_NODIRATIME && PyModule_AddIntMacro(m, ST_NODIRATIME)) return -1; if (ST_NODIRATIME && PyModule_AddIntMacro(m, ST_NODIRATIME)) return -1;
if (ST_RELATIME && PyModule_AddIntMacro(m, ST_RELATIME)) return -1; if (ST_RELATIME && PyModule_AddIntMacro(m, ST_RELATIME)) return -1;
#endif
/* FreeBSD sendfile() constants */ /* FreeBSD sendfile() constants */
if (SF_NODISKIO && PyModule_AddIntMacro(m, SF_NODISKIO)) return -1; if (SF_NODISKIO && PyModule_AddIntMacro(m, SF_NODISKIO)) return -1;
@ -12159,7 +12161,6 @@ static const char * const have_functions[] = {
NULL NULL
}; };
PyMODINIT_FUNC PyMODINIT_FUNC
INITFUNC(void) INITFUNC(void)
{ {
@ -12257,44 +12258,6 @@ INITFUNC(void)
return NULL; return NULL;
PyModule_AddObject(m, "uname_result", (PyObject *)&UnameResultType); PyModule_AddObject(m, "uname_result", (PyObject *)&UnameResultType);
#ifdef __APPLE__
/*
* Step 2 of weak-linking support on Mac OS X.
*
* The code below removes functions that are not available on the
* currently active platform.
*
* This block allow one to use a python binary that was build on
* OSX 10.4 on OSX 10.3, without losing access to new APIs on
* OSX 10.4.
*/
#ifdef HAVE_FSTATVFS
if (fstatvfs == NULL) {
if (PyObject_DelAttrString(m, "fstatvfs") == -1) {
return NULL;
}
}
#endif /* HAVE_FSTATVFS */
#ifdef HAVE_STATVFS
if (statvfs == NULL) {
if (PyObject_DelAttrString(m, "statvfs") == -1) {
return NULL;
}
}
#endif /* HAVE_STATVFS */
# ifdef HAVE_LCHOWN
if (lchown == NULL) {
if (PyObject_DelAttrString(m, "lchown") == -1) {
return NULL;
}
}
#endif /* HAVE_LCHOWN */
#endif /* __APPLE__ */
Py_INCREF(&TerminalSizeType); Py_INCREF(&TerminalSizeType);
PyModule_AddObject(m, "terminal_size", (PyObject*) &TerminalSizeType); PyModule_AddObject(m, "terminal_size", (PyObject*) &TerminalSizeType);
@ -12302,6 +12265,11 @@ INITFUNC(void)
if (!billion) if (!billion)
return NULL; return NULL;
if (IsWindows()) {
if (PyObject_DelAttrString(m, "lchown") == -1) return NULL;
if (PyObject_DelAttrString(m, "chown") == -1) return NULL;
}
/* suppress "function not used" warnings */ /* suppress "function not used" warnings */
{ {
int ignored; int ignored;

View file

@ -6,22 +6,20 @@
*/ */
#include "libc/assert.h" #include "libc/assert.h"
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/dce.h"
#include "libc/fmt/fmt.h" #include "libc/fmt/fmt.h"
#include "libc/intrin/asan.internal.h"
#include "libc/sysv/consts/map.h" #include "libc/sysv/consts/map.h"
#include "libc/sysv/consts/prot.h" #include "libc/sysv/consts/prot.h"
#include "third_party/python/Include/objimpl.h" #include "third_party/python/Include/objimpl.h"
#include "third_party/python/Include/pydebug.h" #include "third_party/python/Include/pydebug.h"
#include "third_party/python/Include/pyerrors.h" #include "third_party/python/Include/pyerrors.h"
#include "third_party/python/Include/pylifecycle.h"
#include "third_party/python/Include/pymacro.h" #include "third_party/python/Include/pymacro.h"
#include "third_party/python/Include/pymem.h" #include "third_party/python/Include/pymem.h"
#include "third_party/python/Include/yoink.h" #include "third_party/python/Include/yoink.h"
/* clang-format off */ /* clang-format off */
#ifdef MODE_DBG
/* Defined in tracemalloc.c */
extern void _PyMem_DumpTraceback(int fd, const void *ptr);
#endif
/* Python's malloc wrappers (see pymem.h) */ /* Python's malloc wrappers (see pymem.h) */
#undef uint #undef uint
@ -1810,13 +1808,12 @@ bumpserialno(void)
#define SST SIZEOF_SIZE_T #define SST SIZEOF_SIZE_T
/* Read sizeof(size_t) bytes at p as a big-endian size_t. */ /* Read sizeof(size_t) bytes at p as a big-endian size_t. */
static size_t static noasan size_t
read_size_t(const void *p) read_size_t(const void *p)
{ {
int i;
const uint8_t *q = (const uint8_t *)p; const uint8_t *q = (const uint8_t *)p;
size_t result = *q++; size_t result = *q++;
int i;
for (i = SST; --i > 0; ++q) for (i = SST; --i > 0; ++q)
result = (result << 8) | *q; result = (result << 8) | *q;
return result; return result;
@ -1825,7 +1822,7 @@ read_size_t(const void *p)
/* Write n as a big-endian size_t, MSB at address p, LSB at /* Write n as a big-endian size_t, MSB at address p, LSB at
* p + sizeof(size_t) - 1. * p + sizeof(size_t) - 1.
*/ */
static void static noasan void
write_size_t(void *p, size_t n) write_size_t(void *p, size_t n)
{ {
uint8_t *q = (uint8_t *)p + SST - 1; uint8_t *q = (uint8_t *)p + SST - 1;
@ -1897,6 +1894,11 @@ _PyMem_DebugRawAlloc(int use_calloc, void *ctx, size_t nbytes)
memset(tail, FORBIDDENBYTE, SST); memset(tail, FORBIDDENBYTE, SST);
write_size_t(tail + SST, serialno); write_size_t(tail + SST, serialno);
if (IsAsan()) {
__asan_poison((uintptr_t)(p + SST + 1), SST-1, kAsanHeapUnderrun);
__asan_poison((uintptr_t)tail, SST, kAsanHeapOverrun);
}
return p + 2*SST; return p + 2*SST;
} }
@ -1949,12 +1951,16 @@ _PyMem_DebugRawFree(void *ctx, void *p)
_PyMem_DebugCheckAddress(api->api_id, p); _PyMem_DebugCheckAddress(api->api_id, p);
nbytes = read_size_t(q); nbytes = read_size_t(q);
nbytes += 4*SST; nbytes += 4*SST;
if (nbytes > 0) if (nbytes > 0) {
if (IsAsan()) {
__asan_unpoison((uintptr_t)q, nbytes);
}
memset(q, DEADBYTE, nbytes); memset(q, DEADBYTE, nbytes);
}
api->alloc.free(api->alloc.ctx, q); api->alloc.free(api->alloc.ctx, q);
} }
static void * static noasan void *
_PyMem_DebugRawRealloc(void *ctx, void *p, size_t nbytes) _PyMem_DebugRawRealloc(void *ctx, void *p, size_t nbytes)
{ {
debug_alloc_api_t *api = (debug_alloc_api_t *)ctx; debug_alloc_api_t *api = (debug_alloc_api_t *)ctx;
@ -1987,11 +1993,16 @@ _PyMem_DebugRawRealloc(void *ctx, void *p, size_t nbytes)
q += 2*SST; q += 2*SST;
tail = q + nbytes; tail = q + nbytes;
memset(tail, FORBIDDENBYTE, SST); __builtin_memset(tail, FORBIDDENBYTE, SST);
if (IsAsan()) __asan_poison((uintptr_t)tail, SST, kAsanHeapOverrun);
write_size_t(tail + SST, serialno); write_size_t(tail + SST, serialno);
if (nbytes > original_nbytes) { if (nbytes > original_nbytes) {
/* growing: mark new extra memory clean */ /* growing: mark new extra memory clean */
if (IsAsan()) {
__asan_unpoison((uintptr_t)(q + original_nbytes),
nbytes - original_nbytes);
}
memset(q + original_nbytes, CLEANBYTE, memset(q + original_nbytes, CLEANBYTE,
nbytes - original_nbytes); nbytes - original_nbytes);
} }
@ -2042,7 +2053,7 @@ _PyMem_DebugRealloc(void *ctx, void *ptr, size_t nbytes)
* and call Py_FatalError to kill the program. * and call Py_FatalError to kill the program.
* The API id, is also checked. * The API id, is also checked.
*/ */
static void static noasan void
_PyMem_DebugCheckAddress(char api, const void *p) _PyMem_DebugCheckAddress(char api, const void *p)
{ {
const uint8_t *q = (const uint8_t *)p; const uint8_t *q = (const uint8_t *)p;
@ -2095,7 +2106,7 @@ error:
} }
/* Display info to stderr about the memory block at p. */ /* Display info to stderr about the memory block at p. */
static void static noasan void
_PyObject_DebugDumpAddress(const void *p) _PyObject_DebugDumpAddress(const void *p)
{ {
const uint8_t *q = (const uint8_t *)p; const uint8_t *q = (const uint8_t *)p;

View file

@ -1269,41 +1269,68 @@ class ChainOfVisitors:
v.visit(object) v.visit(object)
v.emit("", 0) v.emit("", 0)
common_msg = "/* File automatically generated by %s. */\n\n"
def main(srcfile, dump_module=False): def main(srcfile, dump_module=False):
argv0 = sys.argv[0] argv0 = sys.argv[0]
components = argv0.split(os.sep) components = argv0.split(os.sep)
argv0 = os.sep.join(components[-2:]) argv0 = os.sep.join(components[-2:])
auto_gen_msg = common_msg % argv0
mod = asdl.parse(srcfile) mod = asdl.parse(srcfile)
if dump_module: if dump_module:
print('Parsed Module:') print('Parsed Module:')
print(mod) print(mod)
if not asdl.check(mod): if not asdl.check(mod):
sys.exit(1) sys.exit(1)
if H_FILE: if H_FILE:
with open(H_FILE, "w") as f: with open(H_FILE, "w") as f:
f.write(auto_gen_msg) f.write("\
f.write('#include "asdl.h"\n\n') #ifndef COSMOPOLITAN_THIRD_PARTY_PYTHON_INCLUDE_PYTHON_AST_H_\n\
#define COSMOPOLITAN_THIRD_PARTY_PYTHON_INCLUDE_PYTHON_AST_H_\n\
#include \"third_party/python/Include/asdl.h\"\n\
#if !(__ASSEMBLER__ + __LINKER__ + 0)\n\
COSMOPOLITAN_C_START_\n\
/* clang-format off */\n\
/* File automatically generated by %s. */\n\
\n\
" % argv0)
c = ChainOfVisitors(TypeDefVisitor(f), c = ChainOfVisitors(TypeDefVisitor(f),
StructVisitor(f), StructVisitor(f),
PrototypeVisitor(f), PrototypeVisitor(f),
) )
c.visit(mod) c.visit(mod)
f.write("PyObject* PyAST_mod2obj(mod_ty t);\n") f.write("\
f.write("mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode);\n") PyObject* PyAST_mod2obj(mod_ty t);\n\
f.write("int PyAST_Check(PyObject* obj);\n") mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode);\n\
int PyAST_Check(PyObject* obj);\n\
\n\
COSMOPOLITAN_C_END_\n\
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */\n\
#endif /* COSMOPOLITAN_THIRD_PARTY_PYTHON_INCLUDE_PYTHON_AST_H_ */\n")
if C_FILE: if C_FILE:
with open(C_FILE, "w") as f: with open(C_FILE, "w") as f:
f.write(auto_gen_msg) f.write('\
f.write('#include <stddef.h>\n') #include "third_party/python/Include/%s-ast.h"\n\
f.write('\n') #include "third_party/python/Include/abstract.h"\n\
f.write('#include "Python.h"\n') #include "third_party/python/Include/boolobject.h"\n\
f.write('#include "%s-ast.h"\n' % mod.name) #include "third_party/python/Include/descrobject.h"\n\
f.write('\n') #include "third_party/python/Include/dictobject.h"\n\
f.write("static PyTypeObject AST_type;\n") #include "third_party/python/Include/listobject.h"\n\
#include "third_party/python/Include/longobject.h"\n\
#include "third_party/python/Include/modsupport.h"\n\
#include "third_party/python/Include/object.h"\n\
#include "third_party/python/Include/objimpl.h"\n\
#include "third_party/python/Include/pyerrors.h"\n\
#include "third_party/python/Include/pythonrun.h"\n\
#include "third_party/python/Include/tupleobject.h"\n\
#include "third_party/python/Include/yoink.h"\n\
/* clang-format off */\n\
\n\
PYTHON_PROVIDE("_ast");\n\
\n\
/* File automatically generated by %s. */\n\
\n\
static PyTypeObject AST_type;\n\
' % (mod.name, argv0))
v = ChainOfVisitors( v = ChainOfVisitors(
PyTypesDeclareVisitor(f), PyTypesDeclareVisitor(f),
PyTypesVisitor(f), PyTypesVisitor(f),

View file

@ -146,7 +146,7 @@ static label labels[19] = {
{7, 0}, {7, 0},
{8, 0}, {8, 0},
}; };
static grammar _PyParser_Grammar = { static grammar _PyParser_Grammarz = {
6, 6,
dfas, dfas,
{19, labels}, {19, labels},
@ -156,7 +156,7 @@ static grammar _PyParser_Grammar = {
grammar * grammar *
meta_grammar(void) meta_grammar(void)
{ {
return &_PyParser_Grammar; return &_PyParser_Grammarz;
} }
grammar * grammar *

File diff suppressed because it is too large Load diff

View file

@ -23,8 +23,11 @@
#include "third_party/python/Include/traceback.h" #include "third_party/python/Include/traceback.h"
#include "third_party/python/Include/tupleobject.h" #include "third_party/python/Include/tupleobject.h"
#include "third_party/python/Include/unicodeobject.h" #include "third_party/python/Include/unicodeobject.h"
#include "third_party/python/Include/yoink.h"
/* clang-format off */ /* clang-format off */
PYTHON_PROVIDE("_warnings");
#define MODULE_NAME "_warnings" #define MODULE_NAME "_warnings"
PyDoc_STRVAR(warnings__doc__, PyDoc_STRVAR(warnings__doc__,

46
third_party/python/Python/atexit.c vendored Normal file
View file

@ -0,0 +1,46 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=4 sts=4 sw=4 fenc=utf-8 :vi
Python 3
https://docs.python.org/3/license.html │
*/
#include "third_party/python/Include/pyerrors.h"
#include "third_party/python/Include/pylifecycle.h"
/* clang-format off */
#define NEXITFUNCS 32
static void (*_Py_exitfunc)(void);
static void (*exitfuncs[NEXITFUNCS])(void);
static int nexitfuncs = 0;
void
_Py_PyAtExit(void (*func)(void))
{
_Py_exitfunc = func;
}
void
_Py_CallExitFuncs(void)
{
if (!_Py_exitfunc) return;
_Py_exitfunc();
PyErr_Clear();
}
int Py_AtExit(void (*func)(void))
{
if (nexitfuncs >= NEXITFUNCS)
return -1;
exitfuncs[nexitfuncs++] = func;
return 0;
}
void
_Py_CallLlExitFuncs(void)
{
while (nexitfuncs > 0)
(*exitfuncs[--nexitfuncs])();
fflush(stdout);
fflush(stderr);
}

View file

@ -208,7 +208,7 @@ PYTHON_PROVIDE("builtins.zip");
Don't forget to modify PyUnicode_DecodeFSDefault() if you touch any of the Don't forget to modify PyUnicode_DecodeFSDefault() if you touch any of the
values for Py_FileSystemDefaultEncoding! values for Py_FileSystemDefaultEncoding!
*/ */
#if defined(__APPLE__) #if defined(__APPLE__) || defined(__COSMOPOLITAN__)
const char *Py_FileSystemDefaultEncoding = "utf-8"; const char *Py_FileSystemDefaultEncoding = "utf-8";
int Py_HasFileSystemDefaultEncoding = 1; int Py_HasFileSystemDefaultEncoding = 1;
#elif defined(MS_WINDOWS) #elif defined(MS_WINDOWS)

View file

@ -1034,16 +1034,12 @@ done:
PyErr_Clear(); /* Just in case */ PyErr_Clear(); /* Just in case */
} }
extern PyObject *PyModule_GetWarningsModule(void);
void void
PyErr_SyntaxLocation(const char *filename, int lineno) PyErr_SyntaxLocation(const char *filename, int lineno)
{ {
PyErr_SyntaxLocationEx(filename, lineno, -1); PyErr_SyntaxLocationEx(filename, lineno, -1);
} }
/* Set file and line information for the current exception. /* Set file and line information for the current exception.
If the exception is not a SyntaxError, also sets additional attributes If the exception is not a SyntaxError, also sets additional attributes
to make printing of exceptions believe it is a syntax error. */ to make printing of exceptions believe it is a syntax error. */

169
third_party/python/Python/fatality.c vendored Normal file
View file

@ -0,0 +1,169 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=4 sts=4 sw=4 fenc=utf-8 :vi
Python 3
https://docs.python.org/3/license.html │
*/
#include "libc/bits/weaken.h"
#include "libc/log/log.h"
#include "libc/stdio/stdio.h"
#include "third_party/python/Include/abstract.h"
#include "third_party/python/Include/pyerrors.h"
#include "third_party/python/Include/pylifecycle.h"
#include "third_party/python/Include/pythonrun.h"
#include "third_party/python/Include/sysmodule.h"
#include "third_party/python/Include/traceback.h"
/* clang-format off */
_Py_IDENTIFIER(flush);
_Py_IDENTIFIER(stdout);
_Py_IDENTIFIER(stderr);
/* Import the site module (not into __main__ though) */
static void
_Py_FatalError_DumpTracebacks(int fd)
{
fputc('\n', stderr);
fflush(stderr);
/* display the current Python stack */
_Py_DumpTracebackThreads(fd, NULL, NULL);
}
/* Print the current exception (if an exception is set) with its traceback,
or display the current Python stack.
Don't call PyErr_PrintEx() and the except hook, because Py_FatalError() is
called on catastrophic cases.
Return 1 if the traceback was displayed, 0 otherwise. */
static int
_Py_FatalError_PrintExc(int fd)
{
PyObject *ferr, *res;
PyObject *exception, *v, *tb;
int has_tb;
PyErr_Fetch(&exception, &v, &tb);
if (exception == NULL) {
/* No current exception */
return 0;
}
ferr = _PySys_GetObjectId(&PyId_stderr);
if (ferr == NULL || ferr == Py_None) {
/* sys.stderr is not set yet or set to None,
no need to try to display the exception */
return 0;
}
PyErr_NormalizeException(&exception, &v, &tb);
if (tb == NULL) {
tb = Py_None;
Py_INCREF(tb);
}
PyException_SetTraceback(v, tb);
if (exception == NULL) {
/* PyErr_NormalizeException() failed */
return 0;
}
has_tb = (tb != Py_None);
PyErr_Display(exception, v, tb);
Py_XDECREF(exception);
Py_XDECREF(v);
Py_XDECREF(tb);
/* sys.stderr may be buffered: call sys.stderr.flush() */
res = _PyObject_CallMethodId(ferr, &PyId_flush, NULL);
if (res == NULL)
PyErr_Clear();
else
Py_DECREF(res);
return has_tb;
}
/* Print fatal error message and abort */
void
Py_FatalError(const char *msg)
{
const int fd = fileno(stderr);
static int reentrant = 0;
#ifdef MS_WINDOWS
size_t len;
WCHAR* buffer;
size_t i;
#endif
if (reentrant) {
/* Py_FatalError() caused a second fatal error.
Example: _Py_FlushStdFiles() raises a recursion error. */
goto exit;
}
reentrant = 1;
fprintf(stderr, "Fatal Python error: %s\n", msg);
fflush(stderr); /* it helps in Windows debug build */
/* Check if the current thread has a Python thread state
and holds the GIL */
PyThreadState *tss_tstate = NULL; // PyGILState_GetThisThreadState();
if (tss_tstate != NULL) {
PyThreadState *tstate = PyThreadState_GET();
if (tss_tstate != tstate) {
/* The Python thread does not hold the GIL */
tss_tstate = NULL;
}
}
else {
/* Py_FatalError() has been called from a C thread
which has no Python thread state. */
}
int has_tstate_and_gil = (tss_tstate != NULL);
if (has_tstate_and_gil) {
/* If an exception is set, print the exception with its traceback */
if (!_Py_FatalError_PrintExc(fd)) {
/* No exception is set, or an exception is set without traceback */
_Py_FatalError_DumpTracebacks(fd);
}
}
else {
_Py_FatalError_DumpTracebacks(fd);
}
/* The main purpose of faulthandler is to display the traceback. We already
* did our best to display it. So faulthandler can now be disabled.
* (Don't trigger it on abort().) */
_PyFaulthandler_Fini();
/* Check if the current Python thread hold the GIL */
if (has_tstate_and_gil) {
/* Flush sys.stdout and sys.stderr */
_Py_FlushStdFiles();
}
#ifdef MS_WINDOWS
len = strlen(msg);
/* Convert the message to wchar_t. This uses a simple one-to-one
conversion, assuming that the this error message actually uses ASCII
only. If this ceases to be true, we will have to convert. */
buffer = alloca( (len+1) * (sizeof *buffer));
for( i=0; i<=len; ++i)
buffer[i] = msg[i];
OutputDebugStringW(L"Fatal Python error: ");
OutputDebugStringW(buffer);
OutputDebugStringW(L"\n");
#endif /* MS_WINDOWS */
exit:
#if defined(MS_WINDOWS) && defined(_DEBUG)
DebugBreak();
#endif
if (weaken(__die)) weaken(__die)();
abort();
}

View file

@ -0,0 +1,28 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=4 sts=4 sw=4 fenc=utf-8 :vi
Python 3
https://docs.python.org/3/license.html │
*/
#include "libc/calls/calls.h"
#include "third_party/python/Include/pydebug.h"
#include "third_party/python/Include/pylifecycle.h"
/* clang-format off */
/*
* The file descriptor fd is considered ``interactive'' if either
* a) isatty(fd) is TRUE, or
* b) the -i flag was given, and the filename associated with
* the descriptor is NULL or "<stdin>" or "???".
*/
int
Py_FdIsInteractive(FILE *fp, const char *filename)
{
if (isatty((int)fileno(fp)))
return 1;
if (!Py_InteractiveFlag)
return 0;
return (filename == NULL) ||
(strcmp(filename, "<stdin>") == 0) ||
(strcmp(filename, "???") == 0);
}

237
third_party/python/Python/finalize.c vendored Normal file
View file

@ -0,0 +1,237 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=4 sts=4 sw=4 fenc=utf-8 :vi
Python 3
https://docs.python.org/3/license.html │
*/
#include "third_party/python/Include/fileobject.h"
#include "third_party/python/Include/grammar.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/object.h"
#include "third_party/python/Include/objimpl.h"
#include "third_party/python/Include/pydebug.h"
#include "third_party/python/Include/pyerrors.h"
#include "third_party/python/Include/pylifecycle.h"
#include "third_party/python/Include/pymem.h"
#include "third_party/python/Include/pystate.h"
#include "third_party/python/Include/yoink.h"
#include "third_party/python/pyconfig.h"
/* clang-format off */
/* Undo the effect of Py_Initialize().
Beware: if multiple interpreter and/or thread states exist, these
are not wiped out; only the current thread and interpreter state
are deleted. But since everything else is deleted, those other
interpreter and thread states should no longer be used.
(XXX We should do better, e.g. wipe out all interpreters and
threads.)
Locking: as above.
*/
int
Py_FinalizeEx(void)
{
PyInterpreterState *interp;
PyThreadState *tstate;
int status = 0;
if (!_Py_initialized)
return status;
#ifdef WITH_THREAD
wait_for_thread_shutdown();
#endif
/* The interpreter is still entirely intact at this point, and the
* exit funcs may be relying on that. In particular, if some thread
* or exit func is still waiting to do an import, the import machinery
* expects Py_IsInitialized() to return true. So don't say the
* interpreter is uninitialized until after the exit funcs have run.
* Note that Threading.py uses an exit func to do a join on all the
* threads created thru it, so this also protects pending imports in
* the threads created via Threading.
*/
_Py_CallExitFuncs();
/* Get current thread state and interpreter pointer */
tstate = PyThreadState_GET();
interp = tstate->interp;
/* Remaining threads (e.g. daemon threads) will automatically exit
after taking the GIL (in PyEval_RestoreThread()). */
_Py_Finalizing = tstate;
_Py_initialized = 0;
/* Flush sys.stdout and sys.stderr */
if (_Py_FlushStdFiles() < 0) {
status = -1;
}
/* Disable signal handling */
PyOS_FiniInterrupts();
/* Collect garbage. This may call finalizers; it's nice to call these
* before all modules are destroyed.
* XXX If a __del__ or weakref callback is triggered here, and tries to
* XXX import a module, bad things can happen, because Python no
* XXX longer believes it's initialized.
* XXX Fatal Python error: Interpreter not initialized (version mismatch?)
* XXX is easy to provoke that way. I've also seen, e.g.,
* XXX Exception exceptions.ImportError: 'No module named sha'
* XXX in <function callback at 0x008F5718> ignored
* XXX but I'm unclear on exactly how that one happens. In any case,
* XXX I haven't seen a real-life report of either of these.
*/
_PyGC_CollectIfEnabled();
#ifdef COUNT_ALLOCS
/* With COUNT_ALLOCS, it helps to run GC multiple times:
each collection might release some types from the type
list, so they become garbage. */
while (_PyGC_CollectIfEnabled() > 0)
/* nothing */;
#endif
/* Destroy all modules */
PyImport_Cleanup();
/* Flush sys.stdout and sys.stderr (again, in case more was printed) */
if (_Py_FlushStdFiles() < 0) {
status = -1;
}
/* Collect final garbage. This disposes of cycles created by
* class definitions, for example.
* XXX This is disabled because it caused too many problems. If
* XXX a __del__ or weakref callback triggers here, Python code has
* XXX a hard time running, because even the sys module has been
* XXX cleared out (sys.stdout is gone, sys.excepthook is gone, etc).
* XXX One symptom is a sequence of information-free messages
* XXX coming from threads (if a __del__ or callback is invoked,
* XXX other threads can execute too, and any exception they encounter
* XXX triggers a comedy of errors as subsystem after subsystem
* XXX fails to find what it *expects* to find in sys to help report
* XXX the exception and consequent unexpected failures). I've also
* XXX seen segfaults then, after adding print statements to the
* XXX Python code getting called.
*/
#if 0
_PyGC_CollectIfEnabled();
#endif
#ifdef MODE_DBG
/* Disable tracemalloc after all Python objects have been destroyed,
so it is possible to use tracemalloc in objects destructor. */
_PyTraceMalloc_Fini();
#endif
/* Destroy the database used by _PyImport_{Fixup,Find}Extension */
_PyImport_Fini();
/* Cleanup typeobject.c's internal caches. */
_PyType_Fini();
/* unload faulthandler module */
_PyFaulthandler_Fini();
/* Debugging stuff */
#ifdef COUNT_ALLOCS
dump_counts(stderr);
#endif
/* dump hash stats */
_PyHash_Fini();
_PY_DEBUG_PRINT_TOTAL_REFS();
#ifdef Py_TRACE_REFS
/* Display all objects still alive -- this can invoke arbitrary
* __repr__ overrides, so requires a mostly-intact interpreter.
* Alas, a lot of stuff may still be alive now that will be cleaned
* up later.
*/
if (Py_GETENV("PYTHONDUMPREFS"))
_Py_PrintReferences(stderr);
#endif /* Py_TRACE_REFS */
/* Clear interpreter state and all thread states. */
PyInterpreterState_Clear(interp);
/* Now we decref the exception classes. After this point nothing
can raise an exception. That's okay, because each Fini() method
below has been checked to make sure no exceptions are ever
raised.
*/
_PyExc_Fini();
/* Sundry finalizers */
PyMethod_Fini();
PyFrame_Fini();
PyCFunction_Fini();
PyTuple_Fini();
PyList_Fini();
PySet_Fini();
PyBytes_Fini();
PyByteArray_Fini();
PyLong_Fini();
PyFloat_Fini();
PyDict_Fini();
PySlice_Fini();
_PyGC_Fini();
_PyRandom_Fini();
_PyArg_Fini();
PyAsyncGen_Fini();
/* Cleanup Unicode implementation */
_PyUnicode_Fini();
/* reset file system default encoding */
if (!Py_HasFileSystemDefaultEncoding && Py_FileSystemDefaultEncoding) {
PyMem_RawFree((char*)Py_FileSystemDefaultEncoding);
Py_FileSystemDefaultEncoding = NULL;
}
/* XXX Still allocated:
- various static ad-hoc pointers to interned strings
- int and float free list blocks
- whatever various modules and libraries allocate
*/
PyGrammar_RemoveAccelerators(&_PyParser_Grammar);
/* Cleanup auto-thread-state */
#ifdef WITH_THREAD
_PyGILState_Fini();
#endif /* WITH_THREAD */
/* Delete current thread. After this, many C API calls become crashy. */
PyThreadState_Swap(NULL);
PyInterpreterState_Delete(interp);
#ifdef Py_TRACE_REFS
/* Display addresses (& refcnts) of all objects still alive.
* An address can be used to find the repr of the object, printed
* above by _Py_PrintReferences.
*/
if (Py_GETENV("PYTHONDUMPREFS"))
_Py_PrintReferenceAddresses(stderr);
#endif /* Py_TRACE_REFS */
#ifdef WITH_PYMALLOC
if (_PyMem_PymallocEnabled()) {
char *opt = Py_GETENV("PYTHONMALLOCSTATS");
if (opt != NULL && *opt != '\0')
_PyObject_DebugMallocStats(stderr);
}
#endif
_Py_CallLlExitFuncs();
return status;
}
void
Py_Finalize(void)
{
Py_FinalizeEx();
}

34
third_party/python/Python/flags.c vendored Normal file
View file

@ -0,0 +1,34 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=4 sts=4 sw=4 fenc=utf-8 :vi
Python 3
https://docs.python.org/3/license.html │
*/
#include "third_party/python/Include/pydebug.h"
#include "third_party/python/Include/pylifecycle.h"
/* clang-format off */
/* Global configuration variable declarations are in pydebug.h */
/* XXX (ncoghlan): move those declarations to pylifecycle.h? */
int Py_DebugFlag; /* Needed by parser.c */
int Py_VerboseFlag; /* Needed by import.c */
int Py_QuietFlag; /* Needed by sysmodule.c */
int Py_InteractiveFlag; /* Needed by Py_FdIsInteractive() below */
int Py_InspectFlag; /* Needed to determine whether to exit at SystemExit */
int Py_OptimizeFlag; /* Needed by compile.c */
int Py_NoSiteFlag; /* Suppress 'import site' */
int Py_BytesWarningFlag; /* Warn on str(bytes) and str(buffer) */
int Py_UseClassExceptionsFlag = 1; /* Needed by bltinmodule.c: deprecated */
int Py_FrozenFlag; /* Needed by getpath.c */
int Py_IgnoreEnvironmentFlag; /* e.g. PYTHONPATH, PYTHONHOME */
int Py_DontWriteBytecodeFlag; /* Suppress writing bytecode files (*.pyc) */
int Py_NoUserSiteDirectory; /* for -s and site.py */
int Py_UnbufferedStdioFlag; /* Unbuffered binary std{in,out,err} */
int Py_HashRandomizationFlag; /* for -R and PYTHONHASHSEED */
int Py_IsolatedFlag; /* for -I, isolate from user's env */
#ifdef MS_WINDOWS
int Py_LegacyWindowsFSEncodingFlag; /* Uses mbcs instead of utf-8 */
int Py_LegacyWindowsStdioFlag; /* Uses FileIO instead of WindowsConsoleIO */
#endif
PyThreadState *_Py_Finalizing;

View file

@ -0,0 +1,60 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=4 sts=4 sw=4 fenc=utf-8 :vi
Python 3
https://docs.python.org/3/license.html │
*/
#include "third_party/python/Include/abstract.h"
#include "third_party/python/Include/object.h"
#include "third_party/python/Include/pyerrors.h"
#include "third_party/python/Include/pylifecycle.h"
#include "third_party/python/Include/sysmodule.h"
/* clang-format off */
_Py_IDENTIFIER(flush);
_Py_IDENTIFIER(stdout);
_Py_IDENTIFIER(stderr);
static int
file_is_closed(PyObject *fobj)
{
int r;
PyObject *tmp = PyObject_GetAttrString(fobj, "closed");
if (tmp == NULL) {
PyErr_Clear();
return 0;
}
r = PyObject_IsTrue(tmp);
Py_DECREF(tmp);
if (r < 0)
PyErr_Clear();
return r > 0;
}
int
_Py_FlushStdFiles(void)
{
PyObject *fout = _PySys_GetObjectId(&PyId_stdout);
PyObject *ferr = _PySys_GetObjectId(&PyId_stderr);
PyObject *tmp;
int status = 0;
if (fout != NULL && fout != Py_None && !file_is_closed(fout)) {
tmp = _PyObject_CallMethodId(fout, &PyId_flush, NULL);
if (tmp == NULL) {
PyErr_WriteUnraisable(fout);
status = -1;
}
else
Py_DECREF(tmp);
}
if (ferr != NULL && ferr != Py_None && !file_is_closed(ferr)) {
tmp = _PyObject_CallMethodId(ferr, &PyId_flush, NULL);
if (tmp == NULL) {
PyErr_Clear();
status = -1;
}
else
Py_DECREF(tmp);
}
return status;
}

76
third_party/python/Python/getsig.c vendored Normal file
View file

@ -0,0 +1,76 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=4 sts=4 sw=4 fenc=utf-8 :vi
Python 3
https://docs.python.org/3/license.html │
*/
#include "libc/calls/calls.h"
#include "libc/calls/sigbits.h"
#include "third_party/python/Include/pydebug.h"
#include "third_party/python/Include/pylifecycle.h"
#include "third_party/python/pyconfig.h"
/* clang-format off */
PyOS_sighandler_t
PyOS_getsig(int sig)
{
#ifdef HAVE_SIGACTION
struct sigaction context;
if (sigaction(sig, NULL, &context) == -1)
return SIG_ERR;
return context.sa_handler;
#else
PyOS_sighandler_t handler;
/* Special signal handling for the secure CRT in Visual Studio 2005 */
#if defined(_MSC_VER) && _MSC_VER >= 1400
switch (sig) {
/* Only these signals are valid */
case SIGINT:
case SIGILL:
case SIGFPE:
case SIGSEGV:
case SIGTERM:
case SIGBREAK:
case SIGABRT:
break;
/* Don't call signal() with other values or it will assert */
default:
return SIG_ERR;
}
#endif /* _MSC_VER && _MSC_VER >= 1400 */
handler = signal(sig, SIG_IGN);
if (handler != SIG_ERR)
signal(sig, handler);
return handler;
#endif
}
/*
* All of the code in this function must only use async-signal-safe functions,
* listed at `man 7 signal` or
* http://www.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_04.html.
*/
PyOS_sighandler_t
PyOS_setsig(int sig, PyOS_sighandler_t handler)
{
#ifdef HAVE_SIGACTION
/* Some code in Modules/signalmodule.c depends on sigaction() being
* used here if HAVE_SIGACTION is defined. Fix that if this code
* changes to invalidate that assumption.
*/
struct sigaction context, ocontext;
context.sa_handler = handler;
sigemptyset(&context.sa_mask);
context.sa_flags = 0;
if (sigaction(sig, &context, &ocontext) == -1)
return SIG_ERR;
return ocontext.sa_handler;
#else
PyOS_sighandler_t oldhandler;
oldhandler = signal(sig, handler);
#ifdef HAVE_SIGINTERRUPT
siginterrupt(sig, 1);
#endif
return oldhandler;
#endif
}

View file

@ -10,7 +10,6 @@
#include "third_party/python/Include/pgenheaders.h" #include "third_party/python/Include/pgenheaders.h"
#include "third_party/python/Include/grammar.h" #include "third_party/python/Include/grammar.h"
extern grammar _PyParser_Grammar;
static arc arcs_0_0[3] = { static arc arcs_0_0[3] = {
{2, 1}, {2, 1},
{3, 1}, {3, 1},

Some files were not shown because too many files have changed in this diff Show more