本文整理汇总了Python中pyasm.common.Xml.get_node方法的典型用法代码示例。如果您正苦于以下问题:Python Xml.get_node方法的具体用法?Python Xml.get_node怎么用?Python Xml.get_node使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyasm.common.Xml
的用法示例。
在下文中一共展示了Xml.get_node方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_plugin_data
# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import get_node [as 别名]
def get_plugin_data(my, reldir):
manifest_path = "%s/%s/manifest.xml" % (my.base_dir, reldir)
xml = Xml()
xml.read_file(manifest_path)
node = xml.get_node("manifest/data")
data = xml.get_node_values_of_children(node)
return data
示例2: get_plugins_data
# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import get_node [as 别名]
def get_plugins_data(my, plugin_type=None):
plugins_data = {}
for root, dirnames, basenames in os.walk(my.base_dir):
reldir = root.replace(my.base_dir + "/", "")
if "manifest.xml" in basenames:
manifest_path = "%s/manifest.xml" % root
xml = Xml()
xml.read_file(manifest_path)
node = xml.get_node("manifest/data")
data = xml.get_node_values_of_children(node)
if plugin_type and not data.get("type") == plugin_type:
continue
plugins_data[reldir] = data
return plugins_data
示例3: get_widget_from_hash
# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import get_node [as 别名]
def get_widget_from_hash(cls, hash, return_none=False, force_no_index=False, kwargs={}):
from pyasm.web import DivWdg
if hash.startswith("//"):
use_top = False
hash = hash[1:]
else:
use_top = True
import re
p = re.compile("^/(\w+)")
m = p.search(hash)
if not m:
if return_none:
return None
print "Cannot parse hash[%s]" % hash
return DivWdg("Cannot parse hash [%s]" % hash)
key = m.groups()[0]
# guest user should never be able to see admin site
if key != 'login':
security = Environment.get_security()
login = security.get_user_name()
if login == "guest" and key == 'admin':
from pyasm.widget import Error403Wdg
return Error403Wdg().get_buffer_display()
sobject = cls._get_predefined_url(key, hash)
# look up the url
if not sobject:
search = Search("config/url")
search.add_filter("url", "/%s/%%"%key, "like")
search.add_filter("url", "/%s"%key)
search.add_where("or")
sobject = search.get_sobject()
if not sobject:
if return_none:
return None
return DivWdg("No Widget found for hash [%s]" % hash)
config = sobject.get_value("widget")
config = config.replace('&','&')
url = sobject.get_value("url")
url = url.strip()
# update the config value with expressions
options = Common.extract_dict(hash, url)
for name, value in options.items():
config = config.replace("{%s}" % name, value)
xml = Xml()
xml.read_string(config)
use_index, use_admin, use_sidebar = cls._get_flags(xml, sobject, force_no_index, kwargs)
if use_admin:
# use admin
from tactic.ui.app import PageNavContainerWdg
top = PageNavContainerWdg( hash=hash, use_sidebar=use_sidebar )
return top.get_buffer_display()
elif use_index:
# check if there is an index
search = Search("config/url")
search.add_filter("url", "/index")
index = search.get_sobject()
# just use admin if no index page is found
if not index:
from tactic.ui.app import PageNavContainerWdg
top = PageNavContainerWdg( hash=hash, use_sidebar=use_sidebar )
return top.get_buffer_display()
config = index.get_value("widget")
xml = Xml()
xml.read_string(config)
node = xml.get_node("element/display")
options.update(xml.get_node_values_of_children(node))
class_name = xml.get_value("element/display/@class")
if class_name:
options['class_name'] = class_name
# this passes the hash value to the index widget
# which must handle it accordingly
options['hash'] = hash
top = cls.build_widget(options)
return top.get_buffer_display()
#.........这里部分代码省略.........
示例4: get_text
# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import get_node [as 别名]
def get_text(self, path, last_path=None, highlight=True):
if path.startswith("http"):
if path.startswith("https://docs.google.com/document"):
# NOTE: this is very specific to google docs
if not path.endswith("?embedded=true"):
path = "%s?embedded=true" % path
is_html = True
else:
is_html = False
import urllib2
response = urllib2.urlopen(path)
html = response.read()
fix = '''<meta content="text/html; charset=UTF-8" http-equiv="content-type">'''
html = html.replace(fix, "")
html = html.replace("&", "&")
if is_html:
xml = Xml()
try:
xml.read_string(html)
except:
self.doc_mode = "formatted"
html = html.replace("&", "&")
print
print "WARNING: cannot parse as XML"
print
return html
if self.doc_mode == "formatted":
return xml.to_string().replace("&", "&")
node = xml.get_node("html/body")
text = xml.to_string(node)
text = text.replace("<body", "<div style='margin: 0px'")
text = text.replace("</body>", "</div>")
text = text.replace("&", "&")
else:
text = html
lines2 = []
lines = text.split("\n")
for line in lines:
tmp_line = line.strip()
if tmp_line.startswith("<span"):
tmp_line = tmp_line.replace("<span>", "")
tmp_line = tmp_line.replace("</span>", "")
tmp_line = tmp_line.replace("<span/>", "")
elif tmp_line.startswith("<p "):
continue
elif tmp_line.startswith("</p>"):
continue
# FIXME: there has to be a function to do this
tmp_line = tmp_line.replace(" ", "")
tmp_line = tmp_line.replace(""", '"')
tmp_line = tmp_line.replace("'", "'")
lines2.append(tmp_line)
text = "\n".join(lines2)
#print 'text', text
#import html2text
#text = html2text.html2text(html)
# clear out any remaining html tags
import re
text = re.sub('<[^<]+?>', '', text)
else:
f = open(path)
lines = f.readlines()
f.close()
#f = open(path)
#lines2 = f.readlines()
#f.close()
#diff = self.get_diff(lines, lines2)
#text = "".join(diff)
text = "".join(lines)
# read last text if it exists
if last_path and os.path.exists(last_path):
#.........这里部分代码省略.........
示例5: get_widget_from_hash
# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import get_node [as 别名]
#.........这里部分代码省略.........
search = Search("config/url")
search.add_filter("url", "/%s/%%"%key, "like")
search.add_filter("url", "/%s"%key)
search.add_where("or")
sobject = search.get_sobject()
if not sobject:
if return_none:
return None
return DivWdg("No Widget found for hash [%s]" % hash)
config = sobject.get_value("widget")
config = config.replace('&','&')
url = sobject.get_value("url")
url = url.strip()
# update the config value with expressions
options = Common.extract_dict(hash, url)
for name, value in options.items():
config = config.replace("{%s}" % name, value)
xml = Xml()
xml.read_string(config)
use_index, use_admin, use_sidebar = cls._get_flags(xml, sobject, force_no_index, kwargs)
# add the admin bar
security = Environment.get_security()
is_admin = security.check_access("builtin", "view_site_admin", "allow")
if is_admin and use_admin:
# use admin
from tactic.ui.app import PageNavContainerWdg
top = PageNavContainerWdg( hash=hash, use_sidebar=use_sidebar )
return top.get_buffer_display()
elif use_index:
# check if there is an index
search = Search("config/url")
search.add_filter("url", "/index")
index = search.get_sobject()
# just use admin if no index page is found
if not index:
from tactic.ui.app import PageNavContainerWdg
top = PageNavContainerWdg( hash=hash, use_sidebar=use_sidebar )
return top.get_buffer_display()
config = index.get_value("widget")
xml = Xml()
xml.read_string(config)
node = xml.get_node("element/display")
options.update(xml.get_node_values_of_children(node))
class_name = xml.get_value("element/display/@class")
if class_name:
options['class_name'] = class_name
# this passes the hash value to the index widget
# which must handle it accordingly
options['hash'] = hash
top = cls.build_widget(options)
return top.get_buffer_display()
# process the options and then build the widget from the xml
options = Common.extract_dict(hash, url)
for name, value in kwargs.items():
options[name] = value
node = xml.get_node("element/display")
options.update(xml.get_node_values_of_children(node))
class_name = xml.get_value("element/display/@class")
if class_name:
options['class_name'] = class_name
widget = cls.build_widget(options)
name = hash.lstrip("/")
name_array = name.split("/")
if name_array:
name_end = name_array[-1]
name_end = name_end.replace("_", " ")
widget.set_name(name_end)
else:
widget.set_name(name)
return widget
示例6: get_display
# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import get_node [as 别名]
def get_display(my):
my.kwargs['search_key'] = 'prod/asset?project=sample3d&code=chr001'
custom = """<?xml version='1.0' encoding='UTF-8'?>
<custom>
<html>
<div>
This is html
<textarea class='spt_test spt_input' name='description'>
</textarea>
<input class='spt_input' type='text' name='title'/>
<br/>
<input class='spt_button1' type='button' value='Press Me'/>
<input class='spt_button2' type='button' value='Press Me2'/>
<input class='spt_button3' type='button' value='Calendar'/>
<input class='spt_refresh' type='button' value='Refresh'/>
<element>
<display class='tactic.ui.widget.CalendarWdg'/>
</element>
Much simpler!!!
<elemeent class='CalendarWdg' blah='adasf'/>
</div>
</html>
<behavior class='spt_button1'>{
"type": "click_up",
"cbjs_action": '''
app.mel('sphere');
//var top = bvr.src_el.getParent(".spt_panel");
//var values = spt.api.Utility.get_input_values(top);
//console.log(values);
'''
}</behavior>
<behavior class='spt_button2'>{
"type": "click_up",
"cbjs_action": "alert(bvr.kwargs.search_key);"
}</behavior>
<behavior class='spt_button3'>{
"type": "click_up",
"cbjs_action": '''
spt.panel.load('main_body', bvr.class_name, bvr.kwargs);
//spt.panel.load('main_body', 'tactic.ui.widget.CalendarWdg', bvr.kwargs);
'''
}</behavior>
<behavior class='spt_refresh'>{
"type": "click_up",
"cbjs_action": '''
var top = bvr.src_el.getParent(".spt_panel");
spt.panel.refresh(top);
'''
}</behavior>
</custom>
"""
xml = Xml()
xml.read_string(custom)
top = DivWdg()
my.set_as_panel(top)
top.add_class("spt_panel")
inner = DivWdg()
top.add(inner)
html_node = xml.get_node("custom/html")
html = xml.to_string(html_node)
inner.add(html)
behaviors = xml.get_nodes("custom/behavior")
for behavior in behaviors:
css_class = Xml.get_attribute(behavior, 'class')
value = Xml.get_node_value(behavior)
value = eval(value)
# add the kwargs to this so behaviors have access
value['kwargs'] = my.kwargs
value['class_name'] = Common.get_full_class_name(my)
inner.add_behavior({
'type': 'load',
'value': value,
'css_class': css_class,
'cbjs_action': '''
var el = bvr.src_el.getElement("."+bvr.css_class);
if (!el) {
alert("WARNING: element ["+bvr.css_clsss+"] does not exist");
}
spt.behavior.add( el, bvr.value);
'''
})
#.........这里部分代码省略.........
示例7: PageNavContainerWdg
# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import get_node [as 别名]
#.........这里部分代码省略.........
</config>
'''
else:
config = '''
<config>
<application>
<element name="left_nav">
<display class="tactic.ui.panel.SideBarPanelWdg">
<auto_size>True</auto_size>
</display>
</element>
<element name="main_body">
<display class="tactic.ui.startup.MainWdg"/>
<web/>
</element>
</application>
</config>
'''
return config
def set_state(self, panel_name, widget_class, options, values):
'''this is called by side_bar.js mostly'''
# set the class name
display_node = self.config_xml.get_node("config/application/element[@name='%s']/display" % (panel_name) )
self.config_xml.set_attribute(display_node, "class", widget_class)
# remove all the old options
#display_node = self.config_xml.get_node("config/application/element[@name='%s']/display" % panel_name )
for child_node in self.config_xml.get_children(display_node):
self.config_xml.remove_child(display_node, child_node)
# set the options
for name, value in options.items():
node = self.config_xml.get_node("config/application/element[@name='%s']/display/%s" % (panel_name, name) )
if isinstance( value, basestring ):
#print("WARNING: set application: skipping [%s] with value [%s]" % (name, value))
#continue
element = self.config_xml.create_text_element(name, value)
self.config_xml.append_child(display_node, element)
elif isinstance( value, dict): # if it is a dictionary
# TODO: run recursively.. supports 2 level only now
sub_element = self.config_xml.create_element(name)
self.config_xml.append_child(display_node, element)
for name2, value2 in value.items():
if isinstance(value2, dict):
sub_element2 = self.config_xml.create_element(name2)
self.config_xml.append_child(sub_element, sub_element2)
for name3, value3 in value2.items():
element = self.config_xml.create_text_element(name3, value3)
self.config_xml.append_child(sub_element2, element)
else:
element = self.config_xml.create_text_element(name2, value2)
self.config_xml.append_child(sub_element, element)
示例8: get_widget_from_hashXX
# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import get_node [as 别名]
#.........这里部分代码省略.........
elif use_admin in [False, 'false']:
use_admin = False
use_sidebar = kwargs.get("use_sidebar")
if use_sidebar in [False, 'false']:
use_sidebar = False
elif use_admin in [True, 'true']:
use_sidebar = True
if use_index is not None or use_admin is not None:
pass
elif force_no_index in [True, 'true']:
use_index = False
else:
use_index = sobject.get_value("index", no_exception=True)
if not use_index:
use_index = xml.get_value("/element/@index");
if use_index in ['true', True]:
use_index = True
use_admin = sobject.get_value("admin", no_exception=True)
if not use_admin:
use_admin = xml.get_value("/element/@admin");
if use_admin in ['true', True]:
use_admin = True
use_sidebar = xml.get_value("/element/@sidebar");
if use_sidebar in ['false', False]:
use_sidebar = False
if use_index or use_admin:
# check if there is an index
search = Search("config/url")
search.add_filter("url", "/index")
index = search.get_sobject()
if not index or use_admin:
# use admin
from tactic.ui.app import PageNavContainerWdg
top = PageNavContainerWdg( hash=hash, use_sidebar=use_sidebar )
else:
config = index.get_value("widget")
xml = Xml()
xml.read_string(config)
node = xml.get_node("element/display")
options = {}
options.update(xml.get_node_values_of_children(node))
class_name = xml.get_value("element/display/@class")
if class_name:
options['class_name'] = class_name
# this passes the hash value to the index widget
# which must handle it accordingly
if key == "top":
hash = hash.replace("/top", "/tab")
options['hash'] = hash
top = cls.build_widget(options)
return top.get_buffer_display()
# build the widget
if key == "top":
class_name = 'tactic.ui.panel.HashPanelWdg'
options = {
"hash": hash.replace("/link", "/tab"),
"class_name": class_name
}
else:
url = sobject.get_value("url")
url = url.strip()
options = Common.extract_dict(hash, url)
for name, value in kwargs.items():
options[name] = value
node = xml.get_node("element/display")
options.update(xml.get_node_values_of_children(node))
class_name = xml.get_value("element/display/@class")
if class_name:
options['class_name'] = class_name
widget = cls.build_widget(options)
name = hash.lstrip("/")
name = name.replace("/", " ")
widget.set_name(name)
return widget