comparison roundup/anypy/strings.py @ 7771:4261449081be

chore: fix spacing/indent, ignore rule, reduce if/elif with or
author John Rouillard <rouilj@ieee.org>
date Sat, 02 Mar 2024 04:26:33 -0500
parents c65e0a725c88
children
comparison
equal deleted inserted replaced
7770:f002747b6773 7771:4261449081be
60 return u.encode('utf-8') 60 return u.encode('utf-8')
61 61
62 62
63 def us2u(s, errors='strict'): 63 def us2u(s, errors='strict'):
64 """Convert a string or Unicode string to a Unicode string.""" 64 """Convert a string or Unicode string to a Unicode string."""
65 if _py3: 65 if _py3 or isinstance(s, unicode): # noqa: F821
66 return s
67 elif isinstance(s, unicode): # noqa: F821
68 return s 66 return s
69 else: 67 else:
70 return unicode(s, 'utf-8', errors) # noqa: F821 68 return unicode(s, 'utf-8', errors) # noqa: F821
71 69
72 70
146 except SyntaxError: 144 except SyntaxError:
147 # handle case where link operation reports id a long 145 # handle case where link operation reports id a long
148 # int ('issue', 5002L, "status") rather than as a 146 # int ('issue', 5002L, "status") rather than as a
149 # string. This was a bug that existed and was fixed 147 # string. This was a bug that existed and was fixed
150 # before or with v1.2.0 148 # before or with v1.2.0
151 import re 149 import re # noqa: PLC0415
152 v = ast.literal_eval(re.sub(r', ([0-9]+)L,', r', \1,', s)) 150 v = ast.literal_eval(re.sub(r', ([0-9]+)L,', r', \1,', s))
153 151
154 if isinstance(v, str): 152 if isinstance(v, str):
155 return v.encode('iso-8859-1').decode('utf-8') 153 return v.encode('iso-8859-1').decode('utf-8')
156 elif isinstance(v, dict): 154 elif isinstance(v, dict):
164 v_mod[key] = value 162 v_mod[key] = value
165 return v_mod 163 return v_mod
166 else: 164 else:
167 return v 165 return v
168 else: 166 else:
169 return ast.literal_eval(s) 167 return ast.literal_eval(s)
170 168
171 except (ValueError, SyntaxError) as e: 169 except (ValueError, SyntaxError) as e:
172 raise ValueError( 170 raise ValueError(
173 ("Error %(exception)s trying to parse value '%(value)s'") % 171 ("Error %(exception)s trying to parse value '%(value)s'") %
174 { 'exception': e, 'value': s}) 172 {'exception': e, 'value': s})
175

Roundup Issue Tracker: http://roundup-tracker.org/