├── .gitmodules ├── pythonx ├── tests │ └── __init__.py └── python_function_expander │ ├── __init__.py │ ├── trimmer │ ├── __init__.py │ ├── vim_trimmer.py │ ├── call_visitor.py │ ├── trimmer.py │ └── parser.py │ ├── ultisnipsaide │ ├── __init__.py │ ├── px │ │ ├── __init__.py │ │ ├── cursor │ │ │ └── __init__.py │ │ └── syntax.py │ ├── parsers │ │ ├── __init__.py │ │ └── numberify.py │ └── ultisnipsaide.py │ ├── vendors │ ├── astroid │ │ ├── tests │ │ │ ├── __init__.py │ │ │ ├── testdata │ │ │ │ ├── python2 │ │ │ │ │ └── data │ │ │ │ │ │ ├── tmp__init__.py │ │ │ │ │ │ ├── find_test │ │ │ │ │ │ ├── __init__.py │ │ │ │ │ │ ├── module.py │ │ │ │ │ │ ├── module2.py │ │ │ │ │ │ ├── nonregr.py │ │ │ │ │ │ └── noendingnewline.py │ │ │ │ │ │ ├── foogle │ │ │ │ │ │ └── fax │ │ │ │ │ │ │ ├── a.py │ │ │ │ │ │ │ └── __init__.py │ │ │ │ │ │ ├── notamodule │ │ │ │ │ │ └── file.py │ │ │ │ │ │ ├── path_pkgutil_1 │ │ │ │ │ │ └── package │ │ │ │ │ │ │ ├── foo.py │ │ │ │ │ │ │ └── __init__.py │ │ │ │ │ │ ├── path_pkgutil_2 │ │ │ │ │ │ └── package │ │ │ │ │ │ │ ├── bar.py │ │ │ │ │ │ │ └── __init__.py │ │ │ │ │ │ ├── path_pkgutil_3 │ │ │ │ │ │ └── package │ │ │ │ │ │ │ ├── baz.py │ │ │ │ │ │ │ └── __init__.py │ │ │ │ │ │ ├── module1abs │ │ │ │ │ │ ├── core.py │ │ │ │ │ │ └── __init__.py │ │ │ │ │ │ ├── path_pkg_resources_1 │ │ │ │ │ │ └── package │ │ │ │ │ │ │ ├── foo.py │ │ │ │ │ │ │ └── __init__.py │ │ │ │ │ │ ├── path_pkg_resources_2 │ │ │ │ │ │ └── package │ │ │ │ │ │ │ ├── bar.py │ │ │ │ │ │ │ └── __init__.py │ │ │ │ │ │ ├── path_pkg_resources_3 │ │ │ │ │ │ └── package │ │ │ │ │ │ │ ├── baz.py │ │ │ │ │ │ │ └── __init__.py │ │ │ │ │ │ ├── unicode_package │ │ │ │ │ │ ├── core │ │ │ │ │ │ │ └── __init__.py │ │ │ │ │ │ └── __init__.py │ │ │ │ │ │ ├── appl │ │ │ │ │ │ ├── __init__.py │ │ │ │ │ │ └── myConnection.py │ │ │ │ │ │ ├── invalid_encoding.py │ │ │ │ │ │ ├── package │ │ │ │ │ │ ├── hello.py │ │ │ │ │ │ ├── subpackage │ │ │ │ │ │ │ ├── __init__.py │ │ │ │ │ │ │ └── module.py │ │ │ │ │ │ ├── __init__.py │ │ │ │ │ │ ├── absimport.py │ │ │ │ │ │ └── import_package_subpackage_module.py │ │ │ │ │ │ ├── SSL1 │ │ │ │ │ │ ├── __init__.py │ │ │ │ │ │ └── Connection1.py │ │ │ │ │ │ ├── contribute_to_namespace │ │ │ │ │ │ └── namespace_pep_420 │ │ │ │ │ │ │ └── submodule.py │ │ │ │ │ │ ├── namespace_pep_420 │ │ │ │ │ │ └── module.py │ │ │ │ │ │ ├── lmfp │ │ │ │ │ │ ├── __init__.py │ │ │ │ │ │ └── foo.py │ │ │ │ │ │ ├── recursion.py │ │ │ │ │ │ ├── __init__.py │ │ │ │ │ │ ├── absimp │ │ │ │ │ │ ├── sidepackage │ │ │ │ │ │ │ └── __init__.py │ │ │ │ │ │ ├── string.py │ │ │ │ │ │ └── __init__.py │ │ │ │ │ │ ├── email.py │ │ │ │ │ │ ├── absimport.py │ │ │ │ │ │ ├── notall.py │ │ │ │ │ │ ├── all.py │ │ │ │ │ │ ├── descriptor_crash.py │ │ │ │ │ │ ├── format.py │ │ │ │ │ │ ├── foogle_fax-0.12.5-py2.7-nspkg.pth │ │ │ │ │ │ ├── noendingnewline.py │ │ │ │ │ │ ├── nonregr.py │ │ │ │ │ │ ├── module.py │ │ │ │ │ │ └── module2.py │ │ │ │ └── python3 │ │ │ │ │ └── data │ │ │ │ │ ├── tmp__init__.py │ │ │ │ │ ├── find_test │ │ │ │ │ ├── __init__.py │ │ │ │ │ ├── module.py │ │ │ │ │ ├── module2.py │ │ │ │ │ ├── nonregr.py │ │ │ │ │ └── noendingnewline.py │ │ │ │ │ ├── foogle │ │ │ │ │ └── fax │ │ │ │ │ │ ├── a.py │ │ │ │ │ │ └── __init__.py │ │ │ │ │ ├── notamodule │ │ │ │ │ └── file.py │ │ │ │ │ ├── path_pkgutil_1 │ │ │ │ │ └── package │ │ │ │ │ │ ├── foo.py │ │ │ │ │ │ └── __init__.py │ │ │ │ │ ├── path_pkgutil_2 │ │ │ │ │ └── package │ │ │ │ │ │ ├── bar.py │ │ │ │ │ │ └── __init__.py │ │ │ │ │ ├── path_pkgutil_3 │ │ │ │ │ └── package │ │ │ │ │ │ ├── baz.py │ │ │ │ │ │ └── __init__.py │ │ │ │ │ ├── module1abs │ │ │ │ │ ├── core.py │ │ │ │ │ └── __init__.py │ │ │ │ │ ├── path_pkg_resources_1 │ │ │ │ │ └── package │ │ │ │ │ │ ├── foo.py │ │ │ │ │ │ └── __init__.py │ │ │ │ │ ├── path_pkg_resources_2 │ │ │ │ │ └── package │ │ │ │ │ │ ├── bar.py │ │ │ │ │ │ └── __init__.py │ │ │ │ │ ├── path_pkg_resources_3 │ │ │ │ │ └── package │ │ │ │ │ │ ├── baz.py │ │ │ │ │ │ └── __init__.py │ │ │ │ │ ├── unicode_package │ │ │ │ │ ├── core │ │ │ │ │ │ └── __init__.py │ │ │ │ │ └── __init__.py │ │ │ │ │ ├── appl │ │ │ │ │ ├── __init__.py │ │ │ │ │ └── myConnection.py │ │ │ │ │ ├── invalid_encoding.py │ │ │ │ │ ├── package │ │ │ │ │ ├── hello.py │ │ │ │ │ ├── subpackage │ │ │ │ │ │ ├── __init__.py │ │ │ │ │ │ └── module.py │ │ │ │ │ ├── __init__.py │ │ │ │ │ ├── absimport.py │ │ │ │ │ └── import_package_subpackage_module.py │ │ │ │ │ ├── SSL1 │ │ │ │ │ ├── __init__.py │ │ │ │ │ └── Connection1.py │ │ │ │ │ ├── absimport.py │ │ │ │ │ ├── contribute_to_namespace │ │ │ │ │ └── namespace_pep_420 │ │ │ │ │ │ └── submodule.py │ │ │ │ │ ├── namespace_pep_420 │ │ │ │ │ └── module.py │ │ │ │ │ ├── lmfp │ │ │ │ │ ├── __init__.py │ │ │ │ │ └── foo.py │ │ │ │ │ ├── recursion.py │ │ │ │ │ ├── __init__.py │ │ │ │ │ ├── absimp │ │ │ │ │ ├── sidepackage │ │ │ │ │ │ └── __init__.py │ │ │ │ │ ├── string.py │ │ │ │ │ └── __init__.py │ │ │ │ │ ├── email.py │ │ │ │ │ ├── notall.py │ │ │ │ │ ├── all.py │ │ │ │ │ ├── descriptor_crash.py │ │ │ │ │ ├── format.py │ │ │ │ │ ├── foogle_fax-0.12.5-py2.7-nspkg.pth │ │ │ │ │ ├── noendingnewline.py │ │ │ │ │ ├── nonregr.py │ │ │ │ │ ├── module.py │ │ │ │ │ └── module2.py │ │ │ ├── resources.py │ │ │ ├── unittest_raw_building.py │ │ │ ├── unittest_peephole.py │ │ │ └── unittest_utils.py │ │ ├── interpreter │ │ │ ├── __init__.py │ │ │ ├── _import │ │ │ │ ├── __init__.py │ │ │ │ └── util.py │ │ │ └── dunder_lookup.py │ │ ├── brain │ │ │ ├── brain_uuid.py │ │ │ ├── brain_threading.py │ │ │ ├── brain_dateutil.py │ │ │ ├── brain_mechanize.py │ │ │ ├── brain_hashlib.py │ │ │ ├── brain_re.py │ │ │ ├── brain_io.py │ │ │ ├── brain_qt.py │ │ │ ├── brain_attrs.py │ │ │ ├── brain_fstrings.py │ │ │ ├── brain_pkg_resources.py │ │ │ ├── brain_nose.py │ │ │ ├── brain_collections.py │ │ │ ├── brain_pytest.py │ │ │ ├── brain_functools.py │ │ │ ├── brain_typing.py │ │ │ ├── brain_random.py │ │ │ ├── brain_multiprocessing.py │ │ │ ├── brain_subprocess.py │ │ │ ├── brain_ssl.py │ │ │ ├── brain_curses.py │ │ │ └── brain_gi.py │ │ ├── test_utils.py │ │ ├── nodes.py │ │ ├── astpeephole.py │ │ ├── __pkginfo__.py │ │ ├── transforms.py │ │ ├── context.py │ │ ├── util.py │ │ ├── mixins.py │ │ ├── decorators.py │ │ ├── helpers.py │ │ ├── __init__.py │ │ └── exceptions.py │ └── astroid-1.6.5.dist-info │ │ ├── INSTALLER │ │ ├── top_level.txt │ │ ├── WHEEL │ │ ├── metadata.json │ │ ├── DESCRIPTION.rst │ │ └── METADATA │ ├── config.py │ ├── environment.py │ └── common.py ├── UltiSnips └── python.snippets ├── plugin ├── python-function-expander.vim └── trimmer.vim └── LICENSE /.gitmodules: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pythonx/tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/trimmer/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/ultisnipsaide/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/ultisnipsaide/px/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/ultisnipsaide/parsers/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/interpreter/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid-1.6.5.dist-info/INSTALLER: -------------------------------------------------------------------------------- 1 | pip 2 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/interpreter/_import/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid-1.6.5.dist-info/top_level.txt: -------------------------------------------------------------------------------- 1 | astroid 2 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/tmp__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/tmp__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/find_test/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/find_test/module.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/find_test/module2.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/find_test/nonregr.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/foogle/fax/a.py: -------------------------------------------------------------------------------- 1 | x = 1 -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/notamodule/file.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/find_test/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/find_test/module.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/find_test/module2.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/find_test/nonregr.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/foogle/fax/a.py: -------------------------------------------------------------------------------- 1 | x = 1 -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/notamodule/file.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/foogle/fax/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/foogle/fax/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/find_test/noendingnewline.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/path_pkgutil_1/package/foo.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/path_pkgutil_2/package/bar.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/path_pkgutil_3/package/baz.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/find_test/noendingnewline.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/path_pkgutil_1/package/foo.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/path_pkgutil_2/package/bar.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/path_pkgutil_3/package/baz.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/module1abs/core.py: -------------------------------------------------------------------------------- 1 | import sys 2 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/path_pkg_resources_1/package/foo.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/path_pkg_resources_2/package/bar.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/path_pkg_resources_3/package/baz.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/unicode_package/core/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/module1abs/core.py: -------------------------------------------------------------------------------- 1 | import sys 2 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/path_pkg_resources_1/package/foo.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/path_pkg_resources_2/package/bar.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/path_pkg_resources_3/package/baz.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/unicode_package/core/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/appl/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Init 3 | """ 4 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/invalid_encoding.py: -------------------------------------------------------------------------------- 1 | # -*- coding: lala -*- -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/unicode_package/__init__.py: -------------------------------------------------------------------------------- 1 | x = "șțîâ" -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/appl/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Init 3 | """ 4 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/invalid_encoding.py: -------------------------------------------------------------------------------- 1 | # -*- coding: lala -*- -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/unicode_package/__init__.py: -------------------------------------------------------------------------------- 1 | x = "șțîâ" -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/package/hello.py: -------------------------------------------------------------------------------- 1 | """hello module""" 2 | 3 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/package/hello.py: -------------------------------------------------------------------------------- 1 | """hello module""" 2 | 3 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/SSL1/__init__.py: -------------------------------------------------------------------------------- 1 | from Connection1 import Connection 2 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/SSL1/__init__.py: -------------------------------------------------------------------------------- 1 | from .Connection1 import Connection 2 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/package/subpackage/__init__.py: -------------------------------------------------------------------------------- 1 | """package.subpackage""" 2 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/package/subpackage/__init__.py: -------------------------------------------------------------------------------- 1 | """package.subpackage""" 2 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/contribute_to_namespace/namespace_pep_420/submodule.py: -------------------------------------------------------------------------------- 1 | var = 42 -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/package/subpackage/module.py: -------------------------------------------------------------------------------- 1 | """package.subpackage.module""" 2 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/absimport.py: -------------------------------------------------------------------------------- 1 | 2 | import email 3 | from email import message 4 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/contribute_to_namespace/namespace_pep_420/submodule.py: -------------------------------------------------------------------------------- 1 | var = 42 -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/package/subpackage/module.py: -------------------------------------------------------------------------------- 1 | """package.subpackage.module""" 2 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/namespace_pep_420/module.py: -------------------------------------------------------------------------------- 1 | from namespace_pep_420.submodule import var -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/namespace_pep_420/module.py: -------------------------------------------------------------------------------- 1 | from namespace_pep_420.submodule import var -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/lmfp/__init__.py: -------------------------------------------------------------------------------- 1 | # force a "direct" python import 2 | from . import foo 3 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/recursion.py: -------------------------------------------------------------------------------- 1 | """ For issue #25 """ 2 | class Base(object): 3 | pass -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/lmfp/__init__.py: -------------------------------------------------------------------------------- 1 | # force a "direct" python import 2 | from . import foo 3 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/recursion.py: -------------------------------------------------------------------------------- 1 | """ For issue #25 """ 2 | class Base(object): 3 | pass -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/__init__.py: -------------------------------------------------------------------------------- 1 | __revision__="$Id: __init__.py,v 1.1 2005-06-13 20:55:20 syt Exp $" 2 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/absimp/sidepackage/__init__.py: -------------------------------------------------------------------------------- 1 | """a side package with nothing in it 2 | """ 3 | 4 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/email.py: -------------------------------------------------------------------------------- 1 | """fake email module to test absolute import doesn't grab this one""" 2 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/__init__.py: -------------------------------------------------------------------------------- 1 | __revision__="$Id: __init__.py,v 1.1 2005-06-13 20:55:20 syt Exp $" 2 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/absimp/sidepackage/__init__.py: -------------------------------------------------------------------------------- 1 | """a side package with nothing in it 2 | """ 3 | 4 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/email.py: -------------------------------------------------------------------------------- 1 | """fake email module to test absolute import doesn't grab this one""" 2 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/package/__init__.py: -------------------------------------------------------------------------------- 1 | """package's __init__ file""" 2 | 3 | 4 | from . import subpackage 5 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/path_pkg_resources_1/package/__init__.py: -------------------------------------------------------------------------------- 1 | __import__('pkg_resources').declare_namespace(__name__) -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/path_pkg_resources_2/package/__init__.py: -------------------------------------------------------------------------------- 1 | __import__('pkg_resources').declare_namespace(__name__) -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/path_pkg_resources_3/package/__init__.py: -------------------------------------------------------------------------------- 1 | __import__('pkg_resources').declare_namespace(__name__) -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/package/__init__.py: -------------------------------------------------------------------------------- 1 | """package's __init__ file""" 2 | 3 | 4 | from . import subpackage 5 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/path_pkg_resources_1/package/__init__.py: -------------------------------------------------------------------------------- 1 | __import__('pkg_resources').declare_namespace(__name__) -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/path_pkg_resources_2/package/__init__.py: -------------------------------------------------------------------------------- 1 | __import__('pkg_resources').declare_namespace(__name__) -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/path_pkg_resources_3/package/__init__.py: -------------------------------------------------------------------------------- 1 | __import__('pkg_resources').declare_namespace(__name__) -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/module1abs/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . import core 3 | from .core import * 4 | print(sys.version) 5 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/absimport.py: -------------------------------------------------------------------------------- 1 | from __future__ import absolute_import 2 | import email 3 | from email import message 4 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/absimp/string.py: -------------------------------------------------------------------------------- 1 | from __future__ import absolute_import, print_function 2 | import string 3 | print(string) 4 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/notall.py: -------------------------------------------------------------------------------- 1 | name = 'a' 2 | _bla = 2 3 | other = 'o' 4 | class Aaa: pass 5 | 6 | def func(): return 'yo' 7 | 8 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/absimp/string.py: -------------------------------------------------------------------------------- 1 | from __future__ import absolute_import, print_function 2 | import string 3 | print(string) 4 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/path_pkgutil_1/package/__init__.py: -------------------------------------------------------------------------------- 1 | from pkgutil import extend_path 2 | __path__ = extend_path(__path__, __name__) -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/path_pkgutil_2/package/__init__.py: -------------------------------------------------------------------------------- 1 | from pkgutil import extend_path 2 | __path__ = extend_path(__path__, __name__) -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/path_pkgutil_3/package/__init__.py: -------------------------------------------------------------------------------- 1 | from pkgutil import extend_path 2 | __path__ = extend_path(__path__, __name__) -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/notall.py: -------------------------------------------------------------------------------- 1 | 2 | name = 'a' 3 | _bla = 2 4 | other = 'o' 5 | class Aaa: pass 6 | 7 | def func(): print('yo') 8 | 9 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/path_pkgutil_1/package/__init__.py: -------------------------------------------------------------------------------- 1 | from pkgutil import extend_path 2 | __path__ = extend_path(__path__, __name__) -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/path_pkgutil_2/package/__init__.py: -------------------------------------------------------------------------------- 1 | from pkgutil import extend_path 2 | __path__ = extend_path(__path__, __name__) -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/path_pkgutil_3/package/__init__.py: -------------------------------------------------------------------------------- 1 | from pkgutil import extend_path 2 | __path__ = extend_path(__path__, __name__) -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid-1.6.5.dist-info/WHEEL: -------------------------------------------------------------------------------- 1 | Wheel-Version: 1.0 2 | Generator: bdist_wheel (0.30.0) 3 | Root-Is-Purelib: true 4 | Tag: py2-none-any 5 | Tag: py3-none-any 6 | 7 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/absimp/__init__.py: -------------------------------------------------------------------------------- 1 | """a package with absolute import activated 2 | """ 3 | 4 | from __future__ import absolute_import 5 | 6 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/absimp/__init__.py: -------------------------------------------------------------------------------- 1 | """a package with absolute import activated 2 | """ 3 | 4 | from __future__ import absolute_import 5 | 6 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/module1abs/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import absolute_import, print_function 2 | from . import core 3 | from .core import * 4 | print(sys.version) 5 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/all.py: -------------------------------------------------------------------------------- 1 | 2 | name = 'a' 3 | _bla = 2 4 | other = 'o' 5 | class Aaa: pass 6 | 7 | def func(): print 'yo' 8 | 9 | __all__ = 'Aaa', '_bla', 'name' 10 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/all.py: -------------------------------------------------------------------------------- 1 | 2 | name = 'a' 3 | _bla = 2 4 | other = 'o' 5 | class Aaa: pass 6 | 7 | def func(): print('yo') 8 | 9 | __all__ = 'Aaa', '_bla', 'name' 10 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/lmfp/foo.py: -------------------------------------------------------------------------------- 1 | import sys 2 | if not getattr(sys, 'bar', None): 3 | sys.just_once = [] 4 | # there used to be two numbers here because 5 | # of a load_module_from_path bug 6 | sys.just_once.append(42) 7 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/lmfp/foo.py: -------------------------------------------------------------------------------- 1 | import sys 2 | if not getattr(sys, 'bar', None): 3 | sys.just_once = [] 4 | # there used to be two numbers here because 5 | # of a load_module_from_path bug 6 | sys.just_once.append(42) 7 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/package/absimport.py: -------------------------------------------------------------------------------- 1 | from __future__ import absolute_import, print_function 2 | import import_package_subpackage_module # fail 3 | print(import_package_subpackage_module) 4 | 5 | from . import hello as hola 6 | 7 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/package/absimport.py: -------------------------------------------------------------------------------- 1 | from __future__ import absolute_import, print_function 2 | import import_package_subpackage_module # fail 3 | print(import_package_subpackage_module) 4 | 5 | from . import hello as hola 6 | 7 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/descriptor_crash.py: -------------------------------------------------------------------------------- 1 | 2 | import urllib 3 | 4 | class Page(object): 5 | _urlOpen = staticmethod(urllib.urlopen) 6 | 7 | def getPage(self, url): 8 | handle = self._urlOpen(url) 9 | data = handle.read() 10 | handle.close() 11 | return data 12 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/descriptor_crash.py: -------------------------------------------------------------------------------- 1 | 2 | import urllib 3 | 4 | class Page(object): 5 | _urlOpen = staticmethod(urllib.urlopen) 6 | 7 | def getPage(self, url): 8 | handle = self._urlOpen(url) 9 | data = handle.read() 10 | handle.close() 11 | return data 12 | -------------------------------------------------------------------------------- /UltiSnips/python.snippets: -------------------------------------------------------------------------------- 1 | global !p 2 | from python_function_expander.ultisnipsaide import ultisnipsaide as aide 3 | from python_function_expander import jedi_expander 4 | endglobal 5 | 6 | 7 | context "not aide.is_string() and not aide.is_comment()" 8 | post_jump "jedi_expander.expand_signatures(snip, force=True)" 9 | snippet ( "Expand the current callable object" i 10 | ($1 11 | endsnippet 12 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/appl/myConnection.py: -------------------------------------------------------------------------------- 1 | from data import SSL1 2 | class MyConnection(SSL1.Connection): 3 | 4 | """An SSL connection.""" 5 | 6 | def __init__(self, dummy): 7 | print('MyConnection init') 8 | 9 | if __name__ == '__main__': 10 | myConnection = MyConnection(' ') 11 | input('Press Enter to continue...') 12 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/appl/myConnection.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | from data import SSL1 3 | class MyConnection(SSL1.Connection): 4 | 5 | """An SSL connection.""" 6 | 7 | def __init__(self, dummy): 8 | print('MyConnection init') 9 | 10 | if __name__ == '__main__': 11 | myConnection = MyConnection(' ') 12 | raw_input('Press Enter to continue...') 13 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/SSL1/Connection1.py: -------------------------------------------------------------------------------- 1 | """M2Crypto.SSL.Connection 2 | 3 | Copyright (c) 1999-2004 Ng Pheng Siong. All rights reserved.""" 4 | 5 | RCS_id='$Id: Connection1.py,v 1.1 2005-06-13 20:55:22 syt Exp $' 6 | 7 | #Some code deleted here 8 | 9 | class Connection: 10 | 11 | """An SSL connection.""" 12 | 13 | def __init__(self, ctx, sock=None): 14 | print('init Connection') 15 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/interpreter/_import/util.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Claudiu Popa 2 | 3 | try: 4 | import pkg_resources 5 | except ImportError: 6 | pkg_resources = None 7 | 8 | 9 | def is_namespace(modname): 10 | # pylint: disable=no-member; astroid issue #290, modifying globals at runtime. 11 | return (pkg_resources is not None 12 | and modname in pkg_resources._namespace_packages) 13 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/SSL1/Connection1.py: -------------------------------------------------------------------------------- 1 | """M2Crypto.SSL.Connection 2 | 3 | Copyright (c) 1999-2004 Ng Pheng Siong. All rights reserved.""" 4 | from __future__ import print_function 5 | RCS_id='$Id: Connection1.py,v 1.1 2005-06-13 20:55:22 syt Exp $' 6 | 7 | #Some code deleted here 8 | 9 | class Connection: 10 | 11 | """An SSL connection.""" 12 | 13 | def __init__(self, ctx, sock=None): 14 | print('init Connection') 15 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/ultisnipsaide/ultisnipsaide.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # IMPORT THIRD-PARTY LIBRARIES 5 | from .px import cursor 6 | from .px import syntax 7 | 8 | 9 | def is_comment(): 10 | return syntax.is_comment(cursor.get()) 11 | 12 | 13 | def is_string(): 14 | names = ['String', 'Constant'] 15 | syntax_names = syntax.get_names(cursor.get()) 16 | for name in names: 17 | if name in syntax_names: 18 | return True 19 | 20 | return False 21 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/config.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | '''A simple module to store the user's style preferences.''' 5 | 6 | 7 | INDENT_PREFERENCE = {'indent': ' '} 8 | 9 | 10 | def get_indent_preference(): 11 | '''str: How the user prefers their indentation. Default: " ".''' 12 | return INDENT_PREFERENCE['indent'] 13 | 14 | 15 | def register_indent_preference(text): 16 | '''Set indentation that will be used for multi-line function calls.''' 17 | INDENT_PREFERENCE['indent'] = text 18 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/format.py: -------------------------------------------------------------------------------- 1 | """A multiline string 2 | """ 3 | 4 | function('aeozrijz\ 5 | earzer', hop) 6 | # XXX write test 7 | x = [i for i in range(5) 8 | if i % 4] 9 | 10 | fonction(1, 11 | 2, 12 | 3, 13 | 4) 14 | 15 | def definition(a, 16 | b, 17 | c): 18 | return a + b + c 19 | 20 | class debile(dict, 21 | object): 22 | pass 23 | 24 | if aaaa: pass 25 | else: 26 | aaaa,bbbb = 1,2 27 | aaaa,bbbb = bbbb,aaaa 28 | # XXX write test 29 | hop = \ 30 | aaaa 31 | 32 | 33 | __revision__.lower(); 34 | 35 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/format.py: -------------------------------------------------------------------------------- 1 | """A multiline string 2 | """ 3 | 4 | function('aeozrijz\ 5 | earzer', hop) 6 | # XXX write test 7 | x = [i for i in range(5) 8 | if i % 4] 9 | 10 | fonction(1, 11 | 2, 12 | 3, 13 | 4) 14 | 15 | def definition(a, 16 | b, 17 | c): 18 | return a + b + c 19 | 20 | class debile(dict, 21 | object): 22 | pass 23 | 24 | if aaaa: pass 25 | else: 26 | aaaa,bbbb = 1,2 27 | aaaa,bbbb = bbbb,aaaa 28 | # XXX write test 29 | hop = \ 30 | aaaa 31 | 32 | 33 | __revision__.lower(); 34 | 35 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/environment.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # IMPORT THIRD-PARTY LIBRARIES 5 | import vim 6 | 7 | # IMPORT LOCAL LIBRARIES 8 | from . import config 9 | 10 | 11 | def init(): 12 | '''Get the user's preferred indentation, if they have it defined.''' 13 | try: 14 | indent = vim.eval('g:vim_python_style_swapper_indent') 15 | except Exception: 16 | pass 17 | else: 18 | config.register_indent_preference(indent) 19 | return 20 | 21 | if vim.eval('&expandtab'): 22 | default_indent = ' ' 23 | else: 24 | default_indent = '\t' 25 | 26 | config.register_indent_preference(default_indent) 27 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/foogle_fax-0.12.5-py2.7-nspkg.pth: -------------------------------------------------------------------------------- 1 | import sys, types, os;p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('foogle',));ie = os.path.exists(os.path.join(p,'__init__.py'));m = not ie and sys.modules.setdefault('foogle', types.ModuleType('foogle'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p) 2 | import sys, types, os;p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('foogle','crank'));ie = os.path.exists(os.path.join(p,'__init__.py'));m = not ie and sys.modules.setdefault('foogle.crank', types.ModuleType('foogle.crank'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p) 3 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/foogle_fax-0.12.5-py2.7-nspkg.pth: -------------------------------------------------------------------------------- 1 | import sys, types, os;p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('foogle',));ie = os.path.exists(os.path.join(p,'__init__.py'));m = not ie and sys.modules.setdefault('foogle', types.ModuleType('foogle'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p) 2 | import sys, types, os;p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('foogle','crank'));ie = os.path.exists(os.path.join(p,'__init__.py'));m = not ie and sys.modules.setdefault('foogle.crank', types.ModuleType('foogle.crank'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p) 3 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/brain/brain_uuid.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2017 Claudiu Popa 2 | 3 | # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html 4 | # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER 5 | 6 | """Astroid hooks for the UUID module.""" 7 | 8 | 9 | from astroid import MANAGER 10 | from astroid import nodes 11 | 12 | 13 | def _patch_uuid_class(node): 14 | # The .int member is patched using __dict__ 15 | node.locals['int'] = [nodes.Const(0, parent=node)] 16 | 17 | 18 | MANAGER.register_transform( 19 | nodes.ClassDef, 20 | _patch_uuid_class, 21 | lambda node: node.qname() == 'uuid.UUID' 22 | ) 23 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/noendingnewline.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | 4 | class TestCase(unittest.TestCase): 5 | 6 | def setUp(self): 7 | unittest.TestCase.setUp(self) 8 | 9 | 10 | def tearDown(self): 11 | unittest.TestCase.tearDown(self) 12 | 13 | def testIt(self): 14 | self.a = 10 15 | self.xxx() 16 | 17 | 18 | def xxx(self): 19 | if False: 20 | pass 21 | print 'a' 22 | 23 | if False: 24 | pass 25 | pass 26 | 27 | if False: 28 | pass 29 | print 'rara' 30 | 31 | 32 | if __name__ == '__main__': 33 | print 'test2' 34 | unittest.main() 35 | 36 | 37 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/noendingnewline.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | 4 | class TestCase(unittest.TestCase): 5 | 6 | def setUp(self): 7 | unittest.TestCase.setUp(self) 8 | 9 | 10 | def tearDown(self): 11 | unittest.TestCase.tearDown(self) 12 | 13 | def testIt(self): 14 | self.a = 10 15 | self.xxx() 16 | 17 | 18 | def xxx(self): 19 | if False: 20 | pass 21 | print('a') 22 | 23 | if False: 24 | pass 25 | pass 26 | 27 | if False: 28 | pass 29 | print('rara') 30 | 31 | 32 | if __name__ == '__main__': 33 | print('test2') 34 | unittest.main() 35 | 36 | 37 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/common.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | '''Any generic function that is used across multiple modules.''' 5 | 6 | 7 | def get_default(text): 8 | '''Get the default value of some parameter. 9 | 10 | Args: 11 | text (str): The name and default value of a parameter. 12 | This comes in the form "foo=bar" and "bar" is the default. 13 | 14 | Returns: 15 | str: The found default. 16 | 17 | ''' 18 | try: 19 | index = text.index('=') 20 | except ValueError: 21 | return '' 22 | 23 | default = text[index + 1:] 24 | 25 | if default == '...': # `typeshed` frequently shows just a ... for default values. 26 | return '' 27 | 28 | return default 29 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/brain/brain_threading.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Claudiu Popa 2 | 3 | # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html 4 | # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER 5 | 6 | import astroid 7 | 8 | 9 | def _thread_transform(): 10 | return astroid.parse(''' 11 | class lock(object): 12 | def acquire(self, blocking=True): 13 | pass 14 | def release(self): 15 | pass 16 | def __enter__(self): 17 | return True 18 | def __exit__(self, *args): 19 | pass 20 | 21 | def Lock(): 22 | return lock() 23 | ''') 24 | 25 | 26 | astroid.register_module_extender(astroid.MANAGER, 'threading', _thread_transform) 27 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/brain/brain_dateutil.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2015-2016 Claudiu Popa 2 | # Copyright (c) 2016 Cara Vinson 3 | 4 | # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html 5 | # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER 6 | 7 | """Astroid hooks for dateutil""" 8 | 9 | import textwrap 10 | 11 | from astroid import MANAGER, register_module_extender 12 | from astroid.builder import AstroidBuilder 13 | 14 | def dateutil_transform(): 15 | return AstroidBuilder(MANAGER).string_build(textwrap.dedent(''' 16 | import datetime 17 | def parse(timestr, parserinfo=None, **kwargs): 18 | return datetime.datetime() 19 | ''')) 20 | 21 | register_module_extender(MANAGER, 'dateutil.parser', dateutil_transform) 22 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/brain/brain_mechanize.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2015-2016 Claudiu Popa 2 | 3 | # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html 4 | # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER 5 | 6 | from astroid import MANAGER, register_module_extender 7 | from astroid.builder import AstroidBuilder 8 | 9 | def mechanize_transform(): 10 | return AstroidBuilder(MANAGER).string_build(''' 11 | 12 | class Browser(object): 13 | def open(self, url, data=None, timeout=None): 14 | return None 15 | def open_novisit(self, url, data=None, timeout=None): 16 | return None 17 | def open_local_file(self, filename): 18 | return None 19 | 20 | ''') 21 | 22 | 23 | register_module_extender(MANAGER, 'mechanize', mechanize_transform) 24 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/ultisnipsaide/px/cursor/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf8 2 | 3 | import re 4 | import vim 5 | 6 | 7 | def get(): 8 | return from_vim(vim.current.window.cursor) 9 | 10 | 11 | def set(cursor): 12 | vim.current.window.cursor = to_vim(cursor) 13 | 14 | 15 | def get_adjusted(): 16 | (line, column) = get() 17 | 18 | if vim.eval('mode()') != 'i': 19 | return (line, column + 1) 20 | else: 21 | return (line, column) 22 | 23 | 24 | def to_vim(cursor): 25 | return (cursor[0] + 1, cursor[1]) 26 | 27 | 28 | def to_vim_lang(cursor): 29 | return (cursor[0] + 1, cursor[1] + 1) 30 | 31 | 32 | def from_vim(cursor): 33 | return (cursor[0] - 1, cursor[1]) 34 | 35 | 36 | def is_between(line, cursor, before, after): 37 | if not re.search(before, line[:cursor[1]+1]): 38 | return False 39 | 40 | if not re.search(after, line[cursor[1]:]): 41 | return False 42 | 43 | return True 44 | -------------------------------------------------------------------------------- /plugin/python-function-expander.vim: -------------------------------------------------------------------------------- 1 | if !has('python') && !has('python3') 2 | echoerr "vim-python-function-expander requires Python. Cannot continue loading this plugin" 3 | finish 4 | endif 5 | 6 | 7 | " Get a Python version to run with (Vim 8.0+ can just use `pythonx`) 8 | if get(g:, 'expander_python_version', '2') == '2' && has('python') 9 | let g:_uspy=":python " 10 | elseif get(g:, 'expander_python_version', '3') == '3' && has('python3') 11 | let g:_uspy=":python3 " 12 | else 13 | echoerr "No matching Python version could be found" 14 | endif 15 | 16 | 17 | if get(g:, 'expander_loaded', '0') == '1' 18 | finish 19 | endif 20 | 21 | 22 | if get(g:, 'expander_full_auto', '0') == '1' 23 | autocmd! CursorHoldI *.py call s:ExpandSignatures() 24 | endif 25 | 26 | 27 | function! s:ExpandSignatures() 28 | "from python_function_expander import jedi_expander 29 | "jedi_expander.expand_signature_at_cursor()" 30 | execute g:_uspy "from python_function_expander import jedi_expander;jedi_expander.expand_signature_at_cursor()" 31 | endfunction 32 | 33 | 34 | let g:expander_loaded = '1' 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Colin Kennedy 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/ultisnipsaide/px/syntax.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # IMPORT THIRD-PARTY LIBRARIES 5 | import vim 6 | 7 | # IMPORT LOCAL LIBRARIES 8 | from . import cursor 9 | 10 | 11 | def is_string(cursor): 12 | return 'String' in get_names(cursor) 13 | 14 | 15 | # lookbehind=True will match previous character as well due weird syntax 16 | # identification in vim, when last character in comment is not identified 17 | # as comment. 18 | def is_comment(cursor, lookbehind=True): 19 | comment = 'Comment' in get_names(cursor) 20 | 21 | if lookbehind: 22 | if cursor[1] != 0 and is_comment((cursor[0], cursor[1]-1), False): 23 | return True 24 | 25 | return comment 26 | 27 | 28 | def get_names(position): 29 | try: 30 | syntax_stack = vim.eval('synstack({}, {})'.format( 31 | *cursor.to_vim_lang(position) 32 | )) 33 | except: 34 | return [] 35 | 36 | names = [] 37 | for syn_id in syntax_stack: 38 | names.append( 39 | vim.eval('synIDattr(synIDtrans({}), "name")'.format(syn_id)) 40 | ) 41 | 42 | return names 43 | 44 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/brain/brain_hashlib.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Claudiu Popa 2 | 3 | # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html 4 | # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER 5 | 6 | import six 7 | 8 | import astroid 9 | 10 | 11 | def _hashlib_transform(): 12 | template = ''' 13 | class %(name)s(object): 14 | def __init__(self, value=''): pass 15 | def digest(self): 16 | return %(digest)s 17 | def copy(self): 18 | return self 19 | def update(self, value): pass 20 | def hexdigest(self): 21 | return '' 22 | @property 23 | def name(self): 24 | return %(name)r 25 | @property 26 | def block_size(self): 27 | return 1 28 | @property 29 | def digest_size(self): 30 | return 1 31 | ''' 32 | algorithms = ('md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512') 33 | classes = "".join( 34 | template % {'name': hashfunc, 'digest': 'b""' if six.PY3 else '""'} 35 | for hashfunc in algorithms) 36 | return astroid.parse(classes) 37 | 38 | 39 | astroid.register_module_extender(astroid.MANAGER, 'hashlib', _hashlib_transform) 40 | 41 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/brain/brain_re.py: -------------------------------------------------------------------------------- 1 | # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html 2 | # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER 3 | import sys 4 | import astroid 5 | 6 | PY36 = sys.version_info >= (3, 6) 7 | 8 | if PY36: 9 | # Since Python 3.6 there is the RegexFlag enum 10 | # where every entry will be exposed via updating globals() 11 | 12 | def _re_transform(): 13 | return astroid.parse(''' 14 | import sre_compile 15 | ASCII = sre_compile.SRE_FLAG_ASCII 16 | IGNORECASE = sre_compile.SRE_FLAG_IGNORECASE 17 | LOCALE = sre_compile.SRE_FLAG_LOCALE 18 | UNICODE = sre_compile.SRE_FLAG_UNICODE 19 | MULTILINE = sre_compile.SRE_FLAG_MULTILINE 20 | DOTALL = sre_compile.SRE_FLAG_DOTALL 21 | VERBOSE = sre_compile.SRE_FLAG_VERBOSE 22 | A = ASCII 23 | I = IGNORECASE 24 | L = LOCALE 25 | U = UNICODE 26 | M = MULTILINE 27 | S = DOTALL 28 | X = VERBOSE 29 | TEMPLATE = sre_compile.SRE_FLAG_TEMPLATE 30 | T = TEMPLATE 31 | DEBUG = sre_compile.SRE_FLAG_DEBUG 32 | ''') 33 | 34 | astroid.register_module_extender(astroid.MANAGER, 're', _re_transform) 35 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid-1.6.5.dist-info/metadata.json: -------------------------------------------------------------------------------- 1 | {"classifiers": ["Topic :: Software Development :: Libraries :: Python Modules", "Topic :: Software Development :: Quality Assurance", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy"], "extensions": {"python.details": {"contacts": [{"email": "code-quality@python.org", "name": "Python Code Quality Authority", "role": "author"}], "document_names": {"description": "DESCRIPTION.rst"}, "project_urls": {"Home": "https://github.com/PyCQA/astroid"}}}, "extras": [], "generator": "bdist_wheel (0.30.0)", "license": "LGPL", "metadata_version": "2.0", "name": "astroid", "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*", "run_requires": [{"requires": ["lazy-object-proxy", "six", "wrapt"]}, {"environment": "python_version<\"3.4\"", "requires": ["backports.functools-lru-cache", "enum34 (>=1.1.3)", "singledispatch"]}], "summary": "A abstract syntax tree for Python with inference support.", "version": "1.6.5"} -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/nonregr.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | try: 4 | enumerate = enumerate 5 | except NameError: 6 | 7 | def enumerate(iterable): 8 | """emulates the python2.3 enumerate() function""" 9 | i = 0 10 | for val in iterable: 11 | yield i, val 12 | i += 1 13 | 14 | def toto(value): 15 | for k, v in value: 16 | print(v.get('yo')) 17 | 18 | 19 | import imp 20 | fp, mpath, desc = imp.find_module('optparse',a) 21 | s_opt = imp.load_module('std_optparse', fp, mpath, desc) 22 | 23 | class OptionParser(s_opt.OptionParser): 24 | 25 | def parse_args(self, args=None, values=None, real_optparse=False): 26 | if real_optparse: 27 | pass 28 | ## return super(OptionParser, self).parse_args() 29 | else: 30 | import optcomp 31 | optcomp.completion(self) 32 | 33 | 34 | class Aaa(object): 35 | """docstring""" 36 | def __init__(self): 37 | self.__setattr__('a','b') 38 | pass 39 | 40 | def one_public(self): 41 | """docstring""" 42 | pass 43 | 44 | def another_public(self): 45 | """docstring""" 46 | pass 47 | 48 | class Ccc(Aaa): 49 | """docstring""" 50 | 51 | class Ddd(Aaa): 52 | """docstring""" 53 | pass 54 | 55 | class Eee(Ddd): 56 | """docstring""" 57 | pass 58 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/nonregr.py: -------------------------------------------------------------------------------- 1 | from __future__ import generators, print_function 2 | 3 | try: 4 | enumerate = enumerate 5 | except NameError: 6 | 7 | def enumerate(iterable): 8 | """emulates the python2.3 enumerate() function""" 9 | i = 0 10 | for val in iterable: 11 | yield i, val 12 | i += 1 13 | 14 | def toto(value): 15 | for k, v in value: 16 | print(v.get('yo')) 17 | 18 | 19 | import imp 20 | fp, mpath, desc = imp.find_module('optparse',a) 21 | s_opt = imp.load_module('std_optparse', fp, mpath, desc) 22 | 23 | class OptionParser(s_opt.OptionParser): 24 | 25 | def parse_args(self, args=None, values=None, real_optparse=False): 26 | if real_optparse: 27 | pass 28 | ## return super(OptionParser, self).parse_args() 29 | else: 30 | import optcomp 31 | optcomp.completion(self) 32 | 33 | 34 | class Aaa(object): 35 | """docstring""" 36 | def __init__(self): 37 | self.__setattr__('a','b') 38 | pass 39 | 40 | def one_public(self): 41 | """docstring""" 42 | pass 43 | 44 | def another_public(self): 45 | """docstring""" 46 | pass 47 | 48 | class Ccc(Aaa): 49 | """docstring""" 50 | 51 | class Ddd(Aaa): 52 | """docstring""" 53 | pass 54 | 55 | class Eee(Ddd): 56 | """docstring""" 57 | pass 58 | -------------------------------------------------------------------------------- /plugin/trimmer.vim: -------------------------------------------------------------------------------- 1 | if !has('python') && !has('python3') 2 | echoerr "vim-python-function-expander requires Python. Cannot continue loading this plugin" 3 | finish 4 | endif 5 | 6 | 7 | " Get a Python version to run with (Vim 8.0+ can just use `pythonx`) 8 | if get(g:, 'expander_python_version', '2') == '2' && has('python') 9 | let g:_uspy=":python " 10 | elseif get(g:, 'expander_python_version', '3') == '3' && has('python3') 11 | let g:_uspy=":python3 " 12 | else 13 | echoerr "No matching Python version could be found" 14 | endif 15 | 16 | 17 | if get(g:, 'trimmer_loaded', '0') == '1' 18 | finish 19 | endif 20 | 21 | command! -nargs=0 TrimUnchangedPythonParameters call s:TrimUnchangedPythonParameters() 22 | 23 | " Plugin mappings 24 | nnoremap (trimmer-mapping) :TrimUnchangedPythonParameters 25 | 26 | " Create default mappings if they are not defined 27 | if !hasmapto('(trimmer-mapping)') 28 | nmap ta (trimmer-mapping) 29 | endif 30 | 31 | 32 | " from python_function_expander import environment 33 | " environment.init() 34 | execute g:_uspy "from python_function_expander import environment;environment.init()" 35 | 36 | 37 | function! s:TrimUnchangedPythonParameters() 38 | " from python_function_expander.trimmer import vim_trimmer 39 | " vim_trimmer.trim_unchanged_arguments_in_buffer() 40 | execute g:_uspy "from python_function_expander.trimmer import vim_trimmer;vim_trimmer.trim_unchanged_arguments_in_buffer()" 41 | endfunction 42 | 43 | 44 | let g:trimmer_loaded = '1' 45 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/trimmer/vim_trimmer.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | '''The main module which trims text out of Vim's current buffer.''' 5 | 6 | # IMPORT THIRD-PARTY LIBRARIES 7 | import vim 8 | 9 | # IMPORT LOCAL LIBRARIES 10 | from . import trimmer 11 | 12 | 13 | def _to_vim(cursor): 14 | '''tuple[int, int]: Change the given cursor to a Vim cursor, which is base-1.''' 15 | # Reference: https://github.com/reconquest/vim-pythonx 16 | # I copied the code from this repository, to avoid the extra dependency 17 | # 18 | return (cursor[0] + 1, cursor[1]) 19 | 20 | 21 | def _set_cursor(cursor): 22 | '''Set the current cursor as the user's cursor in the current buffer.''' 23 | # Reference: https://github.com/reconquest/vim-pythonx 24 | # I copied the code from this repository, to avoid the extra dependency 25 | # 26 | vim.current.window.cursor = _to_vim(cursor) 27 | 28 | 29 | def trim_unchanged_arguments_in_buffer(): 30 | '''Remove any unneeded arguments in the function call of the user's cursor.''' 31 | code = '\n'.join(vim.current.window.buffer) 32 | (row, column) = vim.current.window.cursor 33 | 34 | trimmed_code, call = trimmer.get_trimmed_keywords(code, row, column) 35 | 36 | if not call: 37 | return 38 | 39 | trimmed_lines = trimmed_code.splitlines() 40 | vim.current.window.buffer[:] = trimmed_lines 41 | 42 | first_non_whitespace_character_column = \ 43 | len(trimmed_lines[call.fromlineno - 1]) - \ 44 | len(trimmed_lines[call.fromlineno - 1].lstrip()) 45 | 46 | _set_cursor((call.fromlineno - 1, first_non_whitespace_character_column)) 47 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/brain/brain_io.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Claudiu Popa 2 | 3 | # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html 4 | # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER 5 | 6 | '''Astroid brain hints for some of the _io C objects.''' 7 | 8 | import astroid 9 | 10 | 11 | BUFFERED = {'BufferedWriter', 'BufferedReader'} 12 | TextIOWrapper = 'TextIOWrapper' 13 | FileIO = 'FileIO' 14 | BufferedWriter = 'BufferedWriter' 15 | 16 | 17 | def _generic_io_transform(node, name, cls): 18 | '''Transform the given name, by adding the given *class* as a member of the node.''' 19 | 20 | io_module = astroid.MANAGER.ast_from_module_name('_io') 21 | attribute_object = io_module[cls] 22 | instance = attribute_object.instantiate_class() 23 | node.locals[name] = [instance] 24 | 25 | 26 | def _transform_text_io_wrapper(node): 27 | # This is not always correct, since it can vary with the type of the descriptor, 28 | # being stdout, stderr or stdin. But we cannot get access to the name of the 29 | # stream, which is why we are using the BufferedWriter class as a default 30 | # value 31 | return _generic_io_transform(node, name='buffer', cls=BufferedWriter) 32 | 33 | 34 | def _transform_buffered(node): 35 | return _generic_io_transform(node, name='raw', cls=FileIO) 36 | 37 | 38 | astroid.MANAGER.register_transform(astroid.ClassDef, 39 | _transform_buffered, 40 | lambda node: node.name in BUFFERED) 41 | astroid.MANAGER.register_transform(astroid.ClassDef, 42 | _transform_text_io_wrapper, 43 | lambda node: node.name == TextIOWrapper) 44 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/brain/brain_qt.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2015-2016 Claudiu Popa 2 | 3 | # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html 4 | # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER 5 | 6 | """Astroid hooks for the PyQT library.""" 7 | 8 | from astroid import MANAGER, register_module_extender 9 | from astroid.builder import AstroidBuilder 10 | from astroid import nodes 11 | from astroid import parse 12 | 13 | 14 | def _looks_like_signal(node, signal_name='pyqtSignal'): 15 | if '__class__' in node.instance_attrs: 16 | try: 17 | cls = node.instance_attrs['__class__'][0] 18 | return cls.name == signal_name 19 | except AttributeError: 20 | # return False if the cls does not have a name attribute 21 | pass 22 | return False 23 | 24 | 25 | def transform_pyqt_signal(node): 26 | module = parse(''' 27 | class pyqtSignal(object): 28 | def connect(self, slot, type=None, no_receiver_check=False): 29 | pass 30 | def disconnect(self, slot): 31 | pass 32 | def emit(self, *args): 33 | pass 34 | ''') 35 | signal_cls = module['pyqtSignal'] 36 | node.instance_attrs['emit'] = signal_cls['emit'] 37 | node.instance_attrs['disconnect'] = signal_cls['disconnect'] 38 | node.instance_attrs['connect'] = signal_cls['connect'] 39 | 40 | 41 | def pyqt4_qtcore_transform(): 42 | return AstroidBuilder(MANAGER).string_build(''' 43 | 44 | def SIGNAL(signal_name): pass 45 | 46 | class QObject(object): 47 | def emit(self, signal): pass 48 | ''') 49 | 50 | 51 | register_module_extender(MANAGER, 'PyQt4.QtCore', pyqt4_qtcore_transform) 52 | MANAGER.register_transform(nodes.FunctionDef, transform_pyqt_signal, 53 | _looks_like_signal) -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/brain/brain_attrs.py: -------------------------------------------------------------------------------- 1 | # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html 2 | # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER 3 | """ 4 | Astroid hook for the attrs library 5 | 6 | Without this hook pylint reports unsupported-assignment-operation 7 | for atrrs classes 8 | """ 9 | 10 | import astroid 11 | from astroid import MANAGER 12 | 13 | 14 | ATTR_IB = 'attr.ib' 15 | 16 | 17 | def is_decorated_with_attrs( 18 | node, decorator_names=('attr.s', 'attr.attrs', 'attr.attributes')): 19 | """Return True if a decorated node has 20 | an attr decorator applied.""" 21 | if not node.decorators: 22 | return False 23 | for decorator_attribute in node.decorators.nodes: 24 | if decorator_attribute.as_string() in decorator_names: 25 | return True 26 | return False 27 | 28 | 29 | def attr_attributes_transform(node): 30 | """Given that the ClassNode has an attr decorator, 31 | rewrite class attributes as instance attributes 32 | """ 33 | # Astroid can't infer this attribute properly 34 | # Prevents https://github.com/PyCQA/pylint/issues/1884 35 | node.locals["__attrs_attrs__"] = [astroid.Unknown(parent=node.body)] 36 | 37 | for cdefbodynode in node.body: 38 | if not isinstance(cdefbodynode, astroid.Assign): 39 | continue 40 | if isinstance(cdefbodynode.value, astroid.Call): 41 | if cdefbodynode.value.func.as_string() != ATTR_IB: 42 | continue 43 | else: 44 | continue 45 | for target in cdefbodynode.targets: 46 | 47 | rhs_node = astroid.Unknown( 48 | lineno=cdefbodynode.lineno, 49 | col_offset=cdefbodynode.col_offset, 50 | parent=cdefbodynode 51 | ) 52 | node.locals[target.name] = [rhs_node] 53 | 54 | 55 | MANAGER.register_transform( 56 | astroid.Class, 57 | attr_attributes_transform, 58 | is_decorated_with_attrs) 59 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/module.py: -------------------------------------------------------------------------------- 1 | """test module for astroid 2 | """ 3 | 4 | __revision__ = '$Id: module.py,v 1.2 2005-11-02 11:56:54 syt Exp $' 5 | from astroid.node_classes import Name as NameNode 6 | from astroid import modutils 7 | from astroid.utils import * 8 | import os.path 9 | MY_DICT = {} 10 | 11 | def global_access(key, val): 12 | """function test""" 13 | local = 1 14 | MY_DICT[key] = val 15 | for i in val: 16 | if i: 17 | del MY_DICT[i] 18 | continue 19 | else: 20 | break 21 | else: 22 | return 23 | 24 | 25 | class YO: 26 | """hehe""" 27 | a = 1 28 | 29 | def __init__(self): 30 | try: 31 | self.yo = 1 32 | except ValueError as ex: 33 | pass 34 | except (NameError, TypeError): 35 | raise XXXError() 36 | except: 37 | raise 38 | 39 | 40 | 41 | class YOUPI(YO): 42 | class_attr = None 43 | 44 | def __init__(self): 45 | self.member = None 46 | 47 | def method(self): 48 | """method test""" 49 | global MY_DICT 50 | try: 51 | MY_DICT = {} 52 | local = None 53 | autre = [a for (a, b) in MY_DICT if b] 54 | if b in autre: 55 | return 56 | else: 57 | if a in autre: 58 | return 'hehe' 59 | global_access(local, val=autre) 60 | finally: 61 | return local 62 | 63 | def static_method(): 64 | """static method test""" 65 | assert MY_DICT, '???' 66 | static_method = staticmethod(static_method) 67 | 68 | def class_method(cls): 69 | """class method test""" 70 | exec(a, b) 71 | class_method = classmethod(class_method) 72 | 73 | 74 | def four_args(a, b, c, d): 75 | """four arguments (was nested_args)""" 76 | while 1: 77 | if a: 78 | break 79 | a += +1 80 | else: 81 | b += -2 82 | if c: 83 | d = ((a) and (b)) or (c) 84 | else: 85 | c = ((a) and (b)) or (d) 86 | list(map(lambda x, y: (y, x), a)) 87 | redirect = four_args 88 | 89 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/resources.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014 Google, Inc. 2 | # Copyright (c) 2015-2016 Claudiu Popa 3 | 4 | # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html 5 | # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER 6 | 7 | import os 8 | import sys 9 | 10 | import pkg_resources 11 | 12 | from astroid import builder 13 | from astroid import MANAGER 14 | from astroid.bases import BUILTINS 15 | from astroid import tests 16 | 17 | 18 | DATA_DIR = os.path.join('testdata', 'python{}'.format(sys.version_info[0])) 19 | RESOURCE_PATH = os.path.join(tests.__path__[0], DATA_DIR, 'data') 20 | 21 | def find(name): 22 | return pkg_resources.resource_filename( 23 | 'astroid.tests', os.path.normpath(os.path.join(DATA_DIR, name))) 24 | 25 | 26 | def build_file(path, modname=None): 27 | return builder.AstroidBuilder().file_build(find(path), modname) 28 | 29 | 30 | class SysPathSetup(object): 31 | def setUp(self): 32 | sys.path.insert(0, find('')) 33 | 34 | def tearDown(self): 35 | del sys.path[0] 36 | datadir = find('') 37 | for key in list(sys.path_importer_cache): 38 | if key.startswith(datadir): 39 | del sys.path_importer_cache[key] 40 | 41 | 42 | class AstroidCacheSetupMixin(object): 43 | """Mixin for handling the astroid cache problems. 44 | 45 | When clearing the astroid cache, some tests fails due to 46 | cache inconsistencies, where some objects had a different 47 | builtins object referenced. 48 | This saves the builtins module and makes sure to add it 49 | back to the astroid_cache after the tests finishes. 50 | The builtins module is special, since some of the 51 | transforms for a couple of its objects (str, bytes etc) 52 | are executed only once, so astroid_bootstrapping will be 53 | useless for retrieving the original builtins module. 54 | """ 55 | 56 | @classmethod 57 | def setUpClass(cls): 58 | cls._builtins = MANAGER.astroid_cache.get(BUILTINS) 59 | 60 | @classmethod 61 | def tearDownClass(cls): 62 | if cls._builtins: 63 | MANAGER.astroid_cache[BUILTINS] = cls._builtins 64 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/brain/brain_fstrings.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2017 Claudiu Popa 2 | 3 | # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html 4 | # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER 5 | 6 | import sys 7 | 8 | import astroid 9 | 10 | 11 | def _clone_node_with_lineno(node, parent, lineno): 12 | cls = node.__class__ 13 | other_fields = node._other_fields 14 | _astroid_fields = node._astroid_fields 15 | init_params = { 16 | 'lineno': lineno, 17 | 'col_offset': node.col_offset, 18 | 'parent': parent 19 | } 20 | postinit_params = { 21 | param: getattr(node, param) 22 | for param in _astroid_fields 23 | } 24 | if other_fields: 25 | init_params.update({ 26 | param: getattr(node, param) 27 | for param in other_fields 28 | }) 29 | new_node = cls(**init_params) 30 | if hasattr(node, 'postinit') and _astroid_fields: 31 | new_node.postinit(**postinit_params) 32 | return new_node 33 | 34 | 35 | def _transform_formatted_value(node): 36 | if node.value and node.value.lineno == 1: 37 | if node.lineno != node.value.lineno: 38 | new_node = astroid.FormattedValue( 39 | lineno=node.lineno, 40 | col_offset=node.col_offset, 41 | parent=node.parent 42 | ) 43 | new_value = _clone_node_with_lineno( 44 | node=node.value, 45 | lineno=node.lineno, 46 | parent=new_node 47 | ) 48 | new_node.postinit(value=new_value, 49 | format_spec=node.format_spec) 50 | return new_node 51 | 52 | 53 | if sys.version_info[:2] >= (3, 6): 54 | # TODO: this fix tries to *patch* http://bugs.python.org/issue29051 55 | # The problem is that FormattedValue.value, which is a Name node, 56 | # has wrong line numbers, usually 1. This creates problems for pylint, 57 | # which expects correct line numbers for things such as message control. 58 | astroid.MANAGER.register_transform( 59 | astroid.FormattedValue, 60 | _transform_formatted_value) 61 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/module.py: -------------------------------------------------------------------------------- 1 | """test module for astroid 2 | """ 3 | 4 | __revision__ = '$Id: module.py,v 1.2 2005-11-02 11:56:54 syt Exp $' 5 | from astroid.node_classes import Name as NameNode 6 | from astroid import modutils 7 | from astroid.utils import * 8 | import os.path 9 | MY_DICT = {} 10 | 11 | def global_access(key, val): 12 | """function test""" 13 | local = 1 14 | MY_DICT[key] = val 15 | for i in val: 16 | if i: 17 | del MY_DICT[i] 18 | continue 19 | else: 20 | break 21 | else: 22 | return local 23 | 24 | 25 | class YO: 26 | """hehe""" 27 | a = 1 28 | 29 | def __init__(self): 30 | try: 31 | self.yo = 1 32 | except ValueError, ex: 33 | pass 34 | except (NameError, TypeError): 35 | raise XXXError() 36 | except: 37 | raise 38 | 39 | 40 | 41 | class YOUPI(YO): 42 | class_attr = None 43 | 44 | def __init__(self): 45 | self.member = None 46 | 47 | def method(self): 48 | """method test""" 49 | global MY_DICT 50 | try: 51 | MY_DICT = {} 52 | local = None 53 | autre = [a for (a, b) in MY_DICT if b] 54 | if b in autre: 55 | return b 56 | else: 57 | if a in autre: 58 | return a 59 | global_access(local, val=autre) 60 | finally: 61 | return local 62 | 63 | def static_method(): 64 | """static method test""" 65 | assert MY_DICT, '???' 66 | static_method = staticmethod(static_method) 67 | 68 | def class_method(cls): 69 | """class method test""" 70 | exec a in b 71 | class_method = classmethod(class_method) 72 | 73 | 74 | def four_args(a, b, c, d): 75 | """four arguments (was nested_args)""" 76 | pass 77 | while 1: 78 | if a: 79 | break 80 | a += +1 81 | else: 82 | b += -2 83 | if c: 84 | d = ((a) and (b)) or (c) 85 | else: 86 | c = ((a) and (b)) or (d) 87 | map(lambda x, y: (y, x), a) 88 | redirect = four_args 89 | 90 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/test_utils.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2014 Google, Inc. 2 | # Copyright (c) 2015-2016 Cara Vinson 3 | # Copyright (c) 2015-2016 Claudiu Popa 4 | 5 | # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html 6 | # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER 7 | 8 | """Utility functions for test code that uses astroid ASTs as input.""" 9 | import contextlib 10 | import functools 11 | import sys 12 | import warnings 13 | 14 | from astroid import nodes 15 | from astroid import util 16 | 17 | 18 | def require_version(minver=None, maxver=None): 19 | """ Compare version of python interpreter to the given one. Skip the test 20 | if older. 21 | """ 22 | def parse(string, default=None): 23 | string = string or default 24 | try: 25 | return tuple(int(v) for v in string.split('.')) 26 | except ValueError: 27 | util.reraise(ValueError('%s is not a correct version : should be X.Y[.Z].' % string)) 28 | 29 | def check_require_version(f): 30 | current = sys.version_info[:3] 31 | if parse(minver, "0") < current <= parse(maxver, "4"): 32 | return f 33 | 34 | str_version = '.'.join(str(v) for v in sys.version_info) 35 | @functools.wraps(f) 36 | def new_f(self, *args, **kwargs): 37 | if minver is not None: 38 | self.skipTest('Needs Python > %s. Current version is %s.' 39 | % (minver, str_version)) 40 | elif maxver is not None: 41 | self.skipTest('Needs Python <= %s. Current version is %s.' 42 | % (maxver, str_version)) 43 | return new_f 44 | 45 | 46 | return check_require_version 47 | 48 | def get_name_node(start_from, name, index=0): 49 | return [n for n in start_from.nodes_of_class(nodes.Name) if n.name == name][index] 50 | 51 | 52 | @contextlib.contextmanager 53 | def enable_warning(warning): 54 | warnings.simplefilter('always', warning) 55 | try: 56 | yield 57 | finally: 58 | # Reset it to default value, so it will take 59 | # into account the values from the -W flag. 60 | warnings.simplefilter('default', warning) 61 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/brain/brain_pkg_resources.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Claudiu Popa 2 | 3 | # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html 4 | # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER 5 | 6 | 7 | import astroid 8 | from astroid import parse 9 | from astroid import inference_tip 10 | from astroid import register_module_extender 11 | from astroid import MANAGER 12 | 13 | 14 | def pkg_resources_transform(): 15 | return parse(''' 16 | def require(*requirements): 17 | return pkg_resources.working_set.require(*requirements) 18 | 19 | def run_script(requires, script_name): 20 | return pkg_resources.working_set.run_script(requires, script_name) 21 | 22 | def iter_entry_points(group, name=None): 23 | return pkg_resources.working_set.iter_entry_points(group, name) 24 | 25 | def resource_exists(package_or_requirement, resource_name): 26 | return get_provider(package_or_requirement).has_resource(resource_name) 27 | 28 | def resource_isdir(package_or_requirement, resource_name): 29 | return get_provider(package_or_requirement).resource_isdir( 30 | resource_name) 31 | 32 | def resource_filename(package_or_requirement, resource_name): 33 | return get_provider(package_or_requirement).get_resource_filename( 34 | self, resource_name) 35 | 36 | def resource_stream(package_or_requirement, resource_name): 37 | return get_provider(package_or_requirement).get_resource_stream( 38 | self, resource_name) 39 | 40 | def resource_string(package_or_requirement, resource_name): 41 | return get_provider(package_or_requirement).get_resource_string( 42 | self, resource_name) 43 | 44 | def resource_listdir(package_or_requirement, resource_name): 45 | return get_provider(package_or_requirement).resource_listdir( 46 | resource_name) 47 | 48 | def extraction_error(): 49 | pass 50 | 51 | def get_cache_path(archive_name, names=()): 52 | extract_path = self.extraction_path or get_default_cache() 53 | target_path = os.path.join(extract_path, archive_name+'-tmp', *names) 54 | return target_path 55 | 56 | def postprocess(tempname, filename): 57 | pass 58 | 59 | def set_extraction_path(path): 60 | pass 61 | 62 | def cleanup_resources(force=False): 63 | pass 64 | 65 | def get_distribution(dist): 66 | return Distribution(dist) 67 | 68 | ''') 69 | 70 | register_module_extender(MANAGER, 'pkg_resources', pkg_resources_transform) 71 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/brain/brain_nose.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2015-2016 Claudiu Popa 2 | 3 | # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html 4 | # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER 5 | 6 | 7 | """Hooks for nose library.""" 8 | 9 | import re 10 | import textwrap 11 | 12 | import astroid 13 | import astroid.builder 14 | 15 | _BUILDER = astroid.builder.AstroidBuilder(astroid.MANAGER) 16 | 17 | 18 | def _pep8(name, caps=re.compile('([A-Z])')): 19 | return caps.sub(lambda m: '_' + m.groups()[0].lower(), name) 20 | 21 | 22 | def _nose_tools_functions(): 23 | """Get an iterator of names and bound methods.""" 24 | module = _BUILDER.string_build(textwrap.dedent(''' 25 | import unittest 26 | 27 | class Test(unittest.TestCase): 28 | pass 29 | a = Test() 30 | ''')) 31 | try: 32 | case = next(module['a'].infer()) 33 | except astroid.InferenceError: 34 | return 35 | for method in case.methods(): 36 | if method.name.startswith('assert') and '_' not in method.name: 37 | pep8_name = _pep8(method.name) 38 | yield pep8_name, astroid.BoundMethod(method, case) 39 | if method.name == 'assertEqual': 40 | # nose also exports assert_equals. 41 | yield 'assert_equals', astroid.BoundMethod(method, case) 42 | 43 | 44 | def _nose_tools_transform(node): 45 | for method_name, method in _nose_tools_functions(): 46 | node.locals[method_name] = [method] 47 | 48 | 49 | def _nose_tools_trivial_transform(): 50 | """Custom transform for the nose.tools module.""" 51 | stub = _BUILDER.string_build('''__all__ = []''') 52 | all_entries = ['ok_', 'eq_'] 53 | 54 | for pep8_name, method in _nose_tools_functions(): 55 | all_entries.append(pep8_name) 56 | stub[pep8_name] = method 57 | 58 | # Update the __all__ variable, since nose.tools 59 | # does this manually with .append. 60 | all_assign = stub['__all__'].parent 61 | all_object = astroid.List(all_entries) 62 | all_object.parent = all_assign 63 | all_assign.value = all_object 64 | return stub 65 | 66 | 67 | astroid.register_module_extender(astroid.MANAGER, 'nose.tools.trivial', 68 | _nose_tools_trivial_transform) 69 | astroid.MANAGER.register_transform(astroid.Module, _nose_tools_transform, 70 | lambda n: n.name == 'nose.tools') 71 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/package/import_package_subpackage_module.py: -------------------------------------------------------------------------------- 1 | # pylint: disable-msg=I0011,C0301,W0611 2 | """I found some of my scripts trigger off an AttributeError in pylint 3 | 0.8.1 (with common 0.12.0 and astroid 0.13.1). 4 | 5 | Traceback (most recent call last): 6 | File "/usr/bin/pylint", line 4, in ? 7 | lint.Run(sys.argv[1:]) 8 | File "/usr/lib/python2.4/site-packages/pylint/lint.py", line 729, in __init__ 9 | linter.check(args) 10 | File "/usr/lib/python2.4/site-packages/pylint/lint.py", line 412, in check 11 | self.check_file(filepath, modname, checkers) 12 | File "/usr/lib/python2.4/site-packages/pylint/lint.py", line 426, in check_file 13 | astroid = self._check_file(filepath, modname, checkers) 14 | File "/usr/lib/python2.4/site-packages/pylint/lint.py", line 450, in _check_file 15 | self.check_astroid_module(astroid, checkers) 16 | File "/usr/lib/python2.4/site-packages/pylint/lint.py", line 494, in check_astroid_module 17 | self.astroid_events(astroid, [checker for checker in checkers 18 | File "/usr/lib/python2.4/site-packages/pylint/lint.py", line 511, in astroid_events 19 | self.astroid_events(child, checkers, _reversed_checkers) 20 | File "/usr/lib/python2.4/site-packages/pylint/lint.py", line 511, in astroid_events 21 | self.astroid_events(child, checkers, _reversed_checkers) 22 | File "/usr/lib/python2.4/site-packages/pylint/lint.py", line 508, in astroid_events 23 | checker.visit(astroid) 24 | File "/usr/lib/python2.4/site-packages/logilab/astroid/utils.py", line 84, in visit 25 | method(node) 26 | File "/usr/lib/python2.4/site-packages/pylint/checkers/variables.py", line 295, in visit_import 27 | self._check_module_attrs(node, module, name_parts[1:]) 28 | File "/usr/lib/python2.4/site-packages/pylint/checkers/variables.py", line 357, in _check_module_attrs 29 | self.add_message('E0611', args=(name, module.name), 30 | AttributeError: Import instance has no attribute 'name' 31 | 32 | 33 | You can reproduce it by: 34 | (1) create package structure like the following: 35 | 36 | package/ 37 | __init__.py 38 | subpackage/ 39 | __init__.py 40 | module.py 41 | 42 | (2) in package/__init__.py write: 43 | 44 | import subpackage 45 | 46 | (3) run pylint with a script importing package.subpackage.module. 47 | """ 48 | __revision__ = '$Id: import_package_subpackage_module.py,v 1.1 2005-11-10 15:59:32 syt Exp $' 49 | import package.subpackage.module 50 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/package/import_package_subpackage_module.py: -------------------------------------------------------------------------------- 1 | # pylint: disable-msg=I0011,C0301,W0611 2 | """I found some of my scripts trigger off an AttributeError in pylint 3 | 0.8.1 (with common 0.12.0 and astroid 0.13.1). 4 | 5 | Traceback (most recent call last): 6 | File "/usr/bin/pylint", line 4, in ? 7 | lint.Run(sys.argv[1:]) 8 | File "/usr/lib/python2.4/site-packages/pylint/lint.py", line 729, in __init__ 9 | linter.check(args) 10 | File "/usr/lib/python2.4/site-packages/pylint/lint.py", line 412, in check 11 | self.check_file(filepath, modname, checkers) 12 | File "/usr/lib/python2.4/site-packages/pylint/lint.py", line 426, in check_file 13 | astroid = self._check_file(filepath, modname, checkers) 14 | File "/usr/lib/python2.4/site-packages/pylint/lint.py", line 450, in _check_file 15 | self.check_astroid_module(astroid, checkers) 16 | File "/usr/lib/python2.4/site-packages/pylint/lint.py", line 494, in check_astroid_module 17 | self.astroid_events(astroid, [checker for checker in checkers 18 | File "/usr/lib/python2.4/site-packages/pylint/lint.py", line 511, in astroid_events 19 | self.astroid_events(child, checkers, _reversed_checkers) 20 | File "/usr/lib/python2.4/site-packages/pylint/lint.py", line 511, in astroid_events 21 | self.astroid_events(child, checkers, _reversed_checkers) 22 | File "/usr/lib/python2.4/site-packages/pylint/lint.py", line 508, in astroid_events 23 | checker.visit(astroid) 24 | File "/usr/lib/python2.4/site-packages/logilab/astroid/utils.py", line 84, in visit 25 | method(node) 26 | File "/usr/lib/python2.4/site-packages/pylint/checkers/variables.py", line 295, in visit_import 27 | self._check_module_attrs(node, module, name_parts[1:]) 28 | File "/usr/lib/python2.4/site-packages/pylint/checkers/variables.py", line 357, in _check_module_attrs 29 | self.add_message('E0611', args=(name, module.name), 30 | AttributeError: Import instance has no attribute 'name' 31 | 32 | 33 | You can reproduce it by: 34 | (1) create package structure like the following: 35 | 36 | package/ 37 | __init__.py 38 | subpackage/ 39 | __init__.py 40 | module.py 41 | 42 | (2) in package/__init__.py write: 43 | 44 | import subpackage 45 | 46 | (3) run pylint with a script importing package.subpackage.module. 47 | """ 48 | __revision__ = '$Id: import_package_subpackage_module.py,v 1.1 2005-11-10 15:59:32 syt Exp $' 49 | import package.subpackage.module 50 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid-1.6.5.dist-info/DESCRIPTION.rst: -------------------------------------------------------------------------------- 1 | Astroid 2 | ======= 3 | 4 | .. image:: https://travis-ci.org/PyCQA/astroid.svg?branch=master 5 | :target: https://travis-ci.org/PyCQA/astroid 6 | 7 | .. image:: https://ci.appveyor.com/api/projects/status/co3u42kunguhbh6l/branch/master?svg=true 8 | :alt: AppVeyor Build Status 9 | :target: https://ci.appveyor.com/project/PCManticore/astroid 10 | 11 | .. image:: https://coveralls.io/repos/github/PyCQA/astroid/badge.svg?branch=master 12 | :target: https://coveralls.io/github/PyCQA/astroid?branch=master 13 | 14 | .. image:: https://readthedocs.org/projects/astroid/badge/?version=latest 15 | :target: http://astroid.readthedocs.io/en/latest/?badge=latest 16 | :alt: Documentation Status 17 | 18 | 19 | 20 | What's this? 21 | ------------ 22 | 23 | The aim of this module is to provide a common base representation of 24 | python source code for projects such as pychecker, pyreverse, 25 | pylint... Well, actually the development of this library is essentially 26 | governed by pylint's needs. It used to be called logilab-astng. 27 | 28 | It provides a compatible representation which comes from the `_ast` 29 | module. It rebuilds the tree generated by the builtin _ast module by 30 | recursively walking down the AST and building an extended ast. The new 31 | node classes have additional methods and attributes for different 32 | usages. They include some support for static inference and local name 33 | scopes. Furthermore, astroid builds partial trees by inspecting living 34 | objects. 35 | 36 | 37 | Installation 38 | ------------ 39 | 40 | Extract the tarball, jump into the created directory and run:: 41 | 42 | python setup.py install 43 | 44 | For installation options, see:: 45 | 46 | python setup.py install --help 47 | 48 | 49 | If you have any questions, please mail the code-quality@python.org 50 | mailing list for support. See 51 | http://mail.python.org/mailman/listinfo/code-quality for subscription 52 | information and archives. You may find older archives at 53 | http://lists.logilab.org/mailman/listinfo/python-projects . 54 | 55 | Python Versions 56 | --------------- 57 | 58 | astroid is compatible with Python 2.7 as well as 3.4 and later. astroid uses 59 | the same code base for both Python versions, using six. 60 | 61 | Test 62 | ---- 63 | 64 | Tests are in the 'test' subdirectory. To launch the whole tests suite 65 | at once, you can use unittest discover:: 66 | 67 | python -m unittest discover -p "unittest*.py" 68 | 69 | 70 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/brain/brain_collections.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Claudiu Popa 2 | 3 | # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html 4 | # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER 5 | import sys 6 | 7 | import astroid 8 | 9 | PY35 = sys.version_info >= (3, 5) 10 | 11 | 12 | def _collections_transform(): 13 | return astroid.parse(''' 14 | class defaultdict(dict): 15 | default_factory = None 16 | def __missing__(self, key): pass 17 | def __getitem__(self, key): return default_factory 18 | 19 | ''' + _deque_mock() + ''' 20 | 21 | class OrderedDict(dict): 22 | def __reversed__(self): return self[::-1] 23 | ''') 24 | 25 | 26 | def _deque_mock(): 27 | base_deque_class = ''' 28 | class deque(object): 29 | maxlen = 0 30 | def __init__(self, iterable=None, maxlen=None): 31 | self.iterable = iterable 32 | def append(self, x): pass 33 | def appendleft(self, x): pass 34 | def clear(self): pass 35 | def count(self, x): return 0 36 | def extend(self, iterable): pass 37 | def extendleft(self, iterable): pass 38 | def pop(self): pass 39 | def popleft(self): pass 40 | def remove(self, value): pass 41 | def reverse(self): pass 42 | def rotate(self, n=1): pass 43 | def __iter__(self): return self 44 | def __reversed__(self): return self.iterable[::-1] 45 | def __getitem__(self, index): pass 46 | def __setitem__(self, index, value): pass 47 | def __delitem__(self, index): pass 48 | def __bool__(self): return bool(self.iterable) 49 | def __nonzero__(self): return bool(self.iterable) 50 | def __contains__(self, o): return o in self.iterable 51 | def __len__(self): return len(self.iterable) 52 | def __copy__(self): return deque(self.iterable)''' 53 | if PY35: 54 | base_deque_class += ''' 55 | def copy(self): return deque(self.iterable) 56 | def index(self, x, start=0, end=0): return 0 57 | def insert(self, x, i): pass 58 | def __add__(self, other): pass 59 | def __iadd__(self, other): pass 60 | def __mul__(self, other): pass 61 | def __imul__(self, other): pass 62 | def __rmul__(self, other): pass''' 63 | return base_deque_class 64 | 65 | astroid.register_module_extender(astroid.MANAGER, 'collections', _collections_transform) 66 | 67 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/brain/brain_pytest.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014-2016 Claudiu Popa 2 | # Copyright (c) 2016 Cara Vinson 3 | 4 | # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html 5 | # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER 6 | 7 | """Astroid hooks for pytest.""" 8 | from __future__ import absolute_import 9 | from astroid import MANAGER, register_module_extender 10 | from astroid.builder import AstroidBuilder 11 | 12 | 13 | def pytest_transform(): 14 | return AstroidBuilder(MANAGER).string_build(''' 15 | 16 | try: 17 | import _pytest.mark 18 | import _pytest.recwarn 19 | import _pytest.runner 20 | import _pytest.python 21 | import _pytest.skipping 22 | import _pytest.assertion 23 | except ImportError: 24 | pass 25 | else: 26 | deprecated_call = _pytest.recwarn.deprecated_call 27 | warns = _pytest.recwarn.warns 28 | 29 | exit = _pytest.runner.exit 30 | fail = _pytest.runner.fail 31 | skip = _pytest.runner.skip 32 | importorskip = _pytest.runner.importorskip 33 | 34 | xfail = _pytest.skipping.xfail 35 | mark = _pytest.mark.MarkGenerator() 36 | raises = _pytest.python.raises 37 | 38 | # New in pytest 3.0 39 | try: 40 | approx = _pytest.python.approx 41 | register_assert_rewrite = _pytest.assertion.register_assert_rewrite 42 | except AttributeError: 43 | pass 44 | 45 | 46 | # Moved in pytest 3.0 47 | 48 | try: 49 | import _pytest.freeze_support 50 | freeze_includes = _pytest.freeze_support.freeze_includes 51 | except ImportError: 52 | try: 53 | import _pytest.genscript 54 | freeze_includes = _pytest.genscript.freeze_includes 55 | except ImportError: 56 | pass 57 | 58 | try: 59 | import _pytest.debugging 60 | set_trace = _pytest.debugging.pytestPDB().set_trace 61 | except ImportError: 62 | try: 63 | import _pytest.pdb 64 | set_trace = _pytest.pdb.pytestPDB().set_trace 65 | except ImportError: 66 | pass 67 | 68 | try: 69 | import _pytest.fixtures 70 | fixture = _pytest.fixtures.fixture 71 | yield_fixture = _pytest.fixtures.yield_fixture 72 | except ImportError: 73 | try: 74 | import _pytest.python 75 | fixture = _pytest.python.fixture 76 | yield_fixture = _pytest.python.yield_fixture 77 | except ImportError: 78 | pass 79 | ''') 80 | 81 | register_module_extender(MANAGER, 'pytest', pytest_transform) 82 | register_module_extender(MANAGER, 'py.test', pytest_transform) 83 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/brain/brain_functools.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Claudiu Popa 2 | 3 | """Astroid hooks for understanding functools library module.""" 4 | 5 | import astroid 6 | from astroid import BoundMethod 7 | from astroid import extract_node 8 | from astroid import helpers 9 | from astroid.interpreter import objectmodel 10 | from astroid import MANAGER 11 | 12 | 13 | LRU_CACHE = 'functools.lru_cache' 14 | 15 | 16 | class LruWrappedModel(objectmodel.FunctionModel): 17 | """Special attribute model for functions decorated with functools.lru_cache. 18 | 19 | The said decorators patches at decoration time some functions onto 20 | the decorated function. 21 | """ 22 | 23 | @property 24 | def py__wrapped__(self): 25 | return self._instance 26 | 27 | @property 28 | def pycache_info(self): 29 | cache_info = extract_node(''' 30 | from functools import _CacheInfo 31 | _CacheInfo(0, 0, 0, 0) 32 | ''') 33 | class CacheInfoBoundMethod(BoundMethod): 34 | def infer_call_result(self, caller, context=None): 35 | yield helpers.safe_infer(cache_info) 36 | 37 | return CacheInfoBoundMethod(proxy=self._instance, bound=self._instance) 38 | 39 | @property 40 | def pycache_clear(self): 41 | node = extract_node('''def cache_clear(self): pass''') 42 | return BoundMethod(proxy=node, bound=self._instance.parent.scope()) 43 | 44 | 45 | def _transform_lru_cache(node, context=None): 46 | # TODO: this is not ideal, since the node should be immutable, 47 | # but due to https://github.com/PyCQA/astroid/issues/354, 48 | # there's not much we can do now. 49 | # Replacing the node would work partially, because, 50 | # in pylint, the old node would still be available, leading 51 | # to spurious false positives. 52 | node.special_attributes = LruWrappedModel()(node) 53 | return 54 | 55 | 56 | def _looks_like_lru_cache(node): 57 | """Check if the given function node is decorated with lru_cache.""" 58 | if not node.decorators: 59 | return False 60 | 61 | for decorator in node.decorators.nodes: 62 | if not isinstance(decorator, astroid.Call): 63 | continue 64 | 65 | func = helpers.safe_infer(decorator.func) 66 | if func in (None, astroid.Uninferable): 67 | continue 68 | 69 | if isinstance(func, astroid.FunctionDef) and func.qname() == LRU_CACHE: 70 | return True 71 | return False 72 | 73 | 74 | MANAGER.register_transform(astroid.FunctionDef, _transform_lru_cache, 75 | _looks_like_lru_cache) 76 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/nodes.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2006-2011, 2013 LOGILAB S.A. (Paris, FRANCE) 2 | # Copyright (c) 2014-2016 Claudiu Popa 3 | # Copyright (c) 2014 Google, Inc. 4 | # Copyright (c) 2015-2016 Cara Vinson 5 | 6 | # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html 7 | # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER 8 | 9 | """Every available node class. 10 | 11 | .. seealso:: 12 | :doc:`ast documentation ` 13 | 14 | All nodes inherit from :class:`~astroid.node_classes.NodeNG`. 15 | """ 16 | # pylint: disable=unused-import,redefined-builtin 17 | 18 | from astroid.node_classes import ( 19 | Arguments, AssignAttr, Assert, Assign, AnnAssign, 20 | AssignName, AugAssign, Repr, BinOp, BoolOp, Break, Call, Compare, 21 | Comprehension, Const, Continue, Decorators, DelAttr, DelName, Delete, 22 | Dict, Expr, Ellipsis, EmptyNode, ExceptHandler, Exec, ExtSlice, For, 23 | ImportFrom, Attribute, Global, If, IfExp, Import, Index, Keyword, 24 | List, Name, Nonlocal, Pass, Print, Raise, Return, Set, Slice, Starred, Subscript, 25 | TryExcept, TryFinally, Tuple, UnaryOp, While, With, Yield, YieldFrom, 26 | const_factory, 27 | AsyncFor, Await, AsyncWith, 28 | FormattedValue, JoinedStr, 29 | # Backwards-compatibility aliases 30 | Backquote, Discard, AssName, AssAttr, Getattr, CallFunc, From, 31 | # Node not present in the builtin ast module. 32 | DictUnpack, 33 | Unknown, 34 | ) 35 | from astroid.scoped_nodes import ( 36 | Module, GeneratorExp, Lambda, DictComp, 37 | ListComp, SetComp, FunctionDef, ClassDef, 38 | AsyncFunctionDef, 39 | # Backwards-compatibility aliases 40 | Class, Function, GenExpr, 41 | ) 42 | 43 | 44 | 45 | ALL_NODE_CLASSES = ( 46 | AsyncFunctionDef, AsyncFor, AsyncWith, Await, 47 | 48 | Arguments, AssignAttr, Assert, Assign, AnnAssign, AssignName, AugAssign, 49 | Repr, BinOp, BoolOp, Break, 50 | Call, ClassDef, Compare, Comprehension, Const, Continue, 51 | Decorators, DelAttr, DelName, Delete, 52 | Dict, DictComp, DictUnpack, Expr, 53 | Ellipsis, EmptyNode, ExceptHandler, Exec, ExtSlice, 54 | For, ImportFrom, FunctionDef, 55 | Attribute, GeneratorExp, Global, 56 | If, IfExp, Import, Index, 57 | Keyword, 58 | Lambda, List, ListComp, 59 | Name, Nonlocal, 60 | Module, 61 | Pass, Print, 62 | Raise, Return, 63 | Set, SetComp, Slice, Starred, Subscript, 64 | TryExcept, TryFinally, Tuple, 65 | UnaryOp, 66 | While, With, 67 | Yield, YieldFrom, 68 | FormattedValue, JoinedStr, 69 | ) 70 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/interpreter/dunder_lookup.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Claudiu Popa 2 | # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html 3 | # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER 4 | 5 | """Contains logic for retrieving special methods. 6 | 7 | This implementation does not rely on the dot attribute access 8 | logic, found in ``.getattr()``. The difference between these two 9 | is that the dunder methods are looked with the type slots 10 | (you can find more about these here 11 | http://lucumr.pocoo.org/2014/8/16/the-python-i-would-like-to-see/) 12 | As such, the lookup for the special methods is actually simpler than 13 | the dot attribute access. 14 | """ 15 | import itertools 16 | 17 | import astroid 18 | from astroid import exceptions 19 | 20 | 21 | def _lookup_in_mro(node, name): 22 | attrs = node.locals.get(name, []) 23 | 24 | nodes = itertools.chain.from_iterable( 25 | ancestor.locals.get(name, []) 26 | for ancestor in node.ancestors(recurs=True) 27 | ) 28 | values = list(itertools.chain(attrs, nodes)) 29 | if not values: 30 | raise exceptions.AttributeInferenceError( 31 | attribute=name, 32 | target=node 33 | ) 34 | 35 | return values 36 | 37 | 38 | def lookup(node, name): 39 | """Lookup the given special method name in the given *node* 40 | 41 | If the special method was found, then a list of attributes 42 | will be returned. Otherwise, `astroid.AttributeInferenceError` 43 | is going to be raised. 44 | """ 45 | if isinstance(node, (astroid.List, 46 | astroid.Tuple, 47 | astroid.Const, 48 | astroid.Dict, 49 | astroid.Set)): 50 | return _builtin_lookup(node, name) 51 | elif isinstance(node, astroid.Instance): 52 | return _lookup_in_mro(node, name) 53 | elif isinstance(node, astroid.ClassDef): 54 | return _class_lookup(node, name) 55 | 56 | raise exceptions.AttributeInferenceError( 57 | attribute=name, 58 | target=node 59 | ) 60 | 61 | 62 | def _class_lookup(node, name): 63 | metaclass = node.metaclass() 64 | if metaclass is None: 65 | raise exceptions.AttributeInferenceError( 66 | attribute=name, 67 | target=node 68 | ) 69 | 70 | return _lookup_in_mro(metaclass, name) 71 | 72 | 73 | def _builtin_lookup(node, name): 74 | values = node.locals.get(name, []) 75 | if not values: 76 | raise exceptions.AttributeInferenceError( 77 | attribute=name, 78 | target=node 79 | ) 80 | 81 | return values 82 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/astpeephole.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2015-2016 Claudiu Popa 2 | 3 | # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html 4 | # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER 5 | 6 | """Small AST optimizations.""" 7 | 8 | import _ast 9 | 10 | from astroid import nodes 11 | 12 | 13 | __all__ = ('ASTPeepholeOptimizer', ) 14 | 15 | 16 | try: 17 | _TYPES = (_ast.Str, _ast.Bytes) 18 | except AttributeError: 19 | _TYPES = (_ast.Str, ) 20 | 21 | 22 | class ASTPeepholeOptimizer(object): 23 | """Class for applying small optimizations to generate new AST.""" 24 | 25 | def optimize_binop(self, node, parent=None): 26 | """Optimize BinOps with string Const nodes on the lhs. 27 | 28 | This fixes an infinite recursion crash, where multiple 29 | strings are joined using the addition operator. With a 30 | sufficient number of such strings, astroid will fail 31 | with a maximum recursion limit exceeded. The 32 | function will return a Const node with all the strings 33 | already joined. 34 | Return ``None`` if no AST node can be obtained 35 | through optimization. 36 | """ 37 | ast_nodes = [] 38 | current = node 39 | while isinstance(current, _ast.BinOp): 40 | # lhs must be a BinOp with the addition operand. 41 | if not isinstance(current.left, _ast.BinOp): 42 | return None 43 | if (not isinstance(current.left.op, _ast.Add) 44 | or not isinstance(current.op, _ast.Add)): 45 | return None 46 | 47 | # rhs must a str / bytes. 48 | if not isinstance(current.right, _TYPES): 49 | return None 50 | 51 | ast_nodes.append(current.right.s) 52 | current = current.left 53 | 54 | if (isinstance(current, _ast.BinOp) 55 | and isinstance(current.left, _TYPES) 56 | and isinstance(current.right, _TYPES)): 57 | # Stop early if we are at the last BinOp in 58 | # the operation 59 | ast_nodes.append(current.right.s) 60 | ast_nodes.append(current.left.s) 61 | break 62 | 63 | if not ast_nodes: 64 | return None 65 | 66 | # If we have inconsistent types, bail out. 67 | known = type(ast_nodes[0]) 68 | if any(not isinstance(element, known) 69 | for element in ast_nodes[1:]): 70 | return None 71 | 72 | value = known().join(reversed(ast_nodes)) 73 | newnode = nodes.Const(value, node.lineno, node.col_offset, parent) 74 | return newnode 75 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python2/data/module2.py: -------------------------------------------------------------------------------- 1 | from data.module import YO, YOUPI 2 | import data 3 | 4 | 5 | class Specialization(YOUPI, YO): 6 | pass 7 | 8 | 9 | 10 | class Metaclass(type): 11 | pass 12 | 13 | 14 | 15 | class Interface: 16 | pass 17 | 18 | 19 | 20 | class MyIFace(Interface): 21 | pass 22 | 23 | 24 | 25 | class AnotherIFace(Interface): 26 | pass 27 | 28 | 29 | 30 | class MyException(Exception): 31 | pass 32 | 33 | 34 | 35 | class MyError(MyException): 36 | pass 37 | 38 | 39 | 40 | class AbstractClass(object): 41 | 42 | def to_override(self, whatever): 43 | raise NotImplementedError() 44 | 45 | def return_something(self, param): 46 | if param: 47 | return 'toto' 48 | return 49 | 50 | 51 | 52 | class Concrete0: 53 | __implements__ = MyIFace 54 | 55 | 56 | 57 | class Concrete1: 58 | __implements__ = (MyIFace, AnotherIFace) 59 | 60 | 61 | 62 | class Concrete2: 63 | __implements__ = (MyIFace, AnotherIFace) 64 | 65 | 66 | 67 | class Concrete23(Concrete1): 68 | pass 69 | 70 | del YO.member 71 | del YO 72 | [SYN1, SYN2] = (Concrete0, Concrete1) 73 | assert '1' 74 | b = (1) | (((2) & (3)) ^ (8)) 75 | bb = ((1) | (two)) | (6) 76 | ccc = ((one) & (two)) & (three) 77 | dddd = ((x) ^ (o)) ^ (r) 78 | exec 'c = 3' 79 | exec 'c = 3' in {}, {} 80 | 81 | def raise_string(a=2, *args, **kwargs): 82 | raise Exception, 'yo' 83 | yield 'coucou' 84 | yield 85 | a = (b) + (2) 86 | c = (b) * (2) 87 | c = (b) / (2) 88 | c = (b) // (2) 89 | c = (b) - (2) 90 | c = (b) % (2) 91 | c = (b) ** (2) 92 | c = (b) << (2) 93 | c = (b) >> (2) 94 | c = ~b 95 | c = not b 96 | d = [c] 97 | e = d[:] 98 | e = d[a:b:c] 99 | raise_string(*args, **kwargs) 100 | print >> stream, 'bonjour' 101 | print >> stream, 'salut', 102 | 103 | def make_class(any, base=data.module.YO, *args, **kwargs): 104 | """check base is correctly resolved to Concrete0""" 105 | 106 | 107 | class Aaaa(base): 108 | """dynamic class""" 109 | 110 | 111 | return Aaaa 112 | from os.path import abspath 113 | import os as myos 114 | 115 | 116 | class A: 117 | pass 118 | 119 | 120 | 121 | class A(A): 122 | pass 123 | 124 | 125 | def generator(): 126 | """A generator.""" 127 | yield 128 | 129 | def not_a_generator(): 130 | """A function that contains generator, but is not one.""" 131 | 132 | def generator(): 133 | yield 134 | genl = lambda : (yield) 135 | 136 | def with_metaclass(meta, *bases): 137 | return meta('NewBase', bases, {}) 138 | 139 | 140 | class NotMetaclass(with_metaclass(Metaclass)): 141 | pass 142 | 143 | 144 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/testdata/python3/data/module2.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | from data.module import YO, YOUPI 3 | import data 4 | 5 | 6 | class Specialization(YOUPI, YO): 7 | pass 8 | 9 | 10 | 11 | class Metaclass(type): 12 | pass 13 | 14 | 15 | 16 | class Interface: 17 | pass 18 | 19 | 20 | 21 | class MyIFace(Interface): 22 | pass 23 | 24 | 25 | 26 | class AnotherIFace(Interface): 27 | pass 28 | 29 | 30 | 31 | class MyException(Exception): 32 | pass 33 | 34 | 35 | 36 | class MyError(MyException): 37 | pass 38 | 39 | 40 | 41 | class AbstractClass(object): 42 | 43 | def to_override(self, whatever): 44 | raise NotImplementedError() 45 | 46 | def return_something(self, param): 47 | if param: 48 | return 'toto' 49 | return 50 | 51 | 52 | 53 | class Concrete0: 54 | __implements__ = MyIFace 55 | 56 | 57 | 58 | class Concrete1: 59 | __implements__ = (MyIFace, AnotherIFace) 60 | 61 | 62 | 63 | class Concrete2: 64 | __implements__ = (MyIFace, AnotherIFace) 65 | 66 | 67 | 68 | class Concrete23(Concrete1): 69 | pass 70 | 71 | del YO.member 72 | del YO 73 | [SYN1, SYN2] = (Concrete0, Concrete1) 74 | assert repr(1) 75 | b = (1) | (((2) & (3)) ^ (8)) 76 | bb = ((1) | (two)) | (6) 77 | ccc = ((one) & (two)) & (three) 78 | dddd = ((x) ^ (o)) ^ (r) 79 | exec('c = 3') 80 | exec('c = 3', {}, {}) 81 | 82 | def raise_string(a=2, *args, **kwargs): 83 | raise Exception('yo') 84 | yield 'coucou' 85 | yield 86 | a = (b) + (2) 87 | c = (b) * (2) 88 | c = (b) / (2) 89 | c = (b) // (2) 90 | c = (b) - (2) 91 | c = (b) % (2) 92 | c = (b) ** (2) 93 | c = (b) << (2) 94 | c = (b) >> (2) 95 | c = ~b 96 | c = not b 97 | d = [c] 98 | e = d[:] 99 | e = d[a:b:c] 100 | raise_string(*args, **kwargs) 101 | print('bonjour', file=stream) 102 | print('salut', end=' ', file=stream) 103 | 104 | def make_class(any, base=data.module.YO, *args, **kwargs): 105 | """check base is correctly resolved to Concrete0""" 106 | 107 | 108 | class Aaaa(base): 109 | """dynamic class""" 110 | 111 | 112 | return Aaaa 113 | from os.path import abspath 114 | import os as myos 115 | 116 | 117 | class A: 118 | pass 119 | 120 | 121 | 122 | class A(A): 123 | pass 124 | 125 | 126 | def generator(): 127 | """A generator.""" 128 | yield 129 | 130 | def not_a_generator(): 131 | """A function that contains generator, but is not one.""" 132 | 133 | def generator(): 134 | yield 135 | genl = lambda : (yield) 136 | 137 | def with_metaclass(meta, *bases): 138 | return meta('NewBase', bases, {}) 139 | 140 | 141 | class NotMetaclass(with_metaclass(Metaclass)): 142 | pass 143 | 144 | 145 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/__pkginfo__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2006-2014 LOGILAB S.A. (Paris, FRANCE) 2 | # Copyright (c) 2014-2016 Claudiu Popa 3 | # Copyright (c) 2014 Google, Inc. 4 | 5 | # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html 6 | # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER 7 | 8 | """astroid packaging information""" 9 | 10 | from sys import version_info as py_version 11 | 12 | from pkg_resources import parse_version 13 | from setuptools import __version__ as setuptools_version 14 | 15 | distname = 'astroid' 16 | 17 | modname = 'astroid' 18 | 19 | version = '1.6.5' 20 | numversion = tuple(map(int, version.split('.'))) 21 | 22 | extras_require = {} 23 | install_requires = ['lazy_object_proxy', 'six', 'wrapt'] 24 | 25 | 26 | def has_environment_marker_range_operators_support(): 27 | """Code extracted from 'pytest/setup.py' 28 | https://github.com/pytest-dev/pytest/blob/7538680c/setup.py#L31 29 | 30 | The first known release to support environment marker with range operators 31 | it is 17.1, see: https://setuptools.readthedocs.io/en/latest/history.html#id113 32 | """ 33 | return parse_version(setuptools_version) >= parse_version('17.1') 34 | 35 | 36 | if has_environment_marker_range_operators_support(): 37 | extras_require[':python_version<"3.4"'] = ['enum34>=1.1.3', 38 | 'singledispatch', 39 | 'backports.functools_lru_cache'] 40 | else: 41 | if py_version < (3, 4): 42 | install_requires.extend(['enum34', 43 | 'singledispatch', 44 | 'backports.functools_lru_cache']) 45 | 46 | 47 | # pylint: disable=redefined-builtin; why license is a builtin anyway? 48 | license = 'LGPL' 49 | 50 | author = 'Python Code Quality Authority' 51 | author_email = 'code-quality@python.org' 52 | mailinglist = "mailto://%s" % author_email 53 | web = 'https://github.com/PyCQA/astroid' 54 | 55 | description = "A abstract syntax tree for Python with inference support." 56 | 57 | classifiers = ["Topic :: Software Development :: Libraries :: Python Modules", 58 | "Topic :: Software Development :: Quality Assurance", 59 | "Programming Language :: Python", 60 | "Programming Language :: Python :: 2", 61 | "Programming Language :: Python :: 2.7", 62 | "Programming Language :: Python :: 3", 63 | "Programming Language :: Python :: 3.4", 64 | "Programming Language :: Python :: 3.5", 65 | "Programming Language :: Python :: 3.6", 66 | "Programming Language :: Python :: Implementation :: CPython", 67 | "Programming Language :: Python :: Implementation :: PyPy", 68 | ] 69 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/trimmer/call_visitor.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # IMPORT THIRD-PARTY LIBRARIES 5 | try: 6 | from astroid import as_string 7 | except ImportError: 8 | import sys 9 | import os 10 | 11 | _ROOT = os.path.join(os.path.dirname(os.path.realpath(__file__))) 12 | sys.path.append(os.path.join(_ROOT, 'vendors')) 13 | 14 | from astroid import as_string 15 | 16 | 17 | class MultiLineCallVisitor(as_string.AsStringVisitor): 18 | 19 | '''A visitor that re-prints `astroid.Call` nodes in a multi-line style. 20 | 21 | Attributes: 22 | _single_line_exceptions (tuple[str]): 23 | Any functions, by-name, which should not allowed to be made multi-line. 24 | 25 | ''' 26 | 27 | _single_line_exceptions = ('super', ) 28 | 29 | def _format_args(self, args): 30 | '''Change the given arguments into "multi-line" style arguments. 31 | 32 | Args: 33 | args (list[str]): 34 | The list of args/kwargs to change. 35 | 36 | Returns: 37 | list[str]: The multi-line representation of `args`. 38 | 39 | ''' 40 | if not args: 41 | return '' 42 | 43 | # `args` has a chance of being a tuple. We need indexing so convert it to a list 44 | args = list(args) 45 | 46 | # Add proper indentation to every arg 47 | args[0] = '\n{indent}'.format(indent=self.indent) + args[0] 48 | args = [args[0]] + ['{indent}{name}'.format(indent=self.indent, name=name) for name in args[1:]] 49 | 50 | # Add commas to every arg, including the last arg 51 | args[-1] += ',\n' 52 | args = ',\n'.join(args) 53 | 54 | return args 55 | 56 | def _get_args(self, node): 57 | '''list[str]: Add newline and extra space to each arg and kwarg.''' 58 | args = [arg.accept(self) for arg in node.args] 59 | 60 | keywords = [] 61 | 62 | if node.keywords: 63 | keywords = [kwarg.accept(self) for kwarg in node.keywords] 64 | 65 | args.extend(keywords) 66 | return self._format_args(args) 67 | 68 | def visit_call(self, node): 69 | '''Expand an `astroid.Call` object into a valid Python string. 70 | 71 | Args: 72 | node (`astroid.Call`): The node to create a string representation for. 73 | 74 | Returns: 75 | str: The printable representation of the given `node`. 76 | 77 | ''' 78 | expression = node.func.accept(self) 79 | 80 | try: 81 | if node.func.name in self._single_line_exceptions: 82 | return node.as_string() 83 | except AttributeError: 84 | # This only happens if node is a `astroid.Attribute` 85 | # An attribute will never be in the list of function exceptions so 86 | # just ignore it. 87 | # 88 | pass 89 | 90 | args = self._get_args(node) 91 | 92 | return '{expression}({args})'.format(expression=expression, args=args) 93 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/brain/brain_typing.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 David Euresti 2 | 3 | """Astroid hooks for typing.py support.""" 4 | import textwrap 5 | 6 | from astroid import ( 7 | MANAGER, UseInferenceDefault, extract_node, inference_tip, 8 | nodes, InferenceError) 9 | from astroid.nodes import List, Tuple 10 | 11 | 12 | TYPING_NAMEDTUPLE_BASENAMES = { 13 | 'NamedTuple', 14 | 'typing.NamedTuple' 15 | } 16 | 17 | 18 | def infer_typing_namedtuple(node, context=None): 19 | """Infer a typing.NamedTuple(...) call.""" 20 | # This is essentially a namedtuple with different arguments 21 | # so we extract the args and infer a named tuple. 22 | try: 23 | func = next(node.func.infer()) 24 | except InferenceError: 25 | raise UseInferenceDefault 26 | 27 | if func.qname() != 'typing.NamedTuple': 28 | raise UseInferenceDefault 29 | 30 | if len(node.args) != 2: 31 | raise UseInferenceDefault 32 | 33 | if not isinstance(node.args[1], (List, Tuple)): 34 | raise UseInferenceDefault 35 | 36 | names = [] 37 | for elt in node.args[1].elts: 38 | if not isinstance(elt, (List, Tuple)): 39 | raise UseInferenceDefault 40 | if len(elt.elts) != 2: 41 | raise UseInferenceDefault 42 | names.append(elt.elts[0].as_string()) 43 | 44 | typename = node.args[0].as_string() 45 | node = extract_node('namedtuple(%(typename)s, (%(fields)s,)) ' % 46 | {'typename': typename, 'fields': ",".join(names)}) 47 | return node.infer(context=context) 48 | 49 | 50 | def infer_typing_namedtuple_class(node, context=None): 51 | """Infer a subclass of typing.NamedTuple""" 52 | 53 | # Check if it has the corresponding bases 54 | annassigns_fields = [ 55 | annassign.target.name for annassign in node.body 56 | if isinstance(annassign, nodes.AnnAssign) 57 | ] 58 | code = textwrap.dedent(''' 59 | from collections import namedtuple 60 | namedtuple({typename!r}, {fields!r}) 61 | ''').format( 62 | typename=node.name, 63 | fields=",".join(annassigns_fields) 64 | ) 65 | node = extract_node(code) 66 | return node.infer(context=context) 67 | 68 | 69 | def has_namedtuple_base(node): 70 | """Predicate for class inference tip 71 | 72 | :type node: ClassDef 73 | :rtype: bool 74 | """ 75 | return set(node.basenames) & TYPING_NAMEDTUPLE_BASENAMES 76 | 77 | 78 | def looks_like_typing_namedtuple(node): 79 | func = node.func 80 | if isinstance(func, nodes.Attribute): 81 | return func.attrname == 'NamedTuple' 82 | if isinstance(func, nodes.Name): 83 | return func.name == 'NamedTuple' 84 | return False 85 | 86 | 87 | MANAGER.register_transform( 88 | nodes.Call, 89 | inference_tip(infer_typing_namedtuple), 90 | looks_like_typing_namedtuple 91 | ) 92 | 93 | MANAGER.register_transform( 94 | nodes.ClassDef, 95 | inference_tip(infer_typing_namedtuple_class), 96 | has_namedtuple_base 97 | ) 98 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/brain/brain_random.py: -------------------------------------------------------------------------------- 1 | # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html 2 | # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER 3 | import random 4 | 5 | import astroid 6 | from astroid import helpers 7 | from astroid import MANAGER 8 | 9 | 10 | ACCEPTED_ITERABLES_FOR_SAMPLE = ( 11 | astroid.List, 12 | astroid.Set, 13 | astroid.Tuple, 14 | ) 15 | 16 | 17 | def _clone_node_with_lineno(node, parent, lineno): 18 | cls = node.__class__ 19 | other_fields = node._other_fields 20 | _astroid_fields = node._astroid_fields 21 | init_params = { 22 | 'lineno': lineno, 23 | 'col_offset': node.col_offset, 24 | 'parent': parent 25 | } 26 | postinit_params = { 27 | param: getattr(node, param) 28 | for param in _astroid_fields 29 | } 30 | if other_fields: 31 | init_params.update({ 32 | param: getattr(node, param) 33 | for param in other_fields 34 | }) 35 | new_node = cls(**init_params) 36 | if hasattr(node, 'postinit') and _astroid_fields: 37 | new_node.postinit(**postinit_params) 38 | return new_node 39 | 40 | 41 | def infer_random_sample(node, context=None): 42 | if len(node.args) != 2: 43 | raise astroid.UseInferenceDefault 44 | 45 | length = node.args[1] 46 | if not isinstance(length, astroid.Const): 47 | raise astroid.UseInferenceDefault 48 | if not isinstance(length.value, int): 49 | raise astroid.UseInferenceDefault 50 | 51 | inferred_sequence = helpers.safe_infer(node.args[0], context=context) 52 | if inferred_sequence in (None, astroid.Uninferable): 53 | raise astroid.UseInferenceDefault 54 | 55 | # TODO: might need to support more cases 56 | if not isinstance(inferred_sequence, ACCEPTED_ITERABLES_FOR_SAMPLE): 57 | raise astroid.UseInferenceDefault 58 | 59 | if length.value > len(inferred_sequence.elts): 60 | # In this case, this will raise a ValueError 61 | raise astroid.UseInferenceDefault 62 | 63 | try: 64 | elts = random.sample(inferred_sequence.elts, length.value) 65 | except ValueError: 66 | raise astroid.UseInferenceDefault 67 | 68 | new_node = astroid.List( 69 | lineno=node.lineno, 70 | col_offset=node.col_offset, 71 | parent=node.scope(), 72 | ) 73 | new_elts = [ 74 | _clone_node_with_lineno( 75 | elt, 76 | parent=new_node, 77 | lineno=new_node.lineno 78 | ) 79 | for elt in elts 80 | ] 81 | new_node.postinit(new_elts) 82 | return iter((new_node, )) 83 | 84 | 85 | def _looks_like_random_sample(node): 86 | func = node.func 87 | if isinstance(func, astroid.Attribute): 88 | return func.attrname == 'sample' 89 | if isinstance(func, astroid.Name): 90 | return func.name == 'sample' 91 | return False 92 | 93 | 94 | MANAGER.register_transform( 95 | astroid.Call, 96 | astroid.inference_tip(infer_random_sample), 97 | _looks_like_random_sample, 98 | ) 99 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/transforms.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2015-2016 Claudiu Popa 2 | 3 | # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html 4 | # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER 5 | 6 | 7 | import collections 8 | import warnings 9 | 10 | 11 | class TransformVisitor(object): 12 | """A visitor for handling transforms. 13 | 14 | The standard approach of using it is to call 15 | :meth:`~visit` with an *astroid* module and the class 16 | will take care of the rest, walking the tree and running the 17 | transforms for each encountered node. 18 | """ 19 | 20 | def __init__(self): 21 | self.transforms = collections.defaultdict(list) 22 | 23 | def _transform(self, node): 24 | """Call matching transforms for the given node if any and return the 25 | transformed node. 26 | """ 27 | cls = node.__class__ 28 | if cls not in self.transforms: 29 | # no transform registered for this class of node 30 | return node 31 | 32 | transforms = self.transforms[cls] 33 | orig_node = node # copy the reference 34 | for transform_func, predicate in transforms: 35 | if predicate is None or predicate(node): 36 | ret = transform_func(node) 37 | # if the transformation function returns something, it's 38 | # expected to be a replacement for the node 39 | if ret is not None: 40 | if node is not orig_node: 41 | # node has already be modified by some previous 42 | # transformation, warn about it 43 | warnings.warn('node %s substituted multiple times' % node) 44 | node = ret 45 | return node 46 | 47 | def _visit(self, node): 48 | if hasattr(node, '_astroid_fields'): 49 | for field in node._astroid_fields: 50 | value = getattr(node, field) 51 | visited = self._visit_generic(value) 52 | setattr(node, field, visited) 53 | return self._transform(node) 54 | 55 | def _visit_generic(self, node): 56 | if isinstance(node, list): 57 | return [self._visit_generic(child) for child in node] 58 | elif isinstance(node, tuple): 59 | return tuple(self._visit_generic(child) for child in node) 60 | 61 | return self._visit(node) 62 | 63 | def register_transform(self, node_class, transform, predicate=None): 64 | """Register `transform(node)` function to be applied on the given 65 | astroid's `node_class` if `predicate` is None or returns true 66 | when called with the node as argument. 67 | 68 | The transform function may return a value which is then used to 69 | substitute the original node in the tree. 70 | """ 71 | self.transforms[node_class].append((transform, predicate)) 72 | 73 | def unregister_transform(self, node_class, transform, predicate=None): 74 | """Unregister the given transform.""" 75 | self.transforms[node_class].remove((transform, predicate)) 76 | 77 | def visit(self, module): 78 | """Walk the given astroid *tree* and transform each encountered node 79 | 80 | Only the nodes which have transforms registered will actually 81 | be replaced or changed. 82 | """ 83 | module.body = [self._visit(child) for child in module.body] 84 | return self._transform(module) 85 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/brain/brain_multiprocessing.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Claudiu Popa 2 | 3 | # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html 4 | # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER 5 | 6 | import sys 7 | 8 | import astroid 9 | from astroid import exceptions 10 | 11 | 12 | PY34 = sys.version_info >= (3, 4) 13 | 14 | 15 | def _multiprocessing_transform(): 16 | module = astroid.parse(''' 17 | from multiprocessing.managers import SyncManager 18 | def Manager(): 19 | return SyncManager() 20 | ''') 21 | if not PY34: 22 | return module 23 | 24 | # On Python 3.4, multiprocessing uses a getattr lookup inside contexts, 25 | # in order to get the attributes they need. Since it's extremely 26 | # dynamic, we use this approach to fake it. 27 | node = astroid.parse(''' 28 | from multiprocessing.context import DefaultContext, BaseContext 29 | default = DefaultContext() 30 | base = BaseContext() 31 | ''') 32 | try: 33 | context = next(node['default'].infer()) 34 | base = next(node['base'].infer()) 35 | except exceptions.InferenceError: 36 | return module 37 | 38 | for node in (context, base): 39 | for key, value in node.locals.items(): 40 | if key.startswith("_"): 41 | continue 42 | 43 | value = value[0] 44 | if isinstance(value, astroid.FunctionDef): 45 | # We need to rebound this, since otherwise 46 | # it will have an extra argument (self). 47 | value = astroid.BoundMethod(value, node) 48 | module[key] = value 49 | return module 50 | 51 | 52 | def _multiprocessing_managers_transform(): 53 | return astroid.parse(''' 54 | import array 55 | import threading 56 | import multiprocessing.pool as pool 57 | 58 | import six 59 | 60 | class Namespace(object): 61 | pass 62 | 63 | class Value(object): 64 | def __init__(self, typecode, value, lock=True): 65 | self._typecode = typecode 66 | self._value = value 67 | def get(self): 68 | return self._value 69 | def set(self, value): 70 | self._value = value 71 | def __repr__(self): 72 | return '%s(%r, %r)'%(type(self).__name__, self._typecode, self._value) 73 | value = property(get, set) 74 | 75 | def Array(typecode, sequence, lock=True): 76 | return array.array(typecode, sequence) 77 | 78 | class SyncManager(object): 79 | Queue = JoinableQueue = six.moves.queue.Queue 80 | Event = threading.Event 81 | RLock = threading.RLock 82 | BoundedSemaphore = threading.BoundedSemaphore 83 | Condition = threading.Condition 84 | Barrier = threading.Barrier 85 | Pool = pool.Pool 86 | list = list 87 | dict = dict 88 | Value = Value 89 | Array = Array 90 | Namespace = Namespace 91 | __enter__ = lambda self: self 92 | __exit__ = lambda *args: args 93 | 94 | def start(self, initializer=None, initargs=None): 95 | pass 96 | def shutdown(self): 97 | pass 98 | ''') 99 | 100 | 101 | astroid.register_module_extender(astroid.MANAGER, 'multiprocessing.managers', 102 | _multiprocessing_managers_transform) 103 | astroid.register_module_extender(astroid.MANAGER, 'multiprocessing', 104 | _multiprocessing_transform) 105 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/brain/brain_subprocess.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Claudiu Popa 2 | 3 | # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html 4 | # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER 5 | 6 | import sys 7 | import textwrap 8 | 9 | import six 10 | 11 | import astroid 12 | 13 | 14 | PY34 = sys.version_info >= (3, 4) 15 | PY36 = sys.version_info >= (3, 6) 16 | 17 | 18 | def _subprocess_transform(): 19 | if six.PY3: 20 | communicate = (bytes('string', 'ascii'), bytes('string', 'ascii')) 21 | communicate_signature = 'def communicate(self, input=None, timeout=None)' 22 | if PY36: 23 | init = """ 24 | def __init__(self, args, bufsize=0, executable=None, 25 | stdin=None, stdout=None, stderr=None, 26 | preexec_fn=None, close_fds=False, shell=False, 27 | cwd=None, env=None, universal_newlines=False, 28 | startupinfo=None, creationflags=0, restore_signals=True, 29 | start_new_session=False, pass_fds=(), *, 30 | encoding=None, errors=None): 31 | pass 32 | """ 33 | else: 34 | init = """ 35 | def __init__(self, args, bufsize=0, executable=None, 36 | stdin=None, stdout=None, stderr=None, 37 | preexec_fn=None, close_fds=False, shell=False, 38 | cwd=None, env=None, universal_newlines=False, 39 | startupinfo=None, creationflags=0, restore_signals=True, 40 | start_new_session=False, pass_fds=()): 41 | pass 42 | """ 43 | else: 44 | communicate = ('string', 'string') 45 | communicate_signature = 'def communicate(self, input=None)' 46 | init = """ 47 | def __init__(self, args, bufsize=0, executable=None, 48 | stdin=None, stdout=None, stderr=None, 49 | preexec_fn=None, close_fds=False, shell=False, 50 | cwd=None, env=None, universal_newlines=False, 51 | startupinfo=None, creationflags=0): 52 | pass 53 | """ 54 | if PY34: 55 | wait_signature = 'def wait(self, timeout=None)' 56 | else: 57 | wait_signature = 'def wait(self)' 58 | if six.PY3: 59 | ctx_manager = ''' 60 | def __enter__(self): return self 61 | def __exit__(self, *args): pass 62 | ''' 63 | else: 64 | ctx_manager = '' 65 | code = textwrap.dedent(''' 66 | class Popen(object): 67 | returncode = pid = 0 68 | stdin = stdout = stderr = file() 69 | 70 | %(communicate_signature)s: 71 | return %(communicate)r 72 | %(wait_signature)s: 73 | return self.returncode 74 | def poll(self): 75 | return self.returncode 76 | def send_signal(self, signal): 77 | pass 78 | def terminate(self): 79 | pass 80 | def kill(self): 81 | pass 82 | %(ctx_manager)s 83 | ''' % {'communicate': communicate, 84 | 'communicate_signature': communicate_signature, 85 | 'wait_signature': wait_signature, 86 | 'ctx_manager': ctx_manager}) 87 | 88 | init_lines = textwrap.dedent(init).splitlines() 89 | indented_init = '\n'.join([' ' * 4 + line for line in init_lines]) 90 | code += indented_init 91 | return astroid.parse(code) 92 | 93 | 94 | astroid.register_module_extender(astroid.MANAGER, 'subprocess', _subprocess_transform) 95 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/brain/brain_ssl.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Claudiu Popa 2 | 3 | # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html 4 | # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER 5 | 6 | """Astroid hooks for the ssl library.""" 7 | 8 | from astroid import MANAGER, register_module_extender 9 | from astroid.builder import AstroidBuilder 10 | from astroid import nodes 11 | from astroid import parse 12 | 13 | 14 | def ssl_transform(): 15 | return parse(''' 16 | from _ssl import OPENSSL_VERSION_NUMBER, OPENSSL_VERSION_INFO, OPENSSL_VERSION 17 | from _ssl import _SSLContext, MemoryBIO 18 | from _ssl import ( 19 | SSLError, SSLZeroReturnError, SSLWantReadError, SSLWantWriteError, 20 | SSLSyscallError, SSLEOFError, 21 | ) 22 | from _ssl import CERT_NONE, CERT_OPTIONAL, CERT_REQUIRED 23 | from _ssl import txt2obj as _txt2obj, nid2obj as _nid2obj 24 | from _ssl import RAND_status, RAND_add, RAND_bytes, RAND_pseudo_bytes 25 | try: 26 | from _ssl import RAND_egd 27 | except ImportError: 28 | # LibreSSL does not provide RAND_egd 29 | pass 30 | from _ssl import (OP_ALL, OP_CIPHER_SERVER_PREFERENCE, 31 | OP_NO_COMPRESSION, OP_NO_SSLv2, OP_NO_SSLv3, 32 | OP_NO_TLSv1, OP_NO_TLSv1_1, OP_NO_TLSv1_2, 33 | OP_SINGLE_DH_USE, OP_SINGLE_ECDH_USE) 34 | 35 | from _ssl import (ALERT_DESCRIPTION_ACCESS_DENIED, ALERT_DESCRIPTION_BAD_CERTIFICATE, 36 | ALERT_DESCRIPTION_BAD_CERTIFICATE_HASH_VALUE, 37 | ALERT_DESCRIPTION_BAD_CERTIFICATE_STATUS_RESPONSE, 38 | ALERT_DESCRIPTION_BAD_RECORD_MAC, 39 | ALERT_DESCRIPTION_CERTIFICATE_EXPIRED, 40 | ALERT_DESCRIPTION_CERTIFICATE_REVOKED, 41 | ALERT_DESCRIPTION_CERTIFICATE_UNKNOWN, 42 | ALERT_DESCRIPTION_CERTIFICATE_UNOBTAINABLE, 43 | ALERT_DESCRIPTION_CLOSE_NOTIFY, ALERT_DESCRIPTION_DECODE_ERROR, 44 | ALERT_DESCRIPTION_DECOMPRESSION_FAILURE, 45 | ALERT_DESCRIPTION_DECRYPT_ERROR, 46 | ALERT_DESCRIPTION_HANDSHAKE_FAILURE, 47 | ALERT_DESCRIPTION_ILLEGAL_PARAMETER, 48 | ALERT_DESCRIPTION_INSUFFICIENT_SECURITY, 49 | ALERT_DESCRIPTION_INTERNAL_ERROR, 50 | ALERT_DESCRIPTION_NO_RENEGOTIATION, 51 | ALERT_DESCRIPTION_PROTOCOL_VERSION, 52 | ALERT_DESCRIPTION_RECORD_OVERFLOW, 53 | ALERT_DESCRIPTION_UNEXPECTED_MESSAGE, 54 | ALERT_DESCRIPTION_UNKNOWN_CA, 55 | ALERT_DESCRIPTION_UNKNOWN_PSK_IDENTITY, 56 | ALERT_DESCRIPTION_UNRECOGNIZED_NAME, 57 | ALERT_DESCRIPTION_UNSUPPORTED_CERTIFICATE, 58 | ALERT_DESCRIPTION_UNSUPPORTED_EXTENSION, 59 | ALERT_DESCRIPTION_USER_CANCELLED) 60 | from _ssl import (SSL_ERROR_EOF, SSL_ERROR_INVALID_ERROR_CODE, SSL_ERROR_SSL, 61 | SSL_ERROR_SYSCALL, SSL_ERROR_WANT_CONNECT, SSL_ERROR_WANT_READ, 62 | SSL_ERROR_WANT_WRITE, SSL_ERROR_WANT_X509_LOOKUP, SSL_ERROR_ZERO_RETURN) 63 | from _ssl import VERIFY_CRL_CHECK_CHAIN, VERIFY_CRL_CHECK_LEAF, VERIFY_DEFAULT, VERIFY_X509_STRICT 64 | from _ssl import HAS_SNI, HAS_ECDH, HAS_NPN, HAS_ALPN 65 | from _ssl import _OPENSSL_API_VERSION 66 | from _ssl import PROTOCOL_SSLv23, PROTOCOL_TLSv1, PROTOCOL_TLSv1_1, PROTOCOL_TLSv1_2 67 | ''') 68 | 69 | 70 | register_module_extender(MANAGER, 'ssl', ssl_transform) 71 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid-1.6.5.dist-info/METADATA: -------------------------------------------------------------------------------- 1 | Metadata-Version: 2.0 2 | Name: astroid 3 | Version: 1.6.5 4 | Summary: A abstract syntax tree for Python with inference support. 5 | Home-page: https://github.com/PyCQA/astroid 6 | Author: Python Code Quality Authority 7 | Author-email: code-quality@python.org 8 | License: LGPL 9 | Platform: UNKNOWN 10 | Classifier: Topic :: Software Development :: Libraries :: Python Modules 11 | Classifier: Topic :: Software Development :: Quality Assurance 12 | Classifier: Programming Language :: Python 13 | Classifier: Programming Language :: Python :: 2 14 | Classifier: Programming Language :: Python :: 2.7 15 | Classifier: Programming Language :: Python :: 3 16 | Classifier: Programming Language :: Python :: 3.4 17 | Classifier: Programming Language :: Python :: 3.5 18 | Classifier: Programming Language :: Python :: 3.6 19 | Classifier: Programming Language :: Python :: Implementation :: CPython 20 | Classifier: Programming Language :: Python :: Implementation :: PyPy 21 | Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.* 22 | Requires-Dist: lazy-object-proxy 23 | Requires-Dist: six 24 | Requires-Dist: wrapt 25 | Requires-Dist: enum34 (>=1.1.3); python_version<"3.4" 26 | Requires-Dist: singledispatch; python_version<"3.4" 27 | Requires-Dist: backports.functools-lru-cache; python_version<"3.4" 28 | 29 | Astroid 30 | ======= 31 | 32 | .. image:: https://travis-ci.org/PyCQA/astroid.svg?branch=master 33 | :target: https://travis-ci.org/PyCQA/astroid 34 | 35 | .. image:: https://ci.appveyor.com/api/projects/status/co3u42kunguhbh6l/branch/master?svg=true 36 | :alt: AppVeyor Build Status 37 | :target: https://ci.appveyor.com/project/PCManticore/astroid 38 | 39 | .. image:: https://coveralls.io/repos/github/PyCQA/astroid/badge.svg?branch=master 40 | :target: https://coveralls.io/github/PyCQA/astroid?branch=master 41 | 42 | .. image:: https://readthedocs.org/projects/astroid/badge/?version=latest 43 | :target: http://astroid.readthedocs.io/en/latest/?badge=latest 44 | :alt: Documentation Status 45 | 46 | 47 | 48 | What's this? 49 | ------------ 50 | 51 | The aim of this module is to provide a common base representation of 52 | python source code for projects such as pychecker, pyreverse, 53 | pylint... Well, actually the development of this library is essentially 54 | governed by pylint's needs. It used to be called logilab-astng. 55 | 56 | It provides a compatible representation which comes from the `_ast` 57 | module. It rebuilds the tree generated by the builtin _ast module by 58 | recursively walking down the AST and building an extended ast. The new 59 | node classes have additional methods and attributes for different 60 | usages. They include some support for static inference and local name 61 | scopes. Furthermore, astroid builds partial trees by inspecting living 62 | objects. 63 | 64 | 65 | Installation 66 | ------------ 67 | 68 | Extract the tarball, jump into the created directory and run:: 69 | 70 | python setup.py install 71 | 72 | For installation options, see:: 73 | 74 | python setup.py install --help 75 | 76 | 77 | If you have any questions, please mail the code-quality@python.org 78 | mailing list for support. See 79 | http://mail.python.org/mailman/listinfo/code-quality for subscription 80 | information and archives. You may find older archives at 81 | http://lists.logilab.org/mailman/listinfo/python-projects . 82 | 83 | Python Versions 84 | --------------- 85 | 86 | astroid is compatible with Python 2.7 as well as 3.4 and later. astroid uses 87 | the same code base for both Python versions, using six. 88 | 89 | Test 90 | ---- 91 | 92 | Tests are in the 'test' subdirectory. To launch the whole tests suite 93 | at once, you can use unittest discover:: 94 | 95 | python -m unittest discover -p "unittest*.py" 96 | 97 | 98 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/unittest_raw_building.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014 Google, Inc. 2 | # Copyright (c) 2014-2016 Claudiu Popa 3 | 4 | # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html 5 | # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER 6 | 7 | import inspect 8 | import os 9 | import unittest 10 | 11 | from six.moves import builtins 12 | 13 | from astroid.builder import AstroidBuilder, extract_node 14 | from astroid.raw_building import ( 15 | attach_dummy_node, build_module, 16 | build_class, build_function, build_from_import 17 | ) 18 | from astroid import test_utils 19 | from astroid import nodes 20 | from astroid.bases import BUILTINS 21 | 22 | 23 | class RawBuildingTC(unittest.TestCase): 24 | 25 | def test_attach_dummy_node(self): 26 | node = build_module('MyModule') 27 | attach_dummy_node(node, 'DummyNode') 28 | self.assertEqual(1, len(list(node.get_children()))) 29 | 30 | def test_build_module(self): 31 | node = build_module('MyModule') 32 | self.assertEqual(node.name, 'MyModule') 33 | self.assertEqual(node.pure_python, False) 34 | self.assertEqual(node.package, False) 35 | self.assertEqual(node.parent, None) 36 | 37 | def test_build_class(self): 38 | node = build_class('MyClass') 39 | self.assertEqual(node.name, 'MyClass') 40 | self.assertEqual(node.doc, None) 41 | 42 | def test_build_function(self): 43 | node = build_function('MyFunction') 44 | self.assertEqual(node.name, 'MyFunction') 45 | self.assertEqual(node.doc, None) 46 | 47 | def test_build_function_args(self): 48 | args = ['myArgs1', 'myArgs2'] 49 | # pylint: disable=no-member; not aware of postinit 50 | node = build_function('MyFunction', args) 51 | self.assertEqual('myArgs1', node.args.args[0].name) 52 | self.assertEqual('myArgs2', node.args.args[1].name) 53 | self.assertEqual(2, len(node.args.args)) 54 | 55 | def test_build_function_defaults(self): 56 | # pylint: disable=no-member; not aware of postinit 57 | defaults = ['defaults1', 'defaults2'] 58 | node = build_function('MyFunction', None, defaults) 59 | self.assertEqual(2, len(node.args.defaults)) 60 | 61 | def test_build_from_import(self): 62 | names = ['exceptions, inference, inspector'] 63 | node = build_from_import('astroid', names) 64 | self.assertEqual(len(names), len(node.names)) 65 | 66 | @test_utils.require_version(minver='3.0') 67 | def test_io_is__io(self): 68 | # _io module calls itself io. This leads 69 | # to cyclic dependencies when astroid tries to resolve 70 | # what io.BufferedReader is. The code that handles this 71 | # is in astroid.raw_building.imported_member, which verifies 72 | # the true name of the module. 73 | import _io 74 | 75 | builder = AstroidBuilder() 76 | module = builder.inspect_build(_io) 77 | buffered_reader = module.getattr('BufferedReader')[0] 78 | self.assertEqual(buffered_reader.root().name, 'io') 79 | 80 | @unittest.skipUnless(os.name == 'java', 'Requires Jython') 81 | def test_open_is_inferred_correctly(self): 82 | # Lot of Jython builtins don't have a __module__ attribute. 83 | for name, _ in inspect.getmembers(builtins, predicate=inspect.isbuiltin): 84 | if name == 'print': 85 | continue 86 | node = extract_node('{0} #@'.format(name)) 87 | inferred = next(node.infer()) 88 | self.assertIsInstance(inferred, nodes.FunctionDef, name) 89 | self.assertEqual(inferred.root().name, BUILTINS, name) 90 | 91 | 92 | if __name__ == '__main__': 93 | unittest.main() 94 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/unittest_peephole.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2015-2016 Claudiu Popa 2 | 3 | # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html 4 | # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER 5 | 6 | 7 | """Tests for the astroid AST peephole optimizer.""" 8 | 9 | import ast 10 | import textwrap 11 | import unittest 12 | 13 | import astroid 14 | from astroid import astpeephole 15 | from astroid import builder 16 | from astroid import manager 17 | from astroid import test_utils 18 | from astroid.tests import resources 19 | 20 | 21 | MANAGER = manager.AstroidManager() 22 | 23 | 24 | class PeepholeOptimizer(unittest.TestCase): 25 | @classmethod 26 | def setUpClass(cls): 27 | MANAGER.optimize_ast = True 28 | 29 | @classmethod 30 | def tearDownClass(cls): 31 | MANAGER.optimize_ast = False 32 | 33 | def setUp(self): 34 | self._optimizer = astpeephole.ASTPeepholeOptimizer() 35 | 36 | @staticmethod 37 | def _get_binops(code): 38 | module = ast.parse(textwrap.dedent(code)) 39 | return [node.value for node in module.body 40 | if isinstance(node, ast.Expr)] 41 | 42 | @test_utils.require_version(maxver='3.0') 43 | def test_optimize_binop_unicode(self): 44 | nodes = self._get_binops(""" 45 | u"a" + u"b" + u"c" 46 | 47 | u"a" + "c" + "b" 48 | u"a" + b"c" 49 | """) 50 | 51 | result = self._optimizer.optimize_binop(nodes[0]) 52 | self.assertIsInstance(result, astroid.Const) 53 | self.assertEqual(result.value, u"abc") 54 | 55 | self.assertIsNone(self._optimizer.optimize_binop(nodes[1])) 56 | self.assertIsNone(self._optimizer.optimize_binop(nodes[2])) 57 | 58 | def test_optimize_binop(self): 59 | nodes = self._get_binops(""" 60 | "a" + "b" + "c" + "d" 61 | b"a" + b"b" + b"c" + b"d" 62 | "a" + "b" 63 | 64 | "a" + "b" + 1 + object 65 | var = 4 66 | "a" + "b" + var + "c" 67 | "a" + "b" + "c" - "4" 68 | "a" + "b" + "c" + "d".format() 69 | "a" - "b" 70 | "a" 71 | 1 + 4 + 5 + 6 72 | """) 73 | 74 | result = self._optimizer.optimize_binop(nodes[0]) 75 | self.assertIsInstance(result, astroid.Const) 76 | self.assertEqual(result.value, "abcd") 77 | 78 | result = self._optimizer.optimize_binop(nodes[1]) 79 | self.assertIsInstance(result, astroid.Const) 80 | self.assertEqual(result.value, b"abcd") 81 | 82 | for node in nodes[2:]: 83 | self.assertIsNone(self._optimizer.optimize_binop(node)) 84 | 85 | def test_big_binop_crash(self): 86 | # Test that we don't fail on a lot of joined strings 87 | # through the addition operator. 88 | module = resources.build_file('data/joined_strings.py') 89 | element = next(module['x'].infer()) 90 | self.assertIsInstance(element, astroid.Const) 91 | self.assertEqual(len(element.value), 61660) 92 | 93 | def test_optimisation_disabled(self): 94 | try: 95 | MANAGER.optimize_ast = False 96 | module = builder.parse(""" 97 | '1' + '2' + '3' 98 | """) 99 | self.assertIsInstance(module.body[0], astroid.Expr) 100 | self.assertIsInstance(module.body[0].value, astroid.BinOp) 101 | self.assertIsInstance(module.body[0].value.left, astroid.BinOp) 102 | self.assertIsInstance(module.body[0].value.left.left, 103 | astroid.Const) 104 | finally: 105 | MANAGER.optimize_ast = True 106 | 107 | 108 | if __name__ == '__main__': 109 | unittest.main() 110 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/context.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2015-2016 Cara Vinson 2 | # Copyright (c) 2015-2016 Claudiu Popa 3 | 4 | # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html 5 | # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER 6 | 7 | """Various context related utilities, including inference and call contexts.""" 8 | 9 | import contextlib 10 | import copy 11 | import pprint 12 | 13 | 14 | class InferenceContext(object): 15 | """Provide context for inference 16 | 17 | Store already inferred nodes to save time 18 | Account for already visited nodes to infinite stop infinite recursion 19 | """ 20 | 21 | __slots__ = ('path', 'lookupname', 'callcontext', 'boundnode', 'inferred') 22 | 23 | def __init__(self, path=None, inferred=None): 24 | self.path = path or set() 25 | """Path of visited nodes and their lookupname 26 | :type: set(tuple(NodeNG, optional(str)))""" 27 | self.lookupname = None 28 | self.callcontext = None 29 | self.boundnode = None 30 | self.inferred = inferred or {} 31 | """ 32 | :type: dict(seq, seq) 33 | 34 | Inferred node contexts to their mapped results 35 | Currently the key is (node, lookupname, callcontext, boundnode) 36 | and the value is tuple of the inferred results 37 | """ 38 | 39 | def push(self, node): 40 | """Push node into inference path 41 | 42 | :return: True if node is already in context path else False 43 | :rtype: bool 44 | 45 | Allows one to see if the given node has already 46 | been looked at for this inference context""" 47 | name = self.lookupname 48 | if (node, name) in self.path: 49 | return True 50 | 51 | self.path.add((node, name)) 52 | return False 53 | 54 | def clone(self): 55 | """Clone inference path 56 | 57 | For example, each side of a binary operation (BinOp) 58 | starts with the same context but diverge as each side is inferred 59 | so the InferenceContext will need be cloned""" 60 | # XXX copy lookupname/callcontext ? 61 | clone = InferenceContext(copy.copy(self.path), inferred=self.inferred) 62 | clone.callcontext = self.callcontext 63 | clone.boundnode = self.boundnode 64 | return clone 65 | 66 | def cache_generator(self, key, generator): 67 | """Cache result of generator into dictionary 68 | 69 | Used to cache inference results""" 70 | results = [] 71 | for result in generator: 72 | results.append(result) 73 | yield result 74 | 75 | self.inferred[key] = tuple(results) 76 | 77 | @contextlib.contextmanager 78 | def restore_path(self): 79 | path = set(self.path) 80 | yield 81 | self.path = path 82 | 83 | def __str__(self): 84 | state = ('%s=%s' % (field, pprint.pformat(getattr(self, field), 85 | width=80 - len(field))) 86 | for field in self.__slots__) 87 | return '%s(%s)' % (type(self).__name__, ',\n '.join(state)) 88 | 89 | 90 | class CallContext(object): 91 | """Holds information for a call site.""" 92 | 93 | __slots__ = ('args', 'keywords') 94 | 95 | def __init__(self, args, keywords=None): 96 | self.args = args 97 | if keywords: 98 | keywords = [(arg.arg, arg.value) for arg in keywords] 99 | else: 100 | keywords = [] 101 | self.keywords = keywords 102 | 103 | 104 | def copy_context(context): 105 | if context is not None: 106 | return context.clone() 107 | 108 | return InferenceContext() 109 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/brain/brain_curses.py: -------------------------------------------------------------------------------- 1 | # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html 2 | # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER 3 | import astroid 4 | 5 | 6 | def _curses_transform(): 7 | return astroid.parse(''' 8 | A_ALTCHARSET = 1 9 | A_BLINK = 1 10 | A_BOLD = 1 11 | A_DIM = 1 12 | A_INVIS = 1 13 | A_ITALIC = 1 14 | A_NORMAL = 1 15 | A_PROTECT = 1 16 | A_REVERSE = 1 17 | A_STANDOUT = 1 18 | A_UNDERLINE = 1 19 | A_HORIZONTAL = 1 20 | A_LEFT = 1 21 | A_LOW = 1 22 | A_RIGHT = 1 23 | A_TOP = 1 24 | A_VERTICAL = 1 25 | A_CHARTEXT = 1 26 | A_ATTRIBUTES = 1 27 | A_CHARTEXT = 1 28 | A_COLOR = 1 29 | KEY_MIN = 1 30 | KEY_BREAK = 1 31 | KEY_DOWN = 1 32 | KEY_UP = 1 33 | KEY_LEFT = 1 34 | KEY_RIGHT = 1 35 | KEY_HOME = 1 36 | KEY_BACKSPACE = 1 37 | KEY_F0 = 1 38 | KEY_Fn = 1 39 | KEY_DL = 1 40 | KEY_IL = 1 41 | KEY_DC = 1 42 | KEY_IC = 1 43 | KEY_EIC = 1 44 | KEY_CLEAR = 1 45 | KEY_EOS = 1 46 | KEY_EOL = 1 47 | KEY_SF = 1 48 | KEY_SR = 1 49 | KEY_NPAGE = 1 50 | KEY_PPAGE = 1 51 | KEY_STAB = 1 52 | KEY_CTAB = 1 53 | KEY_CATAB = 1 54 | KEY_ENTER = 1 55 | KEY_SRESET = 1 56 | KEY_RESET = 1 57 | KEY_PRINT = 1 58 | KEY_LL = 1 59 | KEY_A1 = 1 60 | KEY_A3 = 1 61 | KEY_B2 = 1 62 | KEY_C1 = 1 63 | KEY_C3 = 1 64 | KEY_BTAB = 1 65 | KEY_BEG = 1 66 | KEY_CANCEL = 1 67 | KEY_CLOSE = 1 68 | KEY_COMMAND = 1 69 | KEY_COPY = 1 70 | KEY_CREATE = 1 71 | KEY_END = 1 72 | KEY_EXIT = 1 73 | KEY_FIND = 1 74 | KEY_HELP = 1 75 | KEY_MARK = 1 76 | KEY_MESSAGE = 1 77 | KEY_MOVE = 1 78 | KEY_NEXT = 1 79 | KEY_OPEN = 1 80 | KEY_OPTIONS = 1 81 | KEY_PREVIOUS = 1 82 | KEY_REDO = 1 83 | KEY_REFERENCE = 1 84 | KEY_REFRESH = 1 85 | KEY_REPLACE = 1 86 | KEY_RESTART = 1 87 | KEY_RESUME = 1 88 | KEY_SAVE = 1 89 | KEY_SBEG = 1 90 | KEY_SCANCEL = 1 91 | KEY_SCOMMAND = 1 92 | KEY_SCOPY = 1 93 | KEY_SCREATE = 1 94 | KEY_SDC = 1 95 | KEY_SDL = 1 96 | KEY_SELECT = 1 97 | KEY_SEND = 1 98 | KEY_SEOL = 1 99 | KEY_SEXIT = 1 100 | KEY_SFIND = 1 101 | KEY_SHELP = 1 102 | KEY_SHOME = 1 103 | KEY_SIC = 1 104 | KEY_SLEFT = 1 105 | KEY_SMESSAGE = 1 106 | KEY_SMOVE = 1 107 | KEY_SNEXT = 1 108 | KEY_SOPTIONS = 1 109 | KEY_SPREVIOUS = 1 110 | KEY_SPRINT = 1 111 | KEY_SREDO = 1 112 | KEY_SREPLACE = 1 113 | KEY_SRIGHT = 1 114 | KEY_SRSUME = 1 115 | KEY_SSAVE = 1 116 | KEY_SSUSPEND = 1 117 | KEY_SUNDO = 1 118 | KEY_SUSPEND = 1 119 | KEY_UNDO = 1 120 | KEY_MOUSE = 1 121 | KEY_RESIZE = 1 122 | KEY_MAX = 1 123 | ACS_BBSS = 1 124 | ACS_BLOCK = 1 125 | ACS_BOARD = 1 126 | ACS_BSBS = 1 127 | ACS_BSSB = 1 128 | ACS_BSSS = 1 129 | ACS_BTEE = 1 130 | ACS_BULLET = 1 131 | ACS_CKBOARD = 1 132 | ACS_DARROW = 1 133 | ACS_DEGREE = 1 134 | ACS_DIAMOND = 1 135 | ACS_GEQUAL = 1 136 | ACS_HLINE = 1 137 | ACS_LANTERN = 1 138 | ACS_LARROW = 1 139 | ACS_LEQUAL = 1 140 | ACS_LLCORNER = 1 141 | ACS_LRCORNER = 1 142 | ACS_LTEE = 1 143 | ACS_NEQUAL = 1 144 | ACS_PI = 1 145 | ACS_PLMINUS = 1 146 | ACS_PLUS = 1 147 | ACS_RARROW = 1 148 | ACS_RTEE = 1 149 | ACS_S1 = 1 150 | ACS_S3 = 1 151 | ACS_S7 = 1 152 | ACS_S9 = 1 153 | ACS_SBBS = 1 154 | ACS_SBSB = 1 155 | ACS_SBSS = 1 156 | ACS_SSBB = 1 157 | ACS_SSBS = 1 158 | ACS_SSSB = 1 159 | ACS_SSSS = 1 160 | ACS_STERLING = 1 161 | ACS_TTEE = 1 162 | ACS_UARROW = 1 163 | ACS_ULCORNER = 1 164 | ACS_URCORNER = 1 165 | ACS_VLINE = 1 166 | COLOR_BLACK = 1 167 | COLOR_BLUE = 1 168 | COLOR_CYAN = 1 169 | COLOR_GREEN = 1 170 | COLOR_MAGENTA = 1 171 | COLOR_RED = 1 172 | COLOR_WHITE = 1 173 | COLOR_YELLOW = 1 174 | ''') 175 | 176 | 177 | astroid.register_module_extender(astroid.MANAGER, 'curses', _curses_transform) 178 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/tests/unittest_utils.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014, 2016 Google, Inc. 2 | # Copyright (c) 2015-2016 Claudiu Popa 3 | 4 | # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html 5 | # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER 6 | 7 | import unittest 8 | 9 | from astroid import builder 10 | from astroid import InferenceError 11 | from astroid import nodes 12 | from astroid import node_classes 13 | from astroid import util as astroid_util 14 | 15 | 16 | class InferenceUtil(unittest.TestCase): 17 | 18 | def test_not_exclusive(self): 19 | module = builder.parse(""" 20 | x = 10 21 | for x in range(5): 22 | print (x) 23 | 24 | if x > 0: 25 | print ('#' * x) 26 | """, __name__, __file__) 27 | xass1 = module.locals['x'][0] 28 | assert xass1.lineno == 2 29 | xnames = [n for n in module.nodes_of_class(nodes.Name) if n.name == 'x'] 30 | assert len(xnames) == 3 31 | assert xnames[1].lineno == 6 32 | self.assertEqual(node_classes.are_exclusive(xass1, xnames[1]), False) 33 | self.assertEqual(node_classes.are_exclusive(xass1, xnames[2]), False) 34 | 35 | def test_if(self): 36 | module = builder.parse(''' 37 | if 1: 38 | a = 1 39 | a = 2 40 | elif 2: 41 | a = 12 42 | a = 13 43 | else: 44 | a = 3 45 | a = 4 46 | ''') 47 | a1 = module.locals['a'][0] 48 | a2 = module.locals['a'][1] 49 | a3 = module.locals['a'][2] 50 | a4 = module.locals['a'][3] 51 | a5 = module.locals['a'][4] 52 | a6 = module.locals['a'][5] 53 | self.assertEqual(node_classes.are_exclusive(a1, a2), False) 54 | self.assertEqual(node_classes.are_exclusive(a1, a3), True) 55 | self.assertEqual(node_classes.are_exclusive(a1, a5), True) 56 | self.assertEqual(node_classes.are_exclusive(a3, a5), True) 57 | self.assertEqual(node_classes.are_exclusive(a3, a4), False) 58 | self.assertEqual(node_classes.are_exclusive(a5, a6), False) 59 | 60 | def test_try_except(self): 61 | module = builder.parse(''' 62 | try: 63 | def exclusive_func2(): 64 | "docstring" 65 | except TypeError: 66 | def exclusive_func2(): 67 | "docstring" 68 | except: 69 | def exclusive_func2(): 70 | "docstring" 71 | else: 72 | def exclusive_func2(): 73 | "this one redefine the one defined line 42" 74 | ''') 75 | f1 = module.locals['exclusive_func2'][0] 76 | f2 = module.locals['exclusive_func2'][1] 77 | f3 = module.locals['exclusive_func2'][2] 78 | f4 = module.locals['exclusive_func2'][3] 79 | self.assertEqual(node_classes.are_exclusive(f1, f2), True) 80 | self.assertEqual(node_classes.are_exclusive(f1, f3), True) 81 | self.assertEqual(node_classes.are_exclusive(f1, f4), False) 82 | self.assertEqual(node_classes.are_exclusive(f2, f4), True) 83 | self.assertEqual(node_classes.are_exclusive(f3, f4), True) 84 | self.assertEqual(node_classes.are_exclusive(f3, f2), True) 85 | 86 | self.assertEqual(node_classes.are_exclusive(f2, f1), True) 87 | self.assertEqual(node_classes.are_exclusive(f4, f1), False) 88 | self.assertEqual(node_classes.are_exclusive(f4, f2), True) 89 | 90 | def test_unpack_infer_uninferable_nodes(self): 91 | node = builder.extract_node(''' 92 | x = [A] * 1 93 | f = [x, [A] * 2] 94 | f 95 | ''') 96 | inferred = next(node.infer()) 97 | unpacked = list(node_classes.unpack_infer(inferred)) 98 | self.assertEqual(len(unpacked), 3) 99 | self.assertTrue(all(elt is astroid_util.Uninferable 100 | for elt in unpacked)) 101 | 102 | def test_unpack_infer_empty_tuple(self): 103 | node = builder.extract_node(''' 104 | () 105 | ''') 106 | inferred = next(node.infer()) 107 | with self.assertRaises(InferenceError): 108 | list(node_classes.unpack_infer(inferred)) 109 | 110 | 111 | if __name__ == '__main__': 112 | unittest.main() 113 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/util.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2015-2016 Cara Vinson 2 | # Copyright (c) 2015-2016 Claudiu Popa 3 | 4 | # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html 5 | # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER 6 | 7 | import sys 8 | import warnings 9 | 10 | import importlib 11 | import lazy_object_proxy 12 | import six 13 | 14 | 15 | def lazy_descriptor(obj): 16 | class DescriptorProxy(lazy_object_proxy.Proxy): 17 | def __get__(self, instance, owner=None): 18 | return self.__class__.__get__(self, instance) 19 | return DescriptorProxy(obj) 20 | 21 | 22 | def lazy_import(module_name): 23 | return lazy_object_proxy.Proxy( 24 | lambda: importlib.import_module('.' + module_name, 'astroid')) 25 | 26 | 27 | def reraise(exception): 28 | '''Reraises an exception with the traceback from the current exception 29 | block.''' 30 | six.reraise(type(exception), exception, sys.exc_info()[2]) 31 | 32 | 33 | @object.__new__ 34 | class Uninferable(object): 35 | """Special inference object, which is returned when inference fails.""" 36 | def __repr__(self): 37 | return 'Uninferable' 38 | __str__ = __repr__ 39 | 40 | def __getattribute__(self, name): 41 | if name == 'next': 42 | raise AttributeError('next method should not be called') 43 | if name.startswith('__') and name.endswith('__'): 44 | return object.__getattribute__(self, name) 45 | if name == 'accept': 46 | return object.__getattribute__(self, name) 47 | return self 48 | 49 | def __call__(self, *args, **kwargs): 50 | return self 51 | 52 | def __bool__(self): 53 | return False 54 | 55 | __nonzero__ = __bool__ 56 | 57 | def accept(self, visitor): 58 | func = getattr(visitor, "visit_uninferable") 59 | return func(self) 60 | 61 | class BadOperationMessage(object): 62 | """Object which describes a TypeError occurred somewhere in the inference chain 63 | 64 | This is not an exception, but a container object which holds the types and 65 | the error which occurred. 66 | """ 67 | 68 | 69 | class BadUnaryOperationMessage(BadOperationMessage): 70 | """Object which describes operational failures on UnaryOps.""" 71 | 72 | def __init__(self, operand, op, error): 73 | self.operand = operand 74 | self.op = op 75 | self.error = error 76 | 77 | @property 78 | def _object_type_helper(self): 79 | helpers = lazy_import('helpers') 80 | return helpers.object_type 81 | 82 | def _object_type(self, obj): 83 | # pylint: disable=not-callable; can't infer lazy_import 84 | objtype = self._object_type_helper(obj) 85 | if objtype is Uninferable: 86 | return None 87 | 88 | return objtype 89 | 90 | def __str__(self): 91 | if hasattr(self.operand, 'name'): 92 | operand_type = self.operand.name 93 | else: 94 | object_type = self._object_type(self.operand) 95 | if hasattr(object_type, 'name'): 96 | operand_type = object_type.name 97 | else: 98 | # Just fallback to as_string 99 | operand_type = object_type.as_string() 100 | 101 | msg = "bad operand type for unary {}: {}" 102 | return msg.format(self.op, operand_type) 103 | 104 | 105 | class BadBinaryOperationMessage(BadOperationMessage): 106 | """Object which describes type errors for BinOps.""" 107 | 108 | def __init__(self, left_type, op, right_type): 109 | self.left_type = left_type 110 | self.right_type = right_type 111 | self.op = op 112 | 113 | def __str__(self): 114 | msg = "unsupported operand type(s) for {}: {!r} and {!r}" 115 | return msg.format(self.op, self.left_type.name, self.right_type.name) 116 | 117 | 118 | def _instancecheck(cls, other): 119 | wrapped = cls.__wrapped__ 120 | other_cls = other.__class__ 121 | is_instance_of = wrapped is other_cls or issubclass(other_cls, wrapped) 122 | warnings.warn("%r is deprecated and slated for removal in astroid " 123 | "2.0, use %r instead" % (cls.__class__.__name__, 124 | wrapped.__name__), 125 | PendingDeprecationWarning, stacklevel=2) 126 | return is_instance_of 127 | 128 | 129 | def proxy_alias(alias_name, node_type): 130 | """Get a Proxy from the given name to the given node type.""" 131 | proxy = type(alias_name, (lazy_object_proxy.Proxy,), 132 | {'__class__': object.__dict__['__class__'], 133 | '__instancecheck__': _instancecheck}) 134 | return proxy(lambda: node_type) 135 | 136 | 137 | # Backwards-compatibility aliases 138 | YES = Uninferable 139 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/mixins.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2010-2011, 2013-2014 LOGILAB S.A. (Paris, FRANCE) 2 | # Copyright (c) 2014 Google, Inc. 3 | # Copyright (c) 2015-2016 Cara Vinson 4 | 5 | # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html 6 | # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER 7 | 8 | """This module contains some mixins for the different nodes. 9 | """ 10 | 11 | import warnings 12 | 13 | from astroid import decorators 14 | from astroid import exceptions 15 | 16 | 17 | class BlockRangeMixIn(object): 18 | """override block range """ 19 | 20 | @decorators.cachedproperty 21 | def blockstart_tolineno(self): 22 | return self.lineno 23 | 24 | def _elsed_block_range(self, lineno, orelse, last=None): 25 | """handle block line numbers range for try/finally, for, if and while 26 | statements 27 | """ 28 | if lineno == self.fromlineno: 29 | return lineno, lineno 30 | if orelse: 31 | if lineno >= orelse[0].fromlineno: 32 | return lineno, orelse[-1].tolineno 33 | return lineno, orelse[0].fromlineno - 1 34 | return lineno, last or self.tolineno 35 | 36 | 37 | class FilterStmtsMixin(object): 38 | """Mixin for statement filtering and assignment type""" 39 | 40 | def _get_filtered_stmts(self, _, node, _stmts, mystmt): 41 | """method used in _filter_stmts to get statements and trigger break""" 42 | if self.statement() is mystmt: 43 | # original node's statement is the assignment, only keep 44 | # current node (gen exp, list comp) 45 | return [node], True 46 | return _stmts, False 47 | 48 | def assign_type(self): 49 | return self 50 | 51 | def ass_type(self): 52 | warnings.warn('%s.ass_type() is deprecated and slated for removal ' 53 | 'in astroid 2.0, use %s.assign_type() instead.' 54 | % (type(self).__name__, type(self).__name__), 55 | PendingDeprecationWarning, stacklevel=2) 56 | return self.assign_type() 57 | 58 | 59 | class AssignTypeMixin(object): 60 | 61 | def assign_type(self): 62 | return self 63 | 64 | def ass_type(self): 65 | warnings.warn('%s.ass_type() is deprecated and slated for removal ' 66 | 'in astroid 2.0, use %s.assign_type() instead.' 67 | % (type(self).__name__, type(self).__name__), 68 | PendingDeprecationWarning, stacklevel=2) 69 | return self.assign_type() 70 | 71 | def _get_filtered_stmts(self, lookup_node, node, _stmts, mystmt): 72 | """method used in filter_stmts""" 73 | if self is mystmt: 74 | return _stmts, True 75 | if self.statement() is mystmt: 76 | # original node's statement is the assignment, only keep 77 | # current node (gen exp, list comp) 78 | return [node], True 79 | return _stmts, False 80 | 81 | 82 | class ParentAssignTypeMixin(AssignTypeMixin): 83 | 84 | def assign_type(self): 85 | return self.parent.assign_type() 86 | 87 | def ass_type(self): 88 | warnings.warn('%s.ass_type() is deprecated and slated for removal ' 89 | 'in astroid 2.0, use %s.assign_type() instead.' 90 | % (type(self).__name__, type(self).__name__), 91 | PendingDeprecationWarning, stacklevel=2) 92 | return self.assign_type() 93 | 94 | 95 | class ImportFromMixin(FilterStmtsMixin): 96 | """MixIn for From and Import Nodes""" 97 | 98 | def _infer_name(self, frame, name): 99 | return name 100 | 101 | def do_import_module(self, modname=None): 102 | """return the ast for a module whose name is imported by 103 | """ 104 | # handle special case where we are on a package node importing a module 105 | # using the same name as the package, which may end in an infinite loop 106 | # on relative imports 107 | # XXX: no more needed ? 108 | mymodule = self.root() 109 | level = getattr(self, 'level', None) # Import as no level 110 | if modname is None: 111 | modname = self.modname 112 | # XXX we should investigate deeper if we really want to check 113 | # importing itself: modname and mymodule.name be relative or absolute 114 | if mymodule.relative_to_absolute_name(modname, level) == mymodule.name: 115 | # FIXME: we used to raise InferenceError here, but why ? 116 | return mymodule 117 | 118 | return mymodule.import_module(modname, level=level, 119 | relative_only=level and level >= 1) 120 | 121 | def real_name(self, asname): 122 | """get name from 'as' name""" 123 | for name, _asname in self.names: 124 | if name == '*': 125 | return asname 126 | if not _asname: 127 | name = name.split('.', 1)[0] 128 | _asname = name 129 | if asname == _asname: 130 | return name 131 | raise exceptions.AttributeInferenceError( 132 | 'Could not find original name for {attribute} in {target!r}', 133 | target=self, attribute=asname) 134 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/trimmer/trimmer.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | '''The main module that trims arguments out of function calls.''' 5 | 6 | # IMPORT THIRD-PARTY LIBRARIES 7 | import jedi 8 | 9 | # IMPORT LOCAL LIBRARIES 10 | from . import call_visitor 11 | from .. import config 12 | from . import parser 13 | 14 | 15 | class _CommonParameterExcluder(call_visitor.MultiLineCallVisitor): 16 | 17 | '''A class that can parse Python AST nodes into text.''' 18 | 19 | def __init__(self, excluded_keywords, indent=' '): 20 | '''Create the instance and store keywords to exclude. 21 | 22 | Args: 23 | excluded_keywords (set[tuple[str, str]]): 24 | All the keyword and value pairs which will, if found, will not 25 | be added to the returned text. 26 | indent (str): 27 | The text that will be used for indentation. 28 | 29 | ''' 30 | super(_CommonParameterExcluder, self).__init__(indent) 31 | self.excluded_keywords = excluded_keywords 32 | 33 | def _is_allowed(self, node): 34 | '''bool: If the given node isn't listed as an excluded keyword.''' 35 | return (node.arg, node.value.as_string()) not in self.excluded_keywords 36 | 37 | def _get_args(self, node): 38 | '''list[str]: Add newline and extra space to each arg and kwarg.''' 39 | args = [arg.accept(self) for arg in node.args] 40 | 41 | keywords = [] 42 | 43 | if node.keywords: 44 | keywords = [ 45 | kwarg.accept(self) for kwarg in node.keywords if 46 | self._is_allowed(kwarg)] 47 | 48 | args.extend(keywords) 49 | return self._format_args(args) 50 | 51 | 52 | class MultiLineParameterExcluder(_CommonParameterExcluder): 53 | 54 | '''A class that can parse Python AST nodes into a multi-line statement.''' 55 | 56 | pass 57 | 58 | 59 | class SingleLineParameterExcluder(_CommonParameterExcluder): 60 | 61 | '''A class that can parse Python AST nodes into a single statement.''' 62 | 63 | def _format_args(self, args): 64 | '''str: Return the args as a comma-separate list.''' 65 | return ', '.join(args) 66 | 67 | 68 | def adjust_cursor(code, row, column): 69 | '''Change the user's cursor to be inside of ()s of some callable object. 70 | 71 | Jedi is picky about where the cursor sits so, in case the user's cursor 72 | isn't quite where it needs to be, this function will fix it before the 73 | user's script is parsed. 74 | 75 | Args: 76 | code (str): The code to use as a reference for adjusting the cursor. 77 | row (int): A 1-based line number where the cursor sits. 78 | column (int): A 0-based position on `row` where the cursor sits. 79 | 80 | Returns: 81 | tuple[int, int]: The adjusted row and column. 82 | 83 | ''' 84 | lines = code.split('\n') 85 | 86 | # fromlineo is 1-based so convert it to 0-based by subtracting 1 87 | row -= 1 88 | 89 | call_line = lines[row] 90 | try: 91 | column = max((call_line.index('(') + 1, column)) 92 | except ValueError: 93 | # If this happens, it's because the user wrote some really weird syntax, like: 94 | # 95 | # >>> foo\ 96 | # >>> (bar) 97 | # 98 | pass 99 | 100 | # Set row back to 1-based 101 | row += 1 102 | return (row, column) 103 | 104 | 105 | def format_lines(code, node, visited_lines): 106 | '''Replace code with text that has been run through a visitor. 107 | 108 | Args: 109 | code (str): The original code to replace. 110 | node (`astroid.Node`): The callable object that will be replaced. 111 | visited_lines (iter[str]): The lines to replace `code` with. 112 | 113 | Returns: 114 | list[str]: 115 | The code, now with `visited_lines` in-place of the original text. 116 | 117 | ''' 118 | lines = code.split('\n') 119 | indent = get_indent(lines[node.fromlineno - 1]) 120 | output_lines = ['{indent}{text}'.format(indent=indent, text=text) 121 | for text in visited_lines] 122 | 123 | start = node.fromlineno - 1 124 | end = parser.get_tolineno(node, lines) 125 | lines[start:end] = output_lines 126 | 127 | return lines 128 | 129 | 130 | def get_indent(text): 131 | '''str: Find the existing indent from `text`.''' 132 | return text[:len(text) - len(text.lstrip())] 133 | 134 | 135 | def get_trimmed_keywords(code, row, column, adjust=True): 136 | '''Delete the keyword(s) that are set to default value. 137 | 138 | Args: 139 | code (str): The Python text to trim. 140 | row (int): The 1-based index that represents the user's cursor, horizontally. 141 | column (int): The 0-based index that represents the user's cursor, vertically. 142 | 143 | Returns: 144 | tuple[str, `astroid.node` or NoneType]: The trimmed code. 145 | 146 | ''' 147 | node = parser.get_nearest_call(code, row) 148 | 149 | if not node: 150 | return (code, None) 151 | 152 | if adjust: 153 | row, column = adjust_cursor(code, row, column) 154 | 155 | script = jedi.Script(code, row, column) 156 | 157 | if not script: 158 | return (code, None) 159 | 160 | is_multiline = node.fromlineno != node.tolineno 161 | excluded_keywords = parser.get_unchanged_keywords(node, script) 162 | 163 | indent = config.get_indent_preference() 164 | 165 | if is_multiline: 166 | visitor = MultiLineParameterExcluder(excluded_keywords, indent=indent) 167 | else: 168 | visitor = SingleLineParameterExcluder(excluded_keywords, indent=indent) 169 | 170 | lines = format_lines(code, node, visitor(node).split('\n')) 171 | 172 | return ('\n'.join(lines), node) 173 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/decorators.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2015-2016 Cara Vinson 2 | # Copyright (c) 2015 Florian Bruhin 3 | # Copyright (c) 2015-2016 Claudiu Popa 4 | 5 | # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html 6 | # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER 7 | 8 | """ A few useful function/method decorators.""" 9 | 10 | import functools 11 | 12 | import wrapt 13 | 14 | from astroid import context as contextmod 15 | from astroid import exceptions 16 | from astroid import util 17 | 18 | 19 | @wrapt.decorator 20 | def cached(func, instance, args, kwargs): 21 | """Simple decorator to cache result of method calls without args.""" 22 | cache = getattr(instance, '__cache', None) 23 | if cache is None: 24 | instance.__cache = cache = {} 25 | try: 26 | return cache[func] 27 | except KeyError: 28 | cache[func] = result = func(*args, **kwargs) 29 | return result 30 | 31 | 32 | class cachedproperty(object): 33 | """ Provides a cached property equivalent to the stacking of 34 | @cached and @property, but more efficient. 35 | 36 | After first usage, the becomes part of the object's 37 | __dict__. Doing: 38 | 39 | del obj. empties the cache. 40 | 41 | Idea taken from the pyramid_ framework and the mercurial_ project. 42 | 43 | .. _pyramid: http://pypi.python.org/pypi/pyramid 44 | .. _mercurial: http://pypi.python.org/pypi/Mercurial 45 | """ 46 | __slots__ = ('wrapped',) 47 | 48 | def __init__(self, wrapped): 49 | try: 50 | wrapped.__name__ 51 | except AttributeError: 52 | util.reraise(TypeError('%s must have a __name__ attribute' 53 | % wrapped)) 54 | self.wrapped = wrapped 55 | 56 | @property 57 | def __doc__(self): 58 | doc = getattr(self.wrapped, '__doc__', None) 59 | return ('%s' 60 | % ('\n%s' % doc if doc else '')) 61 | 62 | def __get__(self, inst, objtype=None): 63 | if inst is None: 64 | return self 65 | val = self.wrapped(inst) 66 | setattr(inst, self.wrapped.__name__, val) 67 | return val 68 | 69 | 70 | def path_wrapper(func): 71 | """return the given infer function wrapped to handle the path 72 | 73 | Used to stop inference if the node has already been looked 74 | at for a given `InferenceContext` to prevent infinite recursion 75 | """ 76 | # TODO: switch this to wrapt after the monkey-patching is fixed (ceridwen) 77 | @functools.wraps(func) 78 | def wrapped(node, context=None, _func=func, **kwargs): 79 | """wrapper function handling context""" 80 | if context is None: 81 | context = contextmod.InferenceContext() 82 | if context.push(node): 83 | return 84 | 85 | yielded = set() 86 | generator = _func(node, context, **kwargs) 87 | try: 88 | while True: 89 | res = next(generator) 90 | # unproxy only true instance, not const, tuple, dict... 91 | if res.__class__.__name__ == 'Instance': 92 | ares = res._proxied 93 | else: 94 | ares = res 95 | if ares not in yielded: 96 | yield res 97 | yielded.add(ares) 98 | except StopIteration as error: 99 | # Explicit StopIteration to return error information, see 100 | # comment in raise_if_nothing_inferred. 101 | if error.args: 102 | raise StopIteration(error.args[0]) 103 | else: 104 | raise StopIteration 105 | 106 | return wrapped 107 | 108 | 109 | @wrapt.decorator 110 | def yes_if_nothing_inferred(func, instance, args, kwargs): 111 | inferred = False 112 | for node in func(*args, **kwargs): 113 | inferred = True 114 | yield node 115 | if not inferred: 116 | yield util.Uninferable 117 | 118 | 119 | @wrapt.decorator 120 | def raise_if_nothing_inferred(func, instance, args, kwargs): 121 | '''All generators wrapped with raise_if_nothing_inferred *must* 122 | explicitly raise StopIteration with information to create an 123 | appropriate structured InferenceError. 124 | 125 | ''' 126 | # TODO: Explicitly raising StopIteration in a generator will cause 127 | # a RuntimeError in Python >=3.7, as per 128 | # http://legacy.python.org/dev/peps/pep-0479/ . Before 3.7 is 129 | # released, this code will need to use one of four possible 130 | # solutions: a decorator that restores the current behavior as 131 | # described in 132 | # http://legacy.python.org/dev/peps/pep-0479/#sub-proposal-decorator-to-explicitly-request-current-behaviour 133 | # , dynamic imports or exec to generate different code for 134 | # different versions, drop support for all Python versions <3.3, 135 | # or refactoring to change how these decorators work. In any 136 | # event, after dropping support for Python <3.3 this code should 137 | # be refactored to use `yield from`. 138 | inferred = False 139 | try: 140 | generator = func(*args, **kwargs) 141 | while True: 142 | yield next(generator) 143 | inferred = True 144 | except StopIteration as error: 145 | if not inferred: 146 | if error.args: 147 | # pylint: disable=not-a-mapping 148 | raise exceptions.InferenceError(**error.args[0]) 149 | else: 150 | raise exceptions.InferenceError( 151 | 'StopIteration raised without any error information.') 152 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/helpers.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2015-2016 Cara Vinson 2 | # Copyright (c) 2015-2016 Claudiu Popa 3 | 4 | # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html 5 | # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER 6 | 7 | 8 | """ 9 | Various helper utilities. 10 | """ 11 | 12 | import six 13 | 14 | from astroid import bases 15 | from astroid import context as contextmod 16 | from astroid import exceptions 17 | from astroid import manager 18 | from astroid import nodes 19 | from astroid import raw_building 20 | from astroid import scoped_nodes 21 | from astroid import util 22 | 23 | 24 | BUILTINS = six.moves.builtins.__name__ 25 | 26 | 27 | def _build_proxy_class(cls_name, builtins): 28 | proxy = raw_building.build_class(cls_name) 29 | proxy.parent = builtins 30 | return proxy 31 | 32 | 33 | def _function_type(function, builtins): 34 | if isinstance(function, scoped_nodes.Lambda): 35 | if function.root().name == BUILTINS: 36 | cls_name = 'builtin_function_or_method' 37 | else: 38 | cls_name = 'function' 39 | elif isinstance(function, bases.BoundMethod): 40 | if six.PY2: 41 | cls_name = 'instancemethod' 42 | else: 43 | cls_name = 'method' 44 | elif isinstance(function, bases.UnboundMethod): 45 | if six.PY2: 46 | cls_name = 'instancemethod' 47 | else: 48 | cls_name = 'function' 49 | return _build_proxy_class(cls_name, builtins) 50 | 51 | 52 | def _object_type(node, context=None): 53 | astroid_manager = manager.AstroidManager() 54 | builtins = astroid_manager.astroid_cache[BUILTINS] 55 | context = context or contextmod.InferenceContext() 56 | 57 | for inferred in node.infer(context=context): 58 | if isinstance(inferred, scoped_nodes.ClassDef): 59 | if inferred.newstyle: 60 | metaclass = inferred.metaclass() 61 | if metaclass: 62 | yield metaclass 63 | continue 64 | yield builtins.getattr('type')[0] 65 | elif isinstance(inferred, (scoped_nodes.Lambda, bases.UnboundMethod)): 66 | yield _function_type(inferred, builtins) 67 | elif isinstance(inferred, scoped_nodes.Module): 68 | yield _build_proxy_class('module', builtins) 69 | else: 70 | yield inferred._proxied 71 | 72 | 73 | def object_type(node, context=None): 74 | """Obtain the type of the given node 75 | 76 | This is used to implement the ``type`` builtin, which means that it's 77 | used for inferring type calls, as well as used in a couple of other places 78 | in the inference. 79 | The node will be inferred first, so this function can support all 80 | sorts of objects, as long as they support inference. 81 | """ 82 | 83 | try: 84 | types = set(_object_type(node, context)) 85 | except exceptions.InferenceError: 86 | return util.Uninferable 87 | if len(types) > 1 or not types: 88 | return util.Uninferable 89 | return list(types)[0] 90 | 91 | 92 | def safe_infer(node, context=None): 93 | """Return the inferred value for the given node. 94 | 95 | Return None if inference failed or if there is some ambiguity (more than 96 | one node has been inferred). 97 | """ 98 | try: 99 | inferit = node.infer(context=context) 100 | value = next(inferit) 101 | except exceptions.InferenceError: 102 | return None 103 | try: 104 | next(inferit) 105 | return None # None if there is ambiguity on the inferred node 106 | except exceptions.InferenceError: 107 | return None# there is some kind of ambiguity 108 | except StopIteration: 109 | return value 110 | 111 | 112 | def has_known_bases(klass, context=None): 113 | """Return true if all base classes of a class could be inferred.""" 114 | try: 115 | return klass._all_bases_known 116 | except AttributeError: 117 | pass 118 | for base in klass.bases: 119 | result = safe_infer(base, context=context) 120 | # TODO: check for A->B->A->B pattern in class structure too? 121 | if (not isinstance(result, scoped_nodes.ClassDef) or 122 | result is klass or 123 | not has_known_bases(result, context=context)): 124 | klass._all_bases_known = False 125 | return False 126 | klass._all_bases_known = True 127 | return True 128 | 129 | 130 | def _type_check(type1, type2): 131 | if not all(map(has_known_bases, (type1, type2))): 132 | raise exceptions._NonDeducibleTypeHierarchy 133 | 134 | if not all([type1.newstyle, type2.newstyle]): 135 | return False 136 | try: 137 | return type1 in type2.mro()[:-1] 138 | except exceptions.MroError: 139 | # The MRO is invalid. 140 | raise exceptions._NonDeducibleTypeHierarchy 141 | 142 | 143 | def is_subtype(type1, type2): 144 | """Check if *type1* is a subtype of *typ2*.""" 145 | return _type_check(type2, type1) 146 | 147 | 148 | def is_supertype(type1, type2): 149 | """Check if *type2* is a supertype of *type1*.""" 150 | return _type_check(type1, type2) 151 | 152 | 153 | def class_instance_as_index(node): 154 | """Get the value as an index for the given instance. 155 | 156 | If an instance provides an __index__ method, then it can 157 | be used in some scenarios where an integer is expected, 158 | for instance when multiplying or subscripting a list. 159 | """ 160 | context = contextmod.InferenceContext() 161 | context.callcontext = contextmod.CallContext(args=[node]) 162 | 163 | try: 164 | for inferred in node.igetattr('__index__', context=context): 165 | if not isinstance(inferred, bases.BoundMethod): 166 | continue 167 | 168 | for result in inferred.infer_call_result(node, context=context): 169 | if (isinstance(result, nodes.Const) 170 | and isinstance(result.value, int)): 171 | return result 172 | except exceptions.InferenceError: 173 | pass 174 | return None 175 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2006-2013, 2015 LOGILAB S.A. (Paris, FRANCE) 2 | # Copyright (c) 2014 Google, Inc. 3 | # Copyright (c) 2015-2016 Claudiu Popa 4 | 5 | # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html 6 | # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER 7 | 8 | """Python Abstract Syntax Tree New Generation 9 | 10 | The aim of this module is to provide a common base representation of 11 | python source code for projects such as pychecker, pyreverse, 12 | pylint... Well, actually the development of this library is essentially 13 | governed by pylint's needs. 14 | 15 | It extends class defined in the python's _ast module with some 16 | additional methods and attributes. Instance attributes are added by a 17 | builder object, which can either generate extended ast (let's call 18 | them astroid ;) by visiting an existent ast tree or by inspecting living 19 | object. Methods are added by monkey patching ast classes. 20 | 21 | Main modules are: 22 | 23 | * nodes and scoped_nodes for more information about methods and 24 | attributes added to different node classes 25 | 26 | * the manager contains a high level object to get astroid trees from 27 | source files and living objects. It maintains a cache of previously 28 | constructed tree for quick access 29 | 30 | * builder contains the class responsible to build astroid trees 31 | """ 32 | 33 | import os 34 | import sys 35 | import re 36 | from operator import attrgetter 37 | 38 | import enum 39 | 40 | 41 | _Context = enum.Enum('Context', 'Load Store Del') 42 | Load = _Context.Load 43 | Store = _Context.Store 44 | Del = _Context.Del 45 | del _Context 46 | 47 | 48 | from .__pkginfo__ import version as __version__ 49 | # WARNING: internal imports order matters ! 50 | 51 | # pylint: disable=redefined-builtin, wildcard-import 52 | 53 | # make all exception classes accessible from astroid package 54 | from astroid.exceptions import * 55 | 56 | # make all node classes accessible from astroid package 57 | from astroid.nodes import * 58 | 59 | # trigger extra monkey-patching 60 | from astroid import inference 61 | 62 | # more stuff available 63 | from astroid import raw_building 64 | from astroid.bases import BaseInstance, Instance, BoundMethod, UnboundMethod 65 | from astroid.node_classes import are_exclusive, unpack_infer 66 | from astroid.scoped_nodes import builtin_lookup 67 | from astroid.builder import parse, extract_node 68 | from astroid.util import Uninferable, YES 69 | 70 | # make a manager instance (borg) accessible from astroid package 71 | from astroid.manager import AstroidManager 72 | MANAGER = AstroidManager() 73 | del AstroidManager 74 | 75 | # transform utilities (filters and decorator) 76 | 77 | class AsStringRegexpPredicate(object): 78 | """ClassDef to be used as predicate that may be given to `register_transform` 79 | 80 | First argument is a regular expression that will be searched against the `as_string` 81 | representation of the node onto which it's applied. 82 | 83 | If specified, the second argument is an `attrgetter` expression that will be 84 | applied on the node first to get the actual node on which `as_string` should 85 | be called. 86 | 87 | WARNING: This can be fairly slow, as it has to convert every AST node back 88 | to Python code; you should consider examining the AST directly instead. 89 | """ 90 | def __init__(self, regexp, expression=None): 91 | self.regexp = re.compile(regexp) 92 | self.expression = expression 93 | 94 | def __call__(self, node): 95 | if self.expression is not None: 96 | node = attrgetter(self.expression)(node) 97 | # pylint: disable=no-member; github.com/pycqa/astroid/126 98 | return self.regexp.search(node.as_string()) 99 | 100 | def inference_tip(infer_function, raise_on_overwrite=False): 101 | """Given an instance specific inference function, return a function to be 102 | given to MANAGER.register_transform to set this inference function. 103 | 104 | :param bool raise_on_overwrite: Raise an `InferenceOverwriteError` 105 | if the inference tip will overwrite another. Used for debugging 106 | 107 | Typical usage 108 | 109 | .. sourcecode:: python 110 | 111 | MANAGER.register_transform(Call, inference_tip(infer_named_tuple), 112 | predicate) 113 | 114 | .. Note:: 115 | 116 | Using an inference tip will override 117 | any previously set inference tip for the given 118 | node. Use a predicate in the transform to prevent 119 | excess overwrites. 120 | """ 121 | def transform(node, infer_function=infer_function): 122 | if (raise_on_overwrite 123 | and node._explicit_inference is not None 124 | and node._explicit_inference is not infer_function): 125 | raise InferenceOverwriteError( 126 | "Inference already set to {existing_inference}. " 127 | "Trying to overwrite with {new_inference} for {node}" 128 | .format(existing_inference=infer_function, 129 | new_inference=node._explicit_inference, 130 | node=node)) 131 | node._explicit_inference = infer_function 132 | return node 133 | return transform 134 | 135 | 136 | def register_module_extender(manager, module_name, get_extension_mod): 137 | def transform(node): 138 | extension_module = get_extension_mod() 139 | for name, objs in extension_module.locals.items(): 140 | node.locals[name] = objs 141 | for obj in objs: 142 | if obj.parent is extension_module: 143 | obj.parent = node 144 | 145 | manager.register_transform(Module, transform, lambda n: n.name == module_name) 146 | 147 | 148 | # load brain plugins 149 | BRAIN_MODULES_DIR = os.path.join(os.path.dirname(__file__), 'brain') 150 | if BRAIN_MODULES_DIR not in sys.path: 151 | # add it to the end of the list so user path take precedence 152 | sys.path.append(BRAIN_MODULES_DIR) 153 | # load modules in this directory 154 | for module in os.listdir(BRAIN_MODULES_DIR): 155 | if module.endswith('.py'): 156 | __import__(module[:-3]) 157 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/trimmer/parser.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | '''A series of helpers that are used to parse Python callable objects.''' 5 | 6 | # IMPORT THIRD-PARTY LIBRARIES 7 | import functools 8 | import re 9 | 10 | # IMPORT THIRD-PARTY LIBRARIES 11 | import astroid 12 | 13 | # IMPORT LOCAL LIBRARIES 14 | from .. import common 15 | 16 | 17 | class CallVisitor(object): 18 | 19 | '''A node vistor that finds all calls for a given node.''' 20 | 21 | def __init__(self): 22 | '''Create the instance and make a container for nodes.''' 23 | super(CallVisitor, self).__init__() 24 | self.expressions = [] 25 | 26 | def visit(self, node): 27 | '''Visit the given Node's children. 28 | 29 | Args: 30 | (): The node to visit. 31 | 32 | ''' 33 | for child in node.get_children(): 34 | try: 35 | child.accept(self) 36 | except AttributeError: 37 | self.visit(child) 38 | 39 | def visit_call(self, node): 40 | '''Add the found node to the current instance.''' 41 | self.expressions.append(node) 42 | self.visit(node) 43 | 44 | 45 | def get_tolineno(node, lines): 46 | '''Find the 'tolineno' of an astroid node. 47 | 48 | I'm not sure if this is a bug but astroid doesn't properly give the line numbers 49 | of the call. 50 | 51 | Example: 52 | >>> 1. foo( 53 | >>> 2. bar, 54 | >>> 3. fizz, 55 | >>> 4. thing=None 56 | >>> 5. ) 57 | 58 | If you were to ask me "what lines does `foo` take up?" I would say line 1-5. 59 | But astroid doesn't count the line where the ending ")" is positioned. 60 | If asked the same question, astroid would say it's lines 1-4. 61 | 62 | This function exists to correct that mistake. 63 | 64 | Args: 65 | node (): A called object to parse. 66 | lines (list[str]): The lines of source code that `node` is a part of. 67 | 68 | Returns: 69 | int: The found ending line number. If the line number could not be parsed, 70 | this function returns back -1, instead. 71 | 72 | ''' 73 | _LINE_ENDING = re.compile('\):*(?:\s*#[\w\s]*)?$') 74 | # tolineno is 1-based so subtract 1 75 | zeroed_lineno = node.tolineno - 1 76 | 77 | if _LINE_ENDING.search(lines[zeroed_lineno]): 78 | return node.tolineno 79 | 80 | for index, line in enumerate(lines[zeroed_lineno + 1:]): 81 | index += 1 # Make the line 1-based 82 | 83 | if _LINE_ENDING.search(line): 84 | return node.tolineno + index 85 | 86 | # This shouldn't ever happen because the cases above should catch it 87 | return -1 88 | 89 | 90 | def get_nearest_call(code, row): 91 | '''Find the node in some code that is closest to the given row. 92 | 93 | Args: 94 | code (str): The Python code to parse. 95 | row (int): The 0-based row where the Call objects is expected to be. 96 | 97 | Returns: 98 | or NoneType: The found node, if any. 99 | 100 | ''' 101 | node = astroid.parse(code) 102 | visitor = CallVisitor() 103 | visitor.visit(node) 104 | 105 | lines = code.split('\n') 106 | 107 | get_real_tolineno = functools.partial(get_tolineno, lines=lines) 108 | 109 | for node in visitor.expressions: 110 | if isinstance(node, astroid.Call): 111 | tolineno = get_real_tolineno(node) 112 | is_row_on_single_line_call = (node.fromlineno == tolineno and row == node.fromlineno) 113 | is_row_within_multi_line_call = (node.fromlineno != tolineno and row >= node.fromlineno and row <= tolineno) 114 | 115 | if is_row_on_single_line_call or is_row_within_multi_line_call: 116 | return node 117 | 118 | 119 | def get_parameter_info(script): 120 | '''Find the parameter definition for a function call and its default values. 121 | 122 | Note: 123 | This function does NOT give the default value that the user wrote 124 | for the function call. It's the default value that was used for the 125 | object's definition. To get the actual default value info, use . 126 | 127 | Args: 128 | (): The script whose row/column is positioned directly 129 | over the call that must be parsed for parameter data. 130 | 131 | Returns: 132 | dict[str, str]: The keywords and their defined default values. 133 | 134 | ''' 135 | try: 136 | signature = script.call_signatures()[0] 137 | except IndexError: 138 | return dict() 139 | 140 | info = dict() 141 | for parameter in signature.params: 142 | default = common.get_default(parameter.description) 143 | 144 | if default: 145 | info[str(parameter.name)] = default 146 | 147 | return info 148 | 149 | 150 | def get_parameter_values(node): 151 | '''Find the parameter definition for a function call and its default values. 152 | 153 | Note: 154 | This function gives the value that the user wrote for the function call. 155 | To get the default value for that callable object's definition, 156 | use . 157 | 158 | Args: 159 | node (): The callable object to parse. 160 | 161 | Returns: 162 | dict[str, str]: The keywords and the user's defined value. 163 | 164 | ''' 165 | items = dict() 166 | keywords = node.keywords or [] 167 | 168 | for child in keywords: 169 | items[child.arg] = child.value.as_string() 170 | 171 | return items 172 | 173 | 174 | def get_unchanged_keywords(node, script): 175 | '''Check some code and determine which call keywords are set to their defaults. 176 | 177 | Args: 178 | node (): 179 | The callable object to parse. 180 | script (): 181 | The script whose row/column is positioned directly over the call 182 | that must be parsed for parameter data. 183 | 184 | Raises: 185 | RuntimeError: 186 | If astroid and Jedi created different keyword results. 187 | This should never happen but, if it did, it'll create many errors 188 | so this function bails out early. 189 | 190 | Returns: 191 | list[tuple[str, str]]: The keywords and their defined default values. 192 | 193 | ''' 194 | parameters = get_parameter_info(script) 195 | values = get_parameter_values(node) 196 | 197 | if not parameters or not values: 198 | return dict() 199 | 200 | unchanged = [] 201 | 202 | for keyword, value in values.items(): 203 | default = parameters[keyword] 204 | if default == value: 205 | unchanged.append((keyword, value)) 206 | 207 | return unchanged 208 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/brain/brain_gi.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2015-2016 Claudiu Popa 2 | 3 | # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html 4 | # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER 5 | 6 | """Astroid hooks for the Python 2 GObject introspection bindings. 7 | 8 | Helps with understanding everything imported from 'gi.repository' 9 | """ 10 | 11 | import inspect 12 | import itertools 13 | import sys 14 | import re 15 | import warnings 16 | 17 | from astroid import MANAGER, AstroidBuildingError, nodes 18 | from astroid.builder import AstroidBuilder 19 | 20 | 21 | _inspected_modules = {} 22 | 23 | _identifier_re = r'^[A-Za-z_]\w*$' 24 | 25 | def _gi_build_stub(parent): 26 | """ 27 | Inspect the passed module recursively and build stubs for functions, 28 | classes, etc. 29 | """ 30 | classes = {} 31 | functions = {} 32 | constants = {} 33 | methods = {} 34 | for name in dir(parent): 35 | if name.startswith("__"): 36 | continue 37 | 38 | # Check if this is a valid name in python 39 | if not re.match(_identifier_re, name): 40 | continue 41 | 42 | try: 43 | obj = getattr(parent, name) 44 | except: 45 | continue 46 | 47 | if inspect.isclass(obj): 48 | classes[name] = obj 49 | elif (inspect.isfunction(obj) or 50 | inspect.isbuiltin(obj)): 51 | functions[name] = obj 52 | elif (inspect.ismethod(obj) or 53 | inspect.ismethoddescriptor(obj)): 54 | methods[name] = obj 55 | elif (str(obj).startswith(", ) 169 | # Only accept function calls with two constant arguments 170 | if len(node.args) != 2: 171 | return False 172 | 173 | if not all(isinstance(arg, nodes.Const) for arg in node.args): 174 | return False 175 | 176 | func = node.func 177 | if isinstance(func, nodes.Attribute): 178 | if func.attrname != 'require_version': 179 | return False 180 | if isinstance(func.expr, nodes.Name) and func.expr.name == 'gi': 181 | return True 182 | 183 | return False 184 | 185 | if isinstance(func, nodes.Name): 186 | return func.name == 'require_version' 187 | 188 | return False 189 | 190 | def _register_require_version(node): 191 | # Load the gi.require_version locally 192 | try: 193 | import gi 194 | gi.require_version(node.args[0].value, node.args[1].value) 195 | except Exception: 196 | pass 197 | 198 | return node 199 | 200 | MANAGER.register_failed_import_hook(_import_gi_module) 201 | MANAGER.register_transform(nodes.Call, _register_require_version, _looks_like_require_version) 202 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/ultisnipsaide/parsers/numberify.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | '''The module responsible for making a string into an auto_docstring string. 5 | 6 | Basically, a string that looks like this, "foo {bar} {!f} thing {here!f}." 7 | would need to be converted to "foo {bar} {1!f} thing {2:here!f}." 8 | 9 | {!f} is used as a marker to indicate areas that auto_docstring 10 | should be interested in. This information gets used by other text tools, 11 | like UltiSnips, to generate the final docstring. 12 | 13 | ''' 14 | 15 | # IMPORT STANDARD LIBRARIES 16 | import uuid 17 | import re 18 | 19 | # IMPORT LOCAL LIBRARIES 20 | from . import ultisnips_build 21 | 22 | 23 | class RecursiveNumberifyParser(ultisnips_build.RecursiveParser): 24 | 25 | '''The class that converts a Python string to an auto_docstring string.''' 26 | 27 | _conversion_compiled = re.compile(r'(?P\d*)(?P.*)(?P!\w)$') 28 | 29 | def __init__(self): 30 | '''Create this instance and keep a reference to all used numbers.''' 31 | super(RecursiveNumberifyParser, self).__init__() 32 | self._used_names = dict() 33 | self._used_numbers = set() 34 | 35 | @classmethod 36 | def _get_conversion_info(cls, text): 37 | '''Get the group information of the given `text`, if there is any. 38 | 39 | Args: 40 | text (str): The text to parse, using regex. 41 | 42 | Returns: 43 | dict[str, str]: The found information from `text`. 44 | "number" (str): The number assigned to `text`, if any. 45 | "text" (str): The body of the string, if any. 46 | "conversion" (str): The conversion marker of text, if any. 47 | If there is one, it is usually "!f". 48 | 49 | ''' 50 | info = cls._conversion_compiled.match(text) 51 | try: 52 | return info.groupdict() 53 | except AttributeError: 54 | return dict() 55 | 56 | @staticmethod 57 | def _wrap(items): 58 | '''Add {}s around the given items. 59 | 60 | Args: 61 | items (list[str]): The items to join and wrap. 62 | 63 | Returns: 64 | str: The output text. 65 | 66 | ''' 67 | text = ''.join(items) 68 | return '{{{}}}'.format(text) 69 | 70 | def _convert(self, text, force=False): 71 | '''Add a number indicator to the given `text`, if needed. 72 | 73 | Args: 74 | text (str): The text to convert. 75 | force (bool, optional): Unused in this method. Default is False. 76 | 77 | Returns: 78 | str: The converted text. 79 | 80 | ''' 81 | info = self._get_conversion_info(text) 82 | if not info: 83 | # If info is empty, we can safely return the original text 84 | return text 85 | 86 | conversion = info.get('conversion', '') 87 | 88 | latest_number = self._register_and_get_next_number( 89 | text=info.get('text', ''), 90 | stored_number=info.get('number', 0), 91 | ) 92 | 93 | return '{latest_number}{text}{conversion}'.format( 94 | latest_number=latest_number, 95 | text=info.get('text', ''), 96 | conversion=conversion) 97 | 98 | @staticmethod 99 | def _tag(text): 100 | '''str: Do not tag the given text.''' 101 | return text 102 | 103 | def _register_and_get_next_number(self, text='', stored_number=0): 104 | '''Find the next number that this instance should use for formatting. 105 | 106 | If `text` is not empty, check if the name was already used. 107 | If the used name is in our cached used names and the number along with 108 | that used name is the same the number that we have stored for this text 109 | then do not modify `text`'s number and just return it. 110 | 111 | Otherwise though, we need a new number. 112 | 113 | Args: 114 | text (`str`, optional): 115 | The text to use to query the next number. 116 | stored_number (`int`, optional): 117 | The suggested number to use for text, if any. 118 | Default: 0. 119 | 120 | Returns: 121 | int: The next number to use. 122 | 123 | ''' 124 | self._used_names.setdefault(text, dict()) 125 | 126 | try: 127 | latest_number = max(self._used_numbers) + 1 128 | except ValueError: 129 | latest_number = 1 130 | 131 | if not text: 132 | self._used_names[text][stored_number] = latest_number 133 | self._used_numbers.add(latest_number) 134 | return latest_number 135 | 136 | try: 137 | return self._used_names[text][stored_number] 138 | except KeyError: 139 | self._used_names[text][stored_number] = latest_number 140 | self._used_numbers.add(latest_number) 141 | return latest_number 142 | 143 | def parse(self, text): 144 | '''Clear the stored names and numbers and then parse the given `text`. 145 | 146 | Args: 147 | text (str): 148 | The text to add numbers and markers to and to convert to 149 | an auto_docstring-compatible string. 150 | 151 | Returns: 152 | str: The parsed text. 153 | 154 | ''' 155 | self.clear() 156 | return super(RecursiveNumberifyParser, self).parse(text=text) 157 | 158 | @classmethod 159 | def add_conversion(cls, text): 160 | '''Do the main work of the class by adding numbers and markers to `text`. 161 | 162 | Args: 163 | text (str): The text to "numberify". 164 | 165 | Returns: 166 | str: The converted text. 167 | 168 | ''' 169 | # expected - text that doesn't already have !f on it 170 | def _add_conversion(items): 171 | if not ultisnips_build._is_itertype(items): 172 | return items 173 | 174 | try: 175 | is_convertible = cls._is_list_convertible(items) 176 | except AttributeError: 177 | # If this happens, it's because items is a nested list 178 | # Since lists are recursively processed by _add_conversion, it's 179 | # OK to just set this value to False. Other recursion levels 180 | # will sort it out 181 | # 182 | is_convertible = False 183 | 184 | for index, item in enumerate(items): 185 | items[index] = _add_conversion(item) 186 | 187 | if not is_convertible: 188 | items.insert(0, ':') 189 | items.insert(0, str(_get_unique_number())) 190 | items.append(cls.conversion_text) 191 | 192 | # Re-add the "{}"s that pyparsing removed 193 | output = cls._wrap(items) 194 | return output 195 | 196 | output = cls._parse(text, function=_add_conversion) 197 | 198 | # Remove the trailing !f that gets added 199 | output = output[:-2] 200 | return output 201 | 202 | def clear(self): 203 | '''Remove all known names and numbers from this instance.''' 204 | self._used_names = self._used_names.__class__() 205 | self._used_numbers = self._used_numbers.__class__() 206 | 207 | 208 | def _get_unique_number(): 209 | '''int: Get a unique (non-repeated) number value.''' 210 | return uuid.uuid4().int 211 | -------------------------------------------------------------------------------- /pythonx/python_function_expander/vendors/astroid/exceptions.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2007, 2009-2010, 2013 LOGILAB S.A. (Paris, FRANCE) 2 | # Copyright (c) 2014 Google, Inc. 3 | # Copyright (c) 2015-2016 Cara Vinson 4 | # Copyright (c) 2015-2016 Claudiu Popa 5 | 6 | # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html 7 | # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER 8 | 9 | """this module contains exceptions used in the astroid library 10 | """ 11 | from astroid import util 12 | 13 | 14 | class AstroidError(Exception): 15 | """base exception class for all astroid related exceptions 16 | 17 | AstroidError and its subclasses are structured, intended to hold 18 | objects representing state when the exception is thrown. Field 19 | values are passed to the constructor as keyword-only arguments. 20 | Each subclass has its own set of standard fields, but use your 21 | best judgment to decide whether a specific exception instance 22 | needs more or fewer fields for debugging. Field values may be 23 | used to lazily generate the error message: self.message.format() 24 | will be called with the field names and values supplied as keyword 25 | arguments. 26 | """ 27 | def __init__(self, message='', **kws): 28 | super(AstroidError, self).__init__(message) 29 | self.message = message 30 | for key, value in kws.items(): 31 | setattr(self, key, value) 32 | 33 | def __str__(self): 34 | return self.message.format(**vars(self)) 35 | 36 | 37 | class AstroidBuildingError(AstroidError): 38 | """exception class when we are unable to build an astroid representation 39 | 40 | Standard attributes: 41 | modname: Name of the module that AST construction failed for. 42 | error: Exception raised during construction. 43 | """ 44 | 45 | def __init__(self, message='Failed to import module {modname}.', **kws): 46 | super(AstroidBuildingError, self).__init__(message, **kws) 47 | 48 | 49 | class AstroidImportError(AstroidBuildingError): 50 | """Exception class used when a module can't be imported by astroid.""" 51 | 52 | 53 | class TooManyLevelsError(AstroidImportError): 54 | """Exception class which is raised when a relative import was beyond the top-level. 55 | 56 | Standard attributes: 57 | level: The level which was attempted. 58 | name: the name of the module on which the relative import was attempted. 59 | """ 60 | level = None 61 | name = None 62 | 63 | def __init__(self, message='Relative import with too many levels ' 64 | '({level}) for module {name!r}', **kws): 65 | super(TooManyLevelsError, self).__init__(message, **kws) 66 | 67 | 68 | class AstroidSyntaxError(AstroidBuildingError): 69 | """Exception class used when a module can't be parsed.""" 70 | 71 | 72 | class NoDefault(AstroidError): 73 | """raised by function's `default_value` method when an argument has 74 | no default value 75 | 76 | Standard attributes: 77 | func: Function node. 78 | name: Name of argument without a default. 79 | """ 80 | func = None 81 | name = None 82 | 83 | def __init__(self, message='{func!r} has no default for {name!r}.', **kws): 84 | super(NoDefault, self).__init__(message, **kws) 85 | 86 | 87 | class ResolveError(AstroidError): 88 | """Base class of astroid resolution/inference error. 89 | 90 | ResolveError is not intended to be raised. 91 | 92 | Standard attributes: 93 | context: InferenceContext object. 94 | """ 95 | context = None 96 | 97 | 98 | class MroError(ResolveError): 99 | """Error raised when there is a problem with method resolution of a class. 100 | 101 | Standard attributes: 102 | mros: A sequence of sequences containing ClassDef nodes. 103 | cls: ClassDef node whose MRO resolution failed. 104 | context: InferenceContext object. 105 | """ 106 | mros = () 107 | cls = None 108 | 109 | def __str__(self): 110 | mro_names = ", ".join("({})".format(", ".join(b.name for b in m)) 111 | for m in self.mros) 112 | return self.message.format(mros=mro_names, cls=self.cls) 113 | 114 | 115 | class DuplicateBasesError(MroError): 116 | """Error raised when there are duplicate bases in the same class bases.""" 117 | 118 | 119 | class InconsistentMroError(MroError): 120 | """Error raised when a class's MRO is inconsistent.""" 121 | 122 | 123 | class SuperError(ResolveError): 124 | 125 | """Error raised when there is a problem with a super call. 126 | 127 | Standard attributes: 128 | super_: The Super instance that raised the exception. 129 | context: InferenceContext object. 130 | """ 131 | super_ = None 132 | 133 | def __str__(self): 134 | return self.message.format(**vars(self.super_)) 135 | 136 | 137 | class InferenceError(ResolveError): 138 | """raised when we are unable to infer a node 139 | 140 | Standard attributes: 141 | node: The node inference was called on. 142 | context: InferenceContext object. 143 | """ 144 | node = None 145 | context = None 146 | 147 | def __init__(self, message='Inference failed for {node!r}.', **kws): 148 | super(InferenceError, self).__init__(message, **kws) 149 | 150 | 151 | # Why does this inherit from InferenceError rather than ResolveError? 152 | # Changing it causes some inference tests to fail. 153 | class NameInferenceError(InferenceError): 154 | """Raised when a name lookup fails, corresponds to NameError. 155 | 156 | Standard attributes: 157 | name: The name for which lookup failed, as a string. 158 | scope: The node representing the scope in which the lookup occurred. 159 | context: InferenceContext object. 160 | """ 161 | name = None 162 | scope = None 163 | 164 | def __init__(self, message='{name!r} not found in {scope!r}.', **kws): 165 | super(NameInferenceError, self).__init__(message, **kws) 166 | 167 | 168 | class AttributeInferenceError(ResolveError): 169 | """Raised when an attribute lookup fails, corresponds to AttributeError. 170 | 171 | Standard attributes: 172 | target: The node for which lookup failed. 173 | attribute: The attribute for which lookup failed, as a string. 174 | context: InferenceContext object. 175 | """ 176 | target = None 177 | attribute = None 178 | 179 | def __init__(self, message='{attribute!r} not found on {target!r}.', **kws): 180 | super(AttributeInferenceError, self).__init__(message, **kws) 181 | 182 | 183 | class UseInferenceDefault(Exception): 184 | """exception to be raised in custom inference function to indicate that it 185 | should go back to the default behaviour 186 | """ 187 | 188 | 189 | class _NonDeducibleTypeHierarchy(Exception): 190 | """Raised when is_subtype / is_supertype can't deduce the relation between two types.""" 191 | 192 | 193 | class AstroidIndexError(AstroidError): 194 | """Raised when an Indexable / Mapping does not have an index / key.""" 195 | 196 | 197 | class AstroidTypeError(AstroidError): 198 | """Raised when a TypeError would be expected in Python code.""" 199 | 200 | 201 | class InferenceOverwriteError(AstroidError): 202 | """Raised when an inference tip is overwritten 203 | 204 | Currently only used for debugging. 205 | """ 206 | 207 | 208 | # Backwards-compatibility aliases 209 | OperationError = util.BadOperationMessage 210 | UnaryOperationError = util.BadUnaryOperationMessage 211 | BinaryOperationError = util.BadBinaryOperationMessage 212 | 213 | SuperArgumentTypeError = SuperError 214 | UnresolvableName = NameInferenceError 215 | NotFoundError = AttributeInferenceError 216 | AstroidBuildingException = AstroidBuildingError 217 | --------------------------------------------------------------------------------