Uploaded Test files
This commit is contained in:
parent
f584ad9d97
commit
2e81cb7d99
16627 changed files with 2065359 additions and 102444 deletions
0
venv/Lib/site-packages/traitlets/utils/__init__.py
Normal file
0
venv/Lib/site-packages/traitlets/utils/__init__.py
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
25
venv/Lib/site-packages/traitlets/utils/bunch.py
Normal file
25
venv/Lib/site-packages/traitlets/utils/bunch.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
"""Yet another implementation of bunch
|
||||
|
||||
attribute-access of items on a dict.
|
||||
"""
|
||||
|
||||
# Copyright (c) Jupyter Development Team.
|
||||
# Distributed under the terms of the Modified BSD License.
|
||||
|
||||
class Bunch(dict):
|
||||
"""A dict with attribute-access"""
|
||||
def __getattr__(self, key):
|
||||
try:
|
||||
return self.__getitem__(key)
|
||||
except KeyError:
|
||||
raise AttributeError(key)
|
||||
|
||||
def __setattr__(self, key, value):
|
||||
self.__setitem__(key, value)
|
||||
|
||||
def __dir__(self):
|
||||
# py2-compat: can't use super because dict doesn't have __dir__
|
||||
names = dir({})
|
||||
names.extend(self.keys())
|
||||
return names
|
||||
|
86
venv/Lib/site-packages/traitlets/utils/getargspec.py
Normal file
86
venv/Lib/site-packages/traitlets/utils/getargspec.py
Normal file
|
@ -0,0 +1,86 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
getargspec excerpted from:
|
||||
|
||||
sphinx.util.inspect
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
Helpers for inspecting Python modules.
|
||||
:copyright: Copyright 2007-2015 by the Sphinx team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
import inspect
|
||||
from six import PY3
|
||||
|
||||
# Unmodified from sphinx below this line
|
||||
|
||||
if PY3:
|
||||
from functools import partial
|
||||
|
||||
def getargspec(func):
|
||||
"""Like inspect.getargspec but supports functools.partial as well."""
|
||||
if inspect.ismethod(func):
|
||||
func = func.__func__
|
||||
if type(func) is partial:
|
||||
orig_func = func.func
|
||||
argspec = getargspec(orig_func)
|
||||
args = list(argspec[0])
|
||||
defaults = list(argspec[3] or ())
|
||||
kwoargs = list(argspec[4])
|
||||
kwodefs = dict(argspec[5] or {})
|
||||
if func.args:
|
||||
args = args[len(func.args):]
|
||||
for arg in func.keywords or ():
|
||||
try:
|
||||
i = args.index(arg) - len(args)
|
||||
del args[i]
|
||||
try:
|
||||
del defaults[i]
|
||||
except IndexError:
|
||||
pass
|
||||
except ValueError: # must be a kwonly arg
|
||||
i = kwoargs.index(arg)
|
||||
del kwoargs[i]
|
||||
del kwodefs[arg]
|
||||
return inspect.FullArgSpec(args, argspec[1], argspec[2],
|
||||
tuple(defaults), kwoargs,
|
||||
kwodefs, argspec[6])
|
||||
while hasattr(func, '__wrapped__'):
|
||||
func = func.__wrapped__
|
||||
if not inspect.isfunction(func):
|
||||
raise TypeError('%r is not a Python function' % func)
|
||||
return inspect.getfullargspec(func)
|
||||
|
||||
else: # 2.6, 2.7
|
||||
from functools import partial
|
||||
|
||||
def getargspec(func):
|
||||
"""Like inspect.getargspec but supports functools.partial as well."""
|
||||
if inspect.ismethod(func):
|
||||
func = func.__func__
|
||||
parts = 0, ()
|
||||
if type(func) is partial:
|
||||
keywords = func.keywords
|
||||
if keywords is None:
|
||||
keywords = {}
|
||||
parts = len(func.args), keywords.keys()
|
||||
func = func.func
|
||||
if not inspect.isfunction(func):
|
||||
raise TypeError('%r is not a Python function' % func)
|
||||
args, varargs, varkw = inspect.getargs(func.__code__)
|
||||
func_defaults = func.__defaults__
|
||||
if func_defaults is None:
|
||||
func_defaults = []
|
||||
else:
|
||||
func_defaults = list(func_defaults)
|
||||
if parts[0]:
|
||||
args = args[parts[0]:]
|
||||
if parts[1]:
|
||||
for arg in parts[1]:
|
||||
i = args.index(arg) - len(args)
|
||||
del args[i]
|
||||
try:
|
||||
del func_defaults[i]
|
||||
except IndexError:
|
||||
pass
|
||||
return inspect.ArgSpec(args, varargs, varkw, func_defaults)
|
42
venv/Lib/site-packages/traitlets/utils/importstring.py
Normal file
42
venv/Lib/site-packages/traitlets/utils/importstring.py
Normal file
|
@ -0,0 +1,42 @@
|
|||
# encoding: utf-8
|
||||
"""
|
||||
A simple utility to import something by its string name.
|
||||
"""
|
||||
# Copyright (c) IPython Development Team.
|
||||
# Distributed under the terms of the Modified BSD License.
|
||||
|
||||
from ipython_genutils.py3compat import cast_bytes_py2
|
||||
from six import string_types
|
||||
|
||||
def import_item(name):
|
||||
"""Import and return ``bar`` given the string ``foo.bar``.
|
||||
|
||||
Calling ``bar = import_item("foo.bar")`` is the functional equivalent of
|
||||
executing the code ``from foo import bar``.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
name : string
|
||||
The fully qualified name of the module/package being imported.
|
||||
|
||||
Returns
|
||||
-------
|
||||
mod : module object
|
||||
The module that was imported.
|
||||
"""
|
||||
if not isinstance(name, string_types):
|
||||
raise TypeError("import_item accepts strings, not '%s'." % type(name))
|
||||
name = cast_bytes_py2(name)
|
||||
parts = name.rsplit('.', 1)
|
||||
if len(parts) == 2:
|
||||
# called with 'foo.bar....'
|
||||
package, obj = parts
|
||||
module = __import__(package, fromlist=[obj])
|
||||
try:
|
||||
pak = getattr(module, obj)
|
||||
except AttributeError:
|
||||
raise ImportError('No module named %s' % obj)
|
||||
return pak
|
||||
else:
|
||||
# called with un-dotted string
|
||||
return __import__(parts[0])
|
17
venv/Lib/site-packages/traitlets/utils/sentinel.py
Normal file
17
venv/Lib/site-packages/traitlets/utils/sentinel.py
Normal file
|
@ -0,0 +1,17 @@
|
|||
"""Sentinel class for constants with useful reprs"""
|
||||
|
||||
# Copyright (c) IPython Development Team.
|
||||
# Distributed under the terms of the Modified BSD License.
|
||||
|
||||
class Sentinel(object):
|
||||
|
||||
def __init__(self, name, module, docstring=None):
|
||||
self.name = name
|
||||
self.module = module
|
||||
if docstring:
|
||||
self.__doc__ = docstring
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
return str(self.module)+'.'+self.name
|
||||
|
0
venv/Lib/site-packages/traitlets/utils/tests/__init__.py
Normal file
0
venv/Lib/site-packages/traitlets/utils/tests/__init__.py
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
14
venv/Lib/site-packages/traitlets/utils/tests/test_bunch.py
Normal file
14
venv/Lib/site-packages/traitlets/utils/tests/test_bunch.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
from ..bunch import Bunch
|
||||
|
||||
def test_bunch():
|
||||
b = Bunch(x=5, y=10)
|
||||
assert 'y' in b
|
||||
assert 'x' in b
|
||||
assert b.x == 5
|
||||
b['a'] = 'hi'
|
||||
assert b.a == 'hi'
|
||||
|
||||
def test_bunch_dir():
|
||||
b = Bunch(x=5, y=10)
|
||||
assert 'x' in dir(b)
|
||||
assert 'keys' in dir(b)
|
|
@ -0,0 +1,30 @@
|
|||
# encoding: utf-8
|
||||
# Copyright (c) IPython Development Team.
|
||||
# Distributed under the terms of the Modified BSD License.
|
||||
#
|
||||
# Adapted from enthought.traits, Copyright (c) Enthought, Inc.,
|
||||
# also under the terms of the Modified BSD License.
|
||||
"""Tests for traitlets.utils.importstring."""
|
||||
|
||||
import os
|
||||
from unittest import TestCase
|
||||
|
||||
from ..importstring import import_item
|
||||
|
||||
|
||||
class TestImportItem(TestCase):
|
||||
|
||||
def test_import_unicode(self):
|
||||
self.assertIs(os, import_item(u'os'))
|
||||
self.assertIs(os.path, import_item(u'os.path'))
|
||||
self.assertIs(os.path.join, import_item(u'os.path.join'))
|
||||
|
||||
def test_bad_input(self):
|
||||
class NotAString(object):
|
||||
pass
|
||||
msg = (
|
||||
"import_item accepts strings, "
|
||||
"not '%s'." % NotAString
|
||||
)
|
||||
with self.assertRaisesRegexp(TypeError, msg):
|
||||
import_item(NotAString())
|
Loading…
Add table
Add a link
Reference in a new issue