
from collections import OrderedDict as odict, MutableMapping
from itertools import chain

from marrow.schema import Container, Attribute


class Document(Container):
	__foreign__ = 'object'


from collections import OrderedDict as odict, MutableMapping
from itertools import chain

from marrow.schema import Container, Attribute

from .util import py2, SENTINEL, adjust_attribute_sequence



class Document(Container):
	__foreign__ = 'object'
	
	# Mapping Protocol
	
	def __getitem__(self, name):
		return self.__data__[name]
	
	def __setitem__(self, name, value):
		self.__data__[name] = value
	
	def __delitem__(self, name):
		del self.__data__[name]
	
	def __iter__(self):
		return iter(self.__data__.keys())
	
	def __len__(self):
		return len(self.__data__)
	
	if py2:
		def keys(self):
			return self.__data__.iterkeys()
		
		def items(self):
			return self.__data__.iteritems()
		
		def values(self):
			return self.__data__.itervalues()
	
	else:
		def keys(self):
			return self.__data__.keys()
		
		def items(self):
			return self.__data__.items()
		
		def values(self):
			return self.__data__.values()
	
	def __contains__(self, key):
		return key in self.__data__
	
	def __eq__(self, other):
		return self.__data__ == other
	
	def __ne__(self, other):
		return self.__data__ != other
	
	def get(self, key, default=None):
		return self.__data__.get(key, default)
	
	def clear(self):
		self.__data__.clear()
	
	def pop(self, name, default=SENTINEL):
		if default is SENTINEL:
			return self.__data__.pop(name)
		
		return self.__data__.pop(name, default)
	
	def popitem(self):
		return self.__data__.popitem()
	
	def update(self, *args, **kw):
		self.__data__.update(*args, **kw)
	
	def setdefault(self, key, value=None):
		return self.__data__.setdefault(key, value)


MutableMapping.register(Document)  # Metaclass conflict if we subclass.

Make compatible with direct use by pymongo.
Make compatible with direct use by pymongo.

I.e. for direct passing to collection.insert()

  
  from collections import OrderedDict as odict, MutableMapping
  from itertools import chain
  
  from marrow.schema import Container, Attribute
  
+ from .util import py2, SENTINEL, adjust_attribute_sequence
+ 
+ 
  
  class Document(Container):
  	__foreign__ = 'object'
+ 	
+ 	# Mapping Protocol
+ 	
+ 	def __getitem__(self, name):
+ 		return self.__data__[name]
+ 	
+ 	def __setitem__(self, name, value):
+ 		self.__data__[name] = value
+ 	
+ 	def __delitem__(self, name):
+ 		del self.__data__[name]
+ 	
+ 	def __iter__(self):
+ 		return iter(self.__data__.keys())
+ 	
+ 	def __len__(self):
+ 		return len(self.__data__)
+ 	
+ 	if py2:
+ 		def keys(self):
+ 			return self.__data__.iterkeys()
+ 		
+ 		def items(self):
+ 			return self.__data__.iteritems()
+ 		
+ 		def values(self):
+ 			return self.__data__.itervalues()
+ 	
+ 	else:
+ 		def keys(self):
+ 			return self.__data__.keys()
+ 		
+ 		def items(self):
+ 			return self.__data__.items()
+ 		
+ 		def values(self):
+ 			return self.__data__.values()
+ 	
+ 	def __contains__(self, key):
+ 		return key in self.__data__
+ 	
+ 	def __eq__(self, other):
+ 		return self.__data__ == other
+ 	
+ 	def __ne__(self, other):
+ 		return self.__data__ != other
+ 	
+ 	def get(self, key, default=None):
+ 		return self.__data__.get(key, default)
+ 	
+ 	def clear(self):
+ 		self.__data__.clear()
+ 	
+ 	def pop(self, name, default=SENTINEL):
+ 		if default is SENTINEL:
+ 			return self.__data__.pop(name)
+ 		
+ 		return self.__data__.pop(name, default)
+ 	
+ 	def popitem(self):
+ 		return self.__data__.popitem()
+ 	
+ 	def update(self, *args, **kw):
+ 		self.__data__.update(*args, **kw)
+ 	
+ 	def setdefault(self, key, value=None):
+ 		return self.__data__.setdefault(key, value)
  
+ 
+ MutableMapping.register(Document)  # Metaclass conflict if we subclass.
+ 
Make compatible with direct use by pymongo.
## Code Before:

from collections import OrderedDict as odict, MutableMapping
from itertools import chain

from marrow.schema import Container, Attribute


class Document(Container):
	__foreign__ = 'object'

## Instruction:
Make compatible with direct use by pymongo.
## Code After:

from collections import OrderedDict as odict, MutableMapping
from itertools import chain

from marrow.schema import Container, Attribute

from .util import py2, SENTINEL, adjust_attribute_sequence



class Document(Container):
	__foreign__ = 'object'
	
	# Mapping Protocol
	
	def __getitem__(self, name):
		return self.__data__[name]
	
	def __setitem__(self, name, value):
		self.__data__[name] = value
	
	def __delitem__(self, name):
		del self.__data__[name]
	
	def __iter__(self):
		return iter(self.__data__.keys())
	
	def __len__(self):
		return len(self.__data__)
	
	if py2:
		def keys(self):
			return self.__data__.iterkeys()
		
		def items(self):
			return self.__data__.iteritems()
		
		def values(self):
			return self.__data__.itervalues()
	
	else:
		def keys(self):
			return self.__data__.keys()
		
		def items(self):
			return self.__data__.items()
		
		def values(self):
			return self.__data__.values()
	
	def __contains__(self, key):
		return key in self.__data__
	
	def __eq__(self, other):
		return self.__data__ == other
	
	def __ne__(self, other):
		return self.__data__ != other
	
	def get(self, key, default=None):
		return self.__data__.get(key, default)
	
	def clear(self):
		self.__data__.clear()
	
	def pop(self, name, default=SENTINEL):
		if default is SENTINEL:
			return self.__data__.pop(name)
		
		return self.__data__.pop(name, default)
	
	def popitem(self):
		return self.__data__.popitem()
	
	def update(self, *args, **kw):
		self.__data__.update(*args, **kw)
	
	def setdefault(self, key, value=None):
		return self.__data__.setdefault(key, value)


MutableMapping.register(Document)  # Metaclass conflict if we subclass.
