Giter Club home page Giter Club logo

pyisbn's Introduction

James Rowe (he/him)

Hi, I’m James. I’m a Senior Developer with EADS, specialising in navigation systems(both GNNS and land-based).

You’ll find here things that are either not important enough for, or too incomplete to warrant, their own location.

Feel free to get in touch.

pyisbn's People

Contributors

cclauss avatar dependabot-preview[bot] avatar jnrowe avatar notconfusing avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyisbn's Issues

pyisbn allows some invalid ISBNs

Expected behaviour

pyisbn determines that these ISBNs are invalid:

2901568582497 
5800034170763

Current behaviour

pyisbn parses these and returns True on a call to validate()

Steps to reproduce

Full script to reproduce in case I'm using the package incorrectly:

#! /usr/bin/env python3

import pyisbn
import logging

def validate_isbn(isbn_string):
    try:
        parsed_isbn = pyisbn.Isbn(isbn_string)
    except pyisbn.IsbnError:
        logging.error("pyisbn: failed to parse this ISBN: {}".format(isbn_string))
        return False
    try:
        if not parsed_isbn.validate():
            logging.warning('pyisbn:Invalid ISBN: {}'.format(isbn_string))
            return False
    except pyisbn.IsbnError:
        logging.error("pyisbn: failed to parse this ISBN: {}".format(isbn_string))
        return False

    return True

if __name__ == '__main__':
    validate_isbn('2901568582497')
    validate_isbn('5800034170763')

Environment Information

  • OS: Ubuntu 18.04.1 LTS (bionic)
  • pyisbn version: 1.2.0
  • python version: 3.6.5

Quick request

Can you please release this using LGPL or BSD? I would like to use it in my codebase which is non-GPL. Thanks for your consideration.

Support hyphenation of ISBNs when converting to str()

I've held off adding this directly to pyisbn for a few years now, mostly
because it isn't clear that:

  1. There is a free database of publisher data
  2. It would make sense to include the data, as it all too quickly becomes dated

I'm starting to think hyphenation should exist directly in pyisbn, and it
should be added before the [perhaps] imminent stable release. However, how
should it be done?

Option 1

Recreate a database and include it in the package

Option 2

Define a format for a database and add a parser for the database

Option 3

Add a function to pull one of the online databases and let users deal with the
licensing issues. In some regions the data is freely available, and we
shouldn't really penalize people who don't live in places with silly restrictions.

Invalid Bookland region -> ISBN: 7798404510807

Hi,

I am developing and small app that reads books from a DB and validate each ISBN which maybe lack of ISBN-13 conversion (which is needed).

Now, the DB contains many ISBN like this one, which throws:

pyisbn.validate("7798404510807")
Traceback (most recent call last):
File "", line 1, in
File "/home/gustavo/Nextcloud/GDNet/Clientes/Patalibro/Desarrollo Lector/GetBooksPrices/venv/lib/python3.10/site-packages/pyisbn/init.py", line 504, in validate
isbn = _isbn_cleanse(isbn)
File "/home/gustavo/Nextcloud/GDNet/Clientes/Patalibro/Desarrollo Lector/GetBooksPrices/venv/lib/python3.10/site-packages/pyisbn/init.py", line 414, in _isbn_cleanse
raise IsbnError('invalid Bookland region')
pyisbn.IsbnError: invalid Bookland region

