diff options
author | Matěj Cepl <mcepl@cepl.eu> | 2024-01-18 19:09:58 +0100 |
---|---|---|
committer | Matěj Cepl <mcepl@cepl.eu> | 2024-01-18 19:09:58 +0100 |
commit | cc7362d28bd9c43cb6839809f86e59874f2fe458 (patch) | |
tree | 1053748f5890c769d1e99806bc0c8bcffca6f0fe /libbe/ui | |
parent | 003bd13629d9db2f14156f97b74a4672e9ecdf77 (diff) | |
download | bugseverywhere-cc7362d28bd9c43cb6839809f86e59874f2fe458.tar.gz |
2to3 conversion of the repo.
Diffstat (limited to 'libbe/ui')
-rw-r--r-- | libbe/ui/command_line.py | 74 | ||||
-rw-r--r-- | libbe/ui/util/editor.py | 4 | ||||
-rw-r--r-- | libbe/ui/util/user.py | 4 |
3 files changed, 41 insertions, 41 deletions
diff --git a/libbe/ui/command_line.py b/libbe/ui/command_line.py index 5d4d80a..be6f80a 100644 --- a/libbe/ui/command_line.py +++ b/libbe/ui/command_line.py @@ -89,10 +89,10 @@ class CmdOptionParser(optparse.OptionParser): options,parsed_args = optparse.OptionParser.parse_args( self, args=args, values=values) options = options.__dict__ - for name,value in options.items(): + for name,value in list(options.items()): if '_' in name: # reconstruct original option name options[name.replace('_', '-')] = options.pop(name) - for name,value in options.items(): + for name,value in list(options.items()): argument = None option = self._option_by_name[name] if option.arg != None: @@ -157,8 +157,8 @@ class CmdOptionParser(optparse.OptionParser): fragment = parser.rargs[0] self.complete(argument, fragment) else: - print >> self.command.stdout, command_option.callback( - self.command, command_option, value) + print(command_option.callback( + self.command, command_option, value), file=self.command.stdout) raise CallbackExit def complete(self, argument=None, fragment=None): @@ -166,7 +166,7 @@ class CmdOptionParser(optparse.OptionParser): if fragment != None: comps = [c for c in comps if c.startswith(fragment)] if len(comps) > 0: - print >> self.command.stdout, '\n'.join(comps) + print('\n'.join(comps), file=self.command.stdout) raise CallbackExit def process_raw_argument(self, argument, value): @@ -175,7 +175,7 @@ class CmdOptionParser(optparse.OptionParser): if argument.type == 'string': if not hasattr(self, 'argv_encoding'): self.argv_encoding = libbe.util.encoding.get_argv_encoding() - return unicode(value, self.argv_encoding) + return str(value, self.argv_encoding) return value @@ -305,36 +305,36 @@ def dispatch(ui, command, args): ret = ui.run(command, options, args) except CallbackExit: return 0 - except UnicodeDecodeError, e: - print >> ui.io.stdout, '\n'.join([ + except UnicodeDecodeError as e: + print('\n'.join([ 'ERROR:', str(e), 'You should set a locale that supports unicode, e.g.', ' export LANG=en_US.utf8', 'See http://docs.python.org/library/locale.html for details', - ]) + ]), file=ui.io.stdout) return 1 - except libbe.command.UsageError, e: - print >> ui.io.stdout, 'Usage Error:\n', e + except libbe.command.UsageError as e: + print('Usage Error:\n', e, file=ui.io.stdout) if e.command: - print >> ui.io.stdout, e.command.usage() - print >> ui.io.stdout, 'For usage information, try' - print >> ui.io.stdout, ' be help %s' % e.command_name + print(e.command.usage(), file=ui.io.stdout) + print('For usage information, try', file=ui.io.stdout) + print(' be help %s' % e.command_name, file=ui.io.stdout) return 1 - except libbe.command.UserError, e: - print >> ui.io.stdout, 'ERROR:\n', e + except libbe.command.UserError as e: + print('ERROR:\n', e, file=ui.io.stdout) return 1 - except OSError, e: - print >> ui.io.stdout, 'OSError:\n', e + except OSError as e: + print('OSError:\n', e, file=ui.io.stdout) return 1 - except libbe.storage.ConnectionError, e: - print >> ui.io.stdout, 'Connection Error:\n', e + except libbe.storage.ConnectionError as e: + print('Connection Error:\n', e, file=ui.io.stdout) return 1 - except libbe.util.http.HTTPError, e: - print >> ui.io.stdout, 'HTTP Error:\n', e + except libbe.util.http.HTTPError as e: + print('HTTP Error:\n', e, file=ui.io.stdout) return 1 except (libbe.util.id.MultipleIDMatches, libbe.util.id.NoIDMatches, - libbe.util.id.InvalidIDStructure), e: - print >> ui.io.stdout, 'Invalid id:\n', e + libbe.util.id.InvalidIDStructure) as e: + print('Invalid id:\n', e, file=ui.io.stdout) return 1 finally: command.cleanup() @@ -352,26 +352,26 @@ def main(): options,args = parser.parse_args() except CallbackExit: return 0 - except libbe.command.UsageError, e: + except libbe.command.UsageError as e: if isinstance(e.command, BE): # no command given, print usage string - print >> ui.io.stdout, 'Usage Error:\n', e - print >> ui.io.stdout, be.usage() - print >> ui.io.stdout, 'For example, try' - print >> ui.io.stdout, ' be help' + print('Usage Error:\n', e, file=ui.io.stdout) + print(be.usage(), file=ui.io.stdout) + print('For example, try', file=ui.io.stdout) + print(' be help', file=ui.io.stdout) else: - print >> ui.io.stdout, 'Usage Error:\n', e + print('Usage Error:\n', e, file=ui.io.stdout) if e.command: - print >> ui.io.stdout, e.command.usage() - print >> ui.io.stdout, 'For usage information, try' - print >> ui.io.stdout, ' be help %s' % e.command_name + print(e.command.usage(), file=ui.io.stdout) + print('For usage information, try', file=ui.io.stdout) + print(' be help %s' % e.command_name, file=ui.io.stdout) return 1 command_name = args.pop(0) try: Class = libbe.command.get_command_class(command_name=command_name) - except libbe.command.UnknownCommand, e: - print >> ui.io.stdout, e + except libbe.command.UnknownCommand as e: + print(e, file=ui.io.stdout) return 1 ui.storage_callbacks = libbe.command.StorageCallbacks(options['repo']) @@ -392,8 +392,8 @@ def main(): ret = dispatch(ui, command, args) try: ui.cleanup() - except IOError, e: - print >> ui.io.stdout, 'IOError:\n', e + except IOError as e: + print('IOError:\n', e, file=ui.io.stdout) return 1 return ret diff --git a/libbe/ui/util/editor.py b/libbe/ui/util/editor.py index f852c01..8412ff6 100644 --- a/libbe/ui/util/editor.py +++ b/libbe/ui/util/editor.py @@ -36,7 +36,7 @@ if libbe.TESTING == True: import doctest -comment_marker = u"== Anything below this line will be ignored\n" +comment_marker = "== Anything below this line will be ignored\n" class CantFindEditor(Exception): def __init__(self): @@ -76,7 +76,7 @@ def editor_string(comment=None, encoding=None): fhandle, fname = tempfile.mkstemp() try: if comment is not None: - cstring = u'\n'+comment_string(comment) + cstring = '\n'+comment_string(comment) os.write(fhandle, cstring.encode(encoding)) os.close(fhandle) oldmtime = os.path.getmtime(fname) diff --git a/libbe/ui/util/user.py b/libbe/ui/util/user.py index 5306593..4a4e7f1 100644 --- a/libbe/ui/util/user.py +++ b/libbe/ui/util/user.py @@ -46,7 +46,7 @@ def get_fallback_username(): """ name = None for env in ['LOGNAME', 'USERNAME']: - if os.environ.has_key(env): + if env in os.environ: name = os.environ[env] break if name is None and pwd: @@ -60,7 +60,7 @@ def get_fallback_fullname(): """ name = None for env in ['FULLNAME']: - if os.environ.has_key(env): + if env in os.environ: name = os.environ[env] break if pwd and not name: |