~pythoneers/ubuntu/lucid/python2.6/ltsppa

« back to all changes in this revision

Viewing changes to Lib/lib2to3/fixes/fix_urllib.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2010-03-11 13:30:19 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20100311133019-sonignhpjsu6ld0x
Tags: 2.6.5~rc2-0ubuntu1
Python 2.6.5 release candidate 2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
MAPPING = {'urllib':  [
13
13
                ('urllib.request',
14
14
                    ['URLOpener', 'FancyURLOpener', 'urlretrieve',
15
 
                     '_urlopener', 'urlcleanup']),
 
15
                     '_urlopener', 'urlopen', 'urlcleanup',
 
16
                     'pathname2url', 'url2pathname']),
16
17
                ('urllib.parse',
17
18
                    ['quote', 'quote_plus', 'unquote', 'unquote_plus',
18
 
                     'urlencode', 'pathname2url', 'url2pathname', 'splitattr',
19
 
                     'splithost', 'splitnport', 'splitpasswd', 'splitport',
20
 
                     'splitquery', 'splittag', 'splittype', 'splituser',
21
 
                     'splitvalue', ]),
 
19
                     'urlencode', 'splitattr', 'splithost', 'splitnport',
 
20
                     'splitpasswd', 'splitport', 'splitquery', 'splittag',
 
21
                     'splittype', 'splituser', 'splitvalue', ]),
22
22
                ('urllib.error',
23
23
                    ['ContentTooShortError'])],
24
24
           'urllib2' : [
63
63
            yield """import_name< 'import'
64
64
                                  dotted_as_name< module_as=%r 'as' any > >
65
65
                  """ % old_module
66
 
            yield """power< module_dot=%r trailer< '.' member=%s > any* >
 
66
            # bare_with_attr has a special significance for FixImports.match().
 
67
            yield """power< bare_with_attr=%r trailer< '.' member=%s > any* >
67
68
                  """ % (old_module, members)
68
69
 
69
70
 
78
79
           replacements.
79
80
        """
80
81
        import_mod = results.get('module')
81
 
        pref = import_mod.get_prefix()
 
82
        pref = import_mod.prefix
82
83
 
83
84
        names = []
84
85
 
94
95
           module.
95
96
        """
96
97
        mod_member = results.get('mod_member')
97
 
        pref = mod_member.get_prefix()
 
98
        pref = mod_member.prefix
98
99
        member = results.get('member')
99
100
 
100
101
        # Simple case with only a single member being imported
150
151
 
151
152
    def transform_dot(self, node, results):
152
153
        """Transform for calls to module members in code."""
153
 
        module_dot = results.get('module_dot')
 
154
        module_dot = results.get('bare_with_attr')
154
155
        member = results.get('member')
155
 
        # this may be a list of length one, or just a node
 
156
        new_name = None
156
157
        if isinstance(member, list):
157
158
            member = member[0]
158
 
        new_name = None
159
159
        for change in MAPPING[module_dot.value]:
160
160
            if member.value in change[1]:
161
161
                new_name = change[0]
162
162
                break
163
163
        if new_name:
164
164
            module_dot.replace(Name(new_name,
165
 
                                    prefix=module_dot.get_prefix()))
 
165
                                    prefix=module_dot.prefix))
166
166
        else:
167
167
            self.cannot_convert(node, 'This is an invalid module element')
168
168
 
171
171
            self.transform_import(node, results)
172
172
        elif results.get('mod_member'):
173
173
            self.transform_member(node, results)
174
 
        elif results.get('module_dot'):
 
174
        elif results.get('bare_with_attr'):
175
175
            self.transform_dot(node, results)
176
176
        # Renaming and star imports are not supported for these modules.
177
177
        elif results.get('module_star'):