Show More
@@ -92,6 +92,36 b' def replacetokens(tokens, opts):' | |||||
92 | except IndexError: |
|
92 | except IndexError: | |
93 | break |
|
93 | break | |
94 |
|
94 | |||
|
95 | def _isitemaccess(j): | |||
|
96 | """Assert the next tokens form an item access on `tokens[j]` and that | |||
|
97 | `tokens[j]` is a name. | |||
|
98 | """ | |||
|
99 | try: | |||
|
100 | return ( | |||
|
101 | tokens[j].type == token.NAME | |||
|
102 | and _isop(j + 1, '[') | |||
|
103 | and tokens[j + 2].type == token.STRING | |||
|
104 | and _isop(j + 3, ']') | |||
|
105 | ) | |||
|
106 | except IndexError: | |||
|
107 | return False | |||
|
108 | ||||
|
109 | def _ismethodcall(j, *methodnames): | |||
|
110 | """Assert the next tokens form a call to `methodname` with a string | |||
|
111 | as first argument on `tokens[j]` and that `tokens[j]` is a name. | |||
|
112 | """ | |||
|
113 | try: | |||
|
114 | return ( | |||
|
115 | tokens[j].type == token.NAME | |||
|
116 | and _isop(j + 1, '.') | |||
|
117 | and tokens[j + 2].type == token.NAME | |||
|
118 | and tokens[j + 2].string in methodnames | |||
|
119 | and _isop(j + 3, '(') | |||
|
120 | and tokens[j + 4].type == token.STRING | |||
|
121 | ) | |||
|
122 | except IndexError: | |||
|
123 | return False | |||
|
124 | ||||
95 | coldelta = 0 # column increment for new opening parens |
|
125 | coldelta = 0 # column increment for new opening parens | |
96 | coloffset = -1 # column offset for the current line (-1: TBD) |
|
126 | coloffset = -1 # column offset for the current line (-1: TBD) | |
97 | parens = [(0, 0, 0)] # stack of (line, end-column, column-offset) |
|
127 | parens = [(0, 0, 0)] # stack of (line, end-column, column-offset) |
General Comments 0
You need to be logged in to leave comments.
Login now