#NEWLINE# def validate_collection( self , name_or_collection , scandata = False , full = False ) : #NEWLINE# #INDENT# 'Validate a collection.\n\n        Returns a dict of validation info. Raises CollectionInvalid if\n        validation fails.\n\n        With MongoDB < 1.9 the result dict will include a `result` key\n        with a string value that represents the validation results. With\n        MongoDB >= 1.9 the `result` key no longer exists and the results\n        are split into individual fields in the result dict.\n\n        :Parameters:\n          - `name_or_collection`: A Collection object or the name of a\n            collection to validate.\n          - `scandata`: Do extra checks beyond checking the overall\n            structure of the collection.\n          - `full`: Have the server do a more thorough scan of the\n            collection. Use with `scandata` for a thorough scan\n            of the structure of the collection and the individual\n            documents. Ignored in MongoDB versions before 1.9.\n        ' #NEWLINE# name = name_or_collection #NEWLINE# if isinstance ( name , Collection ) : #NEWLINE# #INDENT# name = name . name #NEWLINE# #UNINDENT# if ( not isinstance ( name , string_type ) ) : #NEWLINE# #INDENT# raise TypeError ( ( 'name_or_collection must be an instance of %s or Collection' % ( string_type . __name__ , ) ) ) #NEWLINE# #UNINDENT# result = self . command ( 'validate' , _unicode ( name ) , scandata = scandata , full = full ) #NEWLINE# valid = True #NEWLINE# if ( 'result' in result ) : #NEWLINE# #INDENT# info = result [ 'result' ] #NEWLINE# if ( ( info . find ( 'exception' ) != ( - 1 ) ) or ( info . find ( 'corrupt' ) != ( - 1 ) ) ) : #NEWLINE# #INDENT# raise CollectionInvalid ( ( '%s invalid: %s' % ( name , info ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( 'raw' in result ) : #NEWLINE# #INDENT# for ( _ , res ) in iteritems ( result [ 'raw' ] ) : #NEWLINE# #INDENT# if ( 'result' in res ) : #NEWLINE# #INDENT# info = res [ 'result' ] #NEWLINE# if ( ( info . find ( 'exception' ) != ( - 1 ) ) or ( info . find ( 'corrupt' ) != ( - 1 ) ) ) : #NEWLINE# #INDENT# raise CollectionInvalid ( ( '%s invalid: %s' % ( name , info ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( not res . get ( 'valid' , False ) ) : #NEWLINE# #INDENT# valid = False #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( not result . get ( 'valid' , False ) ) : #NEWLINE# #INDENT# valid = False #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( not valid ) : #NEWLINE# #INDENT# raise CollectionInvalid ( ( '%s invalid: %r' % ( name , result ) ) ) #NEWLINE# #UNINDENT# return result