/usr/lib/python2.7/dist-packages/geopy/util.py is in python-geopy 1.3.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | """
Utils.
"""
import logging
from geopy.compat import py3k
if not py3k: # pragma: no cover
NUMBER_TYPES = (int, long, float)
else: # pragma: no cover
NUMBER_TYPES = (int, float) # long -> int in Py3k
try:
from decimal import Decimal
NUMBER_TYPES = NUMBER_TYPES + (Decimal, )
except ImportError: # pragma: no cover
pass
class NullHandler(logging.Handler):
"""
No output.
"""
def emit(self, record):
pass
logger = logging.getLogger('geopy') # pylint: disable=C0103
logger.setLevel(logging.CRITICAL)
def pairwise(seq):
"""
Pair an iterable, e.g., (1, 2, 3, 4) -> ((1, 2), (3, 4))
"""
for i in range(0, len(seq) - 1):
yield (seq[i], seq[i + 1])
if not py3k:
def join_filter(sep, seq, pred=bool):
"""
Join with a filter.
"""
return sep.join([unicode(i) for i in seq if pred(i)])
else:
def join_filter(sep, seq, pred=bool):
"""
Join with a filter.
"""
return sep.join([str(i) for i in seq if pred(i)])
if not py3k:
def decode_page(page):
"""
Return unicode string of geocoder results.
Nearly all services use JSON, so assume UTF8 encoding unless the
response specifies otherwise.
"""
if hasattr(page, 'read'): # urllib
# note getparam in py2
encoding = page.headers.getparam("charset") or "utf-8"
return unicode(page.read(), encoding=encoding)
else: # requests?
encoding = page.headers.get("charset", "utf-8")
return unicode(page.content, encoding=encoding)
else:
def decode_page(page):
"""
Return unicode string of geocoder results.
Nearly all services use JSON, so assume UTF8 encoding unless the
response specifies otherwise.
"""
if hasattr(page, 'read'): # urllib
# note get_param in py3
encoding = page.headers.get_param("charset") or "utf-8"
return str(page.read(), encoding=encoding)
else: # requests?
encoding = page.headers.get("charset") or "utf-8"
return str(page.content, encoding=encoding)
|