Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _records(isbn, data):
"""Classify (canonically) the parsed data."""
# check status
try:
err = data.get('error', '')
if err:
raise
except:
LOGGER.debug('DataWrongShapeError for %s with status %s', isbn, err)
raise DataWrongShapeError("error: '%s' for isbn %s" % (err, isbn))
# put the selected data in records
try:
recs = data['data'][0]
except: # pragma: no cover
LOGGER.debug('NoDataForSelectorError for %s', isbn)
raise NoDataForSelectorError(isbn)
# consistency check (isbn request = isbn response)
if recs:
ids = recs.get('isbn13', '')
if isbn not in repr(ids): # pragma: no cover
LOGGER.debug('ISBNNotConsistentError for %s (%s)', isbn, repr(ids))
raise ISBNNotConsistentError("%s not in %s" % (isbn, repr(ids)))
# map canonical <- records
return _mapper(isbn, recs)
def _editions(isbn, data):
"""Return the records from the parsed response."""
# check status
try:
status = data['stat']
if status != 'ok':
raise # pragma: no cover
except: # pragma: no cover
LOGGER.debug('DataWrongShapeError for %s with status %s', isbn, status)
raise DataWrongShapeError("status: '%s' for isbn %s" % (status, isbn))
# put the selected data in records
try:
recs = [ib['isbn'][0] for ib in data['list']]
except: # pragma: no cover
LOGGER.debug('NoDataForSelectorError for %s', isbn)
raise NoDataForSelectorError(isbn)
return recs
def _records(isbn, data):
"""Classify (canonically) the parsed data."""
# check status
try:
status = data['stat']
if status != 'ok':
raise
except:
LOGGER.debug('DataWrongShapeError for %s with status %s', isbn, status)
raise DataWrongShapeError("status: '%s' for isbn %s" % (status, isbn))
# put the selected data in records
try:
recs = data['list'][0]
except: # pragma: no cover
LOGGER.debug('NoDataForSelectorError for %s', isbn)
raise NoDataForSelectorError(isbn)
# consistency check (isbn request = isbn response)
if recs:
ids = recs.get('isbn', '')
if isbn not in repr(ids): # pragma: no cover
LOGGER.debug('ISBNNotConsistentError for %s (%s)', isbn, repr(ids))
raise ISBNNotConsistentError("%s not in %s" % (isbn, repr(ids)))
# map canonical <- records
return _mapper(isbn, recs)
def _records(words, data):
"""Classify (canonically) the parsed data."""
# put the selected data in records
try:
recs = [d['volumeInfo'] for d in data['items']]
except Exception: # pragma: no cover
LOGGER.debug('NoDataForSelectorError for (%s)', words)
raise NoDataForSelectorError(words)
# map canonical <- records
return [_mapper(r) for r in recs if _mapper(r)]