Private helper function. Takes a signature in Argument Clinic's extended signature format. Returns a tuple of two things: * that signature re-rendered in standard Python syntax, and * the index of the "self" parameter (generally 0), or None if the function does not
(signature)
| 2099 | |
| 2100 | |
| 2101 | def _signature_strip_non_python_syntax(signature): |
| 2102 | """ |
| 2103 | Private helper function. Takes a signature in Argument Clinic's |
| 2104 | extended signature format. |
| 2105 | |
| 2106 | Returns a tuple of two things: |
| 2107 | * that signature re-rendered in standard Python syntax, and |
| 2108 | * the index of the "self" parameter (generally 0), or None if |
| 2109 | the function does not have a "self" parameter. |
| 2110 | """ |
| 2111 | |
| 2112 | if not signature: |
| 2113 | return signature, None |
| 2114 | |
| 2115 | self_parameter = None |
| 2116 | |
| 2117 | lines = [l.encode('ascii') for l in signature.split('\n') if l] |
| 2118 | generator = iter(lines).__next__ |
| 2119 | token_stream = tokenize.tokenize(generator) |
| 2120 | |
| 2121 | text = [] |
| 2122 | add = text.append |
| 2123 | |
| 2124 | current_parameter = 0 |
| 2125 | OP = token.OP |
| 2126 | |
| 2127 | # token stream always starts with ENCODING token, skip it |
| 2128 | t = next(token_stream) |
| 2129 | assert t.type == tokenize.ENCODING |
| 2130 | |
| 2131 | for t in token_stream: |
| 2132 | type, string = t.type, t.string |
| 2133 | |
| 2134 | if type == OP: |
| 2135 | if string == ',': |
| 2136 | current_parameter += 1 |
| 2137 | |
| 2138 | if (type == OP) and (string == '$'): |
| 2139 | assert self_parameter is None |
| 2140 | self_parameter = current_parameter |
| 2141 | continue |
| 2142 | |
| 2143 | add(string) |
| 2144 | if (string == ','): |
| 2145 | add(' ') |
| 2146 | clean_signature = ''.join(text).strip().replace("\n", "") |
| 2147 | return clean_signature, self_parameter |
| 2148 | |
| 2149 | |
| 2150 | def _signature_fromstr(cls, obj, s, skip_bound_arg=True): |