rules.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # coding=utf-8
  2. """
  3. This module exists solely to figure how long a registrant/publication
  4. number may be within an ISBN. The rules change based on the prefix and
  5. language/region. This list of rules only encapsulates the 978 prefix
  6. for English books. 978 is the largest and, until recently, the only
  7. prefix.
  8. The complete list of prefixes and rules can be found at
  9. https://www.isbn-international.org/range_file_generation
  10. """
  11. from collections import namedtuple
  12. RegistrantRule = namedtuple(
  13. 'RegistrantRule', ['min', 'max', 'registrant_length'])
  14. # Structure: RULES[`EAN Prefix`][`Registration Group`] = [Rule1, Rule2, ...]
  15. RULES = {
  16. '978': {
  17. '0': [
  18. RegistrantRule('0000000', '1999999', 2),
  19. RegistrantRule('2000000', '2279999', 3),
  20. RegistrantRule('2280000', '2289999', 4),
  21. RegistrantRule('2290000', '6479999', 3),
  22. RegistrantRule('6480000', '6489999', 7),
  23. RegistrantRule('6490000', '6999999', 3),
  24. RegistrantRule('7000000', '8499999', 4),
  25. RegistrantRule('8500000', '8999999', 5),
  26. RegistrantRule('9000000', '9499999', 6),
  27. RegistrantRule('9500000', '9999999', 7)
  28. ],
  29. '1': [
  30. RegistrantRule('0000000', '0999999', 2),
  31. RegistrantRule('1000000', '3999999', 3),
  32. RegistrantRule('4000000', '5499999', 4),
  33. RegistrantRule('5500000', '7319999', 5),
  34. RegistrantRule('7320000', '7399999', 7),
  35. RegistrantRule('7400000', '8697999', 5),
  36. RegistrantRule('8698000', '9729999', 6),
  37. RegistrantRule('9730000', '9877999', 4),
  38. RegistrantRule('9878000', '9989999', 6),
  39. RegistrantRule('9990000', '9999999', 7)
  40. ]
  41. }
  42. }