MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / python_safe_name

Function python_safe_name

src/commoncode/text.py:121–133  ·  view source on GitHub ↗

Return a name derived from string `s` safe to use as a Python identifier.

(s)

Source from the content-addressed store, hash-verified

119
120
121def python_safe_name(s):
122 """
123 Return a name derived from string `s` safe to use as a Python identifier.
124 """
125 if not isinstance(s, str):
126 s = as_unicode(s)
127 s = toascii(s)
128 s = foldcase(s)
129 s = nopunctuation(s)
130 s = s.replace(" ", "_")
131 s = "_".join(s.split())
132 s = s.strip("_")
133 return s
134
135
136def as_unicode(s):

Callers 8

get_license_expressionFunction · 0.90
process_codebaseMethod · 0.90
build_package_nameFunction · 0.90
pysafe_expressionMethod · 0.90
make_test_functionFunction · 0.90

Calls 7

toasciiFunction · 0.85
foldcaseFunction · 0.85
nopunctuationFunction · 0.85
as_unicodeFunction · 0.70
replaceMethod · 0.45
joinMethod · 0.45
splitMethod · 0.45

Tested by 2

make_test_functionFunction · 0.72