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
d4b10a72
Kaydet (Commit)
d4b10a72
authored
Tem 30, 2015
tarafından
Keryn Knight
Kaydeden (comit)
Tim Graham
Agu 31, 2015
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Refs #24121 -- Added a repr() to gis.GeoIP and gis.GeoIP2.
üst
9c40f01a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
1 deletion
+56
-1
base.py
django/contrib/gis/geoip/base.py
+12
-1
base.py
django/contrib/gis/geoip2/base.py
+10
-0
test_geoip.py
tests/gis_tests/test_geoip.py
+20
-0
test_geoip2.py
tests/gis_tests/test_geoip2.py
+14
-0
No files found.
django/contrib/gis/geoip/base.py
Dosyayı görüntüle @
d4b10a72
...
...
@@ -13,7 +13,7 @@ from django.contrib.gis.geoip.prototypes import (
from
django.core.validators
import
ipv4_re
from
django.utils
import
six
from
django.utils.deprecation
import
RemovedInDjango20Warning
from
django.utils.encoding
import
force_bytes
from
django.utils.encoding
import
force_bytes
,
force_text
# Regular expressions for recognizing the GeoIP free database editions.
free_regex
=
re
.
compile
(
r'^GEO-\d{3}FREE'
)
...
...
@@ -145,6 +145,17 @@ class GeoIP(object):
if
self
.
_city
:
GeoIP_delete
(
self
.
_city
)
def
__repr__
(
self
):
version
=
''
if
GeoIP_lib_version
is
not
None
:
version
+=
' [v
%
s]'
%
force_text
(
GeoIP_lib_version
())
return
'<
%(cls)
s
%(version)
s _country_file="
%(country)
s", _city_file="
%(city)
s">'
%
{
'cls'
:
self
.
__class__
.
__name__
,
'version'
:
version
,
'country'
:
self
.
_country_file
,
'city'
:
self
.
_city_file
,
}
def
_check_query
(
self
,
query
,
country
=
False
,
city
=
False
,
city_or_country
=
False
):
"Helper routine for checking the query and database availability."
# Making sure a string was passed in for the query.
...
...
django/contrib/gis/geoip2/base.py
Dosyayı görüntüle @
d4b10a72
...
...
@@ -133,6 +133,16 @@ class GeoIP2(object):
if
self
.
_reader
:
self
.
_reader
.
close
()
def
__repr__
(
self
):
meta
=
self
.
_reader
.
metadata
()
version
=
'[v
%
s.
%
s]'
%
(
meta
.
binary_format_major_version
,
meta
.
binary_format_minor_version
)
return
'<
%(cls)
s
%(version)
s _country_file="
%(country)
s", _city_file="
%(city)
s">'
%
{
'cls'
:
self
.
__class__
.
__name__
,
'version'
:
version
,
'country'
:
self
.
_country_file
,
'city'
:
self
.
_city_file
,
}
def
_check_query
(
self
,
query
,
country
=
False
,
city
=
False
,
city_or_country
=
False
):
"Helper routine for checking the query and database availability."
# Making sure a string was passed in for the query.
...
...
tests/gis_tests/test_geoip.py
Dosyayı görüntüle @
d4b10a72
...
...
@@ -8,10 +8,12 @@ from unittest import skipUnless
from
django.conf
import
settings
from
django.contrib.gis.geoip
import
HAS_GEOIP
from
django.contrib.gis.geoip.prototypes
import
GeoIP_lib_version
from
django.contrib.gis.geos
import
HAS_GEOS
,
GEOSGeometry
from
django.test
import
ignore_warnings
from
django.utils
import
six
from
django.utils.deprecation
import
RemovedInDjango20Warning
from
django.utils.encoding
import
force_text
if
HAS_GEOIP
:
from
django.contrib.gis.geoip
import
GeoIP
,
GeoIPException
...
...
@@ -128,3 +130,21 @@ class GeoIPTest(unittest.TestCase):
self
.
assertEqual
(
len
(
warns
),
1
)
msg
=
str
(
warns
[
0
]
.
message
)
self
.
assertIn
(
'django.contrib.gis.geoip is deprecated'
,
msg
)
def
test_repr
(
self
):
path
=
settings
.
GEOIP_PATH
g
=
GeoIP
(
path
=
path
)
country_path
=
g
.
_country_file
city_path
=
g
.
_city_file
if
GeoIP_lib_version
:
expected
=
'<GeoIP [v
%(version)
s] _country_file="
%(country)
s", _city_file="
%(city)
s">'
%
{
'version'
:
force_text
(
GeoIP_lib_version
()),
'country'
:
country_path
,
'city'
:
city_path
,
}
else
:
expected
=
'<GeoIP _country_file="
%(country)
s", _city_file="
%(city)
s">'
%
{
'country'
:
country_path
,
'city'
:
city_path
,
}
self
.
assertEqual
(
repr
(
g
),
expected
)
tests/gis_tests/test_geoip2.py
Dosyayı görüntüle @
d4b10a72
...
...
@@ -137,3 +137,17 @@ class GeoIPTest(unittest.TestCase):
self
.
assertEqual
(
'US'
,
d
[
'country_code'
])
self
.
assertEqual
(
'Lawrence'
,
d
[
'city'
])
self
.
assertEqual
(
'KS'
,
d
[
'region'
])
def
test_repr
(
self
):
path
=
settings
.
GEOIP_PATH
g
=
GeoIP2
(
path
=
path
)
meta
=
g
.
_reader
.
metadata
()
version
=
'
%
s.
%
s'
%
(
meta
.
binary_format_major_version
,
meta
.
binary_format_minor_version
)
country_path
=
g
.
_country_file
city_path
=
g
.
_city_file
expected
=
'<GeoIP2 [v
%(version)
s] _country_file="
%(country)
s", _city_file="
%(city)
s">'
%
{
'version'
:
version
,
'country'
:
country_path
,
'city'
:
city_path
,
}
self
.
assertEqual
(
repr
(
g
),
expected
)
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