comparison sat_frontends/jp/cmd_message.py @ 2624:56f94936df1e

code style reformatting using black
author Goffi <goffi@goffi.org>
date Wed, 27 Jun 2018 20:14:46 +0200
parents 26edcf3a30eb
children 32b5f68a23b4
comparison
equal deleted inserted replaced
2623:49533de4540b 2624:56f94936df1e
25 25
26 __commands__ = ["Message"] 26 __commands__ = ["Message"]
27 27
28 28
29 class Send(base.CommandBase): 29 class Send(base.CommandBase):
30
31 def __init__(self, host): 30 def __init__(self, host):
32 super(Send, self).__init__(host, 'send', help=_('send a message to a contact')) 31 super(Send, self).__init__(host, "send", help=_("send a message to a contact"))
33 32
34 def add_parser_options(self): 33 def add_parser_options(self):
35 self.parser.add_argument("-l", "--lang", type=str, default='', help=_(u"language of the message")) 34 self.parser.add_argument(
36 self.parser.add_argument("-s", "--separate", action="store_true", help=_(u"separate xmpp messages: send one message per line instead of one message alone.")) 35 "-l", "--lang", type=str, default="", help=_(u"language of the message")
37 self.parser.add_argument("-n", "--new-line", action="store_true", help=_(u"add a new line at the beginning of the input (usefull for ascii art ;))")) 36 )
38 self.parser.add_argument("-S", "--subject", type=base.unicode_decoder, help=_(u"subject of the message")) 37 self.parser.add_argument(
39 self.parser.add_argument("-L", "--subject_lang", type=str, default='', help=_(u"language of subject")) 38 "-s",
40 self.parser.add_argument("-t", "--type", choices=C.MESS_TYPE_STANDARD + (C.MESS_TYPE_AUTO,), default=C.MESS_TYPE_AUTO, help=_("type of the message")) 39 "--separate",
40 action="store_true",
41 help=_(
42 u"separate xmpp messages: send one message per line instead of one message alone."
43 ),
44 )
45 self.parser.add_argument(
46 "-n",
47 "--new-line",
48 action="store_true",
49 help=_(
50 u"add a new line at the beginning of the input (usefull for ascii art ;))"
51 ),
52 )
53 self.parser.add_argument(
54 "-S",
55 "--subject",
56 type=base.unicode_decoder,
57 help=_(u"subject of the message"),
58 )
59 self.parser.add_argument(
60 "-L", "--subject_lang", type=str, default="", help=_(u"language of subject")
61 )
62 self.parser.add_argument(
63 "-t",
64 "--type",
65 choices=C.MESS_TYPE_STANDARD + (C.MESS_TYPE_AUTO,),
66 default=C.MESS_TYPE_AUTO,
67 help=_("type of the message"),
68 )
41 syntax = self.parser.add_mutually_exclusive_group() 69 syntax = self.parser.add_mutually_exclusive_group()
42 syntax.add_argument("-x", "--xhtml", action="store_true", help=_(u"XHTML body")) 70 syntax.add_argument("-x", "--xhtml", action="store_true", help=_(u"XHTML body"))
43 syntax.add_argument("-r", "--rich", action="store_true", help=_(u"rich body")) 71 syntax.add_argument("-r", "--rich", action="store_true", help=_(u"rich body"))
44 self.parser.add_argument("jid", type=base.unicode_decoder, help=_(u"the destination jid")) 72 self.parser.add_argument(
73 "jid", type=base.unicode_decoder, help=_(u"the destination jid")
74 )
45 75
46 def start(self): 76 def start(self):
47 if self.args.xhtml and self.args.separate: 77 if self.args.xhtml and self.args.separate:
48 self.disp(u"argument -s/--separate is not compatible yet with argument -x/--xhtml", error=True) 78 self.disp(
79 u"argument -s/--separate is not compatible yet with argument -x/--xhtml",
80 error=True,
81 )
49 self.host.quit(2) 82 self.host.quit(2)
50 83
51 jids = self.host.check_jids([self.args.jid]) 84 jids = self.host.check_jids([self.args.jid])
52 jid = jids[0] 85 jid = jids[0]
53 self.sendStdin(jid) 86 self.sendStdin(jid)
56 """Send incomming data on stdin to jabber contact 89 """Send incomming data on stdin to jabber contact
57 90
58 @param dest_jid: destination jid 91 @param dest_jid: destination jid
59 """ 92 """
60 header = "\n" if self.args.new_line else "" 93 header = "\n" if self.args.new_line else ""
61 stdin_lines = [stream.decode('utf-8','ignore') for stream in sys.stdin.readlines()] 94 stdin_lines = [
95 stream.decode("utf-8", "ignore") for stream in sys.stdin.readlines()
96 ]
62 extra = {} 97 extra = {}
63 if self.args.subject is None: 98 if self.args.subject is None:
64 subject = {} 99 subject = {}
65 else: 100 else:
66 subject = {self.args.subject_lang: self.args.subject} 101 subject = {self.args.subject_lang: self.args.subject}
70 if self.args.lang: 105 if self.args.lang:
71 key = u"{}_{}".format(key, self.args.lang) 106 key = u"{}_{}".format(key, self.args.lang)
72 extra[key] = clean_ustr(u"".join(stdin_lines)) 107 extra[key] = clean_ustr(u"".join(stdin_lines))
73 stdin_lines = [] 108 stdin_lines = []
74 109
75 if self.args.separate: #we send stdin in several messages 110 if self.args.separate: # we send stdin in several messages
76 if header: 111 if header:
77 self.host.bridge.messageSend(dest_jid, {self.args.lang: header}, subject, self.args.type, profile_key=self.profile, callback=lambda: None, errback=lambda ignore: ignore) 112 self.host.bridge.messageSend(
113 dest_jid,
114 {self.args.lang: header},
115 subject,
116 self.args.type,
117 profile_key=self.profile,
118 callback=lambda: None,
119 errback=lambda ignore: ignore,
120 )
78 121
79 for line in stdin_lines: 122 for line in stdin_lines:
80 self.host.bridge.messageSend(dest_jid, {self.args.lang: line.replace("\n","")}, subject, self.args.type, extra, profile_key=self.host.profile, callback=lambda: None, errback=lambda ignore: ignore) 123 self.host.bridge.messageSend(
124 dest_jid,
125 {self.args.lang: line.replace("\n", "")},
126 subject,
127 self.args.type,
128 extra,
129 profile_key=self.host.profile,
130 callback=lambda: None,
131 errback=lambda ignore: ignore,
132 )
81 133
82 else: 134 else:
83 msg = {self.args.lang: header + clean_ustr(u"".join(stdin_lines))} if not (self.args.xhtml or self.args.rich) else {} 135 msg = (
84 self.host.bridge.messageSend(dest_jid, msg, subject, self.args.type, extra, profile_key=self.host.profile, callback=lambda: None, errback=lambda ignore: ignore) 136 {self.args.lang: header + clean_ustr(u"".join(stdin_lines))}
137 if not (self.args.xhtml or self.args.rich)
138 else {}
139 )
140 self.host.bridge.messageSend(
141 dest_jid,
142 msg,
143 subject,
144 self.args.type,
145 extra,
146 profile_key=self.host.profile,
147 callback=lambda: None,
148 errback=lambda ignore: ignore,
149 )
85 150
86 151
87 class Message(base.CommandBase): 152 class Message(base.CommandBase):
88 subcommands = (Send, ) 153 subcommands = (Send,)
89 154
90 def __init__(self, host): 155 def __init__(self, host):
91 super(Message, self).__init__(host, 'message', use_profile=False, help=_('messages handling')) 156 super(Message, self).__init__(
157 host, "message", use_profile=False, help=_("messages handling")
158 )