Mercurial > libervia-backend
comparison frontends/src/jp/common.py @ 2279:e2f96cd1887b
jp (cmd_pubsub): xmpp: uri handling, first draft
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 28 Jun 2017 19:19:08 +0200 |
parents | 5cd45a79775b |
children | 4bc9a2c2d6c9 |
comparison
equal
deleted
inserted
replaced
2278:489efbda377c | 2279:e2f96cd1887b |
---|---|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | 19 |
20 from sat_frontends.jp.constants import Const as C | 20 from sat_frontends.jp.constants import Const as C |
21 from sat.core.i18n import _ | 21 from sat.core.i18n import _ |
22 from sat.tools.common import regex | 22 from sat.tools.common import regex |
23 from sat.tools.common import uri | |
23 from sat.tools import config | 24 from sat.tools import config |
24 from ConfigParser import NoSectionError, NoOptionError | 25 from ConfigParser import NoSectionError, NoOptionError |
25 import json | 26 import json |
26 import os | 27 import os |
27 import os.path | 28 import os.path |
77 # we split arguments first to avoid escaping issues in file names | 78 # we split arguments first to avoid escaping issues in file names |
78 return [a.format(**format_kw) for a in shlex.split(cmd_line)] | 79 return [a.format(**format_kw) for a in shlex.split(cmd_line)] |
79 except ValueError as e: | 80 except ValueError as e: |
80 host.disp(u"Couldn't parse editor cmd [{cmd}]: {reason}".format(cmd=cmd_line, reason=e)) | 81 host.disp(u"Couldn't parse editor cmd [{cmd}]: {reason}".format(cmd=cmd_line, reason=e)) |
81 return [] | 82 return [] |
83 | |
84 | |
85 def checkURI(args): | |
86 """check if args.node is an URI | |
87 | |
88 if a valid xmpp: URI is found, args.service, args.node and args.item will be set | |
89 """ | |
90 # FIXME: Q&D way to handle xmpp: uris, a generic way is needed | |
91 # and it should be merged with code in BaseEdit | |
92 if not args.service and args.node.startswith('xmpp:'): | |
93 try: | |
94 uri_data = uri.parseXMPPUri(args.node) | |
95 except ValueError: | |
96 pass | |
97 else: | |
98 if uri_data[u'type'] == 'pubsub': | |
99 args.service = uri_data[u'path'] | |
100 args.node = uri_data[u'node'] | |
101 if u'item' in uri_data: | |
102 try: | |
103 item = getattr(uri_data, 'item') | |
104 except AttributeError: | |
105 pass | |
106 else: | |
107 if item is None: | |
108 args.item = uri_data | |
82 | 109 |
83 | 110 |
84 class BaseEdit(object): | 111 class BaseEdit(object): |
85 u"""base class for editing commands | 112 u"""base class for editing commands |
86 | 113 |