astroid-1.0.1/ 0000775 0001754 0001754 00000000000 12230252376 012652 5 ustar syt syt 0000000 0000000 astroid-1.0.1/astroid.egg-info/ 0000775 0001754 0001754 00000000000 12230252376 016011 5 ustar syt syt 0000000 0000000 astroid-1.0.1/astroid.egg-info/SOURCES.txt 0000664 0001754 0001754 00000004314 12230252372 017673 0 ustar syt syt 0000000 0000000 COPYING
COPYING.LESSER
ChangeLog
MANIFEST.in
README
README.Python3
setup.py
./__init__.py
./__pkginfo__.py
./as_string.py
./bases.py
./builder.py
./exceptions.py
./inference.py
./inspector.py
./manager.py
./mixins.py
./node_classes.py
./nodes.py
./protocols.py
./raw_building.py
./rebuilder.py
./scoped_nodes.py
./test_utils.py
./utils.py
./test/unittest_brain.py
./test/unittest_builder.py
./test/unittest_inference.py
./test/unittest_inspector.py
./test/unittest_lookup.py
./test/unittest_manager.py
./test/unittest_nodes.py
./test/unittest_python3.py
./test/unittest_regrtest.py
./test/unittest_scoped_nodes.py
./test/unittest_utils.py
./test/data/__init__.py
./test/data/absimport.py
./test/data/all.py
./test/data/email.py
./test/data/format.py
./test/data/module.py
./test/data/module2.py
./test/data/noendingnewline.py
./test/data/nonregr.py
./test/data/notall.py
./test/data/SSL1/Connection1.py
./test/data/SSL1/__init__.py
./test/data/appl/__init__.py
./test/data/appl/myConnection.py
./test/data2/__init__.py
./test/data2/clientmodule_test.py
./test/data2/suppliermodule_test.py
astroid.egg-info/PKG-INFO
astroid.egg-info/SOURCES.txt
astroid.egg-info/dependency_links.txt
astroid.egg-info/requires.txt
astroid.egg-info/top_level.txt
brain/py2gi.py
brain/py2mechanize.py
brain/py2qt4.py
brain/py2stdlib.py
test/fulltest.sh
test/data/MyPyPa-0.1.0-py2.5.egg
test/data/MyPyPa-0.1.0-py2.5.zip
test/data/__init__.py
test/data/absimport.py
test/data/all.py
test/data/email.py
test/data/format.py
test/data/module.py
test/data/module2.py
test/data/noendingnewline.py
test/data/nonregr.py
test/data/notall.py
test/data/SSL1/Connection1.py
test/data/SSL1/__init__.py
test/data/appl/__init__.py
test/data/appl/myConnection.py
test/data2/__init__.py
test/data2/clientmodule_test.py
test/data2/suppliermodule_test.py
test/regrtest_data/descriptor_crash.py
test/regrtest_data/absimp/__init__.py
test/regrtest_data/absimp/string.py
test/regrtest_data/absimp/sidepackage/__init__.py
test/regrtest_data/package/__init__.py
test/regrtest_data/package/absimport.py
test/regrtest_data/package/hello.py
test/regrtest_data/package/import_package_subpackage_module.py
test/regrtest_data/package/subpackage/__init__.py
test/regrtest_data/package/subpackage/module.py astroid-1.0.1/astroid.egg-info/dependency_links.txt 0000664 0001754 0001754 00000000001 12230252372 022053 0 ustar syt syt 0000000 0000000
astroid-1.0.1/astroid.egg-info/requires.txt 0000664 0001754 0001754 00000000030 12230252372 020376 0 ustar syt syt 0000000 0000000 logilab-common >= 0.60.0 astroid-1.0.1/astroid.egg-info/PKG-INFO 0000664 0001754 0001754 00000005411 12230252372 017103 0 ustar syt syt 0000000 0000000 Metadata-Version: 1.1
Name: astroid
Version: 1.0.1
Summary: rebuild a new abstract syntax tree from Python's ast
Home-page: http://bitbucket.org/logilab/astroid
Author: Logilab
Author-email: python-projects@lists.logilab.org
License: LGPL
Description: Astroid
=======
What's this?
------------
The aim of this module is to provide a common base representation of
python source code for projects such as pychecker, pyreverse,
pylint... Well, actually the development of this library is essentially
governed by pylint's needs. It used to be called logilab-astng.
It provides a compatible representation which comes from the `_ast`
module. It rebuilds the tree generated by the builtin _ast module by
recursively walking down the AST and building an extended ast. The new
node classes have additional methods and attributes for different
usages. They include some support for static inference and local name
scopes. Furthermore, astroid builds partial trees by inspecting living
objects.
Main modules are:
* `bases`, `node_classses` and `scoped_nodes` contain the classes for the
different type of nodes of the tree.
* the `manager` contains a high level object to get astroid trees from
source files and living objects. It maintains a cache of previously
constructed tree for quick access.
Installation
------------
Extract the tarball, jump into the created directory and run::
python setup.py install
For installation options, see::
python setup.py install --help
If you have any questions, please mail the code-quality@python.org
mailing list for support. See
http://mail.python.org/mailman/listinfo/code-quality for subscription
information and archives. You may find older archives at
http://lists.logilab.org/mailman/listinfo/python-projects .
Test
----
Tests are in the 'test' subdirectory. To launch the whole tests suite
at once, you may use the 'pytest' utility from logilab-common (simply
type 'pytest' from within this directory) or if you're running python
>= 2.7, using discover, for instance::
python -m unittest discover -p "unittest*.py"
Platform: UNKNOWN
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Software Development :: Quality Assurance
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 3
astroid-1.0.1/astroid.egg-info/top_level.txt 0000664 0001754 0001754 00000000010 12230252372 020526 0 ustar syt syt 0000000 0000000 astroid
astroid-1.0.1/__init__.py 0000664 0001754 0001754 00000010426 12175502170 014764 0 ustar syt syt 0000000 0000000 # copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
# This file is part of astroid.
#
# astroid is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 2.1 of the License, or (at your
# option) any later version.
#
# astroid is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
# for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with astroid. If not, see .
"""Python Abstract Syntax Tree New Generation
The aim of this module is to provide a common base representation of
python source code for projects such as pychecker, pyreverse,
pylint... Well, actually the development of this library is essentially
governed by pylint's needs.
It extends class defined in the python's _ast module with some
additional methods and attributes. Instance attributes are added by a
builder object, which can either generate extended ast (let's call
them astroid ;) by visiting an existent ast tree or by inspecting living
object. Methods are added by monkey patching ast classes.
Main modules are:
* nodes and scoped_nodes for more information about methods and
attributes added to different node classes
* the manager contains a high level object to get astroid trees from
source files and living objects. It maintains a cache of previously
constructed tree for quick access
* builder contains the class responsible to build astroid trees
"""
__doctype__ = "restructuredtext en"
import sys
import re
from operator import attrgetter
# WARNING: internal imports order matters !
# make all exception classes accessible from astroid package
from astroid.exceptions import *
# make all node classes accessible from astroid package
from astroid.nodes import *
# trigger extra monkey-patching
from astroid import inference
# more stuff available
from astroid import raw_building
from astroid.bases import YES, Instance, BoundMethod, UnboundMethod
from astroid.node_classes import are_exclusive, unpack_infer
from astroid.scoped_nodes import builtin_lookup
# make a manager instance (borg) as well as Project and Package classes
# accessible from astroid package
from astroid.manager import AstroidManager, Project
MANAGER = AstroidManager()
del AstroidManager
# transform utilities (filters and decorator)
class AsStringRegexpPredicate(object):
"""Class to be used as predicate that may be given to `register_transform`
First argument is a regular expression that will be searched against the `as_string`
representation of the node onto which it's applied.
If specified, the second argument is an `attrgetter` expression that will be
applied on the node first to get the actual node on which `as_string` should
be called.
"""
def __init__(self, regexp, expression=None):
self.regexp = re.compile(regexp)
self.expression = expression
def __call__(self, node):
if self.expression is not None:
node = attrgetter(self.expression)(node)
return self.regexp.search(node.as_string())
def inference_tip(infer_function):
"""Given an instance specific inference function, return a function to be
given to MANAGER.register_transform to set this inference function.
Typical usage
.. sourcecode:: python
MANAGER.register_transform(CallFunc, inference_tip(infer_named_tuple),
AsStringRegexpPredicate('namedtuple', 'func'))
"""
def transform(node, infer_function=infer_function):
node._explicit_inference = infer_function
return node
return transform
# load brain plugins
from os import listdir
from os.path import join, dirname
BRAIN_MODULES_DIR = join(dirname(__file__), 'brain')
if BRAIN_MODULES_DIR not in sys.path:
# add it to the end of the list so user path take precedence
sys.path.append(BRAIN_MODULES_DIR)
# load modules in this directory
for module in listdir(BRAIN_MODULES_DIR):
if module.endswith('.py'):
__import__(module[:-3])
astroid-1.0.1/brain/ 0000775 0001754 0001754 00000000000 12230252376 013745 5 ustar syt syt 0000000 0000000 astroid-1.0.1/brain/py2mechanize.py 0000664 0001754 0001754 00000001024 12175502170 016710 0 ustar syt syt 0000000 0000000 from astroid import MANAGER
from astroid.builder import AstroidBuilder
def mechanize_transform(module):
fake = AstroidBuilder(MANAGER).string_build('''
class Browser(object):
def open(self, url, data=None, timeout=None):
return None
def open_novisit(self, url, data=None, timeout=None):
return None
def open_local_file(self, filename):
return None
''')
module.locals['Browser'] = fake.locals['Browser']
import py2stdlib
py2stdlib.MODULE_TRANSFORMS['mechanize'] = mechanize_transform
astroid-1.0.1/brain/py2stdlib.py 0000664 0001754 0001754 00000013463 12211312704 016231 0 ustar syt syt 0000000 0000000 """Astroid hooks for the Python 2 standard library.
Currently help understanding of :
* hashlib.md5 and hashlib.sha1
"""
from astroid import MANAGER, AsStringRegexpPredicate, UseInferenceDefault, inference_tip
from astroid import nodes
from astroid.builder import AstroidBuilder
MODULE_TRANSFORMS = {}
# module specific transformation functions #####################################
def transform(module):
try:
tr = MODULE_TRANSFORMS[module.name]
except KeyError:
pass
else:
tr(module)
MANAGER.register_transform(nodes.Module, transform)
# module specific transformation functions #####################################
def hashlib_transform(module):
template = '''
class %s(object):
def __init__(self, value=''): pass
def digest(self):
return u''
def update(self, value): pass
def hexdigest(self):
return u''
'''
algorithms = ('md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512')
classes = "".join(template % hashfunc for hashfunc in algorithms)
fake = AstroidBuilder(MANAGER).string_build(classes)
for hashfunc in algorithms:
module.locals[hashfunc] = fake.locals[hashfunc]
def collections_transform(module):
fake = AstroidBuilder(MANAGER).string_build('''
class defaultdict(dict):
default_factory = None
def __missing__(self, key): pass
class deque(object):
maxlen = 0
def __init__(iterable=None, maxlen=None): pass
def append(self, x): pass
def appendleft(self, x): pass
def clear(self): pass
def count(self, x): return 0
def extend(self, iterable): pass
def extendleft(self, iterable): pass
def pop(self): pass
def popleft(self): pass
def remove(self, value): pass
def reverse(self): pass
def rotate(self, n): pass
''')
for klass in ('deque', 'defaultdict'):
module.locals[klass] = fake.locals[klass]
def pkg_resources_transform(module):
fake = AstroidBuilder(MANAGER).string_build('''
def resource_exists(package_or_requirement, resource_name):
pass
def resource_isdir(package_or_requirement, resource_name):
pass
def resource_filename(package_or_requirement, resource_name):
pass
def resource_stream(package_or_requirement, resource_name):
pass
def resource_string(package_or_requirement, resource_name):
pass
def resource_listdir(package_or_requirement, resource_name):
pass
def extraction_error():
pass
def get_cache_path(archive_name, names=()):
pass
def postprocess(tempname, filename):
pass
def set_extraction_path(path):
pass
def cleanup_resources(force=False):
pass
''')
for func_name, func in fake.locals.items():
module.locals[func_name] = func
def urlparse_transform(module):
fake = AstroidBuilder(MANAGER).string_build('''
def urlparse(url, scheme='', allow_fragments=True):
return ParseResult()
class ParseResult(object):
def __init__(self):
self.scheme = ''
self.netloc = ''
self.path = ''
self.params = ''
self.query = ''
self.fragment = ''
self.username = None
self.password = None
self.hostname = None
self.port = None
def geturl(self):
return ''
''')
for func_name, func in fake.locals.items():
module.locals[func_name] = func
def subprocess_transform(module):
fake = AstroidBuilder(MANAGER).string_build('''
class Popen(object):
returncode = pid = 0
stdin = stdout = stderr = file()
def __init__(self, args, bufsize=0, executable=None,
stdin=None, stdout=None, stderr=None,
preexec_fn=None, close_fds=False, shell=False,
cwd=None, env=None, universal_newlines=False,
startupinfo=None, creationflags=0):
pass
def communicate(self, input=None):
return ('string', 'string')
def wait(self):
return self.returncode
def poll(self):
return self.returncode
def send_signal(self, signal):
pass
def terminate(self):
pass
def kill(self):
pass
''')
for func_name, func in fake.locals.items():
module.locals[func_name] = func
MODULE_TRANSFORMS['hashlib'] = hashlib_transform
MODULE_TRANSFORMS['collections'] = collections_transform
MODULE_TRANSFORMS['pkg_resources'] = pkg_resources_transform
MODULE_TRANSFORMS['urlparse'] = urlparse_transform
MODULE_TRANSFORMS['subprocess'] = subprocess_transform
# namedtuple support ###########################################################
def infer_named_tuple(node, context=None):
"""Specific inference function for namedtuple CallFunc node"""
# node is a CallFunc node, class name as first argument and generated class
# attributes as second argument
if len(node.args) != 2:
# something weird here, go back to class implementation
raise UseInferenceDefault()
# namedtuple list of attributes can be a list of strings or a
# whitespace-separate string
try:
name = node.args[0].value
try:
attributes = node.args[1].value.split()
except AttributeError:
attributes = [const.value for const in node.args[1].elts]
except AttributeError:
raise UseInferenceDefault()
# we want to return a Class node instance with proper attributes set
class_node = nodes.Class(name, 'docstring')
# set base class=tuple
class_node.bases.append(nodes.Tuple._proxied)
# XXX add __init__(*attributes) method
for attr in attributes:
fake_node = nodes.EmptyNode()
fake_node.parent = class_node
class_node.instance_attrs[attr] = [fake_node]
# we use UseInferenceDefault, we can't be a generator so return an iterator
return iter([class_node])
MANAGER.register_transform(nodes.CallFunc, inference_tip(infer_named_tuple),
AsStringRegexpPredicate('namedtuple', 'func'))
astroid-1.0.1/brain/py2qt4.py 0000664 0001754 0001754 00000001015 12175502170 015455 0 ustar syt syt 0000000 0000000 """Astroid hooks for the Python 2 qt4 module.
Currently help understanding of :
* PyQT4.QtCore
"""
from astroid import MANAGER
from astroid.builder import AstroidBuilder
def pyqt4_qtcore_transform(module):
fake = AstroidBuilder(MANAGER).string_build('''
def SIGNAL(signal_name): pass
class QObject(object):
def emit(self, signal): pass
''')
for klass in ('QObject',):
module.locals[klass] = fake.locals[klass]
import py2stdlib
py2stdlib.MODULE_TRANSFORMS['PyQt4.QtCore'] = pyqt4_qtcore_transform
astroid-1.0.1/brain/py2gi.py 0000664 0001754 0001754 00000010742 12230252355 015352 0 ustar syt syt 0000000 0000000 """Astroid hooks for the Python 2 GObject introspection bindings.
Helps with understanding everything imported from 'gi.repository'
"""
import inspect
import sys
from astroid import MANAGER, AstroidBuildingException
from astroid.builder import AstroidBuilder
_inspected_modules = {}
def _gi_build_stub(parent):
"""
Inspect the passed module recursively and build stubs for functions,
classes, etc.
"""
classes = {}
functions = {}
constants = {}
methods = {}
for name in dir(parent):
if not name or name.startswith("__"):
# GLib.IConv has a parameter named "" :/
continue
try:
obj = getattr(parent, name)
except:
continue
if inspect.isclass(obj):
classes[name] = obj
elif (inspect.isfunction(obj) or
inspect.isbuiltin(obj)):
functions[name] = obj
elif (inspect.ismethod(obj) or
inspect.ismethoddescriptor(obj)):
methods[name] = obj
elif type(obj) in [int, str]:
constants[name] = obj
elif (str(obj).startswith("