本文整理汇总了Python中pyxmpp.utils.from_utf8函数的典型用法代码示例。如果您正苦于以下问题:Python from_utf8函数的具体用法?Python from_utf8怎么用?Python from_utf8使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了from_utf8函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: from_xml
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").decode("utf-8"))
subscription=node.prop("subscription")
if subscription not in ("none","from","to","both","remove"):
subscription="none"
ask=node.prop("ask")
if ask not in ("subscribe",None):
ask=None
name=from_utf8(node.prop("name"))
groups=[]
n=node.children
while n:
if n.type!="element":
n=n.next
continue
ns=get_node_ns_uri(n)
if ns and ns!=ROSTER_NS or n.name!="group":
n=n.next
continue
group=n.getContent()
if group:
groups.append(from_utf8(group))
n=n.next
self.jid=jid
self.name=name
self.groups=groups
self.subscription=subscription
self.ask=ask
开发者ID:AdamPrzybyla,项目名称:pyxmpp,代码行数:34,代码来源:roster.py
示例2: response
def response(self,response):
"""Process a client reponse.
:Parameters:
- `response`: the response from the client.
:Types:
- `response`: `str`
:return: a challenge, a success indicator or a failure indicator.
:returntype: `sasl.Challenge`, `sasl.Success` or `sasl.Failure`"""
s=response.split("\000")
if len(s)!=3:
self.__logger.debug("Bad response: %r" % (response,))
return Failure("not-authorized")
authzid,username,password=s
authzid=from_utf8(authzid)
username=from_utf8(username)
password=from_utf8(password)
if not self.password_manager.check_password(username,password):
self.__logger.debug("Bad password. Response was: %r" % (response,))
return Failure("not-authorized")
info={"mechanism":"PLAIN","username":username}
if self.password_manager.check_authzid(authzid,info):
return Success(username,None,authzid)
else:
self.__logger.debug("Authzid verification failed.")
return Failure("invalid-authzid")
开发者ID:AlexUlrich,项目名称:digsby,代码行数:27,代码来源:plain.py
示例3: _new_from_xml
def _new_from_xml(cls, xmlnode):
"""Create a new `Field` object from an XML element.
:Parameters:
- `xmlnode`: the XML element.
:Types:
- `xmlnode`: `libxml2.xmlNode`
:return: the object created.
:returntype: `Field`
"""
field_type = xmlnode.prop("type")
label = from_utf8(xmlnode.prop("label"))
name = from_utf8(xmlnode.prop("var"))
child = xmlnode.children
values = []
options = []
required = False
desc = None
while child:
if child.type != "element" or child.ns().content != DATAFORM_NS:
pass
elif child.name == "required":
required = True
elif child.name == "desc":
desc = from_utf8(child.getContent())
elif child.name == "value":
values.append(from_utf8(child.getContent()))
elif child.name == "option":
options.append(Option._new_from_xml(child))
child = child.next
if field_type and not field_type.endswith("-multi") and len(values) > 1:
raise BadRequestProtocolError, "Multiple values for a single-value field"
return cls(name, values, field_type, label, options, required, desc)
开发者ID:AlexUlrich,项目名称:digsby,代码行数:34,代码来源:dataforms.py
示例4: from_xml
def from_xml(self,xmlnode):
"""Initialize Delay object from an XML node.
:Parameters:
- `xmlnode`: the jabber:x:delay XML element.
:Types:
- `xmlnode`: `libxml2.xmlNode`"""
if xmlnode.type!="element":
raise ValueError,"XML node is not a jabber:x:delay element (not an element)"
ns=get_node_ns_uri(xmlnode)
if ns and (ns != self.xml_element_namespace
or xmlnode.name != self.xml_element_name):
raise ValueError,"XML node is not a " + self.xml_element_namespace + " element"
stamp=xmlnode.prop("stamp")
tm = _parse_ts(stamp)
tm=tm[0:8]+(0,)
self.timestamp=datetime.datetime.fromtimestamp(time.mktime(tm))
delay_from=from_utf8(xmlnode.prop("from"))
if delay_from:
try:
self.delay_from = JID(delay_from)
except JIDError:
raise JIDMalformedProtocolError, "Bad JID in the " + self.xml_element_namespace + " 'from' attribute"
else:
self.delay_from = None
self.reason = from_utf8(xmlnode.getContent())
开发者ID:Jajcus,项目名称:pyxmpp,代码行数:26,代码来源:delay.py
示例5: handle_message
def handle_message(self, stanza):
'''
<message
from='[email protected]/desktop'
to='[email protected]'>
<x xmlns='jabber:x:conference'
jid='[email protected]'
password='cauldronburn'
reason='Hey Hecate, this is the place for all good witches!'/>
</message>
'''
try:
fromjid = stanza.get_from()
x = stanza.xpath_eval('c:x',{'c':CONFERENCE_NS})[0]
roomjid = JID(from_utf8(x.prop('jid')))
roomname = JID(roomjid).node
password = x.prop('password')
password = from_utf8(password) if password else None
reason = x.prop('reason')
reason = from_utf8(reason) if reason else None
except Exception:
traceback.print_exc()
return False
else:
if not all((roomname, fromjid)):
return False
self.protocol.hub.on_invite(
protocol = self.protocol,
buddy = fromjid,
room_name = roomname,
message = reason,
on_yes = lambda: self.protocol.join_chat_jid(roomjid,
self.protocol.self_buddy.jid.node))
return True # don't let other message handlers do it
开发者ID:AlexUlrich,项目名称:digsby,代码行数:34,代码来源:__init__.py
示例6: from_xml
def from_xml(self, xmlnode):
"""Initialize Delay object from an XML node.
:Parameters:
- `xmlnode`: the jabber:x:delay XML element.
:Types:
- `xmlnode`: `libxml2.xmlNode`"""
if xmlnode.type != "element":
raise ValueError, "XML node is not a jabber:x:delay element (not an element)"
ns = get_node_ns_uri(xmlnode)
if ns and ns != DELAY_NS or xmlnode.name != "x":
raise ValueError, "XML node is not a jabber:x:delay element"
stamp = xmlnode.prop("stamp")
if stamp.endswith("Z"):
stamp = stamp[:-1]
if "-" in stamp:
stamp = stamp.split("-", 1)[0]
try:
tm = time.strptime(stamp, "%Y%m%dT%H:%M:%S")
except ValueError:
raise BadRequestProtocolError, "Bad timestamp"
tm = tm[0:8] + (0,)
self.timestamp = datetime.datetime.fromtimestamp(time.mktime(tm))
delay_from = from_utf8(xmlnode.prop("from"))
if delay_from:
try:
self.delay_from = JID(delay_from)
except JIDError:
raise JIDMalformedProtocolError, "Bad JID in the jabber:x:delay 'from' attribute"
else:
self.delay_from = None
self.reason = from_utf8(xmlnode.getContent())
开发者ID:Hellogz,项目名称:pyxmpp,代码行数:32,代码来源:delay.py
示例7: __from_xml
def __from_xml(self, xmlnode):
"""Initialize `Register` from an XML node.
:Parameters:
- `xmlnode`: the jabber:x:register XML element.
:Types:
- `xmlnode`: `libxml2.xmlNode`"""
self.__logger.debug("Converting jabber:iq:register element from XML")
if xmlnode.type != "element":
raise ValueError, "XML node is not a jabber:iq:register element (not an element)"
ns = get_node_ns_uri(xmlnode)
if ns and ns != REGISTER_NS or xmlnode.name != "query":
raise ValueError, "XML node is not a jabber:iq:register element"
for element in xml_element_iter(xmlnode.children):
ns = get_node_ns_uri(element)
if ns == DATAFORM_NS and element.name == "x" and not self.form:
self.form = Form(element)
elif ns != REGISTER_NS:
continue
name = element.name
if name == "instructions" and not self.instructions:
self.instructions = from_utf8(element.getContent())
elif name == "registered":
self.registered = True
elif name == "remove":
self.remove = True
elif name in legacy_fields and not getattr(self, name):
value = from_utf8(element.getContent())
if value is None:
value = u""
self.__logger.debug(u"Setting legacy field %r to %r" % (name, value))
setattr(self, name, value)
开发者ID:Hellogz,项目名称:pyxmpp,代码行数:34,代码来源:register.py
示例8: __from_xml
def __from_xml(self, xmlnode):
"""Initialize a `Form` object from an XML element.
:Parameters:
- `xmlnode`: the XML element.
:Types:
- `xmlnode`: `libxml2.xmlNode`
"""
self.fields = []
self.reported_fields = []
self.items = []
self.title = None
self.instructions = None
if (xmlnode.type != "element" or xmlnode.name != "x"
or xmlnode.ns().content != DATAFORM_NS):
raise ValueError, "Not a form: " + xmlnode.serialize()
self.type = xmlnode.prop("type")
if not self.type in self.allowed_types:
raise BadRequestProtocolError, "Bad form type: %r" % (self.type,)
child = xmlnode.children
while child:
if child.type != "element" or child.ns().content != DATAFORM_NS:
pass
elif child.name == "title":
self.title = from_utf8(child.getContent())
elif child.name == "instructions":
self.instructions = from_utf8(child.getContent())
elif child.name == "field":
self.fields.append(Field._new_from_xml(child))
elif child.name == "item":
self.items.append(Item._new_from_xml(child))
elif child.name == "reported":
self.__get_reported(child)
child = child.next
开发者ID:AdamPrzybyla,项目名称:pyxmpp,代码行数:34,代码来源:dataforms.py
示例9: __from_xml
def __from_xml(self, node):
if node.type!="element":
raise ValueError,"XML node is not a %s element (not en element)" % self.xml_element_name
ns=get_node_ns_uri(node)
if ns and ns!=self.xml_element_namespace or node.name!=self.xml_element_name:
raise ValueError,"XML node is not an %s element" % self.xml_element_name
labelss = xpath_eval(node, 'g:labels',{'g':GOOGLE_MAIL_NOTIFY_NS})
labels = labelss[0].getContent() if labelss else None
self.labels = from_utf8(labels).split('|') if labels else []
senderss = xpath_eval(node, 'g:senders',{'g':GOOGLE_MAIL_NOTIFY_NS})
self.senders = Senders(senderss[0]) if senderss else []
subjects = xpath_eval(node, 'g:subject',{'g':GOOGLE_MAIL_NOTIFY_NS})
self.subject = from_utf8(subjects[0].getContent()) if subjects else None
snippets = xpath_eval(node, 'g:snippet',{'g':GOOGLE_MAIL_NOTIFY_NS})
self.snippet = from_utf8(snippets[0].getContent()) if snippets else None
self.tid = int(from_utf8(node.prop("tid")))
self.participation = int(from_utf8(node.prop("participation")))
self.messages = int(from_utf8(node.prop("messages")))
self.date = int(from_utf8(node.prop("date")))
self.url = from_utf8(node.prop("date"))
开发者ID:AlexUlrich,项目名称:digsby,代码行数:25,代码来源:mail_thread_info.py
示例10: received_data
def received_data(self, stanza) :
from_jid = stanza.get_from()
iq = stanza.get_query()
sid = from_utf8(iq.prop('sid'))
data = base64.b64decode(iq.getContent())
seq = from_utf8(iq.prop('seq'))
print "get data seq : ", seq
session = self.session_mgr.get_session(from_jid, sid)
if session :
session.received_data(data, seq)
iq = stanza.make_result_response()
else :
iq = stanza.make_error_response('unexpected-request')
self.client.get_stream().send(iq)
开发者ID:walker8088,项目名称:easyworld,代码行数:14,代码来源:filemgr.py
示例11: __from_xml
def __from_xml(self, node):
'''A libxml2 node to a digsby.action'''
if node.type!="element":
raise ValueError,"XML node is not an action element (not en element)"
ns = get_node_ns_uri(node)
if ns and ns != DIGSBY_STATS_COUNTER_NS or node.name != "action":
raise ValueError,"XML node is not an action element"
type = node.prop("type")
self.type = from_utf8(type) if type is not None else None
initial = node.prop("initial")
self.initial = int(from_utf8(initial)) if initial is not None else None
value = node.prop("value")
self.value = int(from_utf8(value)) if value is not None else None
result = node.prop("result")
self.result = int(from_utf8(result)) if result is not None else None
开发者ID:AlexUlrich,项目名称:digsby,代码行数:15,代码来源:action.py
示例12: __from_xml
def __from_xml(self,node):
if node.type!="element":
raise ValueError,"XML node is not a %s element (not en element)" % self.xml_element_name
ns=get_node_ns_uri(node)
if ns and ns!=self.xml_element_namespace or node.name!=self.xml_element_name:
raise ValueError,"XML node is not an %s element" % self.xml_element_name
self.name = from_utf8(node.prop("name"))
self.address = from_utf8(node.prop("address"))
originator = node.prop("originator")
self.originator = int(from_utf8(originator)) if originator else 0
unread = node.prop("unread")
self.unread = int(from_utf8(unread)) if unread else 0
开发者ID:AlexUlrich,项目名称:digsby,代码行数:15,代码来源:sender.py
示例13: from_xml
def from_xml(self,node):
if node.type!="element":
raise ValueError,"XML node is not a ip (not en element)"
ns=get_node_ns_uri(node)
if ns and ns!=self.xml_element_namespace or node.name!=self.xml_element_name:
raise ValueError,"XML node is not a %s descriptor" % self.xml_element_name
self.ip = from_utf8(node.getContent())
开发者ID:AlexUlrich,项目名称:digsby,代码行数:7,代码来源:ip.py
示例14: __from_xml
def __from_xml(self, node):
if node.type!="element":
raise ValueError,"XML node is not a %s element (not en element)" % self.xml_element_name
ns=get_node_ns_uri(node)
if ns and ns!=self.xml_element_namespace or node.name!=self.xml_element_name:
raise ValueError,"XML node is not an %s element" % self.xml_element_name
self.result_time = int(from_utf8(node.prop("result-time")))
self.total_matched = int(from_utf8(node.prop("total-matched")))
self.url = from_utf8(node.prop("url"))
total_estimate = node.prop("messages")
self.total_estimate = int(from_utf8(total_estimate)) if total_estimate else 0
threads = xpath_eval(node, 'g:mail-thread-info',{'g':GOOGLE_MAIL_NOTIFY_NS})
self.extend(MailThreadInfo(thread) for thread in threads)
开发者ID:AlexUlrich,项目名称:digsby,代码行数:16,代码来源:mailbox.py
示例15: __disco_items
def __disco_items(self,iq):
"""Handle a disco#items request.
`self.disco_get_items` method will be used to prepare the query response.
:Parameters:
- `iq`: the IQ stanza received.
:Types:
- `iq`: `pyxmpp.iq.Iq`"""
q=iq.get_query()
if q.hasProp("node"):
node=from_utf8(q.prop("node"))
else:
node=None
items=self.disco_get_items(node,iq)
if isinstance(items,DiscoItems):
resp=iq.make_result_response()
self.__logger.debug("Disco-items query: %s preparing response: %s with reply: %s"
% (iq.serialize(),resp.serialize(),items.xmlnode.serialize()))
resp.set_content(items.xmlnode.copyNode(1))
elif isinstance(items,Stanza):
resp=items
else:
resp=iq.make_error_response("item-not-found")
self.__logger.debug("Disco-items response: %s" % (resp.serialize(),))
self.stream.send(resp)
开发者ID:AlexUlrich,项目名称:digsby,代码行数:26,代码来源:client.py
示例16: _plain_auth_in_stage2
def _plain_auth_in_stage2(self, username, _unused, stanza):
"""Handle the second stage (<iq type='set'/>) of legacy "plain"
authentication.
[server only]"""
password=stanza.xpath_eval("a:query/a:password",{"a":"jabber:iq:auth"})
if password:
password=from_utf8(password[0].getContent())
if not password:
self.__logger.debug("No password found in plain auth request")
iq=stanza.make_error_response("bad-request")
self.send(iq)
return
if self.check_password(username,password):
iq=stanza.make_result_response()
self.send(iq)
self.peer_authenticated=True
self.auth_method_used="plain"
self.state_change("authorized",self.peer)
self._post_auth()
else:
self.__logger.debug("Plain auth failed")
iq=stanza.make_error_response("bad-request")
e=iq.get_error()
e.add_custom_condition('jabber:iq:auth:error',"user-unauthorized")
self.send(iq)
开发者ID:AlexUlrich,项目名称:digsby,代码行数:27,代码来源:clientstream.py
示例17: __disco_info
def __disco_info(self,iq):
"""Handle a disco-info query.
:Parameters:
- `iq`: the stanza received.
Types:
- `iq`: `pyxmpp.Iq`"""
q=iq.get_query()
if q.hasProp("node"):
node=from_utf8(q.prop("node"))
else:
node=None
info=self.disco_get_info(node,iq)
if isinstance(info,DiscoInfo):
resp=iq.make_result_response()
self.__logger.debug("Disco-info query: %s preparing response: %s with reply: %s"
% (iq.serialize(),resp.serialize(),info.xmlnode.serialize()))
resp.set_content(info.xmlnode.copyNode(1))
elif isinstance(info,Stanza):
resp=info
else:
resp=iq.make_error_response("item-not-found")
self.__logger.debug("Disco-info response: %s" % (resp.serialize(),))
self.stream.send(resp)
开发者ID:AlexUlrich,项目名称:digsby,代码行数:25,代码来源:component.py
示例18: get_type
def get_type(self):
"""Get the error type.
:return: type of the error.
:returntype: `unicode`"""
if not self.xmlnode.hasProp("type"):
self.upgrade()
return from_utf8(self.xmlnode.prop("type"))
开发者ID:AdamPrzybyla,项目名称:pyxmpp,代码行数:8,代码来源:error.py
示例19: get_password
def get_password(self):
"""Get password from the MUC request.
:returntype: `unicode`
"""
for child in xml_element_iter(self.xmlnode.children):
if get_node_ns_uri(child) == MUC_NS and child.name == "password":
return from_utf8(child.getContent())
return None
开发者ID:AdamPrzybyla,项目名称:pyxmpp,代码行数:9,代码来源:muccore.py
示例20: get_history
def get_history(self):
"""Return history parameters carried by the stanza.
:returntype: `HistoryParameters`"""
for child in xml_element_iter(self.xmlnode.children):
if get_node_ns_uri(child) == MUC_NS and child.name == "history":
maxchars = from_utf8(child.prop("maxchars"))
if maxchars is not None:
maxchars = int(maxchars)
maxstanzas = from_utf8(child.prop("maxstanzas"))
if maxstanzas is not None:
maxstanzas = int(maxstanzas)
maxseconds = from_utf8(child.prop("maxseconds"))
if maxseconds is not None:
maxseconds = int(maxseconds)
# TODO: since -- requires parsing of Jabber dateTime profile
since = None
return HistoryParameters(maxchars, maxstanzas, maxseconds, since)
开发者ID:AdamPrzybyla,项目名称:pyxmpp,代码行数:18,代码来源:muccore.py
注:本文中的pyxmpp.utils.from_utf8函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论