本文整理汇总了Python中coherence.extern.et.ET.tostring方法的典型用法代码示例。如果您正苦于以下问题:Python ET.tostring方法的具体用法?Python ET.tostring怎么用?Python ET.tostring使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类coherence.extern.et.ET
的用法示例。
在下文中一共展示了ET.tostring方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: new_subscriber
# 需要导入模块: from coherence.extern.et import ET [as 别名]
# 或者: from coherence.extern.et.ET import tostring [as 别名]
def new_subscriber(self, subscriber):
notify = []
for vdict in self._variables.values():
notify += [v for v in vdict.values() if v.send_events == True]
self.info("new_subscriber", subscriber, notify)
if len(notify) <= 0:
return
root = ET.Element('e:propertyset')
root.attrib['xmlns:e']='urn:schemas-upnp-org:event-1-0'
evented_variables = 0
for n in notify:
e = ET.SubElement( root, 'e:property')
if n.name == 'LastChange':
if subscriber['seq'] == 0:
text = self.build_last_change_event(n.instance, force=True)
else:
text = self.build_last_change_event(n.instance)
if text is not None:
ET.SubElement( e, n.name).text = text
evented_variables += 1
else:
ET.SubElement( e, n.name).text = str(n.value)
evented_variables += 1
if evented_variables > 0:
xml = ET.tostring( root, encoding='utf-8')
event.send_notification(subscriber, xml)
self._subscribers[subscriber['sid']] = subscriber
示例2: propagate_notification
# 需要导入模块: from coherence.extern.et import ET [as 别名]
# 或者: from coherence.extern.et.ET import tostring [as 别名]
def propagate_notification(self, notify):
#print "propagate_notification", notify
if len(self._subscribers) <= 0:
return
if len(notify) <= 0:
return
root = ET.Element('e:propertyset')
root.attrib['xmlns:e']='urn:schemas-upnp-org:event-1-0'
if isinstance( notify, variable.StateVariable):
notify = [notify,]
evented_variables = 0
for n in notify:
e = ET.SubElement( root, 'e:property')
if n.name == 'LastChange':
text = self.build_last_change_event(instance=n.instance)
if text is not None:
ET.SubElement( e, n.name).text = text
evented_variables += 1
else:
s = ET.SubElement( e, n.name).text = str(n.value)
evented_variables += 1
if n.dependant_variable != None:
dependants = n.dependant_variable.get_allowed_values()
if dependants != None and len(dependants) > 0:
s.attrib['channel']=dependants[0]
if evented_variables == 0:
return
xml = ET.tostring( root, encoding='utf-8')
#print "propagate_notification", xml
for s in self._subscribers.values():
event.send_notification(s, xml)
示例3: toString
# 需要导入模块: from coherence.extern.et import ET [as 别名]
# 或者: from coherence.extern.et.ET import tostring [as 别名]
def toString(self):
""" sigh - having that optional preamble here
breaks some of the older ContentDirectoryClients
"""
#preamble = """<?xml version="1.0" encoding="utf-8"?>"""
#return preamble + ET.tostring(self,encoding='utf-8')
return ET.tostring(self,encoding='utf-8')
示例4: fromElement
# 需要导入模块: from coherence.extern.et import ET [as 别名]
# 或者: from coherence.extern.et.ET import tostring [as 别名]
def fromElement(self, elt):
Object.fromElement(self, elt)
for child in elt.getchildren():
if child.tag.endswith('refID'):
self.refID = child.text
elif child.tag.endswith('res'):
res = Resource.fromString(ET.tostring(child))
self.res.append(res)
示例5: fromString
# 需要导入模块: from coherence.extern.et import ET [as 别名]
# 或者: from coherence.extern.et.ET import tostring [as 别名]
def fromString(cls, aString):
instance = cls()
elt = utils.parse_xml(aString, 'utf-8')
elt = elt.getroot()
for node in elt.getchildren():
upnp_class_name = node.findtext('{%s}class' % 'urn:schemas-upnp-org:metadata-1-0/upnp/')
upnp_class = instance.get_upnp_class(upnp_class_name.strip())
new_node = upnp_class.fromString(ET.tostring(node))
instance.addItem(new_node)
return instance
示例6: render_NOTIFY
# 需要导入模块: from coherence.extern.et import ET [as 别名]
# 或者: from coherence.extern.et.ET import tostring [as 别名]
def render_NOTIFY(self, request):
self.info("EventServer received notify from %s, code: %d" % (request.client, request.code))
data = request.content.getvalue()
self.debug("EventServer notify data (%i) %s", len(data), data)
request.setResponseCode(200)
command = {"method": request.method, "path": request.path}
headers = request.received_headers
louie.send("UPnP.Event.Server.message_received", None, command, headers, data)
if request.code != 200:
self.info("data: %s", data)
else:
headers = request.getAllHeaders()
sid = headers["sid"]
try:
tree = utils.parse_xml(data).getroot()
ns = "urn:schemas-upnp-org:event-1-0"
event = Event(sid)
for prop in tree.findall("{%s}property" % ns):
for var in prop.getchildren():
tag = var.tag
idx = tag.find("}") + 1
self.debug("EventServer Event %s %s", var, ET.tostring(var))
if var.text is not None:
event.update({tag[idx:]: var.text})
else:
# this is solwise DMP1120w not escaping LastChange
txt = ET.tostring(var)[12:-13]
self.debug("EventServer Event %s", txt)
event.update({tag[idx:]: txt})
self.control_point.propagate(event)
except (SyntaxError, AttributeError):
self.warning("malformed event notification from %r", request.client)
self.exception("data: %r", data)
return ""
except Exception:
self.exception("data: %r", data)
return ""
示例7: element_to_didl
# 需要导入模块: from coherence.extern.et import ET [as 别名]
# 或者: from coherence.extern.et.ET import tostring [as 别名]
def element_to_didl(item):
""" a helper method to create a DIDLElement out of one ET element
or XML fragment string
"""
if not isinstance(item,basestring):
item = ET.tostring(item)
didl = """<DIDL-Lite xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:dlna="urn:schemas-dlna-org:metadata-1-0"
xmlns:pv="http://www.pv.com/pvns/"
xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/">""" \
+ item + \
"""</DIDL-Lite>"""
return didl
示例8: __init__
# 需要导入模块: from coherence.extern.et import ET [as 别名]
# 或者: from coherence.extern.et.ET import tostring [as 别名]
def __init__(self, server, control):
root = ET.Element('scpd')
root.attrib['xmlns']='urn:schemas-upnp-org:service-1-0'
e = ET.SubElement(root, 'specVersion')
ET.SubElement( e, 'major').text = '1'
ET.SubElement( e, 'minor').text = '0'
e = ET.SubElement( root, 'actionList')
for action in server._actions.values():
s = ET.SubElement( e, 'action')
ET.SubElement( s, 'name').text = action.get_name()
al = ET.SubElement( s, 'argumentList')
for argument in action.get_arguments_list():
a = ET.SubElement( al, 'argument')
ET.SubElement( a, 'name').text = argument.get_name()
ET.SubElement( a, 'direction').text = argument.get_direction()
ET.SubElement( a, 'relatedStateVariable').text = argument.get_state_variable()
e = ET.SubElement( root, 'serviceStateTable')
for var in server._variables[0].values():
s = ET.SubElement( e, 'stateVariable')
if var.send_events == True:
s.attrib['sendEvents'] = 'yes'
else:
s.attrib['sendEvents'] = 'no'
ET.SubElement( s, 'name').text = var.name
ET.SubElement( s, 'dataType').text = var.data_type
if(not var.has_vendor_values and len(var.allowed_values)):
#if len(var.allowed_values):
v = ET.SubElement( s, 'allowedValueList')
for value in var.allowed_values:
ET.SubElement( v, 'allowedValue').text = value
if( var.allowed_value_range != None and
len(var.allowed_value_range) > 0):
complete = True
for name,value in var.allowed_value_range.items():
if value == None:
complete = False
if complete == True:
avl = ET.SubElement( s, 'allowedValueRange')
for name,value in var.allowed_value_range.items():
if value != None:
ET.SubElement( avl, name).text = str(value)
self.xml = """<?xml version="1.0" encoding="utf-8"?>""" + ET.tostring( root, encoding='utf-8')
static.Data.__init__(self, self.xml, 'text/xml')
示例9: build_soap_call
# 需要导入模块: from coherence.extern.et import ET [as 别名]
# 或者: from coherence.extern.et.ET import tostring [as 别名]
def build_soap_call(method, arguments, is_response=False, encoding=SOAP_ENCODING, envelope_attrib=None, typed=None):
""" create a shell for a SOAP request or response element
- set method to none to omit the method element and add the arguments directly to the body (for an error msg)
- arguments can be a dict or an ET.Element
"""
envelope = ET.Element("s:Envelope")
if envelope_attrib:
for n in envelope_attrib:
envelope.attrib.update({n[0]: n[1]})
else:
envelope.attrib.update({"s:encodingStyle": "http://schemas.xmlsoap.org/soap/encoding/"})
envelope.attrib.update({"xmlns:s": "http://schemas.xmlsoap.org/soap/envelope/"})
body = ET.SubElement(envelope, "s:Body")
if method:
# append the method call
if is_response is True:
method += "Response"
re = ET.SubElement(body, method)
if encoding:
re.set(NS_SOAP_ENV + "encodingStyle", encoding)
else:
re = body
# append the arguments
if isinstance(arguments, (dict, OrderedDict)):
type_map = {str: "xsd:string", unicode: "xsd:string", int: "xsd:int", float: "xsd:float", bool: "xsd:boolean"}
for arg_name, arg_val in arguments.iteritems():
arg_type = type_map[type(arg_val)]
if arg_type == "xsd:string" and type(arg_val) == unicode:
arg_val = arg_val.encode("utf-8")
if arg_type == "xsd:int" or arg_type == "xsd:float":
arg_val = str(arg_val)
if arg_type == "xsd:boolean":
if arg_val == True:
arg_val = "1"
else:
arg_val = "0"
e = ET.SubElement(re, arg_name)
if typed and arg_type:
if not isinstance(type, ET.QName):
arg_type = ET.QName("http://www.w3.org/1999/XMLSchema", arg_type)
e.set(NS_XSI + "type", arg_type)
e.text = arg_val
else:
if arguments == None:
arguments = {}
re.append(arguments)
preamble = """<?xml version="1.0" encoding="utf-8"?>"""
return preamble + ET.tostring(envelope, "utf-8")
示例10: fromElement
# 需要导入模块: from coherence.extern.et import ET [as 别名]
# 或者: from coherence.extern.et.ET import tostring [as 别名]
def fromElement(self, elt):
"""
TODO:
* creator
* writeStatus
"""
self.elementName = elt.tag
self.id = elt.attrib.get('id',None)
self.parentID = elt.attrib.get('parentID',None)
self.refID = elt.attrib.get('refID',None)
if elt.attrib.get('restricted',None) in [1,'true','True','1','yes','Yes']:
self.restricted = True
else:
self.restricted = False
for child in elt.getchildren():
if child.tag.endswith('title'):
self.title = child.text
elif child.tag.endswith('albumArtURI'):
self.albumArtURI = child.text
elif child.tag.endswith('originalTrackNumber'):
self.originalTrackNumber = int(child.text)
elif child.tag.endswith('description'):
self.description = child.text
elif child.tag.endswith('longDescription'):
self.longDescription = child.text
elif child.tag.endswith('artist'):
self.artist = child.text
elif child.tag.endswith('genre'):
if self.genre != None:
if self.genres == None:
self.genres = [self.genre,]
self.genres.append(child.text)
self.genre = child.text
elif child.tag.endswith('album'):
self.album = child.text
elif child.tag.endswith('class'):
self.upnp_class = child.text
elif child.tag.endswith('server_uuid'):
self.server_uuid = child.text
elif child.tag.endswith('res'):
res = Resource.fromString(ET.tostring(child))
self.res.append(res)
示例11: fromElement
# 需要导入模块: from coherence.extern.et import ET [as 别名]
# 或者: from coherence.extern.et.ET import tostring [as 别名]
def fromElement(self, elt):
"""
TODO:
* creator
* writeStatus
"""
self.elementName = elt.tag
self.id = elt.attrib.get("id", None)
self.parentID = elt.attrib.get("parentID", None)
self.refID = elt.attrib.get("refID", None)
if elt.attrib.get("restricted", None) in [1, "true", "True", "1", "yes", "Yes"]:
self.restricted = True
else:
self.restricted = False
for child in elt.getchildren():
if child.tag.endswith("title"):
self.title = child.text
elif child.tag.endswith("albumArtURI"):
self.albumArtURI = child.text
elif child.tag.endswith("originalTrackNumber"):
self.originalTrackNumber = int(child.text)
elif child.tag.endswith("description"):
self.description = child.text
elif child.tag.endswith("longDescription"):
self.longDescription = child.text
elif child.tag.endswith("artist"):
self.artist = child.text
elif child.tag.endswith("album"):
self.album = child.text
elif child.tag.endswith("class"):
self.upnp_class = child.text
elif child.tag.endswith("server_uuid"):
self.server_uuid = child.text
elif child.tag.endswith("res"):
res = Resource.fromString(ET.tostring(child))
self.res.append(res)
示例12: upnp_X_GetFeatureList
# 需要导入模块: from coherence.extern.et import ET [as 别名]
# 或者: from coherence.extern.et.ET import tostring [as 别名]
def upnp_X_GetFeatureList(self,**kwargs):
Log.w()
attrib = {
"xmlns" : "urn:schemas-upnp-org:av:avs",
"xmlns:xsi" : "http://www.w3.org/2001/XMLSchema-instance",
"xsi:schemaLocation" : "urn:schemas-upnp-org:av:avs http://www.upnp.org/schemas/av/avs.xsd"
}
features = ET.Element("Features")
features.attrib.update(attrib)
attrib = {
"name" : "samsung.com_BASICVIEW",
"version" : "1"
}
feature = ET.SubElement(features, "Feature")
feature.attrib.update(attrib)
#audio/video container id definition
tag = ET.SubElement(feature, "container")
tag.attrib.update({ "type": DIDLLite.AudioItem.upnp_class, "id" : str(self._audio.get_id()) })
tag = ET.SubElement(feature, "container")
tag.attrib.update({ "type": DIDLLite.VideoItem.upnp_class, "id" : str(self._video.get_id()) })
return {"FeatureList" : ET.tostring(features, "utf-8")}
示例13: button_action
# 需要导入模块: from coherence.extern.et import ET [as 别名]
# 或者: from coherence.extern.et.ET import tostring [as 别名]
def button_action(self, widget, event):
x = int(event.x)
y = int(event.y)
path = self.treeview.get_path_at_pos(x, y)
if path == None:
return True
row_path,column,_,_ = path
if event.button == 3:
clipboard = Gtk.clipboard_get(Gdk.SELECTION_CLIPBOARD)
iter = self.store.get_iter(row_path)
menu = Gtk.Menu()
item = Gtk.MenuItem("copy value")
value,= self.store.get(iter,4)
item.connect("activate", lambda w: clipboard.set_text(value))
menu.append(item)
item = Gtk.MenuItem("copy raw event")
raw,= self.store.get(iter,5)
try:
from coherence.extern.et import ET, indent, parse_xml
xml = parse_xml(raw)
xml = xml.getroot()
indent(xml,0)
raw = ET.tostring(xml, encoding='utf-8')
except:
import traceback
print traceback.format_exc()
item.connect("activate", lambda w: clipboard.set_text(raw))
menu.append(item)
menu.show_all()
menu.popup(None,None,None,event.button,event.time)
return True
return False
示例14: build_last_change_event
# 需要导入模块: from coherence.extern.et import ET [as 别名]
# 或者: from coherence.extern.et.ET import tostring [as 别名]
def build_last_change_event(self, instance=0, force=False):
got_one = False
root = ET.Element('Event')
root.attrib['xmlns']=self.event_metadata
for instance, vdict in self._variables.items():
e = ET.SubElement( root, 'InstanceID')
e.attrib['val']=str(instance)
for variable in vdict.values():
if( variable.name != 'LastChange' and
variable.name[0:11] != 'A_ARG_TYPE_' and
variable.never_evented == False and
(variable.updated == True or force == True)):
s = ET.SubElement( e, variable.name)
s.attrib['val'] = str(variable.value)
variable.updated = False
got_one = True
if variable.dependant_variable != None:
dependants = variable.dependant_variable.get_allowed_values()
if dependants != None and len(dependants) > 0:
s.attrib['channel']=dependants[0]
if got_one == True:
return ET.tostring( root, encoding='utf-8')
else:
return None
示例15: build_single_notification
# 需要导入模块: from coherence.extern.et import ET [as 别名]
# 或者: from coherence.extern.et.ET import tostring [as 别名]
def build_single_notification(self, instance, variable_name, value):
root = ET.Element('e:propertyset')
root.attrib['xmlns:e']='urn:schemas-upnp-org:event-1-0'
e = ET.SubElement( root, 'e:property')
s = ET.SubElement( e, variable_name).text = str(value)
return ET.tostring( root, encoding='utf-8')