def get_input_format_for_book(db, book_id, pref):
 if (pref is None):
  pref = get_preferred_input_format_for_book(db, book_id)
 if hasattr(pref, 'lower'):
  pref = pref.lower()
 input_formats = get_supported_input_formats_for_book(db, book_id)
 input_format = (pref if (pref in input_formats) else sort_formats_by_preference(input_formats, prefs['input_format_order'])[0])
 return (input_format, input_formats)

def get_input_format_for_book ( db , book_id , pref ) : if ( pref is None ) : pref = get_preferred_input_format_for_book ( db , book_id ) if hasattr ( pref , 'lower' ) : pref = pref . lower ( ) input_formats = get_supported_input_formats_for_book ( db , book_id ) input_format = ( pref if ( pref in input_formats ) else sort_formats_by_preference ( input_formats , prefs [ 'input_format_order' ] ) [ 0 ] ) return ( input_format , input_formats )
return for the book identified by book_id .