Commit 05322189 by William Tisäter

Fix PEP8 violations and convert dos format to unix

parent 3c3225b9
# -*- 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
...@@ -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 Constants needed for parsing binary GeoIP databases. It is part of the pygeoip
package. package.
...@@ -30,321 +31,332 @@ GEOIP_STANDARD = 0 ...@@ -30,321 +31,332 @@ GEOIP_STANDARD = 0
GEOIP_MEMORY_CACHE = 1 GEOIP_MEMORY_CACHE = 1
DMA_MAP = { DMA_MAP = {
500 : 'Portland-Auburn, ME', 500: 'Portland-Auburn, ME',
501 : 'New York, NY', 501: 'New York, NY',
502 : 'Binghamton, NY', 502: 'Binghamton, NY',
503 : 'Macon, GA', 503: 'Macon, GA',
504 : 'Philadelphia, PA', 504: 'Philadelphia, PA',
505 : 'Detroit, MI', 505: 'Detroit, MI',
506 : 'Boston, MA', 506: 'Boston, MA',
507 : 'Savannah, GA', 507: 'Savannah, GA',
508 : 'Pittsburgh, PA', 508: 'Pittsburgh, PA',
509 : 'Ft Wayne, IN', 509: 'Ft Wayne, IN',
510 : 'Cleveland, OH', 510: 'Cleveland, OH',
511 : 'Washington, DC', 511: 'Washington, DC',
512 : 'Baltimore, MD', 512: 'Baltimore, MD',
513 : 'Flint, MI', 513: 'Flint, MI',
514 : 'Buffalo, NY', 514: 'Buffalo, NY',
515 : 'Cincinnati, OH', 515: 'Cincinnati, OH',
516 : 'Erie, PA', 516: 'Erie, PA',
517 : 'Charlotte, NC', 517: 'Charlotte, NC',
518 : 'Greensboro, NC', 518: 'Greensboro, NC',
519 : 'Charleston, SC', 519: 'Charleston, SC',
520 : 'Augusta, GA', 520: 'Augusta, GA',
521 : 'Providence, RI', 521: 'Providence, RI',
522 : 'Columbus, GA', 522: 'Columbus, GA',
523 : 'Burlington, VT', 523: 'Burlington, VT',
524 : 'Atlanta, GA', 524: 'Atlanta, GA',
525 : 'Albany, GA', 525: 'Albany, GA',
526 : 'Utica-Rome, NY', 526: 'Utica-Rome, NY',
527 : 'Indianapolis, IN', 527: 'Indianapolis, IN',
528 : 'Miami, FL', 528: 'Miami, FL',
529 : 'Louisville, KY', 529: 'Louisville, KY',
530 : 'Tallahassee, FL', 530: 'Tallahassee, FL',
531 : 'Tri-Cities, TN', 531: 'Tri-Cities, TN',
532 : 'Albany-Schenectady-Troy, NY', 532: 'Albany-Schenectady-Troy, NY',
533 : 'Hartford, CT', 533: 'Hartford, CT',
534 : 'Orlando, FL', 534: 'Orlando, FL',
535 : 'Columbus, OH', 535: 'Columbus, OH',
536 : 'Youngstown-Warren, OH', 536: 'Youngstown-Warren, OH',
537 : 'Bangor, ME', 537: 'Bangor, ME',
538 : 'Rochester, NY', 538: 'Rochester, NY',
539 : 'Tampa, FL', 539: 'Tampa, FL',
540 : 'Traverse City-Cadillac, MI', 540: 'Traverse City-Cadillac, MI',
541 : 'Lexington, KY', 541: 'Lexington, KY',
542 : 'Dayton, OH', 542: 'Dayton, OH',
543 : 'Springfield-Holyoke, MA', 543: 'Springfield-Holyoke, MA',
544 : 'Norfolk-Portsmouth, VA', 544: 'Norfolk-Portsmouth, VA',
545 : 'Greenville-New Bern-Washington, NC', 545: 'Greenville-New Bern-Washington, NC',
546 : 'Columbia, SC', 546: 'Columbia, SC',
547 : 'Toledo, OH', 547: 'Toledo, OH',
548 : 'West Palm Beach, FL', 548: 'West Palm Beach, FL',
549 : 'Watertown, NY', 549: 'Watertown, NY',
550 : 'Wilmington, NC', 550: 'Wilmington, NC',
551 : 'Lansing, MI', 551: 'Lansing, MI',
552 : 'Presque Isle, ME', 552: 'Presque Isle, ME',
553 : 'Marquette, MI', 553: 'Marquette, MI',
554 : 'Wheeling, WV', 554: 'Wheeling, WV',
555 : 'Syracuse, NY', 555: 'Syracuse, NY',
556 : 'Richmond-Petersburg, VA', 556: 'Richmond-Petersburg, VA',
557 : 'Knoxville, TN', 557: 'Knoxville, TN',
558 : 'Lima, OH', 558: 'Lima, OH',
559 : 'Bluefield-Beckley-Oak Hill, WV', 559: 'Bluefield-Beckley-Oak Hill, WV',
560 : 'Raleigh-Durham, NC', 560: 'Raleigh-Durham, NC',
561 : 'Jacksonville, FL', 561: 'Jacksonville, FL',
563 : 'Grand Rapids, MI', 563: 'Grand Rapids, MI',
564 : 'Charleston-Huntington, WV', 564: 'Charleston-Huntington, WV',
565 : 'Elmira, NY', 565: 'Elmira, NY',
566 : 'Harrisburg-Lancaster-Lebanon-York, PA', 566: 'Harrisburg-Lancaster-Lebanon-York, PA',
567 : 'Greenville-Spartenburg, SC', 567: 'Greenville-Spartenburg, SC',
569 : 'Harrisonburg, VA', 569: 'Harrisonburg, VA',
570 : 'Florence-Myrtle Beach, SC', 570: 'Florence-Myrtle Beach, SC',
571 : 'Ft Myers, FL', 571: 'Ft Myers, FL',
573 : 'Roanoke-Lynchburg, VA', 573: 'Roanoke-Lynchburg, VA',
574 : 'Johnstown-Altoona, PA', 574: 'Johnstown-Altoona, PA',
575 : 'Chattanooga, TN', 575: 'Chattanooga, TN',
576 : 'Salisbury, MD', 576: 'Salisbury, MD',
577 : 'Wilkes Barre-Scranton, PA', 577: 'Wilkes Barre-Scranton, PA',
581 : 'Terre Haute, IN', 581: 'Terre Haute, IN',
582 : 'Lafayette, IN', 582: 'Lafayette, IN',
583 : 'Alpena, MI', 583: 'Alpena, MI',
584 : 'Charlottesville, VA', 584: 'Charlottesville, VA',
588 : 'South Bend, IN', 588: 'South Bend, IN',
592 : 'Gainesville, FL', 592: 'Gainesville, FL',
596 : 'Zanesville, OH', 596: 'Zanesville, OH',
597 : 'Parkersburg, WV', 597: 'Parkersburg, WV',
598 : 'Clarksburg-Weston, WV', 598: 'Clarksburg-Weston, WV',
600 : 'Corpus Christi, TX', 600: 'Corpus Christi, TX',
602 : 'Chicago, IL', 602: 'Chicago, IL',
603 : 'Joplin-Pittsburg, MO', 603: 'Joplin-Pittsburg, MO',
604 : 'Columbia-Jefferson City, MO', 604: 'Columbia-Jefferson City, MO',
605 : 'Topeka, KS', 605: 'Topeka, KS',
606 : 'Dothan, AL', 606: 'Dothan, AL',
609 : 'St Louis, MO', 609: 'St Louis, MO',
610 : 'Rockford, IL', 610: 'Rockford, IL',
611 : 'Rochester-Mason City-Austin, MN', 611: 'Rochester-Mason City-Austin, MN',
612 : 'Shreveport, LA', 612: 'Shreveport, LA',
613 : 'Minneapolis-St Paul, MN', 613: 'Minneapolis-St Paul, MN',
616 : 'Kansas City, MO', 616: 'Kansas City, MO',
617 : 'Milwaukee, WI', 617: 'Milwaukee, WI',
618 : 'Houston, TX', 618: 'Houston, TX',
619 : 'Springfield, MO', 619: 'Springfield, MO',
620 : 'Tuscaloosa, AL', 620: 'Tuscaloosa, AL',
622 : 'New Orleans, LA', 622: 'New Orleans, LA',
623 : 'Dallas-Fort Worth, TX', 623: 'Dallas-Fort Worth, TX',
624 : 'Sioux City, IA', 624: 'Sioux City, IA',
625 : 'Waco-Temple-Bryan, TX', 625: 'Waco-Temple-Bryan, TX',
626 : 'Victoria, TX', 626: 'Victoria, TX',
627 : 'Wichita Falls, TX', 627: 'Wichita Falls, TX',
628 : 'Monroe, LA', 628: 'Monroe, LA',
630 : 'Birmingham, AL', 630: 'Birmingham, AL',
631 : 'Ottumwa-Kirksville, IA', 631: 'Ottumwa-Kirksville, IA',
632 : 'Paducah, KY', 632: 'Paducah, KY',
633 : 'Odessa-Midland, TX', 633: 'Odessa-Midland, TX',
634 : 'Amarillo, TX', 634: 'Amarillo, TX',
635 : 'Austin, TX', 635: 'Austin, TX',
636 : 'Harlingen, TX', 636: 'Harlingen, TX',
637 : 'Cedar Rapids-Waterloo, IA', 637: 'Cedar Rapids-Waterloo, IA',
638 : 'St Joseph, MO', 638: 'St Joseph, MO',
639 : 'Jackson, TN', 639: 'Jackson, TN',
640 : 'Memphis, TN', 640: 'Memphis, TN',
641 : 'San Antonio, TX', 641: 'San Antonio, TX',
642 : 'Lafayette, LA', 642: 'Lafayette, LA',
643 : 'Lake Charles, LA', 643: 'Lake Charles, LA',
644 : 'Alexandria, LA', 644: 'Alexandria, LA',
646 : 'Anniston, AL', 646: 'Anniston, AL',
647 : 'Greenwood-Greenville, MS', 647: 'Greenwood-Greenville, MS',
648 : 'Champaign-Springfield-Decatur, IL', 648: 'Champaign-Springfield-Decatur, IL',
649 : 'Evansville, IN', 649: 'Evansville, IN',
650 : 'Oklahoma City, OK', 650: 'Oklahoma City, OK',
651 : 'Lubbock, TX', 651: 'Lubbock, TX',
652 : 'Omaha, NE', 652: 'Omaha, NE',
656 : 'Panama City, FL', 656: 'Panama City, FL',
657 : 'Sherman, TX', 657: 'Sherman, TX',
658 : 'Green Bay-Appleton, WI', 658: 'Green Bay-Appleton, WI',
659 : 'Nashville, TN', 659: 'Nashville, TN',
661 : 'San Angelo, TX', 661: 'San Angelo, TX',
662 : 'Abilene-Sweetwater, TX', 662: 'Abilene-Sweetwater, TX',
669 : 'Madison, WI', 669: 'Madison, WI',
670 : 'Ft Smith-Fay-Springfield, AR', 670: 'Ft Smith-Fay-Springfield, AR',
671 : 'Tulsa, OK', 671: 'Tulsa, OK',
673 : 'Columbus-Tupelo-West Point, MS', 673: 'Columbus-Tupelo-West Point, MS',
675 : 'Peoria-Bloomington, IL', 675: 'Peoria-Bloomington, IL',
676 : 'Duluth, MN', 676: 'Duluth, MN',
678 : 'Wichita, KS', 678: 'Wichita, KS',
679 : 'Des Moines, IA', 679: 'Des Moines, IA',
682 : 'Davenport-Rock Island-Moline, IL', 682: 'Davenport-Rock Island-Moline, IL',
686 : 'Mobile, AL', 686: 'Mobile, AL',
687 : 'Minot-Bismarck-Dickinson, ND', 687: 'Minot-Bismarck-Dickinson, ND',
691 : 'Huntsville, AL', 691: 'Huntsville, AL',
692 : 'Beaumont-Port Author, TX', 692: 'Beaumont-Port Author, TX',
693 : 'Little Rock-Pine Bluff, AR', 693: 'Little Rock-Pine Bluff, AR',
698 : 'Montgomery, AL', 698: 'Montgomery, AL',
702 : 'La Crosse-Eau Claire, WI', 702: 'La Crosse-Eau Claire, WI',
705 : 'Wausau-Rhinelander, WI', 705: 'Wausau-Rhinelander, WI',
709 : 'Tyler-Longview, TX', 709: 'Tyler-Longview, TX',
710 : 'Hattiesburg-Laurel, MS', 710: 'Hattiesburg-Laurel, MS',
711 : 'Meridian, MS', 711: 'Meridian, MS',
716 : 'Baton Rouge, LA', 716: 'Baton Rouge, LA',
717 : 'Quincy, IL', 717: 'Quincy, IL',
718 : 'Jackson, MS', 718: 'Jackson, MS',
722 : 'Lincoln-Hastings, NE', 722: 'Lincoln-Hastings, NE',
724 : 'Fargo-Valley City, ND', 724: 'Fargo-Valley City, ND',
725 : 'Sioux Falls, SD', 725: 'Sioux Falls, SD',
734 : 'Jonesboro, AR', 734: 'Jonesboro, AR',
736 : 'Bowling Green, KY', 736: 'Bowling Green, KY',
737 : 'Mankato, MN', 737: 'Mankato, MN',
740 : 'North Platte, NE', 740: 'North Platte, NE',
743 : 'Anchorage, AK', 743: 'Anchorage, AK',
744 : 'Honolulu, HI', 744: 'Honolulu, HI',
745 : 'Fairbanks, AK', 745: 'Fairbanks, AK',
746 : 'Biloxi-Gulfport, MS', 746: 'Biloxi-Gulfport, MS',
747 : 'Juneau, AK', 747: 'Juneau, AK',
749 : 'Laredo, TX', 749: 'Laredo, TX',
751 : 'Denver, CO', 751: 'Denver, CO',
752 : 'Colorado Springs, CO', 752: 'Colorado Springs, CO',
753 : 'Phoenix, AZ', 753: 'Phoenix, AZ',
754 : 'Butte-Bozeman, MT', 754: 'Butte-Bozeman, MT',
755 : 'Great Falls, MT', 755: 'Great Falls, MT',
756 : 'Billings, MT', 756: 'Billings, MT',
757 : 'Boise, ID', 757: 'Boise, ID',
758 : 'Idaho Falls-Pocatello, ID', 758: 'Idaho Falls-Pocatello, ID',
759 : 'Cheyenne, WY', 759: 'Cheyenne, WY',
760 : 'Twin Falls, ID', 760: 'Twin Falls, ID',
762 : 'Missoula, MT', 762: 'Missoula, MT',
764 : 'Rapid City, SD', 764: 'Rapid City, SD',
765 : 'El Paso, TX', 765: 'El Paso, TX',
766 : 'Helena, MT', 766: 'Helena, MT',
767 : 'Casper-Riverton, WY', 767: 'Casper-Riverton, WY',
770 : 'Salt Lake City, UT', 770: 'Salt Lake City, UT',
771 : 'Yuma, AZ', 771: 'Yuma, AZ',
773 : 'Grand Junction, CO', 773: 'Grand Junction, CO',
789 : 'Tucson, AZ', 789: 'Tucson, AZ',
790 : 'Albuquerque, NM', 790: 'Albuquerque, NM',
798 : 'Glendive, MT', 798: 'Glendive, MT',
800 : 'Bakersfield, CA', 800: 'Bakersfield, CA',
801 : 'Eugene, OR', 801: 'Eugene, OR',
802 : 'Eureka, CA', 802: 'Eureka, CA',
803 : 'Los Angeles, CA', 803: 'Los Angeles, CA',
804 : 'Palm Springs, CA', 804: 'Palm Springs, CA',
807 : 'San Francisco, CA', 807: 'San Francisco, CA',
810 : 'Yakima-Pasco, WA', 810: 'Yakima-Pasco, WA',
811 : 'Reno, NV', 811: 'Reno, NV',
813 : 'Medford-Klamath Falls, OR', 813: 'Medford-Klamath Falls, OR',
819 : 'Seattle-Tacoma, WA', 819: 'Seattle-Tacoma, WA',
820 : 'Portland, OR', 820: 'Portland, OR',
821 : 'Bend, OR', 821: 'Bend, OR',
825 : 'San Diego, CA', 825: 'San Diego, CA',
828 : 'Monterey-Salinas, CA', 828: 'Monterey-Salinas, CA',
839 : 'Las Vegas, NV', 839: 'Las Vegas, NV',
855 : 'Santa Barbara, CA', 855: 'Santa Barbara, CA',
862 : 'Sacramento, CA', 862: 'Sacramento, CA',
866 : 'Fresno, CA', 866: 'Fresno, CA',
868 : 'Chico-Redding, CA', 868: 'Chico-Redding, CA',
881 : 'Spokane, WA' 881: 'Spokane, WA'
} }
COUNTRY_CODES = ( COUNTRY_CODES = (
'', 'AP', 'EU', 'AD', 'AE', 'AF', 'AG', 'AI', 'AL', 'AM', 'AN', 'AO', 'AQ', '',
'AR', 'AS', 'AT', 'AU', 'AW', 'AZ', 'BA', 'BB', 'BD', 'BE', 'BF', 'BG', 'BH', 'AP', 'EU', 'AD', 'AE', 'AF', 'AG', 'AI', 'AL', 'AM', 'AN', 'AO', 'AQ',
'BI', 'BJ', 'BM', 'BN', 'BO', 'BR', 'BS', 'BT', 'BV', 'BW', 'BY', 'BZ', 'CA', 'AR', 'AS', 'AT', 'AU', 'AW', 'AZ', 'BA', 'BB', 'BD', 'BE', 'BF', 'BG',
'CC', 'CD', 'CF', 'CG', 'CH', 'CI', 'CK', 'CL', 'CM', 'CN', 'CO', 'CR', 'CU', 'BH', 'BI', 'BJ', 'BM', 'BN', 'BO', 'BR', 'BS', 'BT', 'BV', 'BW', 'BY',
'CV', 'CX', 'CY', 'CZ', 'DE', 'DJ', 'DK', 'DM', 'DO', 'DZ', 'EC', 'EE', 'EG', 'BZ', 'CA', 'CC', 'CD', 'CF', 'CG', 'CH', 'CI', 'CK', 'CL', 'CM', 'CN',
'EH', 'ER', 'ES', 'ET', 'FI', 'FJ', 'FK', 'FM', 'FO', 'FR', 'FX', 'GA', 'GB', 'CO', 'CR', 'CU', 'CV', 'CX', 'CY', 'CZ', 'DE', 'DJ', 'DK', 'DM', 'DO',
'GD', 'GE', 'GF', 'GH', 'GI', 'GL', 'GM', 'GN', 'GP', 'GQ', 'GR', 'GS', 'GT', 'DZ', 'EC', 'EE', 'EG', 'EH', 'ER', 'ES', 'ET', 'FI', 'FJ', 'FK', 'FM',
'GU', 'GW', 'GY', 'HK', 'HM', 'HN', 'HR', 'HT', 'HU', 'ID', 'IE', 'IL', 'IN', 'FO', 'FR', 'FX', 'GA', 'GB', 'GD', 'GE', 'GF', 'GH', 'GI', 'GL', 'GM',
'IO', 'IQ', 'IR', 'IS', 'IT', 'JM', 'JO', 'JP', 'KE', 'KG', 'KH', 'KI', 'KM', 'GN', 'GP', 'GQ', 'GR', 'GS', 'GT', 'GU', 'GW', 'GY', 'HK', 'HM', 'HN',
'KN', 'KP', 'KR', 'KW', 'KY', 'KZ', 'LA', 'LB', 'LC', 'LI', 'LK', 'LR', 'LS', 'HR', 'HT', 'HU', 'ID', 'IE', 'IL', 'IN', 'IO', 'IQ', 'IR', 'IS', 'IT',
'LT', 'LU', 'LV', 'LY', 'MA', 'MC', 'MD', 'MG', 'MH', 'MK', 'ML', 'MM', 'MN', 'JM', 'JO', 'JP', 'KE', 'KG', 'KH', 'KI', 'KM', 'KN', 'KP', 'KR', 'KW',
'MO', 'MP', 'MQ', 'MR', 'MS', 'MT', 'MU', 'MV', 'MW', 'MX', 'MY', 'MZ', 'NA', 'KY', 'KZ', 'LA', 'LB', 'LC', 'LI', 'LK', 'LR', 'LS', 'LT', 'LU', 'LV',
'NC', 'NE', 'NF', 'NG', 'NI', 'NL', 'NO', 'NP', 'NR', 'NU', 'NZ', 'OM', 'PA', 'LY', 'MA', 'MC', 'MD', 'MG', 'MH', 'MK', 'ML', 'MM', 'MN', 'MO', 'MP',
'PE', 'PF', 'PG', 'PH', 'PK', 'PL', 'PM', 'PN', 'PR', 'PS', 'PT', 'PW', 'PY', 'MQ', 'MR', 'MS', 'MT', 'MU', 'MV', 'MW', 'MX', 'MY', 'MZ', 'NA', 'NC',
'QA', 'RE', 'RO', 'RU', 'RW', 'SA', 'SB', 'SC', 'SD', 'SE', 'SG', 'SH', 'SI', 'NE', 'NF', 'NG', 'NI', 'NL', 'NO', 'NP', 'NR', 'NU', 'NZ', 'OM', 'PA',
'SJ', 'SK', 'SL', 'SM', 'SN', 'SO', 'SR', 'ST', 'SV', 'SY', 'SZ', 'TC', 'TD', 'PE', 'PF', 'PG', 'PH', 'PK', 'PL', 'PM', 'PN', 'PR', 'PS', 'PT', 'PW',
'TF', 'TG', 'TH', 'TJ', 'TK', 'TM', 'TN', 'TO', 'TL', 'TR', 'TT', 'TV', 'TW', 'PY', 'QA', 'RE', 'RO', 'RU', 'RW', 'SA', 'SB', 'SC', 'SD', 'SE', 'SG',
'TZ', 'UA', 'UG', 'UM', 'US', 'UY', 'UZ', 'VA', 'VC', 'VE', 'VG', 'VI', 'VN', 'SH', 'SI', 'SJ', 'SK', 'SL', 'SM', 'SN', 'SO', 'SR', 'ST', 'SV', 'SY',
'VU', 'WF', 'WS', 'YE', 'YT', 'RS', 'ZA', 'ZM', 'ME', 'ZW', 'A1', 'A2', 'O1', 'SZ', 'TC', 'TD', 'TF', 'TG', 'TH', 'TJ', 'TK', 'TM', 'TN', 'TO', 'TL',
'AX', 'GG', 'IM', 'JE', 'BL', 'MF' 'TR', 'TT', 'TV', 'TW', 'TZ', 'UA', 'UG', 'UM', 'US', 'UY', 'UZ', 'VA',
) 'VC', 'VE', 'VG', 'VI', 'VN', 'VU', 'WF', 'WS', 'YE', 'YT', 'RS', 'ZA',
'ZM', 'ME', 'ZW', 'A1', 'A2', 'O1', 'AX', 'GG', 'IM', 'JE', 'BL', 'MF'
)
COUNTRY_CODES3 = ( COUNTRY_CODES3 = (
'','AP','EU','AND','ARE','AFG','ATG','AIA','ALB','ARM','ANT','AGO','AQ','ARG', '', 'AP', 'EU', 'AND', 'ARE', 'AFG', 'ATG', 'AIA', 'ALB', 'ARM', 'ANT',
'ASM','AUT','AUS','ABW','AZE','BIH','BRB','BGD','BEL','BFA','BGR','BHR','BDI', 'AGO', 'AQ', 'ARG', 'ASM', 'AUT', 'AUS', 'ABW', 'AZE', 'BIH', 'BRB', 'BGD',
'BEN','BMU','BRN','BOL','BRA','BHS','BTN','BV','BWA','BLR','BLZ','CAN','CC', 'BEL', 'BFA', 'BGR', 'BHR', 'BDI', 'BEN', 'BMU', 'BRN', 'BOL', 'BRA',
'COD','CAF','COG','CHE','CIV','COK','CHL','CMR','CHN','COL','CRI','CUB','CPV', 'BHS', 'BTN', 'BV', 'BWA', 'BLR', 'BLZ', 'CAN', 'CC', 'COD', 'CAF', 'COG',
'CX','CYP','CZE','DEU','DJI','DNK','DMA','DOM','DZA','ECU','EST','EGY','ESH', 'CHE', 'CIV', 'COK', 'CHL', 'CMR', 'CHN', 'COL', 'CRI', 'CUB', 'CPV', 'CX',
'ERI','ESP','ETH','FIN','FJI','FLK','FSM','FRO','FRA','FX','GAB','GBR','GRD', 'CYP', 'CZE', 'DEU', 'DJI', 'DNK', 'DMA', 'DOM', 'DZA', 'ECU', 'EST',
'GEO','GUF','GHA','GIB','GRL','GMB','GIN','GLP','GNQ','GRC','GS','GTM','GUM', 'EGY', 'ESH', 'ERI', 'ESP', 'ETH', 'FIN', 'FJI', 'FLK', 'FSM', 'FRO',
'GNB','GUY','HKG','HM','HND','HRV','HTI','HUN','IDN','IRL','ISR','IND','IO', 'FRA', 'FX', 'GAB', 'GBR', 'GRD', 'GEO', 'GUF', 'GHA', 'GIB', 'GRL', 'GMB',
'IRQ','IRN','ISL','ITA','JAM','JOR','JPN','KEN','KGZ','KHM','KIR','COM','KNA', 'GIN', 'GLP', 'GNQ', 'GRC', 'GS', 'GTM', 'GUM', 'GNB', 'GUY', 'HKG', 'HM',
'PRK','KOR','KWT','CYM','KAZ','LAO','LBN','LCA','LIE','LKA','LBR','LSO','LTU', 'HND', 'HRV', 'HTI', 'HUN', 'IDN', 'IRL', 'ISR', 'IND', 'IO', 'IRQ', 'IRN',
'LUX','LVA','LBY','MAR','MCO','MDA','MDG','MHL','MKD','MLI','MMR','MNG','MAC', 'ISL', 'ITA', 'JAM', 'JOR', 'JPN', 'KEN', 'KGZ', 'KHM', 'KIR', 'COM',
'MNP','MTQ','MRT','MSR','MLT','MUS','MDV','MWI','MEX','MYS','MOZ','NAM','NCL', 'KNA', 'PRK', 'KOR', 'KWT', 'CYM', 'KAZ', 'LAO', 'LBN', 'LCA', 'LIE',
'NER','NFK','NGA','NIC','NLD','NOR','NPL','NRU','NIU','NZL','OMN','PAN','PER', 'LKA', 'LBR', 'LSO', 'LTU', 'LUX', 'LVA', 'LBY', 'MAR', 'MCO', 'MDA',
'PYF','PNG','PHL','PAK','POL','SPM','PCN','PRI','PSE','PRT','PLW','PRY','QAT', 'MDG', 'MHL', 'MKD', 'MLI', 'MMR', 'MNG', 'MAC', 'MNP', 'MTQ', 'MRT',
'REU','ROU','RUS','RWA','SAU','SLB','SYC','SDN','SWE','SGP','SHN','SVN','SJM', 'MSR', 'MLT', 'MUS', 'MDV', 'MWI', 'MEX', 'MYS', 'MOZ', 'NAM', 'NCL',
'SVK','SLE','SMR','SEN','SOM','SUR','STP','SLV','SYR','SWZ','TCA','TCD','TF', 'NER', 'NFK', 'NGA', 'NIC', 'NLD', 'NOR', 'NPL', 'NRU', 'NIU', 'NZL',
'TGO','THA','TJK','TKL','TLS','TKM','TUN','TON','TUR','TTO','TUV','TWN','TZA', 'OMN', 'PAN', 'PER', 'PYF', 'PNG', 'PHL', 'PAK', 'POL', 'SPM', 'PCN',
'UKR','UGA','UM','USA','URY','UZB','VAT','VCT','VEN','VGB','VIR','VNM','VUT', 'PRI', 'PSE', 'PRT', 'PLW', 'PRY', 'QAT', 'REU', 'ROU', 'RUS', 'RWA',
'WLF','WSM','YEM','YT','SRB','ZAF','ZMB','MNE','ZWE','A1','A2','O1', 'SAU', 'SLB', 'SYC', 'SDN', 'SWE', 'SGP', 'SHN', 'SVN', 'SJM', 'SVK',
'ALA','GGY','IMN','JEY','BLM','MAF' 'SLE', 'SMR', 'SEN', 'SOM', 'SUR', 'STP', 'SLV', 'SYR', 'SWZ', 'TCA',
) 'TCD', 'TF', 'TGO', 'THA', 'TJK', 'TKL', 'TLS', 'TKM', 'TUN', 'TON', 'TUR',
'TTO', 'TUV', 'TWN', 'TZA', 'UKR', 'UGA', 'UM', 'USA', 'URY', 'UZB', 'VAT',
'VCT', 'VEN', 'VGB', 'VIR', 'VNM', 'VUT', 'WLF', 'WSM', 'YEM', 'YT', 'SRB',
'ZAF', 'ZMB', 'MNE', 'ZWE', 'A1', 'A2', 'O1', 'ALA', 'GGY', 'IMN', 'JEY',
'BLM', 'MAF'
)
COUNTRY_NAMES = ( COUNTRY_NAMES = (
"", "Asia/Pacific Region", "Europe", "Andorra", "United Arab Emirates", '', 'Asia/Pacific Region', 'Europe', 'Andorra', 'United Arab Emirates',
"Afghanistan", "Antigua and Barbuda", "Anguilla", "Albania", "Armenia", 'Afghanistan', 'Antigua and Barbuda', 'Anguilla', 'Albania', 'Armenia',
"Netherlands Antilles", "Angola", "Antarctica", "Argentina", "American Samoa", 'Netherlands Antilles', 'Angola', 'Antarctica', 'Argentina',
"Austria", "Australia", "Aruba", "Azerbaijan", "Bosnia and Herzegovina", 'American Samoa', 'Austria', 'Australia', 'Aruba', 'Azerbaijan',
"Barbados", "Bangladesh", "Belgium", "Burkina Faso", "Bulgaria", "Bahrain", 'Bosnia and Herzegovina', 'Barbados', 'Bangladesh', 'Belgium',
"Burundi", "Benin", "Bermuda", "Brunei Darussalam", "Bolivia", "Brazil", 'Burkina Faso', 'Bulgaria', 'Bahrain', 'Burundi', 'Benin', 'Bermuda',
"Bahamas", "Bhutan", "Bouvet Island", "Botswana", "Belarus", "Belize", 'Brunei Darussalam', 'Bolivia', 'Brazil', 'Bahamas', 'Bhutan',
"Canada", "Cocos (Keeling) Islands", "Congo, The Democratic Republic of the", 'Bouvet Island', 'Botswana', 'Belarus', 'Belize', 'Canada',
"Central African Republic", "Congo", "Switzerland", "Cote D'Ivoire", "Cook Islands", 'Cocos (Keeling) Islands', 'Congo, The Democratic Republic of the',
"Chile", "Cameroon", "China", "Colombia", "Costa Rica", "Cuba", "Cape Verde", 'Central African Republic', 'Congo', 'Switzerland', 'Cote D\'Ivoire',
"Christmas Island", "Cyprus", "Czech Republic", "Germany", "Djibouti", 'Cook Islands', 'Chile', 'Cameroon', 'China', 'Colombia', 'Costa Rica',
"Denmark", "Dominica", "Dominican Republic", "Algeria", "Ecuador", "Estonia", 'Cuba', 'Cape Verde', 'Christmas Island', 'Cyprus', 'Czech Republic',
"Egypt", "Western Sahara", "Eritrea", "Spain", "Ethiopia", "Finland", "Fiji", 'Germany', 'Djibouti', 'Denmark', 'Dominica', 'Dominican Republic',
"Falkland Islands (Malvinas)", "Micronesia, Federated States of", "Faroe Islands", 'Algeria', 'Ecuador', 'Estonia', 'Egypt', 'Western Sahara', 'Eritrea',
"France", "France, Metropolitan", "Gabon", "United Kingdom", 'Spain', 'Ethiopia', 'Finland', 'Fiji', 'Falkland Islands (Malvinas)',
"Grenada", "Georgia", "French Guiana", "Ghana", "Gibraltar", "Greenland", 'Micronesia, Federated States of', 'Faroe Islands', 'France',
"Gambia", "Guinea", "Guadeloupe", "Equatorial Guinea", "Greece", 'France, Metropolitan', 'Gabon', 'United Kingdom', 'Grenada', 'Georgia',
"South Georgia and the South Sandwich Islands", 'French Guiana', 'Ghana', 'Gibraltar', 'Greenland', 'Gambia', 'Guinea',
"Guatemala", "Guam", "Guinea-Bissau", 'Guadeloupe', 'Equatorial Guinea', 'Greece',
"Guyana", "Hong Kong", "Heard Island and McDonald Islands", "Honduras", 'South Georgia and the South Sandwich Islands', 'Guatemala', 'Guam',
"Croatia", "Haiti", "Hungary", "Indonesia", "Ireland", "Israel", "India", 'Guinea-Bissau', 'Guyana', 'Hong Kong',
"British Indian Ocean Territory", "Iraq", "Iran, Islamic Republic of", 'Heard Island and McDonald Islands', 'Honduras', 'Croatia', 'Haiti',
"Iceland", "Italy", "Jamaica", "Jordan", "Japan", "Kenya", "Kyrgyzstan", 'Hungary', 'Indonesia', 'Ireland', 'Israel', 'India',
"Cambodia", "Kiribati", "Comoros", "Saint Kitts and Nevis", 'British Indian Ocean Territory', 'Iraq', 'Iran, Islamic Republic of',
"Korea, Democratic People's Republic of", 'Iceland', 'Italy', 'Jamaica', 'Jordan', 'Japan', 'Kenya', 'Kyrgyzstan',
"Korea, Republic of", "Kuwait", "Cayman Islands", 'Cambodia', 'Kiribati', 'Comoros', 'Saint Kitts and Nevis',
"Kazakhstan", "Lao People's Democratic Republic", "Lebanon", "Saint Lucia", 'Korea, Democratic People\'s Republic of', 'Korea, Republic of', 'Kuwait',
"Liechtenstein", "Sri Lanka", "Liberia", "Lesotho", "Lithuania", "Luxembourg", 'Cayman Islands', 'Kazakhstan', 'Lao People\'s Democratic Republic',
"Latvia", "Libya", "Morocco", "Monaco", "Moldova, Republic of", 'Lebanon', 'Saint Lucia', 'Liechtenstein', 'Sri Lanka', 'Liberia',
"Madagascar", "Marshall Islands", "Macedonia", 'Lesotho', 'Lithuania', 'Luxembourg', 'Latvia', 'Libya', 'Morocco',
"Mali", "Myanmar", "Mongolia", "Macau", "Northern Mariana Islands", 'Monaco', 'Moldova, Republic of', 'Madagascar', 'Marshall Islands',
"Martinique", "Mauritania", "Montserrat", "Malta", "Mauritius", "Maldives", 'Macedonia', 'Mali', 'Myanmar', 'Mongolia', 'Macau',
"Malawi", "Mexico", "Malaysia", "Mozambique", "Namibia", "New Caledonia", 'Northern Mariana Islands', 'Martinique', 'Mauritania', 'Montserrat',
"Niger", "Norfolk Island", "Nigeria", "Nicaragua", "Netherlands", "Norway", 'Malta', 'Mauritius', 'Maldives', 'Malawi', 'Mexico', 'Malaysia',
"Nepal", "Nauru", "Niue", "New Zealand", "Oman", "Panama", "Peru", "French Polynesia", 'Mozambique', 'Namibia', 'New Caledonia', 'Niger', 'Norfolk Island',
"Papua New Guinea", "Philippines", "Pakistan", "Poland", "Saint Pierre and Miquelon", 'Nigeria', 'Nicaragua', 'Netherlands', 'Norway', 'Nepal', 'Nauru', 'Niue',
"Pitcairn Islands", "Puerto Rico", "Palestinian Territory", 'New Zealand', 'Oman', 'Panama', 'Peru', 'French Polynesia',
"Portugal", "Palau", "Paraguay", "Qatar", "Reunion", "Romania", 'Papua New Guinea', 'Philippines', 'Pakistan', 'Poland',
"Russian Federation", "Rwanda", "Saudi Arabia", "Solomon Islands", 'Saint Pierre and Miquelon', 'Pitcairn Islands', 'Puerto Rico',
"Seychelles", "Sudan", "Sweden", "Singapore", "Saint Helena", "Slovenia", 'Palestinian Territory', 'Portugal', 'Palau', 'Paraguay', 'Qatar',
"Svalbard and Jan Mayen", "Slovakia", "Sierra Leone", "San Marino", "Senegal", 'Reunion', 'Romania', 'Russian Federation', 'Rwanda', 'Saudi Arabia',
"Somalia", "Suriname", "Sao Tome and Principe", "El Salvador", "Syrian Arab Republic", 'Solomon Islands', 'Seychelles', 'Sudan', 'Sweden', 'Singapore',
"Swaziland", "Turks and Caicos Islands", "Chad", "French Southern Territories", 'Saint Helena', 'Slovenia', 'Svalbard and Jan Mayen', 'Slovakia',
"Togo", "Thailand", "Tajikistan", "Tokelau", "Turkmenistan", 'Sierra Leone', 'San Marino', 'Senegal', 'Somalia', 'Suriname',
"Tunisia", "Tonga", "Timor-Leste", "Turkey", "Trinidad and Tobago", "Tuvalu", 'Sao Tome and Principe', 'El Salvador', 'Syrian Arab Republic',
"Taiwan", "Tanzania, United Republic of", "Ukraine", 'Swaziland', 'Turks and Caicos Islands', 'Chad',
"Uganda", "United States Minor Outlying Islands", "United States", "Uruguay", 'French Southern Territories', 'Togo', 'Thailand', 'Tajikistan', 'Tokelau',
"Uzbekistan", "Holy See (Vatican City State)", "Saint Vincent and the Grenadines", 'Turkmenistan', 'Tunisia', 'Tonga', 'Timor-Leste', 'Turkey',
"Venezuela", "Virgin Islands, British", "Virgin Islands, U.S.", 'Trinidad and Tobago', 'Tuvalu', 'Taiwan', 'Tanzania, United Republic of',
"Vietnam", "Vanuatu", "Wallis and Futuna", "Samoa", "Yemen", "Mayotte", 'Ukraine', 'Uganda', 'United States Minor Outlying Islands',
"Serbia", "South Africa", "Zambia", "Montenegro", "Zimbabwe", 'United States', 'Uruguay', 'Uzbekistan', 'Holy See (Vatican City State)',
"Anonymous Proxy","Satellite Provider","Other", 'Saint Vincent and the Grenadines', 'Venezuela', 'Virgin Islands, British',
"Aland Islands","Guernsey","Isle of Man","Jersey","Saint Barthelemy","Saint Martin" 'Virgin Islands, U.S.', 'Vietnam', 'Vanuatu', 'Wallis and Futuna', 'Samoa',
) 'Yemen', 'Mayotte', 'Serbia', 'South Africa', 'Zambia', 'Montenegro',
'Zimbabwe', 'Anonymous Proxy', 'Satellite Provider', 'Other',
'Aland Islands', 'Guernsey', 'Isle of Man', 'Jersey', 'Saint Barthelemy',
'Saint Martin'
)
# storage / caching flags # storage / caching flags
STANDARD = 0 STANDARD = 0
...@@ -390,5 +402,3 @@ US_OFFSET = 1 ...@@ -390,5 +402,3 @@ US_OFFSET = 1
CANADA_OFFSET = 677 CANADA_OFFSET = 677
WORLD_OFFSET = 1353 WORLD_OFFSET = 1353
FIPS_RANGE = 360 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