Convert camel case to a "pythonic" name. If the name contains the ``sep`` character, then it is returned unchanged.
(name, sep='_', _xform_cache=_xform_cache)
| 176 | |
| 177 | |
| 178 | def xform_name(name, sep='_', _xform_cache=_xform_cache): |
| 179 | """Convert camel case to a "pythonic" name. |
| 180 | |
| 181 | If the name contains the ``sep`` character, then it is |
| 182 | returned unchanged. |
| 183 | |
| 184 | """ |
| 185 | if sep in name: |
| 186 | # If the sep is in the name, assume that it's already |
| 187 | # transformed and return the string unchanged. |
| 188 | return name |
| 189 | key = (name, sep) |
| 190 | if key not in _xform_cache: |
| 191 | if _special_case_transform.search(name) is not None: |
| 192 | is_special = _special_case_transform.search(name) |
| 193 | matched = is_special.group() |
| 194 | # Replace something like ARNs, ACLs with _arns, _acls. |
| 195 | name = name[: -len(matched)] + sep + matched.lower() |
| 196 | s1 = _first_cap_regex.sub(r'\1' + sep + r'\2', name) |
| 197 | transformed = _end_cap_regex.sub(r'\1' + sep + r'\2', s1).lower() |
| 198 | _xform_cache[key] = transformed |
| 199 | return _xform_cache[key] |