Mercurial > libervia-backend
comparison sat_frontends/jp/arg_tools.py @ 3028:ab2696e34d29
Python 3 port:
/!\ this is a huge commit
/!\ starting from this commit, SàT is needs Python 3.6+
/!\ SàT maybe be instable or some feature may not work anymore, this will improve with time
This patch port backend, bridge and frontends to Python 3.
Roughly this has been done this way:
- 2to3 tools has been applied (with python 3.7)
- all references to python2 have been replaced with python3 (notably shebangs)
- fixed files not handled by 2to3 (notably the shell script)
- several manual fixes
- fixed issues reported by Python 3 that where not handled in Python 2
- replaced "async" with "async_" when needed (it's a reserved word from Python 3.7)
- replaced zope's "implements" with @implementer decorator
- temporary hack to handle data pickled in database, as str or bytes may be returned,
to be checked later
- fixed hash comparison for password
- removed some code which is not needed anymore with Python 3
- deactivated some code which needs to be checked (notably certificate validation)
- tested with jp, fixed reported issues until some basic commands worked
- ported Primitivus (after porting dependencies like urwid satext)
- more manual fixes
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 13 Aug 2019 19:08:41 +0200 |
parents | 003b8b4b56a7 |
children | 9d0df638c8b4 |
comparison
equal
deleted
inserted
replaced
3027:ff5bcb12ae60 | 3028:ab2696e34d29 |
---|---|
26 | 26 |
27 @param smart(bool): if True, only escape if needed | 27 @param smart(bool): if True, only escape if needed |
28 """ | 28 """ |
29 if smart and not " " in arg and not '"' in arg: | 29 if smart and not " " in arg and not '"' in arg: |
30 return arg | 30 return arg |
31 return u'"' + arg.replace(u'"', u'\\"') + u'"' | 31 return '"' + arg.replace('"', '\\"') + '"' |
32 | 32 |
33 | 33 |
34 def get_cmd_choices(cmd=None, parser=None): | 34 def get_cmd_choices(cmd=None, parser=None): |
35 try: | 35 try: |
36 choices = parser._subparsers._group_actions[0].choices | 36 choices = parser._subparsers._group_actions[0].choices |
74 post_args = args[len(parser_args) :] | 74 post_args = args[len(parser_args) :] |
75 | 75 |
76 opt_args = [] | 76 opt_args = [] |
77 pos_args = [] | 77 pos_args = [] |
78 actions = {a.dest: a for a in parser._actions} | 78 actions = {a.dest: a for a in parser._actions} |
79 for arg, value in use.iteritems(): | 79 for arg, value in use.items(): |
80 try: | 80 try: |
81 if arg == u"item" and not u"item" in actions: | 81 if arg == "item" and not "item" in actions: |
82 # small hack when --item is appended to a --items list | 82 # small hack when --item is appended to a --items list |
83 arg = u"items" | 83 arg = "items" |
84 action = actions[arg] | 84 action = actions[arg] |
85 except KeyError: | 85 except KeyError: |
86 if verbose: | 86 if verbose: |
87 host.disp( | 87 host.disp( |
88 _( | 88 _( |
89 u"ignoring {name}={value}, not corresponding to any argument (in USE)" | 89 "ignoring {name}={value}, not corresponding to any argument (in USE)" |
90 ).format(name=arg, value=escape(value)) | 90 ).format(name=arg, value=escape(value)) |
91 ) | 91 ) |
92 else: | 92 else: |
93 if verbose: | 93 if verbose: |
94 host.disp( | 94 host.disp( |
95 _(u"arg {name}={value} (in USE)").format( | 95 _("arg {name}={value} (in USE)").format( |
96 name=arg, value=escape(value) | 96 name=arg, value=escape(value) |
97 ) | 97 ) |
98 ) | 98 ) |
99 if not action.option_strings: | 99 if not action.option_strings: |
100 pos_args.append(value) | 100 pos_args.append(value) |