~ubuntu-branches/ubuntu/wily/pymongo/wily-proposed

« back to all changes in this revision

Viewing changes to bson/dbref.py

  • Committer: Package Import Robot
  • Author(s): Federico Ceratto
  • Date: 2015-04-26 22:43:13 UTC
  • mfrom: (24.1.5 sid)
  • Revision ID: package-import@ubuntu.com-20150426224313-0hga2jphvf0rrmfe
Tags: 3.0.1-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2009-2014 MongoDB, Inc.
 
1
# Copyright 2009-2015 MongoDB, Inc.
2
2
#
3
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
4
# you may not use this file except in compliance with the License.
16
16
 
17
17
from copy import deepcopy
18
18
 
 
19
from bson.py3compat import iteritems, string_type
19
20
from bson.son import SON
20
21
 
21
22
 
42
43
          - `**kwargs` (optional): additional keyword arguments will
43
44
            create additional, custom fields
44
45
 
45
 
        .. versionchanged:: 1.8
46
 
           Now takes keyword arguments to specify additional fields.
47
 
        .. versionadded:: 1.1.1
48
 
           The `database` parameter.
49
 
 
50
46
        .. mongodoc:: dbrefs
51
47
        """
52
 
        if not isinstance(collection, basestring):
 
48
        if not isinstance(collection, string_type):
53
49
            raise TypeError("collection must be an "
54
 
                            "instance of %s" % (basestring.__name__,))
55
 
        if database is not None and not isinstance(database, basestring):
 
50
                            "instance of %s" % string_type.__name__)
 
51
        if database is not None and not isinstance(database, string_type):
56
52
            raise TypeError("database must be an "
57
 
                            "instance of %s" % (basestring.__name__,))
 
53
                            "instance of %s" % string_type.__name__)
58
54
 
59
55
        self.__collection = collection
60
56
        self.__id = id
79
75
        """Get the name of this DBRef's database.
80
76
 
81
77
        Returns None if this DBRef doesn't specify a database.
82
 
 
83
 
        .. versionadded:: 1.1.1
84
78
        """
85
79
        return self.__database
86
80
 
110
104
 
111
105
    def __repr__(self):
112
106
        extra = "".join([", %s=%r" % (k, v)
113
 
                         for k, v in self.__kwargs.iteritems()])
 
107
                         for k, v in iteritems(self.__kwargs)])
114
108
        if self.database is None:
115
109
            return "DBRef(%r, %r%s)" % (self.collection, self.id, extra)
116
110
        return "DBRef(%r, %r, %r%s)" % (self.collection, self.id,
129
123
        return not self == other
130
124
 
131
125
    def __hash__(self):
132
 
        """Get a hash value for this :class:`DBRef`.
133
 
 
134
 
        .. versionadded:: 1.1
135
 
        """
 
126
        """Get a hash value for this :class:`DBRef`."""
136
127
        return hash((self.__collection, self.__id, self.__database,
137
128
                     tuple(sorted(self.__kwargs.items()))))
138
129
 
139
130
    def __deepcopy__(self, memo):
140
 
        """Support function for `copy.deepcopy()`.
141
 
 
142
 
        .. versionadded:: 1.10
143
 
        """
 
131
        """Support function for `copy.deepcopy()`."""
144
132
        return DBRef(deepcopy(self.__collection, memo),
145
133
                     deepcopy(self.__id, memo),
146
134
                     deepcopy(self.__database, memo),