forked from python-bugzilla/python-bugzilla
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_util.py
More file actions
31 lines (25 loc) · 820 Bytes
/
_util.py
File metadata and controls
31 lines (25 loc) · 820 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# This work is licensed under the GNU GPLv2 or later.
# See the COPYING file in the top-level directory.
import locale
from ._compatimports import IS_PY3
def listify(val):
"""Ensure that value is either None or a list, converting single values
into 1-element lists"""
if val is None:
return val
if isinstance(val, list):
return val
return [val]
def to_encoding(ustring):
"""
Locale specific printing per python version
"""
ustring = ustring or ''
if IS_PY3:
return str(ustring)
else: # pragma: no cover
strtype = basestring # pylint: disable=undefined-variable
string = ustring
if not isinstance(ustring, strtype):
string = str(ustring)
return string.encode(locale.getpreferredencoding(), 'replace')