本文整理汇总了Python中rdflib.py3compat.b函数的典型用法代码示例。如果您正苦于以下问题:Python b函数的具体用法?Python b怎么用?Python b使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了b函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: to_key
def to_key(triple, context):
"Takes a string; returns key"
return b("^").join(
(context,
triple[i % 3],
triple[(i + 1) % 3],
triple[(i + 2) % 3], b(""))) # "" to tac on the trailing ^
开发者ID:3mcorp,项目名称:schemaorg,代码行数:7,代码来源:sleepycat.py
示例2: test_result_fragments
def test_result_fragments(self):
rdfXml = serialize(self.sourceGraph, self.serializer)
assert b('<Test rdf:about="http://example.org/data/a">') in rdfXml
assert b('<rdf:Description rdf:about="http://example.org/data/b">') in rdfXml
assert b('<name xml:lang="en">Bee</name>') in rdfXml
assert b('<value rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">3</value>') in rdfXml
assert b('<BNode rdf:nodeID="') in rdfXml, "expected one identified bnode in serialized graph"
开发者ID:Dataliberate,项目名称:rdflib,代码行数:7,代码来源:test_prettyxml.py
示例3: testFinalNewline
def testFinalNewline():
"""
http://code.google.com/p/rdflib/issues/detail?id=5
"""
import sys
import platform
if getattr(sys, 'pypy_version_info', None) or platform.system() == 'Java':
from nose import SkipTest
raise SkipTest(
'Testing under pypy and Jython2.5 fails to detect that ' + \
'IOMemory is a context_aware store')
graph=Graph()
graph.add((URIRef("http://ex.org/a"),
URIRef("http://ex.org/b"),
URIRef("http://ex.org/c")))
failed = set()
for p in rdflib.plugin.plugins(None, rdflib.plugin.Serializer):
if p.name not in ( 'nquads', 'trix' ):
v = graph.serialize(format=p.name)
lines = v.split(b("\n"))
if b("\n") not in v or (lines[-1]!=b('')):
failed.add(p.name)
assert len(failed)==0, "No final newline for formats: '%s'" % failed
开发者ID:alexsdutton,项目名称:rdflib,代码行数:25,代码来源:test_finalnewline.py
示例4: test_result_fragments_with_base
def test_result_fragments_with_base(self):
rdfXml = serialize(self.sourceGraph, self.serializer,
extra_args={'base':"http://example.org/", 'xml_base':"http://example.org/"})
assert b('xml:base="http://example.org/"') in rdfXml
assert b('<Test rdf:about="data/a">') in rdfXml
assert b('<rdf:Description rdf:about="data/b">') in rdfXml
assert b('<value rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">3</value>') in rdfXml
assert b('<BNode rdf:nodeID="') in rdfXml, "expected one identified bnode in serialized graph"
开发者ID:Dataliberate,项目名称:rdflib,代码行数:8,代码来源:test_prettyxml.py
示例5: test_validating_unquote_raises
def test_validating_unquote_raises(self):
ntriples.validate = True
uniquot = b("""<http://www.w3.org/People/Berners-Lee/card#cm> <http://xmlns.com/foaf/0.1/name> "R\\u00E4ksm\\u00F6rg\\u00E5s" <http://www.w3.org/People/Berners-Lee/card> .""")
self.assertRaises(ntriples.ParseError, ntriples.unquote, uniquot)
uniquot = b("""<http://www.w3.org/People/Berners-Lee/card#cm> <http://xmlns.com/foaf/0.1/name> "R\\\\u00E4ksm\\u00F6rg\\u00E5s" <http://www.w3.org/People/Berners-Lee/card> .""")
self.assertRaises(ntriples.ParseError, ntriples.unquote, uniquot)
# revert to default
ntriples.validate = False
开发者ID:afujii,项目名称:rdflib,代码行数:8,代码来源:test_nt_misc.py
示例6: remove
def remove(self, triple, context):
(subject, predicate, object) = triple
assert self.__open, "The Store must be open."
Store.remove(self, (subject, predicate, object), context)
_to_string = self._to_string
if context is not None:
if context == self:
context = None
if subject is not None \
and predicate is not None \
and object is not None \
and context is not None:
s = _to_string(subject)
p = _to_string(predicate)
o = _to_string(object)
c = _to_string(context)
value = self.__indices[0].get(bb("%s^%s^%s^%s^" % (c, s, p, o)))
if value is not None:
self.__remove((bb(s), bb(p), bb(o)), bb(c))
self.__needs_sync = True
else:
cspo, cpos, cosp = self.__indices
index, prefix, from_key, results_from_key = self.__lookup(
(subject, predicate, object), context)
needs_sync = False
for key in index.match_prefix(prefix):
c, s, p, o = from_key(key)
if context is None:
contexts_value = index.get(key) or b("")
# remove triple from all non quoted contexts
contexts = set(contexts_value.split(b("^")))
contexts.add(b("")) # and from the conjunctive index
for c in contexts:
for i, _to_key, _ in self.__indices_info:
i.remove(_to_key((s, p, o), c))
else:
self.__remove((s, p, o), c)
needs_sync = True
if context is not None:
if subject is None and predicate is None and object is None:
# TODO: also if context becomes empty and not just on
# remove((None, None, None), c)
try:
self.__contexts.remove(bb(_to_string(context)))
# except db.DBNotFoundError, e:
# pass
except Exception as e: # pragma: NO COVER
print("%s, Failed to delete %s" % (
e, context)) # pragma: NO COVER
pass # pragma: NO COVER
self.__needs_sync = needs_sync
开发者ID:RDFLib,项目名称:rdflib-kyotocabinet,代码行数:54,代码来源:KyotoCabinet.py
示例7: test_turtle_namespace_prefixes
def test_turtle_namespace_prefixes(self):
g = ConjunctiveGraph()
n3 = \
"""
@prefix _9: <http://data.linkedmdb.org/resource/movie/> .
@prefix p_9: <urn:test:> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
p_9:a p_9:b p_9:c .
<http://data.linkedmdb.org/resource/director/1> a
<http://data.linkedmdb.org/resource/movie/director>;
rdfs:label "Cecil B. DeMille (Director)";
_9:director_name "Cecil B. DeMille" ."""
g.parse(data=n3, format='n3')
turtle = g.serialize(format="turtle")
# Check round-tripping, just for kicks.
g = ConjunctiveGraph()
g.parse(data=turtle, format='turtle')
# Shouldn't have got to here
s=g.serialize(format="turtle")
self.assert_(b('@prefix _9') not in s)
开发者ID:Dataliberate,项目名称:rdflib,代码行数:27,代码来源:test_issue161.py
示例8: unquote
def unquote(s):
"""Unquote an N-Triples string."""
if not validate:
return s.decode('unicode-escape')
else:
result = []
while s:
m = r_safe.match(s)
if m:
s = s[m.end():]
result.append(m.group(1).decode('ascii'))
continue
m = r_quot.match(s)
if m:
s = s[2:]
result.append(quot[m.group(1)])
continue
m = r_uniquot.match(s)
if m:
s = s[m.end():]
u, U = m.groups()
codepoint = int(u or U, 16)
if codepoint > 0x10FFFF:
raise ParseError("Disallowed codepoint: %08X" % codepoint)
result.append(unichr(codepoint))
elif s.startswith(b('\\')):
raise ParseError("Illegal escape at: %s..." % s[:10])
else: raise ParseError("Illegal literal character: %r" % s[0])
return u''.join(result)
开发者ID:EmuxEvans,项目名称:SmartObject,代码行数:31,代码来源:ntriples.py
示例9: test_issue_130
def test_issue_130():
g = rdflib.Graph()
try:
g.parse(location="http://linked-data.ru/example")
except:
raise SkipTest('Test data URL unparseable')
assert b('rdf:about="http://semanticfuture.net/linked-data/example/#company"') in g.serialize(), g.serialize()
开发者ID:d3vgru,项目名称:rdflib,代码行数:7,代码来源:test_issue_130.py
示例10: test_nonvalidating_unquote
def test_nonvalidating_unquote(self):
safe = b(
"""<http://example.org/alice/foaf.rdf#me> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> <http://example.org/alice/foaf1.rdf> ."""
)
ntriples.validate = False
res = ntriples.unquote(safe)
self.assert_(isinstance(res, unicode))
开发者ID:gperasso,项目名称:rdflib,代码行数:7,代码来源:test_ntparse.py
示例11: uriref
def uriref(self):
if self.peek(b('<')):
uri = self.eat(r_uriref).group(1)
uri = unquote(uri)
uri = uriquote(uri)
return URI(uri)
return False
开发者ID:EmuxEvans,项目名称:SmartObject,代码行数:7,代码来源:ntriples.py
示例12: test_validating_unquote
def test_validating_unquote(self):
quot = b("""<http://example.org/alice/foaf.rdf#me> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> <http://example.org/alice/foaf1.rdf> .""")
ntriples.validate = True
res = ntriples.unquote(quot)
# revert to default
ntriples.validate = False
log.debug("restype %s" % type(res))
开发者ID:afujii,项目名称:rdflib,代码行数:7,代码来源:test_nt_misc.py
示例13: __len__
def __len__(self, context=None):
assert self.__open, "The Store must be open."
if context is not None:
if context == self:
context = None
if context is None:
prefix = b("^")
else:
prefix = bb("%s^" % self._to_string(context))
index = self.__indicies[0]
cursor = index.cursor()
current = cursor.set_range(prefix)
count = 0
while current:
key, value = current
if key.startswith(prefix):
count += 1
# Hack to stop 2to3 converting this to next(cursor)
current = getattr(cursor, 'next')()
else:
break
cursor.close()
return count
开发者ID:3mcorp,项目名称:schemaorg,代码行数:25,代码来源:sleepycat.py
示例14: contexts
def contexts(self, triple=None):
_from_string = self._from_string
_to_string = self._to_string
if triple:
s, p, o = triple
s = _to_string(s)
p = _to_string(p)
o = _to_string(o)
contexts = self.__indicies[0].get(bb(
"%s^%s^%s^%s^" % ("", s, p, o)))
if contexts:
for c in contexts.split(b("^")):
if c:
yield _from_string(c)
else:
index = self.__contexts
cursor = index.cursor()
current = cursor.first()
cursor.close()
while current:
key, value = current
context = _from_string(key)
yield context
cursor = index.cursor()
try:
cursor.set_range(key)
# Hack to stop 2to3 converting this to next(cursor)
current = getattr(cursor, 'next')()
except db.DBNotFoundError:
current = None
cursor.close()
开发者ID:3mcorp,项目名称:schemaorg,代码行数:32,代码来源:sleepycat.py
示例15: from_key
def from_key(key):
"Takes a key; returns string"
parts = key.split(b("^"))
return \
parts[0], \
parts[(3 - i + 0) % 3 + 1], \
parts[(3 - i + 1) % 3 + 1], \
parts[(3 - i + 2) % 3 + 1]
开发者ID:3mcorp,项目名称:schemaorg,代码行数:8,代码来源:sleepycat.py
示例16: from_key
def from_key(key, subject, predicate, object, contexts_value):
"Takes a key and subject, predicate, object; returns tuple for yield"
parts = key.split(b("^"))
if subject is None:
# TODO: i & 1: # dis assemble and/or measure to see which is faster
# subject is None or i & 1
s = from_string(parts[(3-i+0)%3+1])
else:
s = subject
if predicate is None:#i & 2:
p = from_string(parts[(3-i+1)%3+1])
else:
p = predicate
if object is None:#i & 4:
o = from_string(parts[(3-i+2)%3+1])
else:
o = object
return (s, p, o), (from_string(c) for c in contexts_value.split(b("^")) if c)
开发者ID:SpazioDati,项目名称:rdflib,代码行数:18,代码来源:sleepycat.py
示例17: test_n32
def test_n32(self):
# this test not generating prefixes for subjects/objects
g = Graph()
g.add((URIRef("http://example1.com/foo"),
URIRef("http://example2.com/bar"),
URIRef("http://example3.com/baz")))
n3 = g.serialize(format="n3")
self.assertTrue(b("<http://example1.com/foo> ns1:bar <http://example3.com/baz> .") in n3)
开发者ID:dbs,项目名称:rdflib,代码行数:9,代码来源:test_namespace.py
示例18: setUp
def setUp(self):
NS = u"http://example.org/"
self.graph = Graph(store)
self.graph.parse(StringInputSource(b("""
@prefix : <http://example.org/> .
@prefix rdf: <%s> .
@prefix rdfs: <%s> .
[ :prop :val ].
[ a rdfs:Class ]."""%(RDF,RDFS))), format="n3")
开发者ID:RDFLib,项目名称:rdfextras,代码行数:9,代码来源:test_short_forms.py
示例19: testBaseSerialize
def testBaseSerialize(self):
g = Graph()
g.add((URIRef('http://example.com/people/Bob'), URIRef(
'urn:knows'), URIRef('http://example.com/people/Linda')))
s = g.serialize(base='http://example.com/', format='n3')
self.assertTrue(b('<people/Bob>') in s)
g2 = ConjunctiveGraph()
g2.parse(data=s, publicID='http://example.com/', format='n3')
self.assertEqual(list(g), list(g2))
开发者ID:cnh,项目名称:rdflib,代码行数:9,代码来源:test_n3.py
示例20: serialize
def serialize(self, stream, base=None, encoding=None, **args):
if base is not None:
warnings.warn("YTSerializer does not support base.")
if encoding is not None:
warnings.warn("YTSerializer does not use custom encoding.")
encoding = self.encoding
for triple in self.store:
stream.write(_yt_row(triple).encode(encoding, "replace"))
stream.write(b("\n"))
开发者ID:cbeer,项目名称:rdflib-ytriples,代码行数:9,代码来源:yt.py
注:本文中的rdflib.py3compat.b函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论