Mercurial > libervia-backend
comparison plugins/plugin_xep_0100.py @ 69:86f1f7f6d332
i18n first draft
- gettext support added in SàT
- first draft of french translation
- added README with a HOWTO for translators
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 03 Mar 2010 17:12:23 +1100 |
parents | d35c5edab53f |
children | 94011f553cd0 |
comparison
equal
deleted
inserted
replaced
68:9b842086d915 | 69:86f1f7f6d332 |
---|---|
32 "import_name": "XEP_0100", | 32 "import_name": "XEP_0100", |
33 "type": "XEP", | 33 "type": "XEP", |
34 "protocols": ["XEP-0100"], | 34 "protocols": ["XEP-0100"], |
35 "dependencies": ["XEP_0077"], | 35 "dependencies": ["XEP_0077"], |
36 "main": "XEP_0100", | 36 "main": "XEP_0100", |
37 "description": """Implementation of Gateways protocol""" | 37 "description": _("""Implementation of Gateways protocol""") |
38 } | 38 } |
39 | 39 |
40 class XEP_0100(): | 40 class XEP_0100(): |
41 | 41 |
42 def __init__(self, host): | 42 def __init__(self, host): |
43 info("Gateways plugin initialization") | 43 info(_("Gateways plugin initialization")) |
44 self.host = host | 44 self.host = host |
45 self.__gateways = {} #dict used to construct the answer to findGateways. Key = target jid | 45 self.__gateways = {} #dict used to construct the answer to findGateways. Key = target jid |
46 host.bridge.addMethod("findGateways", ".communication", in_sign='ss', out_sign='s', method=self.findGateways) | 46 host.bridge.addMethod("findGateways", ".communication", in_sign='ss', out_sign='s', method=self.findGateways) |
47 host.bridge.addMethod("gatewayRegister", ".request", in_sign='ssa(ss)', out_sign='s', method=self.gatewayRegister) | 47 host.bridge.addMethod("gatewayRegister", ".request", in_sign='ssa(ss)', out_sign='s', method=self.gatewayRegister) |
48 | 48 |
49 def __inc_handled_items(self, request_id): | 49 def __inc_handled_items(self, request_id): |
50 self.__gateways[request_id]['__handled_items']+=1 | 50 self.__gateways[request_id]['__handled_items']+=1 |
51 | 51 |
52 if self.__gateways[request_id]['__total_items'] == self.__gateways[request_id]['__handled_items']: | 52 if self.__gateways[request_id]['__total_items'] == self.__gateways[request_id]['__handled_items']: |
53 debug ("All items checked for id [%s]" % str(request_id)) | 53 debug (_("All items checked for id [%s]") % str(request_id)) |
54 | 54 |
55 del self.__gateways[request_id]['__total_items'] | 55 del self.__gateways[request_id]['__total_items'] |
56 del self.__gateways[request_id]['__handled_items'] | 56 del self.__gateways[request_id]['__handled_items'] |
57 self.host.actionResultExt(request_id,"DICT_DICT",self.__gateways[request_id]) | 57 self.host.actionResultExt(request_id,"DICT_DICT",self.__gateways[request_id]) |
58 | 58 |
59 def discoInfo(self, disco, entity, request_id): | 59 def discoInfo(self, disco, entity, request_id): |
60 """Find disco infos about entity, to check if it is a gateway""" | 60 """Find disco infos about entity, to check if it is a gateway""" |
61 | 61 |
62 for identity in disco.identities: | 62 for identity in disco.identities: |
63 if identity[0] == 'gateway': | 63 if identity[0] == 'gateway': |
64 print ("Found gateway (%s): %s" % (entity.full(), disco.identities[identity])) | 64 print (_("Found gateway (%(jid)s): %(identity)s") % {'jid':entity.full(), 'identity':disco.identities[identity]}) |
65 self.__gateways[request_id][entity.full()] = { | 65 self.__gateways[request_id][entity.full()] = { |
66 'name':disco.identities[identity], | 66 'name':disco.identities[identity], |
67 'type':identity[1] | 67 'type':identity[1] |
68 } | 68 } |
69 | 69 |
70 self.__inc_handled_items(request_id) | 70 self.__inc_handled_items(request_id) |
71 | 71 |
72 def discoInfoErr(self, failure, entity, request_id): | 72 def discoInfoErr(self, failure, entity, request_id): |
73 """Something is going wrong with disco""" | 73 """Something is going wrong with disco""" |
74 failure.trap(jab_error.StanzaError) | 74 failure.trap(jab_error.StanzaError) |
75 error("Error when discovering [%s]: %s" % (entity.full(), failure.value.condition)) | 75 error(_("Error when discovering [%(jid)s]: %(condition)s") % {'jid':entity.full(), 'condition':failure.value.condition}) |
76 self.__inc_handled_items(request_id) | 76 self.__inc_handled_items(request_id) |
77 | 77 |
78 | 78 |
79 def discoItems(self, disco, request_id, target, client): | 79 def discoItems(self, disco, request_id, target, client): |
80 """Look for items with disco protocol, and ask infos for each one""" | 80 """Look for items with disco protocol, and ask infos for each one""" |
81 #FIXME: target is used as we can't find the original iq node (parent is None) | 81 #FIXME: target is used as we can't find the original iq node (parent is None) |
82 # an other way would avoid this useless parameter (is there a way with wokkel ?) | 82 # an other way would avoid this useless parameter (is there a way with wokkel ?) |
83 if len(disco._items) == 0: | 83 if len(disco._items) == 0: |
84 debug ("No gateway found") | 84 debug (_("No gateway found")) |
85 self.host.actionResultExt(request_id,"DICT_DICT",{}) | 85 self.host.actionResultExt(request_id,"DICT_DICT",{}) |
86 return | 86 return |
87 | 87 |
88 self.__gateways[request_id] = {'__total_items':len(disco._items), '__handled_items':0, '__private__':{'target':target.full()}} | 88 self.__gateways[request_id] = {'__total_items':len(disco._items), '__handled_items':0, '__private__':{'target':target.full()}} |
89 for item in disco._items: | 89 for item in disco._items: |
90 debug ("item found: %s", item.name) | 90 debug (_("item found: %s"), item.name) |
91 client.disco.requestInfo(item.entity).addCallback(self.discoInfo, entity=item.entity, request_id=request_id) | 91 client.disco.requestInfo(item.entity).addCallback(self.discoInfo, entity=item.entity, request_id=request_id) |
92 client.disco.requestInfo(item.entity).addErrback(self.discoInfoErr, entity=item.entity, request_id=request_id) | 92 client.disco.requestInfo(item.entity).addErrback(self.discoInfoErr, entity=item.entity, request_id=request_id) |
93 | 93 |
94 def registrationSuccessful(self, target): | 94 def registrationSuccessful(self, target): |
95 """Called when in_band registration is ok, we must now follow the rest of procedure""" | 95 """Called when in_band registration is ok, we must now follow the rest of procedure""" |
96 print "Registration successful, doing the rest" | 96 debug (_("Registration successful, doing the rest")) |
97 self.host.addContact(target) | 97 self.host.addContact(target) |
98 self.host.setPresence(target) | 98 self.host.setPresence(target) |
99 | 99 |
100 def gatewayRegister(self, action, target, fields): | 100 def gatewayRegister(self, action, target, fields): |
101 """Register gateway using in-band registration, then log-in to gateway""" | 101 """Register gateway using in-band registration, then log-in to gateway""" |
107 """Find gateways in the target JID, using discovery protocol | 107 """Find gateways in the target JID, using discovery protocol |
108 Return an id used for retrieving the list of gateways | 108 Return an id used for retrieving the list of gateways |
109 """ | 109 """ |
110 client = self.host.getClient(profile_key) | 110 client = self.host.getClient(profile_key) |
111 assert(client) | 111 assert(client) |
112 print "target ===>", target | |
113 to_jid = jid.JID(target) | 112 to_jid = jid.JID(target) |
114 debug ("find gateways (target = %s)" % to_jid.full()) | 113 debug (_("find gateways (target = %s)") % to_jid.full()) |
115 request_id = self.host.get_next_id() | 114 request_id = self.host.get_next_id() |
116 client.disco.requestItems(to_jid).addCallback(self.discoItems, request_id=request_id, target = to_jid, client = client) | 115 client.disco.requestItems(to_jid).addCallback(self.discoItems, request_id=request_id, target = to_jid, client = client) |
117 return request_id | 116 return request_id |