Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _mapper(isbn, records):
"""Map canonical <- records."""
# canonical:
# -> ISBN-13, Title, Authors, Publisher, Year, Language
try:
# mapping: canonical <- records
canonical = {}
canonical['ISBN-13'] = u(isbn)
canonical['Title'] = records.get('title', u('')).replace(' :', ':')
canonical['Authors'] = [a['name'] for a in
records.get('authors', ({'name': u('')},))]
canonical['Publisher'] = records.get('publishers',
[{'name': u('')}, ])[0]['name']
canonical['Year'] = records.get('publish_date', u(',')).split(',')[1]
except: # pragma: no cover
raise RecordMappingError(isbn)
# call stdmeta for extra cleanning and validation
return stdmeta(canonical)
def _mapper(isbn, records):
"""Mapp: canonical <- records."""
# canonical: ISBN-13, Title, Authors, Publisher, Year, Language
try:
canonical = {}
canonical['ISBN-13'] = u(isbn)
canonical['Title'] = records.get('title', u('')).replace(' :', ':')
buf = records.get('author', u(''))
canonical['Authors'] = [x.strip('. ') for x in buf.split(';')]
canonical['Publisher'] = records.get('publisher', u(''))
canonical['Year'] = records.get('year', u(''))
canonical['Language'] = records.get('lang', u(''))
except: # pragma: no cover
raise RecordMappingError(isbn)
# call stdmeta for extra cleanning and validation
return stdmeta(canonical)
def _mapper(isbn, records):
"""Mapp: canonical <- records."""
# canonical: ISBN-13, Title, Authors, Publisher, Year, Language
try:
canonical = {}
canonical['ISBN-13'] = u(isbn)
canonical['Title'] = records.get('title', u('')).replace(' :', ':')
buf = records.get('author', u(''))
canonical['Authors'] = [x.strip('. ') for x in buf.split(';')]
canonical['Publisher'] = records.get('publisher', u(''))
canonical['Year'] = records.get('year', u(''))
canonical['Language'] = records.get('lang', u(''))
except: # pragma: no cover
raise RecordMappingError(isbn)
# call stdmeta for extra cleanning and validation
return stdmeta(canonical)
def _mapper(isbn, records):
"""Mapp: canonical <- records."""
# canonical: ISBN-13, Title, Authors, Publisher, Year, Language
try:
canonical = {}
canonical['ISBN-13'] = u(isbn)
canonical['Title'] = records.get('title', u('')).replace(' :', ':')
buf = records.get('author', u(''))
canonical['Authors'] = [x.strip('. ') for x in buf.split(';')]
canonical['Publisher'] = records.get('publisher', u(''))
canonical['Year'] = records.get('year', u(''))
canonical['Language'] = records.get('lang', u(''))
except: # pragma: no cover
raise RecordMappingError(isbn)
# call stdmeta for extra cleanning and validation
return stdmeta(canonical)
def _mapper(isbn, records):
"""Mapp: canonical <- records."""
# canonical: ISBN-13, Title, Authors, Publisher, Year, Language
try:
canonical = {}
canonical['ISBN-13'] = u(isbn)
canonical['Title'] = records.get('title', u('')).replace(' :', ':')
buf = records.get('author', u(''))
canonical['Authors'] = [x.strip('. ') for x in buf.split(';')]
canonical['Publisher'] = records.get('publisher', u(''))
canonical['Year'] = records.get('year', u(''))
canonical['Language'] = records.get('lang', u(''))
except: # pragma: no cover
raise RecordMappingError(isbn)
# call stdmeta for extra cleanning and validation
return stdmeta(canonical)
def _mapper(isbn, records):
"""Map canonical <- records."""
# canonical:
# -> ISBN-13, Title, Authors, Publisher, Year, Language
try:
# mapping: canonical <- records
canonical = {}
canonical['ISBN-13'] = u(isbn)
canonical['Title'] = records.get('title', u('')).replace(' :', ':')
canonical['Authors'] = [a['name'] for a in
records.get('authors', ({'name': u('')},))]
canonical['Publisher'] = records.get('publishers',
[{'name': u('')}, ])[0]['name']
canonical['Year'] = records.get('publish_date', u(',')).split(',')[1]
except: # pragma: no cover
raise RecordMappingError(isbn)
# call stdmeta for extra cleanning and validation
return stdmeta(canonical)
def _mapper(isbn, records):
"""Mapp: canonical <- records."""
# canonical: ISBN-13, Title, Authors, Publisher, Year, Language
try:
canonical = {}
canonical['ISBN-13'] = u(isbn)
canonical['Title'] = records.get('title', u('')).replace(' :', ':')
buf = records.get('author', u(''))
canonical['Authors'] = [x.strip('. ') for x in buf.split(';')]
canonical['Publisher'] = records.get('publisher', u(''))
canonical['Year'] = records.get('year', u(''))
canonical['Language'] = records.get('lang', u(''))
except: # pragma: no cover
raise RecordMappingError(isbn)
# call stdmeta for extra cleanning and validation
return stdmeta(canonical)
def do_pipe():
"""Validate ISBNs from sys.stdin."""
# check if pipe
if sys.stdin.isatty():
print('Usage:\n cat ISBNs | isbn_validate')
return 1
for line in sys.stdin:
line = line.strip()
buf = re.sub(r"\[|\]|'|-", "", repr(get_isbnlike(line)))
buf = buf.strip()
if ',' in buf:
for b in buf.split(','):
b = get_canonical_isbn(b.strip())
if b:
print(b)
else:
buf = get_canonical_isbn(buf)
if buf:
print(buf)
return 0
It will output all valid ISBNs that receive from input.
Usage:
cat ISBNs| isbn_stdin_validate
"""
# check if pipe
if sys.stdin.isatty():
print('Usage:\n cat ISBNs| isbn_stdin_validate')
return 1
for line in sys.stdin:
line = line.strip()
buf = re.sub(r"\[|\]|'|-", "", repr(get_isbnlike(line)))
buf = buf.strip()
if ',' in buf:
for b in buf.split(','):
b = get_canonical_isbn(b.strip())
if b:
print(b)
else:
buf = get_canonical_isbn(buf)
if buf:
print(buf)
return 0
"""
# check if pipe
if sys.stdin.isatty():
print('Usage:\n cat ISBNs| isbn_stdin_validate')
return 1
for line in sys.stdin:
line = line.strip()
buf = re.sub(r"\[|\]|'|-", "", repr(get_isbnlike(line)))
buf = buf.strip()
if ',' in buf:
for b in buf.split(','):
b = get_canonical_isbn(b.strip())
if b:
print(b)
else:
buf = get_canonical_isbn(buf)
if buf:
print(buf)
return 0