Commit 05322189 by William Tisäter

Fix PEP8 violations and convert dos format to unix

parent 3c3225b9
Just run: Just run:
python setup.py install python setup.py install
\ No newline at end of file
# Pure Python GeoIP API # # Pure Python GeoIP API #
The API is based on [MaxMind's C-based Python API](http://www.maxmind.com/app/python), The API is based on [MaxMind's C-based Python API](http://www.maxmind.com/app/python),
but the code itself is ported from the [Pure PHP GeoIP API](http://pear.php.net/package/Net_GeoIP) by Jim Winstead and Hans Lellelid. but the code itself is ported from the [Pure PHP GeoIP API](http://pear.php.net/package/Net_GeoIP) by Jim Winstead and Hans Lellelid.
It is mostly a drop-in replacement, except the `new` and `open` methods are gone. It is mostly a drop-in replacement, except the `new` and `open` methods are gone.
Tested using tox with Python version 2.5, 2.6, 2.7, 3.0 and 3.1. Tested using tox with Python version 2.5, 2.6, 2.7, 3.0 and 3.1.
## Issues and contribution ## ## Issues and contribution ##
Bug reports are done by [creating an issue on Github](https://github.com/appliedsec/pygeoip/issues). If you want to contribute you can always [create a pull request](https://github.com/appliedsec/pygeoip/pulls) for discussion and code submission. Bug reports are done by [creating an issue on Github](https://github.com/appliedsec/pygeoip/issues). If you want to contribute you can always [create a pull request](https://github.com/appliedsec/pygeoip/pulls) for discussion and code submission.
## Installation ## ## Installation ##
You can easily install pygeoip with setuptools: You can easily install pygeoip with setuptools:
easy_install pygeoip easy_install pygeoip
## Supported Databases ## ## Supported Databases ##
* Country * Country
* Region * Region
* City * City
* Organization * Organization
* ISP * ISP
## Quick Documentation ## ## Quick Documentation ##
Create your GeoIP instance with appropriate access flag. `STANDARD` reads data from disk when needed, `MEMORY_CACHE` loads database into memory on instantiation and `MMAP_CACHE` loads database into memory using mmap. Create your GeoIP instance with appropriate access flag. `STANDARD` reads data from disk when needed, `MEMORY_CACHE` loads database into memory on instantiation and `MMAP_CACHE` loads database into memory using mmap.
import pygeoip import pygeoip
gi = pygeoip.GeoIP('/path/to/GeoIP.dat', pygeoip.MEMORY_CACHE) gi = pygeoip.GeoIP('/path/to/GeoIP.dat', pygeoip.MEMORY_CACHE)
### Country lookup ### ### Country lookup ###
>>> gi.country_code_by_name('google.com') >>> gi.country_code_by_name('google.com')
'US' 'US'
>>> gi.country_code_by_addr('64.233.161.99') >>> gi.country_code_by_addr('64.233.161.99')
'US' 'US'
>>> gi.country_name_by_addr('64.233.161.99') >>> gi.country_name_by_addr('64.233.161.99')
'United States' 'United States'
### City lookup ### ### City lookup ###
>>> gic = pygeoip.GeoIP('/path/to/GeoIPCity.dat') >>> gic = pygeoip.GeoIP('/path/to/GeoIPCity.dat')
>>> gic.record_by_addr('64.233.161.99') >>> gic.record_by_addr('64.233.161.99')
{ {
'city': 'Mountain View', 'city': 'Mountain View',
'region_name': 'CA', 'region_name': 'CA',
'area_code': 650, 'area_code': 650,
'longitude': -122.0574, 'longitude': -122.0574,
'country_code3': 'USA', 'country_code3': 'USA',
'latitude': 37.419199999999989, 'latitude': 37.419199999999989,
'postal_code': '94043', 'postal_code': '94043',
'dma_code': 807, 'dma_code': 807,
'country_code': 'US', 'country_code': 'US',
'country_name': 'United States' 'country_name': 'United States'
} }
### Timezone lookup ### ### Timezone lookup ###
>>> gic = pygeoip.GeoIP('/path/to/GeoIPCity.dat') >>> gic = pygeoip.GeoIP('/path/to/GeoIPCity.dat')
>>> gic.time_zone_by_addr('64.233.161.99') >>> gic.time_zone_by_addr('64.233.161.99')
'America/Los_Angeles' 'America/Los_Angeles'
For more information, [check out the full API documentation](http://packages.python.org/pygeoip). For more information, [check out the full API documentation](http://packages.python.org/pygeoip).
\ No newline at end of file
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" """
Pure Python GeoIP API. The API is based off of U{MaxMind's C-based Python API<http://www.maxmind.com/app/python>}, Pure Python GeoIP API
but the code itself is based on the U{pure PHP5 API<http://pear.php.net/package/Net_GeoIP/>}
by Jim Winstead and Hans Lellelid.
It is mostly a drop-in replacement, except the The API is based on U{MaxMind's C-based Python
C{new} and C{open} methods are gone. You should instantiate the L{GeoIP} class yourself: API<http://www.maxmind.com/app/python>}, but the code itself is based on
the U{pure PHP5 API<http://pear.php.net/package/Net_GeoIP/>} by Jim Winstead
and Hans Lellelid.
It is mostly a drop-in replacement, except the C{new} and C{open} methods
are gone. You should instantiate the L{GeoIP} class yourself:
C{gi = GeoIP('/path/to/GeoIP.dat', pygeoip.MEMORY_CACHE)} C{gi = GeoIP('/path/to/GeoIP.dat', pygeoip.MEMORY_CACHE)}
...@@ -63,9 +66,9 @@ class GeoIPMetaclass(type): ...@@ -63,9 +66,9 @@ class GeoIPMetaclass(type):
""" """
Singleton method to gets an instance without reparsing the db. Unique Singleton method to gets an instance without reparsing the db. Unique
instances are instantiated based on the filename of the db. Flags are instances are instantiated based on the filename of the db. Flags are
ignored for this, i.e. if you initialize one with STANDARD flag (default) ignored for this, i.e. if you initialize one with STANDARD
and then try later to initialize with MEMORY_CACHE, it will still flag (default) and then try later to initialize with MEMORY_CACHE, it
return the STANDARD one. will still return the STANDARD one.
""" """
if not hasattr(cls, '_instances'): if not hasattr(cls, '_instances'):
...@@ -150,9 +153,9 @@ class GeoIP(GeoIPBase): ...@@ -150,9 +153,9 @@ class GeoIP(GeoIPBase):
for i in range(const.STRUCTURE_INFO_MAX_SIZE): for i in range(const.STRUCTURE_INFO_MAX_SIZE):
chars = chr(255) * 3 chars = chr(255) * 3
encoding = 'unicode_escape' flag = 'unicode_escape'
delim = self._filehandle.read(3) delim = self._filehandle.read(3)
if (delim == chars) if PY3 else (delim == unicode(chars, encoding)): if (delim == chars) if PY3 else (delim == unicode(chars, flag)):
self._databaseType = ord(self._filehandle.read(1)) self._databaseType = ord(self._filehandle.read(1))
# Backwards compatibility with databases from # Backwards compatibility with databases from
...@@ -277,7 +280,7 @@ class GeoIP(GeoIPBase): ...@@ -277,7 +280,7 @@ class GeoIP(GeoIPBase):
elif seek_region < const.CANADA_OFFSET: elif seek_region < const.CANADA_OFFSET:
country_code = 'US' country_code = 'US'
region = get_region_name(seek_region - const.US_OFFSET) region = get_region_name(seek_region - const.US_OFFSET)
elif seek_region < const.WORLD_OFFSET: elif seek_region < const.WORLD_OFFSET:
country_code = 'CA' country_code = 'CA'
region = get_region_name(seek_region - const.CANADA_OFFSET) region = get_region_name(seek_region - const.CANADA_OFFSET)
else: else:
...@@ -289,7 +292,7 @@ class GeoIP(GeoIPBase): ...@@ -289,7 +292,7 @@ class GeoIP(GeoIPBase):
country_code = rec['country_code'] if 'country_code' in rec else '' country_code = rec['country_code'] if 'country_code' in rec else ''
region = rec['region_name'] if 'region_name' in rec else '' region = rec['region_name'] if 'region_name' in rec else ''
return {'country_code' : country_code, 'region_name' : region } return {'country_code': country_code, 'region_name': region}
def _get_record(self, ipnum): def _get_record(self, ipnum):
""" """
...@@ -363,7 +366,7 @@ class GeoIP(GeoIPBase): ...@@ -363,7 +366,7 @@ class GeoIP(GeoIPBase):
if record['country_code'] == 'US': if record['country_code'] == 'US':
for j in range(3): for j in range(3):
char = ord(record_buf[record_buf_pos]) char = ord(record_buf[record_buf_pos])
dmaarea_combo += (char << (j*8)) dmaarea_combo += (char << (j * 8))
record_buf_pos += 1 record_buf_pos += 1
record['dma_code'] = int(math.floor(dmaarea_combo / 1000)) record['dma_code'] = int(math.floor(dmaarea_combo / 1000))
...@@ -422,13 +425,16 @@ class GeoIP(GeoIPBase): ...@@ -422,13 +425,16 @@ class GeoIP(GeoIPBase):
@rtype: str @rtype: str
""" """
try: try:
COUNTRY_EDITIONS = (const.COUNTRY_EDITION, const.COUNTRY_EDITION_V6) VALID_EDITIONS = (const.COUNTRY_EDITION, const.COUNTRY_EDITION_V6)
if self._databaseType in COUNTRY_EDITIONS: if self._databaseType in VALID_EDITIONS:
ipv = 6 if addr.find(':') >= 0 else 4 ipv = 6 if addr.find(':') >= 0 else 4
if ipv == 4 and self._databaseType != const.COUNTRY_EDITION: if ipv == 4 and self._databaseType != const.COUNTRY_EDITION:
raise ValueError('Invalid database type; expected IPv6 address') message = 'Invalid database type; expected IPv6 address'
raise ValueError(message)
if ipv == 6 and self._databaseType != const.COUNTRY_EDITION_V6: if ipv == 6 and self._databaseType != const.COUNTRY_EDITION_V6:
raise ValueError('Invalid database type; expected IPv4 address') message = 'Invalid database type; expected IPv4 address'
raise ValueError(message)
country_id = self.id_by_addr(addr) country_id = self.id_by_addr(addr)
...@@ -465,8 +471,8 @@ class GeoIP(GeoIPBase): ...@@ -465,8 +471,8 @@ class GeoIP(GeoIPBase):
@rtype: str @rtype: str
""" """
try: try:
COUNTRY_EDITIONS = (const.COUNTRY_EDITION, const.COUNTRY_EDITION_V6) VALID_EDITIONS = (const.COUNTRY_EDITION, const.COUNTRY_EDITION_V6)
if self._databaseType in COUNTRY_EDITIONS: if self._databaseType in VALID_EDITIONS:
return const.COUNTRY_NAMES[self.id_by_addr(addr)] return const.COUNTRY_NAMES[self.id_by_addr(addr)]
elif self._databaseType in const.CITY_EDITIONS: elif self._databaseType in const.CITY_EDITIONS:
return self.record_by_addr(addr)['country_name'] return self.record_by_addr(addr)['country_name']
......
""" # -*- coding: utf-8 -*-
Constants needed for parsing binary GeoIP databases. It is part of the pygeoip """
package. Constants needed for parsing binary GeoIP databases. It is part of the pygeoip
package.
@author: Jennifer Ennis <zaylea at gmail dot com>
@author: Jennifer Ennis <zaylea at gmail dot com>
@license:
Copyright(C) 2004 MaxMind LLC @license:
Copyright(C) 2004 MaxMind LLC
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by This program is free software: you can redistribute it and/or modify
the Free Software Foundation, either version 3 of the License, or it under the terms of the GNU Lesser General Public License as published by
(at your option) any later version. the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of This program is distributed in the hope that it will be useful,
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the but WITHOUT ANY WARRANTY; without even the implied warranty of
GNU General Public License for more details. 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 Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/lgpl.txt>. You should have received a copy of the GNU Lesser General Public License
""" along with this program. If not, see <http://www.gnu.org/licenses/lgpl.txt>.
"""
from platform import python_version_tuple
from platform import python_version_tuple
PY2 = python_version_tuple()[0] == '2'
PY3 = python_version_tuple()[0] == '3' PY2 = python_version_tuple()[0] == '2'
PY3 = python_version_tuple()[0] == '3'
GEOIP_STANDARD = 0
GEOIP_MEMORY_CACHE = 1 GEOIP_STANDARD = 0
GEOIP_MEMORY_CACHE = 1
DMA_MAP = {
500 : 'Portland-Auburn, ME', DMA_MAP = {
501 : 'New York, NY', 500: 'Portland-Auburn, ME',
502 : 'Binghamton, NY', 501: 'New York, NY',
503 : 'Macon, GA', 502: 'Binghamton, NY',
504 : 'Philadelphia, PA', 503: 'Macon, GA',
505 : 'Detroit, MI', 504: 'Philadelphia, PA',
506 : 'Boston, MA', 505: 'Detroit, MI',
507 : 'Savannah, GA', 506: 'Boston, MA',
508 : 'Pittsburgh, PA', 507: 'Savannah, GA',
509 : 'Ft Wayne, IN', 508: 'Pittsburgh, PA',
510 : 'Cleveland, OH', 509: 'Ft Wayne, IN',
511 : 'Washington, DC', 510: 'Cleveland, OH',
512 : 'Baltimore, MD', 511: 'Washington, DC',
513 : 'Flint, MI', 512: 'Baltimore, MD',
514 : 'Buffalo, NY', 513: 'Flint, MI',
515 : 'Cincinnati, OH', 514: 'Buffalo, NY',
516 : 'Erie, PA', 515: 'Cincinnati, OH',
517 : 'Charlotte, NC', 516: 'Erie, PA',
518 : 'Greensboro, NC', 517: 'Charlotte, NC',
519 : 'Charleston, SC', 518: 'Greensboro, NC',
520 : 'Augusta, GA', 519: 'Charleston, SC',
521 : 'Providence, RI', 520: 'Augusta, GA',
522 : 'Columbus, GA', 521: 'Providence, RI',
523 : 'Burlington, VT', 522: 'Columbus, GA',
524 : 'Atlanta, GA', 523: 'Burlington, VT',
525 : 'Albany, GA', 524: 'Atlanta, GA',
526 : 'Utica-Rome, NY', 525: 'Albany, GA',
527 : 'Indianapolis, IN', 526: 'Utica-Rome, NY',
528 : 'Miami, FL', 527: 'Indianapolis, IN',
529 : 'Louisville, KY', 528: 'Miami, FL',
530 : 'Tallahassee, FL', 529: 'Louisville, KY',
531 : 'Tri-Cities, TN', 530: 'Tallahassee, FL',
532 : 'Albany-Schenectady-Troy, NY', 531: 'Tri-Cities, TN',
533 : 'Hartford, CT', 532: 'Albany-Schenectady-Troy, NY',
534 : 'Orlando, FL', 533: 'Hartford, CT',
535 : 'Columbus, OH', 534: 'Orlando, FL',
536 : 'Youngstown-Warren, OH', 535: 'Columbus, OH',
537 : 'Bangor, ME', 536: 'Youngstown-Warren, OH',
538 : 'Rochester, NY', 537: 'Bangor, ME',
539 : 'Tampa, FL', 538: 'Rochester, NY',
540 : 'Traverse City-Cadillac, MI', 539: 'Tampa, FL',
541 : 'Lexington, KY', 540: 'Traverse City-Cadillac, MI',
542 : 'Dayton, OH', 541: 'Lexington, KY',
543 : 'Springfield-Holyoke, MA', 542: 'Dayton, OH',
544 : 'Norfolk-Portsmouth, VA', 543: 'Springfield-Holyoke, MA',
545 : 'Greenville-New Bern-Washington, NC', 544: 'Norfolk-Portsmouth, VA',
546 : 'Columbia, SC', 545: 'Greenville-New Bern-Washington, NC',
547 : 'Toledo, OH', 546: 'Columbia, SC',
548 : 'West Palm Beach, FL', 547: 'Toledo, OH',
549 : 'Watertown, NY', 548: 'West Palm Beach, FL',
550 : 'Wilmington, NC', 549: 'Watertown, NY',
551 : 'Lansing, MI', 550: 'Wilmington, NC',
552 : 'Presque Isle, ME', 551: 'Lansing, MI',
553 : 'Marquette, MI', 552: 'Presque Isle, ME',
554 : 'Wheeling, WV', 553: 'Marquette, MI',
555 : 'Syracuse, NY', 554: 'Wheeling, WV',
556 : 'Richmond-Petersburg, VA', 555: 'Syracuse, NY',
557 : 'Knoxville, TN', 556: 'Richmond-Petersburg, VA',
558 : 'Lima, OH', 557: 'Knoxville, TN',
559 : 'Bluefield-Beckley-Oak Hill, WV', 558: 'Lima, OH',
560 : 'Raleigh-Durham, NC', 559: 'Bluefield-Beckley-Oak Hill, WV',
561 : 'Jacksonville, FL', 560: 'Raleigh-Durham, NC',
563 : 'Grand Rapids, MI', 561: 'Jacksonville, FL',
564 : 'Charleston-Huntington, WV', 563: 'Grand Rapids, MI',
565 : 'Elmira, NY', 564: 'Charleston-Huntington, WV',
566 : 'Harrisburg-Lancaster-Lebanon-York, PA', 565: 'Elmira, NY',
567 : 'Greenville-Spartenburg, SC', 566: 'Harrisburg-Lancaster-Lebanon-York, PA',
569 : 'Harrisonburg, VA', 567: 'Greenville-Spartenburg, SC',
570 : 'Florence-Myrtle Beach, SC', 569: 'Harrisonburg, VA',
571 : 'Ft Myers, FL', 570: 'Florence-Myrtle Beach, SC',
573 : 'Roanoke-Lynchburg, VA', 571: 'Ft Myers, FL',
574 : 'Johnstown-Altoona, PA', 573: 'Roanoke-Lynchburg, VA',
575 : 'Chattanooga, TN', 574: 'Johnstown-Altoona, PA',
576 : 'Salisbury, MD', 575: 'Chattanooga, TN',
577 : 'Wilkes Barre-Scranton, PA', 576: 'Salisbury, MD',
581 : 'Terre Haute, IN', 577: 'Wilkes Barre-Scranton, PA',
582 : 'Lafayette, IN', 581: 'Terre Haute, IN',
583 : 'Alpena, MI', 582: 'Lafayette, IN',
584 : 'Charlottesville, VA', 583: 'Alpena, MI',
588 : 'South Bend, IN', 584: 'Charlottesville, VA',
592 : 'Gainesville, FL', 588: 'South Bend, IN',
596 : 'Zanesville, OH', 592: 'Gainesville, FL',
597 : 'Parkersburg, WV', 596: 'Zanesville, OH',
598 : 'Clarksburg-Weston, WV', 597: 'Parkersburg, WV',
600 : 'Corpus Christi, TX', 598: 'Clarksburg-Weston, WV',
602 : 'Chicago, IL', 600: 'Corpus Christi, TX',
603 : 'Joplin-Pittsburg, MO', 602: 'Chicago, IL',
604 : 'Columbia-Jefferson City, MO', 603: 'Joplin-Pittsburg, MO',
605 : 'Topeka, KS', 604: 'Columbia-Jefferson City, MO',
606 : 'Dothan, AL', 605: 'Topeka, KS',
609 : 'St Louis, MO', 606: 'Dothan, AL',
610 : 'Rockford, IL', 609: 'St Louis, MO',
611 : 'Rochester-Mason City-Austin, MN', 610: 'Rockford, IL',
612 : 'Shreveport, LA', 611: 'Rochester-Mason City-Austin, MN',
613 : 'Minneapolis-St Paul, MN', 612: 'Shreveport, LA',
616 : 'Kansas City, MO', 613: 'Minneapolis-St Paul, MN',
617 : 'Milwaukee, WI', 616: 'Kansas City, MO',
618 : 'Houston, TX', 617: 'Milwaukee, WI',
619 : 'Springfield, MO', 618: 'Houston, TX',
620 : 'Tuscaloosa, AL', 619: 'Springfield, MO',
622 : 'New Orleans, LA', 620: 'Tuscaloosa, AL',
623 : 'Dallas-Fort Worth, TX', 622: 'New Orleans, LA',
624 : 'Sioux City, IA', 623: 'Dallas-Fort Worth, TX',
625 : 'Waco-Temple-Bryan, TX', 624: 'Sioux City, IA',
626 : 'Victoria, TX', 625: 'Waco-Temple-Bryan, TX',
627 : 'Wichita Falls, TX', 626: 'Victoria, TX',
628 : 'Monroe, LA', 627: 'Wichita Falls, TX',
630 : 'Birmingham, AL', 628: 'Monroe, LA',
631 : 'Ottumwa-Kirksville, IA', 630: 'Birmingham, AL',
632 : 'Paducah, KY', 631: 'Ottumwa-Kirksville, IA',
633 : 'Odessa-Midland, TX', 632: 'Paducah, KY',
634 : 'Amarillo, TX', 633: 'Odessa-Midland, TX',
635 : 'Austin, TX', 634: 'Amarillo, TX',
636 : 'Harlingen, TX', 635: 'Austin, TX',
637 : 'Cedar Rapids-Waterloo, IA', 636: 'Harlingen, TX',
638 : 'St Joseph, MO', 637: 'Cedar Rapids-Waterloo, IA',
639 : 'Jackson, TN', 638: 'St Joseph, MO',
640 : 'Memphis, TN', 639: 'Jackson, TN',
641 : 'San Antonio, TX', 640: 'Memphis, TN',
642 : 'Lafayette, LA', 641: 'San Antonio, TX',
643 : 'Lake Charles, LA', 642: 'Lafayette, LA',
644 : 'Alexandria, LA', 643: 'Lake Charles, LA',
646 : 'Anniston, AL', 644: 'Alexandria, LA',
647 : 'Greenwood-Greenville, MS', 646: 'Anniston, AL',
648 : 'Champaign-Springfield-Decatur, IL', 647: 'Greenwood-Greenville, MS',
649 : 'Evansville, IN', 648: 'Champaign-Springfield-Decatur, IL',
650 : 'Oklahoma City, OK', 649: 'Evansville, IN',
651 : 'Lubbock, TX', 650: 'Oklahoma City, OK',
652 : 'Omaha, NE', 651: 'Lubbock, TX',
656 : 'Panama City, FL', 652: 'Omaha, NE',
657 : 'Sherman, TX', 656: 'Panama City, FL',
658 : 'Green Bay-Appleton, WI', 657: 'Sherman, TX',
659 : 'Nashville, TN', 658: 'Green Bay-Appleton, WI',
661 : 'San Angelo, TX', 659: 'Nashville, TN',
662 : 'Abilene-Sweetwater, TX', 661: 'San Angelo, TX',
669 : 'Madison, WI', 662: 'Abilene-Sweetwater, TX',
670 : 'Ft Smith-Fay-Springfield, AR', 669: 'Madison, WI',
671 : 'Tulsa, OK', 670: 'Ft Smith-Fay-Springfield, AR',
673 : 'Columbus-Tupelo-West Point, MS', 671: 'Tulsa, OK',
675 : 'Peoria-Bloomington, IL', 673: 'Columbus-Tupelo-West Point, MS',
676 : 'Duluth, MN', 675: 'Peoria-Bloomington, IL',
678 : 'Wichita, KS', 676: 'Duluth, MN',
679 : 'Des Moines, IA', 678: 'Wichita, KS',
682 : 'Davenport-Rock Island-Moline, IL', 679: 'Des Moines, IA',
686 : 'Mobile, AL', 682: 'Davenport-Rock Island-Moline, IL',
687 : 'Minot-Bismarck-Dickinson, ND', 686: 'Mobile, AL',
691 : 'Huntsville, AL', 687: 'Minot-Bismarck-Dickinson, ND',
692 : 'Beaumont-Port Author, TX', 691: 'Huntsville, AL',
693 : 'Little Rock-Pine Bluff, AR', 692: 'Beaumont-Port Author, TX',
698 : 'Montgomery, AL', 693: 'Little Rock-Pine Bluff, AR',
702 : 'La Crosse-Eau Claire, WI', 698: 'Montgomery, AL',
705 : 'Wausau-Rhinelander, WI', 702: 'La Crosse-Eau Claire, WI',
709 : 'Tyler-Longview, TX', 705: 'Wausau-Rhinelander, WI',
710 : 'Hattiesburg-Laurel, MS', 709: 'Tyler-Longview, TX',
711 : 'Meridian, MS', 710: 'Hattiesburg-Laurel, MS',
716 : 'Baton Rouge, LA', 711: 'Meridian, MS',
717 : 'Quincy, IL', 716: 'Baton Rouge, LA',
718 : 'Jackson, MS', 717: 'Quincy, IL',
722 : 'Lincoln-Hastings, NE', 718: 'Jackson, MS',
724 : 'Fargo-Valley City, ND', 722: 'Lincoln-Hastings, NE',
725 : 'Sioux Falls, SD', 724: 'Fargo-Valley City, ND',
734 : 'Jonesboro, AR', 725: 'Sioux Falls, SD',
736 : 'Bowling Green, KY', 734: 'Jonesboro, AR',
737 : 'Mankato, MN', 736: 'Bowling Green, KY',
740 : 'North Platte, NE', 737: 'Mankato, MN',
743 : 'Anchorage, AK', 740: 'North Platte, NE',
744 : 'Honolulu, HI', 743: 'Anchorage, AK',
745 : 'Fairbanks, AK', 744: 'Honolulu, HI',
746 : 'Biloxi-Gulfport, MS', 745: 'Fairbanks, AK',
747 : 'Juneau, AK', 746: 'Biloxi-Gulfport, MS',
749 : 'Laredo, TX', 747: 'Juneau, AK',
751 : 'Denver, CO', 749: 'Laredo, TX',
752 : 'Colorado Springs, CO', 751: 'Denver, CO',
753 : 'Phoenix, AZ', 752: 'Colorado Springs, CO',
754 : 'Butte-Bozeman, MT', 753: 'Phoenix, AZ',
755 : 'Great Falls, MT', 754: 'Butte-Bozeman, MT',
756 : 'Billings, MT', 755: 'Great Falls, MT',
757 : 'Boise, ID', 756: 'Billings, MT',
758 : 'Idaho Falls-Pocatello, ID', 757: 'Boise, ID',
759 : 'Cheyenne, WY', 758: 'Idaho Falls-Pocatello, ID',
760 : 'Twin Falls, ID', 759: 'Cheyenne, WY',
762 : 'Missoula, MT', 760: 'Twin Falls, ID',
764 : 'Rapid City, SD', 762: 'Missoula, MT',
765 : 'El Paso, TX', 764: 'Rapid City, SD',
766 : 'Helena, MT', 765: 'El Paso, TX',
767 : 'Casper-Riverton, WY', 766: 'Helena, MT',
770 : 'Salt Lake City, UT', 767: 'Casper-Riverton, WY',
771 : 'Yuma, AZ', 770: 'Salt Lake City, UT',
773 : 'Grand Junction, CO', 771: 'Yuma, AZ',
789 : 'Tucson, AZ', 773: 'Grand Junction, CO',
790 : 'Albuquerque, NM', 789: 'Tucson, AZ',
798 : 'Glendive, MT', 790: 'Albuquerque, NM',
800 : 'Bakersfield, CA', 798: 'Glendive, MT',
801 : 'Eugene, OR', 800: 'Bakersfield, CA',
802 : 'Eureka, CA', 801: 'Eugene, OR',
803 : 'Los Angeles, CA', 802: 'Eureka, CA',
804 : 'Palm Springs, CA', 803: 'Los Angeles, CA',
807 : 'San Francisco, CA', 804: 'Palm Springs, CA',
810 : 'Yakima-Pasco, WA', 807: 'San Francisco, CA',
811 : 'Reno, NV', 810: 'Yakima-Pasco, WA',
813 : 'Medford-Klamath Falls, OR', 811: 'Reno, NV',
819 : 'Seattle-Tacoma, WA', 813: 'Medford-Klamath Falls, OR',
820 : 'Portland, OR', 819: 'Seattle-Tacoma, WA',
821 : 'Bend, OR', 820: 'Portland, OR',
825 : 'San Diego, CA', 821: 'Bend, OR',
828 : 'Monterey-Salinas, CA', 825: 'San Diego, CA',
839 : 'Las Vegas, NV', 828: 'Monterey-Salinas, CA',
855 : 'Santa Barbara, CA', 839: 'Las Vegas, NV',
862 : 'Sacramento, CA', 855: 'Santa Barbara, CA',
866 : 'Fresno, CA', 862: 'Sacramento, CA',
868 : 'Chico-Redding, CA', 866: 'Fresno, CA',
881 : 'Spokane, WA' 868: 'Chico-Redding, CA',
} 881: 'Spokane, WA'
}
COUNTRY_CODES = (
'', 'AP', 'EU', 'AD', 'AE', 'AF', 'AG', 'AI', 'AL', 'AM', 'AN', 'AO', 'AQ', COUNTRY_CODES = (
'AR', 'AS', 'AT', 'AU', 'AW', 'AZ', 'BA', 'BB', 'BD', 'BE', 'BF', 'BG', 'BH', '',
'BI', 'BJ', 'BM', 'BN', 'BO', 'BR', 'BS', 'BT', 'BV', 'BW', 'BY', 'BZ', 'CA', 'AP', 'EU', 'AD', 'AE', 'AF', 'AG', 'AI', 'AL', 'AM', 'AN', 'AO', 'AQ',
'CC', 'CD', 'CF', 'CG', 'CH', 'CI', 'CK', 'CL', 'CM', 'CN', 'CO', 'CR', 'CU', 'AR', 'AS', 'AT', 'AU', 'AW', 'AZ', 'BA', 'BB', 'BD', 'BE', 'BF', 'BG',
'CV', 'CX', 'CY', 'CZ', 'DE', 'DJ', 'DK', 'DM', 'DO', 'DZ', 'EC', 'EE', 'EG', 'BH', 'BI', 'BJ', 'BM', 'BN', 'BO', 'BR', 'BS', 'BT', 'BV', 'BW', 'BY',
'EH', 'ER', 'ES', 'ET', 'FI', 'FJ', 'FK', 'FM', 'FO', 'FR', 'FX', 'GA', 'GB', 'BZ', 'CA', 'CC', 'CD', 'CF', 'CG', 'CH', 'CI', 'CK', 'CL', 'CM', 'CN',
'GD', 'GE', 'GF', 'GH', 'GI', 'GL', 'GM', 'GN', 'GP', 'GQ', 'GR', 'GS', 'GT', 'CO', 'CR', 'CU', 'CV', 'CX', 'CY', 'CZ', 'DE', 'DJ', 'DK', 'DM', 'DO',
'GU', 'GW', 'GY', 'HK', 'HM', 'HN', 'HR', 'HT', 'HU', 'ID', 'IE', 'IL', 'IN', 'DZ', 'EC', 'EE', 'EG', 'EH', 'ER', 'ES', 'ET', 'FI', 'FJ', 'FK', 'FM',
'IO', 'IQ', 'IR', 'IS', 'IT', 'JM', 'JO', 'JP', 'KE', 'KG', 'KH', 'KI', 'KM', 'FO', 'FR', 'FX', 'GA', 'GB', 'GD', 'GE', 'GF', 'GH', 'GI', 'GL', 'GM',
'KN', 'KP', 'KR', 'KW', 'KY', 'KZ', 'LA', 'LB', 'LC', 'LI', 'LK', 'LR', 'LS', 'GN', 'GP', 'GQ', 'GR', 'GS', 'GT', 'GU', 'GW', 'GY', 'HK', 'HM', 'HN',
'LT', 'LU', 'LV', 'LY', 'MA', 'MC', 'MD', 'MG', 'MH', 'MK', 'ML', 'MM', 'MN', 'HR', 'HT', 'HU', 'ID', 'IE', 'IL', 'IN', 'IO', 'IQ', 'IR', 'IS', 'IT',
'MO', 'MP', 'MQ', 'MR', 'MS', 'MT', 'MU', 'MV', 'MW', 'MX', 'MY', 'MZ', 'NA', 'JM', 'JO', 'JP', 'KE', 'KG', 'KH', 'KI', 'KM', 'KN', 'KP', 'KR', 'KW',
'NC', 'NE', 'NF', 'NG', 'NI', 'NL', 'NO', 'NP', 'NR', 'NU', 'NZ', 'OM', 'PA', 'KY', 'KZ', 'LA', 'LB', 'LC', 'LI', 'LK', 'LR', 'LS', 'LT', 'LU', 'LV',
'PE', 'PF', 'PG', 'PH', 'PK', 'PL', 'PM', 'PN', 'PR', 'PS', 'PT', 'PW', 'PY', 'LY', 'MA', 'MC', 'MD', 'MG', 'MH', 'MK', 'ML', 'MM', 'MN', 'MO', 'MP',
'QA', 'RE', 'RO', 'RU', 'RW', 'SA', 'SB', 'SC', 'SD', 'SE', 'SG', 'SH', 'SI', 'MQ', 'MR', 'MS', 'MT', 'MU', 'MV', 'MW', 'MX', 'MY', 'MZ', 'NA', 'NC',
'SJ', 'SK', 'SL', 'SM', 'SN', 'SO', 'SR', 'ST', 'SV', 'SY', 'SZ', 'TC', 'TD', 'NE', 'NF', 'NG', 'NI', 'NL', 'NO', 'NP', 'NR', 'NU', 'NZ', 'OM', 'PA',
'TF', 'TG', 'TH', 'TJ', 'TK', 'TM', 'TN', 'TO', 'TL', 'TR', 'TT', 'TV', 'TW', 'PE', 'PF', 'PG', 'PH', 'PK', 'PL', 'PM', 'PN', 'PR', 'PS', 'PT', 'PW',
'TZ', 'UA', 'UG', 'UM', 'US', 'UY', 'UZ', 'VA', 'VC', 'VE', 'VG', 'VI', 'VN', 'PY', 'QA', 'RE', 'RO', 'RU', 'RW', 'SA', 'SB', 'SC', 'SD', 'SE', 'SG',
'VU', 'WF', 'WS', 'YE', 'YT', 'RS', 'ZA', 'ZM', 'ME', 'ZW', 'A1', 'A2', 'O1', 'SH', 'SI', 'SJ', 'SK', 'SL', 'SM', 'SN', 'SO', 'SR', 'ST', 'SV', 'SY',
'AX', 'GG', 'IM', 'JE', 'BL', 'MF' 'SZ', 'TC', 'TD', 'TF', 'TG', 'TH', 'TJ', 'TK', 'TM', 'TN', 'TO', 'TL',
) 'TR', 'TT', 'TV', 'TW', 'TZ', 'UA', 'UG', 'UM', 'US', 'UY', 'UZ', 'VA',
'VC', 'VE', 'VG', 'VI', 'VN', 'VU', 'WF', 'WS', 'YE', 'YT', 'RS', 'ZA',
COUNTRY_CODES3 = ( 'ZM', 'ME', 'ZW', 'A1', 'A2', 'O1', 'AX', 'GG', 'IM', 'JE', 'BL', 'MF'
'','AP','EU','AND','ARE','AFG','ATG','AIA','ALB','ARM','ANT','AGO','AQ','ARG', )
'ASM','AUT','AUS','ABW','AZE','BIH','BRB','BGD','BEL','BFA','BGR','BHR','BDI',
'BEN','BMU','BRN','BOL','BRA','BHS','BTN','BV','BWA','BLR','BLZ','CAN','CC', COUNTRY_CODES3 = (
'COD','CAF','COG','CHE','CIV','COK','CHL','CMR','CHN','COL','CRI','CUB','CPV', '', 'AP', 'EU', 'AND', 'ARE', 'AFG', 'ATG', 'AIA', 'ALB', 'ARM', 'ANT',
'CX','CYP','CZE','DEU','DJI','DNK','DMA','DOM','DZA','ECU','EST','EGY','ESH', 'AGO', 'AQ', 'ARG', 'ASM', 'AUT', 'AUS', 'ABW', 'AZE', 'BIH', 'BRB', 'BGD',
'ERI','ESP','ETH','FIN','FJI','FLK','FSM','FRO','FRA','FX','GAB','GBR','GRD', 'BEL', 'BFA', 'BGR', 'BHR', 'BDI', 'BEN', 'BMU', 'BRN', 'BOL', 'BRA',
'GEO','GUF','GHA','GIB','GRL','GMB','GIN','GLP','GNQ','GRC','GS','GTM','GUM', 'BHS', 'BTN', 'BV', 'BWA', 'BLR', 'BLZ', 'CAN', 'CC', 'COD', 'CAF', 'COG',
'GNB','GUY','HKG','HM','HND','HRV','HTI','HUN','IDN','IRL','ISR','IND','IO', 'CHE', 'CIV', 'COK', 'CHL', 'CMR', 'CHN', 'COL', 'CRI', 'CUB', 'CPV', 'CX',
'IRQ','IRN','ISL','ITA','JAM','JOR','JPN','KEN','KGZ','KHM','KIR','COM','KNA', 'CYP', 'CZE', 'DEU', 'DJI', 'DNK', 'DMA', 'DOM', 'DZA', 'ECU', 'EST',
'PRK','KOR','KWT','CYM','KAZ','LAO','LBN','LCA','LIE','LKA','LBR','LSO','LTU', 'EGY', 'ESH', 'ERI', 'ESP', 'ETH', 'FIN', 'FJI', 'FLK', 'FSM', 'FRO',
'LUX','LVA','LBY','MAR','MCO','MDA','MDG','MHL','MKD','MLI','MMR','MNG','MAC', 'FRA', 'FX', 'GAB', 'GBR', 'GRD', 'GEO', 'GUF', 'GHA', 'GIB', 'GRL', 'GMB',
'MNP','MTQ','MRT','MSR','MLT','MUS','MDV','MWI','MEX','MYS','MOZ','NAM','NCL', 'GIN', 'GLP', 'GNQ', 'GRC', 'GS', 'GTM', 'GUM', 'GNB', 'GUY', 'HKG', 'HM',
'NER','NFK','NGA','NIC','NLD','NOR','NPL','NRU','NIU','NZL','OMN','PAN','PER', 'HND', 'HRV', 'HTI', 'HUN', 'IDN', 'IRL', 'ISR', 'IND', 'IO', 'IRQ', 'IRN',
'PYF','PNG','PHL','PAK','POL','SPM','PCN','PRI','PSE','PRT','PLW','PRY','QAT', 'ISL', 'ITA', 'JAM', 'JOR', 'JPN', 'KEN', 'KGZ', 'KHM', 'KIR', 'COM',
'REU','ROU','RUS','RWA','SAU','SLB','SYC','SDN','SWE','SGP','SHN','SVN','SJM', 'KNA', 'PRK', 'KOR', 'KWT', 'CYM', 'KAZ', 'LAO', 'LBN', 'LCA', 'LIE',
'SVK','SLE','SMR','SEN','SOM','SUR','STP','SLV','SYR','SWZ','TCA','TCD','TF', 'LKA', 'LBR', 'LSO', 'LTU', 'LUX', 'LVA', 'LBY', 'MAR', 'MCO', 'MDA',
'TGO','THA','TJK','TKL','TLS','TKM','TUN','TON','TUR','TTO','TUV','TWN','TZA', 'MDG', 'MHL', 'MKD', 'MLI', 'MMR', 'MNG', 'MAC', 'MNP', 'MTQ', 'MRT',
'UKR','UGA','UM','USA','URY','UZB','VAT','VCT','VEN','VGB','VIR','VNM','VUT', 'MSR', 'MLT', 'MUS', 'MDV', 'MWI', 'MEX', 'MYS', 'MOZ', 'NAM', 'NCL',
'WLF','WSM','YEM','YT','SRB','ZAF','ZMB','MNE','ZWE','A1','A2','O1', 'NER', 'NFK', 'NGA', 'NIC', 'NLD', 'NOR', 'NPL', 'NRU', 'NIU', 'NZL',
'ALA','GGY','IMN','JEY','BLM','MAF' 'OMN', 'PAN', 'PER', 'PYF', 'PNG', 'PHL', 'PAK', 'POL', 'SPM', 'PCN',
) 'PRI', 'PSE', 'PRT', 'PLW', 'PRY', 'QAT', 'REU', 'ROU', 'RUS', 'RWA',
'SAU', 'SLB', 'SYC', 'SDN', 'SWE', 'SGP', 'SHN', 'SVN', 'SJM', 'SVK',
COUNTRY_NAMES = ( 'SLE', 'SMR', 'SEN', 'SOM', 'SUR', 'STP', 'SLV', 'SYR', 'SWZ', 'TCA',
"", "Asia/Pacific Region", "Europe", "Andorra", "United Arab Emirates", 'TCD', 'TF', 'TGO', 'THA', 'TJK', 'TKL', 'TLS', 'TKM', 'TUN', 'TON', 'TUR',
"Afghanistan", "Antigua and Barbuda", "Anguilla", "Albania", "Armenia", 'TTO', 'TUV', 'TWN', 'TZA', 'UKR', 'UGA', 'UM', 'USA', 'URY', 'UZB', 'VAT',
"Netherlands Antilles", "Angola", "Antarctica", "Argentina", "American Samoa", 'VCT', 'VEN', 'VGB', 'VIR', 'VNM', 'VUT', 'WLF', 'WSM', 'YEM', 'YT', 'SRB',
"Austria", "Australia", "Aruba", "Azerbaijan", "Bosnia and Herzegovina", 'ZAF', 'ZMB', 'MNE', 'ZWE', 'A1', 'A2', 'O1', 'ALA', 'GGY', 'IMN', 'JEY',
"Barbados", "Bangladesh", "Belgium", "Burkina Faso", "Bulgaria", "Bahrain", 'BLM', 'MAF'
"Burundi", "Benin", "Bermuda", "Brunei Darussalam", "Bolivia", "Brazil", )
"Bahamas", "Bhutan", "Bouvet Island", "Botswana", "Belarus", "Belize",
"Canada", "Cocos (Keeling) Islands", "Congo, The Democratic Republic of the", COUNTRY_NAMES = (
"Central African Republic", "Congo", "Switzerland", "Cote D'Ivoire", "Cook Islands", '', 'Asia/Pacific Region', 'Europe', 'Andorra', 'United Arab Emirates',
"Chile", "Cameroon", "China", "Colombia", "Costa Rica", "Cuba", "Cape Verde", 'Afghanistan', 'Antigua and Barbuda', 'Anguilla', 'Albania', 'Armenia',
"Christmas Island", "Cyprus", "Czech Republic", "Germany", "Djibouti", 'Netherlands Antilles', 'Angola', 'Antarctica', 'Argentina',
"Denmark", "Dominica", "Dominican Republic", "Algeria", "Ecuador", "Estonia", 'American Samoa', 'Austria', 'Australia', 'Aruba', 'Azerbaijan',
"Egypt", "Western Sahara", "Eritrea", "Spain", "Ethiopia", "Finland", "Fiji", 'Bosnia and Herzegovina', 'Barbados', 'Bangladesh', 'Belgium',
"Falkland Islands (Malvinas)", "Micronesia, Federated States of", "Faroe Islands", 'Burkina Faso', 'Bulgaria', 'Bahrain', 'Burundi', 'Benin', 'Bermuda',
"France", "France, Metropolitan", "Gabon", "United Kingdom", 'Brunei Darussalam', 'Bolivia', 'Brazil', 'Bahamas', 'Bhutan',
"Grenada", "Georgia", "French Guiana", "Ghana", "Gibraltar", "Greenland", 'Bouvet Island', 'Botswana', 'Belarus', 'Belize', 'Canada',
"Gambia", "Guinea", "Guadeloupe", "Equatorial Guinea", "Greece", 'Cocos (Keeling) Islands', 'Congo, The Democratic Republic of the',
"South Georgia and the South Sandwich Islands", 'Central African Republic', 'Congo', 'Switzerland', 'Cote D\'Ivoire',
"Guatemala", "Guam", "Guinea-Bissau", 'Cook Islands', 'Chile', 'Cameroon', 'China', 'Colombia', 'Costa Rica',
"Guyana", "Hong Kong", "Heard Island and McDonald Islands", "Honduras", 'Cuba', 'Cape Verde', 'Christmas Island', 'Cyprus', 'Czech Republic',
"Croatia", "Haiti", "Hungary", "Indonesia", "Ireland", "Israel", "India", 'Germany', 'Djibouti', 'Denmark', 'Dominica', 'Dominican Republic',
"British Indian Ocean Territory", "Iraq", "Iran, Islamic Republic of", 'Algeria', 'Ecuador', 'Estonia', 'Egypt', 'Western Sahara', 'Eritrea',
"Iceland", "Italy", "Jamaica", "Jordan", "Japan", "Kenya", "Kyrgyzstan", 'Spain', 'Ethiopia', 'Finland', 'Fiji', 'Falkland Islands (Malvinas)',
"Cambodia", "Kiribati", "Comoros", "Saint Kitts and Nevis", 'Micronesia, Federated States of', 'Faroe Islands', 'France',
"Korea, Democratic People's Republic of", 'France, Metropolitan', 'Gabon', 'United Kingdom', 'Grenada', 'Georgia',
"Korea, Republic of", "Kuwait", "Cayman Islands", 'French Guiana', 'Ghana', 'Gibraltar', 'Greenland', 'Gambia', 'Guinea',
"Kazakhstan", "Lao People's Democratic Republic", "Lebanon", "Saint Lucia", 'Guadeloupe', 'Equatorial Guinea', 'Greece',
"Liechtenstein", "Sri Lanka", "Liberia", "Lesotho", "Lithuania", "Luxembourg", 'South Georgia and the South Sandwich Islands', 'Guatemala', 'Guam',
"Latvia", "Libya", "Morocco", "Monaco", "Moldova, Republic of", 'Guinea-Bissau', 'Guyana', 'Hong Kong',
"Madagascar", "Marshall Islands", "Macedonia", 'Heard Island and McDonald Islands', 'Honduras', 'Croatia', 'Haiti',
"Mali", "Myanmar", "Mongolia", "Macau", "Northern Mariana Islands", 'Hungary', 'Indonesia', 'Ireland', 'Israel', 'India',
"Martinique", "Mauritania", "Montserrat", "Malta", "Mauritius", "Maldives", 'British Indian Ocean Territory', 'Iraq', 'Iran, Islamic Republic of',
"Malawi", "Mexico", "Malaysia", "Mozambique", "Namibia", "New Caledonia", 'Iceland', 'Italy', 'Jamaica', 'Jordan', 'Japan', 'Kenya', 'Kyrgyzstan',
"Niger", "Norfolk Island", "Nigeria", "Nicaragua", "Netherlands", "Norway", 'Cambodia', 'Kiribati', 'Comoros', 'Saint Kitts and Nevis',
"Nepal", "Nauru", "Niue", "New Zealand", "Oman", "Panama", "Peru", "French Polynesia", 'Korea, Democratic People\'s Republic of', 'Korea, Republic of', 'Kuwait',
"Papua New Guinea", "Philippines", "Pakistan", "Poland", "Saint Pierre and Miquelon", 'Cayman Islands', 'Kazakhstan', 'Lao People\'s Democratic Republic',
"Pitcairn Islands", "Puerto Rico", "Palestinian Territory", 'Lebanon', 'Saint Lucia', 'Liechtenstein', 'Sri Lanka', 'Liberia',
"Portugal", "Palau", "Paraguay", "Qatar", "Reunion", "Romania", 'Lesotho', 'Lithuania', 'Luxembourg', 'Latvia', 'Libya', 'Morocco',
"Russian Federation", "Rwanda", "Saudi Arabia", "Solomon Islands", 'Monaco', 'Moldova, Republic of', 'Madagascar', 'Marshall Islands',
"Seychelles", "Sudan", "Sweden", "Singapore", "Saint Helena", "Slovenia", 'Macedonia', 'Mali', 'Myanmar', 'Mongolia', 'Macau',
"Svalbard and Jan Mayen", "Slovakia", "Sierra Leone", "San Marino", "Senegal", 'Northern Mariana Islands', 'Martinique', 'Mauritania', 'Montserrat',
"Somalia", "Suriname", "Sao Tome and Principe", "El Salvador", "Syrian Arab Republic", 'Malta', 'Mauritius', 'Maldives', 'Malawi', 'Mexico', 'Malaysia',
"Swaziland", "Turks and Caicos Islands", "Chad", "French Southern Territories", 'Mozambique', 'Namibia', 'New Caledonia', 'Niger', 'Norfolk Island',
"Togo", "Thailand", "Tajikistan", "Tokelau", "Turkmenistan", 'Nigeria', 'Nicaragua', 'Netherlands', 'Norway', 'Nepal', 'Nauru', 'Niue',
"Tunisia", "Tonga", "Timor-Leste", "Turkey", "Trinidad and Tobago", "Tuvalu", 'New Zealand', 'Oman', 'Panama', 'Peru', 'French Polynesia',
"Taiwan", "Tanzania, United Republic of", "Ukraine", 'Papua New Guinea', 'Philippines', 'Pakistan', 'Poland',
"Uganda", "United States Minor Outlying Islands", "United States", "Uruguay", 'Saint Pierre and Miquelon', 'Pitcairn Islands', 'Puerto Rico',
"Uzbekistan", "Holy See (Vatican City State)", "Saint Vincent and the Grenadines", 'Palestinian Territory', 'Portugal', 'Palau', 'Paraguay', 'Qatar',
"Venezuela", "Virgin Islands, British", "Virgin Islands, U.S.", 'Reunion', 'Romania', 'Russian Federation', 'Rwanda', 'Saudi Arabia',
"Vietnam", "Vanuatu", "Wallis and Futuna", "Samoa", "Yemen", "Mayotte", 'Solomon Islands', 'Seychelles', 'Sudan', 'Sweden', 'Singapore',
"Serbia", "South Africa", "Zambia", "Montenegro", "Zimbabwe", 'Saint Helena', 'Slovenia', 'Svalbard and Jan Mayen', 'Slovakia',
"Anonymous Proxy","Satellite Provider","Other", 'Sierra Leone', 'San Marino', 'Senegal', 'Somalia', 'Suriname',
"Aland Islands","Guernsey","Isle of Man","Jersey","Saint Barthelemy","Saint Martin" 'Sao Tome and Principe', 'El Salvador', 'Syrian Arab Republic',
) 'Swaziland', 'Turks and Caicos Islands', 'Chad',
'French Southern Territories', 'Togo', 'Thailand', 'Tajikistan', 'Tokelau',
# storage / caching flags 'Turkmenistan', 'Tunisia', 'Tonga', 'Timor-Leste', 'Turkey',
STANDARD = 0 'Trinidad and Tobago', 'Tuvalu', 'Taiwan', 'Tanzania, United Republic of',
MEMORY_CACHE = 1 'Ukraine', 'Uganda', 'United States Minor Outlying Islands',
MMAP_CACHE = 8 'United States', 'Uruguay', 'Uzbekistan', 'Holy See (Vatican City State)',
'Saint Vincent and the Grenadines', 'Venezuela', 'Virgin Islands, British',
# Database structure constants 'Virgin Islands, U.S.', 'Vietnam', 'Vanuatu', 'Wallis and Futuna', 'Samoa',
COUNTRY_BEGIN = 16776960 'Yemen', 'Mayotte', 'Serbia', 'South Africa', 'Zambia', 'Montenegro',
STATE_BEGIN_REV0 = 16700000 'Zimbabwe', 'Anonymous Proxy', 'Satellite Provider', 'Other',
STATE_BEGIN_REV1 = 16000000 'Aland Islands', 'Guernsey', 'Isle of Man', 'Jersey', 'Saint Barthelemy',
'Saint Martin'
STRUCTURE_INFO_MAX_SIZE = 20 )
DATABASE_INFO_MAX_SIZE = 100
# storage / caching flags
# Database editions STANDARD = 0
COUNTRY_EDITION = 1 MEMORY_CACHE = 1
REGION_EDITION_REV0 = 7 MMAP_CACHE = 8
REGION_EDITION_REV1 = 3
CITY_EDITION_REV0 = 6 # Database structure constants
CITY_EDITION_REV1 = 2 COUNTRY_BEGIN = 16776960
ORG_EDITION = 5 STATE_BEGIN_REV0 = 16700000
ISP_EDITION = 4 STATE_BEGIN_REV1 = 16000000
ASNUM_EDITION = 9
# Not yet supported databases STRUCTURE_INFO_MAX_SIZE = 20
PROXY_EDITION = 8 DATABASE_INFO_MAX_SIZE = 100
NETSPEED_EDITION = 11
COUNTRY_EDITION_V6 = 12 # Database editions
COUNTRY_EDITION = 1
# Collection of databases REGION_EDITION_REV0 = 7
IPV6_EDITIONS = (COUNTRY_EDITION_V6,) REGION_EDITION_REV1 = 3
CITY_EDITIONS = (CITY_EDITION_REV0, CITY_EDITION_REV1) CITY_EDITION_REV0 = 6
REGION_EDITIONS = (REGION_EDITION_REV0, REGION_EDITION_REV1) CITY_EDITION_REV1 = 2
REGION_CITY_EDITIONS = REGION_EDITIONS + CITY_EDITIONS ORG_EDITION = 5
ISP_EDITION = 4
SEGMENT_RECORD_LENGTH = 3 ASNUM_EDITION = 9
STANDARD_RECORD_LENGTH = 3 # Not yet supported databases
ORG_RECORD_LENGTH = 4 PROXY_EDITION = 8
MAX_RECORD_LENGTH = 4 NETSPEED_EDITION = 11
MAX_ORG_RECORD_LENGTH = 300 COUNTRY_EDITION_V6 = 12
FULL_RECORD_LENGTH = 50
# Collection of databases
US_OFFSET = 1 IPV6_EDITIONS = (COUNTRY_EDITION_V6,)
CANADA_OFFSET = 677 CITY_EDITIONS = (CITY_EDITION_REV0, CITY_EDITION_REV1)
WORLD_OFFSET = 1353 REGION_EDITIONS = (REGION_EDITION_REV0, REGION_EDITION_REV1)
FIPS_RANGE = 360 REGION_CITY_EDITIONS = REGION_EDITIONS + CITY_EDITIONS
SEGMENT_RECORD_LENGTH = 3
STANDARD_RECORD_LENGTH = 3
ORG_RECORD_LENGTH = 4
MAX_RECORD_LENGTH = 4
MAX_ORG_RECORD_LENGTH = 300
FULL_RECORD_LENGTH = 50
US_OFFSET = 1
CANADA_OFFSET = 677
WORLD_OFFSET = 1353
FIPS_RANGE = 360
# -*- coding: utf-8 -*-
""" """
Misc. utility functions. It is part of the pygeoip package. Misc. utility functions. It is part of the pygeoip package.
...@@ -51,10 +52,11 @@ def ip2long_v4(ip): ...@@ -51,10 +52,11 @@ def ip2long_v4(ip):
ip_array = ip.split('.') ip_array = ip.split('.')
if PY3: if PY3:
# int and long are unified in py3 # int and long are unified in py3
ip_long = int(ip_array[0]) * 16777216 + int(ip_array[1]) * 65536 + int(ip_array[2]) * 256 + int(ip_array[3]) return int(ip_array[0]) * 16777216 + int(ip_array[1]) * 65536 + \
int(ip_array[2]) * 256 + int(ip_array[3])
else: else:
ip_long = long(ip_array[0]) * 16777216 + long(ip_array[1]) * 65536 + long(ip_array[2]) * 256 + long(ip_array[3]) return long(ip_array[0]) * 16777216 + long(ip_array[1]) * 65536 + \
return ip_long long(ip_array[2]) * 256 + long(ip_array[3])
def ip2long_v6(ip): def ip2long_v6(ip):
......
#!/usr/bin/env python #!/usr/bin/env python
""" """
Setup file for pygeoip package. Setup file for pygeoip package.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment