Gajim - 2016-07-22

  1. Marzanna If I use Node class from nbxmpp, how can I filter certain tags within xhtml?
  2. lovetox getTag
  3. lovetox getTag('body')
  4. lovetox for example
  5. lovetox FYI, xhtml is disabled if you use current pgp implementation or omemo in gajim
  6. Marzanna lovetox, what if I want to get attrs of img tag?
  7. lovetox maybe getAttr("id")
  8. lovetox for example
  9. Dekádě Hop, #eroina
  10. Dekádě Hop, hop, eroina
  11. Marzanna Ok. I want to print it to terminal output (for debugging purposes). What should I use for that?
  12. Dekádě Hop, eroina mea
  13. Marzanna I'm using log = logging.getLogger('gajim.plugin_system.myplugin') Is this correct way display log messages?
  14. lovetox yes
  15. lovetox then you can use
  16. lovetox
  17. lovetox log.debug
  18. lovetox log.error
  19. lovetox that are different log levels
  20. lovetox you have to start gajim then with
  21. lovetox -l gajim.plugin_system.yourplugin=LOGLEVEL
  22. lovetox use DEBUG to catch everything
  23. Marzanna What is default level?
  24. lovetox there is no default
  25. lovetox you set it with every debug message
  26. lovetox if you use log.debug("bla")
  27. lovetox then level of that message is DEBUG
  28. lovetox
  29. lovetox for indepth informations
  30. Marzanna thanks. Now logging works.
  31. lovetox what editor do you use?
  32. Marzanna Text editor?
  33. lovetox to write python code
  34. Marzanna vim
  35. lovetox k :)
  36. Marzanna event.stanza.getTag("body", namespace=nbxmpp.NS_XHTML) return None for messages containing xhtml. What am I doing wring?
  37. Marzanna event.stanza.getTag("body", namespace=nbxmpp.NS_XHTML) return None for messages containing xhtml. What am I doing wrong?
  38. Marzanna event.stanza.getTag("body", namespace=nbxmpp.NS_XHTML) returns None for messages containing xhtml. What am I doing wrong?
  39. Link Mauve Marzanna, because {xhtml}body isn’t a direct payload of message.
  40. Link Mauve See for example.
  41. lovetox you cant just get any tag with getTag
  42. lovetox you can only get childs of the one you are using this method on
  43. Link Mauve {jabber:client}body is the non-formatted payload, {}html/{}body is the formatted one.
  44. lovetox so try event.stanza.getTag("html", namespace=nbxmpp.NS_XHTML)
  45. Link Mauve lovetox, not the same namespace, probably NS_XHTML_IM or something.
  46. lovetox can i just not use a namespace also?
  47. lovetox should work?
  48. lovetox only for testing purpose, of course checking the namespace is recommended
  49. Link Mauve lovetox, no, you should never do that.
  50. Link Mauve I’m not sure it works, and for an XMPP library it should really be forbidden.
  51. Marzanna Is it possible to reload plugin without restarting Gajim?
  52. bot RSS: Feeds for Gajim • Ticket #8371 (Can't write on IRC channel) created Bug description I can not write in channels on but I see the messages. Other Servers work. This server does not show the participants of a channel, maybe that has something to do with it? Steps to reproduce Connect via transpor[…] • gajim-log-twitc[…]
  53. lovetox try to deactivate it via plugin manager
  54. lovetox and activate it again
  55. lovetox but i dont think this will work when you changed code
  56. lovetox restarting gajim is a task i do a hundred times daily :9
  57. Marzanna lovetox, yep, it doesn't work
  58. Marzanna event.stanza.getTag("html", namespace=nbxmpp.NS_XHTML_IM) works but I still have no clue how to filter tags inside xhtml
  59. lovetox i think getTag returns again a node object
  60. lovetox then you can use getTag on that one
  61. Link Mauve Marzanna, what do you mean by filter?
  62. Marzanna Link Mauve, I need to get attribute of img tag inside xhtml
  63. lovetox tag = event.stanza.getTag("html", namespace=nbxmpp.NS_XHTML_IM)
  64. lovetox tag.gettag("img")
  65. Link Mauve Marzanna, you probably need to do recursive parsing, I don’t know anything of nbxmpp’s XML handling but it probably has either an XPath walking method, or children access.
  66. lovetox example:
  67. lovetox for child in xtag.getTags('item'): for cchild in child.getTags(tag): return cchild.getData(), cchild.getAttr(attr)
  68. lovetox just read
  69. lovetox
  70. lovetox there are loads of examples how to get attributes and tags
  71. Link Mauve Ow, that’s very bad, *all* of them should use the namespace attribute. /o\
  72. lovetox it does in the line before
  73. lovetox i didnt quote
  74. lovetox if xtag.getNamespace() not in (NS_MUC_USER, NS_MUC_ADMIN): continue
  75. lovetox =)
  76. lovetox thats just random copied out from somewhere
  77. lovetox you dont have to use on all tags a namespace ..
  78. Link Mauve Not all of them do.
  79. Link Mauve lovetox, you have to.
  80. Link Mauve <a xmlns='something'><b/></a> is equal to <a xmlns='something'><b xmlns='something'/></a>.
  81. Link Mauve You don’t want to allow <a xmlns='something'><b xmlns='evil'/></a> instead.
  82. lovetox ok you mean it should be that way, if i open a random xep like 0313 i see lots of tags without namespace
  83. Link Mauve Every tag has a namespace, it just inherits the closest one.
  84. Link Mauve Every tag has a namespace, it just inherits the one from its parent.
  85. Link Mauve And the root specifies jabber:client as the root namespace.
  86. Link Mauve So message, iq and presence, as well as message/body and a few other elements are in that jabber:client namespace.
  87. lovetox ah ok
  88. lovetox so if i test for the parent namespace be ok
  89. lovetox no mom
  90. lovetox <a xmlns='something'> <b/> </a>
  91. lovetox you would test a for a namespace
  92. lovetox then thest b for a namespace
  93. Link Mauve Yes, both are in the something namespace.
  94. lovetox ah so the lib should give me for b the parent namespace
  95. Link Mauve If you don’t test for any namespace, it means they can be in any, including an evil one.
  96. lovetox because the tag doesnt have one
  97. Link Mauve It does have one, the one from the closest parent.
  98. lovetox yeah but not actually written out
  99. lovetox thats what i mean
  100. Link Mauve The xmlns “attribute” isn’t an attribute, it only declares a namespace for everything under it, until it gets overriden by another xmlns.
  101. lovetox yeah ok i understand, so if i get those example stanza, and i have a xmpp lib, and querry the tag <b/> namespace
  102. lovetox the lib should return "something"
  103. Marzanna Finally. Got that attribute. But my code is the ugliest :C
  104. Marzanna Thank you, guys
  105. Link Mauve lovetox, exactly.
  106. Marzanna Is it possible to invoke function from common/
  107. lovetox what do you want?
  108. Marzanna There is a function "get_bob_data()". I want to call this function witch cid parameter I got from img tag.
  109. lovetox yeah
  110. lovetox just use the connection object
  111. lovetox i search for some example
  112. lovetox try with gajim.connections[account]
  113. lovetox gajim.connections[account].get_bob_data()
  114. lovetox if this is a response to incoming event
  115. lovetox you could get the account from the event object
  116. Marzanna What is the class of event object?
  117. lovetox depends on the event you catch
  118. lovetox
  119. lovetox if its the DecryptedMessageReceivedEvent
  120. lovetox you are catching
  121. lovetox then for example event.conn.get_bob_data()
  122. Marzanna lovetox, thanks.
  123. lovetox generelly you can almost access any objects in gajim
  124. lovetox and theire functions
  125. Marzanna Hmm… File "/usr/share/gajim/src/common/", line 1882, in _on_bob_received data = msg.getTags('data', namespace=nbxmpp.NS_BOB) NameError: global name 'msg' is not defined
  126. Link Mauve That’s one of the issues Cython caught the other day, I gave a list of errors to Asterix but I don’t think he pushed his fixes.
  127. Marzanna I've modified _on_bob_received() to make it work, but it does not affect original message.
  128. Marzanna I've successfully altered original message in my plugin code. But _on_bob_received() leaves it intact.
  129. Marzanna It seems that if I try to modify original message in a callback function it won't have any effect.
  130. Marzanna I call gajim.connections[].connection.SendAndCallForResponse(iq, self.on_bob_received, {'cid': cid, 'cid_node':event.stanza}) from message-received handler function. In callback function on_bob_received() I alter data in original stanza. What am I doing wrong?
  131. lovetox ok so you get a message
  132. lovetox you have to tell me what this thing should actually do, that i can understand it
  133. lovetox you get a xhtml message
  134. lovetox and then you send an iq out
  135. lovetox and wait for a response
  136. lovetox but how does that response look like?
  137. lovetox is it a message? with a body?
  138. lovetox or what
  139. Marzanna I get a response. It looks like
  140. Marzanna Everything is fine until I try to make changes to original message in a callback function.
  141. lovetox ok so you request data and data is returned in the form of an iq
  142. lovetox what do you want to modify
  143. lovetox the data that gets returned?
  144. lovetox or the request?
  145. Marzanna I get message with a reference (, then I request data and then data is returned I want to modify original message to substitute cid with data.
  146. lovetox you want to modify the original incoming message that triggers the request?
  147. Marzanna Yes.
  148. lovetox but the code that you posted has nothing to do with modifying the original message, so i cant see whats wrong with it
  149. lovetox paste your plugin in pastebin
  150. lovetox and send me the link
  151. lovetox i think i know whats wrong
  152. lovetox you have to alter the event.stanza data before you SendAndCallForResponse
  153. lovetox the call back "on_bob_received"
  154. lovetox is for handling the returned data
  155. Marzanna lovetox,
  156. lovetox yeah its like i thought
  157. lovetox you dont understand what SendAndCallForResponse does
  158. lovetox it sends out the request and defines a function that handles what comes back
  159. lovetox but if i understand you correct you dont want to modify the returned data
  160. lovetox you want to modify the original incoming message that sets all into motion
  161. Marzanna exactly
  162. Marzanna Is it possible?
  163. lovetox yes
  164. lovetox you have to modify event.stanza
  165. lovetox before
  166. lovetox iq = nbxmpp.Iq(to=from_, typ='get')
  167. lovetox you create the iq request
  168. Marzanna But how is it supposed to work? In this case I don't have the data from response.
  169. lovetox ah now i get it
  170. lovetox you want to modify the original message with data that come with a later response
  171. lovetox on first thought thats not possible
  172. lovetox or wait
  173. lovetox its rather complicated
  174. lovetox but do you really have to modify the older message
  175. lovetox what does that data that you want into the message?
  176. lovetox does it show something in caht
  177. lovetox or what?
  178. Marzanna I just want to form xhtml_im message with a picture (base64 encoded)
  179. Marzanna Using XEP-0231: Bits of Binary
  180. Link Mauve Marzanna, are you sure you want that?
  181. Link Mauve It would be simpler to modify the displayed message to replace the image with yours.
  182. Link Mauve That way you don’t go through XMPP anymore.
  183. Link Mauve And you can do the late retrieval part of the spec.
  184. lovetox i dont see how he can do that
  185. lovetox at the time of the response, the original message is already printed
  186. Marzanna >It would be simpler to modify the displayed message to replace the image with yours. But it is what I'm trying. I have the displayed message with cid. Then I get data and I want to substitute cid with data I got to display the message with an image.
  187. lovetox at the time of the response there is no message anymore that you could modify
  188. lovetox its already decoded and printed and archived
  189. lovetox you cant touch it anymore
  190. Marzanna Well. Is it possible to form a new message instead of received?
  191. Link Mauve “22:08:30 lovetox> at the time of the response, the original message is already printed”, exactly like Last Message Correction, or even Message Receipts.
  192. Link Mauve Marzanna, ^
  193. Link Mauve Look at how these two specs are implemented, and do the same.
  194. lovetox yeah i never looked how last message correction does this
  195. Marzanna What if I don't want to print it? Is it possible?
  196. lovetox yes that would be my idea
  197. lovetox you could drop the message
  198. lovetox before it reaches gajim
  199. lovetox save it, modify it, and trigger a message incoming event
  200. lovetox but that could get messy somewhere
  201. lovetox maybe its easier to look how last message correction works
  202. lovetox would be cleaner
  203. Marzanna Thanks. Now I need to figure out how to do it :)
  204. lovetox btw Link Mauve
  205. lovetox how to correct a message in gajim?
  206. Link Mauve lovetox, Ctrl-Up IIRC.
  207. lovetox test
  208. lovetox test2
  209. lovetox nice
  210. lovetox Marzanna
  211. lovetox
  212. lovetox correct_last_received_message
  213. lovetox but to write this as first steps with python is more on the harder side :D
  214. Marzanna lovetox, thanks again. But how can I call this function?
  215. Marzanna it seems I found it
  216. Marzanna After hours of struggling I got it working! But the image appears in another chat tab. lol
  217. lovetox probably cause you just take any textview
  218. lovetox you have to get the textview of the user the message was sent to