Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
7b00d902
Kaydet (Commit)
7b00d902
authored
May 10, 2013
tarafından
Claude Paroz
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
[py3] Made GeoIP tests pass with Python 3
üst
465a29ab
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
21 deletions
+17
-21
base.py
django/contrib/gis/geoip/base.py
+11
-14
prototypes.py
django/contrib/gis/geoip/prototypes.py
+6
-1
tests.py
django/contrib/gis/geoip/tests.py
+0
-6
No files found.
django/contrib/gis/geoip/base.py
Dosyayı görüntüle @
7b00d902
...
...
@@ -137,9 +137,6 @@ class GeoIP(object):
if
not
isinstance
(
query
,
six
.
string_types
):
raise
TypeError
(
'GeoIP query must be a string, not type
%
s'
%
type
(
query
)
.
__name__
)
# GeoIP only takes ASCII-encoded strings.
query
=
query
.
encode
(
'ascii'
)
# Extra checks for the existence of country and city databases.
if
city_or_country
and
not
(
self
.
_country
or
self
.
_city
):
raise
GeoIPException
(
'Invalid GeoIP country and city data files.'
)
...
...
@@ -148,8 +145,8 @@ class GeoIP(object):
elif
city
and
not
self
.
_city
:
raise
GeoIPException
(
'Invalid GeoIP city data file:
%
s'
%
self
.
_city_file
)
# Return the query string back to the caller.
return
query
# Return the query string back to the caller.
GeoIP only takes bytestrings.
return
force_bytes
(
query
)
def
city
(
self
,
query
):
"""
...
...
@@ -157,33 +154,33 @@ class GeoIP(object):
Fully Qualified Domain Name (FQDN). Some information in the dictionary
may be undefined (None).
"""
query
=
self
.
_check_query
(
query
,
city
=
True
)
enc_
query
=
self
.
_check_query
(
query
,
city
=
True
)
if
ipv4_re
.
match
(
query
):
# If an IP address was passed in
return
GeoIP_record_by_addr
(
self
.
_city
,
c_char_p
(
query
))
return
GeoIP_record_by_addr
(
self
.
_city
,
c_char_p
(
enc_
query
))
else
:
# If a FQDN was passed in.
return
GeoIP_record_by_name
(
self
.
_city
,
c_char_p
(
query
))
return
GeoIP_record_by_name
(
self
.
_city
,
c_char_p
(
enc_
query
))
def
country_code
(
self
,
query
):
"Returns the country code for the given IP Address or FQDN."
query
=
self
.
_check_query
(
query
,
city_or_country
=
True
)
enc_
query
=
self
.
_check_query
(
query
,
city_or_country
=
True
)
if
self
.
_country
:
if
ipv4_re
.
match
(
query
):
return
GeoIP_country_code_by_addr
(
self
.
_country
,
query
)
return
GeoIP_country_code_by_addr
(
self
.
_country
,
enc_
query
)
else
:
return
GeoIP_country_code_by_name
(
self
.
_country
,
query
)
return
GeoIP_country_code_by_name
(
self
.
_country
,
enc_
query
)
else
:
return
self
.
city
(
query
)[
'country_code'
]
def
country_name
(
self
,
query
):
"Returns the country name for the given IP Address or FQDN."
query
=
self
.
_check_query
(
query
,
city_or_country
=
True
)
enc_
query
=
self
.
_check_query
(
query
,
city_or_country
=
True
)
if
self
.
_country
:
if
ipv4_re
.
match
(
query
):
return
GeoIP_country_name_by_addr
(
self
.
_country
,
query
)
return
GeoIP_country_name_by_addr
(
self
.
_country
,
enc_
query
)
else
:
return
GeoIP_country_name_by_name
(
self
.
_country
,
query
)
return
GeoIP_country_name_by_name
(
self
.
_country
,
enc_
query
)
else
:
return
self
.
city
(
query
)[
'country_name'
]
...
...
django/contrib/gis/geoip/prototypes.py
Dosyayı görüntüle @
7b00d902
...
...
@@ -92,7 +92,7 @@ def check_string(result, func, cargs):
free
(
result
)
else
:
s
=
''
return
s
return
s
.
decode
()
GeoIP_database_info
=
lgeoip
.
GeoIP_database_info
GeoIP_database_info
.
restype
=
geoip_char_p
...
...
@@ -100,7 +100,12 @@ GeoIP_database_info.errcheck = check_string
# String output routines.
def
string_output
(
func
):
def
_err_check
(
result
,
func
,
cargs
):
if
result
:
return
result
.
decode
()
return
result
func
.
restype
=
c_char_p
func
.
errcheck
=
_err_check
return
func
GeoIP_country_code_by_addr
=
string_output
(
lgeoip
.
GeoIP_country_code_by_addr
)
...
...
django/contrib/gis/geoip/tests.py
Dosyayı görüntüle @
7b00d902
...
...
@@ -106,12 +106,6 @@ class GeoIPTest(unittest.TestCase):
d
=
g
.
city
(
"www.osnabrueck.de"
)
self
.
assertEqual
(
'Osnabrück'
,
d
[
'city'
])
def
test06_unicode_query
(
self
):
"Testing that GeoIP accepts unicode string queries, see #17059."
g
=
GeoIP
()
d
=
g
.
country
(
'whitehouse.gov'
)
self
.
assertEqual
(
'US'
,
d
[
'country_code'
])
def
suite
():
s
=
unittest
.
TestSuite
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment