rem stringlengths 0 322k | add stringlengths 0 2.05M | context stringlengths 8 228k |
|---|---|---|
return reta | return ret | def features(self): l=self.xpath_ctxt.xpathEval("d:feature") ret=[] for f in l: if f.hasProp("var"): ret.append(unicode(f.prop("var"),"utf-8")) return reta |
ret.append(DiscoIdentity(i)) | ret.append(DiscoIdentity(self,i)) | def identities(self): ret=[] l=self.xpath_ctxt.xpathEval("d:identity") if l is not None: for i in l: ret.append(DiscoIdentity(i)) return ret |
self.value=unicode(value.getContent(),"utf-8","replace").strip() | value=value.getContent() if value: self.value=unicode(value,"utf-8","replace").strip() else: self.value=u"" | def __init__(self,name,value,rfc2425parameters={}): self.name=name if isinstance(value,libxml2.xmlNode): self.value=unicode(value.getContent(),"utf-8","replace").strip() else: self.value=value if not self.value: raise Empty,"Empty string value" |
n=n.next | empty=0 n=n.next if empty: raise Empty,"Empty N value" | def __init__(self,name,value,rfc2425parameters={}): self.name=name if self.name.upper()!="N": raise RuntimeError,"VCardName handles only 'N' type" if isinstance(value,libxml2.xmlNode): self.family,self.given,self.middle,self.prefix,self.suffix=[u""]*5 n=value.children vns=get_node_ns(value) while n: if n.type!='element... |
number=None | self.number=None | def __init__(self,name,value,rfc2425parameters={}): self.name=name if self.name.upper()!="TEL": raise RuntimeError,"VCardTel handles only 'TEL' type" if isinstance(value,libxml2.xmlNode): number=None self.type=[] n=value.children vns=get_node_ns(value) while n: if n.type!='element': n=n.next continue ns=get_node_ns(n) ... |
number=None | self.address=None | def __init__(self,name,value,rfc2425parameters={}): self.name=name if self.name.upper()!="EMAIL": raise RuntimeError,"VCardEmail handles only 'EMAIL' type" if isinstance(value,libxml2.xmlNode): number=None self.type=[] n=value.children vns=get_node_ns(value) while n: if n.type!='element': n=n.next continue ns=get_node_... |
if kw.has_key("type") and kw["type"] not in presence_types: | if kw.has_key("type") and kw["type"] and kw["type"] not in presence_types: | def __init__(self,node=None,**kw): self.node=None if isinstance(node,Presence): pass elif isinstance(node,Stanza): raise TypeError,"Couldn't make Presence from other Stanza" elif isinstance(node,libxml2.xmlNode): pass elif node is not None: raise TypeError,"Couldn't make Presence from %r" % (type(node),) if kw.has_key... |
raise StanzaError,"Results may only be generated for 'set' or 'get' iq" | raise StanzaError,("Results may only be generated for 'subscribe'," "'subscribed','unsubscribe' or 'unsubscribed' presence") | def make_accept_response(self): if self.get_type() not in ("subscribe","subscribed","unsubscribe","unsubscribed"): raise StanzaError,"Results may only be generated for 'set' or 'get' iq" pr=Presence(type=accept_responses[self.get_type()], fr=self.get_to(),to=self.get_from(),id=self.get_id()) return pr |
raise StanzaError,"Results may only be generated for 'set' or 'get' iq" | raise StanzaError,("Results may only be generated for 'subscribe'," "'subscribed','unsubscribe' or 'unsubscribed' presence") | def make_deny_response(self): if self.get_type() not in ("subscribe","subscribed","unsubscribe","unsubscribed"): raise StanzaError,"Results may only be generated for 'set' or 'get' iq" pr=Presence(type=accept_responses[self.get_type()], fr=self.get_to(),to=self.get_from(),id=self.get_id()) return pr |
jid=JID(node.prop("jid")) | jid=JID(node.prop("jid").decode("utf-8")) | def from_xml(self,node): """Initialize RosterItem from XML node.""" if node.type!="element": raise ValueError,"XML node is not a roster item (not en element)" ns=get_node_ns_uri(node) if ns and ns!=ROSTER_NS or node.name!="item": raise ValueError,"XML node is not a roster item" jid=JID(node.prop("jid")) subscription=no... |
return hangul_decompose[c] | return hangul_decompose(c) | def decompose(c): s=ord(c) if s>=SBase and s-SBase<SCount: return hangul_decompose[c] d=decompositions_3_2_0.get(c,unicodedata.decomposition(c)) if not d: return [c] if d.startswith("<"): d=d[d.index(">")+1:] print "Compatibility decomposition: %r -> %r" % (c,d) else: print "Canonical decomposition: %r -> %r" % (c,d)... |
result[-1:]=(0,lch[1],unichr(last)) | result[-1]=(0,lch[1],unichr(last)) | def hangul_compose(l): if not l: return l ll=len(l) last=ord(l[0][2]) result=[l[0]] for i in range(1,ll): lch=l[i] ch=ord(lch[2]) LIndex=last-LBase if 0<=LIndex and LIndex<LCount: VIndex=ch-VBase if 0<=VIndex and VIndex<VCount: last=(SBase+(LIndex*VCount+VIndex)*TCount) result[-1:]=(0,lch[1],unichr(last)) continue S... |
now = datetime.utcnow() if self.state == 'new': self.state = 'fresh' if self.state == 'fresh': if now > self.freshness_time: self.state = 'old' if self.state == 'old': if now > self.expire_time: self.state = 'stale' if self.state == 'stale': if now > self.purge_time: self.state = 'purged' self.state_value = _state_valu... | self._lock.acquire() try: now = datetime.utcnow() if self.state == 'new': self.state = 'fresh' if self.state == 'fresh': if now > self.freshness_time: self.state = 'old' if self.state == 'old': if now > self.expire_time: self.state = 'stale' if self.state == 'stale': if now > self.purge_time: self.state = 'purged' self... | def update_state(self): """Update current status of the item and compute time of the next state change. |
self.object_handler(item.address, item.value, item.state) | self._object_handler(item.address, item.value, item.state) | def _try_backup_item(self): """Check if a backup item is available in cache and call the item handler if it is. :return: `True` if backup item was found. :returntype: `bool`""" if not self._backup_state: return False item = self.cache.get_item(self.address, self._backup_state) if item: self.object_handler(item.address... |
item = self.get_item(address, state) if item: object_handler(item.address, item.value, item.state) if not self._fetcher: raise TypeError, "No cache fetcher defined" if not error_handler: def error_handler(address, data): return object_handler(address, None, 'error') if freshness_period is None: freshness_period = s... | self._lock.acquire() try: item = self.get_item(address, state) if item: object_handler(item.address, item.value, item.state) if not self._fetcher: raise TypeError, "No cache fetcher defined" if not error_handler: def error_handler(address, data): return object_handler(address, None, 'error') if freshness_period is None... | def request_object(self, address, state, object_handler, error_handler = None, timeout_handler = None, backup_state = None, timeout = timedelta(minutes=60), freshness_period = None, expiration_period = None, purge_period = None): |
state = item.update_state() if state != 'purged': if len(self._items_list) >= self.max_items: self.purge_items() self._items[item.address] = item self._items_list.append(item) self._items_list.sort() return item.state | self._lock.acquire() try: state = item.update_state() if state != 'purged': if len(self._items_list) >= self.max_items: self.purge_items() self._items[item.address] = item self._items_list.append(item) self._items_list.sort() return item.state finally: self._lock.release() | def add_item(self, item): """Add an item to the cache. |
item = self._items.get(address) if not item: | self._lock.acquire() try: item = self._items.get(address) if not item: return None new_state = self.update_item(item) if _state_values[state] >= item.state_value: return item | def get_item(self, address, state = 'fresh'): """Get an item from the cache. |
new_state = self.update_item(item) if _state_values[state] >= item.state_value: return item return None | finally: self._lock.release() | def get_item(self, address, state = 'fresh'): """Get an item from the cache. |
state = item.update_state() if item.state == 'purged': self._purged += 1 if self._purged > 0.25*self.max_items: self.purge_items() else: | self._lock.acquire() try: state = item.update_state() | def update_item(self, item): """Update state of an item in the cache. |
return state | if item.state == 'purged': self._purged += 1 if self._purged > 0.25*self.max_items: self.purge_items() return state finally: self._lock.release() | def update_item(self, item): """Update state of an item in the cache. |
il=self._items_list num_items = len(il) need_remove = num_items - int(0.75 * self.max_items) for i in range(need_remove): item=il.pop(0) try: del self._items[item.address] except KeyError: pass while il and il[0].update_state()=="purged": item=il.pop(0) try: del self._items[item.address] except KeyError: pass | self._lock.acquire() try: il=self._items_list num_items = len(il) need_remove = num_items - int(0.75 * self.max_items) for i in range(need_remove): item=il.pop(0) try: del self._items[item.address] except KeyError: pass while il and il[0].update_state()=="purged": item=il.pop(0) try: del self._items[item.address] exc... | def purge_items(self): """Remove purged and overlimit items from the cache. |
now = datetime.utcnow() for t,f in list(self._active_fetchers): if t > now: break self._active_fetchers.remove((t,f)) self.purge_items() | self._lock.acquire() try: now = datetime.utcnow() for t,f in list(self._active_fetchers): if t > now: break f.timeout() self.purge_items() finally: self._lock.release() | def tick(self): now = datetime.utcnow() for t,f in list(self._active_fetchers): if t > now: break self._active_fetchers.remove((t,f)) self.purge_items() |
for t, f in list(self._active_fetchers): if f is fetcher: self._active_fetchers.remove((t, f)) f._deactivated() return | self._lock.acquire() try: for t, f in list(self._active_fetchers): if f is fetcher: self._active_fetchers.remove((t, f)) f._deactivated() return finally: self._lock.release() | def remove_fetcher(self, fetcher): """Remove a running fetcher from the list of active fetchers. |
self._fetcher = fetcher_class | self._lock.acquire() try: self._fetcher = fetcher_class finally: self._lock.release() | def set_fetcher(self, fetcher_class): """Set the fetcher class. |
if object_class not in self._caches: raise TypeError, "No cache for %r" % (object_class,) self._caches[object_class].request_object(address, state, object_handler, error_handler, timeout_handler, backup_state, timeout, freshness_period, expiration_period, purge_period) | self._lock.acquire() try: if object_class not in self._caches: raise TypeError, "No cache for %r" % (object_class,) self._caches[object_class].request_object(address, state, object_handler, error_handler, timeout_handler, backup_state, timeout, freshness_period, expiration_period, purge_period) finally: self._lock.rel... | def request_object(self, object_class, address, state, object_handler, error_handler = None, timeout_handler = None, backup_state = None, timeout = None, freshness_period = None, expiration_period = None, purge_period = None): |
cache = self._caches.get(object_class) if not cache: cache = Cache(self.max_items, self.default_freshness_period, self.default_expiration_period, self.defaut_purge_period) self._caches[object_class] = cache cache.set_fetcher(fetcher_class) | self._lock.acquire() try: cache = self._caches.get(object_class) if not cache: cache = Cache(self.max_items, self.default_freshness_period, self.default_expiration_period, self.defaut_purge_period) self._caches[object_class] = cache cache.set_fetcher(fetcher_class) finally: self._lock.release() | def register_fetcher(self, object_class, fetcher_class): """Register a fetcher class for an object class. |
cache = self._caches.get(object_class) if not cache: return cache.set_fetcher(None) | self._lock.acquire() try: cache = self._caches.get(object_class) if not cache: return cache.set_fetcher(None) finally: self._lock.release() | def unregister_fetcher(self, object_class): """Unregister a fetcher class for an object class. |
if type(other) in (StringType,UnicodeType): | if other is None: return 0 elif type(other) in (StringType,UnicodeType): | def __eq__(self,other): if type(other) in (StringType,UnicodeType): other=JID(other) elif not isinstance(other,JID): raise TypeError,"Can't compare JID with %r" % (type(other),) return (self.node==other.node and self.domain==other.domain and self.resource==other.resource) |
return uc | return None | def b1_mapping(uc): if stringprep.in_table_b1(uc): return u"" else: return uc |
old_ns_uri = old_ns.content old_ns_prefix = old_ns.name | if old_ns is not None: old_ns_uri = old_ns.content old_ns_prefix = old_ns.name else: old_ns_uri = None old_ns_prefix = None | def replace_ns(node, old_ns, new_ns): """Replace namespaces in a whole subtree. |
if ns and ns.content == old_ns_uri and ns.name == old_ns_prefix: | if ns is None and old_ns is None: node.setNs(new_ns) elif ns and ns.content == old_ns_uri and ns.name == old_ns_prefix: | def replace_ns(node, old_ns, new_ns): """Replace namespaces in a whole subtree. |
def presence_changed(self,user,stanza): """ Called whenever user's presence changes (includes nick, role or affiliation changes). `user` MucRoomUser object describing the user. `stanza` the stanza received. """ pass | def nick_changed(self,user,old_nick,stanza): """ Called after a user nick has been changed. | |
self.room_state.stream.debug(s) | self.room_state.manager.stream.debug(s) | def debug(self,s): self.room_state.stream.debug(s) |
old_user=MucRoomUser(stanza) | old_user=MucRoomUser(user) | def process_unavailable_presence(self,stanza): """ Process <presence type="unavailable"/> received from the room. """ fr=stanza.get_from() if not fr.resource: return nick=fr.resource user=self.users.get(nick) if user: old_user=MucRoomUser(stanza) user.update_presence(stanza) if user.new_nick: mc=stanza.get_muc_child() ... |
self.debug("Connect to %r failed" % sockaddr) | self.debug("Connect to %r failed" % (sockaddr,)) | def _connect(self,addr,port,to=None): if to is None: to=str(addr) if type(addr) in (StringType,UnicodeType): self.state_change("resolving",addr) s=None for res in socket.getaddrinfo(addr,port,0,socket.SOCK_STREAM): family,socktype,proto,canonname,sockaddr=res try: s=socket.socket(family,socktype,proto) self.state_chang... |
return self.timestamp.__cmp__(other.timestamp) | return cmp(timestamp, other.timestamp) | def __cmp__(self,other): return self.timestamp.__cmp__(other.timestamp) |
c=self.xpath_eval("ns:*",{'ns':self.ns}) | c=self.xpath_eval("ns:*",{'ns':self.ns.getContent()}) | def get_condition(self): c=self.xpath_eval("ns:*",{'ns':self.ns}) if not c: self.upgrade() c=self.xpath_eval("ns:*",{'ns':self.ns}) if not c: return None return c[0] |
self.xmlnode=node_or_jid.copyNode(1) | self.xmlnode=xmlnode_or_jid.copyNode(1) | def __init__(self,disco,xmlnode_or_jid,node,name=None,action=None): self.disco=disco if isinstance(xmlnode_or_jid,JID): if disco: self.xmlnode=disco.xmlnode.newChild(disco.xmlnode.ns(),"item",None) else: self.xmlnode=common_root.newChild(None,"item",None) ns=self.xmlnode.newNs(DISCO_ITEMS_NS,None) self.xmlnode.setNs(ns... |
self.xmlnode=node_or_jid | self.xmlnode=xmlnode_or_jid | def __init__(self,disco,xmlnode_or_jid,node,name=None,action=None): self.disco=disco if isinstance(xmlnode_or_jid,JID): if disco: self.xmlnode=disco.xmlnode.newChild(disco.xmlnode.ns(),"item",None) else: self.xmlnode=common_root.newChild(None,"item",None) ns=self.xmlnode.newNs(DISCO_ITEMS_NS,None) self.xmlnode.setNs(ns... |
slef.xmlnode.setProp("node",to_utf8(xmlnode_or_node)) | self.xmlnode.setProp("node",to_utf8(xmlnode_or_node)) | def __init__(self,xmlnode_or_node=None): self.xmlnode=None self.xpath_ctxt=None if isinstance(xmlnode_or_node,libxml2.xmlNode): ns=xmlnode.ns() if ns.getContent() != DISCO_ITEMS_NS: raise RosterError,"Bad disco-items namespace" self.xmlnode=xmlnode.docCopyNode(common_doc,1) common_root.addChild(self.xmlnode) self.ns=se... |
slef.xmlnode.setProp("node",to_utf8(xmlnode_or_node)) | self.xmlnode.setProp("node",to_utf8(xmlnode_or_node)) | def __init__(self,xmlnode_or_node=None): self.xmlnode=None self.xpath_ctxt=None if isinstance(xmlnode_or_node,libxml2.xmlNode): ns=xmlnode.ns() if ns.getContent() != DISCO_INFO_NS: raise RosterError,"Bad disco-info namespace" self.xmlnode=xmlnode.docCopyNode(common_doc,1) common_root.addChild(self.xmlnode) self.ns=self... |
def __init__(self,disco,xmlnode_or_jid,node,name=None,action=None): | def __init__(self,disco,xmlnode_or_jid,node=None,name=None,action=None): | def __init__(self,disco,xmlnode_or_jid,node,name=None,action=None): self.disco=disco if isinstance(xmlnode_or_jid,JID): if disco: self.xmlnode=disco.xmlnode.newChild(disco.xmlnode.ns(),"item",None) else: self.xmlnode=common_root.newChild(None,"item",None) ns=self.xmlnode.newNs(DISCO_ITEMS_NS,None) self.xmlnode.setNs(ns... |
ns=xmlnode.ns() | ns=xmlnode_or_node.ns() | def __init__(self,xmlnode_or_node=None): self.xmlnode=None self.xpath_ctxt=None if isinstance(xmlnode_or_node,libxml2.xmlNode): ns=xmlnode.ns() if ns.getContent() != DISCO_ITEMS_NS: raise RosterError,"Bad disco-items namespace" self.xmlnode=xmlnode.docCopyNode(common_doc,1) common_root.addChild(self.xmlnode) self.ns=se... |
self.xmlnode=xmlnode.docCopyNode(common_doc,1) | self.xmlnode=xmlnode_node_or_node.docCopyNode(common_doc,1) | def __init__(self,xmlnode_or_node=None): self.xmlnode=None self.xpath_ctxt=None if isinstance(xmlnode_or_node,libxml2.xmlNode): ns=xmlnode.ns() if ns.getContent() != DISCO_ITEMS_NS: raise RosterError,"Bad disco-items namespace" self.xmlnode=xmlnode.docCopyNode(common_doc,1) common_root.addChild(self.xmlnode) self.ns=se... |
def identities(self): | def items(self): | def identities(self): ret=[] l=self.xpath_ctxt.xpathEval("d:identity") if l is not None: for i in l: ret.append(DiscoIdentity(i)) return ret |
l=self.xpath_ctxt.xpathEval("d:identity") | l=self.xpath_ctxt.xpathEval("d:item") | def identities(self): ret=[] l=self.xpath_ctxt.xpathEval("d:identity") if l is not None: for i in l: ret.append(DiscoIdentity(i)) return ret |
ret.append(DiscoIdentity(i)) | ret.append(DiscoItem(self,i)) | def identities(self): ret=[] l=self.xpath_ctxt.xpathEval("d:identity") if l is not None: for i in l: ret.append(DiscoIdentity(i)) return ret |
if t.lookup(c) is not None: | if t.lookup(c): | def prohibit(self,s): """Checks for prohibited characters.""" for c in s: for t in self.prohibited: if t.lookup(c) is not None: raise StringprepError,"Prohibited character: %r" % (c,) return s |
if t.lookup(c) is not None: | if t.lookup(c): | def check_unassigned(self,s): """Checks for unassigned character codes.""" for c in s: for t in self.unassigned: if t.lookup(c) is not None: raise StringprepError,"Unassigned character: %r" % (c,) return s |
if D_1.lookup(c) is not None: | if D_1.lookup(c): | def check_bidi(self,s): """Checks if sting is valid for bidirectional printing.""" has_L=0 has_RAL=0 for c in s: if D_1.lookup(c) is not None: has_RAL=1 elif D_2.lookup(c) is not None: has_L=1 if has_L and has_RAL: raise StringprepError,"Both RandALCat and LCat characters present" if has_RAL and (D_1.lookup(s[0]) is No... |
elif D_2.lookup(c) is not None: | elif D_2.lookup(c): | def check_bidi(self,s): """Checks if sting is valid for bidirectional printing.""" has_L=0 has_RAL=0 for c in s: if D_1.lookup(c) is not None: has_RAL=1 elif D_2.lookup(c) is not None: has_L=1 if has_L and has_RAL: raise StringprepError,"Both RandALCat and LCat characters present" if has_RAL and (D_1.lookup(s[0]) is No... |
n=common_doc.newTextChild(None,"handshake",hash) | n=common_root.newTextChild(None,"handshake",hash) | def _auth(self): if self.authenticated: self.debug("_auth: already authenticated") return self.debug("doing handshake...") hash=self._compute_handshake() n=common_doc.newTextChild(None,"handshake",hash) self._write_node(n) n.unlinkNode() n.freeNode() |
self.timeout_time = datetime.utcnow()+timeout_period | if timeout_period: self.timeout_time = datetime.utcnow()+timeout_period else: self.timeout_time = datetime.max | def __init__(self, cache, address, item_freshness_period, item_expiration_period, item_purge_period, object_handler, error_handler, timeout_handler, timeout_period, backup_state = None): """Initialize an `CacheFetcher` object. |
self.default_expiration_period, self.defaut_purge_period) | self.default_expiration_period, self.default_purge_period) | def register_fetcher(self, object_class, fetcher_class): """Register a fetcher class for an object class. |
print >>file("debug.log","a"),`("!HHHHHH",self.id,flags,qdcount,ancount,nscount,arcount)`,`payload` | def bin_format(self,maxsize=512): payload="" qdcount=0 for name,type,cls in self.questions: type=query_types_by_name[type] cls=classes_by_name[cls] data=domain_str2bin(name)+struct.pack("!HH",type,cls) if maxsize and len(data)+len(payload)+12>maxsize: self.tc=1 break payload+=data qdcount+=1 ancount=0 for rr in self.an... | |
if ns==ns1: | if ns==None: | def __init__(self,node_or_cond,ns=None,copy=1,parent=None): """ Contructor: ErrorNode(error_node[,copy=boolean]) -> ErrorNode ErrorNode(xml_node,[,copy=boolean]) -> ErrorNode ErrorNode(condition,ns,[,parent=parent_node]) -> ErrorNode """ if type(node_or_cond) is StringType: node_or_cond=unicode(node_or_cond,"utf-8") s... |
self.ns=node_or_cond.ns | self.ns=node_or_cond.ns.getContent() | def __init__(self,node_or_cond,ns=None,copy=1,parent=None): """ Contructor: ErrorNode(error_node[,copy=boolean]) -> ErrorNode ErrorNode(xml_node,[,copy=boolean]) -> ErrorNode ErrorNode(condition,ns,[,parent=parent_node]) -> ErrorNode """ if type(node_or_cond) is StringType: node_or_cond=unicode(node_or_cond,"utf-8") s... |
self.ns=ns | self.ns=ns.getContent() | def __init__(self,node_or_cond,ns=None,copy=1,parent=None): """ Contructor: ErrorNode(error_node[,copy=boolean]) -> ErrorNode ErrorNode(xml_node,[,copy=boolean]) -> ErrorNode ErrorNode(condition,ns,[,parent=parent_node]) -> ErrorNode """ if type(node_or_cond) is StringType: node_or_cond=unicode(node_or_cond,"utf-8") s... |
c=self.xpath_eval("ns:*",{'ns':self.ns.getContent()}) | c=self.xpath_eval("ns:*",{'ns':self.ns}) | def get_condition(self): c=self.xpath_eval("ns:*",{'ns':self.ns.getContent()}) if not c: self.upgrade() c=self.xpath_eval("ns:*",{'ns':self.ns.getContent()}) if not c: return None return c[0] |
cond,typ=legacy_codes[code] | cond=legacy_codes[code] typ,x=stanza_errors[cond] | def upgrade(self): if not self.node.hasProp("code"): code=None else: try: code=int(self.node.prop("code")) except ValueError,KeyError: code=None if code and legacy_codes.has_key(code): cond,typ=legacy_codes[code] else: cond=None typ="cancel" if not self.node.hasProp("type"): self.node.setProp("type",typ) condition=s... |
print >>sys.stderr,"------" print >>sys.stderr,"node ns: ",node.ns().getContent() print >>sys.stderr,"slot ns: ",slot.ns().getContent() print >>sys.stderr,node.serialize() print >>sys.stderr,"------" | def merge(self): output_doc=self.template_doc.copyDoc(True) slot=output_doc.xpathEval('//*[@id="main"]')[0] content=self.content_doc.xpathEval('//*[@class="document"]/*') for node in content: print >>sys.stderr,"------" print >>sys.stderr,"node ns: ",node.ns().getContent() print >>sys.stderr,"slot ns: ",slot.ns().getCo... | |
logging.getLogger("pyxmpp.Stream.out").debug("OUT: %r",str) | logging.getLogger("pyxmpp.Stream.out").debug("OUT: %r",data) | def _write_raw(self,data): """Same as `Stream.write_raw` but assume `self.lock` is acquired.""" logging.getLogger("pyxmpp.Stream.out").debug("OUT: %r",str) try: self.socket.send(data) except (IOError,OSError),e: raise FatalStreamError("IO Error: "+str(e)) except SSLError,e: raise TLSError("TLS Error: "+str(e)) |
self.set_response_handlers(iq,self._bind_success,self._bind_error) | def bind(self,resource): """Bind to a resource. :Parameters: - `resource`: the resource name to bind to. XMPP stream is authenticated for bare JID only. To use the full JID it must be bound to a resource. """ iq=Iq(typ="set") q=iq.new_query(BIND_NS,"bind") if resource: q.newTextChild(q.ns(),"resource",to_utf8(resourc... | |
self.debug("Skipping unavailable auth method: %s" % method) | self.debug("Skipping unavailable auth method: %s" % (method,) ) | def try_auth(self): if self.authenticated: self.debug("try_auth: already authenticated") return self.features_timeout=None self.debug("trying auth: %r" % (self.auth_methods_left,)) if not self.auth_methods_left: raise AuthenticationError,"No allowed authentication methods available" method=self.auth_methods_left[0] if ... |
return try_auth() | return self.try_auth() | def try_auth(self): if self.authenticated: self.debug("try_auth: already authenticated") return self.features_timeout=None self.debug("trying auth: %r" % (self.auth_methods_left,)) if not self.auth_methods_left: raise AuthenticationError,"No allowed authentication methods available" method=self.auth_methods_left[0] if ... |
return realm_list | return self.jid.domain | def choose_realm(self,realm_list): if not realm_list: return realm_list if self.jid.domain in realm_list: return self.jid.domain return realm_list[0] |
traceback.print_exc(file=sys.stderr) | self.debug_exception() | def process(self): try: self.read() except (FatalStreamError,KeyboardInterrupt,SystemExit),e: self.close() raise except: traceback.print_exc(file=sys.stderr) |
if self.iq_response_handlers.has_key((id,fr.as_unicode())): key=(id,fr.as_unicode()) | if fr: ufr=fr.as_unicode() else: ufr=None if self.iq_response_handlers.has_key((id,ufr)): key=(id,ufr) | def process_iq(self,stanza): id=stanza.get_id() fr=stanza.get_from() |
if not typ: typ="normal" | def process_message(self,stanza): if not self.initiator and not self.peer_authenticated: self.debug("Ignoring message - peer not authenticated yet") return 1 typ=stanza.get_type() if not typ: typ="normal" if self.message_handlers.has_key(typ): self.message_handlers[typ](stanza) return 1 return 0 | |
type=="available" self.message_handlers[type]=handler | type="available" self.presence_handlers[type]=handler | def set_presence_handler(self,type,handler): if not type: type=="available" self.message_handlers[type]=handler |
authenticator,None=all_mechanisms_dict[mechanism] | authenticator=all_mechanisms_dict[mechanism][0] | def ClientAuthenticator(mechanism,password_manager): authenticator,None=all_mechanisms_dict[mechanism] return authenticator(password_manager) |
return unicode(self.node.prep("name"),"utf-8") | return unicode(self.node.prop("name"),"utf-8") | def name(self): return unicode(self.node.prep("name"),"utf-8") |
return unicode(self.node.prep("jid"),"utf-8") | return JID(self.node.prop("jid")) | def jid(self): return unicode(self.node.prep("jid"),"utf-8") |
return unicode(self.node.prep("subscription"),"utf-8") | return unicode(self.node.prop("subscription"),"utf-8") | def subscription(self): return unicode(self.node.prep("subscription"),"utf-8") |
if ns != "jabber:iq:roster": | if ns.getContent() != "jabber:iq:roster": | def __init__(self,node=None): self.node=None self.xpath_ctxt=None if node is None: self.node=common_root.newChild(None,"query",None) self.ns=self.node.newNs("jabber:iq:roster",None) self.node.setNs(self.ns) else: ns=node.ns() if ns != "jabber:iq:roster": raise RosterError,"Bad roster namespace" self.node=node.docCopyNo... |
def item_by_name(self,name): | def items_by_name(self,name): | def item_by_name(self,name): if not name: raise ValueError,"name is None" name=to_utf8(name) if not name.contains('"'): expr='r:item[@name="%s"]' % name elif not name.contains("'"): expr="r:item[@name='%s']" % name else: raise RosterError,"Unsupported roster item name format" l=self.xpath_ctxt.xpathEval(expr) if not l:... |
if not name.contains('"'): | if '"' not in name: | def item_by_name(self,name): if not name: raise ValueError,"name is None" name=to_utf8(name) if not name.contains('"'): expr='r:item[@name="%s"]' % name elif not name.contains("'"): expr="r:item[@name='%s']" % name else: raise RosterError,"Unsupported roster item name format" l=self.xpath_ctxt.xpathEval(expr) if not l:... |
elif not name.contains("'"): | elif "'" not in name: | def item_by_name(self,name): if not name: raise ValueError,"name is None" name=to_utf8(name) if not name.contains('"'): expr='r:item[@name="%s"]' % name elif not name.contains("'"): expr="r:item[@name='%s']" % name else: raise RosterError,"Unsupported roster item name format" l=self.xpath_ctxt.xpathEval(expr) if not l:... |
def item_by_group(self,group): if not name: | def items_by_group(self,group): if not group: | def item_by_group(self,group): if not name: raise ValueError,"group is None" group=to_utf8(group) if not name.contains('"'): expr='r:item[group="%s"]' % group elif not name.contains("'"): expr="r:item[group='%s']" % group else: raise RosterError,"Unsupported roster group name format" l=self.xpath_ctxt.xpathEval(expr) i... |
if not name.contains('"'): expr='r:item[group="%s"]' % group elif not name.contains("'"): expr="r:item[group='%s']" % group | if '"' not in group: expr='r:item[r:group="%s"]' % group elif "'" not in group: expr="r:item[r:group='%s']" % group | def item_by_group(self,group): if not name: raise ValueError,"group is None" group=to_utf8(group) if not name.contains('"'): expr='r:item[group="%s"]' % group elif not name.contains("'"): expr="r:item[group='%s']" % group else: raise RosterError,"Unsupported roster group name format" l=self.xpath_ctxt.xpathEval(expr) i... |
digest_uri="%s/%s/%s" % (serv_type,host) | digest_uri="%s/%s" % (serv_type,host) | def challenge(self,challenge): if not challenge: self.__logger.debug("Empty challenge") return Failure("bad-challenge") |
input_ns = n.ns() | try: input_ns = n.ns() except libxml2.treeError: input_ns = None | def test_replace_ns(self): doc = libxml2.newDoc("1.0") |
n1_ns = n1.ns() | try: n1_ns = n1.ns() except libxml2.treeError: ns1_ns = None | def test_replace_ns(self): doc = libxml2.newDoc("1.0") |
input_ns = n.ns() | try: input_ns = n.ns() except libxml2.treeError: input_ns = None | def test_replace_null_ns(self): doc = libxml2.newDoc("1.0") |
el1.setNs(root1.ns()) | try: root1_ns = root1.ns() except libxml2.treeError: root1_ns = None el1.setNs(root1_ns) | def test_safe_serialize(self): s1 = """<a xmlns="http://pyxmpp.jabberstudio.org/xmlns/test"><b a1="v1" xmlns="http://pyxmpp.jabberstudio.org/xmlns/test1" a2="v2"/></a>""" doc1 = libxml2.parseDoc(s1) root1 = doc1.getRootElement() el1 = root1.children el1.setNs(root1.ns()) |
expr='d:feature[@var="%s"]' % (var,) | expr=u'd:feature[@var="%s"]' % (var,) | def has_feature(self,var): """Check if `self` contains the named feature. |
expr="d:feature[@var='%s']" % (var,) | expr=u"d:feature[@var='%s']" % (var,) | def has_feature(self,var): """Check if `self` contains the named feature. |
l=self.xpath_ctxt.xpathEval(expr) | l=self.xpath_ctxt.xpathEval(to_utf8(expr)) | def has_feature(self,var): """Check if `self` contains the named feature. |
n.setProp("var",var) | n.setProp("var",to_utf8(var)) | def add_feature(self,var): """Add a feature to `self`. |
type_expr="" | type_expr=u"" | def identity_is(self,item_category,item_type=None): """Check if the item described by `self` belongs to the given category and type. :Parameters: - `item_category`: the category name. - `item_type`: the type name. If `None` then only the category is checked. :Types: - `item_category`: unicode - `item_type`: unicode :... |
expr=' and @type="%s"' % (item_type,) | type_expr=u' and @type="%s"' % (item_type,) | def identity_is(self,item_category,item_type=None): """Check if the item described by `self` belongs to the given category and type. :Parameters: - `item_category`: the category name. - `item_type`: the type name. If `None` then only the category is checked. :Types: - `item_category`: unicode - `item_type`: unicode :... |
expr=" and @type='%s'" % (item_type,) | type_expr=u" and @type='%s'" % (item_type,) | def identity_is(self,item_category,item_type=None): """Check if the item described by `self` belongs to the given category and type. :Parameters: - `item_category`: the category name. - `item_type`: the type name. If `None` then only the category is checked. :Types: - `item_category`: unicode - `item_type`: unicode :... |
expr='d:feature[@category="%s"%s]' % (item_category,type_expr) | expr=u'd:identity[@category="%s"%s]' % (item_category,type_expr) | def identity_is(self,item_category,item_type=None): """Check if the item described by `self` belongs to the given category and type. :Parameters: - `item_category`: the category name. - `item_type`: the type name. If `None` then only the category is checked. :Types: - `item_category`: unicode - `item_type`: unicode :... |
expr="d:feature[@category='%s'%s]" % (item_category,type_expr) | expr=u"d:identity[@category='%s'%s]" % (item_category,type_expr) | def identity_is(self,item_category,item_type=None): """Check if the item described by `self` belongs to the given category and type. :Parameters: - `item_category`: the category name. - `item_type`: the type name. If `None` then only the category is checked. :Types: - `item_category`: unicode - `item_type`: unicode :... |
l=self.xpath_ctxt.xpathEval(expr) | l=self.xpath_ctxt.xpathEval(to_utf8(expr)) | def identity_is(self,item_category,item_type=None): """Check if the item described by `self` belongs to the given category and type. :Parameters: - `item_category`: the category name. - `item_type`: the type name. If `None` then only the category is checked. :Types: - `item_category`: unicode - `item_type`: unicode :... |
def unquote(s): | def _unquote(s): | def unquote(s): """Unquote quoted value from DIGEST-MD5 challenge or response. If `s` doesn't start or doesn't end with '"' then return it unchanged, remove the quotes and escape backslashes otherwise. :Parameters: - `s`: a quoted string. :Types: - `s`: `str` :return: the unquoted string. :returntype: `str`""" if no... |
def quote(s): | def _quote(s): | def quote(s): """Prepare a string for quoting for DIGEST-MD5 challenge or response. Don't add the quotes, only escape '"' and "\\" with backslashes. :Parameters: - `s`: a raw string. :Types: - `s`: `str` :return: `s` with '"' and "\\" escaped using "\\". :returntype: `str`""" s=s.replace('\\','\\\\') s=s.replace('"'... |
def h_value(s): | def _h_value(s): | def h_value(s): """H function of the DIGEST-MD5 algorithm (MD5 sum). :Parameters: - `s`: a string. :Types: - `s`: `str` :return: MD5 sum of the string. :returntype: `str`""" return md5.new(s).digest() |
def kd_value(k,s): | def _kd_value(k,s): | def kd_value(k,s): """KD function of the DIGEST-MD5 algorithm. :Parameters: - `k`: a string. - `s`: a string. :Types: - `k`: `str` - `s`: `str` :return: MD5 sum of the strings joined with ':'. :returntype: `str`""" return h_value("%s:%s" % (k,s)) |
return h_value("%s:%s" % (k,s)) def make_urp_hash(username,realm,passwd): | return _h_value("%s:%s" % (k,s)) def _make_urp_hash(username,realm,passwd): | def kd_value(k,s): """KD function of the DIGEST-MD5 algorithm. :Parameters: - `k`: a string. - `s`: a string. :Types: - `k`: `str` - `s`: `str` :return: MD5 sum of the strings joined with ':'. :returntype: `str`""" return h_value("%s:%s" % (k,s)) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.