def validate_textbook_json(textbook):
 if isinstance(textbook, basestring):
  try:
   textbook = json.loads(textbook)
  except ValueError:
   raise TextbookValidationError('invalid JSON')
 if (not isinstance(textbook, dict)):
  raise TextbookValidationError('must be JSON object')
 if (not textbook.get('tab_title')):
  raise TextbookValidationError('must have tab_title')
 tid = unicode(textbook.get('id', ''))
 if (tid and (not tid[0].isdigit())):
  raise TextbookValidationError('textbook ID must start with a digit')
 return textbook

def validate_textbook_json ( textbook ) : if isinstance ( textbook , basestring ) : try : textbook = json . loads ( textbook ) except ValueError : raise TextbookValidationError ( 'invalid JSON' ) if ( not isinstance ( textbook , dict ) ) : raise TextbookValidationError ( 'must be JSON object' ) if ( not textbook . get ( 'tab_title' ) ) : raise TextbookValidationError ( 'must have tab_title' ) tid = unicode ( textbook . get ( 'id' , '' ) ) if ( tid and ( not tid [ 0 ] . isdigit ( ) ) ) : raise TextbookValidationError ( 'textbook ID must start with a digit' ) return textbook
validate the given text as representing a list of pdf textbooks .