mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Update Python mock SDK 3.4 -> 3.7
This commit is contained in:
@@ -1,18 +0,0 @@
|
||||
# Stubs
|
||||
|
||||
class object:
|
||||
pass
|
||||
|
||||
class ABCMeta:
|
||||
pass
|
||||
|
||||
|
||||
class ABC(metaclass=ABCMeta):
|
||||
"""Helper class that provides a standard way to create an ABC using
|
||||
inheritance.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
def abstractmethod(foo):
|
||||
pass
|
||||
@@ -1,38 +0,0 @@
|
||||
################################################################################
|
||||
### Simple tests
|
||||
################################################################################
|
||||
|
||||
# verify that instances can be pickled
|
||||
from collections import namedtuple
|
||||
from pickle import loads, dumps
|
||||
Point = namedtuple('Point', 'x, y', True)
|
||||
p = Point(x=10, y=20)
|
||||
assert p == loads(dumps(p))
|
||||
|
||||
# test and demonstrate ability to override methods
|
||||
class Point(namedtuple('Point', 'x y')):
|
||||
__slots__ = ()
|
||||
@property
|
||||
def hypot(self):
|
||||
return (self.x ** 2 + self.y ** 2) ** 0.5
|
||||
def __str__(self):
|
||||
return 'Point: x=%6.3f y=%6.3f hypot=%6.3f' % (self.x, self.y, self.hypot)
|
||||
|
||||
for p in Point(3, 4), Point(14, 5/7.):
|
||||
print (p)
|
||||
|
||||
class Point(namedtuple('Point', 'x y')):
|
||||
'Point class with optimized _make() and _replace() without error-checking'
|
||||
__slots__ = ()
|
||||
_make = classmethod(tuple.__new__)
|
||||
def _replace(self, _map=map, **kwds):
|
||||
return self._make(_map(kwds.get, ('x', 'y'), self))
|
||||
|
||||
print(Point(11, 22)._replace(x=100))
|
||||
|
||||
Point3D = namedtuple('Point3D', Point._fields + ('z',))
|
||||
print(Point3D.__doc__)
|
||||
|
||||
import doctest, collections
|
||||
TestResults = namedtuple('TestResults', 'failed attempted')
|
||||
print(TestResults(*doctest.testmod(collections)))
|
||||
+131
-59
@@ -9,9 +9,10 @@ Unit tests are in test_collections.
|
||||
from abc import ABCMeta, abstractmethod
|
||||
import sys
|
||||
|
||||
__all__ = ["Awaitable", "Coroutine", "AsyncIterable", "AsyncIterator",
|
||||
"Hashable", "Iterable", "Iterator", "Generator",
|
||||
"Sized", "Container", "Callable",
|
||||
__all__ = ["Awaitable", "Coroutine",
|
||||
"AsyncIterable", "AsyncIterator", "AsyncGenerator",
|
||||
"Hashable", "Iterable", "Iterator", "Generator", "Reversible",
|
||||
"Sized", "Container", "Callable", "Collection",
|
||||
"Set", "MutableSet",
|
||||
"Mapping", "MutableMapping",
|
||||
"MappingView", "KeysView", "ItemsView", "ValuesView",
|
||||
@@ -29,8 +30,8 @@ __name__ = "collections.abc"
|
||||
# so that they will pass tests like:
|
||||
# it = iter(somebytearray)
|
||||
# assert isinstance(it, Iterable)
|
||||
# Note: in other implementations, these types many not be distinct
|
||||
# and they make have their own implementation specific types that
|
||||
# Note: in other implementations, these types might not be distinct
|
||||
# and they may have their own implementation specific types that
|
||||
# are not included on this list.
|
||||
bytes_iterator = type(iter(b''))
|
||||
bytearray_iterator = type(iter(bytearray()))
|
||||
@@ -41,6 +42,7 @@ dict_itemiterator = type(iter({}.items()))
|
||||
list_iterator = type(iter([]))
|
||||
list_reverseiterator = type(iter(reversed([])))
|
||||
range_iterator = type(iter(range(0)))
|
||||
longrange_iterator = type(iter(range(1 << 1000)))
|
||||
set_iterator = type(iter(set()))
|
||||
str_iterator = type(iter(""))
|
||||
tuple_iterator = type(iter(()))
|
||||
@@ -58,10 +60,27 @@ _coro = _coro()
|
||||
coroutine = type(_coro)
|
||||
_coro.close() # Prevent ResourceWarning
|
||||
del _coro
|
||||
## asynchronous generator ##
|
||||
async def _ag(): yield
|
||||
_ag = _ag()
|
||||
async_generator = type(_ag)
|
||||
del _ag
|
||||
|
||||
|
||||
### ONE-TRICK PONIES ###
|
||||
|
||||
def _check_methods(C, *methods):
|
||||
mro = C.__mro__
|
||||
for method in methods:
|
||||
for B in mro:
|
||||
if method in B.__dict__:
|
||||
if B.__dict__[method] is None:
|
||||
return NotImplemented
|
||||
break
|
||||
else:
|
||||
return NotImplemented
|
||||
return True
|
||||
|
||||
class Hashable(metaclass=ABCMeta):
|
||||
|
||||
__slots__ = ()
|
||||
@@ -73,11 +92,7 @@ class Hashable(metaclass=ABCMeta):
|
||||
@classmethod
|
||||
def __subclasshook__(cls, C):
|
||||
if cls is Hashable:
|
||||
for B in C.__mro__:
|
||||
if "__hash__" in B.__dict__:
|
||||
if B.__dict__["__hash__"]:
|
||||
return True
|
||||
break
|
||||
return _check_methods(C, "__hash__")
|
||||
return NotImplemented
|
||||
|
||||
|
||||
@@ -92,11 +107,7 @@ class Awaitable(metaclass=ABCMeta):
|
||||
@classmethod
|
||||
def __subclasshook__(cls, C):
|
||||
if cls is Awaitable:
|
||||
for B in C.__mro__:
|
||||
if "__await__" in B.__dict__:
|
||||
if B.__dict__["__await__"]:
|
||||
return True
|
||||
break
|
||||
return _check_methods(C, "__await__")
|
||||
return NotImplemented
|
||||
|
||||
|
||||
@@ -137,14 +148,7 @@ class Coroutine(Awaitable):
|
||||
@classmethod
|
||||
def __subclasshook__(cls, C):
|
||||
if cls is Coroutine:
|
||||
mro = C.__mro__
|
||||
for method in ('__await__', 'send', 'throw', 'close'):
|
||||
for base in mro:
|
||||
if method in base.__dict__:
|
||||
break
|
||||
else:
|
||||
return NotImplemented
|
||||
return True
|
||||
return _check_methods(C, '__await__', 'send', 'throw', 'close')
|
||||
return NotImplemented
|
||||
|
||||
|
||||
@@ -162,8 +166,7 @@ class AsyncIterable(metaclass=ABCMeta):
|
||||
@classmethod
|
||||
def __subclasshook__(cls, C):
|
||||
if cls is AsyncIterable:
|
||||
if any("__aiter__" in B.__dict__ for B in C.__mro__):
|
||||
return True
|
||||
return _check_methods(C, "__aiter__")
|
||||
return NotImplemented
|
||||
|
||||
|
||||
@@ -182,12 +185,61 @@ class AsyncIterator(AsyncIterable):
|
||||
@classmethod
|
||||
def __subclasshook__(cls, C):
|
||||
if cls is AsyncIterator:
|
||||
if (any("__anext__" in B.__dict__ for B in C.__mro__) and
|
||||
any("__aiter__" in B.__dict__ for B in C.__mro__)):
|
||||
return True
|
||||
return _check_methods(C, "__anext__", "__aiter__")
|
||||
return NotImplemented
|
||||
|
||||
|
||||
class AsyncGenerator(AsyncIterator):
|
||||
|
||||
__slots__ = ()
|
||||
|
||||
async def __anext__(self):
|
||||
"""Return the next item from the asynchronous generator.
|
||||
When exhausted, raise StopAsyncIteration.
|
||||
"""
|
||||
return await self.asend(None)
|
||||
|
||||
@abstractmethod
|
||||
async def asend(self, value):
|
||||
"""Send a value into the asynchronous generator.
|
||||
Return next yielded value or raise StopAsyncIteration.
|
||||
"""
|
||||
raise StopAsyncIteration
|
||||
|
||||
@abstractmethod
|
||||
async def athrow(self, typ, val=None, tb=None):
|
||||
"""Raise an exception in the asynchronous generator.
|
||||
Return next yielded value or raise StopAsyncIteration.
|
||||
"""
|
||||
if val is None:
|
||||
if tb is None:
|
||||
raise typ
|
||||
val = typ()
|
||||
if tb is not None:
|
||||
val = val.with_traceback(tb)
|
||||
raise val
|
||||
|
||||
async def aclose(self):
|
||||
"""Raise GeneratorExit inside coroutine.
|
||||
"""
|
||||
try:
|
||||
await self.athrow(GeneratorExit)
|
||||
except (GeneratorExit, StopAsyncIteration):
|
||||
pass
|
||||
else:
|
||||
raise RuntimeError("asynchronous generator ignored GeneratorExit")
|
||||
|
||||
@classmethod
|
||||
def __subclasshook__(cls, C):
|
||||
if cls is AsyncGenerator:
|
||||
return _check_methods(C, '__aiter__', '__anext__',
|
||||
'asend', 'athrow', 'aclose')
|
||||
return NotImplemented
|
||||
|
||||
|
||||
AsyncGenerator.register(async_generator)
|
||||
|
||||
|
||||
class Iterable(metaclass=ABCMeta):
|
||||
|
||||
__slots__ = ()
|
||||
@@ -200,8 +252,7 @@ class Iterable(metaclass=ABCMeta):
|
||||
@classmethod
|
||||
def __subclasshook__(cls, C):
|
||||
if cls is Iterable:
|
||||
if any("__iter__" in B.__dict__ for B in C.__mro__):
|
||||
return True
|
||||
return _check_methods(C, "__iter__")
|
||||
return NotImplemented
|
||||
|
||||
|
||||
@@ -220,9 +271,7 @@ class Iterator(Iterable):
|
||||
@classmethod
|
||||
def __subclasshook__(cls, C):
|
||||
if cls is Iterator:
|
||||
if (any("__next__" in B.__dict__ for B in C.__mro__) and
|
||||
any("__iter__" in B.__dict__ for B in C.__mro__)):
|
||||
return True
|
||||
return _check_methods(C, '__iter__', '__next__')
|
||||
return NotImplemented
|
||||
|
||||
Iterator.register(bytes_iterator)
|
||||
@@ -234,12 +283,29 @@ Iterator.register(dict_itemiterator)
|
||||
Iterator.register(list_iterator)
|
||||
Iterator.register(list_reverseiterator)
|
||||
Iterator.register(range_iterator)
|
||||
Iterator.register(longrange_iterator)
|
||||
Iterator.register(set_iterator)
|
||||
Iterator.register(str_iterator)
|
||||
Iterator.register(tuple_iterator)
|
||||
Iterator.register(zip_iterator)
|
||||
|
||||
|
||||
class Reversible(Iterable):
|
||||
|
||||
__slots__ = ()
|
||||
|
||||
@abstractmethod
|
||||
def __reversed__(self):
|
||||
while False:
|
||||
yield None
|
||||
|
||||
@classmethod
|
||||
def __subclasshook__(cls, C):
|
||||
if cls is Reversible:
|
||||
return _check_methods(C, "__reversed__", "__iter__")
|
||||
return NotImplemented
|
||||
|
||||
|
||||
class Generator(Iterator):
|
||||
|
||||
__slots__ = ()
|
||||
@@ -283,17 +349,10 @@ class Generator(Iterator):
|
||||
@classmethod
|
||||
def __subclasshook__(cls, C):
|
||||
if cls is Generator:
|
||||
mro = C.__mro__
|
||||
for method in ('__iter__', '__next__', 'send', 'throw', 'close'):
|
||||
for base in mro:
|
||||
if method in base.__dict__:
|
||||
break
|
||||
else:
|
||||
return NotImplemented
|
||||
return True
|
||||
return _check_methods(C, '__iter__', '__next__',
|
||||
'send', 'throw', 'close')
|
||||
return NotImplemented
|
||||
|
||||
|
||||
Generator.register(generator)
|
||||
|
||||
|
||||
@@ -308,8 +367,7 @@ class Sized(metaclass=ABCMeta):
|
||||
@classmethod
|
||||
def __subclasshook__(cls, C):
|
||||
if cls is Sized:
|
||||
if any("__len__" in B.__dict__ for B in C.__mro__):
|
||||
return True
|
||||
return _check_methods(C, "__len__")
|
||||
return NotImplemented
|
||||
|
||||
|
||||
@@ -324,10 +382,18 @@ class Container(metaclass=ABCMeta):
|
||||
@classmethod
|
||||
def __subclasshook__(cls, C):
|
||||
if cls is Container:
|
||||
if any("__contains__" in B.__dict__ for B in C.__mro__):
|
||||
return True
|
||||
return _check_methods(C, "__contains__")
|
||||
return NotImplemented
|
||||
|
||||
class Collection(Sized, Iterable, Container):
|
||||
|
||||
__slots__ = ()
|
||||
|
||||
@classmethod
|
||||
def __subclasshook__(cls, C):
|
||||
if cls is Collection:
|
||||
return _check_methods(C, "__len__", "__iter__", "__contains__")
|
||||
return NotImplemented
|
||||
|
||||
class Callable(metaclass=ABCMeta):
|
||||
|
||||
@@ -340,15 +406,14 @@ class Callable(metaclass=ABCMeta):
|
||||
@classmethod
|
||||
def __subclasshook__(cls, C):
|
||||
if cls is Callable:
|
||||
if any("__call__" in B.__dict__ for B in C.__mro__):
|
||||
return True
|
||||
return _check_methods(C, "__call__")
|
||||
return NotImplemented
|
||||
|
||||
|
||||
### SETS ###
|
||||
|
||||
|
||||
class Set(Sized, Iterable, Container):
|
||||
class Set(Collection):
|
||||
|
||||
"""A set is a finite, iterable container.
|
||||
|
||||
@@ -524,7 +589,7 @@ class MutableSet(Set):
|
||||
try:
|
||||
value = next(it)
|
||||
except StopIteration:
|
||||
raise KeyError
|
||||
raise KeyError from None
|
||||
self.discard(value)
|
||||
return value
|
||||
|
||||
@@ -573,7 +638,7 @@ MutableSet.register(set)
|
||||
### MAPPINGS ###
|
||||
|
||||
|
||||
class Mapping(Sized, Iterable, Container):
|
||||
class Mapping(Collection):
|
||||
|
||||
__slots__ = ()
|
||||
|
||||
@@ -621,6 +686,8 @@ class Mapping(Sized, Iterable, Container):
|
||||
return NotImplemented
|
||||
return dict(self.items()) == dict(other.items())
|
||||
|
||||
__reversed__ = None
|
||||
|
||||
Mapping.register(mappingproxy)
|
||||
|
||||
|
||||
@@ -670,7 +737,7 @@ class ItemsView(MappingView, Set):
|
||||
except KeyError:
|
||||
return False
|
||||
else:
|
||||
return v == value
|
||||
return v is value or v == value
|
||||
|
||||
def __iter__(self):
|
||||
for key in self._mapping:
|
||||
@@ -679,13 +746,14 @@ class ItemsView(MappingView, Set):
|
||||
ItemsView.register(dict_items)
|
||||
|
||||
|
||||
class ValuesView(MappingView):
|
||||
class ValuesView(MappingView, Collection):
|
||||
|
||||
__slots__ = ()
|
||||
|
||||
def __contains__(self, value):
|
||||
for key in self._mapping:
|
||||
if value == self._mapping[key]:
|
||||
v = self._mapping[key]
|
||||
if v is value or v == value:
|
||||
return True
|
||||
return False
|
||||
|
||||
@@ -740,7 +808,7 @@ class MutableMapping(Mapping):
|
||||
try:
|
||||
key = next(iter(self))
|
||||
except StopIteration:
|
||||
raise KeyError
|
||||
raise KeyError from None
|
||||
value = self[key]
|
||||
del self[key]
|
||||
return key, value
|
||||
@@ -794,7 +862,7 @@ MutableMapping.register(dict)
|
||||
### SEQUENCES ###
|
||||
|
||||
|
||||
class Sequence(Sized, Iterable, Container):
|
||||
class Sequence(Reversible, Collection):
|
||||
|
||||
"""All the operations on a read-only sequence.
|
||||
|
||||
@@ -820,7 +888,7 @@ class Sequence(Sized, Iterable, Container):
|
||||
|
||||
def __contains__(self, value):
|
||||
for v in self:
|
||||
if v == value:
|
||||
if v is value or v == value:
|
||||
return True
|
||||
return False
|
||||
|
||||
@@ -831,6 +899,9 @@ class Sequence(Sized, Iterable, Container):
|
||||
def index(self, value, start=0, stop=None):
|
||||
'''S.index(value, [start, [stop]]) -> integer -- return first index of value.
|
||||
Raises ValueError if the value is not present.
|
||||
|
||||
Supporting start and stop arguments is optional, but
|
||||
recommended.
|
||||
'''
|
||||
if start is not None and start < 0:
|
||||
start = max(len(self) + start, 0)
|
||||
@@ -840,7 +911,8 @@ class Sequence(Sized, Iterable, Container):
|
||||
i = start
|
||||
while stop is None or i < stop:
|
||||
try:
|
||||
if self[i] == value:
|
||||
v = self[i]
|
||||
if v is value or v == value:
|
||||
return i
|
||||
except IndexError:
|
||||
break
|
||||
@@ -849,7 +921,7 @@ class Sequence(Sized, Iterable, Container):
|
||||
|
||||
def count(self, value):
|
||||
'S.count(value) -> integer -- return number of occurrences of value'
|
||||
return sum(1 for v in self if v == value)
|
||||
return sum(1 for v in self if v is value or v == value)
|
||||
|
||||
Sequence.register(tuple)
|
||||
Sequence.register(str)
|
||||
@@ -0,0 +1,170 @@
|
||||
# Copyright 2007 Google, Inc. All Rights Reserved.
|
||||
# Licensed to PSF under a Contributor Agreement.
|
||||
|
||||
"""Abstract Base Classes (ABCs) according to PEP 3119."""
|
||||
|
||||
|
||||
def abstractmethod(funcobj):
|
||||
"""A decorator indicating abstract methods.
|
||||
|
||||
Requires that the metaclass is ABCMeta or derived from it. A
|
||||
class that has a metaclass derived from ABCMeta cannot be
|
||||
instantiated unless all of its abstract methods are overridden.
|
||||
The abstract methods can be called using any of the normal
|
||||
'super' call mechanisms.
|
||||
|
||||
Usage:
|
||||
|
||||
class C(metaclass=ABCMeta):
|
||||
@abstractmethod
|
||||
def my_abstract_method(self, ...):
|
||||
...
|
||||
"""
|
||||
funcobj.__isabstractmethod__ = True
|
||||
return funcobj
|
||||
|
||||
|
||||
class abstractclassmethod(classmethod):
|
||||
"""A decorator indicating abstract classmethods.
|
||||
|
||||
Similar to abstractmethod.
|
||||
|
||||
Usage:
|
||||
|
||||
class C(metaclass=ABCMeta):
|
||||
@abstractclassmethod
|
||||
def my_abstract_classmethod(cls, ...):
|
||||
...
|
||||
|
||||
'abstractclassmethod' is deprecated. Use 'classmethod' with
|
||||
'abstractmethod' instead.
|
||||
"""
|
||||
|
||||
__isabstractmethod__ = True
|
||||
|
||||
def __init__(self, callable):
|
||||
callable.__isabstractmethod__ = True
|
||||
super().__init__(callable)
|
||||
|
||||
|
||||
class abstractstaticmethod(staticmethod):
|
||||
"""A decorator indicating abstract staticmethods.
|
||||
|
||||
Similar to abstractmethod.
|
||||
|
||||
Usage:
|
||||
|
||||
class C(metaclass=ABCMeta):
|
||||
@abstractstaticmethod
|
||||
def my_abstract_staticmethod(...):
|
||||
...
|
||||
|
||||
'abstractstaticmethod' is deprecated. Use 'staticmethod' with
|
||||
'abstractmethod' instead.
|
||||
"""
|
||||
|
||||
__isabstractmethod__ = True
|
||||
|
||||
def __init__(self, callable):
|
||||
callable.__isabstractmethod__ = True
|
||||
super().__init__(callable)
|
||||
|
||||
|
||||
class abstractproperty(property):
|
||||
"""A decorator indicating abstract properties.
|
||||
|
||||
Requires that the metaclass is ABCMeta or derived from it. A
|
||||
class that has a metaclass derived from ABCMeta cannot be
|
||||
instantiated unless all of its abstract properties are overridden.
|
||||
The abstract properties can be called using any of the normal
|
||||
'super' call mechanisms.
|
||||
|
||||
Usage:
|
||||
|
||||
class C(metaclass=ABCMeta):
|
||||
@abstractproperty
|
||||
def my_abstract_property(self):
|
||||
...
|
||||
|
||||
This defines a read-only property; you can also define a read-write
|
||||
abstract property using the 'long' form of property declaration:
|
||||
|
||||
class C(metaclass=ABCMeta):
|
||||
def getx(self): ...
|
||||
def setx(self, value): ...
|
||||
x = abstractproperty(getx, setx)
|
||||
|
||||
'abstractproperty' is deprecated. Use 'property' with 'abstractmethod'
|
||||
instead.
|
||||
"""
|
||||
|
||||
__isabstractmethod__ = True
|
||||
|
||||
|
||||
try:
|
||||
from _abc import (get_cache_token, _abc_init, _abc_register,
|
||||
_abc_instancecheck, _abc_subclasscheck, _get_dump,
|
||||
_reset_registry, _reset_caches)
|
||||
except ImportError:
|
||||
from _py_abc import ABCMeta, get_cache_token
|
||||
ABCMeta.__module__ = 'abc'
|
||||
else:
|
||||
class ABCMeta(type):
|
||||
"""Metaclass for defining Abstract Base Classes (ABCs).
|
||||
|
||||
Use this metaclass to create an ABC. An ABC can be subclassed
|
||||
directly, and then acts as a mix-in class. You can also register
|
||||
unrelated concrete classes (even built-in classes) and unrelated
|
||||
ABCs as 'virtual subclasses' -- these and their descendants will
|
||||
be considered subclasses of the registering ABC by the built-in
|
||||
issubclass() function, but the registering ABC won't show up in
|
||||
their MRO (Method Resolution Order) nor will method
|
||||
implementations defined by the registering ABC be callable (not
|
||||
even via super()).
|
||||
"""
|
||||
def __new__(mcls, name, bases, namespace, **kwargs):
|
||||
cls = super().__new__(mcls, name, bases, namespace, **kwargs)
|
||||
_abc_init(cls)
|
||||
return cls
|
||||
|
||||
def register(cls, subclass):
|
||||
"""Register a virtual subclass of an ABC.
|
||||
|
||||
Returns the subclass, to allow usage as a class decorator.
|
||||
"""
|
||||
return _abc_register(cls, subclass)
|
||||
|
||||
def __instancecheck__(cls, instance):
|
||||
"""Override for isinstance(instance, cls)."""
|
||||
return _abc_instancecheck(cls, instance)
|
||||
|
||||
def __subclasscheck__(cls, subclass):
|
||||
"""Override for issubclass(subclass, cls)."""
|
||||
return _abc_subclasscheck(cls, subclass)
|
||||
|
||||
def _dump_registry(cls, file=None):
|
||||
"""Debug helper to print the ABC registry."""
|
||||
print(f"Class: {cls.__module__}.{cls.__qualname__}", file=file)
|
||||
print(f"Inv. counter: {get_cache_token()}", file=file)
|
||||
(_abc_registry, _abc_cache, _abc_negative_cache,
|
||||
_abc_negative_cache_version) = _get_dump(cls)
|
||||
print(f"_abc_registry: {_abc_registry!r}", file=file)
|
||||
print(f"_abc_cache: {_abc_cache!r}", file=file)
|
||||
print(f"_abc_negative_cache: {_abc_negative_cache!r}", file=file)
|
||||
print(f"_abc_negative_cache_version: {_abc_negative_cache_version!r}",
|
||||
file=file)
|
||||
|
||||
def _abc_registry_clear(cls):
|
||||
"""Clear the registry (for debugging or testing)."""
|
||||
_reset_registry(cls)
|
||||
|
||||
def _abc_caches_clear(cls):
|
||||
"""Clear the caches (for debugging or testing)."""
|
||||
_reset_caches(cls)
|
||||
|
||||
|
||||
class ABC(metaclass=ABCMeta):
|
||||
"""Helper class that provides a standard way to create an ABC using
|
||||
inheritance.
|
||||
"""
|
||||
__slots__ = ()
|
||||
+294
-144
@@ -1,13 +1,23 @@
|
||||
'''This module implements specialized container datatypes providing
|
||||
alternatives to Python's general purpose built-in containers, dict,
|
||||
list, set, and tuple.
|
||||
|
||||
* namedtuple factory function for creating tuple subclasses with named fields
|
||||
* deque list-like container with fast appends and pops on either end
|
||||
* ChainMap dict-like class for creating a single view of multiple mappings
|
||||
* Counter dict subclass for counting hashable objects
|
||||
* OrderedDict dict subclass that remembers the order entries were added
|
||||
* defaultdict dict subclass that calls a factory function to supply missing values
|
||||
* UserDict wrapper around dictionary objects for easier dict subclassing
|
||||
* UserList wrapper around list objects for easier list subclassing
|
||||
* UserString wrapper around string objects for easier string subclassing
|
||||
|
||||
'''
|
||||
|
||||
__all__ = ['deque', 'defaultdict', 'namedtuple', 'UserDict', 'UserList',
|
||||
'UserString', 'Counter', 'OrderedDict', 'ChainMap']
|
||||
|
||||
# For backwards compatibility, continue to make the collections ABCs
|
||||
# available through the collections module.
|
||||
from _collections_abc import *
|
||||
import _collections_abc
|
||||
__all__ += _collections_abc.__all__
|
||||
|
||||
from _collections import deque, defaultdict
|
||||
from operator import itemgetter as _itemgetter, eq as _eq
|
||||
from keyword import iskeyword as _iskeyword
|
||||
import sys as _sys
|
||||
@@ -16,10 +26,55 @@ from _weakref import proxy as _proxy
|
||||
from itertools import repeat as _repeat, chain as _chain, starmap as _starmap
|
||||
from reprlib import recursive_repr as _recursive_repr
|
||||
|
||||
try:
|
||||
from _collections import deque
|
||||
except ImportError:
|
||||
pass
|
||||
else:
|
||||
_collections_abc.MutableSequence.register(deque)
|
||||
|
||||
try:
|
||||
from _collections import defaultdict
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
def __getattr__(name):
|
||||
# For backwards compatibility, continue to make the collections ABCs
|
||||
# through Python 3.6 available through the collections module.
|
||||
# Note, no new collections ABCs were added in Python 3.7
|
||||
if name in _collections_abc.__all__:
|
||||
obj = getattr(_collections_abc, name)
|
||||
import warnings
|
||||
warnings.warn("Using or importing the ABCs from 'collections' instead "
|
||||
"of from 'collections.abc' is deprecated, "
|
||||
"and in 3.8 it will stop working",
|
||||
DeprecationWarning, stacklevel=2)
|
||||
globals()[name] = obj
|
||||
return obj
|
||||
raise AttributeError(f'module {__name__!r} has no attribute {name!r}')
|
||||
|
||||
################################################################################
|
||||
### OrderedDict
|
||||
################################################################################
|
||||
|
||||
class _OrderedDictKeysView(_collections_abc.KeysView):
|
||||
|
||||
def __reversed__(self):
|
||||
yield from reversed(self._mapping)
|
||||
|
||||
class _OrderedDictItemsView(_collections_abc.ItemsView):
|
||||
|
||||
def __reversed__(self):
|
||||
for key in reversed(self._mapping):
|
||||
yield (key, self._mapping[key])
|
||||
|
||||
class _OrderedDictValuesView(_collections_abc.ValuesView):
|
||||
|
||||
def __reversed__(self):
|
||||
for key in reversed(self._mapping):
|
||||
yield self._mapping[key]
|
||||
|
||||
class _Link(object):
|
||||
__slots__ = 'prev', 'next', 'key', '__weakref__'
|
||||
|
||||
@@ -38,12 +93,14 @@ class OrderedDict(dict):
|
||||
# Individual links are kept alive by the hard reference in self.__map.
|
||||
# Those hard references disappear when a key is deleted from an OrderedDict.
|
||||
|
||||
def __init__(self, *args, **kwds):
|
||||
def __init__(*args, **kwds):
|
||||
'''Initialize an ordered dictionary. The signature is the same as
|
||||
regular dictionaries, but keyword arguments are not recommended because
|
||||
their insertion order is arbitrary.
|
||||
|
||||
regular dictionaries. Keyword argument order is preserved.
|
||||
'''
|
||||
if not args:
|
||||
raise TypeError("descriptor '__init__' of 'OrderedDict' object "
|
||||
"needs an argument")
|
||||
self, *args = args
|
||||
if len(args) > 1:
|
||||
raise TypeError('expected at most 1 arguments, got %d' % len(args))
|
||||
try:
|
||||
@@ -79,6 +136,8 @@ class OrderedDict(dict):
|
||||
link_next = link.next
|
||||
link_prev.next = link_next
|
||||
link_next.prev = link_prev
|
||||
link.prev = None
|
||||
link.next = None
|
||||
|
||||
def __iter__(self):
|
||||
'od.__iter__() <==> iter(od)'
|
||||
@@ -106,9 +165,9 @@ class OrderedDict(dict):
|
||||
dict.clear(self)
|
||||
|
||||
def popitem(self, last=True):
|
||||
'''od.popitem() -> (k, v), return and remove a (key, value) pair.
|
||||
Pairs are returned in LIFO order if last is true or FIFO order if false.
|
||||
'''Remove and return a (key, value) pair from the dictionary.
|
||||
|
||||
Pairs are returned in LIFO order if last is true or FIFO order if false.
|
||||
'''
|
||||
if not self:
|
||||
raise KeyError('dictionary is empty')
|
||||
@@ -129,15 +188,14 @@ class OrderedDict(dict):
|
||||
return key, value
|
||||
|
||||
def move_to_end(self, key, last=True):
|
||||
'''Move an existing element to the end (or beginning if last==False).
|
||||
|
||||
Raises KeyError if the element does not exist.
|
||||
When last=True, acts like a fast version of self[key]=self.pop(key).
|
||||
'''Move an existing element to the end (or beginning if last is false).
|
||||
|
||||
Raise KeyError if the element does not exist.
|
||||
'''
|
||||
link = self.__map[key]
|
||||
link_prev = link.prev
|
||||
link_next = link.next
|
||||
soft_link = link_next.prev
|
||||
link_prev.next = link_next
|
||||
link_next.prev = link_prev
|
||||
root = self.__root
|
||||
@@ -145,12 +203,14 @@ class OrderedDict(dict):
|
||||
last = root.prev
|
||||
link.prev = last
|
||||
link.next = root
|
||||
last.next = root.prev = link
|
||||
root.prev = soft_link
|
||||
last.next = link
|
||||
else:
|
||||
first = root.next
|
||||
link.prev = root
|
||||
link.next = first
|
||||
root.next = first.prev = link
|
||||
first.prev = soft_link
|
||||
root.next = link
|
||||
|
||||
def __sizeof__(self):
|
||||
sizeof = _sys.getsizeof
|
||||
@@ -161,11 +221,21 @@ class OrderedDict(dict):
|
||||
size += sizeof(self.__root) * n # proxy objects
|
||||
return size
|
||||
|
||||
update = __update = MutableMapping.update
|
||||
keys = MutableMapping.keys
|
||||
values = MutableMapping.values
|
||||
items = MutableMapping.items
|
||||
__ne__ = MutableMapping.__ne__
|
||||
update = __update = _collections_abc.MutableMapping.update
|
||||
|
||||
def keys(self):
|
||||
"D.keys() -> a set-like object providing a view on D's keys"
|
||||
return _OrderedDictKeysView(self)
|
||||
|
||||
def items(self):
|
||||
"D.items() -> a set-like object providing a view on D's items"
|
||||
return _OrderedDictItemsView(self)
|
||||
|
||||
def values(self):
|
||||
"D.values() -> an object providing a view on D's values"
|
||||
return _OrderedDictValuesView(self)
|
||||
|
||||
__ne__ = _collections_abc.MutableMapping.__ne__
|
||||
|
||||
__marker = object()
|
||||
|
||||
@@ -184,7 +254,10 @@ class OrderedDict(dict):
|
||||
return default
|
||||
|
||||
def setdefault(self, key, default=None):
|
||||
'od.setdefault(k[,d]) -> od.get(k,d), also set od[k]=d if k not in od'
|
||||
'''Insert key with a value of default if key is not in the dictionary.
|
||||
|
||||
Return the value for key if key is in the dictionary, else default.
|
||||
'''
|
||||
if key in self:
|
||||
return self[key]
|
||||
self[key] = default
|
||||
@@ -210,9 +283,7 @@ class OrderedDict(dict):
|
||||
|
||||
@classmethod
|
||||
def fromkeys(cls, iterable, value=None):
|
||||
'''OD.fromkeys(S[, v]) -> New ordered dictionary with keys from S.
|
||||
If not specified, the value defaults to None.
|
||||
|
||||
'''Create a new ordered dictionary with keys from iterable and values set to value.
|
||||
'''
|
||||
self = cls()
|
||||
for key in iterable:
|
||||
@@ -229,72 +300,20 @@ class OrderedDict(dict):
|
||||
return dict.__eq__(self, other)
|
||||
|
||||
|
||||
try:
|
||||
from _collections import OrderedDict
|
||||
except ImportError:
|
||||
# Leave the pure Python version in place.
|
||||
pass
|
||||
|
||||
|
||||
################################################################################
|
||||
### namedtuple
|
||||
################################################################################
|
||||
|
||||
_class_template = """\
|
||||
from builtins import property as _property, tuple as _tuple
|
||||
from operator import itemgetter as _itemgetter
|
||||
from collections import OrderedDict
|
||||
_nt_itemgetters = {}
|
||||
|
||||
class {typename}(tuple):
|
||||
'{typename}({arg_list})'
|
||||
|
||||
__slots__ = ()
|
||||
|
||||
_fields = {field_names!r}
|
||||
|
||||
def __new__(_cls, {arg_list}):
|
||||
'Create new instance of {typename}({arg_list})'
|
||||
return _tuple.__new__(_cls, ({arg_list}))
|
||||
|
||||
@classmethod
|
||||
def _make(cls, iterable, new=tuple.__new__, len=len):
|
||||
'Make a new {typename} object from a sequence or iterable'
|
||||
result = new(cls, iterable)
|
||||
if len(result) != {num_fields:d}:
|
||||
raise TypeError('Expected {num_fields:d} arguments, got %d' % len(result))
|
||||
return result
|
||||
|
||||
def _replace(_self, **kwds):
|
||||
'Return a new {typename} object replacing specified fields with new values'
|
||||
result = _self._make(map(kwds.pop, {field_names!r}, _self))
|
||||
if kwds:
|
||||
raise ValueError('Got unexpected field names: %r' % list(kwds))
|
||||
return result
|
||||
|
||||
def __repr__(self):
|
||||
'Return a nicely formatted representation string'
|
||||
return self.__class__.__name__ + '({repr_fmt})' % self
|
||||
|
||||
@property
|
||||
def __dict__(self):
|
||||
'A new OrderedDict mapping field names to their values'
|
||||
return OrderedDict(zip(self._fields, self))
|
||||
|
||||
def _asdict(self):
|
||||
'Return a new OrderedDict which maps field names to their values.'
|
||||
return self.__dict__
|
||||
|
||||
def __getnewargs__(self):
|
||||
'Return self as a plain tuple. Used by copy and pickle.'
|
||||
return tuple(self)
|
||||
|
||||
def __getstate__(self):
|
||||
'Exclude the OrderedDict from pickling'
|
||||
return None
|
||||
|
||||
{field_defs}
|
||||
"""
|
||||
|
||||
_repr_template = '{name}=%r'
|
||||
|
||||
_field_template = '''\
|
||||
{name} = _property(_itemgetter({index:d}), doc='Alias for field number {index:d}')
|
||||
'''
|
||||
|
||||
def namedtuple(typename, field_names, verbose=False, rename=False):
|
||||
def namedtuple(typename, field_names, *, rename=False, defaults=None, module=None):
|
||||
"""Returns a new subclass of tuple with named fields.
|
||||
|
||||
>>> Point = namedtuple('Point', ['x', 'y'])
|
||||
@@ -306,7 +325,7 @@ def namedtuple(typename, field_names, verbose=False, rename=False):
|
||||
>>> x, y = p # unpack like a regular tuple
|
||||
>>> x, y
|
||||
(11, 22)
|
||||
>>> p.x + p.y # fields also accessable by name
|
||||
>>> p.x + p.y # fields also accessible by name
|
||||
33
|
||||
>>> d = p._asdict() # convert to a dictionary
|
||||
>>> d['x']
|
||||
@@ -323,6 +342,8 @@ def namedtuple(typename, field_names, verbose=False, rename=False):
|
||||
if isinstance(field_names, str):
|
||||
field_names = field_names.replace(',', ' ').split()
|
||||
field_names = list(map(str, field_names))
|
||||
typename = _sys.intern(str(typename))
|
||||
|
||||
if rename:
|
||||
seen = set()
|
||||
for index, name in enumerate(field_names):
|
||||
@@ -330,53 +351,130 @@ def namedtuple(typename, field_names, verbose=False, rename=False):
|
||||
or _iskeyword(name)
|
||||
or name.startswith('_')
|
||||
or name in seen):
|
||||
field_names[index] = '_%d' % index
|
||||
field_names[index] = f'_{index}'
|
||||
seen.add(name)
|
||||
|
||||
for name in [typename] + field_names:
|
||||
if type(name) is not str:
|
||||
raise TypeError('Type names and field names must be strings')
|
||||
if not name.isidentifier():
|
||||
raise ValueError('Type names and field names must be valid '
|
||||
'identifiers: %r' % name)
|
||||
f'identifiers: {name!r}')
|
||||
if _iskeyword(name):
|
||||
raise ValueError('Type names and field names cannot be a '
|
||||
'keyword: %r' % name)
|
||||
f'keyword: {name!r}')
|
||||
|
||||
seen = set()
|
||||
for name in field_names:
|
||||
if name.startswith('_') and not rename:
|
||||
raise ValueError('Field names cannot start with an underscore: '
|
||||
'%r' % name)
|
||||
f'{name!r}')
|
||||
if name in seen:
|
||||
raise ValueError('Encountered duplicate field name: %r' % name)
|
||||
raise ValueError(f'Encountered duplicate field name: {name!r}')
|
||||
seen.add(name)
|
||||
|
||||
# Fill-in the class template
|
||||
class_definition = _class_template.format(
|
||||
typename = typename,
|
||||
field_names = tuple(field_names),
|
||||
num_fields = len(field_names),
|
||||
arg_list = repr(tuple(field_names)).replace("'", "")[1:-1],
|
||||
repr_fmt = ', '.join(_repr_template.format(name=name)
|
||||
for name in field_names),
|
||||
field_defs = '\n'.join(_field_template.format(index=index, name=name)
|
||||
for index, name in enumerate(field_names))
|
||||
)
|
||||
field_defaults = {}
|
||||
if defaults is not None:
|
||||
defaults = tuple(defaults)
|
||||
if len(defaults) > len(field_names):
|
||||
raise TypeError('Got more default values than field names')
|
||||
field_defaults = dict(reversed(list(zip(reversed(field_names),
|
||||
reversed(defaults)))))
|
||||
|
||||
# Execute the template string in a temporary namespace and support
|
||||
# tracing utilities by setting a value for frame.f_globals['__name__']
|
||||
namespace = dict(__name__='namedtuple_%s' % typename)
|
||||
exec(class_definition, namespace)
|
||||
result = namespace[typename]
|
||||
result._source = class_definition
|
||||
if verbose:
|
||||
print(result._source)
|
||||
# Variables used in the methods and docstrings
|
||||
field_names = tuple(map(_sys.intern, field_names))
|
||||
num_fields = len(field_names)
|
||||
arg_list = repr(field_names).replace("'", "")[1:-1]
|
||||
repr_fmt = '(' + ', '.join(f'{name}=%r' for name in field_names) + ')'
|
||||
tuple_new = tuple.__new__
|
||||
_len = len
|
||||
|
||||
# Create all the named tuple methods to be added to the class namespace
|
||||
|
||||
s = f'def __new__(_cls, {arg_list}): return _tuple_new(_cls, ({arg_list}))'
|
||||
namespace = {'_tuple_new': tuple_new, '__name__': f'namedtuple_{typename}'}
|
||||
# Note: exec() has the side-effect of interning the field names
|
||||
exec(s, namespace)
|
||||
__new__ = namespace['__new__']
|
||||
__new__.__doc__ = f'Create new instance of {typename}({arg_list})'
|
||||
if defaults is not None:
|
||||
__new__.__defaults__ = defaults
|
||||
|
||||
@classmethod
|
||||
def _make(cls, iterable):
|
||||
result = tuple_new(cls, iterable)
|
||||
if _len(result) != num_fields:
|
||||
raise TypeError(f'Expected {num_fields} arguments, got {len(result)}')
|
||||
return result
|
||||
|
||||
_make.__func__.__doc__ = (f'Make a new {typename} object from a sequence '
|
||||
'or iterable')
|
||||
|
||||
def _replace(_self, **kwds):
|
||||
result = _self._make(map(kwds.pop, field_names, _self))
|
||||
if kwds:
|
||||
raise ValueError(f'Got unexpected field names: {list(kwds)!r}')
|
||||
return result
|
||||
|
||||
_replace.__doc__ = (f'Return a new {typename} object replacing specified '
|
||||
'fields with new values')
|
||||
|
||||
def __repr__(self):
|
||||
'Return a nicely formatted representation string'
|
||||
return self.__class__.__name__ + repr_fmt % self
|
||||
|
||||
def _asdict(self):
|
||||
'Return a new OrderedDict which maps field names to their values.'
|
||||
return OrderedDict(zip(self._fields, self))
|
||||
|
||||
def __getnewargs__(self):
|
||||
'Return self as a plain tuple. Used by copy and pickle.'
|
||||
return tuple(self)
|
||||
|
||||
# Modify function metadata to help with introspection and debugging
|
||||
|
||||
for method in (__new__, _make.__func__, _replace,
|
||||
__repr__, _asdict, __getnewargs__):
|
||||
method.__qualname__ = f'{typename}.{method.__name__}'
|
||||
|
||||
# Build-up the class namespace dictionary
|
||||
# and use type() to build the result class
|
||||
class_namespace = {
|
||||
'__doc__': f'{typename}({arg_list})',
|
||||
'__slots__': (),
|
||||
'_fields': field_names,
|
||||
'_fields_defaults': field_defaults,
|
||||
'__new__': __new__,
|
||||
'_make': _make,
|
||||
'_replace': _replace,
|
||||
'__repr__': __repr__,
|
||||
'_asdict': _asdict,
|
||||
'__getnewargs__': __getnewargs__,
|
||||
}
|
||||
cache = _nt_itemgetters
|
||||
for index, name in enumerate(field_names):
|
||||
try:
|
||||
itemgetter_object, doc = cache[index]
|
||||
except KeyError:
|
||||
itemgetter_object = _itemgetter(index)
|
||||
doc = f'Alias for field number {index}'
|
||||
cache[index] = itemgetter_object, doc
|
||||
class_namespace[name] = property(itemgetter_object, doc=doc)
|
||||
|
||||
result = type(typename, (tuple,), class_namespace)
|
||||
|
||||
# For pickling to work, the __module__ variable needs to be set to the frame
|
||||
# where the named tuple is created. Bypass this step in environments where
|
||||
# sys._getframe is not defined (Jython for example) or sys._getframe is not
|
||||
# defined for arguments greater than 0 (IronPython).
|
||||
try:
|
||||
result.__module__ = _sys._getframe(1).f_globals.get('__name__', '__main__')
|
||||
except (AttributeError, ValueError):
|
||||
pass
|
||||
# defined for arguments greater than 0 (IronPython), or where the user has
|
||||
# specified a particular module.
|
||||
if module is None:
|
||||
try:
|
||||
module = _sys._getframe(1).f_globals.get('__name__', '__main__')
|
||||
except (AttributeError, ValueError):
|
||||
pass
|
||||
if module is not None:
|
||||
result.__module__ = module
|
||||
|
||||
return result
|
||||
|
||||
@@ -447,7 +545,7 @@ class Counter(dict):
|
||||
# http://code.activestate.com/recipes/259174/
|
||||
# Knuth, TAOCP Vol. II section 4.6.3
|
||||
|
||||
def __init__(self, iterable=None, **kwds):
|
||||
def __init__(*args, **kwds):
|
||||
'''Create a new, empty Counter object. And if given, count elements
|
||||
from an input iterable. Or, initialize the count from another mapping
|
||||
of elements to their counts.
|
||||
@@ -458,8 +556,14 @@ class Counter(dict):
|
||||
>>> c = Counter(a=4, b=2) # a new counter from keyword args
|
||||
|
||||
'''
|
||||
super().__init__()
|
||||
self.update(iterable, **kwds)
|
||||
if not args:
|
||||
raise TypeError("descriptor '__init__' of 'Counter' object "
|
||||
"needs an argument")
|
||||
self, *args = args
|
||||
if len(args) > 1:
|
||||
raise TypeError('expected at most 1 arguments, got %d' % len(args))
|
||||
super(Counter, self).__init__()
|
||||
self.update(*args, **kwds)
|
||||
|
||||
def __missing__(self, key):
|
||||
'The count of elements not in the Counter is zero.'
|
||||
@@ -510,7 +614,7 @@ class Counter(dict):
|
||||
raise NotImplementedError(
|
||||
'Counter.fromkeys() is undefined. Use Counter(iterable) instead.')
|
||||
|
||||
def update(self, iterable=None, **kwds):
|
||||
def update(*args, **kwds):
|
||||
'''Like dict.update() but add counts instead of replacing them.
|
||||
|
||||
Source can be an iterable, a dictionary, or another Counter instance.
|
||||
@@ -530,20 +634,27 @@ class Counter(dict):
|
||||
# contexts. Instead, we implement straight-addition. Both the inputs
|
||||
# and outputs are allowed to contain zero and negative counts.
|
||||
|
||||
if not args:
|
||||
raise TypeError("descriptor 'update' of 'Counter' object "
|
||||
"needs an argument")
|
||||
self, *args = args
|
||||
if len(args) > 1:
|
||||
raise TypeError('expected at most 1 arguments, got %d' % len(args))
|
||||
iterable = args[0] if args else None
|
||||
if iterable is not None:
|
||||
if isinstance(iterable, Mapping):
|
||||
if isinstance(iterable, _collections_abc.Mapping):
|
||||
if self:
|
||||
self_get = self.get
|
||||
for elem, count in iterable.items():
|
||||
self[elem] = count + self_get(elem, 0)
|
||||
else:
|
||||
super().update(iterable) # fast path when counter is empty
|
||||
super(Counter, self).update(iterable) # fast path when counter is empty
|
||||
else:
|
||||
_count_elements(self, iterable)
|
||||
if kwds:
|
||||
self.update(kwds)
|
||||
|
||||
def subtract(self, iterable=None, **kwds):
|
||||
def subtract(*args, **kwds):
|
||||
'''Like dict.update() but subtracts counts instead of replacing them.
|
||||
Counts can be reduced below zero. Both the inputs and outputs are
|
||||
allowed to contain zero and negative counts.
|
||||
@@ -559,9 +670,16 @@ class Counter(dict):
|
||||
-1
|
||||
|
||||
'''
|
||||
if not args:
|
||||
raise TypeError("descriptor 'subtract' of 'Counter' object "
|
||||
"needs an argument")
|
||||
self, *args = args
|
||||
if len(args) > 1:
|
||||
raise TypeError('expected at most 1 arguments, got %d' % len(args))
|
||||
iterable = args[0] if args else None
|
||||
if iterable is not None:
|
||||
self_get = self.get
|
||||
if isinstance(iterable, Mapping):
|
||||
if isinstance(iterable, _collections_abc.Mapping):
|
||||
for elem, count in iterable.items():
|
||||
self[elem] = self_get(elem, 0) - count
|
||||
else:
|
||||
@@ -678,14 +796,22 @@ class Counter(dict):
|
||||
|
||||
def __pos__(self):
|
||||
'Adds an empty counter, effectively stripping negative and zero counts'
|
||||
return self + Counter()
|
||||
result = Counter()
|
||||
for elem, count in self.items():
|
||||
if count > 0:
|
||||
result[elem] = count
|
||||
return result
|
||||
|
||||
def __neg__(self):
|
||||
'''Subtracts from an empty counter. Strips positive and zero counts,
|
||||
and flips the sign on negative counts.
|
||||
|
||||
'''
|
||||
return Counter() - self
|
||||
result = Counter()
|
||||
for elem, count in self.items():
|
||||
if count < 0:
|
||||
result[elem] = 0 - count
|
||||
return result
|
||||
|
||||
def _keep_positive(self):
|
||||
'''Internal method to strip elements with a negative or zero count'''
|
||||
@@ -752,15 +878,16 @@ class Counter(dict):
|
||||
|
||||
|
||||
########################################################################
|
||||
### ChainMap (helper for configparser and string.Template)
|
||||
### ChainMap
|
||||
########################################################################
|
||||
|
||||
class ChainMap(MutableMapping):
|
||||
class ChainMap(_collections_abc.MutableMapping):
|
||||
''' A ChainMap groups multiple dicts (or other mappings) together
|
||||
to create a single, updateable view.
|
||||
|
||||
The underlying mappings are stored in a list. That list is public and can
|
||||
accessed or updated using the *maps* attribute. There is no other state.
|
||||
be accessed or updated using the *maps* attribute. There is no other
|
||||
state.
|
||||
|
||||
Lookups search the underlying mappings successively until a key is found.
|
||||
In contrast, writes, updates, and deletions only operate on the first
|
||||
@@ -793,7 +920,10 @@ class ChainMap(MutableMapping):
|
||||
return len(set().union(*self.maps)) # reuses stored hash values if possible
|
||||
|
||||
def __iter__(self):
|
||||
return iter(set().union(*self.maps))
|
||||
d = {}
|
||||
for mapping in reversed(self.maps):
|
||||
d.update(mapping) # reuses stored hash values if possible
|
||||
return iter(d)
|
||||
|
||||
def __contains__(self, key):
|
||||
return any(key in m for m in self.maps)
|
||||
@@ -818,9 +948,8 @@ class ChainMap(MutableMapping):
|
||||
__copy__ = copy
|
||||
|
||||
def new_child(self, m=None): # like Django's Context.push()
|
||||
'''
|
||||
New ChainMap with a new map followed by all previous maps. If no
|
||||
map is provided, an empty dict is used.
|
||||
'''New ChainMap with a new map followed by all previous maps.
|
||||
If no map is provided, an empty dict is used.
|
||||
'''
|
||||
if m is None:
|
||||
m = {}
|
||||
@@ -863,10 +992,25 @@ class ChainMap(MutableMapping):
|
||||
### UserDict
|
||||
################################################################################
|
||||
|
||||
class UserDict(MutableMapping):
|
||||
class UserDict(_collections_abc.MutableMapping):
|
||||
|
||||
# Start by filling-out the abstract methods
|
||||
def __init__(self, dict=None, **kwargs):
|
||||
def __init__(*args, **kwargs):
|
||||
if not args:
|
||||
raise TypeError("descriptor '__init__' of 'UserDict' object "
|
||||
"needs an argument")
|
||||
self, *args = args
|
||||
if len(args) > 1:
|
||||
raise TypeError('expected at most 1 arguments, got %d' % len(args))
|
||||
if args:
|
||||
dict = args[0]
|
||||
elif 'dict' in kwargs:
|
||||
dict = kwargs.pop('dict')
|
||||
import warnings
|
||||
warnings.warn("Passing 'dict' as keyword argument is deprecated",
|
||||
DeprecationWarning, stacklevel=2)
|
||||
else:
|
||||
dict = None
|
||||
self.data = {}
|
||||
if dict is not None:
|
||||
self.update(dict)
|
||||
@@ -915,7 +1059,7 @@ class UserDict(MutableMapping):
|
||||
### UserList
|
||||
################################################################################
|
||||
|
||||
class UserList(MutableSequence):
|
||||
class UserList(_collections_abc.MutableSequence):
|
||||
"""A more or less complete user-defined wrapper around list objects."""
|
||||
def __init__(self, initlist=None):
|
||||
self.data = []
|
||||
@@ -931,7 +1075,6 @@ class UserList(MutableSequence):
|
||||
def __lt__(self, other): return self.data < self.__cast(other)
|
||||
def __le__(self, other): return self.data <= self.__cast(other)
|
||||
def __eq__(self, other): return self.data == self.__cast(other)
|
||||
def __ne__(self, other): return self.data != self.__cast(other)
|
||||
def __gt__(self, other): return self.data > self.__cast(other)
|
||||
def __ge__(self, other): return self.data >= self.__cast(other)
|
||||
def __cast(self, other):
|
||||
@@ -989,7 +1132,7 @@ class UserList(MutableSequence):
|
||||
### UserString
|
||||
################################################################################
|
||||
|
||||
class UserString(Sequence):
|
||||
class UserString(_collections_abc.Sequence):
|
||||
def __init__(self, seq):
|
||||
if isinstance(seq, str):
|
||||
self.data = seq
|
||||
@@ -1003,15 +1146,13 @@ class UserString(Sequence):
|
||||
def __float__(self): return float(self.data)
|
||||
def __complex__(self): return complex(self.data)
|
||||
def __hash__(self): return hash(self.data)
|
||||
def __getnewargs__(self):
|
||||
return (self.data[:],)
|
||||
|
||||
def __eq__(self, string):
|
||||
if isinstance(string, UserString):
|
||||
return self.data == string.data
|
||||
return self.data == string
|
||||
def __ne__(self, string):
|
||||
if isinstance(string, UserString):
|
||||
return self.data != string.data
|
||||
return self.data != string
|
||||
def __lt__(self, string):
|
||||
if isinstance(string, UserString):
|
||||
return self.data < string.data
|
||||
@@ -1051,9 +1192,13 @@ class UserString(Sequence):
|
||||
__rmul__ = __mul__
|
||||
def __mod__(self, args):
|
||||
return self.__class__(self.data % args)
|
||||
def __rmod__(self, format):
|
||||
return self.__class__(format % args)
|
||||
|
||||
# the following methods are defined in alphabetical order:
|
||||
def capitalize(self): return self.__class__(self.data.capitalize())
|
||||
def casefold(self):
|
||||
return self.__class__(self.data.casefold())
|
||||
def center(self, width, *args):
|
||||
return self.__class__(self.data.center(width, *args))
|
||||
def count(self, sub, start=0, end=_sys.maxsize):
|
||||
@@ -1076,15 +1221,19 @@ class UserString(Sequence):
|
||||
return self.data.find(sub, start, end)
|
||||
def format(self, *args, **kwds):
|
||||
return self.data.format(*args, **kwds)
|
||||
def format_map(self, mapping):
|
||||
return self.data.format_map(mapping)
|
||||
def index(self, sub, start=0, end=_sys.maxsize):
|
||||
return self.data.index(sub, start, end)
|
||||
def isalpha(self): return self.data.isalpha()
|
||||
def isalnum(self): return self.data.isalnum()
|
||||
def isascii(self): return self.data.isascii()
|
||||
def isdecimal(self): return self.data.isdecimal()
|
||||
def isdigit(self): return self.data.isdigit()
|
||||
def isidentifier(self): return self.data.isidentifier()
|
||||
def islower(self): return self.data.islower()
|
||||
def isnumeric(self): return self.data.isnumeric()
|
||||
def isprintable(self): return self.data.isprintable()
|
||||
def isspace(self): return self.data.isspace()
|
||||
def istitle(self): return self.data.istitle()
|
||||
def isupper(self): return self.data.isupper()
|
||||
@@ -1093,6 +1242,7 @@ class UserString(Sequence):
|
||||
return self.__class__(self.data.ljust(width, *args))
|
||||
def lower(self): return self.__class__(self.data.lower())
|
||||
def lstrip(self, chars=None): return self.__class__(self.data.lstrip(chars))
|
||||
maketrans = str.maketrans
|
||||
def partition(self, sep):
|
||||
return self.data.partition(sep)
|
||||
def replace(self, old, new, maxsplit=-1):
|
||||
+638
-332
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,151 @@
|
||||
"""
|
||||
Path operations common to more than one OS
|
||||
Do not use directly. The OS specific modules import the appropriate
|
||||
functions from this module themselves.
|
||||
"""
|
||||
import os
|
||||
import stat
|
||||
|
||||
__all__ = ['commonprefix', 'exists', 'getatime', 'getctime', 'getmtime',
|
||||
'getsize', 'isdir', 'isfile', 'samefile', 'sameopenfile',
|
||||
'samestat']
|
||||
|
||||
|
||||
# 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:
|
||||
os.stat(path)
|
||||
except OSError:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
# This follows symbolic links, so both islink() and isdir() can be true
|
||||
# for the same path on systems that support symlinks
|
||||
def isfile(path):
|
||||
"""Test whether a path is a regular file"""
|
||||
try:
|
||||
st = os.stat(path)
|
||||
except OSError:
|
||||
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 = os.stat(s)
|
||||
except OSError:
|
||||
return False
|
||||
return stat.S_ISDIR(st.st_mode)
|
||||
|
||||
|
||||
def getsize(filename):
|
||||
"""Return the size of a file, reported by os.stat()."""
|
||||
return os.stat(filename).st_size
|
||||
|
||||
|
||||
def getmtime(filename):
|
||||
"""Return the last modification time of a file, reported by os.stat()."""
|
||||
return os.stat(filename).st_mtime
|
||||
|
||||
|
||||
def getatime(filename):
|
||||
"""Return the last access time of a file, reported by os.stat()."""
|
||||
return os.stat(filename).st_atime
|
||||
|
||||
|
||||
def getctime(filename):
|
||||
"""Return the metadata change time of a file, reported by os.stat()."""
|
||||
return os.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 ''
|
||||
# Some people pass in a list of pathname parts to operate in an OS-agnostic
|
||||
# fashion; don't try to translate in that case as that's an abuse of the
|
||||
# API and they are already doing what they need to be OS-agnostic and so
|
||||
# they most likely won't be using an os.PathLike object in the sublists.
|
||||
if not isinstance(m[0], (list, tuple)):
|
||||
m = tuple(map(os.fspath, m))
|
||||
s1 = min(m)
|
||||
s2 = max(m)
|
||||
for i, c in enumerate(s1):
|
||||
if c != s2[i]:
|
||||
return s1[:i]
|
||||
return s1
|
||||
|
||||
# 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)
|
||||
|
||||
|
||||
# Are two filenames really pointing to the same file?
|
||||
def samefile(f1, f2):
|
||||
"""Test whether two pathnames reference the same actual file"""
|
||||
s1 = os.stat(f1)
|
||||
s2 = os.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 = os.fstat(fp1)
|
||||
s2 = os.fstat(fp2)
|
||||
return samestat(s1, s2)
|
||||
|
||||
|
||||
# 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."""
|
||||
# NOTE: This code must work for text and bytes strings.
|
||||
|
||||
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:filenameIndex+1] != extsep:
|
||||
return p[:dotIndex], p[dotIndex:]
|
||||
filenameIndex += 1
|
||||
|
||||
return p, p[:0]
|
||||
|
||||
def _check_arg_types(funcname, *args):
|
||||
hasstr = hasbytes = False
|
||||
for s in args:
|
||||
if isinstance(s, str):
|
||||
hasstr = True
|
||||
elif isinstance(s, bytes):
|
||||
hasbytes = True
|
||||
else:
|
||||
raise TypeError('%s() argument must be str or bytes, not %r' %
|
||||
(funcname, s.__class__.__name__)) from None
|
||||
if hasstr and hasbytes:
|
||||
raise TypeError("Can't mix strings and bytes in path components") from None
|
||||
@@ -19,7 +19,7 @@ streams. BytesIO is a simple stream of in-memory bytes.
|
||||
Another IOBase subclass, TextIOBase, deals with the encoding and decoding
|
||||
of streams into text. TextIOWrapper, which extends it, is a buffered text
|
||||
interface to a buffered raw stream (`BufferedIOBase`). Finally, StringIO
|
||||
is a in-memory stream for text.
|
||||
is an in-memory stream for text.
|
||||
|
||||
Argument names are not part of the specification, and only the arguments
|
||||
of open() are intended to be used as keyword arguments.
|
||||
@@ -90,3 +90,10 @@ for klass in (BytesIO, BufferedReader, BufferedWriter, BufferedRandom,
|
||||
for klass in (StringIO, TextIOWrapper):
|
||||
TextIOBase.register(klass)
|
||||
del klass
|
||||
|
||||
try:
|
||||
from _io import _WindowsConsoleIO
|
||||
except ImportError:
|
||||
pass
|
||||
else:
|
||||
RawIOBase.register(_WindowsConsoleIO)
|
||||
@@ -0,0 +1,669 @@
|
||||
# Module 'ntpath' -- common operations on WinNT/Win95 pathnames
|
||||
"""Common pathname manipulations, WindowsNT/95 version.
|
||||
|
||||
Instead of importing this module directly, import os and refer to this
|
||||
module as os.path.
|
||||
"""
|
||||
|
||||
# strings representing various path-related bits and pieces
|
||||
# These are primarily for export; internally, they are hardcoded.
|
||||
# Should be set before imports for resolving cyclic dependency.
|
||||
curdir = '.'
|
||||
pardir = '..'
|
||||
extsep = '.'
|
||||
sep = '\\'
|
||||
pathsep = ';'
|
||||
altsep = '/'
|
||||
defpath = '.;C:\\bin'
|
||||
devnull = 'nul'
|
||||
|
||||
import os
|
||||
import sys
|
||||
import stat
|
||||
import genericpath
|
||||
from genericpath import *
|
||||
|
||||
__all__ = ["normcase","isabs","join","splitdrive","split","splitext",
|
||||
"basename","dirname","commonprefix","getsize","getmtime",
|
||||
"getatime","getctime", "islink","exists","lexists","isdir","isfile",
|
||||
"ismount", "expanduser","expandvars","normpath","abspath",
|
||||
"curdir","pardir","sep","pathsep","defpath","altsep",
|
||||
"extsep","devnull","realpath","supports_unicode_filenames","relpath",
|
||||
"samefile", "sameopenfile", "samestat", "commonpath"]
|
||||
|
||||
def _get_bothseps(path):
|
||||
if isinstance(path, bytes):
|
||||
return b'\\/'
|
||||
else:
|
||||
return '\\/'
|
||||
|
||||
# Normalize the case of a pathname and map slashes to backslashes.
|
||||
# Other normalizations (such as optimizing '../' away) are not done
|
||||
# (this is done by normpath).
|
||||
|
||||
def normcase(s):
|
||||
"""Normalize case of pathname.
|
||||
|
||||
Makes all characters lowercase and all slashes into backslashes."""
|
||||
s = os.fspath(s)
|
||||
try:
|
||||
if isinstance(s, bytes):
|
||||
return s.replace(b'/', b'\\').lower()
|
||||
else:
|
||||
return s.replace('/', '\\').lower()
|
||||
except (TypeError, AttributeError):
|
||||
if not isinstance(s, (bytes, str)):
|
||||
raise TypeError("normcase() argument must be str or bytes, "
|
||||
"not %r" % s.__class__.__name__) from None
|
||||
raise
|
||||
|
||||
|
||||
# Return whether a path is absolute.
|
||||
# Trivial in Posix, harder on Windows.
|
||||
# For Windows it is absolute if it starts with a slash or backslash (current
|
||||
# volume), or if a pathname after the volume-letter-and-colon or UNC-resource
|
||||
# starts with a slash or backslash.
|
||||
|
||||
def isabs(s):
|
||||
"""Test whether a path is absolute"""
|
||||
s = os.fspath(s)
|
||||
s = splitdrive(s)[1]
|
||||
return len(s) > 0 and s[0] in _get_bothseps(s)
|
||||
|
||||
|
||||
# Join two (or more) paths.
|
||||
def join(path, *paths):
|
||||
path = os.fspath(path)
|
||||
if isinstance(path, bytes):
|
||||
sep = b'\\'
|
||||
seps = b'\\/'
|
||||
colon = b':'
|
||||
else:
|
||||
sep = '\\'
|
||||
seps = '\\/'
|
||||
colon = ':'
|
||||
try:
|
||||
if not paths:
|
||||
path[:0] + sep #23780: Ensure compatible data type even if p is null.
|
||||
result_drive, result_path = splitdrive(path)
|
||||
for p in map(os.fspath, paths):
|
||||
p_drive, p_path = splitdrive(p)
|
||||
if p_path and p_path[0] in seps:
|
||||
# Second path is absolute
|
||||
if p_drive or not result_drive:
|
||||
result_drive = p_drive
|
||||
result_path = p_path
|
||||
continue
|
||||
elif p_drive and p_drive != result_drive:
|
||||
if p_drive.lower() != result_drive.lower():
|
||||
# Different drives => ignore the first path entirely
|
||||
result_drive = p_drive
|
||||
result_path = p_path
|
||||
continue
|
||||
# Same drive in different case
|
||||
result_drive = p_drive
|
||||
# Second path is relative to the first
|
||||
if result_path and result_path[-1] not in seps:
|
||||
result_path = result_path + sep
|
||||
result_path = result_path + p_path
|
||||
## add separator between UNC and non-absolute path
|
||||
if (result_path and result_path[0] not in seps and
|
||||
result_drive and result_drive[-1:] != colon):
|
||||
return result_drive + sep + result_path
|
||||
return result_drive + result_path
|
||||
except (TypeError, AttributeError, BytesWarning):
|
||||
genericpath._check_arg_types('join', path, *paths)
|
||||
raise
|
||||
|
||||
|
||||
# Split a path in a drive specification (a drive letter followed by a
|
||||
# colon) and the path specification.
|
||||
# It is always true that drivespec + pathspec == p
|
||||
def splitdrive(p):
|
||||
"""Split a pathname into drive/UNC sharepoint and relative path specifiers.
|
||||
Returns a 2-tuple (drive_or_unc, path); either part may be empty.
|
||||
|
||||
If you assign
|
||||
result = splitdrive(p)
|
||||
It is always true that:
|
||||
result[0] + result[1] == p
|
||||
|
||||
If the path contained a drive letter, drive_or_unc will contain everything
|
||||
up to and including the colon. e.g. splitdrive("c:/dir") returns ("c:", "/dir")
|
||||
|
||||
If the path contained a UNC path, the drive_or_unc will contain the host name
|
||||
and share up to but not including the fourth directory separator character.
|
||||
e.g. splitdrive("//host/computer/dir") returns ("//host/computer", "/dir")
|
||||
|
||||
Paths cannot contain both a drive letter and a UNC path.
|
||||
|
||||
"""
|
||||
p = os.fspath(p)
|
||||
if len(p) >= 2:
|
||||
if isinstance(p, bytes):
|
||||
sep = b'\\'
|
||||
altsep = b'/'
|
||||
colon = b':'
|
||||
else:
|
||||
sep = '\\'
|
||||
altsep = '/'
|
||||
colon = ':'
|
||||
normp = p.replace(altsep, sep)
|
||||
if (normp[0:2] == sep*2) and (normp[2:3] != sep):
|
||||
# is a UNC path:
|
||||
# vvvvvvvvvvvvvvvvvvvv drive letter or UNC path
|
||||
# \\machine\mountpoint\directory\etc\...
|
||||
# directory ^^^^^^^^^^^^^^^
|
||||
index = normp.find(sep, 2)
|
||||
if index == -1:
|
||||
return p[:0], p
|
||||
index2 = normp.find(sep, index + 1)
|
||||
# a UNC path can't have two slashes in a row
|
||||
# (after the initial two)
|
||||
if index2 == index + 1:
|
||||
return p[:0], p
|
||||
if index2 == -1:
|
||||
index2 = len(p)
|
||||
return p[:index2], p[index2:]
|
||||
if normp[1:2] == colon:
|
||||
return p[:2], p[2:]
|
||||
return p[:0], p
|
||||
|
||||
|
||||
# Split a path in head (everything up to the last '/') and tail (the
|
||||
# rest). After the trailing '/' is stripped, the invariant
|
||||
# join(head, tail) == p holds.
|
||||
# The resulting head won't end in '/' unless it is the root.
|
||||
|
||||
def split(p):
|
||||
"""Split a pathname.
|
||||
|
||||
Return tuple (head, tail) where tail is everything after the final slash.
|
||||
Either part may be empty."""
|
||||
p = os.fspath(p)
|
||||
seps = _get_bothseps(p)
|
||||
d, p = splitdrive(p)
|
||||
# set i to index beyond p's last slash
|
||||
i = len(p)
|
||||
while i and p[i-1] not in seps:
|
||||
i -= 1
|
||||
head, tail = p[:i], p[i:] # now tail has no slashes
|
||||
# remove trailing slashes from head, unless it's all slashes
|
||||
head = head.rstrip(seps) or head
|
||||
return d + 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):
|
||||
p = os.fspath(p)
|
||||
if isinstance(p, bytes):
|
||||
return genericpath._splitext(p, b'\\', b'/', b'.')
|
||||
else:
|
||||
return genericpath._splitext(p, '\\', '/', '.')
|
||||
splitext.__doc__ = genericpath._splitext.__doc__
|
||||
|
||||
|
||||
# Return the tail (basename) part of a path.
|
||||
|
||||
def basename(p):
|
||||
"""Returns the final component of a pathname"""
|
||||
return split(p)[1]
|
||||
|
||||
|
||||
# Return the head (dirname) part of a path.
|
||||
|
||||
def dirname(p):
|
||||
"""Returns the directory component of a pathname"""
|
||||
return split(p)[0]
|
||||
|
||||
# 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.
|
||||
This will always return false for Windows prior to 6.0.
|
||||
"""
|
||||
try:
|
||||
st = os.lstat(path)
|
||||
except (OSError, 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:
|
||||
st = os.lstat(path)
|
||||
except OSError:
|
||||
return False
|
||||
return True
|
||||
|
||||
# Is a path a mount point?
|
||||
# Any drive letter root (eg c:\)
|
||||
# Any share UNC (eg \\server\share)
|
||||
# Any volume mounted on a filesystem folder
|
||||
#
|
||||
# No one method detects all three situations. Historically we've lexically
|
||||
# detected drive letter roots and share UNCs. The canonical approach to
|
||||
# detecting mounted volumes (querying the reparse tag) fails for the most
|
||||
# common case: drive letter roots. The alternative which uses GetVolumePathName
|
||||
# fails if the drive letter is the result of a SUBST.
|
||||
try:
|
||||
from nt import _getvolumepathname
|
||||
except ImportError:
|
||||
_getvolumepathname = None
|
||||
def ismount(path):
|
||||
"""Test whether a path is a mount point (a drive root, the root of a
|
||||
share, or a mounted volume)"""
|
||||
path = os.fspath(path)
|
||||
seps = _get_bothseps(path)
|
||||
path = abspath(path)
|
||||
root, rest = splitdrive(path)
|
||||
if root and root[0] in seps:
|
||||
return (not rest) or (rest in seps)
|
||||
if rest in seps:
|
||||
return True
|
||||
|
||||
if _getvolumepathname:
|
||||
return path.rstrip(seps) == _getvolumepathname(path).rstrip(seps)
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
# 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 constructs.
|
||||
|
||||
If user or $HOME is unknown, do nothing."""
|
||||
path = os.fspath(path)
|
||||
if isinstance(path, bytes):
|
||||
tilde = b'~'
|
||||
else:
|
||||
tilde = '~'
|
||||
if not path.startswith(tilde):
|
||||
return path
|
||||
i, n = 1, len(path)
|
||||
while i < n and path[i] not in _get_bothseps(path):
|
||||
i += 1
|
||||
|
||||
if 'HOME' in os.environ:
|
||||
userhome = os.environ['HOME']
|
||||
elif 'USERPROFILE' in os.environ:
|
||||
userhome = os.environ['USERPROFILE']
|
||||
elif not 'HOMEPATH' in os.environ:
|
||||
return path
|
||||
else:
|
||||
try:
|
||||
drive = os.environ['HOMEDRIVE']
|
||||
except KeyError:
|
||||
drive = ''
|
||||
userhome = join(drive, os.environ['HOMEPATH'])
|
||||
|
||||
if isinstance(path, bytes):
|
||||
userhome = os.fsencode(userhome)
|
||||
|
||||
if i != 1: #~user
|
||||
userhome = join(dirname(userhome), path[1:i])
|
||||
|
||||
return userhome + path[i:]
|
||||
|
||||
|
||||
# Expand paths containing shell variable substitutions.
|
||||
# The following rules apply:
|
||||
# - no expansion within single quotes
|
||||
# - '$$' is translated into '$'
|
||||
# - '%%' is translated into '%' if '%%' are not seen in %var1%%var2%
|
||||
# - ${varname} is accepted.
|
||||
# - $varname is accepted.
|
||||
# - %varname% is accepted.
|
||||
# - varnames can be made out of letters, digits and the characters '_-'
|
||||
# (though is not verified in the ${varname} and %varname% cases)
|
||||
# XXX With COMMAND.COM you can use any characters in a variable name,
|
||||
# XXX except '^|<>='.
|
||||
|
||||
def expandvars(path):
|
||||
"""Expand shell variables of the forms $var, ${var} and %var%.
|
||||
|
||||
Unknown variables are left unchanged."""
|
||||
path = os.fspath(path)
|
||||
if isinstance(path, bytes):
|
||||
if b'$' not in path and b'%' not in path:
|
||||
return path
|
||||
import string
|
||||
varchars = bytes(string.ascii_letters + string.digits + '_-', 'ascii')
|
||||
quote = b'\''
|
||||
percent = b'%'
|
||||
brace = b'{'
|
||||
rbrace = b'}'
|
||||
dollar = b'$'
|
||||
environ = getattr(os, 'environb', None)
|
||||
else:
|
||||
if '$' not in path and '%' not in path:
|
||||
return path
|
||||
import string
|
||||
varchars = string.ascii_letters + string.digits + '_-'
|
||||
quote = '\''
|
||||
percent = '%'
|
||||
brace = '{'
|
||||
rbrace = '}'
|
||||
dollar = '$'
|
||||
environ = os.environ
|
||||
res = path[:0]
|
||||
index = 0
|
||||
pathlen = len(path)
|
||||
while index < pathlen:
|
||||
c = path[index:index+1]
|
||||
if c == quote: # no expansion within single quotes
|
||||
path = path[index + 1:]
|
||||
pathlen = len(path)
|
||||
try:
|
||||
index = path.index(c)
|
||||
res += c + path[:index + 1]
|
||||
except ValueError:
|
||||
res += c + path
|
||||
index = pathlen - 1
|
||||
elif c == percent: # variable or '%'
|
||||
if path[index + 1:index + 2] == percent:
|
||||
res += c
|
||||
index += 1
|
||||
else:
|
||||
path = path[index+1:]
|
||||
pathlen = len(path)
|
||||
try:
|
||||
index = path.index(percent)
|
||||
except ValueError:
|
||||
res += percent + path
|
||||
index = pathlen - 1
|
||||
else:
|
||||
var = path[:index]
|
||||
try:
|
||||
if environ is None:
|
||||
value = os.fsencode(os.environ[os.fsdecode(var)])
|
||||
else:
|
||||
value = environ[var]
|
||||
except KeyError:
|
||||
value = percent + var + percent
|
||||
res += value
|
||||
elif c == dollar: # variable or '$$'
|
||||
if path[index + 1:index + 2] == dollar:
|
||||
res += c
|
||||
index += 1
|
||||
elif path[index + 1:index + 2] == brace:
|
||||
path = path[index+2:]
|
||||
pathlen = len(path)
|
||||
try:
|
||||
index = path.index(rbrace)
|
||||
except ValueError:
|
||||
res += dollar + brace + path
|
||||
index = pathlen - 1
|
||||
else:
|
||||
var = path[:index]
|
||||
try:
|
||||
if environ is None:
|
||||
value = os.fsencode(os.environ[os.fsdecode(var)])
|
||||
else:
|
||||
value = environ[var]
|
||||
except KeyError:
|
||||
value = dollar + brace + var + rbrace
|
||||
res += value
|
||||
else:
|
||||
var = path[:0]
|
||||
index += 1
|
||||
c = path[index:index + 1]
|
||||
while c and c in varchars:
|
||||
var += c
|
||||
index += 1
|
||||
c = path[index:index + 1]
|
||||
try:
|
||||
if environ is None:
|
||||
value = os.fsencode(os.environ[os.fsdecode(var)])
|
||||
else:
|
||||
value = environ[var]
|
||||
except KeyError:
|
||||
value = dollar + var
|
||||
res += value
|
||||
if c:
|
||||
index -= 1
|
||||
else:
|
||||
res += c
|
||||
index += 1
|
||||
return res
|
||||
|
||||
|
||||
# Normalize a path, e.g. A//B, A/./B and A/foo/../B all become A\B.
|
||||
# Previously, this function also truncated pathnames to 8+3 format,
|
||||
# but as this module is called "ntpath", that's obviously wrong!
|
||||
|
||||
def normpath(path):
|
||||
"""Normalize path, eliminating double slashes, etc."""
|
||||
path = os.fspath(path)
|
||||
if isinstance(path, bytes):
|
||||
sep = b'\\'
|
||||
altsep = b'/'
|
||||
curdir = b'.'
|
||||
pardir = b'..'
|
||||
special_prefixes = (b'\\\\.\\', b'\\\\?\\')
|
||||
else:
|
||||
sep = '\\'
|
||||
altsep = '/'
|
||||
curdir = '.'
|
||||
pardir = '..'
|
||||
special_prefixes = ('\\\\.\\', '\\\\?\\')
|
||||
if path.startswith(special_prefixes):
|
||||
# in the case of paths with these prefixes:
|
||||
# \\.\ -> device names
|
||||
# \\?\ -> literal paths
|
||||
# do not do any normalization, but return the path unchanged
|
||||
return path
|
||||
path = path.replace(altsep, sep)
|
||||
prefix, path = splitdrive(path)
|
||||
|
||||
# collapse initial backslashes
|
||||
if path.startswith(sep):
|
||||
prefix += sep
|
||||
path = path.lstrip(sep)
|
||||
|
||||
comps = path.split(sep)
|
||||
i = 0
|
||||
while i < len(comps):
|
||||
if not comps[i] or comps[i] == curdir:
|
||||
del comps[i]
|
||||
elif comps[i] == pardir:
|
||||
if i > 0 and comps[i-1] != pardir:
|
||||
del comps[i-1:i+1]
|
||||
i -= 1
|
||||
elif i == 0 and prefix.endswith(sep):
|
||||
del comps[i]
|
||||
else:
|
||||
i += 1
|
||||
else:
|
||||
i += 1
|
||||
# If the path is now empty, substitute '.'
|
||||
if not prefix and not comps:
|
||||
comps.append(curdir)
|
||||
return prefix + sep.join(comps)
|
||||
|
||||
def _abspath_fallback(path):
|
||||
"""Return the absolute version of a path as a fallback function in case
|
||||
`nt._getfullpathname` is not available or raises OSError. See bpo-31047 for
|
||||
more.
|
||||
|
||||
"""
|
||||
|
||||
path = os.fspath(path)
|
||||
if not isabs(path):
|
||||
if isinstance(path, bytes):
|
||||
cwd = os.getcwdb()
|
||||
else:
|
||||
cwd = os.getcwd()
|
||||
path = join(cwd, path)
|
||||
return normpath(path)
|
||||
|
||||
# Return an absolute path.
|
||||
try:
|
||||
from nt import _getfullpathname
|
||||
|
||||
except ImportError: # not running on Windows - mock up something sensible
|
||||
abspath = _abspath_fallback
|
||||
|
||||
else: # use native Windows method on Windows
|
||||
def abspath(path):
|
||||
"""Return the absolute version of a path."""
|
||||
try:
|
||||
return _getfullpathname(path)
|
||||
except OSError:
|
||||
return _abspath_fallback(path)
|
||||
|
||||
# realpath is a no-op on systems without islink support
|
||||
realpath = abspath
|
||||
# Win9x family and earlier have no Unicode filename support.
|
||||
supports_unicode_filenames = (hasattr(sys, "getwindowsversion") and
|
||||
sys.getwindowsversion()[3] >= 2)
|
||||
|
||||
def relpath(path, start=None):
|
||||
"""Return a relative version of a path"""
|
||||
path = os.fspath(path)
|
||||
if isinstance(path, bytes):
|
||||
sep = b'\\'
|
||||
curdir = b'.'
|
||||
pardir = b'..'
|
||||
else:
|
||||
sep = '\\'
|
||||
curdir = '.'
|
||||
pardir = '..'
|
||||
|
||||
if start is None:
|
||||
start = curdir
|
||||
|
||||
if not path:
|
||||
raise ValueError("no path specified")
|
||||
|
||||
start = os.fspath(start)
|
||||
try:
|
||||
start_abs = abspath(normpath(start))
|
||||
path_abs = abspath(normpath(path))
|
||||
start_drive, start_rest = splitdrive(start_abs)
|
||||
path_drive, path_rest = splitdrive(path_abs)
|
||||
if normcase(start_drive) != normcase(path_drive):
|
||||
raise ValueError("path is on mount %r, start on mount %r" % (
|
||||
path_drive, start_drive))
|
||||
|
||||
start_list = [x for x in start_rest.split(sep) if x]
|
||||
path_list = [x for x in path_rest.split(sep) if x]
|
||||
# Work out how much of the filepath is shared by start and path.
|
||||
i = 0
|
||||
for e1, e2 in zip(start_list, path_list):
|
||||
if normcase(e1) != normcase(e2):
|
||||
break
|
||||
i += 1
|
||||
|
||||
rel_list = [pardir] * (len(start_list)-i) + path_list[i:]
|
||||
if not rel_list:
|
||||
return curdir
|
||||
return join(*rel_list)
|
||||
except (TypeError, ValueError, AttributeError, BytesWarning, DeprecationWarning):
|
||||
genericpath._check_arg_types('relpath', path, start)
|
||||
raise
|
||||
|
||||
|
||||
# Return the longest common sub-path of the sequence of paths given as input.
|
||||
# The function is case-insensitive and 'separator-insensitive', i.e. if the
|
||||
# only difference between two paths is the use of '\' versus '/' as separator,
|
||||
# they are deemed to be equal.
|
||||
#
|
||||
# However, the returned path will have the standard '\' separator (even if the
|
||||
# given paths had the alternative '/' separator) and will have the case of the
|
||||
# first path given in the sequence. Additionally, any trailing separator is
|
||||
# stripped from the returned path.
|
||||
|
||||
def commonpath(paths):
|
||||
"""Given a sequence of path names, returns the longest common sub-path."""
|
||||
|
||||
if not paths:
|
||||
raise ValueError('commonpath() arg is an empty sequence')
|
||||
|
||||
paths = tuple(map(os.fspath, paths))
|
||||
if isinstance(paths[0], bytes):
|
||||
sep = b'\\'
|
||||
altsep = b'/'
|
||||
curdir = b'.'
|
||||
else:
|
||||
sep = '\\'
|
||||
altsep = '/'
|
||||
curdir = '.'
|
||||
|
||||
try:
|
||||
drivesplits = [splitdrive(p.replace(altsep, sep).lower()) for p in paths]
|
||||
split_paths = [p.split(sep) for d, p in drivesplits]
|
||||
|
||||
try:
|
||||
isabs, = set(p[:1] == sep for d, p in drivesplits)
|
||||
except ValueError:
|
||||
raise ValueError("Can't mix absolute and relative paths") from None
|
||||
|
||||
# Check that all drive letters or UNC paths match. The check is made only
|
||||
# now otherwise type errors for mixing strings and bytes would not be
|
||||
# caught.
|
||||
if len(set(d for d, p in drivesplits)) != 1:
|
||||
raise ValueError("Paths don't have the same drive")
|
||||
|
||||
drive, path = splitdrive(paths[0].replace(altsep, sep))
|
||||
common = path.split(sep)
|
||||
common = [c for c in common if c and c != curdir]
|
||||
|
||||
split_paths = [[c for c in s if c and c != curdir] for s in split_paths]
|
||||
s1 = min(split_paths)
|
||||
s2 = max(split_paths)
|
||||
for i, c in enumerate(s1):
|
||||
if c != s2[i]:
|
||||
common = common[:i]
|
||||
break
|
||||
else:
|
||||
common = common[:len(s1)]
|
||||
|
||||
prefix = drive + sep if isabs else drive
|
||||
return prefix + sep.join(common)
|
||||
except (TypeError, AttributeError):
|
||||
genericpath._check_arg_types('commonpath', *paths)
|
||||
raise
|
||||
|
||||
|
||||
# determine if two files are in fact the same file
|
||||
try:
|
||||
# GetFinalPathNameByHandle is available starting with Windows 6.0.
|
||||
# Windows XP and non-Windows OS'es will mock _getfinalpathname.
|
||||
if sys.getwindowsversion()[:2] >= (6, 0):
|
||||
from nt import _getfinalpathname
|
||||
else:
|
||||
raise ImportError
|
||||
except (AttributeError, ImportError):
|
||||
# On Windows XP and earlier, two files are the same if their absolute
|
||||
# pathnames are the same.
|
||||
# Non-Windows operating systems fake this method with an XP
|
||||
# approximation.
|
||||
def _getfinalpathname(f):
|
||||
return normcase(abspath(f))
|
||||
|
||||
|
||||
try:
|
||||
# The genericpath.isdir implementation uses os.stat and checks the mode
|
||||
# attribute to tell whether or not the path is a directory.
|
||||
# This is overkill on Windows - just pass the path to GetFileAttributes
|
||||
# and check the attribute from there.
|
||||
from nt import _isdir as isdir
|
||||
except ImportError:
|
||||
# Use genericpath.isdir as imported above.
|
||||
pass
|
||||
+1
-6
@@ -35,7 +35,7 @@ class Complex(Number):
|
||||
In short, those are: a conversion to complex, .real, .imag, +, -,
|
||||
*, /, abs(), .conjugate, ==, and !=.
|
||||
|
||||
If it is given heterogenous arguments, and doesn't have special
|
||||
If it is given heterogeneous arguments, and doesn't have special
|
||||
knowledge about them, it should fall back to the builtin complex
|
||||
type as described below.
|
||||
"""
|
||||
@@ -141,11 +141,6 @@ class Complex(Number):
|
||||
"""self == other"""
|
||||
raise NotImplementedError
|
||||
|
||||
def __ne__(self, other):
|
||||
"""self != other"""
|
||||
# The default __ne__ doesn't negate __eq__ until 3.0.
|
||||
return not (self == other)
|
||||
|
||||
Complex.register(complex)
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -92,8 +92,8 @@ This module exports the following functions:
|
||||
subn Same as sub, but also return the number of substitutions made.
|
||||
split Split a string by the occurrences of a pattern.
|
||||
findall Find all occurrences of a pattern in a string.
|
||||
finditer Return an iterator yielding a match object for each match.
|
||||
compile Compile a pattern into a RegexObject.
|
||||
finditer Return an iterator yielding a Match object for each match.
|
||||
compile Compile a pattern into a Pattern object.
|
||||
purge Clear the regular expression cache.
|
||||
escape Backslash all non-alphanumerics in a string.
|
||||
|
||||
@@ -119,30 +119,47 @@ This module also defines an exception 'error'.
|
||||
|
||||
"""
|
||||
|
||||
import sys
|
||||
import enum
|
||||
import sre_compile
|
||||
import sre_parse
|
||||
import functools
|
||||
try:
|
||||
import _locale
|
||||
except ImportError:
|
||||
_locale = None
|
||||
|
||||
|
||||
# public symbols
|
||||
__all__ = [ "match", "fullmatch", "search", "sub", "subn", "split", "findall",
|
||||
"compile", "purge", "template", "escape", "A", "I", "L", "M", "S", "X",
|
||||
"U", "ASCII", "IGNORECASE", "LOCALE", "MULTILINE", "DOTALL", "VERBOSE",
|
||||
"UNICODE", "error" ]
|
||||
__all__ = [
|
||||
"match", "fullmatch", "search", "sub", "subn", "split",
|
||||
"findall", "finditer", "compile", "purge", "template", "escape",
|
||||
"error", "Pattern", "Match", "A", "I", "L", "M", "S", "X", "U",
|
||||
"ASCII", "IGNORECASE", "LOCALE", "MULTILINE", "DOTALL", "VERBOSE",
|
||||
"UNICODE",
|
||||
]
|
||||
|
||||
__version__ = "2.2.1"
|
||||
|
||||
# flags
|
||||
A = ASCII = sre_compile.SRE_FLAG_ASCII # assume ascii "locale"
|
||||
I = IGNORECASE = sre_compile.SRE_FLAG_IGNORECASE # ignore case
|
||||
L = LOCALE = sre_compile.SRE_FLAG_LOCALE # assume current 8-bit locale
|
||||
U = UNICODE = sre_compile.SRE_FLAG_UNICODE # assume unicode "locale"
|
||||
M = MULTILINE = sre_compile.SRE_FLAG_MULTILINE # make anchors look for newline
|
||||
S = DOTALL = sre_compile.SRE_FLAG_DOTALL # make dot match newline
|
||||
X = VERBOSE = sre_compile.SRE_FLAG_VERBOSE # ignore whitespace and comments
|
||||
|
||||
# sre extensions (experimental, don't rely on these)
|
||||
T = TEMPLATE = sre_compile.SRE_FLAG_TEMPLATE # disable backtracking
|
||||
DEBUG = sre_compile.SRE_FLAG_DEBUG # dump pattern after compilation
|
||||
class RegexFlag(enum.IntFlag):
|
||||
ASCII = sre_compile.SRE_FLAG_ASCII # assume ascii "locale"
|
||||
IGNORECASE = sre_compile.SRE_FLAG_IGNORECASE # ignore case
|
||||
LOCALE = sre_compile.SRE_FLAG_LOCALE # assume current 8-bit locale
|
||||
UNICODE = sre_compile.SRE_FLAG_UNICODE # assume unicode "locale"
|
||||
MULTILINE = sre_compile.SRE_FLAG_MULTILINE # make anchors look for newline
|
||||
DOTALL = sre_compile.SRE_FLAG_DOTALL # make dot match newline
|
||||
VERBOSE = sre_compile.SRE_FLAG_VERBOSE # ignore whitespace and comments
|
||||
A = ASCII
|
||||
I = IGNORECASE
|
||||
L = LOCALE
|
||||
U = UNICODE
|
||||
M = MULTILINE
|
||||
S = DOTALL
|
||||
X = VERBOSE
|
||||
# sre extensions (experimental, don't rely on these)
|
||||
TEMPLATE = sre_compile.SRE_FLAG_TEMPLATE # disable backtracking
|
||||
T = TEMPLATE
|
||||
DEBUG = sre_compile.SRE_FLAG_DEBUG # dump pattern after compilation
|
||||
globals().update(RegexFlag.__members__)
|
||||
|
||||
# sre exception
|
||||
error = sre_compile.error
|
||||
@@ -152,17 +169,17 @@ error = sre_compile.error
|
||||
|
||||
def match(pattern, string, flags=0):
|
||||
"""Try to apply the pattern at the start of the string, returning
|
||||
a match object, or None if no match was found."""
|
||||
a Match object, or None if no match was found."""
|
||||
return _compile(pattern, flags).match(string)
|
||||
|
||||
def fullmatch(pattern, string, flags=0):
|
||||
"""Try to apply the pattern to all of the string, returning
|
||||
a match object, or None if no match was found."""
|
||||
a Match object, or None if no match was found."""
|
||||
return _compile(pattern, flags).fullmatch(string)
|
||||
|
||||
def search(pattern, string, flags=0):
|
||||
"""Scan through string looking for a match to the pattern, returning
|
||||
a match object, or None if no match was found."""
|
||||
a Match object, or None if no match was found."""
|
||||
return _compile(pattern, flags).search(string)
|
||||
|
||||
def sub(pattern, repl, string, count=0, flags=0):
|
||||
@@ -170,7 +187,7 @@ def sub(pattern, repl, string, count=0, flags=0):
|
||||
non-overlapping occurrences of the pattern in string by the
|
||||
replacement repl. repl can be either a string or a callable;
|
||||
if a string, backslash escapes in it are processed. If it is
|
||||
a callable, it's passed the match object and must return
|
||||
a callable, it's passed the Match object and must return
|
||||
a replacement string to be used."""
|
||||
return _compile(pattern, flags).sub(repl, string, count)
|
||||
|
||||
@@ -181,7 +198,7 @@ def subn(pattern, repl, string, count=0, flags=0):
|
||||
string by the replacement repl. number is the number of
|
||||
substitutions that were made. repl can be either a string or a
|
||||
callable; if a string, backslash escapes in it are processed.
|
||||
If it is a callable, it's passed the match object and must
|
||||
If it is a callable, it's passed the Match object and must
|
||||
return a replacement string to be used."""
|
||||
return _compile(pattern, flags).subn(repl, string, count)
|
||||
|
||||
@@ -205,112 +222,90 @@ def findall(pattern, string, flags=0):
|
||||
Empty matches are included in the result."""
|
||||
return _compile(pattern, flags).findall(string)
|
||||
|
||||
if sys.hexversion >= 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.
|
||||
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)
|
||||
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."
|
||||
"Compile a regular expression pattern, returning a Pattern object."
|
||||
return _compile(pattern, flags)
|
||||
|
||||
def purge():
|
||||
"Clear the regular expression caches"
|
||||
_cache.clear()
|
||||
_cache_repl.clear()
|
||||
_compile_repl.cache_clear()
|
||||
|
||||
def template(pattern, flags=0):
|
||||
"Compile a template pattern, returning a pattern object"
|
||||
"Compile a template pattern, returning a Pattern object"
|
||||
return _compile(pattern, flags|T)
|
||||
|
||||
_alphanum_str = frozenset(
|
||||
"_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890")
|
||||
_alphanum_bytes = frozenset(
|
||||
b"_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890")
|
||||
# SPECIAL_CHARS
|
||||
# closing ')', '}' and ']'
|
||||
# '-' (a range in character set)
|
||||
# '&', '~', (extended character set operations)
|
||||
# '#' (comment) and WHITESPACE (ignored) in verbose mode
|
||||
_special_chars_map = {i: '\\' + chr(i) for i in b'()[]{}?*+-|^$\\.&~# \t\n\r\v\f'}
|
||||
|
||||
def escape(pattern):
|
||||
"""
|
||||
Escape all the characters in pattern except ASCII letters, numbers and '_'.
|
||||
Escape special characters in a string.
|
||||
"""
|
||||
if isinstance(pattern, str):
|
||||
alphanum = _alphanum_str
|
||||
s = list(pattern)
|
||||
for i, c in enumerate(pattern):
|
||||
if c not in alphanum:
|
||||
if c == "\000":
|
||||
s[i] = "\\000"
|
||||
else:
|
||||
s[i] = "\\" + c
|
||||
return "".join(s)
|
||||
return pattern.translate(_special_chars_map)
|
||||
else:
|
||||
alphanum = _alphanum_bytes
|
||||
s = []
|
||||
esc = ord(b"\\")
|
||||
for c in pattern:
|
||||
if c in alphanum:
|
||||
s.append(c)
|
||||
else:
|
||||
if c == 0:
|
||||
s.extend(b"\\000")
|
||||
else:
|
||||
s.append(esc)
|
||||
s.append(c)
|
||||
return bytes(s)
|
||||
pattern = str(pattern, 'latin1')
|
||||
return pattern.translate(_special_chars_map).encode('latin1')
|
||||
|
||||
Pattern = type(sre_compile.compile('', 0))
|
||||
Match = type(sre_compile.compile('', 0).match(''))
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# internals
|
||||
|
||||
_cache = {}
|
||||
_cache_repl = {}
|
||||
|
||||
_pattern_type = type(sre_compile.compile("", 0))
|
||||
_cache = {} # ordered!
|
||||
|
||||
_MAXCACHE = 512
|
||||
def _compile(pattern, flags):
|
||||
# internal: compile pattern
|
||||
bypass_cache = flags & DEBUG
|
||||
if not bypass_cache:
|
||||
try:
|
||||
return _cache[type(pattern), pattern, flags]
|
||||
except KeyError:
|
||||
pass
|
||||
if isinstance(pattern, _pattern_type):
|
||||
if isinstance(flags, RegexFlag):
|
||||
flags = flags.value
|
||||
try:
|
||||
return _cache[type(pattern), pattern, flags]
|
||||
except KeyError:
|
||||
pass
|
||||
if isinstance(pattern, Pattern):
|
||||
if flags:
|
||||
raise ValueError(
|
||||
"Cannot process flags argument with a compiled pattern")
|
||||
"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")
|
||||
p = sre_compile.compile(pattern, flags)
|
||||
if not bypass_cache:
|
||||
if not (flags & DEBUG):
|
||||
if len(_cache) >= _MAXCACHE:
|
||||
_cache.clear()
|
||||
# Drop the oldest item
|
||||
try:
|
||||
del _cache[next(iter(_cache))]
|
||||
except (StopIteration, RuntimeError, KeyError):
|
||||
pass
|
||||
_cache[type(pattern), pattern, flags] = p
|
||||
return p
|
||||
|
||||
@functools.lru_cache(_MAXCACHE)
|
||||
def _compile_repl(repl, pattern):
|
||||
# internal: compile replacement pattern
|
||||
try:
|
||||
return _cache_repl[repl, pattern]
|
||||
except KeyError:
|
||||
pass
|
||||
p = sre_parse.parse_template(repl, pattern)
|
||||
if len(_cache_repl) >= _MAXCACHE:
|
||||
_cache_repl.clear()
|
||||
_cache_repl[repl, pattern] = p
|
||||
return p
|
||||
return sre_parse.parse_template(repl, pattern)
|
||||
|
||||
def _expand(pattern, match, template):
|
||||
# internal: match.expand implementation hook
|
||||
# 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
|
||||
# internal: Pattern.sub/subn implementation helper
|
||||
template = _compile_repl(template, pattern)
|
||||
if not template[0] and len(template[1]) == 1:
|
||||
# literal replacement
|
||||
@@ -326,7 +321,7 @@ import copyreg
|
||||
def _pickle(p):
|
||||
return _compile, (p.pattern, p.flags)
|
||||
|
||||
copyreg.pickle(_pattern_type, _pickle, _compile)
|
||||
copyreg.pickle(Pattern, _pickle, _compile)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# experimental stuff (see python-dev discussions for details)
|
||||
@@ -334,16 +329,19 @@ copyreg.pickle(_pattern_type, _pickle, _compile)
|
||||
class Scanner:
|
||||
def __init__(self, lexicon, flags=0):
|
||||
from sre_constants import BRANCH, SUBPATTERN
|
||||
if isinstance(flags, RegexFlag):
|
||||
flags = flags.value
|
||||
self.lexicon = lexicon
|
||||
# combine phrases into a compound pattern
|
||||
p = []
|
||||
s = sre_parse.Pattern()
|
||||
s.flags = flags
|
||||
for phrase, action in lexicon:
|
||||
gid = s.opengroup()
|
||||
p.append(sre_parse.SubPattern(s, [
|
||||
(SUBPATTERN, (len(p)+1, sre_parse.parse(phrase, flags))),
|
||||
(SUBPATTERN, (gid, 0, 0, sre_parse.parse(phrase, flags))),
|
||||
]))
|
||||
s.groups = len(p)+1
|
||||
s.closegroup(gid, p[-1])
|
||||
p = sre_parse.SubPattern(s, [(BRANCH, (None, p))])
|
||||
self.scanner = sre_compile.compile(p)
|
||||
def scan(self, string):
|
||||
@@ -351,7 +349,7 @@ class Scanner:
|
||||
append = result.append
|
||||
match = self.scanner.scanner(string).match
|
||||
i = 0
|
||||
while 1:
|
||||
while True:
|
||||
m = match()
|
||||
if not m:
|
||||
break
|
||||
+275
-145
@@ -1,7 +1,7 @@
|
||||
# encoding: utf-8
|
||||
# module _io calls itself io
|
||||
# from (built-in)
|
||||
# by generator 1.138
|
||||
# by generator 1.145
|
||||
"""
|
||||
The io module provides the Python interfaces to stream handling. The
|
||||
builtin open function is defined in this module.
|
||||
@@ -9,7 +9,7 @@ builtin open function is defined in this module.
|
||||
At the top of the I/O hierarchy is the abstract base class IOBase. It
|
||||
defines the basic interface to a stream. Note, however, that there is no
|
||||
separation between reading and writing to streams; implementations are
|
||||
allowed to raise an IOError if they do not support a given operation.
|
||||
allowed to raise an OSError if they do not support a given operation.
|
||||
|
||||
Extending IOBase is RawIOBase which deals simply with the reading and
|
||||
writing of raw bytes to a stream. FileIO subclasses RawIOBase to provide
|
||||
@@ -24,7 +24,7 @@ streams. BytesIO is a simple stream of in-memory bytes.
|
||||
Another IOBase subclass, TextIOBase, deals with the encoding and decoding
|
||||
of streams into text. TextIOWrapper, which extends it, is a buffered text
|
||||
interface to a buffered raw stream (`BufferedIOBase`). Finally, StringIO
|
||||
is a in-memory stream for text.
|
||||
is an in-memory stream for text.
|
||||
|
||||
Argument names are not part of the specification, and only the arguments
|
||||
of open() are intended to be used as keyword arguments.
|
||||
@@ -47,10 +47,7 @@ DEFAULT_BUFFER_SIZE = 8192
|
||||
|
||||
def open(name, mode=None, buffering=None): # known case of _io.open
|
||||
"""
|
||||
open(file, mode='r', buffering=-1, encoding=None,
|
||||
errors=None, newline=None, closefd=True, opener=None) -> file object
|
||||
|
||||
Open file and return a stream. Raise IOError upon failure.
|
||||
Open file and return a stream. Raise OSError upon failure.
|
||||
|
||||
file is either a text or byte string giving the name (and the path
|
||||
if the file isn't in the current working directory) of the file to
|
||||
@@ -195,8 +192,9 @@ class _IOBase(object):
|
||||
called.
|
||||
|
||||
The basic type used for binary data read from or written to a file is
|
||||
bytes. bytearrays are accepted too, and in some cases (such as
|
||||
readinto) needed. Text I/O classes work with str data.
|
||||
bytes. Other bytes-like objects are accepted as method arguments too.
|
||||
In some cases (such as readinto), a writable object is required. Text
|
||||
I/O classes work with str data.
|
||||
|
||||
Note that calling any method (except additional calls to close(),
|
||||
which are ignored) on a closed stream should raise a ValueError.
|
||||
@@ -223,7 +221,7 @@ class _IOBase(object):
|
||||
"""
|
||||
Returns underlying file descriptor if one exists.
|
||||
|
||||
An IOError is raised if the IO object does not use a file descriptor.
|
||||
OSError is raised if the IO object does not use a file descriptor.
|
||||
"""
|
||||
pass
|
||||
|
||||
@@ -247,7 +245,7 @@ class _IOBase(object):
|
||||
"""
|
||||
Return whether object was opened for reading.
|
||||
|
||||
If False, read() will raise UnsupportedOperation.
|
||||
If False, read() will raise OSError.
|
||||
"""
|
||||
pass
|
||||
|
||||
@@ -255,7 +253,7 @@ class _IOBase(object):
|
||||
"""
|
||||
Read and return a line from the stream.
|
||||
|
||||
If limit is specified, at most limit bytes will be read.
|
||||
If size is specified, at most size bytes will be read.
|
||||
|
||||
The line terminator is always b'\n' for binary files; for text
|
||||
files, the newlines argument to open can be used to select the line
|
||||
@@ -293,7 +291,7 @@ class _IOBase(object):
|
||||
"""
|
||||
Return whether object supports random access.
|
||||
|
||||
If False, seek(), tell() and truncate() will raise UnsupportedOperation.
|
||||
If False, seek(), tell() and truncate() will raise OSError.
|
||||
This method may need to do a test seek().
|
||||
"""
|
||||
pass
|
||||
@@ -315,7 +313,7 @@ class _IOBase(object):
|
||||
"""
|
||||
Return whether object was opened for writing.
|
||||
|
||||
If False, write() will raise UnsupportedOperation.
|
||||
If False, write() will raise OSError.
|
||||
"""
|
||||
pass
|
||||
|
||||
@@ -335,7 +333,6 @@ class _IOBase(object):
|
||||
pass
|
||||
|
||||
def __del__(self, *args, **kwargs): # real signature unknown
|
||||
""" """
|
||||
pass
|
||||
|
||||
def __enter__(self, *args, **kwargs): # real signature unknown
|
||||
@@ -425,12 +422,15 @@ class _BufferedIOBase(_IOBase):
|
||||
def readinto(self, *args, **kwargs): # real signature unknown
|
||||
pass
|
||||
|
||||
def readinto1(self, *args, **kwargs): # real signature unknown
|
||||
pass
|
||||
|
||||
def write(self, *args, **kwargs): # real signature unknown
|
||||
"""
|
||||
Write the given buffer to the IO stream.
|
||||
|
||||
Returns the number of bytes written, which is never less than
|
||||
len(b).
|
||||
Returns the number of bytes written, which is always the length of b
|
||||
in bytes.
|
||||
|
||||
Raises BlockingIOError if the buffer is full and the
|
||||
underlying raw stream cannot accept more data at the moment.
|
||||
@@ -479,6 +479,9 @@ class BufferedRandom(_BufferedIOBase):
|
||||
def readinto(self, *args, **kwargs): # real signature unknown
|
||||
pass
|
||||
|
||||
def readinto1(self, *args, **kwargs): # real signature unknown
|
||||
pass
|
||||
|
||||
def readline(self, *args, **kwargs): # real signature unknown
|
||||
pass
|
||||
|
||||
@@ -569,6 +572,9 @@ class BufferedReader(_BufferedIOBase):
|
||||
def readinto(self, *args, **kwargs): # real signature unknown
|
||||
pass
|
||||
|
||||
def readinto1(self, *args, **kwargs): # real signature unknown
|
||||
pass
|
||||
|
||||
def readline(self, *args, **kwargs): # real signature unknown
|
||||
pass
|
||||
|
||||
@@ -584,9 +590,6 @@ class BufferedReader(_BufferedIOBase):
|
||||
def truncate(self, *args, **kwargs): # real signature unknown
|
||||
pass
|
||||
|
||||
def writable(self, *args, **kwargs): # real signature unknown
|
||||
pass
|
||||
|
||||
def _dealloc_warn(self, *args, **kwargs): # real signature unknown
|
||||
pass
|
||||
|
||||
@@ -660,6 +663,9 @@ class BufferedRWPair(_BufferedIOBase):
|
||||
def readinto(self, *args, **kwargs): # real signature unknown
|
||||
pass
|
||||
|
||||
def readinto1(self, *args, **kwargs): # real signature unknown
|
||||
pass
|
||||
|
||||
def writable(self, *args, **kwargs): # real signature unknown
|
||||
pass
|
||||
|
||||
@@ -704,9 +710,6 @@ class BufferedWriter(_BufferedIOBase):
|
||||
def isatty(self, *args, **kwargs): # real signature unknown
|
||||
pass
|
||||
|
||||
def readable(self, *args, **kwargs): # real signature unknown
|
||||
pass
|
||||
|
||||
def seek(self, *args, **kwargs): # real signature unknown
|
||||
pass
|
||||
|
||||
@@ -759,99 +762,85 @@ class BufferedWriter(_BufferedIOBase):
|
||||
|
||||
|
||||
class BytesIO(_BufferedIOBase):
|
||||
"""
|
||||
BytesIO([buffer]) -> object
|
||||
|
||||
Create a buffered I/O implementation using an in-memory bytes
|
||||
buffer, ready for reading and writing.
|
||||
"""
|
||||
def close(self): # real signature unknown; restored from __doc__
|
||||
""" close() -> None. Disable all I/O operations. """
|
||||
""" Buffered I/O implementation using an in-memory bytes buffer. """
|
||||
def close(self, *args, **kwargs): # real signature unknown
|
||||
""" Disable all I/O operations. """
|
||||
pass
|
||||
|
||||
def flush(self): # real signature unknown; restored from __doc__
|
||||
""" flush() -> None. Does nothing. """
|
||||
def flush(self, *args, **kwargs): # real signature unknown
|
||||
""" Does nothing. """
|
||||
pass
|
||||
|
||||
def getbuffer(self): # real signature unknown; restored from __doc__
|
||||
def getbuffer(self, *args, **kwargs): # real signature unknown
|
||||
""" Get a read-write view over the contents of the BytesIO object. """
|
||||
pass
|
||||
|
||||
def getvalue(self, *args, **kwargs): # real signature unknown
|
||||
""" Retrieve the entire contents of the BytesIO object. """
|
||||
pass
|
||||
|
||||
def isatty(self, *args, **kwargs): # real signature unknown
|
||||
"""
|
||||
getbuffer() -> bytes.
|
||||
Always returns False.
|
||||
|
||||
Get a read-write view over the contents of the BytesIO object.
|
||||
BytesIO objects are not connected to a TTY-like device.
|
||||
"""
|
||||
pass
|
||||
|
||||
def getvalue(self): # real signature unknown; restored from __doc__
|
||||
def read(self, *args, **kwargs): # real signature unknown
|
||||
"""
|
||||
getvalue() -> bytes.
|
||||
|
||||
Retrieve the entire contents of the BytesIO object.
|
||||
"""
|
||||
pass
|
||||
|
||||
def isatty(self): # real signature unknown; restored from __doc__
|
||||
"""
|
||||
isatty() -> False.
|
||||
|
||||
Always returns False since BytesIO objects are not connected
|
||||
to a tty-like device.
|
||||
"""
|
||||
pass
|
||||
|
||||
def read(self, size=None): # real signature unknown; restored from __doc__
|
||||
"""
|
||||
read([size]) -> read at most size bytes, returned as a string.
|
||||
Read at most size bytes, returned as a bytes object.
|
||||
|
||||
If the size argument is negative, read until EOF is reached.
|
||||
Return an empty string at EOF.
|
||||
Return an empty bytes object at EOF.
|
||||
"""
|
||||
pass
|
||||
|
||||
def read1(self, size): # real signature unknown; restored from __doc__
|
||||
def read1(self, *args, **kwargs): # real signature unknown
|
||||
"""
|
||||
read1(size) -> read at most size bytes, returned as a string.
|
||||
Read at most size bytes, returned as a bytes object.
|
||||
|
||||
If the size argument is negative or omitted, read until EOF is reached.
|
||||
Return an empty string at EOF.
|
||||
Return an empty bytes object at EOF.
|
||||
"""
|
||||
pass
|
||||
|
||||
def readable(self): # real signature unknown; restored from __doc__
|
||||
""" readable() -> bool. Returns True if the IO object can be read. """
|
||||
def readable(self, *args, **kwargs): # real signature unknown
|
||||
""" Returns True if the IO object can be read. """
|
||||
pass
|
||||
|
||||
def readinto(self, bytearray): # real signature unknown; restored from __doc__
|
||||
def readinto(self, *args, **kwargs): # real signature unknown
|
||||
"""
|
||||
readinto(bytearray) -> int. Read up to len(b) bytes into b.
|
||||
Read bytes into buffer.
|
||||
|
||||
Returns number of bytes read (0 for EOF), or None if the object
|
||||
is set not to block as has no data to read.
|
||||
is set not to block and has no data to read.
|
||||
"""
|
||||
pass
|
||||
|
||||
def readline(self, size=None): # real signature unknown; restored from __doc__
|
||||
def readline(self, *args, **kwargs): # real signature unknown
|
||||
"""
|
||||
readline([size]) -> next line from the file, as a string.
|
||||
Next line from the file, as a bytes object.
|
||||
|
||||
Retain newline. A non-negative size argument limits the maximum
|
||||
number of bytes to return (an incomplete line may be returned then).
|
||||
Return an empty string at EOF.
|
||||
Return an empty bytes object at EOF.
|
||||
"""
|
||||
pass
|
||||
|
||||
def readlines(self, size=None): # real signature unknown; restored from __doc__
|
||||
def readlines(self, *args, **kwargs): # real signature unknown
|
||||
"""
|
||||
readlines([size]) -> list of strings, each a line from the file.
|
||||
List of bytes objects, each a line from the file.
|
||||
|
||||
Call readline() repeatedly and return a list of the lines so read.
|
||||
The optional size argument, if given, is an approximate bound on the
|
||||
total number of bytes in the lines returned.
|
||||
"""
|
||||
return []
|
||||
pass
|
||||
|
||||
def seek(self, pos, whence=0): # real signature unknown; restored from __doc__
|
||||
def seek(self, *args, **kwargs): # real signature unknown
|
||||
"""
|
||||
seek(pos, whence=0) -> int. Change stream position.
|
||||
Change stream position.
|
||||
|
||||
Seek to byte offset pos relative to position indicated by whence:
|
||||
0 Start of stream (the default). pos should be >= 0;
|
||||
@@ -861,49 +850,49 @@ class BytesIO(_BufferedIOBase):
|
||||
"""
|
||||
pass
|
||||
|
||||
def seekable(self): # real signature unknown; restored from __doc__
|
||||
""" seekable() -> bool. Returns True if the IO object can be seeked. """
|
||||
def seekable(self, *args, **kwargs): # real signature unknown
|
||||
""" Returns True if the IO object can be seeked. """
|
||||
pass
|
||||
|
||||
def tell(self): # real signature unknown; restored from __doc__
|
||||
""" tell() -> current file position, an integer """
|
||||
def tell(self, *args, **kwargs): # real signature unknown
|
||||
""" Current file position, an integer. """
|
||||
pass
|
||||
|
||||
def truncate(self, size=None): # real signature unknown; restored from __doc__
|
||||
def truncate(self, *args, **kwargs): # real signature unknown
|
||||
"""
|
||||
truncate([size]) -> int. Truncate the file to at most size bytes.
|
||||
Truncate the file to at most size bytes.
|
||||
|
||||
Size defaults to the current file position, as returned by tell().
|
||||
The current file position is unchanged. Returns the new size.
|
||||
"""
|
||||
pass
|
||||
|
||||
def writable(self): # real signature unknown; restored from __doc__
|
||||
""" writable() -> bool. Returns True if the IO object can be written. """
|
||||
def writable(self, *args, **kwargs): # real signature unknown
|
||||
""" Returns True if the IO object can be written. """
|
||||
pass
|
||||
|
||||
def write(self, bytes): # real signature unknown; restored from __doc__
|
||||
def write(self, *args, **kwargs): # real signature unknown
|
||||
"""
|
||||
write(bytes) -> int. Write bytes to file.
|
||||
Write bytes to file.
|
||||
|
||||
Return the number of bytes written.
|
||||
"""
|
||||
pass
|
||||
|
||||
def writelines(self, sequence_of_strings): # real signature unknown; restored from __doc__
|
||||
def writelines(self, *args, **kwargs): # real signature unknown
|
||||
"""
|
||||
writelines(sequence_of_strings) -> None. Write strings to the file.
|
||||
Write lines to the file.
|
||||
|
||||
Note that newlines are not added. The sequence can be any iterable
|
||||
object producing strings. This is equivalent to calling write() for
|
||||
each string.
|
||||
Note that newlines are not added. lines can be any iterable object
|
||||
producing bytes-like objects. This is equivalent to calling write() for
|
||||
each element.
|
||||
"""
|
||||
pass
|
||||
|
||||
def __getstate__(self, *args, **kwargs): # real signature unknown
|
||||
pass
|
||||
|
||||
def __init__(self, buffer=None): # real signature unknown; restored from __doc__
|
||||
def __init__(self, *args, **kwargs): # real signature unknown
|
||||
pass
|
||||
|
||||
def __iter__(self, *args, **kwargs): # real signature unknown
|
||||
@@ -939,18 +928,24 @@ class _RawIOBase(_IOBase):
|
||||
""" Read until EOF, using multiple read() call. """
|
||||
pass
|
||||
|
||||
def readinto(self, *args, **kwargs): # real signature unknown
|
||||
pass
|
||||
|
||||
def write(self, *args, **kwargs): # real signature unknown
|
||||
pass
|
||||
|
||||
def __init__(self, *args, **kwargs): # real signature unknown
|
||||
pass
|
||||
|
||||
|
||||
class FileIO(_RawIOBase):
|
||||
"""
|
||||
file(name: str[, mode: str][, opener: None]) -> file IO object
|
||||
Open a file.
|
||||
|
||||
Open a file. The mode can be 'r', 'w', 'x' or 'a' for reading (default),
|
||||
The mode can be 'r' (default), 'w', 'x' or 'a' for reading,
|
||||
writing, exclusive creation or appending. The file will be created if it
|
||||
doesn't exist when opened for writing or appending; it will be truncated
|
||||
when opened for writing. A `FileExistsError` will be raised if it already
|
||||
when opened for writing. A FileExistsError will be raised if it already
|
||||
exists when opened for creating. Opening a file for creating implies
|
||||
writing so this mode behaves in a similar way to 'w'.Add a '+' to the mode
|
||||
to allow simultaneous reading and writing. A custom opener can be used by
|
||||
@@ -961,91 +956,94 @@ class FileIO(_RawIOBase):
|
||||
"""
|
||||
def close(self): # real signature unknown; restored from __doc__
|
||||
"""
|
||||
close() -> None. Close the file.
|
||||
Close the file.
|
||||
|
||||
A closed file cannot be used for further I/O operations. close() may be
|
||||
called more than once without error. Changes the fileno to -1.
|
||||
called more than once without error.
|
||||
"""
|
||||
pass
|
||||
|
||||
def fileno(self): # real signature unknown; restored from __doc__
|
||||
"""
|
||||
fileno() -> int. "file descriptor".
|
||||
|
||||
This is needed for lower-level file interfaces, such the fcntl module.
|
||||
"""
|
||||
def fileno(self, *args, **kwargs): # real signature unknown
|
||||
""" Return the underlying file descriptor (an integer). """
|
||||
pass
|
||||
|
||||
def isatty(self): # real signature unknown; restored from __doc__
|
||||
""" isatty() -> bool. True if the file is connected to a tty device. """
|
||||
def isatty(self, *args, **kwargs): # real signature unknown
|
||||
""" True if the file is connected to a TTY device. """
|
||||
pass
|
||||
|
||||
def read(self, size=-1): # known case of _io.FileIO.read
|
||||
"""
|
||||
read(size: int) -> bytes. read at most size bytes, returned as bytes.
|
||||
Read at most size bytes, returned as bytes.
|
||||
|
||||
Only makes one system call, so less data may be returned than requested
|
||||
Only makes one system call, so less data may be returned than requested.
|
||||
In non-blocking mode, returns None if no data is available.
|
||||
On end-of-file, returns ''.
|
||||
Return an empty bytes object at EOF.
|
||||
"""
|
||||
return ""
|
||||
|
||||
def readable(self): # real signature unknown; restored from __doc__
|
||||
""" readable() -> bool. True if file was opened in a read mode. """
|
||||
def readable(self, *args, **kwargs): # real signature unknown
|
||||
""" True if file was opened in a read mode. """
|
||||
pass
|
||||
|
||||
def readall(self): # real signature unknown; restored from __doc__
|
||||
def readall(self, *args, **kwargs): # real signature unknown
|
||||
"""
|
||||
readall() -> bytes. read all data from the file, returned as bytes.
|
||||
Read all data from the file, returned as bytes.
|
||||
|
||||
In non-blocking mode, returns as much as is immediately available,
|
||||
or None if no data is available. On end-of-file, returns ''.
|
||||
or None if no data is available. Return an empty bytes object at EOF.
|
||||
"""
|
||||
pass
|
||||
|
||||
def readinto(self): # real signature unknown; restored from __doc__
|
||||
""" readinto() -> Same as RawIOBase.readinto(). """
|
||||
""" Same as RawIOBase.readinto(). """
|
||||
pass
|
||||
|
||||
def seek(self, offset, whence=None): # real signature unknown; restored from __doc__
|
||||
def seek(self, *args, **kwargs): # real signature unknown
|
||||
"""
|
||||
seek(offset: int[, whence: int]) -> None. Move to new file position.
|
||||
Move to new file position and return the file position.
|
||||
|
||||
Argument offset is a byte count. Optional argument whence defaults to
|
||||
0 (offset from start of file, offset should be >= 0); other values are 1
|
||||
(move relative to current position, positive or negative), and 2 (move
|
||||
relative to end of file, usually negative, although many platforms allow
|
||||
seeking beyond the end of a file).
|
||||
SEEK_SET or 0 (offset from start of file, offset should be >= 0); other values
|
||||
are SEEK_CUR or 1 (move relative to current position, positive or negative),
|
||||
and SEEK_END or 2 (move relative to end of file, usually negative, although
|
||||
many platforms allow seeking beyond the end of a file).
|
||||
|
||||
Note that not all file objects are seekable.
|
||||
"""
|
||||
pass
|
||||
|
||||
def seekable(self): # real signature unknown; restored from __doc__
|
||||
""" seekable() -> bool. True if file supports random-access. """
|
||||
def seekable(self, *args, **kwargs): # real signature unknown
|
||||
""" True if file supports random-access. """
|
||||
pass
|
||||
|
||||
def tell(self): # real signature unknown; restored from __doc__
|
||||
""" tell() -> int. Current file position """
|
||||
pass
|
||||
|
||||
def truncate(self, size=None): # real signature unknown; restored from __doc__
|
||||
def tell(self, *args, **kwargs): # real signature unknown
|
||||
"""
|
||||
truncate([size: int]) -> None. Truncate the file to at most size bytes.
|
||||
Current file position.
|
||||
|
||||
Size defaults to the current file position, as returned by tell().The current file position is changed to the value of size.
|
||||
Can raise OSError for non seekable files.
|
||||
"""
|
||||
pass
|
||||
|
||||
def writable(self): # real signature unknown; restored from __doc__
|
||||
""" writable() -> bool. True if file was opened in a write mode. """
|
||||
def truncate(self, *args, **kwargs): # real signature unknown
|
||||
"""
|
||||
Truncate the file to at most size bytes and return the truncated size.
|
||||
|
||||
Size defaults to the current file position, as returned by tell().
|
||||
The current file position is changed to the value of size.
|
||||
"""
|
||||
pass
|
||||
|
||||
def write(self, b): # real signature unknown; restored from __doc__
|
||||
def writable(self, *args, **kwargs): # real signature unknown
|
||||
""" True if file was opened in a write mode. """
|
||||
pass
|
||||
|
||||
def write(self, *args, **kwargs): # real signature unknown
|
||||
"""
|
||||
write(b: bytes) -> int. Write bytes b to file, return number written.
|
||||
Write buffer b to file, return number of bytes written.
|
||||
|
||||
Only makes one system call, so not all of the data may be written.
|
||||
The number of bytes actually written is returned.
|
||||
The number of bytes actually written is returned. In non-blocking mode,
|
||||
returns None if the write would block.
|
||||
"""
|
||||
pass
|
||||
|
||||
@@ -1075,20 +1073,23 @@ class FileIO(_RawIOBase):
|
||||
"""True if the file is closed"""
|
||||
|
||||
closefd = property(lambda self: object(), lambda self, v: None, lambda self: None) # default
|
||||
"""True if the file descriptor will be closed"""
|
||||
"""True if the file descriptor will be closed by close()."""
|
||||
|
||||
mode = property(lambda self: object(), lambda self, v: None, lambda self: None) # default
|
||||
"""String giving the file mode"""
|
||||
|
||||
_blksize = property(lambda self: object(), lambda self, v: None, lambda self: None) # default
|
||||
|
||||
_finalizing = property(lambda self: object(), lambda self, v: None, lambda self: None) # default
|
||||
|
||||
|
||||
|
||||
class IncrementalNewlineDecoder(object):
|
||||
"""
|
||||
Codec used when reading a file in universal newlines mode. It wraps
|
||||
another incremental decoder, translating \r\n and \r into \n. It also
|
||||
records the types of newlines encountered. When used with
|
||||
Codec used when reading a file in universal newlines mode.
|
||||
|
||||
It wraps another incremental decoder, translating \r\n and \r into \n.
|
||||
It also records the types of newlines encountered. When used with
|
||||
translate=False, it ensures that the newline sequence is returned in
|
||||
one piece. When used with decoder=None, it expects unicode strings as
|
||||
decode input and translates newlines without first invoking an external
|
||||
@@ -1194,8 +1195,10 @@ class StringIO(_TextIOBase):
|
||||
"""
|
||||
def close(self, *args, **kwargs): # real signature unknown
|
||||
"""
|
||||
Close the IO object. Attempting any further operation after the
|
||||
object is closed will raise a ValueError.
|
||||
Close the IO object.
|
||||
|
||||
Attempting any further operation after the object is closed
|
||||
will raise a ValueError.
|
||||
|
||||
This method has no effect if the file is already closed.
|
||||
"""
|
||||
@@ -1207,15 +1210,15 @@ class StringIO(_TextIOBase):
|
||||
|
||||
def read(self, *args, **kwargs): # real signature unknown
|
||||
"""
|
||||
Read at most n characters, returned as a string.
|
||||
Read at most size characters, returned as a string.
|
||||
|
||||
If the argument is negative or omitted, read until EOF
|
||||
is reached. Return an empty string at EOF.
|
||||
"""
|
||||
pass
|
||||
|
||||
def readable(self): # real signature unknown; restored from __doc__
|
||||
""" readable() -> bool. Returns True if the IO object can be read. """
|
||||
def readable(self, *args, **kwargs): # real signature unknown
|
||||
""" Returns True if the IO object can be read. """
|
||||
pass
|
||||
|
||||
def readline(self, *args, **kwargs): # real signature unknown
|
||||
@@ -1238,8 +1241,8 @@ class StringIO(_TextIOBase):
|
||||
"""
|
||||
pass
|
||||
|
||||
def seekable(self): # real signature unknown; restored from __doc__
|
||||
""" seekable() -> bool. Returns True if the IO object can be seeked. """
|
||||
def seekable(self, *args, **kwargs): # real signature unknown
|
||||
""" Returns True if the IO object can be seeked. """
|
||||
pass
|
||||
|
||||
def tell(self, *args, **kwargs): # real signature unknown
|
||||
@@ -1256,8 +1259,8 @@ class StringIO(_TextIOBase):
|
||||
"""
|
||||
pass
|
||||
|
||||
def writable(self): # real signature unknown; restored from __doc__
|
||||
""" writable() -> bool. Returns True if the IO object can be written. """
|
||||
def writable(self, *args, **kwargs): # real signature unknown
|
||||
""" Returns True if the IO object can be written. """
|
||||
pass
|
||||
|
||||
def write(self, *args, **kwargs): # real signature unknown
|
||||
@@ -1350,6 +1353,14 @@ class TextIOWrapper(_TextIOBase):
|
||||
def readline(self, *args, **kwargs): # real signature unknown
|
||||
pass
|
||||
|
||||
def reconfigure(self, *args, **kwargs): # real signature unknown
|
||||
"""
|
||||
Reconfigure the text stream with new parameters.
|
||||
|
||||
This also does an implicit stream flush.
|
||||
"""
|
||||
pass
|
||||
|
||||
def seek(self, *args, **kwargs): # real signature unknown
|
||||
pass
|
||||
|
||||
@@ -1401,13 +1412,15 @@ class TextIOWrapper(_TextIOBase):
|
||||
|
||||
newlines = property(lambda self: object(), lambda self, v: None, lambda self: None) # default
|
||||
|
||||
write_through = property(lambda self: object(), lambda self, v: None, lambda self: None) # default
|
||||
|
||||
_CHUNK_SIZE = property(lambda self: object(), lambda self, v: None, lambda self: None) # default
|
||||
|
||||
_finalizing = property(lambda self: object(), lambda self, v: None, lambda self: None) # default
|
||||
|
||||
|
||||
|
||||
class UnsupportedOperation(ValueError, OSError):
|
||||
class UnsupportedOperation(OSError, ValueError):
|
||||
# no doc
|
||||
def __init__(self, *args, **kwargs): # real signature unknown
|
||||
pass
|
||||
@@ -1417,6 +1430,109 @@ class UnsupportedOperation(ValueError, OSError):
|
||||
|
||||
|
||||
|
||||
class _WindowsConsoleIO(_RawIOBase):
|
||||
"""
|
||||
Open a console buffer by file descriptor.
|
||||
|
||||
The mode can be 'rb' (default), or 'wb' for reading or writing bytes. All
|
||||
other mode characters will be ignored. Mode 'b' will be assumed if it is
|
||||
omitted. The *opener* parameter is always ignored.
|
||||
"""
|
||||
def close(self): # real signature unknown; restored from __doc__
|
||||
"""
|
||||
Close the handle.
|
||||
|
||||
A closed handle cannot be used for further I/O operations. close() may be
|
||||
called more than once without error.
|
||||
"""
|
||||
pass
|
||||
|
||||
def fileno(self, *args, **kwargs): # real signature unknown
|
||||
"""
|
||||
Return the underlying file descriptor (an integer).
|
||||
|
||||
fileno is only set when a file descriptor is used to open
|
||||
one of the standard streams.
|
||||
"""
|
||||
pass
|
||||
|
||||
def isatty(self, *args, **kwargs): # real signature unknown
|
||||
""" Always True. """
|
||||
pass
|
||||
|
||||
def read(self, *args, **kwargs): # real signature unknown
|
||||
"""
|
||||
Read at most size bytes, returned as bytes.
|
||||
|
||||
Only makes one system call when size is a positive integer,
|
||||
so less data may be returned than requested.
|
||||
Return an empty bytes object at EOF.
|
||||
"""
|
||||
pass
|
||||
|
||||
def readable(self, *args, **kwargs): # real signature unknown
|
||||
""" True if console is an input buffer. """
|
||||
pass
|
||||
|
||||
def readall(self, *args, **kwargs): # real signature unknown
|
||||
"""
|
||||
Read all data from the console, returned as bytes.
|
||||
|
||||
Return an empty bytes object at EOF.
|
||||
"""
|
||||
pass
|
||||
|
||||
def readinto(self): # real signature unknown; restored from __doc__
|
||||
""" Same as RawIOBase.readinto(). """
|
||||
pass
|
||||
|
||||
def writable(self, *args, **kwargs): # real signature unknown
|
||||
""" True if console is an output buffer. """
|
||||
pass
|
||||
|
||||
def write(self, *args, **kwargs): # real signature unknown
|
||||
"""
|
||||
Write buffer b to file, return number of bytes written.
|
||||
|
||||
Only makes one system call, so not all of the data may be written.
|
||||
The number of bytes actually written is returned.
|
||||
"""
|
||||
pass
|
||||
|
||||
def __getattribute__(self, *args, **kwargs): # real signature unknown
|
||||
""" Return getattr(self, name). """
|
||||
pass
|
||||
|
||||
def __getstate__(self, *args, **kwargs): # real signature unknown
|
||||
pass
|
||||
|
||||
def __init__(self, *args, **kwargs): # real signature unknown
|
||||
pass
|
||||
|
||||
@staticmethod # known case of __new__
|
||||
def __new__(*args, **kwargs): # real signature unknown
|
||||
""" Create and return a new object. See help(type) for accurate signature. """
|
||||
pass
|
||||
|
||||
def __repr__(self, *args, **kwargs): # real signature unknown
|
||||
""" Return repr(self). """
|
||||
pass
|
||||
|
||||
closed = property(lambda self: object(), lambda self, v: None, lambda self: None) # default
|
||||
"""True if the file is closed"""
|
||||
|
||||
closefd = property(lambda self: object(), lambda self, v: None, lambda self: None) # default
|
||||
"""True if the file descriptor will be closed by close()."""
|
||||
|
||||
mode = property(lambda self: object(), lambda self, v: None, lambda self: None) # default
|
||||
"""String giving the file mode"""
|
||||
|
||||
_blksize = property(lambda self: object(), lambda self, v: None, lambda self: None) # default
|
||||
|
||||
_finalizing = property(lambda self: object(), lambda self, v: None, lambda self: None) # default
|
||||
|
||||
|
||||
|
||||
class __loader__(object):
|
||||
"""
|
||||
Meta path import for built-in modules.
|
||||
@@ -1424,6 +1540,16 @@ class __loader__(object):
|
||||
All methods are either class or static methods to avoid the need to
|
||||
instantiate the class.
|
||||
"""
|
||||
@classmethod
|
||||
def create_module(cls, *args, **kwargs): # real signature unknown
|
||||
""" Create a built-in module """
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def exec_module(cls, *args, **kwargs): # real signature unknown
|
||||
""" Exec a built-in module """
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def find_module(cls, *args, **kwargs): # real signature unknown
|
||||
"""
|
||||
@@ -1456,7 +1582,11 @@ class __loader__(object):
|
||||
|
||||
@classmethod
|
||||
def load_module(cls, *args, **kwargs): # real signature unknown
|
||||
""" Load a built-in module. """
|
||||
"""
|
||||
Load the specified module into sys.modules and return it.
|
||||
|
||||
This method is deprecated. Use loader.exec_module instead.
|
||||
"""
|
||||
pass
|
||||
|
||||
def module_repr(module): # reliably restored by inspect
|
||||
+579
-503
File diff suppressed because it is too large
Load Diff
+154
-50
@@ -1,7 +1,7 @@
|
||||
# encoding: utf-8
|
||||
# module sys
|
||||
# from (built-in)
|
||||
# by generator 1.138
|
||||
# by generator 1.145
|
||||
"""
|
||||
This module provides access to some objects used or maintained by the
|
||||
interpreter and to functions that interact strongly with the interpreter.
|
||||
@@ -42,12 +42,15 @@ hexversion -- version information encoded as a single integer
|
||||
implementation -- Python implementation information.
|
||||
int_info -- a struct sequence with information about the int implementation.
|
||||
maxsize -- the largest supported length of containers.
|
||||
maxunicode -- the value of the largest Unicode codepoint
|
||||
maxunicode -- the value of the largest Unicode code point
|
||||
platform -- platform identifier
|
||||
prefix -- prefix used to find the Python library
|
||||
thread_info -- a struct sequence with information about the thread implementation.
|
||||
version -- the version of this interpreter as a string
|
||||
version_info -- version information as a named tuple
|
||||
dllhandle -- [Windows only] integer handle of the Python DLL
|
||||
winver -- [Windows only] version number of the Python DLL
|
||||
_enablelegacywindowsfsencoding -- [Windows only]
|
||||
__stdin__ -- the original stdin; don't touch!
|
||||
__stdout__ -- the original stdout; don't touch!
|
||||
__stderr__ -- the original stderr; don't touch!
|
||||
@@ -76,44 +79,53 @@ settrace() -- set the global debug tracing function
|
||||
|
||||
# Variables with simple values
|
||||
|
||||
abiflags = 'm'
|
||||
|
||||
api_version = 1013
|
||||
|
||||
base_exec_prefix = '/Library/Frameworks/Python.framework/Versions/3.4'
|
||||
base_exec_prefix = 'C:\\Python37'
|
||||
|
||||
base_prefix = '/Library/Frameworks/Python.framework/Versions/3.4'
|
||||
base_prefix = 'C:\\Python37'
|
||||
|
||||
byteorder = 'little'
|
||||
|
||||
copyright = 'Copyright (c) 2001-2014 Python Software Foundation.\nAll Rights Reserved.\n\nCopyright (c) 2000 BeOpen.com.\nAll Rights Reserved.\n\nCopyright (c) 1995-2001 Corporation for National Research Initiatives.\nAll Rights Reserved.\n\nCopyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam.\nAll Rights Reserved.'
|
||||
copyright = 'Copyright (c) 2001-2018 Python Software Foundation.\nAll Rights Reserved.\n\nCopyright (c) 2000 BeOpen.com.\nAll Rights Reserved.\n\nCopyright (c) 1995-2001 Corporation for National Research Initiatives.\nAll Rights Reserved.\n\nCopyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam.\nAll Rights Reserved.'
|
||||
|
||||
dllhandle = 140705079492608
|
||||
|
||||
dont_write_bytecode = True
|
||||
|
||||
executable = '/Users/vlan/.virtualenvs/obraz-py3.4/bin/python'
|
||||
executable = 'C:\\Python37\\python.exe'
|
||||
|
||||
exec_prefix = '/Users/vlan/.virtualenvs/obraz-py3.4'
|
||||
exec_prefix = 'C:\\Python37'
|
||||
|
||||
float_repr_style = 'short'
|
||||
|
||||
hexversion = 50594544
|
||||
hexversion = 50790896
|
||||
|
||||
maxsize = 9223372036854775807
|
||||
maxunicode = 1114111
|
||||
|
||||
platform = 'darwin'
|
||||
platform = 'win32'
|
||||
|
||||
prefix = '/Users/vlan/.virtualenvs/obraz-py3.4'
|
||||
prefix = 'C:\\Python37'
|
||||
|
||||
version = '3.4.2 (v3.4.2:ab2c023a9432, Oct 5 2014, 20:42:22) \n[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]'
|
||||
version = '3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:57:15) [MSC v.1915 64 bit (AMD64)]'
|
||||
|
||||
_home = '/Library/Frameworks/Python.framework/Versions/3.4/bin'
|
||||
winver = '3.7'
|
||||
|
||||
__egginsert = 0
|
||||
__plen = 5
|
||||
_framework = ''
|
||||
|
||||
_home = None
|
||||
|
||||
# functions
|
||||
|
||||
def breakpointhook(*args, **kws): # real signature unknown; restored from __doc__
|
||||
"""
|
||||
breakpointhook(*args, **kws)
|
||||
|
||||
This hook function is called by built-in breakpoint().
|
||||
"""
|
||||
pass
|
||||
|
||||
def callstats(): # real signature unknown; restored from __doc__
|
||||
"""
|
||||
callstats() -> tuple of integers
|
||||
@@ -208,14 +220,14 @@ def getdefaultencoding(): # real signature unknown; restored from __doc__
|
||||
"""
|
||||
return ""
|
||||
|
||||
def getdlopenflags(): # real signature unknown; restored from __doc__
|
||||
def getfilesystemencodeerrors(): # real signature unknown; restored from __doc__
|
||||
"""
|
||||
getdlopenflags() -> int
|
||||
getfilesystemencodeerrors() -> string
|
||||
|
||||
Return the current value of the flags that are used for dlopen calls.
|
||||
The flag constants are defined in the os module.
|
||||
Return the error mode used to convert Unicode filenames in
|
||||
operating system filenames.
|
||||
"""
|
||||
return 0
|
||||
return ""
|
||||
|
||||
def getfilesystemencoding(): # real signature unknown; restored from __doc__
|
||||
"""
|
||||
@@ -276,6 +288,42 @@ def gettrace(): # real signature unknown; restored from __doc__
|
||||
"""
|
||||
pass
|
||||
|
||||
def getwindowsversion(): # real signature unknown; restored from __doc__
|
||||
"""
|
||||
getwindowsversion()
|
||||
|
||||
Return information about the running version of Windows as a named tuple.
|
||||
The members are named: major, minor, build, platform, service_pack,
|
||||
service_pack_major, service_pack_minor, suite_mask, and product_type. For
|
||||
backward compatibility, only the first 5 items are available by indexing.
|
||||
All elements are numbers, except service_pack and platform_type which are
|
||||
strings, and platform_version which is a 3-tuple. Platform is always 2.
|
||||
Product_type may be 1 for a workstation, 2 for a domain controller, 3 for a
|
||||
server. Platform_version is a 3-tuple containing a version number that is
|
||||
intended for identifying the OS rather than feature detection.
|
||||
"""
|
||||
pass
|
||||
|
||||
def get_asyncgen_hooks(): # real signature unknown; restored from __doc__
|
||||
"""
|
||||
get_asyncgen_hooks()
|
||||
|
||||
Return a namedtuple of installed asynchronous generators hooks (firstiter, finalizer).
|
||||
"""
|
||||
pass
|
||||
|
||||
def get_coroutine_origin_tracking_depth(*args, **kwargs): # real signature unknown
|
||||
""" Check status of origin tracking for coroutine objects in this thread. """
|
||||
pass
|
||||
|
||||
def get_coroutine_wrapper(): # real signature unknown; restored from __doc__
|
||||
"""
|
||||
get_coroutine_wrapper()
|
||||
|
||||
Return the wrapper for coroutine objects set by sys.set_coroutine_wrapper.
|
||||
"""
|
||||
pass
|
||||
|
||||
def intern(string): # real signature unknown; restored from __doc__
|
||||
"""
|
||||
intern(string) -> string
|
||||
@@ -287,6 +335,13 @@ def intern(string): # real signature unknown; restored from __doc__
|
||||
"""
|
||||
return ""
|
||||
|
||||
def is_finalizing(): # real signature unknown; restored from __doc__
|
||||
"""
|
||||
is_finalizing()
|
||||
Return True if Python is exiting.
|
||||
"""
|
||||
pass
|
||||
|
||||
def setcheckinterval(n): # real signature unknown; restored from __doc__
|
||||
"""
|
||||
setcheckinterval(n)
|
||||
@@ -296,19 +351,6 @@ def setcheckinterval(n): # real signature unknown; restored from __doc__
|
||||
"""
|
||||
pass
|
||||
|
||||
def setdlopenflags(n): # real signature unknown; restored from __doc__
|
||||
"""
|
||||
setdlopenflags(n) -> None
|
||||
|
||||
Set the flags used by the interpreter for dlopen calls, such as when the
|
||||
interpreter loads extension modules. Among other things, this will enable
|
||||
a lazy resolving of symbols when importing a module, if called as
|
||||
sys.setdlopenflags(0). To share symbols across extension modules, call as
|
||||
sys.setdlopenflags(os.RTLD_GLOBAL). Symbolic names for the flag modules
|
||||
can be found in the os module (RTLD_xxx constants, e.g. os.RTLD_LAZY).
|
||||
"""
|
||||
pass
|
||||
|
||||
def setprofile(function): # real signature unknown; restored from __doc__
|
||||
"""
|
||||
setprofile(function)
|
||||
@@ -352,6 +394,32 @@ def settrace(function): # real signature unknown; restored from __doc__
|
||||
"""
|
||||
pass
|
||||
|
||||
def set_asyncgen_hooks(*args, **kwargs): # real signature unknown; NOTE: unreliably restored from __doc__
|
||||
"""
|
||||
set_asyncgen_hooks(*, firstiter=None, finalizer=None)
|
||||
|
||||
Set a finalizer for async generators objects.
|
||||
"""
|
||||
pass
|
||||
|
||||
def set_coroutine_origin_tracking_depth(*args, **kwargs): # real signature unknown
|
||||
"""
|
||||
Enable or disable origin tracking for coroutine objects in this thread.
|
||||
|
||||
Coroutine objects will track 'depth' frames of traceback information about
|
||||
where they came from, available in their cr_origin attribute. Set depth of 0
|
||||
to disable.
|
||||
"""
|
||||
pass
|
||||
|
||||
def set_coroutine_wrapper(wrapper): # real signature unknown; restored from __doc__
|
||||
"""
|
||||
set_coroutine_wrapper(wrapper)
|
||||
|
||||
Set a wrapper for coroutine objects.
|
||||
"""
|
||||
pass
|
||||
|
||||
def _clear_type_cache(): # real signature unknown; restored from __doc__
|
||||
"""
|
||||
_clear_type_cache() -> None
|
||||
@@ -382,6 +450,18 @@ def _debugmallocstats(): # real signature unknown; restored from __doc__
|
||||
"""
|
||||
pass
|
||||
|
||||
def _enablelegacywindowsfsencoding(): # real signature unknown; restored from __doc__
|
||||
"""
|
||||
_enablelegacywindowsfsencoding()
|
||||
|
||||
Changes the default filesystem encoding to mbcs:replace for consistency
|
||||
with earlier versions of Python. See PEP 529 for more information.
|
||||
|
||||
This is equivalent to defining the PYTHONLEGACYWINDOWSFSENCODING
|
||||
environment variable before launching Python.
|
||||
"""
|
||||
pass
|
||||
|
||||
def _getframe(depth=None): # real signature unknown; restored from __doc__
|
||||
"""
|
||||
_getframe([depth]) -> frameobject
|
||||
@@ -396,6 +476,14 @@ def _getframe(depth=None): # real signature unknown; restored from __doc__
|
||||
"""
|
||||
pass
|
||||
|
||||
def __breakpointhook__(*args, **kwargs): # real signature unknown
|
||||
"""
|
||||
breakpointhook(*args, **kws)
|
||||
|
||||
This hook function is called by built-in breakpoint().
|
||||
"""
|
||||
pass
|
||||
|
||||
def __displayhook__(*args, **kwargs): # real signature unknown
|
||||
"""
|
||||
displayhook(object) -> None
|
||||
@@ -425,6 +513,16 @@ class __loader__(object):
|
||||
All methods are either class or static methods to avoid the need to
|
||||
instantiate the class.
|
||||
"""
|
||||
@classmethod
|
||||
def create_module(cls, *args, **kwargs): # real signature unknown
|
||||
""" Create a built-in module """
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def exec_module(cls, *args, **kwargs): # real signature unknown
|
||||
""" Exec a built-in module """
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def find_module(cls, *args, **kwargs): # real signature unknown
|
||||
"""
|
||||
@@ -457,7 +555,11 @@ class __loader__(object):
|
||||
|
||||
@classmethod
|
||||
def load_module(cls, *args, **kwargs): # real signature unknown
|
||||
""" Load a built-in module. """
|
||||
"""
|
||||
Load the specified module into sys.modules and return it.
|
||||
|
||||
This method is deprecated. Use loader.exec_module instead.
|
||||
"""
|
||||
pass
|
||||
|
||||
def module_repr(module): # reliably restored by inspect
|
||||
@@ -498,6 +600,8 @@ flags = (
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
False,
|
||||
0,
|
||||
)
|
||||
|
||||
float_info = (
|
||||
@@ -542,12 +646,12 @@ meta_path = [
|
||||
modules = {} # real value of type <class 'dict'> skipped
|
||||
|
||||
path = [
|
||||
'/Users/vlan/src/idea/out/classes/production/python-helpers',
|
||||
'/Library/Frameworks/Python.framework/Versions/3.4/lib/python34.zip',
|
||||
'/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4',
|
||||
'/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/plat-darwin',
|
||||
'/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/lib-dynload',
|
||||
'/Users/vlan/.virtualenvs/obraz-py3.4/lib/python3.4/site-packages',
|
||||
'C:\\Projects\\IDEA\\out\\classes\\production\\intellij.python.helpers',
|
||||
'C:\\Python37\\python37.zip',
|
||||
'C:\\Python37\\DLLs',
|
||||
'C:\\Python37\\lib',
|
||||
'C:\\Python37',
|
||||
'C:\\Python37\\lib\\site-packages',
|
||||
]
|
||||
|
||||
path_hooks = [
|
||||
@@ -557,39 +661,39 @@ path_hooks = [
|
||||
|
||||
path_importer_cache = {} # real value of type <class 'dict'> skipped
|
||||
|
||||
stderr = None # (!) forward: __stderr__, real value is ''
|
||||
stderr = None # (!) real value is ''
|
||||
|
||||
stdin = None # (!) forward: __stdin__, real value is ''
|
||||
|
||||
stdout = None # (!) forward: __stdout__, real value is ''
|
||||
|
||||
thread_info = (
|
||||
'pthread',
|
||||
'mutex+cond',
|
||||
'nt',
|
||||
None,
|
||||
None,
|
||||
)
|
||||
|
||||
version_info = (
|
||||
3,
|
||||
4,
|
||||
2,
|
||||
7,
|
||||
1,
|
||||
'final',
|
||||
0,
|
||||
)
|
||||
|
||||
warnoptions = []
|
||||
|
||||
_mercurial = (
|
||||
_git = (
|
||||
'CPython',
|
||||
'v3.4.2',
|
||||
'ab2c023a9432',
|
||||
'v3.7.1',
|
||||
'260ec2c36a',
|
||||
)
|
||||
|
||||
_xoptions = {}
|
||||
|
||||
__spec__ = None # (!) real value is ''
|
||||
|
||||
__stderr__ = None # (!) real value is ''
|
||||
__stderr__ = stderr
|
||||
|
||||
__stdin__ = None # (!) real value is ''
|
||||
|
||||
@@ -76,7 +76,7 @@ import java.util.*;
|
||||
@TestDataPath("$CONTENT_ROOT/../testData/")
|
||||
public abstract class PyTestCase extends UsefulTestCase {
|
||||
public static final String PYTHON_2_MOCK_SDK = "2.7";
|
||||
public static final String PYTHON_3_MOCK_SDK = "3.4";
|
||||
public static final String PYTHON_3_MOCK_SDK = "3.7";
|
||||
|
||||
protected static final PyLightProjectDescriptor ourPyDescriptor = new PyLightProjectDescriptor(PYTHON_2_MOCK_SDK);
|
||||
protected static final PyLightProjectDescriptor ourPy3Descriptor = new PyLightProjectDescriptor(PYTHON_3_MOCK_SDK);
|
||||
|
||||
Reference in New Issue
Block a user