backport pylint-brain 27:2c83031cb6a3. Closes #4294, #46273

authorSylvain Th?nault <sylvain.thenault@logilab.fr>
changeset31dd11229614
branchstable
phasepublic
hiddenno
parent revision#55333bb6658e test and fix absolute import handling. Closes #106191
child revision#604235790ace 0.24.1
files modified by this revision
brain/py2mechanize.py
brain/py2qt4.py
brain/py2stdlib.py
# HG changeset patch
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1349434049 -7200
# Fri Oct 05 12:47:29 2012 +0200
# Branch stable
# Node ID 31dd11229614836d52478e1097ccd2281221dc57
# Parent 55333bb6658e5fe9b0d0217193497ba9153e35be
backport pylint-brain 27:2c83031cb6a3. Closes #4294, #46273

diff --git a/brain/py2mechanize.py b/brain/py2mechanize.py
@@ -0,0 +1,20 @@
1 +from logilab.astng import MANAGER
2 +from logilab.astng.builder import ASTNGBuilder
3 +
4 +def mechanize_transform(module):
5 +    fake = ASTNGBuilder(MANAGER).string_build('''
6 +
7 +class Browser(object):
8 +    def open(self, url, data=None, timeout=None):
9 +        return None
10 +    def open_novisit(self, url, data=None, timeout=None):
11 +        return None
12 +    def open_local_file(self, filename):
13 +        return None
14 +
15 +''')
16 +    module.locals['Browser'] = fake.locals['Browser']
17 +
18 +import py2stdlib
19 +py2stdlib.MODULE_TRANSFORMS['mechanize'] = mechanize_transform
20 +
diff --git a/brain/py2qt4.py b/brain/py2qt4.py
@@ -0,0 +1,25 @@
21 +"""ASTNG hooks for the Python 2 qt4 module.
22 +
23 +Currently help understanding of :
24 +
25 +* PyQT4.QtCore
26 +"""
27 +
28 +from logilab.astng import MANAGER
29 +from logilab.astng.builder import ASTNGBuilder
30 +
31 +
32 +def pyqt4_qtcore_transform(module):
33 +    fake = ASTNGBuilder(MANAGER).string_build('''
34 +
35 +def SIGNAL(signal_name): pass
36 +
37 +class QObject(object):
38 +    def emit(self, signal): pass
39 +''')
40 +    for klass in ('QObject',):
41 +        module.locals[klass] = fake.locals[klass]
42 +
43 +
44 +import py2stdlib
45 +py2stdlib.MODULE_TRANSFORMS['PyQt4.QtCore'] = pyqt4_qtcore_transform
diff --git a/brain/py2stdlib.py b/brain/py2stdlib.py
@@ -93,20 +93,63 @@
46  ''')
47 
48      for func_name, func in fake.locals.items():
49          module.locals[func_name] = func
50 
51 -    # for func in ('resource_exists', 'resource_isdir', 'resource_filename',
52 -    #     'resource_stream', 'resource_string', 'resource_listdir',
53 -    #     'extraction_error', 'get_cache_path', 'postprocess',
54 -    #     'set_extraction_path', 'cleanup_resources'):
55 
56 -    #     module.locals[func] = fake.locals[func]
57 +def urlparse_transform(module):
58 +    fake = ASTNGBuilder(MANAGER).string_build('''
59 +
60 +def urlparse(urlstring, default_scheme='', allow_fragments=True):
61 +    return ParseResult()
62 +
63 +class ParseResult(object):
64 +    def __init__(self):
65 +        self.scheme = ''
66 +        self.netloc = ''
67 +        self.path = ''
68 +        self.params = ''
69 +        self.query = ''
70 +        self.fragment = ''
71 +        self.username = None
72 +        self.password = None
73 +        self.hostname = None
74 +        self.port = None
75 +
76 +    def geturl(self):
77 +        return ''
78 +''')
79 +
80 +    for func_name, func in fake.locals.items():
81 +        module.locals[func_name] = func
82 +
83 +def subprocess_transform(module):
84 +    fake = ASTNGBuilder(MANAGER).string_build('''
85 +
86 +class Popen(object):
87 +
88 +    def __init__(self, args, bufsize=0, executable=None,
89 +                 stdin=None, stdout=None, stderr=None,
90 +                 preexec_fn=None, close_fds=False, shell=False,
91 +                 cwd=None, env=None, universal_newlines=False,
92 +                 startupinfo=None, creationflags=0):
93 +        pass
94 +
95 +    def communicate(self, input=None):
96 +        return ('string', 'string')
97 +    ''')
98 +
99 +    for func_name, func in fake.locals.items():
100 +        module.locals[func_name] = func
101 +
102 +
103 
104  MODULE_TRANSFORMS['hashlib'] = hashlib_transform
105  MODULE_TRANSFORMS['collections'] = collections_transform
106  MODULE_TRANSFORMS['pkg_resources'] = pkg_resources_transform
107 +MODULE_TRANSFORMS['urlparse'] = urlparse_transform
108 +MODULE_TRANSFORMS['subprocess'] = subprocess_transform
109 
110 
111  def transform(module):
112      try:
113          tr = MODULE_TRANSFORMS[module.name]
@@ -115,5 +158,7 @@
114      else:
115          tr(module)
116 
117  from logilab.astng import MANAGER
118  MANAGER.register_transformer(transform)
119 +
120 +