2626from warnings import warn
2727
2828from neo4j .exceptions import ProtocolError , ServiceUnavailable
29- from neo4j .compat import urlparse , integer , string
29+ from neo4j .compat import urlparse
3030from neo4j .exceptions import CypherError , TransientError
3131from neo4j .config import default_config
3232
@@ -81,11 +81,6 @@ class GraphDatabase(object):
8181
8282 value_systems = {}
8383
84- @classmethod
85- def register_value_system (cls , value_system_class ):
86- if value_system_class .__name__ not in cls .value_systems :
87- cls .value_systems [value_system_class .__name__ ] = value_system_class ()
88-
8984 @classmethod
9085 def driver (cls , uri , ** config ):
9186 """ Acquire a :class:`.Driver` instance for the given URI and
@@ -638,167 +633,6 @@ def closed(self):
638633 return self ._closed
639634
640635
641- class Record (object ):
642- """ Record is an ordered collection of fields.
643-
644- A Record object is used for storing result values along with field names.
645- Fields can be accessed by numeric or named index (``record[0]`` or
646- ``record["field"]``).
647- """
648-
649- def __init__ (self , keys , values ):
650- self ._keys = tuple (keys )
651- self ._values = tuple (values )
652-
653- def __repr__ (self ):
654- values = self ._values
655- s = []
656- for i , field in enumerate (self ._keys ):
657- s .append ("%s=%r" % (field , values [i ]))
658- return "<%s %s>" % (self .__class__ .__name__ , " " .join (s ))
659-
660- def __hash__ (self ):
661- return hash (self ._keys ) ^ hash (self ._values )
662-
663- def __eq__ (self , other ):
664- try :
665- return (self ._keys == tuple (other .keys ()) and
666- self ._values == tuple (other .values ()))
667- except AttributeError :
668- return False
669-
670- def __ne__ (self , other ):
671- return not self .__eq__ (other )
672-
673- def __len__ (self ):
674- return len (self ._keys )
675-
676- def __getitem__ (self , item ):
677- if isinstance (item , string ):
678- return self ._values [self .index (item )]
679- elif isinstance (item , integer ):
680- return self ._values [item ]
681- else :
682- raise TypeError (item )
683-
684- def __iter__ (self ):
685- return iter (self ._keys )
686-
687- def __contains__ (self , key ):
688- try :
689- self .index (key )
690- except (IndexError , KeyError ):
691- return False
692- else :
693- return True
694-
695- def index (self , item ):
696- """ Return the index of the given item.
697- """
698- if isinstance (item , integer ):
699- if 0 <= item < len (self ._keys ):
700- return item
701- raise IndexError (item )
702- if isinstance (item , string ):
703- try :
704- return self ._keys .index (item )
705- except ValueError :
706- raise KeyError (item )
707- raise TypeError (item )
708-
709- def value (self , item = 0 , default = None ):
710- """ Obtain a single value from the record by index or key. If no
711- index or key is specified, the first value is returned. If the
712- specified item does not exist, the default value is returned.
713-
714- :param item:
715- :param default:
716- :return:
717- """
718- try :
719- index = self .index (item )
720- except (IndexError , KeyError ):
721- return default
722- else :
723- return self ._values [index ]
724-
725- def keys (self ):
726- """ Return the keys of the record.
727-
728- :return: tuple of key names
729- """
730- return self ._keys
731-
732- def values (self , * items ):
733- """ Return the values of the record, optionally filtering to
734- include only certain values by index or key.
735-
736- :param items: indexes or keys of the items to include; if none
737- are provided, all values will be included
738- :return: tuple of values
739- """
740- if items :
741- d = []
742- values = self ._values
743- for item in items :
744- try :
745- i = self .index (item )
746- except KeyError :
747- d .append (None )
748- else :
749- d .append (values [i ])
750- return tuple (d )
751- return self ._values
752-
753- def items (self , * items ):
754- """ Return the fields of the record as a list of key and value tuples
755-
756- :return:
757- """
758- if items :
759- d = []
760- keys = self ._keys
761- values = self ._values
762- for item in items :
763- try :
764- i = self .index (item )
765- except KeyError :
766- d .append ((item , None ))
767- else :
768- d .append ((keys [i ], values [i ]))
769- return d
770- return list (zip (self ._keys , self ._values ))
771-
772- def data (self , * items ):
773- """ Return the keys and values of this record as a dictionary,
774- optionally including only certain values by index or key. Keys
775- provided in the items that are not in the record will be
776- inserted with a value of :py:const:`None`; indexes provided
777- that are out of bounds will trigger an :py:`IndexError`.
778-
779- :param items: indexes or keys of the items to include; if none
780- are provided, all values will be included
781- :return: dictionary of values, keyed by field name
782- :raises: :py:`IndexError` if an out-of-bounds index is specified
783- """
784- if items :
785- d = {}
786- keys = self ._keys
787- values = self ._values
788- for item in items :
789- try :
790- i = self .index (item )
791- except KeyError :
792- d [item ] = None
793- else :
794- d [keys [i ]] = values [i ]
795- return d
796- return dict (self )
797-
798- def copy (self ):
799- return self .__class__ (self ._keys , self ._values )
800-
801-
802636class StatementResult (object ):
803637 """ A handler for the result of Cypher statement execution. Instances
804638 of this class are typically constructed and returned by
@@ -813,7 +647,7 @@ class StatementResult(object):
813647
814648 value_system = None
815649
816- zipper = Record
650+ zipper = zip
817651
818652 _session = None
819653
@@ -945,21 +779,6 @@ def peek(self):
945779 return zipper (keys , hydrate (values ))
946780 return None
947781
948- def value (self , item = 0 , default = None ):
949- """ Return the remainder of the result as a list of values.
950- """
951- return [record .value (item , default ) for record in self .records ()]
952-
953- def values (self , * items ):
954- """ Return the remainder of the result as a list of tuples.
955- """
956- return [record .values (* items ) for record in self .records ()]
957-
958- def data (self , * items ):
959- """ Return the remainder of the result as a list of dictionaries.
960- """
961- return [record .data (* items ) for record in self .records ()]
962-
963782
964783def fix_statement (statement ):
965784 if isinstance (statement , bytes ):
0 commit comments