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