
    Vg                     b    d dl mZmZ d dlmZ ddlmZ ddlmZm	Z	m
Z
 ddlmZ  G d d	e      Zy
)    )ListTuple)RegistrantRule   )BaseProvider   )ISBNISBN10ISBN13)RULESc            	       t    e Zd ZdZdee   fdZededee   de	eef   fd       Z
ddedefdZddedefd	Zy
)Provideras  Generates fake ISBNs. ISBN rules vary across languages/regions
    so this class makes no attempt at replicating all of the rules. It
    only replicates the 978 EAN prefix for the English registration
    groups, meaning the first 4 digits of the ISBN-13 will either be
    978-0 or 978-1. Since we are only replicating 978 prefixes, every
    ISBN-13 will have a direct mapping to an ISBN-10.

    See https://www.isbn-international.org/content/what-isbn for the
    format of ISBNs.
    See https://www.isbn-international.org/range_file_generation for the
    list of rules pertaining to each prefix/registration group.
    returnc                 `   | j                  t        j                               }| j                  t        |   j                               }t        j                  t        |      z
  t        |      z
  dz
  }| j                  d|z        }t        |   |   }| j                  ||      \  }}||||gS )zSGenerate the information required to create an ISBN-10 or
        ISBN-13.
        r   #)random_elementr   keysr	   
MAX_LENGTHlennumerify_registrant_publication)selfean	reg_groupreg_pub_lenreg_pubrules
registrantpublications           ^/var/www/html/hubwallet-dev/venv/lib/python3.12/site-packages/faker/providers/isbn/__init__.py_bodyzProvider._body   s     &&uzz|4,,U3Z__->?	  ??SX5IFJ }}S;%67 ',Cj&;"&">">w"N
KY
K88    r   r   c                     |D ]5  }|j                   | dd cxk  r|j                  k  s&n )|j                  } n t        d      | d| | |d }}||fS )an  Separate the registration from the publication in a given
        string.
        :param reg_pub: A string of digits representing a registration
            and publication.
        :param rules: A list of RegistrantRules which designate where
            to separate the values in the string.
        :returns: A (registrant, publication) tuple of strings.
        Nz9Registrant/Publication not found in registrant rule list.)minmaxregistrant_length	Exception)r   r   rulereg_lenr   r   s         r    r   z Provider._registrant_publication-   sn      	\Dxx73B<3488300	\
 Z[[")(7"3WWX5FK
;&&r"   	separatorc                 j    | j                         \  }}}}t        ||||      }|j                  |      S N)r!   r   formatr   r+   r   groupr   r   isbns          r    isbn13zProvider.isbn13@   5    .2jjl+UJc5*k:{{9%%r"   c                 j    | j                         \  }}}}t        ||||      }|j                  |      S r-   )r!   r
   r.   r/   s          r    isbn10zProvider.isbn10E   r3   r"   N)-)__name__
__module____qualname____doc__r   strr!   staticmethodr   r   r   r2   r5    r"   r    r   r   
   sv    9tCy 9* ' 'T.5I 'eTWY\T\o ' '$& &c &
& &c &r"   r   N)typingr   r   faker.providers.isbn.rulesr    r   r1   r	   r
   r   r   r   r   r=   r"   r    <module>rA      s#     5  & & >&| >&r"   