Converts key names into parameter names. For example, converting "max-results" -> "max_results" Args: key: string, the method key name. Returns: A safe method name based on the key name.
(key)
| 166 | |
| 167 | |
| 168 | def key2param(key): |
| 169 | """Converts key names into parameter names. |
| 170 | |
| 171 | For example, converting "max-results" -> "max_results" |
| 172 | |
| 173 | Args: |
| 174 | key: string, the method key name. |
| 175 | |
| 176 | Returns: |
| 177 | A safe method name based on the key name. |
| 178 | """ |
| 179 | result = [] |
| 180 | key = list(key) |
| 181 | if not key[0].isalpha(): |
| 182 | result.append("x") |
| 183 | for c in key: |
| 184 | if c.isalnum(): |
| 185 | result.append(c) |
| 186 | else: |
| 187 | result.append("_") |
| 188 | |
| 189 | return "".join(result) |
| 190 | |
| 191 | |
| 192 | @positional(2) |
no outgoing calls
searching dependent graphs…