# HG changeset patch # User Paul Boddie # Date 1472586958 -7200 # Node ID f551873980e538945f19934e397f33297d0f0f9c # Parent a03de9203c2873795d255b505f03f6686e372d51 Added PythonLight alternative libraries. diff -r a03de9203c28 -r f551873980e5 lib/UserDict.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/UserDict.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,176 @@ +"""A more or less complete user-defined wrapper around dictionary objects.""" + +class UserDict: + def __init__(self, dict=None, **kwargs): + self.data = {} + if dict is not None: + self.update(dict) + if len(kwargs): + self.update(kwargs) + def __repr__(self): return repr(self.data) + def __cmp__(self, dict): + if isinstance(dict, UserDict): + return cmp(self.data, dict.data) + else: + return cmp(self.data, dict) + __hash__ = None # Avoid Py3k warning + def __len__(self): return len(self.data) + def __getitem__(self, key): + if key in self.data: + return self.data[key] + if hasattr(self.__class__, "__missing__"): + return self.__class__.__missing__(self, key) + raise KeyError(key) + def __setitem__(self, key, item): self.data[key] = item + def __delitem__(self, key): del self.data[key] + def clear(self): self.data.clear() + def copy(self): + if self.__class__ is UserDict: + return UserDict(self.data.copy()) + import copy + data = self.data + try: + self.data = {} + c = copy.copy(self) + finally: + self.data = data + c.update(self) + return c + def keys(self): return self.data.keys() + def items(self): return self.data.items() + def iteritems(self): return self.data.iteritems() + def iterkeys(self): return self.data.iterkeys() + def itervalues(self): return self.data.itervalues() + def values(self): return self.data.values() + def has_key(self, key): return key in self.data + def update(self, dict=None, **kwargs): + if dict is None: + pass + elif isinstance(dict, UserDict): + self.data.update(dict.data) + elif isinstance(dict, type({})) or not hasattr(dict, 'items'): + self.data.update(dict) + else: + for k, v in dict.items(): + self[k] = v + if len(kwargs): + self.data.update(kwargs) + def get(self, key, failobj=None): + if key not in self: + return failobj + return self[key] + def setdefault(self, key, failobj=None): + if key not in self: + self[key] = failobj + return self[key] + def pop(self, key, *args): + return self.data.pop(key, *args) + def popitem(self): + return self.data.popitem() + def __contains__(self, key): + return key in self.data + @classmethod + def fromkeys(cls, iterable, value=None): + d = cls() + for key in iterable: + d[key] = value + return d + +class IterableUserDict(UserDict): + def __iter__(self): + return iter(self.data) + +class DictMixin: + # Mixin defining all dictionary methods for classes that already have + # a minimum dictionary interface including getitem, setitem, delitem, + # and keys. Without knowledge of the subclass constructor, the mixin + # does not define __init__() or copy(). In addition to the four base + # methods, progressively more efficiency comes with defining + # __contains__(), __iter__(), and iteritems(). + + # second level definitions support higher levels + def __iter__(self): + for k in self.keys(): + yield k + def has_key(self, key): + try: + self[key] + except KeyError: + return False + return True + def __contains__(self, key): + return self.has_key(key) + + # third level takes advantage of second level definitions + def iteritems(self): + for k in self: + yield (k, self[k]) + def iterkeys(self): + return self.__iter__() + + # fourth level uses definitions from lower levels + def itervalues(self): + for _, v in self.iteritems(): + yield v + def values(self): + return [v for _, v in self.iteritems()] + def items(self): + return list(self.iteritems()) + def clear(self): + for key in self.keys(): + del self[key] + def setdefault(self, key, default=None): + try: + return self[key] + except KeyError: + self[key] = default + return default + def pop(self, key, *args): + if len(args) > 1: + raise TypeError, "pop expected at most 2 arguments, got "\ + + repr(1 + len(args)) + try: + value = self[key] + except KeyError: + if args: + return args[0] + raise + del self[key] + return value + def popitem(self): + try: + k, v = self.iteritems().next() + except StopIteration: + raise KeyError, 'container is empty' + del self[k] + return (k, v) + def update(self, other=None, **kwargs): + # Make progressively weaker assumptions about "other" + if other is None: + pass + elif hasattr(other, 'iteritems'): # iteritems saves memory and lookups + for k, v in other.iteritems(): + self[k] = v + elif hasattr(other, 'keys'): + for k in other.keys(): + self[k] = other[k] + else: + for k, v in other: + self[k] = v + if kwargs: + self.update(kwargs) + def get(self, key, default=None): + try: + return self[key] + except KeyError: + return default + def __repr__(self): + return repr(dict(self.iteritems())) + def __cmp__(self, other): + if other is None: + return 1 + if isinstance(other, DictMixin): + other = dict(other.iteritems()) + return cmp(dict(self.iteritems()), other) + def __len__(self): + return len(self.keys()) diff -r a03de9203c28 -r f551873980e5 lib/__builtins__/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/__builtins__/__init__.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,105 @@ +#!/usr/bin/env python + +""" +Simple built-in classes and functions. + +Copyright (C) 2015 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +from __builtins__.core import object, type, function, BaseException, Exception, Warning + +# Exceptions. + +from __builtins__.exception import ( + ArithmeticError, + AssertionError, + AttributeError, + DeprecationWarning, + EOFError, + EnvironmentError, + FloatingPointError, + FutureWarning, + GeneratorExit, + ImportError, + ImportWarning, + IndentationError, + IndexError, + IOError, + KeyError, + KeyboardInterrupt, + LookupError, + MemoryError, + NameError, + NotImplementedError, + OSError, + OverflowError, + PendingDeprecationWarning, + ReferenceError, + RuntimeError, + RuntimeWarning, + StandardError, + StopIteration, + SyntaxError, + SyntaxWarning, + SystemError, + SystemExit, + TabError, + TypeError, + UnboundLocalError, + UnicodeDecodeError, + UnicodeEncodeError, + UnicodeError, + UnicodeTranslateError, + UnicodeWarning, + UserWarning, + ValueError, + ZeroDivisionError + ) + + +# Classes. + +from __builtins__.bool import bool +from __builtins__.buffer import buffer +from __builtins__.complex import complex +from __builtins__.dict import dict +from __builtins__.ellipsis import ellipsis +from __builtins__.file import file +from __builtins__.float import float +from __builtins__.int import int +from __builtins__.span import xrange, slice +from __builtins__.iterator import listiterator +from __builtins__.list import list +from __builtins__.long import long +from __builtins__.none import NoneType +from __builtins__.notimplemented import NotImplementedType +from __builtins__.property import property +from __builtins__.set import frozenset, set +from __builtins__.string import basestring, str, unicode +from __builtins__.tuple import tuple + +# Functions. + +from __builtins__.attribute import getattr, hasattr, setattr +from __builtins__.character import chr, hex, oct, ord, unichr +from __builtins__.comparable import cmp, hash +from __builtins__.identity import callable, help, id, isinstance, issubclass, repr +from __builtins__.io import eval, open, raw_input +from __builtins__.iterable import all, any, enumerate, filter, iter, len, map, max, min, range, reduce, reversed, sorted, sum, zip +from __builtins__.namespace import dir, globals, locals, vars +from __builtins__.numeric import abs, divmod, pow, round + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/__builtins__/attribute.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/__builtins__/attribute.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,40 @@ +#!/usr/bin/env python + +""" +Attribute-related functions. + +Copyright (C) 2015 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +_getattr_default=object() # a unique placeholder for a missing value + +def getattr(obj, name, default=_getattr_default): + + "Implementation of getattr." + + try: + return _getattr(obj, name) + except AttributeError: + if default is not _getattr_default: + return default + else: + raise + +def hasattr(obj, name): pass +def setattr(obj, name, value): pass +def _getattr(obj, name): pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/__builtins__/bool.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/__builtins__/bool.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,29 @@ +#!/usr/bin/env python + +""" +Boolean objects. + +Copyright (C) 2015 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +class bool(object): + def __bool__(self): + "Identity operation." + return self + def __str__(self): + return self is True and "True" or "False" + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/__builtins__/buffer.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/__builtins__/buffer.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,27 @@ +#!/usr/bin/env python + +""" +Buffer object. + +Copyright (C) 2015 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +class buffer(object): + def __init__(self, size): pass + def append(self, s): pass + def __str__(self): pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/__builtins__/character.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/__builtins__/character.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,28 @@ +#!/usr/bin/env python + +""" +Character-related functions. + +Copyright (C) 2015 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +def chr(i): pass +def hex(number): pass +def oct(number): pass +def ord(c): pass +def unichr(i): pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/__builtins__/comparable.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/__builtins__/comparable.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,25 @@ +#!/usr/bin/env python + +""" +Comparison-related functions. + +Copyright (C) 2015 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +def cmp(x, y): pass +def hash(obj): pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/__builtins__/complex.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/__builtins__/complex.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,57 @@ +#!/usr/bin/env python + +""" +Complex number objects. + +Copyright (C) 2015, 2016 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +class complex(object): + def __init__(self, real, imag=None): + self.real = real + self.imag = imag + + def __iadd__(self, other): pass + def __isub__(self, other): pass + def __add__(self, other): pass + def __radd__(self, other): pass + def __sub__(self, other): pass + def __rsub__(self, other): pass + def __mul__(self, other): pass + def __rmul__(self, other): pass + def __div__(self, other): pass + def __rdiv__(self, other): pass + def __floordiv__(self, other): pass + def __rfloordiv__(self, other): pass + def __and__(self, other): pass + def __rand__(self, other): pass + def __or__(self, other): pass + def __ror__(self, other): pass + def __xor__(self, other): pass + def __rxor__(self, other): pass + def __lt__(self, other): pass + def __gt__(self, other): pass + def __le__(self, other): pass + def __ge__(self, other): pass + def __eq__(self, other): pass + def __ne__(self, other): pass + def __neg__(self): pass + def __pos__(self): pass + def __str__(self): pass + def __bool__(self): pass + def conjugate(self): pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/__builtins__/core.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/__builtins__/core.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,45 @@ +#!/usr/bin/env python + +""" +Core objects. + +Copyright (C) 2015 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +class object: + def __init__(self): + "No-operation." + pass + def __bool__(self): + "Objects are true by default." + return True + +class function(object): + def __init__(self): + + # Reserve special attributes for function instances. + + self.__fn__ = None + self.__args__ = None + +class type(object): + pass + +class BaseException(object): pass +class Exception(BaseException): pass +class Warning(object): pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/__builtins__/dict.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/__builtins__/dict.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,48 @@ +#!/usr/bin/env python + +""" +Dictionary objects. + +Copyright (C) 2015 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +from __builtins__.iterator import listiterator + +class dict(object): + def __init__(self, *args): pass + def __setitem__(self, key, value): pass + def __delitem__(self, key, value): pass + + def __getitem__(self, key): + # Note usage. + KeyError + + def clear(self): pass + def has_key(self): pass + def keys(self): pass + def values(self): pass + def items(self): pass + def get(self, key): pass + def setdefault(self, key, value): pass + def update(self, other): pass + + def __iter__(self): + + "Return an iterator." + + return listiterator(self.keys()) + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/__builtins__/ellipsis.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/__builtins__/ellipsis.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,24 @@ +#!/usr/bin/env python + +""" +Ellipsis object. + +Copyright (C) 2015 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +class ellipsis: pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/__builtins__/exception/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/__builtins__/exception/__init__.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,89 @@ +#!/usr/bin/env python + +""" +Exception objects. + +Copyright (C) 2015 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +from __builtins__.exception.assertion import ( + AssertionError + ) + +from __builtins__.exception.base import ( + GeneratorExit, + IndexError, + KeyError, + LookupError, + NotImplementedError, + ReferenceError, + StandardError, + StopIteration, + TypeError, + ValueError + ) + +from __builtins__.exception.io import ( + EOFError, + IOError, + KeyboardInterrupt + ) + +from __builtins__.exception.naming import ( + AttributeError, + ImportError, + ImportWarning, + NameError, + UnboundLocalError + ) + +from __builtins__.exception.numeric import ( + ArithmeticError, + FloatingPointError, + OverflowError, + ZeroDivisionError + ) + +from __builtins__.exception.program import ( + DeprecationWarning, + FutureWarning, + IndentationError, + PendingDeprecationWarning, + SyntaxError, + SyntaxWarning, + TabError, + UserWarning + ) + +from __builtins__.exception.system import ( + EnvironmentError, + MemoryError, + OSError, + RuntimeError, + RuntimeWarning, + SystemError, + SystemExit + ) + +from __builtins__.exception.unicode import ( + UnicodeDecodeError, + UnicodeEncodeError, + UnicodeError, + UnicodeTranslateError, + UnicodeWarning + ) + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/__builtins__/exception/assertion.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/__builtins__/exception/assertion.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,24 @@ +#!/usr/bin/env python + +""" +Assertion exception objects. + +Copyright (C) 2015 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +class AssertionError(Exception): pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/__builtins__/exception/base.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/__builtins__/exception/base.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,33 @@ +#!/usr/bin/env python + +""" +Base exception objects. + +Copyright (C) 2015 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +class GeneratorExit(Exception): pass +class IndexError(Exception): pass +class KeyError(Exception): pass +class LookupError(Exception): pass +class NotImplementedError(Exception): pass +class ReferenceError(Exception): pass +class StandardError(Exception): pass +class StopIteration(Exception): pass +class TypeError(Exception): pass +class ValueError(Exception): pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/__builtins__/exception/io.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/__builtins__/exception/io.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,26 @@ +#!/usr/bin/env python + +""" +Input/output exception objects. + +Copyright (C) 2015 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +class EOFError(Exception): pass +class IOError(Exception): pass +class KeyboardInterrupt(Exception): pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/__builtins__/exception/naming.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/__builtins__/exception/naming.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,28 @@ +#!/usr/bin/env python + +""" +Name-related exception objects. + +Copyright (C) 2015 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +class AttributeError(Exception): pass +class ImportError(Exception): pass +class ImportWarning(Warning): pass +class NameError(Exception): pass +class UnboundLocalError(Exception): pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/__builtins__/exception/numeric.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/__builtins__/exception/numeric.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,27 @@ +#!/usr/bin/env python + +""" +Numeric exception objects. + +Copyright (C) 2015 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +class ArithmeticError(Exception): pass +class FloatingPointError(Exception): pass +class OverflowError(Exception): pass +class ZeroDivisionError(Exception): pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/__builtins__/exception/program.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/__builtins__/exception/program.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,31 @@ +#!/usr/bin/env python + +""" +Program exception objects. + +Copyright (C) 2015 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +class DeprecationWarning(Exception): pass +class FutureWarning(Warning): pass +class IndentationError(Exception): pass +class PendingDeprecationWarning(Warning): pass +class SyntaxError(Exception): pass +class SyntaxWarning(Warning): pass +class TabError(Exception): pass +class UserWarning(Warning): pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/__builtins__/exception/system.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/__builtins__/exception/system.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,30 @@ +#!/usr/bin/env python + +""" +System exception objects. + +Copyright (C) 2015 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +class EnvironmentError(Exception): pass +class MemoryError(Exception): pass +class OSError(Exception): pass +class RuntimeError(Exception): pass +class RuntimeWarning(Warning): pass +class SystemError(Exception): pass +class SystemExit(Exception): pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/__builtins__/exception/unicode.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/__builtins__/exception/unicode.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,28 @@ +#!/usr/bin/env python + +""" +Unicode exception objects. + +Copyright (C) 2015 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +class UnicodeDecodeError(Exception): pass +class UnicodeEncodeError(Exception): pass +class UnicodeError(Exception): pass +class UnicodeTranslateError(Exception): pass +class UnicodeWarning(Warning): pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/__builtins__/file.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/__builtins__/file.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,29 @@ +#!/usr/bin/env python + +""" +File objects. + +Copyright (C) 2015 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +class file(object): + def read(self, n=None): pass + def write(self, s): pass + def close(self): pass + def readline(self, size=None): pass + def readlines(self, size=None): pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/__builtins__/float.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/__builtins__/float.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,54 @@ +#!/usr/bin/env python + +""" +Floating point objects. + +Copyright (C) 2015, 2016 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +class float(object): + def __init__(self, number_or_string=None): + # Note member. + self.data = 0 + + def __iadd__(self, other): pass + def __isub__(self, other): pass + def __add__(self, other): pass + def __radd__(self, other): pass + def __sub__(self, other): pass + def __rsub__(self, other): pass + def __mul__(self, other): pass + def __rmul__(self, other): pass + def __div__(self, other): pass + def __rdiv__(self, other): pass + def __floordiv__(self, other): pass + def __rfloordiv__(self, other): pass + def __mod__(self, other): pass + def __rmod__(self, other): pass + def __pow__(self, other): pass + def __rpow__(self, other): pass + def __lt__(self, other): pass + def __gt__(self, other): pass + def __le__(self, other): pass + def __ge__(self, other): pass + def __eq__(self, other): pass + def __ne__(self, other): pass + def __neg__(self): pass + def __pos__(self): pass + def __str__(self): pass + def __bool__(self): pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/__builtins__/identity.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/__builtins__/identity.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,50 @@ +#!/usr/bin/env python + +""" +Identity-related functions. + +Copyright (C) 2015 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +from native import _isinstance + +def callable(obj): pass +def help(*args): pass +def id(obj): pass + +def isinstance(obj, cls_or_tuple): + + """ + Return whether 'obj' is an instance of 'cls_or_tuple', where the latter is + either a class or a tuple of classes. + """ + + # NOTE: CPython insists on tuples, but any sequence might be considered + # NOTE: acceptable. + + if _isinstance(cls_or_tuple, tuple): + for cls in cls_or_tuple: + if obj.__class__ is cls or _isinstance(obj, cls): + return True + return False + else: + return obj.__class__ is cls_or_tuple or _isinstance(obj, cls_or_tuple) + +def issubclass(obj, cls_or_tuple): pass + +def repr(obj): pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/__builtins__/int.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/__builtins__/int.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,158 @@ +#!/usr/bin/env python + +""" +Integer objects. + +Copyright (C) 2015, 2016 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +import native + +class int(object): + def __init__(self, number_or_string=None): + # Note member. + self.data = 0 + + def __iadd__(self, other): + "Return a new int for the operation." + return _binary_op(self, other, native._int_add) + + def __isub__(self, other): + "Return a new int for the operation." + return _binary_op(self, other, native._int_sub) + + def __imul__(self, other): + "Return a new int for the operation." + return _binary_op(self, other, native._int_mul) + + def __idiv__(self, other): + "Return a new int for the operation." + return _binary_op(self, other, native._int_div) + + def __imod__(self, other): + "Return a new int for the operation." + return _binary_op(self, other, native._int_mod) + + def __ipow__(self, other): + "Return a new int for the operation." + return _binary_op(self, other, native._int_pow) + + def __iand__(self, other): + "Return a new int for the operation." + return _binary_op(self, other, native._int_and) + + def __ior__(self, other): + "Return a new int for the operation." + return _binary_op(self, other, native._int_or) + + def __ixor__(self, other): + "Return a new int for the operation." + return _binary_op(self, other, native._int_xor) + + __add__ = __radd__ = __iadd__ + __sub__ = __isub__ + + def __rsub__(self, other): + "Return a new int for the operation." + return _binary_op(self, other, native._int_rsub) + + __mul__ = __rmul__ = __imul__ + __div__ = __idiv__ + + def __rdiv__(self, other): + "Return a new int for the operation." + return _binary_op(self, other, native._int_rdiv) + + def __floordiv__(self, other): pass + def __rfloordiv__(self, other): pass + def __ifloordiv__(self, other): pass + + __mod__ = __imod__ + + def __rmod__(self, other): + "Return a new int for the operation." + return _binary_op(self, other, native._int_rmod) + + __pow__ = __ipow__ + + def __rpow__(self, other): + "Return a new int for the operation." + return _binary_op(self, other, native._int_rpow) + + __and__ = __rand__ = __iand__ + __or__ = __ror__ = __ior__ + __xor__ = __rxor__ = __ixor__ + + def __lt__(self, other): + "Return a new boolean for the comparison." + return _binary_op(self, other, native._int_lt) + + def __gt__(self, other): + "Return a new boolean for the comparison." + return _binary_op(self, other, native._int_gt) + + def __le__(self, other): + "Return a new boolean for the comparison." + return _negate(self.__gt__(other)) + + def __ge__(self, other): + "Return a new boolean for the comparison." + return _negate(self.__lt__(other)) + + def __eq__(self, other): + "Return a new boolean for the comparison." + return _binary_op(self, other, native._int_eq) + + def __ne__(self, other): + "Return a new boolean for the comparison." + return _negate(self.__eq__(other)) + + def __invert__(self): pass + def __neg__(self): pass + def __pos__(self): pass + def __str__(self): pass + def __lshift__(self): pass + def __rlshift__(self): pass + def __rshift__(self): pass + def __rrshift__(self): pass + def __ilshift__(self): pass + def __irshift__(self): pass + + def __bool__(self): + "Return whether this int is non-zero." + return _negate(native._int_eq(self, 0)) + +# Utility functions. + +def _binary_op(self, other, op): + + "Test the type of 'other' and perform 'op'." + + if self.__class__ is other.__class__: + return op(self, other) + else: + return NotImplemented + +def _negate(result): + + "Negate any valid logical value." + + if result is NotImplemented: + return result + else: + return not result + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/__builtins__/io.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/__builtins__/io.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,26 @@ +#!/usr/bin/env python + +""" +Input/output-related functions. + +Copyright (C) 2015 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +def eval(source, globals=None, locals=None): pass +def open(name, mode=None, buffering=None): pass +def raw_input(prompt=None): pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/__builtins__/iterable.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/__builtins__/iterable.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,74 @@ +#!/usr/bin/env python + +""" +Iteration-related functions. + +Copyright (C) 2015 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +from __builtins__.span import xrange + +def all(iterable): pass +def any(iterable): pass +def enumerate(iterable): pass +def filter(function, sequence): pass +def iter(collection): + + "Implementation of iter without callable plus sentinel support." + + return collection.__iter__() + +def len(obj): + + "Implementation of len." + + return obj.__len__() + +def map(function, *args): pass + +def max(*args): + + "Implementation of max." + + highest = args[0] + for arg in args[1:]: + if arg > highest: + highest = arg + return highest + +def min(*args): + + "Implementation of min." + + lowest = args[0] + for arg in args[1:]: + if arg > lowest: + lowest = arg + return lowest + +def range(start_or_end, end=None, step=1): + + "Implementation of range." + + return list(xrange(start_or_end, end, step)) + +def reduce(function, sequence, initial=None): pass +def reversed(sequence): pass +def sorted(iterable, cmp=None, key=None, reverse=False): pass +def sum(sequence, start=0): pass +def zip(*args): pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/__builtins__/iterator.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/__builtins__/iterator.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,44 @@ +#!/usr/bin/env python + +""" +Iterator objects. + +Copyright (C) 2015 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +class listiterator(object): + + "Implementation of listiterator." + + def __init__(self, l): + + "Initialise with the given list 'l'." + + self.l = l + self.i = 0 + + def next(self): + + "Return the next item." + + try: + value = self.l[self.i] + self.i += 1 + return value + except IndexError: + raise StopIteration() + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/__builtins__/list.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/__builtins__/list.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,91 @@ +#!/usr/bin/env python + +""" +List objects. + +Copyright (C) 2015 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +from __builtins__.sequence import * + +class list(object): + + "Implementation of list." + + def __init__(self, args=None): + + "Initialise the list." + + if args is not None: + self.extend(args) + + def __new__(self): + # Reserve space for a fragment reference. + self._elements = None + + def __getitem__(self, index): + + "Return the item or slice specified by 'index'." + + return _getitem(self, index) + + def __contains__(self, value): pass + def __setitem__(self, index, value): pass + def __delitem__(self, index): pass + + def __getslice__(self, start, end=None): + + "Return a slice starting from 'start', with the optional 'end'." + + return _getslice(self, start, end) + + def __setslice__(self, start, end, slice): pass + def __delslice__(self, start, end): pass + def append(self, value): pass + def insert(self, i, value): pass + + def extend(self, iterable): + + "Extend the list with the contents of 'iterable'." + + for i in iterable: + self.append(i) + + def pop(self): pass + def reverse(self): pass + def sort(self, cmp=None, key=None, reverse=0): pass + def __len__(self): pass + def __add__(self, other): pass + def __iadd__(self, other): pass + def __str__(self): pass + + def __bool__(self): + + "Lists are true if non-empty." + + return self.__len__() != 0 + + def __iter__(self): + + "Return an iterator." + + return listiterator(self) + + # Special implementation methods. + + def __get_single_item__(self, index): pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/__builtins__/long.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/__builtins__/long.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,53 @@ +#!/usr/bin/env python + +""" +Long objects. + +Copyright (C) 2015 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +class long(object): + def __init__(self, number_or_string=None): pass + def __iadd__(self, other): pass + def __isub__(self, other): pass + def __add__(self, other): pass + def __radd__(self, other): pass + def __sub__(self, other): pass + def __rsub__(self, other): pass + def __mul__(self, other): pass + def __rmul__(self, other): pass + def __div__(self, other): pass + def __rdiv__(self, other): pass + def __floordiv__(self, other): pass + def __rfloordiv__(self, other): pass + def __and__(self, other): pass + def __rand__(self, other): pass + def __or__(self, other): pass + def __ror__(self, other): pass + def __xor__(self, other): pass + def __rxor__(self, other): pass + def __lt__(self, other): pass + def __gt__(self, other): pass + def __le__(self, other): pass + def __ge__(self, other): pass + def __eq__(self, other): pass + def __ne__(self, other): pass + def __neg__(self): pass + def __pos__(self): pass + def __str__(self): pass + def __bool__(self): pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/__builtins__/namespace.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/__builtins__/namespace.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,27 @@ +#!/usr/bin/env python + +""" +Namespace-related functions. + +Copyright (C) 2015 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +def dir(obj=None): pass +def globals(): pass +def locals(): pass +def vars(obj=None): pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/__builtins__/none.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/__builtins__/none.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,27 @@ +#!/usr/bin/env python + +""" +None objects. + +Copyright (C) 2015 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +class NoneType: + def __bool__(self): + "None is always false." + return False + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/__builtins__/notimplemented.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/__builtins__/notimplemented.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,24 @@ +#!/usr/bin/env python + +""" +Not implemented object. + +Copyright (C) 2015 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +class NotImplementedType: pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/__builtins__/numeric.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/__builtins__/numeric.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,27 @@ +#!/usr/bin/env python + +""" +Numeric functions. + +Copyright (C) 2015 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +def abs(number): pass +def divmod(x, y): pass +def pow(x, y, z=None): pass +def round(number, ndigits=None): pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/__builtins__/operator.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/__builtins__/operator.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,40 @@ +#!/usr/bin/env python + +""" +Operator-related functions. + +Copyright (C) 2015 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +def _binary_op(self, other, op): + + "Test the type of 'other' and perform 'op'." + + if self.__class__ is other.__class__: + return op(self, other) + else: + return NotImplemented + +def _negate(result): + + "Negate any valid logical value." + + if result is NotImplemented: + return result + else: + return not result + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/__builtins__/property.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/__builtins__/property.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,25 @@ +#!/usr/bin/env python + +""" +Property objects. + +Copyright (C) 2015 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +class property(object): + def __init__(fget=None, fset=None, fdel=None, doc=None): pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/__builtins__/sequence.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/__builtins__/sequence.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,96 @@ +#!/usr/bin/env python + +""" +Sequence operations. + +Copyright (C) 2015 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +from native import _isinstance + +def _getitem(seq, index): + + "Return the item or slice specified by 'index'." + + if _isinstance(index, int): + index = _normalise_index(index, seq.__len__()) + return seq.__get_single_item__(index) + elif _isinstance(index, slice): + return seq.__getslice__(index.start, index.end) + else: + raise TypeError + +def _getslice(seq, start, end=None): + + "Return a slice starting from 'start', with the optional 'end'." + + length = seq.__len__() + + if start is None: + start = 0 + else: + start = _normalise_index(start, length) + + if end is None: + end = length + else: + end = _normalise_index(end, length) + + result = [] + while start < end: + result.append(seq.__get_single_item__(start)) + start += 1 + return result + +def _get_absolute_index(index, length): + + """ + Return the absolute index for 'index' given a collection having the + specified 'length'. + """ + + if index < 0: + return length + index + else: + return index + +def _normalise_index(index, length): + + "Normalise 'index' for a collection having the specified 'length'." + + return _min(length, _max(0, _get_absolute_index(index, length))) + +def _max(x, y): + + "Return the maximum of 'x' and 'y'." + + if x >= y: + return x + else: + return y + +def _min(x, y): + + "Return the minimum of 'x' and 'y'." + + if x <= y: + return x + else: + return y + +def _tuple(l): pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/__builtins__/set.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/__builtins__/set.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,51 @@ +#!/usr/bin/env python + +""" +Set objects. + +Copyright (C) 2015 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +class frozenset(object): + def __init__(self, iterable): pass + +class set(object): + def __init__(self, iterable): pass + def add(self, item): pass + def clear(self): pass + def copy(self): pass + def difference(self, other): pass + def difference_update(self, other): pass + def discard(self, item): pass + def intersection(self, other): pass + def intersection_update(self, other): pass + def issubset(self, other): pass + def issuperset(self, other): pass + + def __iter__(self): + + "Return an iterator." + + return listiterator(list(self)) + + def pop(self): pass + def remove(self, item): pass + def symmetric_difference(self, other): pass + def symmetric_difference_update(self, other): pass + def union(self, other): pass + def update(self, other): pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/__builtins__/span.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/__builtins__/span.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,71 @@ +#!/usr/bin/env python + +""" +Span-related objects. + +Copyright (C) 2015 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +class xrange(object): + + "Implementation of xrange." + + NO_END = object() + + def __init__(self, start_or_end, end=NO_END, step=1): + + "Initialise the xrange with the given 'start_or_end', 'end' and 'step'." + + if end is xrange.NO_END: + self.start = 0 + self.end = start_or_end + else: + self.start = start_or_end + self.end = end + + self.step = step + self.current = self.start + self.limited = self.end is not xrange.NO_END + + def __iter__(self): + + "Return an iterator, currently self." + + return self + + def next(self): + + "Return the next item or raise a StopIteration exception." + + if self.limited: + if self.step < 0 and self.current <= self.end or self.step > 0 and self.current >= self.end: + raise StopIteration() + + current = self.current + self.current += self.step + return current + +class slice(xrange): + + "Implementation of slice." + + def __init__(self, start_or_end=None, end=xrange.NO_END, step=1): + + "Initialise the slice with the given 'start_or_end', 'end' and 'step'." + + xrange.__init__(self, start_or_end, end, step) + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/__builtins__/string.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/__builtins__/string.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,107 @@ +#!/usr/bin/env python + +""" +String objects. + +Copyright (C) 2015, 2016 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +from __builtins__.operator import * +import native + +class basestring(object): + def __init__(self, data=None): + # Note member. + self.data = data + + def __contains__(self, value): pass + + def __getitem__(self, index): + # Note usage. + IndexError + + def __getslice__(self, start, end=None): pass + + def __iadd__(self, other): + "Return a new string for the operation." + return _binary_op(self, other, native._str_add) + + __add__ = __radd__ = __iadd__ + + def __mul__(self, other): pass + def __rmul__(self, other): pass + def __mod__(self, other): pass + def __rmod__(self, other): pass + + def __lt__(self, other): + "Return a new boolean for the comparison." + return _binary_op(self, other, native._str_lt) + + def __gt__(self, other): + "Return a new boolean for the comparison." + return _binary_op(self, other, native._str_gt) + + def __le__(self, other): + "Return a new boolean for the comparison." + return _negate(self.__gt__(other)) + + def __ge__(self, other): + "Return a new boolean for the comparison." + return _negate(self.__lt__(other)) + + def __eq__(self, other): + "Return a new boolean for the comparison." + return _binary_op(self, other, native._str_eq) + + def __ne__(self, other): + "Return a new boolean for the comparison." + return _negate(self.__eq__(other)) + + def __len__(self): pass + def __str__(self): pass + + def __bool__(self): + return _negate(native._str_eq(self, "")) + + def endswith(self, s): pass + def find(self, sub, start=None, end=None): pass + def index(self, sub, start=None, end=None): pass + def join(self, l): pass + def lower(self): pass + def lstrip(self, chars=None): pass + def replace(self, old, new, count=None): pass + def rfind(self, sub, start=None, end=None): pass + def rsplit(self, sep=None, maxsplit=None): pass + def rstrip(self, chars=None): pass + def split(self, sep=None, maxsplit=None): pass + def splitlines(self, keepends=False): pass + def startswith(self, s): pass + def strip(self, chars=None): pass + def upper(self): pass + + def __iter__(self): + + "Return an iterator." + + return listiterator(self) + +class str(basestring): + pass + +class unicode(basestring): + def encode(self, encoding): pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/__builtins__/tuple.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/__builtins__/tuple.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,62 @@ +#!/usr/bin/env python + +""" +Tuple objects. + +Copyright (C) 2015 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +from __builtins__.sequence import * + +class tuple(object): + + "Implementation of tuple." + + def __init__(self, args): pass + + def __getitem__(self, index): + + "Return the item or slice specified by 'index'." + + return _getitem(self, index) + + def __getslice__(self, start, end=None): + + "Return a slice starting from 'start', with the optional 'end'." + + return _tuple(_getslice(self, start, end)) + + def __len__(self): pass + def __add__(self, other): pass + def __str__(self): pass + + def __bool__(self): + + "Tuples are true if non-empty." + + return self.__len__() != 0 + + def __iter__(self): + + "Return an iterator." + + return listiterator(self) + + # Special implementation methods. + + def __get_single_item__(self, index): pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/_hashlib.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/_hashlib.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,24 @@ +#!/usr/bin/env python + +def new(s=None): + pass + +def openssl_md5(s=None): + pass + +def openssl_sha1(s=None): + pass + +def openssl_sha224(s=None): + pass + +def openssl_sha256(s=None): + pass + +def openssl_sha384(s=None): + pass + +def openssl_sha512(s=None): + pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/_random.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/_random.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,30 @@ +#!/usr/bin/env python + +""" +Random numbers. + +Copyright (C) 2012 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +class Random: + def getrandbits(self, k): pass + def getstate(self): pass + def jumpahead(self, x): pass + def random(self): pass + def seed(self, n=None): pass + def setstate(self, state): pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/_sre.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/_sre.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,44 @@ +#!/usr/bin/env python + +CODESIZE = 4 +MAGIC = 20140812 + +class RegexObject: + + def __init__(self, flags, groups, groupindex, pattern): + self.flags = flags + self.groups = groups + self.groupindex = groupindex + self.pattern = pattern + + def search(self, string, pos=None, endpos=None): pass + def match(self, string, pos=None, endpos=None): pass + def split(self, string, maxsplit=0): pass + def findall(self, string, pos=None, endpos=None): pass + def finditer(self, string, pos=None, endpos=None): pass + def sub(self, repl, string, count=0): pass + def subn(self, repl, string, count=0): pass + +class MatchObject: + + def __init__(self, pos, endpos, lastindex, lastgroup, re, string): + self.pos = pos + self.endpos = endpos + self.lastindex = lastindex + self.lastgroup = lastgroup + self.re = re + self.string = string + + def expand(self, template): pass + def group(self, *groups): pass + def groups(self, default=None): pass + def groupdict(self, default=None): pass + def start(self, group=None): pass + def end(self, group=None): pass + def span(self, group=None): pass + +def compile(pattern, flags=0): pass +def getcodesize(): pass +def getlower(c): pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/_weakref.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/_weakref.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,29 @@ +#!/usr/bin/env python + +""" +Weak references. + +Copyright (C) 2012 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +class ref: + pass + +def getweakrefcount(obj): pass +def getweakrefs(obj): pass +def proxy(obj, callback=None): pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/array.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/array.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,53 @@ +#!/usr/bin/env python + +""" +Array functions and objects. + +Copyright (C) 2011, 2014 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +class array: + + """ + An array of primitive objects. + NOTE: In principle, arrays of full instances could be supported with + NOTE: knowledge of the size of each instance. + """ + + def __init__(self, typecode, itemsize): + self.typecode = typecode + self.itemsize = itemsize + + def append(self, value): pass + def buffer_info(self): pass + def byteswap(self): pass + def count(self, value): pass + def extend(self, l): pass + def fromfile(self, f): pass + def fromlist(self, l): pass + def fromstring(self, s): pass + def index(self, value): pass + def insert(self, index, value): pass + def pop(self): pass + def read(self): pass + def remove(self, value): pass + def reverse(self): pass + def tofile(self): pass + def tolist(self): pass + def tostring(self): pass + def write(self): pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/binascii.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/binascii.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,49 @@ +#!/usr/bin/env python + +def a2b_base64(ascii): + pass + +def a2b_hex(hexstr): + pass + +def a2b_hqx(ascii): + pass + +def a2b_qp(data): + pass + +def a2b_uu(ascii): + pass + +def b2a_base64(data): + pass + +def b2a_hex(data): + pass + +def b2a_hqx(data): + pass + +def b2a_qp(data, quotetabs=0, istext=1, header=0): + pass + +def b2a_uu(data): + pass + +def crc32(data, oldcrc=0): + pass + +def crc_hqx(data, oldcrc): + pass + +hexlify = b2a_hex + +def rlecode_hqx(data): + pass + +def rledecode_hqx(data): + pass + +unhexlify = a2b_hex + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/collections.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/collections.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,36 @@ +#!/usr/bin/env python + +""" +Collections. + +Copyright (C) 2013 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +class defaultdict(dict): + pass + +class deque(object): + def append(x): pass + def appendleft(x): pass + def clear(): pass + def extend(iterable): pass + def extendleft(iterable): pass + def pop(): pass + def popleft(): pass + def remove(value): pass + def rotate(n): pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/copy.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/copy.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,25 @@ +#!/usr/bin/env python + +""" +Copying functions. + +Copyright (C) 2015 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +def copy(x): pass +def deepcopy(x): pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/exceptions.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/exceptions.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,1 @@ +from __builtins__.exception import * diff -r a03de9203c28 -r f551873980e5 lib/genericos.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/genericos.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,48 @@ +#!/usr/bin/env python + +from posix.io import fstat +from posix.filesys import listdir, lstat, readlink +from posix.process import getcwd, getcwdu, getuid + +class OSError(EnvironmentError): + pass + +error = OSError +environ = {} + +def execl(file, *args): pass +def execle(file, *args): pass +def execlp(file, *args): pass +def execlpe(file, *args): pass +def execv(path, args): pass +def execve(path, args, env): pass +def execvp(file, args): pass +def execvpe(file, args, env): pass +def getenv(key, default=None): pass +def makedirs(name, mode=511): pass +def popen2(cmd, mode='t', bufsize=-1): pass +def popen3(cmd, mode='t', bufsize=-1): pass +def popen4(cmd, mode='t', bufsize=-1): pass +def removedirs(name): pass +def renames(old, new): pass +def spawnl(mode, file, *args): pass +def spawnle(mode, file, *args): pass +def spawnlp(mode, file, *args): pass +def spawnlpe(mode, file, *args): pass +def spawnv(mode, file, args): pass +def spawnve(mode, file, args, env): pass +def spawnvp(mode, file, args): pass +def spawnvpe(mode, file, args, env): pass +def walk(top, topdown=True, onerror=None, followlinks=False): pass + +P_WAIT = 0 +P_NOWAIT = P_NOWAITO = 1 + +SEEK_CUR = 1 +SEEK_END = 2 +SEEK_SET = 0 + +name = 'posix' +linesep = '\n' + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/genericpath.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/genericpath.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,105 @@ +""" +Path operations common to more than one OS +Do not use directly. The OS specific modules import the appropriate +functions from this module themselves. +""" +from os import error, stat +from stat import * + +__all__ = ['commonprefix', 'exists', 'getatime', 'getctime', 'getmtime', + 'getsize', 'isdir', 'isfile'] + + +# Does a path exist? +# This is false for dangling symbolic links on systems that support them. +def exists(path): + """Test whether a path exists. Returns False for broken symbolic links""" + try: + stat(path) + except error: + return False + return True + + +# This follows symbolic links, so both islink() and isdir() can be true +# for the same path ono systems that support symlinks +def isfile(path): + """Test whether a path is a regular file""" + try: + st = stat(path) + except error: + return False + return stat.S_ISREG(st.st_mode) + + +# Is a path a directory? +# This follows symbolic links, so both islink() and isdir() +# can be true for the same path on systems that support symlinks +def isdir(s): + """Return true if the pathname refers to an existing directory.""" + try: + st = stat(s) + except error: + return False + return stat.S_ISDIR(st.st_mode) + + +def getsize(filename): + """Return the size of a file, reported by os.stat().""" + return stat(filename).st_size + + +def getmtime(filename): + """Return the last modification time of a file, reported by os.stat().""" + return stat(filename).st_mtime + + +def getatime(filename): + """Return the last access time of a file, reported by os.stat().""" + return stat(filename).st_atime + + +def getctime(filename): + """Return the metadata change time of a file, reported by os.stat().""" + return stat(filename).st_ctime + + +# Return the longest prefix of all list elements. +def commonprefix(m): + "Given a list of pathnames, returns the longest common leading component" + if not m: return '' + s1 = min(m) + s2 = max(m) + for i, c in enumerate(s1): + if c != s2[i]: + return s1[:i] + return s1 + +# Split a path in root and extension. +# The extension is everything starting at the last dot in the last +# pathname component; the root is everything before that. +# It is always true that root + ext == p. + +# Generic implementation of splitext, to be parametrized with +# the separators +def _splitext(p, sep, altsep, extsep): + """Split the extension from a pathname. + + Extension is everything from the last dot to the end, ignoring + leading dots. Returns "(root, ext)"; ext may be empty.""" + + sepIndex = p.rfind(sep) + if altsep: + altsepIndex = p.rfind(altsep) + sepIndex = max(sepIndex, altsepIndex) + + dotIndex = p.rfind(extsep) + if dotIndex > sepIndex: + # skip all leading dots + filenameIndex = sepIndex + 1 + while filenameIndex < dotIndex: + if p[filenameIndex] != extsep: + return p[:dotIndex], p[dotIndex:] + filenameIndex += 1 + + return p, '' diff -r a03de9203c28 -r f551873980e5 lib/itertools.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/itertools.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,199 @@ +#!/usr/bin/env python + +class chain: + def __init__(self, *iterables): + pass + + def __iter__(self): + pass + + def from_iterable(self, iterable): + pass + + def next(self): + pass + +class combinations: + def __init__(self, iterable, r): + pass + + def __iter__(self): + pass + + def next(self): + pass + +class combinations_with_replacement: + def __init__(self, iterable, r): + pass + + def __iter__(self): + pass + + def next(self): + pass + +class compress: + def __init__(self, data, selectors): + pass + + def __iter__(self): + pass + + def next(self): + pass + +class count: + def __init__(self, start=0, step=1): + pass + + def __iter__(self): + pass + + def next(self): + pass + +class cycle: + def __init__(self, iterable): + pass + + def __iter__(self): + pass + + def next(self): + pass + +class dropwhile: + def __init__(self, predicate, iterable): + pass + + def __iter__(self): + pass + + def next(self): + pass + +class groupby: + def __init__(self, iterable, keyfunc=None): + pass + + def __iter__(self): + pass + + def next(self): + pass + +class ifilter: + def __init__(self, function, sequence): + pass + + def __iter__(self): + pass + + def next(self): + pass + +class ifilterfalse: + def __init__(self, function, sequence): + pass + + def __iter__(self): + pass + + def next(self): + pass + +class imap: + def __init__(self, func, *iterables): + pass + + def __iter__(self): + pass + + def next(self): + pass + +class islice: + def __init__(self, iterable, start_or_stop, stop=None, step=None): + pass + + def __iter__(self): + pass + + def next(self): + pass + +class izip: + def __init__(self, *args): + pass + + def __iter__(self): + pass + + def next(self): + pass + +class izip_longest: + def __init__(self, *args, **kw): #fillvalue=None + pass + + def __iter__(self): + pass + + def next(self): + pass + +class permutations: + def __init__(self, iterable, r=None): + pass + + def __iter__(self): + pass + + def next(self): + pass + +class product: + def __init__(self, *iterables): + pass + + def __iter__(self): + pass + + def next(self): + pass + +class repeat: + def __init__(self, object, times=None): + pass + + def __iter__(self): + pass + + def next(self): + pass + +class starmap: + def __init__(self, function, sequence): + pass + + def __iter__(self): + pass + + def next(self): + pass + +class takewhile: + def __init__(self, predicate, iterable): + pass + + def __iter__(self): + pass + + def next(self): + pass + +def tee(iterable, n=2): + pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/math.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/math.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,58 @@ +#!/usr/bin/env python + +""" +Mathematical functions. + +Copyright (C) 2012 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +def pow(x, y): + + "Return x ** y." + + return x ** y + +def acos(x): pass +def asin(x): pass +def atan(x): pass +def atan2(y, x): pass +def ceil(x): pass +def cos(x): pass +def cosh(x): pass +def degrees(x): pass +def exp(x): pass +def fabs(x): pass +def floor(x): pass +def fmod(x, y): pass +def frexp(x): pass +def hypot(x, y): pass +def ldexp(x, i): pass +def log(x, base=None): pass +def log10(x): pass +def modf(x): pass +def radians(x): pass +def sin(x): pass +def sinh(x): pass +def sqrt(x): pass +def tan(x): pass +def tanh(x): pass + +# NOTE: From Python 2.7 on i386. + +e = 2.718281828459045 +pi = 3.141592653589793 + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/native.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/native.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,51 @@ +#!/usr/bin/env python + +""" +Native library functions. + +Copyright (C) 2011, 2015, 2016 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +def _is(x, y): pass +def _is_not(x, y): pass + +def _int_add(self, other): pass +def _int_sub(self, other): pass +def _int_mul(self, other): pass +def _int_div(self, other): pass +def _int_mod(self, other): pass +def _int_pow(self, other): pass +def _int_and(self, other): pass +def _int_or(self, other): pass +def _int_xor(self, other): pass + +def _int_rsub(self, other): pass +def _int_rdiv(self, other): pass +def _int_rmod(self, other): pass +def _int_rpow(self, other): pass + +def _int_lt(self, other): pass +def _int_gt(self, other): pass +def _int_eq(self, other): pass + +def _str_add(self, other): pass +def _str_lt(self, other): pass +def _str_gt(self, other): pass +def _str_eq(self, other): pass + +def _isinstance(obj, cls): pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/operator/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/operator/__init__.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,28 @@ +#!/usr/bin/env python + +""" +Operator support. + +Copyright (C) 2015, 2016 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +from operator.binary import * +from operator.unary import * +from operator.augmented import * +from operator.comparison import * +from operator.sequence import * + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/operator/augmented.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/operator/augmented.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,69 @@ +#!/usr/bin/env python + +""" +Operator support. + +Copyright (C) 2010, 2013, 2015 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +from operator.core import augassign + +# These functions defer method lookup by wrapping the attribute access in +# lambda functions. Thus, the appropriate methods are defined locally, but no +# attempt to obtain them is made until the generic function is called. + +# NOTE: The compiler should make it possible for the following functions to call +# NOTE: the generic operator implementations with no additional call overhead. + +# Augmented assignment functions. + +def iadd(a, b): + return augassign(a, b, lambda a: a.__iadd__, lambda a: a.__add__, lambda b: b.__radd__) + +def iand_(a, b): + return augassign(a, b, lambda a: a.__iand__, lambda a: a.__and__, lambda b: b.__rand__) + +def idiv(a, b): + return augassign(a, b, lambda a: a.__idiv__, lambda a: a.__div__, lambda b: b.__rdiv__) + +def ifloordiv(a, b): + return augassign(a, b, lambda a: a.__ifloordiv__, lambda a: a.__floordiv__, lambda b: b.__rfloordiv__) + +def ilshift(a, b): + return augassign(a, b, lambda a: a.__ilshift__, lambda a: a.__lshift__, lambda b: b.__rlshift__) + +def imod(a, b): + return augassign(a, b, lambda a: a.__imod__, lambda a: a.__mod__, lambda b: b.__rmod__) + +def imul(a, b): + return augassign(a, b, lambda a: a.__imul__, lambda a: a.__mul__, lambda b: b.__rmul__) + +def ior_(a, b): + return augassign(a, b, lambda a: a.__ior__, lambda a: a.__or__, lambda b: b.__ror__) + +def ipow(a, b): + return augassign(a, b, lambda a: a.__ipow__, lambda a: a.__pow__, lambda b: b.__rpow__) + +def irshift(a, b): + return augassign(a, b, lambda a: a.__irshift__, lambda a: a.__rshift__, lambda b: b.__rrshift__) + +def isub(a, b): + return augassign(a, b, lambda a: a.__isub__, lambda a: a.__sub__, lambda b: b.__rsub__) + +def ixor(a, b): + return augassign(a, b, lambda a: a.__ixor__, lambda a: a.__xor__, lambda b: b.__rxor__) + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/operator/binary.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/operator/binary.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,78 @@ +#!/usr/bin/env python + +""" +Operator support. + +Copyright (C) 2010, 2013, 2015, 2016 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +from operator.core import binary_op, is_, is_not + +# These functions defer method lookup by wrapping the attribute access in +# lambda functions. Thus, the appropriate methods are defined locally, but no +# attempt to obtain them is made until the generic function is called. + +# NOTE: The compiler should make it possible for the following functions to call +# NOTE: the generic operator implementations with no additional call overhead. + +# Binary operator functions. + +def add(a, b): + return binary_op(a, b, lambda a: a.__add__, lambda b: b.__radd__) + +def and_(a, b): + return binary_op(a, b, lambda a: a.__and__, lambda b: b.__rand__) + +def contains(a, b): + return in_(b, a) + +def div(a, b): + return binary_op(a, b, lambda a: a.__div__, lambda b: b.__rdiv__) + +def floordiv(a, b): + return binary_op(a, b, lambda a: a.__floordiv__, lambda b: b.__rfloordiv__) + +def in_(a, b): + return a.__contains__(b) + +def not_in(a, b): + return not a.__contains__(b) + +def lshift(a, b): + return binary_op(a, b, lambda a: a.__lshift__, lambda b: b.__rlshift__) + +def mod(a, b): + return binary_op(a, b, lambda a: a.__mod__, lambda b: b.__rmod__) + +def mul(a, b): + return binary_op(a, b, lambda a: a.__mul__, lambda b: b.__rmul__) + +def or_(a, b): + return binary_op(a, b, lambda a: a.__or__, lambda b: b.__ror__) + +def pow(a, b): + return binary_op(a, b, lambda a: a.__pow__, lambda b: b.__rpow__) + +def rshift(a, b): + return binary_op(a, b, lambda a: a.__rshift__, lambda b: b.__rrshift__) + +def sub(a, b): + return binary_op(a, b, lambda a: a.__sub__, lambda b: b.__rsub__) + +def xor(a, b): + return binary_op(a, b, lambda a: a.__xor__, lambda b: b.__rxor__) + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/operator/comparison.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/operator/comparison.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,51 @@ +#!/usr/bin/env python + +""" +Operator support. + +Copyright (C) 2010, 2013, 2015 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +from operator.core import binary_op + +# These functions defer method lookup by wrapping the attribute access in +# lambda functions. Thus, the appropriate methods are defined locally, but no +# attempt to obtain them is made until the generic function is called. + +# NOTE: The compiler should make it possible for the following functions to call +# NOTE: the generic operator implementations with no additional call overhead. + +# Comparison functions. + +def eq(a, b): + return binary_op(a, b, lambda a: a.__eq__, lambda b: b.__eq__) + +def ge(a, b): + return binary_op(a, b, lambda a: a.__ge__, lambda b: b.__le__) + +def gt(a, b): + return binary_op(a, b, lambda a: a.__gt__, lambda b: b.__lt__) + +def le(a, b): + return binary_op(a, b, lambda a: a.__le__, lambda b: b.__ge__) + +def lt(a, b): + return binary_op(a, b, lambda a: a.__lt__, lambda b: b.__gt__) + +def ne(a, b): + return binary_op(a, b, lambda a: a.__ne__, lambda b: b.__ne__) + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/operator/core.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/operator/core.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,114 @@ +#!/usr/bin/env python + +""" +Operator support. + +Copyright (C) 2010, 2013, 2015, 2016 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +# Define "is" and "is not" in terms of native operations. They are imported by +# the operator.binary module. + +from native import _is as is_, _is_not as is_not + +def binary_op(a, b, left_accessor, right_accessor): + + """ + A single parameterised function providing the binary operator mechanism for + arguments 'a' and 'b' using accessors given as 'left_accessor' and + 'right_accessor' which provide the methods for the operands. + """ + + # First, try and get a method for the left argument, and then call it with + # the right argument. + + try: + fn = left_accessor(a) + except AttributeError: + pass + else: + result = fn(b) + if is_not(result, NotImplemented): + return result + + # Otherwise, try and get a method for the right argument, and then call it + # with the left argument. + + try: + fn = right_accessor(b) + except AttributeError: + pass + else: + result = fn(a) + if is_not(result, NotImplemented): + return result + + # Where no methods were available, or if neither method could support the + # operation, raise an exception. + + raise TypeError + +def unary_op(a, accessor): + + """ + A single parameterised function providing the unary operator mechanism for + the argument 'a' using the given 'accessor' to provide the method for the + operand. + """ + + # First, try and get a method for the argument, and then call it. + + try: + fn = accessor(a) + except AttributeError: + pass + else: + result = fn() + if is_not(result, NotImplemented): + return result + + # Where no method was available, or if the method could not support the + # operation, raise an exception. + + raise TypeError + +def augassign(a, b, augmented_accessor, left_accessor, right_accessor): + + """ + A single parameterised function providing the augmented assignment mechanism + for arguments 'a' and 'b' either using 'augmented_accessor' (directly + affecting 'a') or using 'left_accessor' and 'right_accessor' (conventional + operator method accessors). + + The result of the assignment is returned. + """ + + # First, try and get a method that directly affects the assignment target. + + try: + fn = augmented_accessor(a) + except AttributeError: + pass + else: + result = fn(b) + if is_not(result, NotImplemented): + return result + + # Otherwise, attempt a conventional binary operation. + + return binary_op(a, b, left_accessor, right_accessor) + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/operator/sequence.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/operator/sequence.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,46 @@ +#!/usr/bin/env python + +""" +Operator support. + +Copyright (C) 2010, 2013, 2015 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +# Necessary import since the operator module gets imported very early during +# builtins initialisation. + +from __builtins__.span import slice + +# NOTE: The compiler should make it possible for the following functions to call +# NOTE: the generic operator implementations with no additional call overhead. + +# Access and slicing functions. + +def getitem(a, b): + return a.__getitem__(b) + +def setitem(a, b, c): + a.__setitem__(b, c) + +# NOTE: Should be able to optimise temporary instance allocations for slices. + +def getslice(a, b, c): + return a.__getitem__(slice(b, c)) + +def setslice(a, b, c, d): + a.__setitem__(slice(b, c), d) + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/operator/unary.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/operator/unary.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,45 @@ +#!/usr/bin/env python + +""" +Operator support. + +Copyright (C) 2010, 2013, 2015 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +from operator.core import unary_op + +# These functions defer method lookup by wrapping the attribute access in +# lambda functions. Thus, the appropriate methods are defined locally, but no +# attempt to obtain them is made until the generic function is called. + +# NOTE: The compiler should make it possible for the following functions to call +# NOTE: the generic operator implementations with no additional call overhead. + +# Unary operator functions. + +def invert(a): + return unary_op(a, lambda a: a.__invert__) + +def neg(a): + return unary_op(a, lambda a: a.__neg__) + +def not_(a): + return not a + +def pos(a): + return unary_op(a, lambda a: a.__pos__) + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/os.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/os.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,19 @@ +#!/usr/bin/env python + +from posix import * +from genericos import * + +import posixpath as path + +from posixpath import ( + altsep, + curdir, + defpath, + devnull, + extsep, + pardir, + pathsep, + sep + ) + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/parser.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/parser.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,27 @@ +#!/usr/bin/env python + +class ASTType: + pass + +class ParserError(Exception): + pass + +class STType: + pass + +def ast2list(ast): pass +def ast2tuple(ast): pass +def compileast(ast, filename=None): pass +def compilest(st): pass +def expr(s): pass +def isexpr(ast): pass +def issuite(ast): pass +def sequence2ast(sequence): pass +def sequence2st(sequence): pass +def st2list(st, line_info=None, col_info=None): pass +def st2tuple(st, line_info=None, col_info=None): pass +def suite(suite): pass +def tuple2ast(sequence): pass +def tuple2st(sequence): pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/posix/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/posix/__init__.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,12 @@ +#!/usr/bin/env python + +from posix.core import name, linesep +from posix.conf import * +from posix.filesys import * +from posix.io import * +from posix.process import * +from posix.random import * +from posix.stat import * +from posix.temp import * + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/posix/conf.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/posix/conf.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,8 @@ +#!/usr/bin/env python + +def confstr(name): pass +def pathconf(path, name): pass +def strerror(code): pass +def sysconf(name): pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/posix/core.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/posix/core.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,6 @@ +#!/usr/bin/env python + +name = 'posix' +linesep = '\n' + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/posix/filesys.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/posix/filesys.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,31 @@ +#!/usr/bin/env python + +def access(path, mode): pass +def chdir(path): pass +def chmod(path, mode): pass +def chown(path, uid, gid): pass +def lchown(path, uid, gid): pass +def link(src, dst): pass +def listdir(path): pass +def lstat(path): pass +def major(device): pass +def makedev(major, minor): pass +def minor(device): pass +def mkdir(path, mode=0777): pass +def mkfifo(filename, mode=0666): pass +def mknod(filename, mode=0600, device=None): pass +def read(fd, buffersize): pass +def readlink(path): pass +def remove(path): pass +def rename(old, new): pass +def rmdir(path): pass +def symlink(src, dst): pass +def unlink(path): pass +def utime(path, (atime, mtime)): pass + +F_OK = 0 +R_OK = 4 +W_OK = 2 +X_OK = 1 + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/posix/io.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/posix/io.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,54 @@ +#!/usr/bin/env python + +def close(fd): pass +def closerange(fd_low, fd_high): pass +def dup(fd): pass +def dup2(old_fd, new_fd): pass +def fchdir(fildes): pass +def fchmod(fd, mode): pass +def fchown(fd, uid, gid): pass +def fdatasync(fildes): pass +def fdopen(fd, mode='r', bufsize=None): pass +def fpathconf(fd, name): pass +def fstat(fd): pass +def fstatvfs(fd): pass +def fsync(fildes): pass +def ftruncate(fd, length): pass +def isatty(fd): pass +def lseek(fd, pos, how): pass +def open(filename, flag, mode=0777): pass +def openpty(): pass +def pipe(): pass +def putenv(key, value): pass +def times(): pass +def ttyname(fd): pass +def umask(new_mask): pass +def uname(): pass +def unsetenv(key): pass +def write(fd, string): pass + +O_APPEND = 1024 +O_ASYNC = 8192 +O_CREAT = 64 +O_DIRECT = 16384 +O_DIRECTORY = 65536 +O_DSYNC = 4096 +O_EXCL = 128 +O_LARGEFILE = 32768 +O_NDELAY = 2048 +O_NOATIME = 262144 +O_NOCTTY = 256 +O_NOFOLLOW = 131072 +O_NONBLOCK = 2048 +O_RDONLY = 0 +O_RDWR = 2 +O_RSYNC = 1052672 +O_SYNC = 1052672 +O_TRUNC = 512 +O_WRONLY = 1 + +SEEK_CUR = 1 +SEEK_END = 2 +SEEK_SET = 0 + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/posix/process.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/posix/process.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,86 @@ +#!/usr/bin/env python + +def abort(): pass +def chroot(path): pass +def ctermid(): pass +def execv(path, args): pass +def execve(path, args, env): pass +def fork(): pass +def forkpty(): pass +def getcwd(): pass +def getcwdu(): pass +def getegid(): pass +def geteuid(): pass +def getgid(): pass +def getgroups(): pass +def getloadavg(): pass +def getlogin(): pass +def getpgid(pid): pass +def getpgrp(): pass +def getpid(): pass +def getppid(): pass +def getresgid(): pass +def getresuid(): pass +def getsid(pid): pass +def getuid(): pass +def initgroups(username, gid): pass +def kill(pid, sig): pass +def killpg(pgid, sig): pass +def nice(inc): pass +def popen(command, mode='r', bufsize=None): pass +def setegid(gid): pass +def seteuid(uid): pass +def setgid(gid): pass +def setgroups(list): pass +def setpgid(pid, pgrp): pass +def setpgrp(): pass +def setregid(rgid, egid): pass +def setresgid(rgid, egid, sgid): pass +def setresuid(ruid, euid, suid): pass +def setreuid(ruid, euid): pass +def setsid(): pass +def setuid(uid): pass +def system(command): pass +def tcgetpgrp(fd): pass +def tcsetpgrp(fd, pgid): pass +def wait(): pass +def wait3(options): pass +def wait4(pid, options): pass +def waitpid(pid, options): pass + +def WCOREDUMP(status): pass +def WEXITSTATUS(status): pass +def WIFCONTINUED(status): pass +def WIFEXITED(status): pass +def WIFSIGNALED(status): pass +def WIFSTOPPED(status): pass +def WSTOPSIG(status): pass +def WTERMSIG(status): pass + +EX_CANTCREAT = 73 +EX_CONFIG = 78 +EX_DATAERR = 65 +EX_IOERR = 74 +EX_NOHOST = 68 +EX_NOINPUT = 66 +EX_NOPERM = 77 +EX_NOUSER = 67 +EX_OK = 0 +EX_OSERR = 71 +EX_OSFILE = 72 +EX_PROTOCOL = 76 +EX_SOFTWARE = 70 +EX_TEMPFAIL = 75 +EX_UNAVAILABLE = 69 +EX_USAGE = 64 + +NGROUPS_MAX = 65536 + +P_WAIT = 0 +P_NOWAIT = P_NOWAITO = 1 + +WCONTINUED = 8 +WNOHANG = 1 +WUNTRACED = 2 + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/posix/random.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/posix/random.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,5 @@ +#!/usr/bin/env python + +def urandom(n): pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/posix/stat.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/posix/stat.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,56 @@ +#!/usr/bin/env python + +class stat_result: + def __init__(self, st_atime, st_blksize, st_blocks, st_ctime, st_dev, st_gid, st_ino, st_mode, st_mtime, st_nlink, st_rdev, st_size, st_uid): + self.st_atime = st_atime + self.st_blksize = st_blksize + self.st_blocks = st_blocks + self.st_ctime = st_ctime + self.st_dev = st_dev + self.st_gid = st_gid + self.st_ino = st_ino + self.st_mode = st_mode + self.st_mtime = st_mtime + self.st_nlink = st_nlink + self.st_rdev = st_rdev + self.st_size = st_size + self.st_uid = st_uid + + n_fields = 16 + n_sequence_fields = 10 + n_unnamed_fields = 3 + +class statvfs_result: + def __init__(self, f_bavail, f_bfree, f_blocks, f_bsize, f_favail, f_ffree, f_files, f_flag, f_frsize, f_namemax): + self.f_bavail = f_bavail + self.f_bfree = f_bfree + self.f_blocks = f_blocks + self.f_bsize = f_bsize + self.f_favail = f_favail + self.f_ffree = f_ffree + self.f_files = f_files + self.f_flag = f_flag + self.f_frsize = f_frsize + self.f_namemax = f_namemax + + n_fields = 10 + n_sequence_fields = 10 + n_unnamed_fields = 0 + +def stat(path): pass +def stat_float_times(newval=None): pass +def statvfs(path): pass + +ST_APPEND = 256 +ST_MANDLOCK = 64 +ST_NOATIME = 1024 +ST_NODEV = 4 +ST_NODIRATIME = 2048 +ST_NOEXEC = 8 +ST_NOSUID = 2 +ST_RDONLY = 1 +ST_RELATIME = 4096 +ST_SYNCHRONOUS = 16 +ST_WRITE = 128 + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/posix/temp.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/posix/temp.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,9 @@ +#!/usr/bin/env python + +def tempnam(dir=None, prefix=None): pass +def tmpfile(): pass +def tmpnam(): pass + +TMP_MAX = 238328 + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/posixpath.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/posixpath.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,420 @@ +"""Common operations on Posix pathnames. + +Instead of importing this module directly, import os and refer to +this module as os.path. The "os.path" name is an alias for this +module on Posix systems; on other systems (e.g. Mac, Windows), +os.path provides the same operations in a manner specific to that +platform, and is an alias to another module (e.g. macpath, ntpath). + +Some of this can actually be useful on non-Posix systems too, e.g. +for manipulation of the pathname component of URLs. +""" + +from genericos import environ, error, fstat, getcwd, getcwdu, getuid, listdir, lstat, readlink +import sys +import stat +import genericpath +from genericpath import * + +try: + _unicode = unicode +except NameError: + # If Python is built without Unicode support, the unicode type + # will not exist. Fake one. + class _unicode(object): + pass + +__all__ = ["normcase","isabs","join","splitdrive","split","splitext", + "basename","dirname","commonprefix","getsize","getmtime", + "getatime","getctime","islink","exists","lexists","isdir","isfile", + "ismount","walk","expanduser","expandvars","normpath","abspath", + "samefile","sameopenfile","samestat", + "curdir","pardir","sep","pathsep","defpath","altsep","extsep", + "devnull","realpath","supports_unicode_filenames","relpath"] + +# strings representing various path-related bits and pieces +curdir = '.' +pardir = '..' +extsep = '.' +sep = '/' +pathsep = ':' +defpath = ':/bin:/usr/bin' +altsep = None +devnull = '/dev/null' + +# Normalize the case of a pathname. Trivial in Posix, string.lower on Mac. +# On MS-DOS this may also turn slashes into backslashes; however, other +# normalizations (such as optimizing '../' away) are not allowed +# (another function should be defined to do that). + +def normcase(s): + """Normalize case of pathname. Has no effect under Posix""" + return s + + +# Return whether a path is absolute. +# Trivial in Posix, harder on the Mac or MS-DOS. + +def isabs(s): + """Test whether a path is absolute""" + return s.startswith('/') + + +# Join pathnames. +# Ignore the previous parts if a part is absolute. +# Insert a '/' unless the first part is empty or already ends in '/'. + +def join(a, *p): + """Join two or more pathname components, inserting '/' as needed. + If any component is an absolute path, all previous path components + will be discarded. An empty last part will result in a path that + ends with a separator.""" + path = a + for b in p: + if b.startswith('/'): + path = b + elif path == '' or path.endswith('/'): + path += b + else: + path += '/' + b + return path + + +# Split a path in head (everything up to the last '/') and tail (the +# rest). If the path ends in '/', tail will be empty. If there is no +# '/' in the path, head will be empty. +# Trailing '/'es are stripped from head unless it is the root. + +def split(p): + """Split a pathname. Returns tuple "(head, tail)" where "tail" is + everything after the final slash. Either part may be empty.""" + i = p.rfind('/') + 1 + head, tail = p[:i], p[i:] + if head and head != '/'*len(head): + head = head.rstrip('/') + return head, tail + + +# Split a path in root and extension. +# The extension is everything starting at the last dot in the last +# pathname component; the root is everything before that. +# It is always true that root + ext == p. + +def splitext(p): + return genericpath._splitext(p, sep, altsep, extsep) + +# Split a pathname into a drive specification and the rest of the +# path. Useful on DOS/Windows/NT; on Unix, the drive is always empty. + +def splitdrive(p): + """Split a pathname into drive and path. On Posix, drive is always + empty.""" + return '', p + + +# Return the tail (basename) part of a path, same as split(path)[1]. + +def basename(p): + """Returns the final component of a pathname""" + i = p.rfind('/') + 1 + return p[i:] + + +# Return the head (dirname) part of a path, same as split(path)[0]. + +def dirname(p): + """Returns the directory component of a pathname""" + i = p.rfind('/') + 1 + head = p[:i] + if head and head != '/'*len(head): + head = head.rstrip('/') + return head + + +# Is a path a symbolic link? +# This will always return false on systems where os.lstat doesn't exist. + +def islink(path): + """Test whether a path is a symbolic link""" + try: + st = lstat(path) + except (error, AttributeError): + return False + return stat.S_ISLNK(st.st_mode) + +# Being true for dangling symbolic links is also useful. + +def lexists(path): + """Test whether a path exists. Returns True for broken symbolic links""" + try: + lstat(path) + except error: + return False + return True + + +# Are two filenames really pointing to the same file? + +def samefile(f1, f2): + """Test whether two pathnames reference the same actual file""" + s1 = stat(f1) + s2 = stat(f2) + return samestat(s1, s2) + + +# Are two open files really referencing the same file? +# (Not necessarily the same file descriptor!) + +def sameopenfile(fp1, fp2): + """Test whether two open file objects reference the same file""" + s1 = fstat(fp1) + s2 = fstat(fp2) + return samestat(s1, s2) + + +# Are two stat buffers (obtained from stat, fstat or lstat) +# describing the same file? + +def samestat(s1, s2): + """Test whether two stat buffers reference the same file""" + return s1.st_ino == s2.st_ino and \ + s1.st_dev == s2.st_dev + + +# Is a path a mount point? +# (Does this work for all UNIXes? Is it even guaranteed to work by Posix?) + +def ismount(path): + """Test whether a path is a mount point""" + if islink(path): + # A symlink can never be a mount point + return False + try: + s1 = lstat(path) + s2 = lstat(join(path, '..')) + except error: + return False # It doesn't exist -- so not a mount point :-) + dev1 = s1.st_dev + dev2 = s2.st_dev + if dev1 != dev2: + return True # path/.. on a different device as path + ino1 = s1.st_ino + ino2 = s2.st_ino + if ino1 == ino2: + return True # path/.. is the same i-node as path + return False + + +# Directory tree walk. +# For each directory under top (including top itself, but excluding +# '.' and '..'), func(arg, dirname, filenames) is called, where +# dirname is the name of the directory and filenames is the list +# of files (and subdirectories etc.) in the directory. +# The func may modify the filenames list, to implement a filter, +# or to impose a different order of visiting. + +def walk(top, func, arg): + """Directory tree walk with callback function. + + For each directory in the directory tree rooted at top (including top + itself, but excluding '.' and '..'), call func(arg, dirname, fnames). + dirname is the name of the directory, and fnames a list of the names of + the files and subdirectories in dirname (excluding '.' and '..'). func + may modify the fnames list in-place (e.g. via del or slice assignment), + and walk will only recurse into the subdirectories whose names remain in + fnames; this can be used to implement a filter, or to impose a specific + order of visiting. No semantics are defined for, or required of, arg, + beyond that arg is always passed to func. It can be used, e.g., to pass + a filename pattern, or a mutable object designed to accumulate + statistics. Passing None for arg is common.""" + try: + names = listdir(top) + except error: + return + func(arg, top, names) + for name in names: + name = join(top, name) + try: + st = lstat(name) + except error: + continue + if stat.S_ISDIR(st.st_mode): + walk(name, func, arg) + + +# Expand paths beginning with '~' or '~user'. +# '~' means $HOME; '~user' means that user's home directory. +# If the path doesn't begin with '~', or if the user or $HOME is unknown, +# the path is returned unchanged (leaving error reporting to whatever +# function is called with the expanded path as argument). +# See also module 'glob' for expansion of *, ? and [...] in pathnames. +# (A function should also be defined to do full *sh-style environment +# variable expansion.) + +def expanduser(path): + """Expand ~ and ~user constructions. If user or $HOME is unknown, + do nothing.""" + if not path.startswith('~'): + return path + i = path.find('/', 1) + if i < 0: + i = len(path) + if i == 1: + if 'HOME' not in environ: + import pwd + userhome = pwd.getpwuid(getuid()).pw_dir + else: + userhome = environ['HOME'] + else: + import pwd + try: + pwent = pwd.getpwnam(path[1:i]) + except KeyError: + return path + userhome = pwent.pw_dir + userhome = userhome.rstrip('/') + return (userhome + path[i:]) or '/' + + +# Expand paths containing shell variable substitutions. +# This expands the forms $variable and ${variable} only. +# Non-existent variables are left unchanged. + +_varprog = None + +def expandvars(path): + """Expand shell variables of form $var and ${var}. Unknown variables + are left unchanged.""" + global _varprog + if '$' not in path: + return path + if not _varprog: + import re + _varprog = re.compile(r'\$(\w+|\{[^}]*\})') + i = 0 + while True: + m = _varprog.search(path, i) + if not m: + break + i, j = m.span(0) + name = m.group(1) + if name.startswith('{') and name.endswith('}'): + name = name[1:-1] + if name in environ: + tail = path[j:] + path = path[:i] + environ[name] + i = len(path) + path += tail + else: + i = j + return path + + +# Normalize a path, e.g. A//B, A/./B and A/foo/../B all become A/B. +# It should be understood that this may change the meaning of the path +# if it contains symbolic links! + +def normpath(path): + """Normalize path, eliminating double slashes, etc.""" + # Preserve unicode (if path is unicode) + slash, dot = (u'/', u'.') if isinstance(path, _unicode) else ('/', '.') + if path == '': + return dot + initial_slashes = path.startswith('/') + # POSIX allows one or two initial slashes, but treats three or more + # as single slash. + if (initial_slashes and + path.startswith('//') and not path.startswith('///')): + initial_slashes = 2 + comps = path.split('/') + new_comps = [] + for comp in comps: + if comp in ('', '.'): + continue + if (comp != '..' or (not initial_slashes and not new_comps) or + (new_comps and new_comps[-1] == '..')): + new_comps.append(comp) + elif new_comps: + new_comps.pop() + comps = new_comps + path = slash.join(comps) + if initial_slashes: + path = slash*initial_slashes + path + return path or dot + + +def abspath(path): + """Return an absolute path.""" + if not isabs(path): + if isinstance(path, _unicode): + cwd = getcwdu() + else: + cwd = getcwd() + path = join(cwd, path) + return normpath(path) + + +# Return a canonical path (i.e. the absolute location of a file on the +# filesystem). + +def realpath(filename): + """Return the canonical path of the specified filename, eliminating any +symbolic links encountered in the path.""" + if isabs(filename): + bits = ['/'] + filename.split('/')[1:] + else: + bits = [''] + filename.split('/') + + for i in range(2, len(bits)+1): + component = join(*bits[0:i]) + # Resolve symbolic links. + if islink(component): + resolved = _resolve_link(component) + if resolved is None: + # Infinite loop -- return original component + rest of the path + return abspath(join(*([component] + bits[i:]))) + else: + newpath = join(*([resolved] + bits[i:])) + return realpath(newpath) + + return abspath(filename) + + +def _resolve_link(path): + """Internal helper function. Takes a path and follows symlinks + until we either arrive at something that isn't a symlink, or + encounter a path we've seen before (meaning that there's a loop). + """ + paths_seen = set() + while islink(path): + if path in paths_seen: + # Already seen this path, so we must have a symlink loop + return None + paths_seen.add(path) + # Resolve where the link points to + resolved = readlink(path) + if not isabs(resolved): + dir = dirname(path) + path = normpath(join(dir, resolved)) + else: + path = normpath(resolved) + return path + +supports_unicode_filenames = (sys.platform == 'darwin') + +def relpath(path, start=curdir): + """Return a relative version of a path""" + + if not path: + raise ValueError("no path specified") + + start_list = [x for x in abspath(start).split(sep) if x] + path_list = [x for x in abspath(path).split(sep) if x] + + # Work out how much of the filepath is shared by start and path. + i = len(commonprefix([start_list, path_list])) + + rel_list = [pardir] * (len(start_list)-i) + path_list[i:] + if not rel_list: + return curdir + return join(*rel_list) diff -r a03de9203c28 -r f551873980e5 lib/pwd.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/pwd.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,22 @@ +#!/usr/bin/env python + +class struct_passwd: + + def __init__(self, pw_dir, pw_gecos, pw_gid, pw_name, pw_passwd, pw_shell, pw_uid): + self.pw_dir = pw_dir + self.pw_gecos = pw_gecos + self.pw_gid = pw_gid + self.pw_name = pw_name + self.pw_passwd = pw_passwd + self.pw_shell = pw_shell + self.pw_uid = pw_uid + + n_fields = 7 + n_sequence_fields = 7 + n_unnamed_fields = 0 + +def getpwall(): pass +def getpwnam(name): pass +def getpwuid(uid): pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/pygame/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/pygame/__init__.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,24 @@ +#!/usr/bin/env python + +""" +PyGame compatibility package. + +Copyright (C) 2011 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +from pygame.constants import * + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/pygame/constants.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/pygame/constants.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,281 @@ +#!/usr/bin/env python + +""" +PyGame compatibility package: constant definitions. + +Copyright (C) 2011 Paul Boddie +Copyright (C) 1997-2006 Sam Lantinga (SDL/SDL_keysym.h, originally LGPL 2.1 or later) + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +# The keyboard syms have been cleverly chosen to map to ASCII. + +K_UNKNOWN = 0 +K_FIRST = 0 +K_BACKSPACE = 8 +K_TAB = 9 +K_CLEAR = 12 +K_RETURN = 13 +K_PAUSE = 19 +K_ESCAPE = 27 +K_SPACE = 32 +K_EXCLAIM = 33 +K_QUOTEDBL = 34 +K_HASH = 35 +K_DOLLAR = 36 +K_AMPERSAND = 38 +K_QUOTE = 39 +K_LEFTPAREN = 40 +K_RIGHTPAREN = 41 +K_ASTERISK = 42 +K_PLUS = 43 +K_COMMA = 44 +K_MINUS = 45 +K_PERIOD = 46 +K_SLASH = 47 +K_0 = 48 +K_1 = 49 +K_2 = 50 +K_3 = 51 +K_4 = 52 +K_5 = 53 +K_6 = 54 +K_7 = 55 +K_8 = 56 +K_9 = 57 +K_COLON = 58 +K_SEMICOLON = 59 +K_LESS = 60 +K_EQUALS = 61 +K_GREATER = 62 +K_QUESTION = 63 +K_AT = 64 + +# Skip uppercase letters. + +K_LEFTBRACKET = 91 +K_BACKSLASH = 92 +K_RIGHTBRACKET = 93 +K_CARET = 94 +K_UNDERSCORE = 95 +K_BACKQUOTE = 96 +K_a = 97 +K_b = 98 +K_c = 99 +K_d = 100 +K_e = 101 +K_f = 102 +K_g = 103 +K_h = 104 +K_i = 105 +K_j = 106 +K_k = 107 +K_l = 108 +K_m = 109 +K_n = 110 +K_o = 111 +K_p = 112 +K_q = 113 +K_r = 114 +K_s = 115 +K_t = 116 +K_u = 117 +K_v = 118 +K_w = 119 +K_x = 120 +K_y = 121 +K_z = 122 +K_DELETE = 127 +# End of ASCII mapped keysyms. + +# International keyboard syms. + +K_WORLD_0 = 160 # 0xA0 +K_WORLD_1 = 161 +K_WORLD_2 = 162 +K_WORLD_3 = 163 +K_WORLD_4 = 164 +K_WORLD_5 = 165 +K_WORLD_6 = 166 +K_WORLD_7 = 167 +K_WORLD_8 = 168 +K_WORLD_9 = 169 +K_WORLD_10 = 170 +K_WORLD_11 = 171 +K_WORLD_12 = 172 +K_WORLD_13 = 173 +K_WORLD_14 = 174 +K_WORLD_15 = 175 +K_WORLD_16 = 176 +K_WORLD_17 = 177 +K_WORLD_18 = 178 +K_WORLD_19 = 179 +K_WORLD_20 = 180 +K_WORLD_21 = 181 +K_WORLD_22 = 182 +K_WORLD_23 = 183 +K_WORLD_24 = 184 +K_WORLD_25 = 185 +K_WORLD_26 = 186 +K_WORLD_27 = 187 +K_WORLD_28 = 188 +K_WORLD_29 = 189 +K_WORLD_30 = 190 +K_WORLD_31 = 191 +K_WORLD_32 = 192 +K_WORLD_33 = 193 +K_WORLD_34 = 194 +K_WORLD_35 = 195 +K_WORLD_36 = 196 +K_WORLD_37 = 197 +K_WORLD_38 = 198 +K_WORLD_39 = 199 +K_WORLD_40 = 200 +K_WORLD_41 = 201 +K_WORLD_42 = 202 +K_WORLD_43 = 203 +K_WORLD_44 = 204 +K_WORLD_45 = 205 +K_WORLD_46 = 206 +K_WORLD_47 = 207 +K_WORLD_48 = 208 +K_WORLD_49 = 209 +K_WORLD_50 = 210 +K_WORLD_51 = 211 +K_WORLD_52 = 212 +K_WORLD_53 = 213 +K_WORLD_54 = 214 +K_WORLD_55 = 215 +K_WORLD_56 = 216 +K_WORLD_57 = 217 +K_WORLD_58 = 218 +K_WORLD_59 = 219 +K_WORLD_60 = 220 +K_WORLD_61 = 221 +K_WORLD_62 = 222 +K_WORLD_63 = 223 +K_WORLD_64 = 224 +K_WORLD_65 = 225 +K_WORLD_66 = 226 +K_WORLD_67 = 227 +K_WORLD_68 = 228 +K_WORLD_69 = 229 +K_WORLD_70 = 230 +K_WORLD_71 = 231 +K_WORLD_72 = 232 +K_WORLD_73 = 233 +K_WORLD_74 = 234 +K_WORLD_75 = 235 +K_WORLD_76 = 236 +K_WORLD_77 = 237 +K_WORLD_78 = 238 +K_WORLD_79 = 239 +K_WORLD_80 = 240 +K_WORLD_81 = 241 +K_WORLD_82 = 242 +K_WORLD_83 = 243 +K_WORLD_84 = 244 +K_WORLD_85 = 245 +K_WORLD_86 = 246 +K_WORLD_87 = 247 +K_WORLD_88 = 248 +K_WORLD_89 = 249 +K_WORLD_90 = 250 +K_WORLD_91 = 251 +K_WORLD_92 = 252 +K_WORLD_93 = 253 +K_WORLD_94 = 254 +K_WORLD_95 = 255 # 0xFF + +# Numeric keypad. + +K_KP0 = 256 +K_KP1 = 257 +K_KP2 = 258 +K_KP3 = 259 +K_KP4 = 260 +K_KP5 = 261 +K_KP6 = 262 +K_KP7 = 263 +K_KP8 = 264 +K_KP9 = 265 +K_KP_PERIOD = 266 +K_KP_DIVIDE = 267 +K_KP_MULTIPLY = 268 +K_KP_MINUS = 269 +K_KP_PLUS = 270 +K_KP_ENTER = 271 +K_KP_EQUALS = 272 + +# Arrows + Home/End pad. + +K_UP = 273 +K_DOWN = 274 +K_RIGHT = 275 +K_LEFT = 276 +K_INSERT = 277 +K_HOME = 278 +K_END = 279 +K_PAGEUP = 280 +K_PAGEDOWN = 281 + +# Function keys. + +K_F1 = 282 +K_F2 = 283 +K_F3 = 284 +K_F4 = 285 +K_F5 = 286 +K_F6 = 287 +K_F7 = 288 +K_F8 = 289 +K_F9 = 290 +K_F10 = 291 +K_F11 = 292 +K_F12 = 293 +K_F13 = 294 +K_F14 = 295 +K_F15 = 296 + +# Key state modifier keys. + +K_NUMLOCK = 300 +K_CAPSLOCK = 301 +K_SCROLLOCK = 302 +K_RSHIFT = 303 +K_LSHIFT = 304 +K_RCTRL = 305 +K_LCTRL = 306 +K_RALT = 307 +K_LALT = 308 +K_RMETA = 309 +K_LMETA = 310 +K_LSUPER = 311 # Left "Windows" key +K_RSUPER = 312 # Right "Windows" key +K_MODE = 313 # "Alt Gr" key +K_COMPOSE = 314 # Multi-key compose key + +# Miscellaneous function keys. + +K_HELP = 315 +K_PRINT = 316 +K_SYSREQ = 317 +K_BREAK = 318 +K_MENU = 319 +K_POWER = 320 # Power Macintosh power key +K_EURO = 321 # Some european keyboards +K_UNDO = 322 # Atari keyboard has Undo + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/random.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/random.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,11 @@ +#!/usr/bin/env python + +from _random import Random + +def random(): + pass + +def randrange(start, stop=None, step=1): + pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/re.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/re.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,315 @@ +# +# Secret Labs' Regular Expression Engine +# +# re-compatible interface for the sre matching engine +# +# Copyright (c) 1998-2001 by Secret Labs AB. All rights reserved. +# +# This version of the SRE library can be redistributed under CNRI's +# Python 1.6 license. For any other use, please contact Secret Labs +# AB (info@pythonware.com). +# +# Portions of this engine have been developed in cooperation with +# CNRI. Hewlett-Packard provided funding for 1.6 integration and +# other compatibility work. +# + +r"""Support for regular expressions (RE). + +This module provides regular expression matching operations similar to +those found in Perl. It supports both 8-bit and Unicode strings; both +the pattern and the strings being processed can contain null bytes and +characters outside the US ASCII range. + +Regular expressions can contain both special and ordinary characters. +Most ordinary characters, like "A", "a", or "0", are the simplest +regular expressions; they simply match themselves. You can +concatenate ordinary characters, so last matches the string 'last'. + +The special characters are: + "." Matches any character except a newline. + "^" Matches the start of the string. + "$" Matches the end of the string or just before the newline at + the end of the string. + "*" Matches 0 or more (greedy) repetitions of the preceding RE. + Greedy means that it will match as many repetitions as possible. + "+" Matches 1 or more (greedy) repetitions of the preceding RE. + "?" Matches 0 or 1 (greedy) of the preceding RE. + *?,+?,?? Non-greedy versions of the previous three special characters. + {m,n} Matches from m to n repetitions of the preceding RE. + {m,n}? Non-greedy version of the above. + "\\" Either escapes special characters or signals a special sequence. + [] Indicates a set of characters. + A "^" as the first character indicates a complementing set. + "|" A|B, creates an RE that will match either A or B. + (...) Matches the RE inside the parentheses. + The contents can be retrieved or matched later in the string. + (?iLmsux) Set the I, L, M, S, U, or X flag for the RE (see below). + (?:...) Non-grouping version of regular parentheses. + (?P...) The substring matched by the group is accessible by name. + (?P=name) Matches the text matched earlier by the group named name. + (?#...) A comment; ignored. + (?=...) Matches if ... matches next, but doesn't consume the string. + (?!...) Matches if ... doesn't match next. + (?<=...) Matches if preceded by ... (must be fixed length). + (?= 0x02020000: + __all__.append("finditer") + def finditer(pattern, string, flags=0): + """Return an iterator over all non-overlapping matches in the + string. For each match, the iterator returns a match object. + + Empty matches are included in the result.""" + return _compile(pattern, flags).finditer(string) + +def compile(pattern, flags=0): + "Compile a regular expression pattern, returning a pattern object." + return _compile(pattern, flags) + +def purge(): + "Clear the regular expression cache" + _cache.clear() + _cache_repl.clear() + +def template(pattern, flags=0): + "Compile a template pattern, returning a pattern object" + return _compile(pattern, flags|T) + +_alphanum = frozenset( + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") + +def escape(pattern): + "Escape all non-alphanumeric characters in pattern." + s = list(pattern) + alphanum = _alphanum + for i, c in enumerate(pattern): + if c not in alphanum: + if c == "\000": + s[i] = "\\000" + else: + s[i] = "\\" + c + return pattern[:0].join(s) + +# -------------------------------------------------------------------- +# internals + +_cache = {} +_cache_repl = {} + +_pattern_type = type(sre_compile.compile("", 0)) + +_MAXCACHE = 100 + +def _compile(*key): + # internal: compile pattern + cachekey = (type(key[0]),) + key + p = _cache.get(cachekey) + if p is not None: + return p + pattern, flags = key + if isinstance(pattern, _pattern_type): + if flags: + raise ValueError('Cannot process flags argument with a compiled pattern') + return pattern + if not sre_compile.isstring(pattern): + raise TypeError, "first argument must be string or compiled pattern" + try: + p = sre_compile.compile(pattern, flags) + except error, v: + raise error, v # invalid expression + if len(_cache) >= _MAXCACHE: + _cache.clear() + _cache[cachekey] = p + return p + +def _compile_repl(*key): + # internal: compile replacement pattern + p = _cache_repl.get(key) + if p is not None: + return p + repl, pattern = key + try: + p = sre_parse.parse_template(repl, pattern) + except error, v: + raise error, v # invalid expression + if len(_cache_repl) >= _MAXCACHE: + _cache_repl.clear() + _cache_repl[key] = p + return p + +def _expand(pattern, match, template): + # internal: match.expand implementation hook + template = sre_parse.parse_template(template, pattern) + return sre_parse.expand_template(template, match) + +def _subx(pattern, template): + # internal: pattern.sub/subn implementation helper + template = _compile_repl(template, pattern) + if not template[0] and len(template[1]) == 1: + # literal replacement + return template[1][0] + def filter(match, template=template): + return sre_parse.expand_template(template, match) + return filter + +# -------------------------------------------------------------------- +# experimental stuff (see python-dev discussions for details) + +class Scanner: + def __init__(self, lexicon, flags=0): + self.lexicon = lexicon + # combine phrases into a compound pattern + p = [] + s = sre_parse.Pattern() + s.flags = flags + for phrase, action in lexicon: + p.append(sre_parse.SubPattern(s, [ + (SUBPATTERN, (len(p)+1, sre_parse.parse(phrase, flags))), + ])) + s.groups = len(p)+1 + p = sre_parse.SubPattern(s, [(BRANCH, (None, p))]) + self.scanner = sre_compile.compile(p) + def scan(self, string): + result = [] + append = result.append + match = self.scanner.scanner(string).match + i = 0 + while 1: + m = match() + if not m: + break + j = m.end() + if i == j: + break + action = self.lexicon[m.lastindex-1][1] + if hasattr(action, '__call__'): + self.match = m + action = action(self, m.group()) + if action is not None: + append(action) + i = j + return result, string[i:] diff -r a03de9203c28 -r f551873980e5 lib/sre_constants.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/sre_constants.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,216 @@ +# +# Secret Labs' Regular Expression Engine +# +# various symbols used by the regular expression engine. +# +# Copyright (c) 1998-2001 by Secret Labs AB. All rights reserved. +# +# See the sre.py file for information on usage and redistribution. +# + +"""Internal support module for sre""" + +# update when constants are added or removed + +MAGIC = 20031017 + +# max code word in this release + +MAXREPEAT = 65535 + +# SRE standard exception (access as sre.error) +# should this really be here? + +class error(Exception): + pass + +# operators + +FAILURE = "failure" +SUCCESS = "success" + +ANY = "any" +ANY_ALL = "any_all" +ASSERT = "assert" +ASSERT_NOT = "assert_not" +AT = "at" +BIGCHARSET = "bigcharset" +BRANCH = "branch" +CALL = "call" +CATEGORY = "category" +CHARSET = "charset" +GROUPREF = "groupref" +GROUPREF_IGNORE = "groupref_ignore" +GROUPREF_EXISTS = "groupref_exists" +IN = "in" +IN_IGNORE = "in_ignore" +INFO = "info" +JUMP = "jump" +LITERAL = "literal" +LITERAL_IGNORE = "literal_ignore" +MARK = "mark" +MAX_REPEAT = "max_repeat" +MAX_UNTIL = "max_until" +MIN_REPEAT = "min_repeat" +MIN_UNTIL = "min_until" +NEGATE = "negate" +NOT_LITERAL = "not_literal" +NOT_LITERAL_IGNORE = "not_literal_ignore" +RANGE = "range" +REPEAT = "repeat" +REPEAT_ONE = "repeat_one" +SUBPATTERN = "subpattern" +MIN_REPEAT_ONE = "min_repeat_one" + +# positions +AT_BEGINNING = "at_beginning" +AT_BEGINNING_LINE = "at_beginning_line" +AT_BEGINNING_STRING = "at_beginning_string" +AT_BOUNDARY = "at_boundary" +AT_NON_BOUNDARY = "at_non_boundary" +AT_END = "at_end" +AT_END_LINE = "at_end_line" +AT_END_STRING = "at_end_string" +AT_LOC_BOUNDARY = "at_loc_boundary" +AT_LOC_NON_BOUNDARY = "at_loc_non_boundary" +AT_UNI_BOUNDARY = "at_uni_boundary" +AT_UNI_NON_BOUNDARY = "at_uni_non_boundary" + +# categories +CATEGORY_DIGIT = "category_digit" +CATEGORY_NOT_DIGIT = "category_not_digit" +CATEGORY_SPACE = "category_space" +CATEGORY_NOT_SPACE = "category_not_space" +CATEGORY_WORD = "category_word" +CATEGORY_NOT_WORD = "category_not_word" +CATEGORY_LINEBREAK = "category_linebreak" +CATEGORY_NOT_LINEBREAK = "category_not_linebreak" +CATEGORY_LOC_WORD = "category_loc_word" +CATEGORY_LOC_NOT_WORD = "category_loc_not_word" +CATEGORY_UNI_DIGIT = "category_uni_digit" +CATEGORY_UNI_NOT_DIGIT = "category_uni_not_digit" +CATEGORY_UNI_SPACE = "category_uni_space" +CATEGORY_UNI_NOT_SPACE = "category_uni_not_space" +CATEGORY_UNI_WORD = "category_uni_word" +CATEGORY_UNI_NOT_WORD = "category_uni_not_word" +CATEGORY_UNI_LINEBREAK = "category_uni_linebreak" +CATEGORY_UNI_NOT_LINEBREAK = "category_uni_not_linebreak" + +OPCODES = [ + + # failure=0 success=1 (just because it looks better that way :-) + FAILURE, SUCCESS, + + ANY, ANY_ALL, + ASSERT, ASSERT_NOT, + AT, + BRANCH, + CALL, + CATEGORY, + CHARSET, BIGCHARSET, + GROUPREF, GROUPREF_EXISTS, GROUPREF_IGNORE, + IN, IN_IGNORE, + INFO, + JUMP, + LITERAL, LITERAL_IGNORE, + MARK, + MAX_UNTIL, + MIN_UNTIL, + NOT_LITERAL, NOT_LITERAL_IGNORE, + NEGATE, + RANGE, + REPEAT, + REPEAT_ONE, + SUBPATTERN, + MIN_REPEAT_ONE + +] + +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 +] + +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 +] + +def makedict(list): + d = {} + i = 0 + for item in list: + d[item] = i + i = i + 1 + return d + +OPCODES = makedict(OPCODES) +ATCODES = makedict(ATCODES) +CHCODES = makedict(CHCODES) + +# replacement operations for "ignore case" mode +OP_IGNORE = { + GROUPREF: GROUPREF_IGNORE, + IN: IN_IGNORE, + LITERAL: LITERAL_IGNORE, + NOT_LITERAL: NOT_LITERAL_IGNORE +} + +AT_MULTILINE = { + AT_BEGINNING: AT_BEGINNING_LINE, + AT_END: AT_END_LINE +} + +AT_LOCALE = { + AT_BOUNDARY: AT_LOC_BOUNDARY, + AT_NON_BOUNDARY: AT_LOC_NON_BOUNDARY +} + +AT_UNICODE = { + AT_BOUNDARY: AT_UNI_BOUNDARY, + AT_NON_BOUNDARY: AT_UNI_NON_BOUNDARY +} + +CH_LOCALE = { + CATEGORY_DIGIT: CATEGORY_DIGIT, + CATEGORY_NOT_DIGIT: CATEGORY_NOT_DIGIT, + CATEGORY_SPACE: CATEGORY_SPACE, + CATEGORY_NOT_SPACE: CATEGORY_NOT_SPACE, + CATEGORY_WORD: CATEGORY_LOC_WORD, + CATEGORY_NOT_WORD: CATEGORY_LOC_NOT_WORD, + CATEGORY_LINEBREAK: CATEGORY_LINEBREAK, + CATEGORY_NOT_LINEBREAK: CATEGORY_NOT_LINEBREAK +} + +CH_UNICODE = { + CATEGORY_DIGIT: CATEGORY_UNI_DIGIT, + CATEGORY_NOT_DIGIT: CATEGORY_UNI_NOT_DIGIT, + CATEGORY_SPACE: CATEGORY_UNI_SPACE, + CATEGORY_NOT_SPACE: CATEGORY_UNI_NOT_SPACE, + CATEGORY_WORD: CATEGORY_UNI_WORD, + CATEGORY_NOT_WORD: CATEGORY_UNI_NOT_WORD, + CATEGORY_LINEBREAK: CATEGORY_UNI_LINEBREAK, + CATEGORY_NOT_LINEBREAK: CATEGORY_UNI_NOT_LINEBREAK +} + +# flags +SRE_FLAG_TEMPLATE = 1 # template mode (disable backtracking) +SRE_FLAG_IGNORECASE = 2 # case insensitive +SRE_FLAG_LOCALE = 4 # honour system locale +SRE_FLAG_MULTILINE = 8 # treat target as multiline string +SRE_FLAG_DOTALL = 16 # treat target as a single string +SRE_FLAG_UNICODE = 32 # use unicode locale +SRE_FLAG_VERBOSE = 64 # ignore whitespace and comments +SRE_FLAG_DEBUG = 128 # debugging + +# flags for INFO primitive +SRE_INFO_PREFIX = 1 # has prefix +SRE_INFO_LITERAL = 2 # entire pattern is literal (given by prefix) +SRE_INFO_CHARSET = 4 # pattern starts with character from given set diff -r a03de9203c28 -r f551873980e5 lib/sre_parse.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/sre_parse.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,791 @@ +# +# Secret Labs' Regular Expression Engine +# +# convert re-style regular expression to sre pattern +# +# Copyright (c) 1998-2001 by Secret Labs AB. All rights reserved. +# +# See the sre.py file for information on usage and redistribution. +# + +"""Internal support module for sre""" + +# XXX: show string offset and offending character for all errors + +import sys + +from sre_constants import * + +SPECIAL_CHARS = ".\\[{()*+?^$|" +REPEAT_CHARS = "*+?{" + +DIGITS = set("0123456789") + +OCTDIGITS = set("01234567") +HEXDIGITS = set("0123456789abcdefABCDEF") + +WHITESPACE = set(" \t\n\r\v\f") + +ESCAPES = { + r"\a": (LITERAL, ord("\a")), + r"\b": (LITERAL, ord("\b")), + r"\f": (LITERAL, ord("\f")), + r"\n": (LITERAL, ord("\n")), + r"\r": (LITERAL, ord("\r")), + r"\t": (LITERAL, ord("\t")), + r"\v": (LITERAL, ord("\v")), + r"\\": (LITERAL, ord("\\")) +} + +CATEGORIES = { + r"\A": (AT, AT_BEGINNING_STRING), # start of string + r"\b": (AT, AT_BOUNDARY), + r"\B": (AT, AT_NON_BOUNDARY), + r"\d": (IN, [(CATEGORY, CATEGORY_DIGIT)]), + r"\D": (IN, [(CATEGORY, CATEGORY_NOT_DIGIT)]), + r"\s": (IN, [(CATEGORY, CATEGORY_SPACE)]), + r"\S": (IN, [(CATEGORY, CATEGORY_NOT_SPACE)]), + r"\w": (IN, [(CATEGORY, CATEGORY_WORD)]), + r"\W": (IN, [(CATEGORY, CATEGORY_NOT_WORD)]), + r"\Z": (AT, AT_END_STRING), # end of string +} + +FLAGS = { + # standard flags + "i": SRE_FLAG_IGNORECASE, + "L": SRE_FLAG_LOCALE, + "m": SRE_FLAG_MULTILINE, + "s": SRE_FLAG_DOTALL, + "x": SRE_FLAG_VERBOSE, + # extensions + "t": SRE_FLAG_TEMPLATE, + "u": SRE_FLAG_UNICODE, +} + +class Pattern: + # master pattern object. keeps track of global attributes + def __init__(self): + self.flags = 0 + self.open = [] + self.groups = 1 + self.groupdict = {} + self.str = None + def opengroup(self, name=None): + gid = self.groups + self.groups = gid + 1 + if name is not None: + ogid = self.groupdict.get(name, None) + if ogid is not None: + raise error, ("redefinition of group name %s as group %d; " + "was group %d" % (repr(name), gid, ogid)) + self.groupdict[name] = gid + self.open.append(gid) + return gid + def closegroup(self, gid): + self.open.remove(gid) + def checkgroup(self, gid): + return gid < self.groups and gid not in self.open + +class SubPattern: + # a subpattern, in intermediate form + def __init__(self, pattern, data=None): + self.pattern = pattern + if data is None: + data = [] + self.data = data + self.width = None + def dump(self, level=0): + nl = 1 + seqtypes = type(()), type([]) + for op, av in self.data: + print level*" " + op,; nl = 0 + if op == "in": + # member sublanguage + print; nl = 1 + for op, a in av: + print (level+1)*" " + op, a + elif op == "branch": + print; nl = 1 + i = 0 + for a in av[1]: + if i > 0: + print level*" " + "or" + a.dump(level+1); nl = 1 + i = i + 1 + elif type(av) in seqtypes: + for a in av: + if isinstance(a, SubPattern): + if not nl: print + a.dump(level+1); nl = 1 + else: + print a, ; nl = 0 + else: + print av, ; nl = 0 + if not nl: print + def __repr__(self): + return repr(self.data) + def __len__(self): + return len(self.data) + def __delitem__(self, index): + del self.data[index] + def __getitem__(self, index): + if isinstance(index, slice): + return SubPattern(self.pattern, self.data[index]) + return self.data[index] + def __setitem__(self, index, code): + self.data[index] = code + def insert(self, index, code): + self.data.insert(index, code) + def append(self, code): + self.data.append(code) + def getwidth(self): + # determine the width (min, max) for this subpattern + if self.width: + return self.width + lo = hi = 0L + UNITCODES = (ANY, RANGE, IN, LITERAL, NOT_LITERAL, CATEGORY) + REPEATCODES = (MIN_REPEAT, MAX_REPEAT) + for op, av in self.data: + if op is BRANCH: + i = sys.maxint + j = 0 + for av in av[1]: + l, h = av.getwidth() + i = min(i, l) + j = max(j, h) + lo = lo + i + hi = hi + j + elif op is CALL: + i, j = av.getwidth() + lo = lo + i + hi = hi + j + elif op is SUBPATTERN: + i, j = av[1].getwidth() + lo = lo + i + hi = hi + j + elif op in REPEATCODES: + i, j = av[2].getwidth() + lo = lo + long(i) * av[0] + hi = hi + long(j) * av[1] + elif op in UNITCODES: + lo = lo + 1 + hi = hi + 1 + elif op == SUCCESS: + break + self.width = int(min(lo, sys.maxint)), int(min(hi, sys.maxint)) + return self.width + +class Tokenizer: + def __init__(self, string): + self.string = string + self.index = 0 + self.__next() + def __next(self): + if self.index >= len(self.string): + self.next = None + return + char = self.string[self.index] + if char[0] == "\\": + try: + c = self.string[self.index + 1] + except IndexError: + raise error, "bogus escape (end of line)" + char = char + c + self.index = self.index + len(char) + self.next = char + def match(self, char, skip=1): + if char == self.next: + if skip: + self.__next() + return 1 + return 0 + def get(self): + this = self.next + self.__next() + return this + def tell(self): + return self.index, self.next + def seek(self, index): + self.index, self.next = index + +def isident(char): + return "a" <= char <= "z" or "A" <= char <= "Z" or char == "_" + +def isdigit(char): + return "0" <= char <= "9" + +def isname(name): + # check that group name is a valid string + if not isident(name[0]): + return False + for char in name[1:]: + if not isident(char) and not isdigit(char): + return False + return True + +def _class_escape(source, escape): + # handle escape code inside character class + code = ESCAPES.get(escape) + if code: + return code + code = CATEGORIES.get(escape) + if code: + return code + try: + c = escape[1:2] + if c == "x": + # hexadecimal escape (exactly two digits) + while source.next in HEXDIGITS and len(escape) < 4: + escape = escape + source.get() + escape = escape[2:] + if len(escape) != 2: + raise error, "bogus escape: %s" % repr("\\" + escape) + return LITERAL, int(escape, 16) & 0xff + elif c in OCTDIGITS: + # octal escape (up to three digits) + while source.next in OCTDIGITS and len(escape) < 4: + escape = escape + source.get() + escape = escape[1:] + return LITERAL, int(escape, 8) & 0xff + elif c in DIGITS: + raise error, "bogus escape: %s" % repr(escape) + if len(escape) == 2: + return LITERAL, ord(escape[1]) + except ValueError: + pass + raise error, "bogus escape: %s" % repr(escape) + +def _escape(source, escape, state): + # handle escape code in expression + code = CATEGORIES.get(escape) + if code: + return code + code = ESCAPES.get(escape) + if code: + return code + try: + c = escape[1:2] + if c == "x": + # hexadecimal escape + while source.next in HEXDIGITS and len(escape) < 4: + escape = escape + source.get() + if len(escape) != 4: + raise ValueError + return LITERAL, int(escape[2:], 16) & 0xff + elif c == "0": + # octal escape + while source.next in OCTDIGITS and len(escape) < 4: + escape = escape + source.get() + return LITERAL, int(escape[1:], 8) & 0xff + elif c in DIGITS: + # octal escape *or* decimal group reference (sigh) + if source.next in DIGITS: + escape = escape + source.get() + if (escape[1] in OCTDIGITS and escape[2] in OCTDIGITS and + source.next in OCTDIGITS): + # got three octal digits; this is an octal escape + escape = escape + source.get() + return LITERAL, int(escape[1:], 8) & 0xff + # not an octal escape, so this is a group reference + group = int(escape[1:]) + if group < state.groups: + if not state.checkgroup(group): + raise error, "cannot refer to open group" + return GROUPREF, group + raise ValueError + if len(escape) == 2: + return LITERAL, ord(escape[1]) + except ValueError: + pass + raise error, "bogus escape: %s" % repr(escape) + +def _parse_sub(source, state, nested=1): + # parse an alternation: a|b|c + + items = [] + itemsappend = items.append + sourcematch = source.match + while 1: + itemsappend(_parse(source, state)) + if sourcematch("|"): + continue + if not nested: + break + if not source.next or sourcematch(")", 0): + break + else: + raise error, "pattern not properly closed" + + if len(items) == 1: + return items[0] + + subpattern = SubPattern(state) + subpatternappend = subpattern.append + + # check if all items share a common prefix + while 1: + prefix = None + for item in items: + if not item: + break + if prefix is None: + prefix = item[0] + elif item[0] != prefix: + break + else: + # all subitems start with a common "prefix". + # move it out of the branch + for item in items: + del item[0] + subpatternappend(prefix) + continue # check next one + break + + # check if the branch can be replaced by a character set + for item in items: + if len(item) != 1 or item[0][0] != LITERAL: + break + else: + # we can store this as a character set instead of a + # branch (the compiler may optimize this even more) + set = [] + setappend = set.append + for item in items: + setappend(item[0]) + subpatternappend((IN, set)) + return subpattern + + subpattern.append((BRANCH, (None, items))) + return subpattern + +def _parse_sub_cond(source, state, condgroup): + item_yes = _parse(source, state) + if source.match("|"): + item_no = _parse(source, state) + if source.match("|"): + raise error, "conditional backref with more than two branches" + else: + item_no = None + if source.next and not source.match(")", 0): + raise error, "pattern not properly closed" + subpattern = SubPattern(state) + subpattern.append((GROUPREF_EXISTS, (condgroup, item_yes, item_no))) + return subpattern + +_PATTERNENDERS = set("|)") +_ASSERTCHARS = set("=!<") +_LOOKBEHINDASSERTCHARS = set("=!") +_REPEATCODES = set([MIN_REPEAT, MAX_REPEAT]) + +def _parse(source, state): + # parse a simple pattern + subpattern = SubPattern(state) + + # precompute constants into local variables + subpatternappend = subpattern.append + sourceget = source.get + sourcematch = source.match + _len = len + PATTERNENDERS = _PATTERNENDERS + ASSERTCHARS = _ASSERTCHARS + LOOKBEHINDASSERTCHARS = _LOOKBEHINDASSERTCHARS + REPEATCODES = _REPEATCODES + + while 1: + + if source.next in PATTERNENDERS: + break # end of subpattern + this = sourceget() + if this is None: + break # end of pattern + + if state.flags & SRE_FLAG_VERBOSE: + # skip whitespace and comments + if this in WHITESPACE: + continue + if this == "#": + while 1: + this = sourceget() + if this in (None, "\n"): + break + continue + + if this and this[0] not in SPECIAL_CHARS: + subpatternappend((LITERAL, ord(this))) + + elif this == "[": + # character set + set = [] + setappend = set.append +## if sourcematch(":"): +## pass # handle character classes + if sourcematch("^"): + setappend((NEGATE, None)) + # check remaining characters + start = set[:] + while 1: + this = sourceget() + if this == "]" and set != start: + break + elif this and this[0] == "\\": + code1 = _class_escape(source, this) + elif this: + code1 = LITERAL, ord(this) + else: + raise error, "unexpected end of regular expression" + if sourcematch("-"): + # potential range + this = sourceget() + if this == "]": + if code1[0] is IN: + code1 = code1[1][0] + setappend(code1) + setappend((LITERAL, ord("-"))) + break + elif this: + if this[0] == "\\": + code2 = _class_escape(source, this) + else: + code2 = LITERAL, ord(this) + if code1[0] != LITERAL or code2[0] != LITERAL: + raise error, "bad character range" + lo = code1[1] + hi = code2[1] + if hi < lo: + raise error, "bad character range" + setappend((RANGE, (lo, hi))) + else: + raise error, "unexpected end of regular expression" + else: + if code1[0] is IN: + code1 = code1[1][0] + setappend(code1) + + # XXX: should move set optimization to compiler! + if _len(set)==1 and set[0][0] is LITERAL: + subpatternappend(set[0]) # optimization + elif _len(set)==2 and set[0][0] is NEGATE and set[1][0] is LITERAL: + subpatternappend((NOT_LITERAL, set[1][1])) # optimization + else: + # XXX: should add charmap optimization here + subpatternappend((IN, set)) + + elif this and this[0] in REPEAT_CHARS: + # repeat previous item + if this == "?": + min, max = 0, 1 + elif this == "*": + min, max = 0, MAXREPEAT + + elif this == "+": + min, max = 1, MAXREPEAT + elif this == "{": + if source.next == "}": + subpatternappend((LITERAL, ord(this))) + continue + here = source.tell() + min, max = 0, MAXREPEAT + lo = hi = "" + while source.next in DIGITS: + lo = lo + source.get() + if sourcematch(","): + while source.next in DIGITS: + hi = hi + sourceget() + else: + hi = lo + if not sourcematch("}"): + subpatternappend((LITERAL, ord(this))) + source.seek(here) + continue + if lo: + min = int(lo) + if hi: + max = int(hi) + if max < min: + raise error, "bad repeat interval" + else: + raise error, "not supported" + # figure out which item to repeat + if subpattern: + item = subpattern[-1:] + else: + item = None + if not item or (_len(item) == 1 and item[0][0] == AT): + raise error, "nothing to repeat" + if item[0][0] in REPEATCODES: + raise error, "multiple repeat" + if sourcematch("?"): + subpattern[-1] = (MIN_REPEAT, (min, max, item)) + else: + subpattern[-1] = (MAX_REPEAT, (min, max, item)) + + elif this == ".": + subpatternappend((ANY, None)) + + elif this == "(": + group = 1 + name = None + condgroup = None + if sourcematch("?"): + group = 0 + # options + if sourcematch("P"): + # python extensions + if sourcematch("<"): + # named group: skip forward to end of name + name = "" + while 1: + char = sourceget() + if char is None: + raise error, "unterminated name" + if char == ">": + break + name = name + char + group = 1 + if not isname(name): + raise error, "bad character in group name" + elif sourcematch("="): + # named backreference + name = "" + while 1: + char = sourceget() + if char is None: + raise error, "unterminated name" + if char == ")": + break + name = name + char + if not isname(name): + raise error, "bad character in group name" + gid = state.groupdict.get(name) + if gid is None: + raise error, "unknown group name" + subpatternappend((GROUPREF, gid)) + continue + else: + char = sourceget() + if char is None: + raise error, "unexpected end of pattern" + raise error, "unknown specifier: ?P%s" % char + elif sourcematch(":"): + # non-capturing group + group = 2 + elif sourcematch("#"): + # comment + while 1: + if source.next is None or source.next == ")": + break + sourceget() + if not sourcematch(")"): + raise error, "unbalanced parenthesis" + continue + elif source.next in ASSERTCHARS: + # lookahead assertions + char = sourceget() + dir = 1 + if char == "<": + if source.next not in LOOKBEHINDASSERTCHARS: + raise error, "syntax error" + dir = -1 # lookbehind + char = sourceget() + p = _parse_sub(source, state) + if not sourcematch(")"): + raise error, "unbalanced parenthesis" + if char == "=": + subpatternappend((ASSERT, (dir, p))) + else: + subpatternappend((ASSERT_NOT, (dir, p))) + continue + elif sourcematch("("): + # conditional backreference group + condname = "" + while 1: + char = sourceget() + if char is None: + raise error, "unterminated name" + if char == ")": + break + condname = condname + char + group = 2 + if isname(condname): + condgroup = state.groupdict.get(condname) + if condgroup is None: + raise error, "unknown group name" + else: + try: + condgroup = int(condname) + except ValueError: + raise error, "bad character in group name" + else: + # flags + if not source.next in FLAGS: + raise error, "unexpected end of pattern" + while source.next in FLAGS: + state.flags = state.flags | FLAGS[sourceget()] + if group: + # parse group contents + if group == 2: + # anonymous group + group = None + else: + group = state.opengroup(name) + if condgroup: + p = _parse_sub_cond(source, state, condgroup) + else: + p = _parse_sub(source, state) + if not sourcematch(")"): + raise error, "unbalanced parenthesis" + if group is not None: + state.closegroup(group) + subpatternappend((SUBPATTERN, (group, p))) + else: + while 1: + char = sourceget() + if char is None: + raise error, "unexpected end of pattern" + if char == ")": + break + raise error, "unknown extension" + + elif this == "^": + subpatternappend((AT, AT_BEGINNING)) + + elif this == "$": + subpattern.append((AT, AT_END)) + + elif this and this[0] == "\\": + code = _escape(source, this, state) + subpatternappend(code) + + else: + raise error, "parser error" + + return subpattern + +def parse(str, flags=0, pattern=None): + # parse 're' pattern into list of (opcode, argument) tuples + + source = Tokenizer(str) + + if pattern is None: + pattern = Pattern() + pattern.flags = flags + pattern.str = str + + p = _parse_sub(source, pattern, 0) + + tail = source.get() + if tail == ")": + raise error, "unbalanced parenthesis" + elif tail: + raise error, "bogus characters at end of regular expression" + + if flags & SRE_FLAG_DEBUG: + p.dump() + + if not (flags & SRE_FLAG_VERBOSE) and p.pattern.flags & SRE_FLAG_VERBOSE: + # the VERBOSE flag was switched on inside the pattern. to be + # on the safe side, we'll parse the whole thing again... + return parse(str, p.pattern.flags) + + return p + +def parse_template(source, pattern): + # parse 're' replacement string into list of literals and + # group references + s = Tokenizer(source) + sget = s.get + p = [] + a = p.append + def literal(literal, p=p, pappend=a): + if p and p[-1][0] is LITERAL: + p[-1] = LITERAL, p[-1][1] + literal + else: + pappend((LITERAL, literal)) + sep = source[:0] + if type(sep) is type(""): + makechar = chr + else: + makechar = unichr + while 1: + this = sget() + if this is None: + break # end of replacement string + if this and this[0] == "\\": + # group + c = this[1:2] + if c == "g": + name = "" + if s.match("<"): + while 1: + char = sget() + if char is None: + raise error, "unterminated group name" + if char == ">": + break + name = name + char + if not name: + raise error, "bad group name" + try: + index = int(name) + if index < 0: + raise error, "negative group number" + except ValueError: + if not isname(name): + raise error, "bad character in group name" + try: + index = pattern.groupindex[name] + except KeyError: + raise IndexError, "unknown group name" + a((MARK, index)) + elif c == "0": + if s.next in OCTDIGITS: + this = this + sget() + if s.next in OCTDIGITS: + this = this + sget() + literal(makechar(int(this[1:], 8) & 0xff)) + elif c in DIGITS: + isoctal = False + if s.next in DIGITS: + this = this + sget() + if (c in OCTDIGITS and this[2] in OCTDIGITS and + s.next in OCTDIGITS): + this = this + sget() + isoctal = True + literal(makechar(int(this[1:], 8) & 0xff)) + if not isoctal: + a((MARK, int(this[1:]))) + else: + try: + this = makechar(ESCAPES[this][1]) + except KeyError: + pass + literal(this) + else: + literal(this) + # convert template to groups and literals lists + i = 0 + groups = [] + groupsappend = groups.append + literals = [None] * len(p) + for c, s in p: + if c is MARK: + groupsappend((i, s)) + # literal[i] is already None + else: + literals[i] = s + i = i + 1 + return groups, literals + +def expand_template(template, match): + g = match.group + sep = match.string[:0] + groups, literals = template + literals = literals[:] + try: + for index, group in groups: + literals[index] = s = g(group) + if s is None: + raise error, "unmatched group" + except IndexError: + raise error, "invalid group reference" + return sep.join(literals) diff -r a03de9203c28 -r f551873980e5 lib/sys.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/sys.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,41 @@ +#!/usr/bin/env python + +""" +System functions and objects. + +Copyright (C) 2008, 2012, 2014 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +# Placeholders for run-time data. + +stdin = file() +stdout = file() +stderr = file() + +argv = [] +path = [] + +hexversion = 0x20703f0 # 2.7.3 final 0 +maxint = 2147483647 # 2**31 - 1 +maxunicode = 1114111 +platform = 'posix' + +# Functions to be implemented natively. + +def exit(status=0): + pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/threading.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/threading.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,825 @@ +#!/usr/bin/env python + +""" +Thread module emulating a subset of Java's threading model. + +See docs/COPYING.txt and docs/LICENCE-python.txt for copyright and licensing +information for Python standard library modules. +""" + +import sys as _sys + +try: + import thread +except ImportError: + del _sys.modules[__name__] + raise + +from time import time as _time, sleep as _sleep +from traceback import format_exc as _format_exc +from collections import deque + +# Rename some stuff so "from threading import *" is safe +__all__ = ['activeCount', 'Condition', 'currentThread', 'enumerate', 'Event', + 'Lock', 'RLock', 'Semaphore', 'BoundedSemaphore', 'Thread', + 'Timer', 'setprofile', 'settrace', 'local', 'stack_size'] + +_start_new_thread = thread.start_new_thread +_allocate_lock = thread.allocate_lock +_get_ident = thread.get_ident +ThreadError = thread.error +del thread + + +# Support for profile and trace hooks + +_profile_hook = None +_trace_hook = None + +def setprofile(func): + global _profile_hook + _profile_hook = func + +def settrace(func): + global _trace_hook + _trace_hook = func + +# Synchronization classes + +Lock = _allocate_lock + +def RLock(*args, **kwargs): + return _RLock(*args, **kwargs) + +class _RLock: + + def __init__(self): + self.__block = _allocate_lock() + self.__owner = None + self.__count = 0 + + def __repr__(self): + owner = self.__owner + return "<%s(%s, %d)>" % ( + self.__class__.__name__, + owner and owner.getName(), + self.__count) + + def acquire(self, blocking=1): + me = currentThread() + if self.__owner is me: + self.__count = self.__count + 1 + if __debug__: + self._note("%s.acquire(%s): recursive success", self, blocking) + return 1 + rc = self.__block.acquire(blocking) + if rc: + self.__owner = me + self.__count = 1 + if __debug__: + self._note("%s.acquire(%s): initial success", self, blocking) + else: + if __debug__: + self._note("%s.acquire(%s): failure", self, blocking) + return rc + + __enter__ = acquire + + def release(self): + if self.__owner is not currentThread(): + raise RuntimeError("cannot release un-aquired lock") + self.__count = count = self.__count - 1 + if not count: + self.__owner = None + self.__block.release() + if __debug__: + self._note("%s.release(): final release", self) + else: + if __debug__: + self._note("%s.release(): non-final release", self) + + def __exit__(self, t, v, tb): + self.release() + + # Internal methods used by condition variables + + def _acquire_restore(self, (count, owner)): + self.__block.acquire() + self.__count = count + self.__owner = owner + if __debug__: + self._note("%s._acquire_restore()", self) + + def _release_save(self): + if __debug__: + self._note("%s._release_save()", self) + count = self.__count + self.__count = 0 + owner = self.__owner + self.__owner = None + self.__block.release() + return (count, owner) + + def _is_owned(self): + return self.__owner is currentThread() + + +def Condition(*args, **kwargs): + return _Condition(*args, **kwargs) + +class _Condition: + + def __init__(self, lock=None): + if lock is None: + lock = RLock() + self.__lock = lock + # Export the lock's acquire() and release() methods + self.acquire = lock.acquire + self.release = lock.release + # If the lock defines _release_save() and/or _acquire_restore(), + # these override the default implementations (which just call + # release() and acquire() on the lock). Ditto for _is_owned(). + try: + self._release_save = lock._release_save + except AttributeError: + pass + try: + self._acquire_restore = lock._acquire_restore + except AttributeError: + pass + try: + self._is_owned = lock._is_owned + except AttributeError: + pass + self.__waiters = [] + + def __enter__(self): + return self.__lock.__enter__() + + def __exit__(self, *args): + return self.__lock.__exit__(*args) + + def __repr__(self): + return "" % (self.__lock, len(self.__waiters)) + + def _release_save(self): + self.__lock.release() # No state to save + + def _acquire_restore(self, x): + self.__lock.acquire() # Ignore saved state + + def _is_owned(self): + # Return True if lock is owned by currentThread. + # This method is called only if __lock doesn't have _is_owned(). + if self.__lock.acquire(0): + self.__lock.release() + return False + else: + return True + + def wait(self, timeout=None): + if not self._is_owned(): + raise RuntimeError("cannot wait on un-aquired lock") + waiter = _allocate_lock() + waiter.acquire() + self.__waiters.append(waiter) + saved_state = self._release_save() + try: # restore state no matter what (e.g., KeyboardInterrupt) + if timeout is None: + waiter.acquire() + if __debug__: + self._note("%s.wait(): got it", self) + else: + # Balancing act: We can't afford a pure busy loop, so we + # have to sleep; but if we sleep the whole timeout time, + # we'll be unresponsive. The scheme here sleeps very + # little at first, longer as time goes on, but never longer + # than 20 times per second (or the timeout time remaining). + endtime = _time() + timeout + delay = 0.0005 # 500 us -> initial delay of 1 ms + while True: + gotit = waiter.acquire(0) + if gotit: + break + remaining = endtime - _time() + if remaining <= 0: + break + delay = min(delay * 2, remaining, .05) + _sleep(delay) + if not gotit: + if __debug__: + self._note("%s.wait(%s): timed out", self, timeout) + try: + self.__waiters.remove(waiter) + except ValueError: + pass + else: + if __debug__: + self._note("%s.wait(%s): got it", self, timeout) + finally: + self._acquire_restore(saved_state) + + def notify(self, n=1): + if not self._is_owned(): + raise RuntimeError("cannot notify on un-aquired lock") + __waiters = self.__waiters + waiters = __waiters[:n] + if not waiters: + if __debug__: + self._note("%s.notify(): no waiters", self) + return + self._note("%s.notify(): notifying %d waiter%s", self, n, + n!=1 and "s" or "") + for waiter in waiters: + waiter.release() + try: + __waiters.remove(waiter) + except ValueError: + pass + + def notifyAll(self): + self.notify(len(self.__waiters)) + + +def Semaphore(*args, **kwargs): + return _Semaphore(*args, **kwargs) + +class _Semaphore: + + # After Tim Peters' semaphore class, but not quite the same (no maximum) + + def __init__(self, value=1): + if value < 0: + raise ValueError("semaphore initial value must be >= 0") + self.__cond = Condition(Lock()) + self.__value = value + + def acquire(self, blocking=1): + rc = False + self.__cond.acquire() + while self.__value == 0: + if not blocking: + break + if __debug__: + self._note("%s.acquire(%s): blocked waiting, value=%s", + self, blocking, self.__value) + self.__cond.wait() + else: + self.__value = self.__value - 1 + if __debug__: + self._note("%s.acquire: success, value=%s", + self, self.__value) + rc = True + self.__cond.release() + return rc + + __enter__ = acquire + + def release(self): + self.__cond.acquire() + self.__value = self.__value + 1 + if __debug__: + self._note("%s.release: success, value=%s", + self, self.__value) + self.__cond.notify() + self.__cond.release() + + def __exit__(self, t, v, tb): + self.release() + + +def BoundedSemaphore(*args, **kwargs): + return _BoundedSemaphore(*args, **kwargs) + +class _BoundedSemaphore(_Semaphore): + """Semaphore that checks that # releases is <= # acquires""" + def __init__(self, value=1): + _Semaphore.__init__(self, value) + self._initial_value = value + + def release(self): + if self._Semaphore__value >= self._initial_value: + raise ValueError, "Semaphore released too many times" + return _Semaphore.release(self) + + +def Event(*args, **kwargs): + return _Event(*args, **kwargs) + +class _Event: + + # After Tim Peters' event class (without is_posted()) + + def __init__(self): + self.__cond = Condition(Lock()) + self.__flag = False + + def isSet(self): + return self.__flag + + def set(self): + self.__cond.acquire() + try: + self.__flag = True + self.__cond.notifyAll() + finally: + self.__cond.release() + + def clear(self): + self.__cond.acquire() + try: + self.__flag = False + finally: + self.__cond.release() + + def wait(self, timeout=None): + self.__cond.acquire() + try: + if not self.__flag: + self.__cond.wait(timeout) + finally: + self.__cond.release() + +# Helper to generate new thread names +_counter = 0 +def _newname(template="Thread-%d"): + global _counter + _counter = _counter + 1 + return template % _counter + +# Active thread administration +_active_limbo_lock = _allocate_lock() +_active = {} # maps thread id to Thread object +_limbo = {} + + +# Main class for threads + +class Thread: + + __initialized = False + # Need to store a reference to sys.exc_info for printing + # out exceptions when a thread tries to use a global var. during interp. + # shutdown and thus raises an exception about trying to perform some + # operation on/with a NoneType + __exc_info = _sys.exc_info + + def __init__(self, group=None, target=None, name=None, + args=(), kwargs=None): + assert group is None, "group argument must be None for now" + if kwargs is None: + kwargs = {} + self.__target = target + self.__name = str(name or _newname()) + self.__args = args + self.__kwargs = kwargs + self.__daemonic = self._set_daemon() + self.__started = False + self.__stopped = False + self.__block = Condition(Lock()) + self.__initialized = True + # sys.stderr is not stored in the class like + # sys.exc_info since it can be changed between instances + self.__stderr = _sys.stderr + + def _set_daemon(self): + # Overridden in _MainThread and _DummyThread + return currentThread().isDaemon() + + def __repr__(self): + assert self.__initialized, "Thread.__init__() was not called" + status = "initial" + if self.__started: + status = "started" + if self.__stopped: + status = "stopped" + if self.__daemonic: + status = status + " daemon" + return "<%s(%s, %s)>" % (self.__class__.__name__, self.__name, status) + + def start(self): + if not self.__initialized: + raise RuntimeError("thread.__init__() not called") + if self.__started: + raise RuntimeError("thread already started") + if __debug__: + self._note("%s.start(): starting thread", self) + _active_limbo_lock.acquire() + _limbo[self] = self + _active_limbo_lock.release() + _start_new_thread(self.__bootstrap, ()) + self.__started = True + _sleep(0.000001) # 1 usec, to let the thread run (Solaris hack) + + def run(self): + if self.__target: + self.__target(*self.__args, **self.__kwargs) + + def __bootstrap(self): + # Wrapper around the real bootstrap code that ignores + # exceptions during interpreter cleanup. Those typically + # happen when a daemon thread wakes up at an unfortunate + # moment, finds the world around it destroyed, and raises some + # random exception *** while trying to report the exception in + # __bootstrap_inner() below ***. Those random exceptions + # don't help anybody, and they confuse users, so we suppress + # them. We suppress them only when it appears that the world + # indeed has already been destroyed, so that exceptions in + # __bootstrap_inner() during normal business hours are properly + # reported. Also, we only suppress them for daemonic threads; + # if a non-daemonic encounters this, something else is wrong. + try: + self.__bootstrap_inner() + except: + if self.__daemonic and _sys is None: + return + raise + + def __bootstrap_inner(self): + try: + self.__started = True + _active_limbo_lock.acquire() + _active[_get_ident()] = self + del _limbo[self] + _active_limbo_lock.release() + if __debug__: + self._note("%s.__bootstrap(): thread started", self) + + if _trace_hook: + self._note("%s.__bootstrap(): registering trace hook", self) + _sys.settrace(_trace_hook) + if _profile_hook: + self._note("%s.__bootstrap(): registering profile hook", self) + _sys.setprofile(_profile_hook) + + try: + self.run() + except SystemExit: + if __debug__: + self._note("%s.__bootstrap(): raised SystemExit", self) + except: + if __debug__: + self._note("%s.__bootstrap(): unhandled exception", self) + # If sys.stderr is no more (most likely from interpreter + # shutdown) use self.__stderr. Otherwise still use sys (as in + # _sys) in case sys.stderr was redefined since the creation of + # self. + if _sys: + _sys.stderr.write("Exception in thread %s:\n%s\n" % + (self.getName(), _format_exc())) + else: + # Do the best job possible w/o a huge amt. of code to + # approximate a traceback (code ideas from + # Lib/traceback.py) + exc_type, exc_value, exc_tb = self.__exc_info() + try: + print>>self.__stderr, ( + "Exception in thread " + self.getName() + + " (most likely raised during interpreter shutdown):") + print>>self.__stderr, ( + "Traceback (most recent call last):") + while exc_tb: + print>>self.__stderr, ( + ' File "%s", line %s, in %s' % + (exc_tb.tb_frame.f_code.co_filename, + exc_tb.tb_lineno, + exc_tb.tb_frame.f_code.co_name)) + exc_tb = exc_tb.tb_next + print>>self.__stderr, ("%s: %s" % (exc_type, exc_value)) + # Make sure that exc_tb gets deleted since it is a memory + # hog; deleting everything else is just for thoroughness + finally: + del exc_type, exc_value, exc_tb + else: + if __debug__: + self._note("%s.__bootstrap(): normal return", self) + finally: + _active_limbo_lock.acquire() + try: + self.__stop() + try: + # We don't call self.__delete() because it also + # grabs _active_limbo_lock. + del _active[_get_ident()] + except: + pass + finally: + _active_limbo_lock.release() + + def __stop(self): + self.__block.acquire() + self.__stopped = True + self.__block.notifyAll() + self.__block.release() + + def __delete(self): + "Remove current thread from the dict of currently running threads." + + # Notes about running with dummy_thread: + # + # Must take care to not raise an exception if dummy_thread is being + # used (and thus this module is being used as an instance of + # dummy_threading). dummy_thread.get_ident() always returns -1 since + # there is only one thread if dummy_thread is being used. Thus + # len(_active) is always <= 1 here, and any Thread instance created + # overwrites the (if any) thread currently registered in _active. + # + # An instance of _MainThread is always created by 'threading'. This + # gets overwritten the instant an instance of Thread is created; both + # threads return -1 from dummy_thread.get_ident() and thus have the + # same key in the dict. So when the _MainThread instance created by + # 'threading' tries to clean itself up when atexit calls this method + # it gets a KeyError if another Thread instance was created. + # + # This all means that KeyError from trying to delete something from + # _active if dummy_threading is being used is a red herring. But + # since it isn't if dummy_threading is *not* being used then don't + # hide the exception. + + _active_limbo_lock.acquire() + try: + try: + del _active[_get_ident()] + except KeyError: + if 'dummy_threading' not in _sys.modules: + raise + finally: + _active_limbo_lock.release() + + def join(self, timeout=None): + if not self.__initialized: + raise RuntimeError("Thread.__init__() not called") + if not self.__started: + raise RuntimeError("cannot join thread before it is started") + if self is currentThread(): + raise RuntimeError("cannot join current thread") + + if __debug__: + if not self.__stopped: + self._note("%s.join(): waiting until thread stops", self) + self.__block.acquire() + try: + if timeout is None: + while not self.__stopped: + self.__block.wait() + if __debug__: + self._note("%s.join(): thread stopped", self) + else: + deadline = _time() + timeout + while not self.__stopped: + delay = deadline - _time() + if delay <= 0: + if __debug__: + self._note("%s.join(): timed out", self) + break + self.__block.wait(delay) + else: + if __debug__: + self._note("%s.join(): thread stopped", self) + finally: + self.__block.release() + + def getName(self): + assert self.__initialized, "Thread.__init__() not called" + return self.__name + + def setName(self, name): + assert self.__initialized, "Thread.__init__() not called" + self.__name = str(name) + + def isAlive(self): + assert self.__initialized, "Thread.__init__() not called" + return self.__started and not self.__stopped + + def isDaemon(self): + assert self.__initialized, "Thread.__init__() not called" + return self.__daemonic + + def setDaemon(self, daemonic): + if not self.__initialized: + raise RuntimeError("Thread.__init__() not called") + if self.__started: + raise RuntimeError("cannot set daemon status of active thread"); + self.__daemonic = daemonic + +# The timer class was contributed by Itamar Shtull-Trauring + +def Timer(*args, **kwargs): + return _Timer(*args, **kwargs) + +class _Timer(Thread): + """Call a function after a specified number of seconds: + + t = Timer(30.0, f, args=[], kwargs={}) + t.start() + t.cancel() # stop the timer's action if it's still waiting + """ + + def __init__(self, interval, function, args=[], kwargs={}): + Thread.__init__(self) + self.interval = interval + self.function = function + self.args = args + self.kwargs = kwargs + self.finished = Event() + + def cancel(self): + """Stop the timer if it hasn't finished yet""" + self.finished.set() + + def run(self): + self.finished.wait(self.interval) + if not self.finished.isSet(): + self.function(*self.args, **self.kwargs) + self.finished.set() + +# Special thread class to represent the main thread +# This is garbage collected through an exit handler + +class _MainThread(Thread): + + def __init__(self): + Thread.__init__(self, name="MainThread") + self._Thread__started = True + _active_limbo_lock.acquire() + _active[_get_ident()] = self + _active_limbo_lock.release() + + def _set_daemon(self): + return False + + def _exitfunc(self): + self._Thread__stop() + t = _pickSomeNonDaemonThread() + if t: + if __debug__: + self._note("%s: waiting for other threads", self) + while t: + t.join() + t = _pickSomeNonDaemonThread() + if __debug__: + self._note("%s: exiting", self) + self._Thread__delete() + +def _pickSomeNonDaemonThread(): + for t in enumerate(): + if not t.isDaemon() and t.isAlive(): + return t + return None + + +# Dummy thread class to represent threads not started here. +# These aren't garbage collected when they die, nor can they be waited for. +# If they invoke anything in threading.py that calls currentThread(), they +# leave an entry in the _active dict forever after. +# Their purpose is to return *something* from currentThread(). +# They are marked as daemon threads so we won't wait for them +# when we exit (conform previous semantics). + +class _DummyThread(Thread): + + def __init__(self): + Thread.__init__(self, name=_newname("Dummy-%d")) + + # Thread.__block consumes an OS-level locking primitive, which + # can never be used by a _DummyThread. Since a _DummyThread + # instance is immortal, that's bad, so release this resource. + del self._Thread__block + + self._Thread__started = True + _active_limbo_lock.acquire() + _active[_get_ident()] = self + _active_limbo_lock.release() + + def _set_daemon(self): + return True + + def join(self, timeout=None): + assert False, "cannot join a dummy thread" + + +# Global API functions + +def currentThread(): + try: + return _active[_get_ident()] + except KeyError: + ##print "currentThread(): no current thread for", _get_ident() + return _DummyThread() + +def activeCount(): + _active_limbo_lock.acquire() + count = len(_active) + len(_limbo) + _active_limbo_lock.release() + return count + +def enumerate(): + _active_limbo_lock.acquire() + active = _active.values() + _limbo.values() + _active_limbo_lock.release() + return active + +from thread import stack_size + +# Create the main thread object, +# and make it available for the interpreter +# (Py_Main) as threading._shutdown. + +_shutdown = _MainThread()._exitfunc + +# get thread-local implementation, either from the thread +# module, or from the python fallback + +try: + from thread import _local as local +except ImportError: + from _threading_local import local + + +# Self-test code + +def _test(): + + class BoundedQueue: + + def __init__(self, limit): + self.mon = RLock() + self.rc = Condition(self.mon) + self.wc = Condition(self.mon) + self.limit = limit + self.queue = deque() + + def put(self, item): + self.mon.acquire() + while len(self.queue) >= self.limit: + self._note("put(%s): queue full", item) + self.wc.wait() + self.queue.append(item) + self._note("put(%s): appended, length now %d", + item, len(self.queue)) + self.rc.notify() + self.mon.release() + + def get(self): + self.mon.acquire() + while not self.queue: + self._note("get(): queue empty") + self.rc.wait() + item = self.queue.popleft() + self._note("get(): got %s, %d left", item, len(self.queue)) + self.wc.notify() + self.mon.release() + return item + + class ProducerThread(Thread): + + def __init__(self, queue, quota): + Thread.__init__(self, name="Producer") + self.queue = queue + self.quota = quota + + def run(self): + from random import random + counter = 0 + while counter < self.quota: + counter = counter + 1 + self.queue.put("%s.%d" % (self.getName(), counter)) + _sleep(random() * 0.00001) + + + class ConsumerThread(Thread): + + def __init__(self, queue, count): + Thread.__init__(self, name="Consumer") + self.queue = queue + self.count = count + + def run(self): + while self.count > 0: + item = self.queue.get() + print item + self.count = self.count - 1 + + NP = 3 + QL = 4 + NI = 5 + + Q = BoundedQueue(QL) + P = [] + for i in range(NP): + t = ProducerThread(Q, NI) + t.setName("Producer-%d" % (i+1)) + P.append(t) + C = ConsumerThread(Q, NI*NP) + for t in P: + t.start() + _sleep(0.000001) + C.start() + for t in P: + t.join() + C.join() + +if __name__ == '__main__': + _test() + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/time.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/time.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,39 @@ +#!/usr/bin/env python + +class struct_time(tuple): + pass + +def asctime(t=None): + pass + +def clock(): + pass + +def ctime(seconds): + pass + +def gmtime(seconds=None): + pass + +def localtime(seconds=None): + pass + +def mktime(t): + pass + +def sleep(seconds): + pass + +def strftime(format, t=None): + pass + +def strptime(s, format): + pass + +def time(): + pass + +def tzset(): + pass + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/types.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/types.py Tue Aug 30 21:55:58 2016 +0200 @@ -0,0 +1,70 @@ +#!/usr/bin/env python + +""" +Type objects. + +Copyright (C) 2012, 2015 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +# Built-in type duplication. + +type = type +NoneType = NoneType +NotImplementedType = NotImplementedType + +# Synonyms for built-in types. + +BooleanType = bool +BufferType = buffer +BuiltinFunctionType = function +BuiltinMethodType = function +ComplexType = complex +DictType = dict +EllipsisType = ellipsis +FileType = file +FloatType = float +FunctionType = function +IntType = int +LambdaType = function +ListType = list +LongType = long +MethodType = function +ObjectType = object +SliceType = slice +StringType = str +TupleType = tuple +UnboundMethodType = function +UnicodeType = unicode +XRangeType = xrange + +StringTypes = (StringType, UnicodeType) + +# Types without special definitions. + +ClassType = object +GeneratorType = object +InstanceType = object +ModuleType = object +TracebackType = object + +# Implementation-specific definitions not relevant to micropython. + +DictProxyType = object +FrameType = object +GetSetDescriptorType = object +MemberDescriptorType = object + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r a03de9203c28 -r f551873980e5 lib/warnings.py