~inkscape.dev/inkscape-devlibs64/trunk

« back to all changes in this revision

Viewing changes to python/Lib/lib2to3/fixes/fix_ws_comma.py

  • Committer: Eduard Braun
  • Date: 2016-10-22 16:51:19 UTC
  • Revision ID: eduard.braun2@gmx.de-20161022165119-9eosgy6lp8j1kzli
Update Python to version 2.7.12

Included modules:
  coverage 4.2
  lxml 3.6.4
  numpy 1.11.2
  scour 0.35
  six 1.10.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
"""Fixer that changes 'a ,b' into 'a, b'.
2
 
 
3
 
This also changes '{a :b}' into '{a: b}', but does not touch other
4
 
uses of colons.  It does not touch other uses of whitespace.
5
 
 
6
 
"""
7
 
 
8
 
from .. import pytree
9
 
from ..pgen2 import token
10
 
from .. import fixer_base
11
 
 
12
 
class FixWsComma(fixer_base.BaseFix):
13
 
 
14
 
    explicit = True # The user must ask for this fixers
15
 
 
16
 
    PATTERN = """
17
 
    any<(not(',') any)+ ',' ((not(',') any)+ ',')* [not(',') any]>
18
 
    """
19
 
 
20
 
    COMMA = pytree.Leaf(token.COMMA, u",")
21
 
    COLON = pytree.Leaf(token.COLON, u":")
22
 
    SEPS = (COMMA, COLON)
23
 
 
24
 
    def transform(self, node, results):
25
 
        new = node.clone()
26
 
        comma = False
27
 
        for child in new.children:
28
 
            if child in self.SEPS:
29
 
                prefix = child.prefix
30
 
                if prefix.isspace() and u"\n" not in prefix:
31
 
                    child.prefix = u""
32
 
                comma = True
33
 
            else:
34
 
                if comma:
35
 
                    prefix = child.prefix
36
 
                    if not prefix:
37
 
                        child.prefix = u" "
38
 
                comma = False
39
 
        return new
 
1
"""Fixer that changes 'a ,b' into 'a, b'.
 
2
 
 
3
This also changes '{a :b}' into '{a: b}', but does not touch other
 
4
uses of colons.  It does not touch other uses of whitespace.
 
5
 
 
6
"""
 
7
 
 
8
from .. import pytree
 
9
from ..pgen2 import token
 
10
from .. import fixer_base
 
11
 
 
12
class FixWsComma(fixer_base.BaseFix):
 
13
 
 
14
    explicit = True # The user must ask for this fixers
 
15
 
 
16
    PATTERN = """
 
17
    any<(not(',') any)+ ',' ((not(',') any)+ ',')* [not(',') any]>
 
18
    """
 
19
 
 
20
    COMMA = pytree.Leaf(token.COMMA, u",")
 
21
    COLON = pytree.Leaf(token.COLON, u":")
 
22
    SEPS = (COMMA, COLON)
 
23
 
 
24
    def transform(self, node, results):
 
25
        new = node.clone()
 
26
        comma = False
 
27
        for child in new.children:
 
28
            if child in self.SEPS:
 
29
                prefix = child.prefix
 
30
                if prefix.isspace() and u"\n" not in prefix:
 
31
                    child.prefix = u""
 
32
                comma = True
 
33
            else:
 
34
                if comma:
 
35
                    prefix = child.prefix
 
36
                    if not prefix:
 
37
                        child.prefix = u" "
 
38
                comma = False
 
39
        return new