def __new__(cls, *args, **kwargs): try: exception = kwargs["exception"] error_cls = type(xstr(exception), (cls, ), {}) except KeyError: error_cls = cls return Exception.__new__(error_cls, *args)
def __new__(cls, *args, **kwargs): try: exception = kwargs["exception"] error_cls = type(xstr(exception), (cls,), {}) except KeyError: error_cls = cls return Exception.__new__(error_cls, *args)
def type(name): """ Return the :class:`.Relationship` subclass corresponding to a given name. :param name: relationship type name :returns: `type` object """ for s in Relationship.__subclasses__(): if s.__name__ == name: return s return type(xstr(name), (Relationship, ), {})
def type(name): """ Return the :class:`.Relationship` subclass corresponding to a given name. :param name: relationship type name :returns: `type` object Example:: >>> KNOWS = Relationship.type("KNOWS") >>> KNOWS(a, b) KNOWS(Node('Person', name='Alice'), Node('Person', name='Bob') """ for s in Relationship.__subclasses__(): if s.__name__ == name: return s return type(xstr(name), (Relationship, ), {})
def parse(cls, s, default_host=None, default_port=None): s = xstr(s) if s.startswith("["): # IPv6 host, _, port = s[1:].rpartition("]") port = port.lstrip(":") try: port = int(port) except (TypeError, ValueError): pass return cls((host or default_host or "localhost", port or default_port or 0, 0, 0)) else: # IPv4 host, _, port = s.partition(":") try: port = int(port) except (TypeError, ValueError): pass return cls((host or default_host or "localhost", port or default_port or 0))
def parse(cls, s, default_host=None, default_port=None): s = xstr(s) if not isinstance(s, str): raise TypeError("Address.parse requires a string argument") if s.startswith("["): # IPv6 host, _, port = s[1:].rpartition("]") port = port.lstrip(":") try: port = int(port) except (TypeError, ValueError): pass return cls((host or default_host or "localhost", port or default_port or 0, 0, 0)) else: # IPv4 host, _, port = s.partition(":") try: port = int(port) except (TypeError, ValueError): pass return cls((host or default_host or "localhost", port or default_port or 0))
def __str__(self): return xstr(cypher_repr(self))
def __str__(self): return xstr(self.__unicode__())