lists.arthurdejong.org
RSS feed

python-stdnum branch master updated. 1.4-12-g49db553

[Date Prev][Date Next] [Thread Prev][Thread Next]

python-stdnum branch master updated. 1.4-12-g49db553



This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "python-stdnum".

The branch, master has been updated
       via  49db5531efb72708a88e2b809009c6734e0fac4c (commit)
       via  2c557a0c2e091487fcf9dfe00d3934208136501e (commit)
      from  b128c8d3cbb6a07c937de531507c63b4b7acd36e (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://arthurdejong.org/git/python-stdnum/commit/?id=49db5531efb72708a88e2b809009c6734e0fac4c

commit 49db5531efb72708a88e2b809009c6734e0fac4c
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Sat Sep 3 19:09:03 2016 +0200

    Add more tests for Referencia Catastral
    
    This adds a number of extra tests for the Spanish Referencia Catastral
    (stdnum.es.referenciacatastral) module, mostly based on numbers found
    online.
    
    This commit includes some of the documentation on the structure of
    Referencia Catastral that was in the original pull request.
    
    See https://github.com/arthurdejong/python-stdnum/pull/38

diff --git a/tests/test_es_referenciacatastral.doctest 
b/tests/test_es_referenciacatastral.doctest
new file mode 100644
index 0000000..f175d1c
--- /dev/null
+++ b/tests/test_es_referenciacatastral.doctest
@@ -0,0 +1,295 @@
+test_es_referenciacatastral.doctest - more detailed doctests
+
+Copyright (C) 2016 David García Garzón
+Copyright (C) 2015 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
+
+
+This file contains more detailed doctests for the
+stdnum.es.referenciacatastral module.
+
+>>> from stdnum.es import referenciacatastral
+>>> from stdnum.exceptions import *
+
+
+The parcel digits are structured differently for urban, non-urban or special
+(infrastructure) cases:
+
+* Urban states
+    * 7 digits: (numeric) block sequence within cartographic sheet,
+        and parcel sequence within the block.
+    * 7 digits: (alphanum) cartographic sheet where the block centroid is.
+
+* Non-urban states:
+    * 2 digits: (numeric) Province or more exactly, ministerial delegation
+    * 3 digits: (numeric) Municipality
+    * 1 digits: (letter) Sector
+    * 3 digits: (numeric) Polygon
+    * 5 digits: (numeric) Parcel
+
+* Special states:
+    * BICE code: (2 digits, a number and a letter)
+        * Energy infrastructure
+            * 1E: Thermal power plant
+            * 1G: Regasification terminal
+            * 1R: Oil refinery
+            * 1N: Nuclear power plant
+            * 1H: Hydro power plant
+        * Hydro
+            * 2P: Dam
+        * Roads and highways
+            * 3A: Tolled highway
+            * 3C: Tolled road
+            * 3T: Tolled tunnel
+        * Ports and airports
+            * 4A: Airports
+            * 4P: Commercial ports
+    * Province (major if many) (2 digits)
+    * Municipality (3 digits)
+    * Scope (1 letter)
+        * E: National
+        * A: Autonomous Community
+        * P: Province
+        * M: Municipality
+    * Number of municipalities it extends (2 digits, numbers)
+    * Abbreviated denomination (4 digits, letters)
+
+An online validator can be found at
+https://www1.sedecatastro.gob.es/CYCBienInmueble/OVCBusqueda.aspx
+
+
+These have been found online and should all be valid numbers.
+
+>>> numbers = '''
+...
+... 000100100QE45D0001GA
+... 000100100TH44D0001GX
+... 000700100UJ13C0001XY
+... 0014001QD4901S0001LP
+... 001700100QC04D0001AF
+... 002100100QD03C0001HH
+... 0307813QD3100N0001LW
+... 0376902QE3607N0001UM
+... 0412501QD0301S0001BQ
+... 0426012TJ3502N0001SQ
+... 0474001QE5307C0033DW
+... 0474001QE5307C0060IB
+... 0474001QE5307C0067GR
+... 0474001QE5307C0149YK
+... 0553304TK9405S0001GR
+... 06011A012002450000QE
+... 06011A045000920000QX
+... 06016A012090090000ZI
+... 06051A005000200000ZJ
+... 06060A040001360000XM
+... 06063A002000200001SL
+... 06063A015000110000AX
+... 06074A005005560000BR
+... 06079A002002810000JX
+... 06080A504000390000II
+... 06080A507000270000IK
+... 06083A045001460000ZM
+... 06083A136002390000UH
+... 06084A508000290000QT
+... 06084A511000950000QL
+... 06085A009000130000YK
+... 06086A023000710000PG
+... 06092A010090070000XY
+... 06105A014002400000QA
+... 06127A011000890000LG
+... 06150A022002960000YK
+... 06151A008000450000PE
+... 06153A002000420000KQ
+... 06154A016090110000XD
+... 06160A030009840000AJ
+... 06162A009000770000LK
+... 06900A228000090000EB
+... 06900A228000110000EA
+... 06900A230000050000EG
+... 0736601QE2503N0002XI
+... 0786418PD6508N0001GB
+... 0791405PD6509S0001RX
+... 0811056TJ8201S0001QF
+... 0847501PE8504N0001EF
+... 0895009TK5309N0001DA
+... 0939216PD5603N0001BB
+... 0989801QC2308N0001LY
+... 10010A012005070000SA
+... 10033A017000040000AH
+... 10036A001002140000MU
+... 10042A005090420000SX
+... 10063A006000030000EW
+... 10083A002030290000DX
+... 10103A002002490000IE
+... 10105A007004020000HQ
+... 10118A004030320000PY
+... 10122A032090100000FH
+... 10134A009000010000RY
+... 10149A011090100000YZ
+... 10178A034090180000JE
+... 1087910TK7118N0001FS
+... 10900A044090170000MU
+... 1099107TJ3419N0001RR
+... 1344504PD5614S0001XE
+... 1468103QC6316N0001PQ
+... 1470436TJ5117S0001EP
+... 1665311QC6316S0001OO
+... 1811701QC3711S0001RM
+... 1927510QD2812N0001GJ
+... 2014801QC3721S0001IR
+... 2019001QD2821N0001QR
+... 2035116PD7423N0001WL
+... 2070105TK4027A0001XW
+... 2093020TK8129S0005RA
+... 2106409QE0520N0001IO
+... 2209001TK5620N0001LL
+... 2217331QC3721N0001GL
+... 2272003TJ5127S0001JF
+... 2335208QC5823N0001YD
+... 2372801QC0427S0001MO
+... 2380105PC8328S0001PS
+... 2409516TK5620N0001HL
+... 2444001QD2724C0001EB
+... 2595010TK8129N0001XX
+... 2641303TK5424S0001WH
+... 2667407TJ5126N0001RS
+... 2735401PD7423N0001AL
+... 2750203PC9625S0001BA
+... 2787101TK8128N0001MT
+... 2792003TK8129S0001QU
+... 2792020TJ6029S0001IO
+... 2911401TJ4521S0001BS
+... 2951205TJ7025S0001RX
+... 3012723TJ4531S0001DH
+... 3065602TH8836N0001KA
+... 3117006QC3731N0001KM
+... 3135901PD7033E0001MF
+... 3178101UJ2337N0001IB
+... 3327002TJ6332N0001QH
+... 3368022PE8136N0001LJ
+... 3390803PC9439S0001XR
+... 3456202TK7435N0001OU
+... 3575302TJ6437N0001QF
+... 3809537QC3230N0001JR
+... 4028713TK8142N0001TE
+... 4045111TK8444N0001KY
+... 4443202PD7044C0068ZB
+... 4471131PD7047A0001DR
+... 4578201UJ0147N0001HD
+... 4637801TK6843N0001WI
+... 4878424TK6347N0001GT
+... 4926002QE4142N0001UP
+... 5034623PC6853S0001MO
+... 5078102VK8957N0001TB
+... 5172401PD7057A0001HI
+... 5215006QC5751N0001EO
+... 5238069TJ6253N0001PD
+... 5335702QE3853N0001AI
+... 5342201QC2854S0001WF
+... 5347806UK9354N0001RU
+... 5349709QC2854N0001FY
+... 5410808QD5451S0001SJ
+... 5417221QC5751N0001JO
+... 5443405UK9354S0001BG
+... 5468703QC3356N0001JR
+... 5539105PC6853N0001KQ
+... 5552401TK6255S0001YQ
+... 5640007TJ6254S0001FG
+... 5670823QC3357S0001AY
+... 5867418QD1256N0001UD
+... 5967307QC0256N0001GO
+... 5972003QD1257S0001MG
+... 6026813QD2762E0001WB
+... 6043208PD9164C0001GI
+... 6045303QE1564N0001UD
+... 6050201PD7065A0001KQ
+... 6061002QC2566S0001DF
+... 6117611QC4261N0001UX
+... 6229101QD2762G0001UG
+... 6284203TH6368S0001UH
+... 6320001QD2161N0001LI
+... 6326404QD2762E0001MB
+... 6380501UH0868S0001LT
+... 6396405TJ8269N0001QT
+... 6407102TJ8360N0001SK
+... 6528901UJ0262N0001PP
+... 6534011PC9763S0001YZ
+... 6537302PD7063H0001WU
+... 6595333QD0069N0001OM
+... 6642023PD7064F0001SY
+... 6684201VK8968S0002RR
+... 6743701QD2764D0001IX
+... 6795121QD0069N0008EU
+... 6821105TK5662S0001QI
+... 6822811QD2162S0001GP
+... 6893505QC5569S0001LO
+... 6991224PD3869S0001FW
+... 7076102TJ5177N0001ZE
+... 7174002QD2077S0001XW
+... 7244002PD7074C0001QY
+... 7282901TJ5178S0001BT
+... 7383502VK8978S0001PU
+... 7384201TJ5178S0012WD
+... 7384201TJ5178S0019OB
+... 7384201TJ5178S0043QS
+... 7479113QE2477N0001UY
+... 7570012TJ4377S0001PO
+... 7640222QE4374B0001FR
+... 7682601TJ5178S0001XT
+... 7749401PD7074H0001HT
+... 7865002TJ4376N0001TU
+... 7865004TJ4376N0001MU
+... 7865006TJ4376N0001KU
+... 7977802TJ5177N0001TE
+... 8327413PE8482N0001HU
+... 8344202PC6684S0001FT
+... 8354003PD7085C0001RR
+... 8384416TJ8688S0001IQ
+... 8645036TJ5984N0001TL
+... 8670604TJ4587S0004BE
+... 8679007TJ5187N0001LU
+... 8696402TH7889N0001XQ
+... 8696802TH7889N0001GQ
+... 8701105PD7180B0001AU
+... 8701110PD7180B0001YU
+... 8788845QC2588H0001IJ
+... 8796005QD2089N0001WO
+... 8796022QD2089N0001OO
+... 8827314QD5282N0001RT
+... 8843501PC7484S0001KU
+... 8910403QD3481S0001LT
+... 8990307TH7889S0001OO
+... 9013602QD2191S0001ET
+... 9165501QE4396E0001YR
+... 9201801QD2190S0001PA
+... 9205301VL8090N0001PW
+... 9265801QE4396E0001PR
+... 9327401QE3592N0001JG
+... 9655311TK9195N0001OJ
+... 9712301QD2191S0001DT
+... 9811901DS3191S0001QY
+... 9811901TN8391S0001QM
+... 9815402PD9391N0001PO
+... 9854802PD7195D0001MX
+... 9872023 VH5797S 0001 WX
+... 9953001PD7195D0001GX
+... 9988220VK8998N0001JU
+... 9996812TJ9699N0001ZE
+...
+... '''
+>>> [x for x in numbers.splitlines() if x and not 
referenciacatastral.is_valid(x)]
+[]

http://arthurdejong.org/git/python-stdnum/commit/?id=2c557a0c2e091487fcf9dfe00d3934208136501e

commit 2c557a0c2e091487fcf9dfe00d3934208136501e
Author: David García Garzón <david.garcia@upf.edu>
Date:   Wed Aug 31 21:43:17 2016 +0200

    Add Spansih Referencia Catastral
    
    The control digit check algorithm is based on Javascript implementation
    by Vicente Sancho that can be found at
    http://trellat.es/validar-la-referencia-catastral-en-javascript/
    
    See https://github.com/arthurdejong/python-stdnum/pull/38

diff --git a/stdnum/es/referenciacatastral.py b/stdnum/es/referenciacatastral.py
new file mode 100644
index 0000000..68c0993
--- /dev/null
+++ b/stdnum/es/referenciacatastral.py
@@ -0,0 +1,114 @@
+# referenciacatastral.py - functions for handling Spanish real state ids
+# coding: utf-8
+#
+# Copyright (C) 2016 David García Garzón
+# Copyright (C) 2016 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
+
+"""Referencia Catastral (Spanish real estate property id)
+
+The cadastral reference code is an identifier for real estate in Spain. It is
+issued by Dirección General del Catastro (General Directorate of Land
+Registry) of the Ministerio de Hacienda (Tresury Ministry).
+
+It has 20 digits and contains numbers and letters including the Spanish Ñ.
+The number consists of 14 digits for the parcel, 4 for identifying properties
+within the parcel and 2 check digits. The parcel digits are structured
+differently for urban, non-urban or special (infrastructure) cases.
+
+More information:
+
+* http://www.catastro.meh.es/esp/referencia_catastral_1.asp (Spanish)
+* http://www.catastro.meh.es/documentos/05042010_P.pdf (Spanish)
+* https://es.wikipedia.org/wiki/Catastro#Referencia_catastral
+
+>>> validate('7837301-VG8173B-0001 TT')  # Lanteira town hall
+'7837301VG8173B0001TT'
+>>> validate('783301 VG8173B 0001 TT')  # missing digit
+Traceback (most recent call last):
+    ...
+InvalidLength: ...
+>>> validate('7837301/VG8173B 0001 TT')  # not alphanumeric
+Traceback (most recent call last):
+    ...
+InvalidFormat: ...
+>>> validate('7837301 VG8173B 0001 NN')  # bad check digits
+Traceback (most recent call last):
+    ...
+InvalidChecksum: ...
+>>> format('4A08169P03PRAT0001LR')  # BCN Airport
+'4A08169 P03PRAT 0001 LR'
+"""
+
+from stdnum.exceptions import *
+from stdnum.util import clean
+
+
+alphabet = u'ABCDEFGHIJKLMNÑOPQRSTUVWXYZ0123456789'
+
+
+def compact(number):
+    """Convert the number to the minimal representation. This strips the
+    number of any valid separators and removes surrounding whitespace."""
+    return clean(number, ' -').strip().upper()
+
+
+def format(number):
+    """Reformat the passed number to the standard format."""
+    number = compact(number)
+    return ' '.join([
+        number[:7],
+        number[7:14],
+        number[14:18],
+        number[18:]
+    ])
+
+
+def _check_digit(number):
+    """Calculate a single check digit on the provided part of the number."""
+    weights = (13, 15, 12, 5, 4, 17, 9, 21, 3, 7, 1)
+    s = sum(w * (int(n) if n.isdigit() else alphabet.find(n) + 1)
+            for w, n in zip(weights, number))
+    return 'MQWERTYUIOPASDFGHJKLBZX'[s % 23]
+
+
+def calc_check_digits(number):
+    """Calculate the check digits for the number."""
+    return (
+        _check_digit(number[0:7] + number[14:18]) +
+        _check_digit(number[7:14] + number[14:18]))
+
+
+def validate(number):
+    """Checks to see if the number provided is a valid Cadastral Reference.
+    This checks the length, formatting and check digits."""
+    number = compact(number)
+    if not all(c in alphabet for c in number):
+        raise InvalidFormat()
+    if len(number) != 20:
+        raise InvalidLength()
+    if calc_check_digits(number) != number[18:]:
+        raise InvalidChecksum()
+    return number
+
+
+def is_valid(number):
+    """Checks to see if the number provided is a valid Cadastral Reference."""
+    try:
+        return bool(validate(number))
+    except ValidationError:
+        return False

-----------------------------------------------------------------------

Summary of changes:
 stdnum/es/referenciacatastral.py          | 114 ++++++++++++
 tests/test_es_referenciacatastral.doctest | 295 ++++++++++++++++++++++++++++++
 2 files changed, 409 insertions(+)
 create mode 100644 stdnum/es/referenciacatastral.py
 create mode 100644 tests/test_es_referenciacatastral.doctest


hooks/post-receive
-- 
python-stdnum
-- 
To unsubscribe send an email to
python-stdnum-commits-unsubscribe@lists.arthurdejong.org or see
https://lists.arthurdejong.org/python-stdnum-commits/