Open Media Library Platform

This commit is contained in:
j 2013-10-11 19:28:32 +02:00
commit 411ad5b16f
5849 changed files with 1778641 additions and 0 deletions

View file

@ -0,0 +1,24 @@
# __init__.py - collection of Slovak numbers
# coding: utf-8
#
# Copyright (C) 2012 Arthur de Jong
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301 USA
"""Collection of Slovak numbers."""
# provide vat as an alias
from stdnum.sk import dph as vat

View file

@ -0,0 +1,77 @@
# vat.py - functions for handling Slovak VAT numbers
# coding: utf-8
#
# Copyright (C) 2012, 2013 Arthur de Jong
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301 USA
"""IČ DPH (IČ pre daň z pridanej hodnoty, Slovak VAT number).
The DPH (Identifikačné číslo pre daň z pridanej hodnoty) is a 10-digit
number used for VAT purposes. It has a straightforward checksum.
>>> validate('SK 202 274 96 19')
'2022749619'
>>> validate('SK 202 274 96 18') # invalid check digits
Traceback (most recent call last):
...
InvalidChecksum: ...
"""
from stdnum.exceptions import *
from stdnum.sk import rc
from stdnum.util import clean
def compact(number):
"""Convert the number to the minimal representation. This strips the
number of any valid separators and removes surrounding whitespace."""
number = clean(number, ' -').upper().strip()
if number.startswith('SK'):
number = number[2:]
return number
def checksum(number):
"""Calculate the checksum."""
return int(number) % 11
def validate(number):
"""Checks to see if the number provided is a valid VAT number. This
checks the length, formatting and check digit."""
number = compact(number)
if not number.isdigit():
raise InvalidFormat()
if len(number) != 10:
raise InvalidLength()
# it is unclear whether the RČ can be used as a valid VAT number
if rc.is_valid(number):
return number
if number[0] == '0' or int(number[2]) not in (2, 3, 4, 7, 8, 9):
raise InvalidFormat()
if checksum(number) != 0:
raise InvalidChecksum()
return number
def is_valid(number):
"""Checks to see if the number provided is a valid VAT number. This
checks the length, formatting and check digit."""
try:
return bool(validate(number))
except ValidationError:
return False

View file

@ -0,0 +1,53 @@
# rc.py - functions for handling Slovak birth numbers
# coding: utf-8
#
# Copyright (C) 2012, 2013 Arthur de Jong
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301 USA
"""RČ (Rodné číslo, the Slovak birth number).
The birth number (, Rodné číslo) is the Slovak national identifier. The
number can be 9 or 10 digits long. Numbers given out after January 1st
1954 should have 10 digits. The number includes the birth date of the
person and their gender.
This number is identical to the Czech counterpart.
>>> validate('710319/2745')
'7103192745'
>>> validate('991231123')
'991231123'
>>> validate('7103192746') # invalid check digit
Traceback (most recent call last):
...
InvalidChecksum: ...
>>> validate('1103492745') # invalid date
Traceback (most recent call last):
...
InvalidComponent: ...
>>> validate('590312/123') # 9 digit number in 1959
Traceback (most recent call last):
...
InvalidLength: ...
>>> format('7103192745')
'710319/2745'
"""
# since this number is essentially the same as the Czech counterpart
# (until 1993 the Czech Republic and Slovakia were one country)
from stdnum.cz.rc import compact, validate, is_valid, format
__all__ = ['compact', 'validate', 'is_valid', 'format']