]>
git.proxmox.com Git - mirror_edk2.git/blob - AppPkg/Applications/Python/Python-2.7.2/Lib/lib2to3/fixes/fix_itertools_imports.py
8758fb99c2fcc0e16b0fd406870bf7de7cfb35a4
1 """ Fixer for imports of itertools.(imap|ifilter|izip|ifilterfalse) """
4 from lib2to3
import fixer_base
5 from lib2to3
.fixer_util
import BlankLine
, syms
, token
8 class FixItertoolsImports(fixer_base
.BaseFix
):
11 import_from< 'from' 'itertools' 'import' imports=any >
14 def transform(self
, node
, results
):
15 imports
= results
['imports']
16 if imports
.type == syms
.import_as_name
or not imports
.children
:
19 children
= imports
.children
20 for child
in children
[::2]:
21 if child
.type == token
.NAME
:
24 elif child
.type == token
.STAR
:
25 # Just leave the import as is.
28 assert child
.type == syms
.import_as_name
29 name_node
= child
.children
[0]
30 member_name
= name_node
.value
31 if member_name
in (u
'imap', u
'izip', u
'ifilter'):
34 elif member_name
in (u
'ifilterfalse', u
'izip_longest'):
36 name_node
.value
= (u
'filterfalse' if member_name
[1] == u
'f'
39 # Make sure the import statement is still sane
40 children
= imports
.children
[:] or [imports
]
42 for child
in children
:
43 if remove_comma
and child
.type == token
.COMMA
:
48 while children
and children
[-1].type == token
.COMMA
:
49 children
.pop().remove()
51 # If there are no imports left, just get rid of the entire statement
52 if (not (imports
.children
or getattr(imports
, 'value', None)) or
53 imports
.parent
is None):