import checkpatch
import settings
+import tools
# True to use --no-decorate - we check this in Setup()
use_no_decorate = True
raw += LookupEmail(item, alias, raise_on_error=raise_on_error)
result = []
for item in raw:
+ item = tools.FromUnicode(item)
if not item in result:
- if type(item) == unicode:
- item = item.encode('utf-8')
result.append(item)
if tag:
return ['%s %s%s%s' % (tag, quote, email, quote) for email in result]
import gitutil
import settings
import terminal
+import tools
# Series-xxx tags that we understand
valid_series = ['to', 'cc', 'version', 'changes', 'prefix', 'notes', 'name',
cover_cc = gitutil.BuildEmailList(self.get('cover_cc', ''))
cover_cc = [m.encode('utf-8') if type(m) != str else m
for m in cover_cc]
- cc_list = ', '.join([x.decode('utf-8')
+ cc_list = ', '.join([tools.ToUnicode(x)
for x in set(cover_cc + all_ccs)])
print(cover_fname, cc_list.encode('utf-8'), file=fd)
import command
import gitutil
+import tools
"""Default settings per-project.
for setting_name, setting_value in project_defaults.items():
self.set(project_settings, setting_name, setting_value)
- def _to_unicode(self, val):
- """Make sure a value is of type 'unicode'
-
- Args:
- val: string or unicode object
-
- Returns:
- unicode version of val
- """
- return val if isinstance(val, unicode) else val.decode('utf-8')
-
def get(self, section, option, *args, **kwargs):
"""Extend SafeConfigParser to try project_section before section.
val = ConfigParser.SafeConfigParser.get(
self, section, option, *args, **kwargs
)
- return self._to_unicode(val)
+ return tools.ToUnicode(val)
def items(self, section, *args, **kwargs):
"""Extend SafeConfigParser to add project_section to section.
item_dict = dict(top_items)
item_dict.update(project_items)
- return {(self._to_unicode(item), self._to_unicode(val))
+ return {(tools.ToUnicode(item), tools.ToUnicode(val))
for item, val in item_dict.items()}
def ReadGitAliases(fname):
else:
data = chr(byte) * size
return data
+
+def ToUnicode(val):
+ """Make sure a value is a unicode string
+
+ This allows some amount of compatibility between Python 2 and Python3. For
+ the former, it returns a unicode object.
+
+ Args:
+ val: string or unicode object
+
+ Returns:
+ unicode version of val
+ """
+ if sys.version_info[0] >= 3:
+ return val
+ return val if isinstance(val, unicode) else val.decode('utf-8')
+
+def FromUnicode(val):
+ """Make sure a value is a non-unicode string
+
+ This allows some amount of compatibility between Python 2 and Python3. For
+ the former, it converts a unicode object to a string.
+
+ Args:
+ val: string or unicode object
+
+ Returns:
+ non-unicode version of val
+ """
+ if sys.version_info[0] >= 3:
+ return val
+ return val if isinstance(val, str) else val.encode('utf-8')