本文整理汇总了Python中pyff.utils.root函数的典型用法代码示例。如果您正苦于以下问题:Python root函数的具体用法?Python root怎么用?Python root使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了root函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_store_and_retrieve
def test_store_and_retrieve(self):
with patch.multiple("sys", exit=self.sys_exit, stdout=StreamCapturing(sys.stdout)):
tmpdir = tempfile.mkdtemp()
os.rmdir(tmpdir) # lets make sure 'store' can recreate it
try:
self.exec_pipeline("""
- load:
- file://%s/metadata/test01.xml
- select
- store:
directory: %s
""" % (self.datadir, tmpdir))
t1 = parse_xml(resource_filename("metadata/test01.xml", self.datadir))
assert t1 is not None
entity_id = 'https://idp.example.com/saml2/idp/metadata.php'
sha1id = hash_id(entity_id, prefix=False)
fn = "%s/%s.xml" % (tmpdir, sha1id)
assert os.path.exists(fn)
t2 = parse_xml(fn)
assert t2 is not None
assert root(t1).get('entityID') == root(t2).get('entityID')
assert root(t2).get('entityID') == entity_id
except IOError:
raise Skip
finally:
shutil.rmtree(tmpdir)
示例2: test_utils
def test_utils(self):
entity_id = root(self.t).get('entityID')
self.md.store.update(root(self.t), entity_id)
e = self.md.lookup(entity_id)[0]
assert (is_idp(e))
assert (not is_sp(e))
icon = entity_icon_url(e)
assert ('url' in icon)
assert ('https://www.example.com/static/images/umu_logo.jpg' in icon['url'])
assert ('width' in icon)
assert ('358' == icon['width'])
assert ('height' in icon)
assert ('63' == icon['height'])
assert ('62' != icon['height'])
domains = entity_domains(e)
assert ('example.com' in domains)
assert ('example.net' in domains)
assert ('idp.example.com' not in domains)
assert ('foo.com' not in domains)
edup = deepcopy(e)
name, desc = entity_extended_display(e)
assert(name == 'Example University')
assert(desc == 'Identity Provider for Example University')
disp = entity_display_name(e)
assert (disp == 'Example University')
for elt in e.findall(".//{%s}DisplayName" % NS['mdui']):
elt.getparent().remove(elt)
disp = entity_display_name(e)
assert (disp == 'The Example University')
for elt in e.findall(".//{%s}OrganizationDisplayName" % NS['md']):
elt.getparent().remove(elt)
disp = entity_display_name(e)
assert (disp == 'ExampleU')
for elt in e.findall(".//{%s}OrganizationName" % NS['md']):
elt.getparent().remove(elt)
disp = entity_display_name(e)
assert (disp == entity_id)
e = edup
subs = entity_domains(e)
assert ('example.com' in subs)
assert ('example.net' in subs)
assert ('idp.example.com' not in subs)
summary = entity_simple_summary(e)
assert (summary['title'] == 'Example University')
assert (summary['descr'] == 'Identity Provider for Example University')
assert (summary['entityID'] == entity_id)
assert ('domains' in summary)
assert ('id' in summary)
empty = entity_simple_summary(None)
assert (not empty)
示例3: test_entity_attribute
def test_entity_attribute(self):
entity_id = root(self.t).get('entityID')
self.md.set_entity_attributes(root(self.t), {"http://ns.example.org": "foo"})
self.md.store.update(root(self.t), entity_id)
e = self.md.lookup("{%s}%s" % ("http://ns.example.org", 'foo'))[0]
assert (e is not None)
assert (e.get('entityID') == entity_id)
示例4: test_first_select_as
def test_first_select_as(self):
with patch.multiple("sys", exit=self.sys_exit, stdout=StreamCapturing(sys.stdout)):
tmpfile = tempfile.NamedTemporaryFile('w').name
try:
self.exec_pipeline("""
- load:
- file://%s/metadata/test01.xml
- select as FOO
- first
- publish: %s
""" % (self.datadir, tmpfile))
t1 = parse_xml(resource_filename("metadata/test01.xml", self.datadir))
assert t1 is not None
entity_id = 'https://idp.example.com/saml2/idp/metadata.php'
t2 = parse_xml(tmpfile)
assert t2 is not None
assert root(t1).get('entityID') == root(t2).get('entityID')
assert root(t2).get('entityID') == entity_id
except PipeException:
pass
except IOError:
raise Skip
finally:
try:
os.unlink(tmpfile)
except:
pass
示例5: import_metadata
def import_metadata(self, t, url=None):
"""
:param t: An EntitiesDescriptor element
:param url: An optional URL to used to identify the EntitiesDescriptor in the MDRepository
Import an EntitiesDescriptor element using the @Name attribute (or the supplied url parameter). All
EntityDescriptor elements are stripped of any @ID attribute and are then indexed before the collection
is stored in the MDRepository object.
"""
if url is None:
top = t.xpath("//md:EntitiesDescriptor", namespaces=NS)
if top is not None and len(top) == 1:
url = top[0].get("Name", None)
if url is None:
raise ValueError("No collection name found")
self[url] = t
# we always clean incoming ID
# add to the index
ne = 0
if t is not None:
if root(t).tag == "{%s}EntityDescriptor" % NS['md']:
if root(t).attrib.has_key('ID'):
del root(t).attrib['ID']
self.index.add(root(t))
ne += 1
else:
for e in t.findall(".//{%s}EntityDescriptor" % NS['md']):
if e.attrib.has_key('ID'):
del e.attrib['ID']
self.index.add(e)
ne += 1
return ne
示例6: import_metadata
def import_metadata(self, t, url=None):
"""
:param t: An EntitiesDescriptor element
:param url: An optional URL to used to identify the EntitiesDescriptor in the MDRepository
Import an EntitiesDescriptor element using the @Name attribute (or the supplied url parameter). All
EntityDescriptor elements are stripped of any @ID attribute and are then indexed before the collection
is stored in the MDRepository object.
"""
if url is None:
top = t.xpath("//md:EntitiesDescriptor", namespaces=NS)
if top is not None and len(top) == 1:
url = top[0].get("Name", None)
if url is None:
raise MetadataException("No collection name found")
self[url] = t
# we always clean incoming ID
# add to the index
ne = 0
if t is not None:
if root(t).tag == "{%s}EntityDescriptor" % NS['md']:
self._index_entity(root(t))
ne += 1
else:
for e in t.findall(".//{%s}EntityDescriptor" % NS['md']):
self._index_entity(e)
ne += 1
self.fire(type=EVENT_IMPORTED_METADATA, size=ne, url=url)
return ne
示例7: test_utils
def test_utils(self):
entity_id = root(self.t).get("entityID")
self.md.store.update(root(self.t), entity_id)
e = self.md.lookup(entity_id)[0]
assert self.md.is_idp(e)
assert not self.md.is_sp(e)
assert self.md.icon(e) in [
"https://www.example.com/static/images/logo.jpg",
"https://www.example.com/static/images/logo_eng.jpg",
]
domains = self.md.domains(e)
assert "example.com" in domains
assert "example.net" in domains
assert "idp.example.com" in domains
assert "foo.com" not in domains
edup = deepcopy(e)
name, desc = self.md.ext_display(e)
assert name == "Example University"
assert desc == "Identity Provider for Example University"
disp = self.md.display(e)
assert disp == "Example University"
for elt in e.findall(".//{%s}DisplayName" % NS["mdui"]):
elt.getparent().remove(elt)
disp = self.md.display(e)
assert disp == "The Example University"
for elt in e.findall(".//{%s}OrganizationDisplayName" % NS["md"]):
elt.getparent().remove(elt)
disp = self.md.display(e)
assert disp == "ExampleU"
for elt in e.findall(".//{%s}OrganizationName" % NS["md"]):
elt.getparent().remove(elt)
disp = self.md.display(e)
assert disp == entity_id
e = edup
subs = self.md.sub_domains(e)
assert "example.com" in subs
assert "example.net" in subs
assert "idp.example.com" not in subs
summary = self.md.simple_summary(e)
assert summary["title"] == "Example University"
assert summary["descr"] == "Identity Provider for Example University"
assert summary["value"] == entity_id
assert "icon" in summary
assert "icon_url" in summary and summary["icon"] == summary["icon_url"]
assert "domains" in summary
assert "id" in summary
empty = self.md.simple_summary(None)
assert not empty
示例8: test_utils
def test_utils(self):
entity_id = root(self.t).get('entityID')
self.md.store.update(root(self.t), entity_id)
e = self.md.lookup(entity_id)[0]
assert (self.md.is_idp(e))
assert (not self.md.is_sp(e))
assert (self.md.icon(e) in ['https://www.example.com/static/images/logo.jpg',
'https://www.example.com/static/images/logo_eng.jpg'] )
domains = self.md.domains(e)
assert ('example.com' in domains)
assert ('example.net' in domains)
assert ('idp.example.com' not in domains)
assert ('foo.com' not in domains)
edup = deepcopy(e)
name, desc = self.md.ext_display(e)
assert(name == 'Example University')
assert(desc == 'Identity Provider for Example University')
disp = self.md.display(e)
assert (disp == 'Example University')
for elt in e.findall(".//{%s}DisplayName" % NS['mdui']):
elt.getparent().remove(elt)
disp = self.md.display(e)
assert (disp == 'The Example University')
for elt in e.findall(".//{%s}OrganizationDisplayName" % NS['md']):
elt.getparent().remove(elt)
disp = self.md.display(e)
assert (disp == 'ExampleU')
for elt in e.findall(".//{%s}OrganizationName" % NS['md']):
elt.getparent().remove(elt)
disp = self.md.display(e)
assert (disp == entity_id)
e = edup
subs = self.md.sub_domains(e)
assert ('example.com' in subs)
assert ('example.net' in subs)
assert ('idp.example.com' not in subs)
summary = self.md.simple_summary(e)
assert (summary['title'] == 'Example University')
assert (summary['descr'] == 'Identity Provider for Example University')
assert (summary['value'] == entity_id)
assert ('icon' in summary)
assert ('icon_url' in summary and summary['icon'] == summary['icon_url'])
assert ('domains' in summary)
assert ('id' in summary)
empty = self.md.simple_summary(None)
assert (not empty)
示例9: entities
def entities(self, t=None):
"""
:param t: An EntitiesDescriptor element
Returns the list of contained EntityDescriptor elements
"""
if t is None:
return []
elif root(t).tag == "{%s}EntityDescriptor" % NS['md']:
return [root(t)]
else:
return t.findall(".//{%s}EntityDescriptor" % NS['md'])
示例10: update
def update(self, t, tid=None, ts=None, merge_strategy=None):
# log.debug("memory store update: %s: %s" % (repr(t), tid))
relt = root(t)
assert (relt is not None)
ne = 0
if relt.tag == "{%s}EntityDescriptor" % NS['md']:
# log.debug("memory store setting entity descriptor")
self._unindex(relt)
self._index(relt)
self.entities[relt.get('entityID')] = relt # TODO: merge?
if tid is not None:
self.md[tid] = [relt.get('entityID')]
ne += 1
# log.debug("keys %s" % self.md.keys())
elif relt.tag == "{%s}EntitiesDescriptor" % NS['md']:
if tid is None:
tid = relt.get('Name')
lst = []
for e in iter_entities(t):
self.update(e)
lst.append(e.get('entityID'))
ne += 1
self.md[tid] = lst
return ne
示例11: test_replace_ndn
def test_replace_ndn(self):
idp = find_entity(root(self.t2), 'https://idp.nordu.net/idp/shibboleth')
assert (idp is not None)
idp2 = copy.deepcopy(idp)
assert idp2 is not None
for o in idp2.findall(".//{%s}OrganizationName" % NS['md']):
o.text = "FOO"
idp2.set('ID', 'kaka4711')
replace_existing(idp, idp2)
idp3 = find_entity(root(self.t2), 'kaka4711', attr='ID')
assert (idp3 is not None)
for o in idp2.findall(".//{%s}OrganizationName" % NS['md']):
assert (o.text == "FOO")
remove(idp3, None)
idp = find_entity(root(self.t2), 'kaka4711', attr='ID')
assert (idp3 is not None)
示例12: test_lookup_intersect_empty_test01
def test_lookup_intersect_empty_test01(self):
store = self._redis_store()
store.update(self.test01)
entity_id = root(self.test01).get('entityID')
assert (entity_id is not None)
e = store.lookup("{%s}%s+{%s}%s" % (ATTRS['domain'], 'example.com', ATTRS['role'], 'sp'))
assert (len(e) == 0)
示例13: test_display
def test_display(self):
swamid = root(self.swamid)
self.md.store.update(swamid, swamid.get('Name'))
funet_connect = self.md.lookup('https://connect.funet.fi/shibboleth')[0]
name, desc = self.md.ext_display(funet_connect)
assert(name == 'FUNET E-Meeting Service')
dn = self.md.display(funet_connect)
示例14: test_alias_ndn
def test_alias_ndn(self):
r = requests.get("http://127.0.0.1:%s/ndn.xml" % self.port)
assert r.status_code == 200
# assert (r.encoding == 'utf8')
t = parse_xml(StringIO(r.content))
assert t is not None
assert root(t).get("entityID") == "https://idp.nordu.net/idp/shibboleth"
validate_document(t)
示例15: test_alias_ndn
def test_alias_ndn(self):
r = requests.get("http://127.0.0.1:%s/ndn.xml" % self.port)
assert (r.status_code == 200)
# assert (r.encoding == 'utf8')
t = parse_xml(six.BytesIO(r.content))
assert (t is not None)
assert (root(t).get('entityID') == 'https://idp.nordu.net/idp/shibboleth')
validate_document(t)