def _dict_to_bson(doc, check_keys, opts, top_level=True):
 if _raw_document_class(doc):
  return doc.raw
 try:
  elements = []
  if (top_level and ('_id' in doc)):
   elements.append(_name_value_to_bson('_id\x00', doc['_id'], check_keys, opts))
  for (key, value) in iteritems(doc):
   if ((not top_level) or (key != '_id')):
    elements.append(_element_to_bson(key, value, check_keys, opts))
 except AttributeError:
  raise TypeError(('encoder expected a mapping type but got: %r' % (doc,)))
 encoded = ''.join(elements)
 return ((_PACK_INT((len(encoded) + 5)) + encoded) + '\x00')

def _dict_to_bson ( doc , check_keys , opts , top_level = True ) : if _raw_document_class ( doc ) : return doc . raw try : elements = [ ] if ( top_level and ( '_id' in doc ) ) : elements . append ( _name_value_to_bson ( '_id\x00' , doc [ '_id' ] , check_keys , opts ) ) for ( key , value ) in iteritems ( doc ) : if ( ( not top_level ) or ( key != '_id' ) ) : elements . append ( _element_to_bson ( key , value , check_keys , opts ) ) except AttributeError : raise TypeError ( ( 'encoder expected a mapping type but got: %r' % ( doc , ) ) ) encoded = '' . join ( elements ) return ( ( _PACK_INT ( ( len ( encoded ) + 5 ) ) + encoded ) + '\x00' )
encode a document to bson .