Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def uri_string(self):
""" The fully resolved URI string for this target.
:rtype: string
"""
if isinstance(self.entity, int):
uri_string = "{{{0}}}".format(self.entity)
elif isinstance(self.entity, NodePointer):
uri_string = "{{{0}}}".format(self.entity.address)
else:
try:
uri_string = self.entity.ref
except AttributeError:
uri_string = ustr(self.entity)
if self.segments:
if not uri_string.endswith("/"):
uri_string += "/"
uri_string += "/".join(map(percent_encode, self.segments))
return uri_string
def apply(x):
if isinstance(x, dict):
inst.update(x)
elif is_collection(x):
for item in x:
apply(item)
elif isinstance(x, string):
inst.labels().add(ustr(x))
else:
raise TypeError("Cannot cast %s to Node" % obj.__class__.__name__)
def write_literal(self, text):
""" Write literal text.
:arg text:
"""
self.file.write(ustr(text))
def _(*args):
return "".join("_" + ustr(arg) for arg in args)
def _(*args):
return "".join("_" + ustr(arg) for arg in args)
def _delete_path(self, path, name):
for i, rel in enumerate(path.relationships()):
self._delete_relationship(rel, name + "r" + ustr(i))
for i, node in enumerate(path.nodes()):
self._delete_node(node, name + "n" + ustr(i))
def write_identifier(self, identifier):
""" Write an identifier.
"""
if not identifier:
raise ValueError("Invalid identifier")
identifier = ustr(identifier)
safe = (identifier[0] in self.safe_first_chars and
all(ch in self.safe_chars for ch in identifier[1:]))
if not safe:
self.file.write("`")
self.file.write(identifier.replace("`", "``"))
self.file.write("`")
else:
self.file.write(identifier)
def write_literal(self, text):
""" Write literal text.
"""
self.file.write(ustr(text))