The Book indeed exist (https://www.quade.com.ar/agendas-2024/25415-agenda-2024-a5-2-dia-bruja-cristales-purpura-hechicera-7798404510807.html). Any ideas how to solve/skip this?

Environment Information

  • OS: Ubuntu 22.04
  • pyisbn version: 1.3.1
  • python version: 3.10

filtering list using pyisbn.validate()

Thanks for making this useful library available. While trying to filter invalid isbns from a list of 999 items with a function that calls pyisbn.validate(), the operation failed because some isbns were less than 10 digits. However, each subsequent call to pyisbn.validate() kept returning (after the boolean) parts of the previous list. See output 82 - 91. Any idea why?

In [81]: testresult = filter(v, test)
---------------------------------------------------------------------------
IsbnError                                 Traceback (most recent call last)
<ipython-input-81-519d0e9e2e9c> in <module>()
----> 1 testresult = filter(v, test)

<ipython-input-72-31b0fb728e9e> in v(x)
      1 def v(x):
----> 2     return not(pyisbn.validate(x))

c:\python27\lib\site-packages\pyisbn\__init__.pyc in validate(isbn)
    420
    421     """
--> 422     isbn = _isbn_cleanse(isbn)
    423     return isbn[-1].upper() == calculate_checksum(isbn[:-1])

c:\python27\lib\site-packages\pyisbn\__init__.pyc in _isbn_cleanse(isbn, checksum)
    337                 raise IsbnError('non-digit checksum')
    338         else:
--> 339             raise IsbnError('ISBN must be either 10 or 13 characters long')
    340     else:
    341         if len(isbn) == 8:

IsbnError: ISBN must be either 10 or 13 characters long
1149684", "9780691122700", "9780841225695", "9781847552594", "9780841225435", "9780470547847", "9780521876285", "978-143

In [82]: pyisbn.validate("691147949")

Out[82]: True9780534493493", "9780321750891", "9781118017166", "123849888", "9780521736534", "978-0415306362", "98718426
55207", "9780578026152", "978-1849801157", "9781577666936", "9781560328582", "9780854041763", "978-1845426606", "9781890

In [83]: pyisbn.validate("691d147949")
---------------------------------------------------------------------------05032280", "9781592330409", "978091125770", "
IsbnError                                 Traceback (most recent call last)36128663", "9789814280143", "9780205424177",
<ipython-input-83-e8f3bd933b41> in <module>()396", "9783631566152", "9780470598801", "9789812771759", "9780521674423", "
----> 1 pyisbn.validate("691d147949")-0470927076", "9780521877015", "470129239", "9780470129234", "9780205402878", "9781
565939790", "470484098", "9789814322249", "9789812561992", "978-1597496599", "978-0231101332", "9781890627706", "9780470
c:\python27\lib\site-packages\pyisbn\__init__.pyc in validate(isbn)3208496", "9781848729018", "9780763754006", "97807637
    420 "9780415774680", "9780521182491", "3527410392", "978-1111578718", "9781848167582", "978-1571170576", "9789812700
    421     """01703", "9781413015898", "9780631197119", "9780415520683", "9780470585894", "9781405124416", "97814027682
--> 422     isbn = _isbn_cleanse(isbn) "9781107403758", "9783642107092", "9789812837516", "9780131395060", "978-00729219
    423     return isbn[-1].upper() == calculate_checksum(isbn[:-1])2101", "9781107004528", "9781849730914", "9780813817
910", "9781555815363", "471215023", "9781849730525", "9781597560368", "9780415605250", "9789814291675", "9780521856980",
c:\python27\lib\site-packages\pyisbn\__init__.pyc in _isbn_cleanse(isbn, checksum)9", "1597497258", "9789812383068", "97
    326         raise TypeError('ISBN must be a string, received %r' % isbn)49633", "9781848166813", "9781555814816", "9
    327     if not isbn[:-1].isdigit():571172129", "9781592579020", "9780737750836", "9780970245823", "9781107010468", "
--> 328         raise IsbnError('non-digit parts') "9789814295772", "1555815030", "1842651196", "9780840054449", "978084
    329     if checksum:", "1842653989", "9780471757399", "9781111425562", "9781111573997", "9781111573980", "9780538733
    330         if len(isbn) == 9:", "9781842652961", "9780521761314", "9781618120120", "9780954699918", "9780199561797"
, "9780470627761", "9781848165601", "9780309158954", "9780763784508", "9780194372398", "9780805804669", "9780199564811",
IsbnError: non-digit parts166042", "9780691074535", "9781847355560", "9781555616049", "9780691128610", "9781577663485",
"9780854049561", "9780470616912", "9781847552259", "9780521864299", "9780854044665", "9781847350930", "9781847350954", "

In [84]: pyisbn.validate("6912147949")

Out[84]: False "9780521513692", "9789814293761", "9780840049315", "9781842656242", "9780195171693", "9781842652466", "97
89812388582", "9789812565280", "9781592333219", "9780981604558", "9789812561121", "9780309160353", "978-1593701390", "15

In [85]: pyisbn.validate("6912147949")

Out[85]: False71170453", "9781847552402", "9780521518192", "9789812778987", "9781603560085", "9780309137164", "978981277
1131", "9781107009653", "978-1571172013", "978-1571172044", "978-1571172020", "978-0692000274", "9780309187510", "978184

In [86]: pyisbn.validate("6912147949")

Out[86]: False9814329835", "9781555816612", "9780314911612", "9781107403505", "9781602391246", "978-1613504444", "978-11
19993056", "9781599290591", "9780863775697", "9780521899543", "978-9064507434", "9780521699099", "9789814355506", "12382

In [87]: pyisbn.validate("978-0262062664")

Out[87]: True47355591", "9780521651516", "9780470623961", "9780470624296", "9781118156438", "9780312586300", "978-906450
6482", "9781401323448", "9780425213575", "978-1571172143", "978-1571171986", "0-57117-072-3", "978-1571172051", "978-052

In [88]: pyisbn.validate("978-0262062664")

Out[88]: True1848720398", "978-0517562208", "978-1848448346", "9780309138505", "978-9064506710", "9780983490708", "97806
91149493", "1597496618", "1597496537", "9781930448360", "9780521138178", "9781107013469", "9781578263097", "978089529817

In [89]: pyisbn.validate("978-0262062664")

Out[89]: True"9780691131382", "9780691144146", "9780805077469", "9780470538708", "9780674403451", "9781453837085", "9780
691142890", "052117533X", "9780415882194", "9780345494580", "9781568989723", "9789812560421", "9780982290040", "97811080

In [90]: pyisbn.validate("978-0262062664")

Out[90]: True80217371858", "9781594868283", "9781107401648", "9781569242742", "9781848166011", "9780470455753", "9780452
296886", "9780195128987", "9781594770951", "9780312376321", "9781573317566", "9780520202535", "9781859574980", "97805211

In [91]: pyisbn.validate("981429134X")

Out[91]: True02458", "9780309148504", "9781849800204", "9781849730433", "9781849730433", "9789812560889", "9780071636919
", "9780309148382", "9780470655887", "978-1847202055", "9780123814753", "9780970245816", "9780446690744", "9789814295512

In [92]: testresult

Out[92]: []

In [93]: pyisbn.validate("981429134X")
Out[93]: True

In [94]: pyisbn.validate("981429234X")
Out[94]: False

easy_install fails with syntax error in setup.py

easy_install http://www.jnrowe.ukfsn.org/_downloads/pyisbn-0.5.0.tar.bz2

fails on Python 2.5.4 with the following error:

File "setup.py", line 150
except OSError as e:
                ^
SyntaxError: invalid syntax

Handling unicode isbn for _isbn_cleanse

When try to replace the dash of the unicode isbn, it will raise a UnicodeDecodeError, is it ok to convert the isbn to str inside the _isbn_cleanse rather than let the users do it themselves?

I knew you have forced the input must be str type, but I think it will make the api much flexible to support various type string. (I mean str and unicode)

Initial Update

Hi 👊

This is my first visit to this fine repo, but it seems you have been working hard to keep all dependencies updated so far.

Once you have closed this issue, I'll create separate pull requests for every update as soon as I find one.

That's it for now!

Happy merging! 🤖

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.