MCPcopy Create free account
hub / github.com/scottrogowski/code2flow / ascii

Function ascii

tests/test_code/py/pytz/__init__.py:47–60  ·  view source on GitHub ↗

r""" >>> ascii('Hello') 'Hello' >>> ascii('\N{TRADE MARK SIGN}') #doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ... UnicodeEncodeError: ...

(s)

Source from the content-addressed store, hash-verified

45 unicode = str
46
47 def ascii(s):
48 r"""
49 >>> ascii('Hello')
50 'Hello'
51 >>> ascii('\N{TRADE MARK SIGN}') #doctest: +IGNORE_EXCEPTION_DETAIL
52 Traceback (most recent call last):
53 ...
54 UnicodeEncodeError: ...
55 """
56 if type(s) == bytes:
57 s = s.decode('ASCII')
58 else:
59 s.encode('ASCII') # Raise an exception if not ASCII
60 return s # But the string - not a byte string.
61
62else: # Python 2.x
63

Callers 1

timezoneFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected