Mercurial > hg > config
view python/address.py @ 694:ebca6d85213a
File "/usr/lib/python3/dist-packages/IPython/config/__init__.py", line 16, in <module>
from .application import *
File "/usr/lib/python3/dist-packages/IPython/config/application.py", line 31, in <module>
from IPython.config.configurable import SingletonConfigurable
File "/usr/lib/python3/dist-packages/IPython/config/configurable.py", line 33, in <module>
from IPython.utils.text import indent, wrap_paragraphs
File "/usr/lib/python3/dist-packages/IPython/utils/text.py", line 28, in <module>
from IPython.external.path import path
File "/usr/lib/python3/dist-packages/IPython/external/path/__init__.py", line 2, in <module>
from path import *
File "/home/jhammel/python/path.py", line 25
print root(path)
^
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Wed, 09 Jul 2014 16:26:49 -0700 |
parents | f3ab51c79813 |
children |
line wrap: on
line source
#!/usr/bin/python import sys from states import * def validate_zipcode(zip, zip4=None): """ validate a zipcode""" if not zip: # a non-existant zip-code is a valid zipcode # ... i think.... return True if '-' in zip: # in this case, split zip into zip5 + zip4 zip, zip4 = zip.split('-') zdict = { 'zip5': zip, 'zip4': zip4 } # if the 4-digit extension exists, add it to zip if zip4: zip += '-' + zip4 # validate zip code format for i in 5, 4: zstring = 'zip' + str(i) z = zdict.get(zstring, '') if z: if (not z.isdigit()) or (len(z) != i): return False return zip def normalizeaddress(query): """ returns normalize address, if it is an address """ # normalize the address query = ','.join([i.strip() for i in query.split('\n')]) querylist = [i.strip() for i in query.split(',')] lastentry = querylist[-1] if lastentry[-1].isdigit(): # it must be a zip code if lastentry[1].isalpha(): querylist = querylist[:-1] + lastentry.split() if not validate_zipcode(querylist[-1]): return False state = querylist[-2] else: state = querylist[-1] if not getstate(state): return False return ', '.join(querylist) def address(query): """ format an address -- query should be a string """ if __name__ == '__main__': i = normalizeaddress(' '.join(sys.argv[1:])) if i: print i else: print 'Not an address'