# -*- coding: UTF-8 -*- """Module for validating values connected to the URLs. This is needed to make sure the the imported URLs have legal values when importing large scale. Note that this needs to be updated if new values are legal. """ # Copyright 2005, 2006 EIAO Consoritum # This program is distributed under the terms of the GNU General # Public License. # # This file is part of the European Internet Accessibility Observatory # (EIAO) # # EIAO is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # EIAO 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 General Public License for more details. # # You should have received a copy of the GNU General Public License # along with EIAO; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, # MA 02110-1301 USA __owner__ = "Morten Goodwin Olsen" __maintainer__ = "Nils Ulltveit-Moe" __version__ = 0.1 from urlreperror import * import sc legalContinents = ['EU'] legalCountries = ['TR','BG','RO','AT', 'BE', 'CH', 'CY', 'CZ', 'DK', 'EE', 'ES', 'FI', 'FR', 'DE', 'GR', 'HU', 'IE', 'IS', 'IT', 'LI', 'LT', 'LU', 'LV', 'MT', 'NL', 'NO', 'PL', 'PT', 'SE', 'SI', 'SK', 'UK','NE'] def _readnuts3(filename): file = open(filename,'r') firstline=file.readline() i=0 nuts3list=[] if firstline.startswith("Code,Level 3"): for line in file.xreadlines(): if line != "\n": i=i+1 params=line.split(",") #using generic addinitialurl-function instead of addInitialSiteURL, which is now removed nuts3list.append(params[0]) file.close() return nuts3list else: return [] sco = sc.SystemConfiguration() legalNuts3 = _readnuts3(sco.nuts3file) legalNace =['Unknown','92.71','75.12','85.30','64.20','85.00','91.11','74.40','70.40','80.40','90.30','92.30','92.51','92.15','55.10','91.10','80.00','91.00','91.20','92.20','85.11','92.40','92.50','92.00','85.14','75.24','75.30','73.50','80.30','91.12','75.10','75.11','75.00','66.00','85.32','88.99','64.99','94.12','65.12','65.21','84.24','84.22','47','84.23','47,9','47.91' ,'53','53.1','53.10','58','58.1','58.13','60','60.1','60.2', '60.10','60.20','64','64.1','64.11','79','79.1','79.11','79.12','84','84.1','84.11','84.12', '85','85.4','85.42','91','91.0','91.01','91.02','94','94.9','94.92'] #legalSectors = ['PU','CO'] #legalCategories = ['FE','LO','UN','MU','PO','LI','PA','NE','TV','RA','BA','TR','EC'] def checkLegalContinent(continent): """Check if a continent is within the legal values Keyword arguments: continent -- Continent to be checked Returns None Examples: >>> checkLegalContinent('EU') >>> try: checkLegalContinent('AM') ... except IllegalContinentProperty: print 'Failing' Failing """ #import pdb #pdb.set_trace() if continent not in legalContinents: raise IllegalContinentProperty(continent) pass def checkLegalCountry(country): """Check if a country is within the legal values Keyword arguments: country -- Country to be checked Returns None Examples: >>> checkLegalCountry('NO') >>> try: checkLegalCountry('JA') ... except IllegalCountryProperty: print 'Failing' Failing """ if country not in legalCountries: raise IllegalCountryProperty(country) pass def checkLegalNuts3(nuts3): """Check that a nuts3 is within legal values. Note that this will raise an exception no mather what, since we currently have no legal Nuts3 values. Keyword arguments: nuts3 -- Nuts3 value to be checked Returns None Examples: >>> checkLegalNuts3('UKM32') >>> try: checkLegalNuts3('UKM397') ... except IllegalNuts3Property: print 'Failing' Failing """ if nuts3 not in legalNuts3: raise IllegalNuts3Property(nuts3) pass def checkLegalNace(nace): """Check that a Nace code is within legal values Keyword arguements: nace -- Category to be check Returns None >>> checkLegalNace('84.11') >>> try: checkLegalNace('PU') ... except IllegalNaceProperty: print 'Failing' Failing """ if nace not in legalNace: raise IllegalNaceProperty(nace) if __name__ == "__main__": import doctest doctest.testmod()