def _bson_to_dict(data, opts):
 try:
  obj_size = _UNPACK_INT(data[:4])[0]
 except struct.error as exc:
  raise InvalidBSON(str(exc))
 if (obj_size != len(data)):
  raise InvalidBSON('invalid object size')
 if (data[(obj_size - 1):obj_size] != '\x00'):
  raise InvalidBSON('bad eoo')
 try:
  if _raw_document_class(opts.document_class):
   return opts.document_class(data, opts)
  return _elements_to_dict(data, 4, (obj_size - 1), opts)
 except InvalidBSON:
  raise
 except Exception:
  (_, exc_value, exc_tb) = sys.exc_info()
  reraise(InvalidBSON, exc_value, exc_tb)

def _bson_to_dict ( data , opts ) : try : obj_size = _UNPACK_INT ( data [ : 4 ] ) [ 0 ] except struct . error as exc : raise InvalidBSON ( str ( exc ) ) if ( obj_size != len ( data ) ) : raise InvalidBSON ( 'invalid object size' ) if ( data [ ( obj_size - 1 ) : obj_size ] != '\x00' ) : raise InvalidBSON ( 'bad eoo' ) try : if _raw_document_class ( opts . document_class ) : return opts . document_class ( data , opts ) return _elements_to_dict ( data , 4 , ( obj_size - 1 ) , opts ) except InvalidBSON : raise except Exception : ( _ , exc_value , exc_tb ) = sys . exc_info ( ) reraise ( InvalidBSON , exc_value , exc_tb )
decode a bson string to document_class .