Permalink
Browse files

Import `six` things more deeply, for brevity.

  • Loading branch information...
1 parent 524affc commit 3e8b8e5bd7afbbd9e143f4721234ad3af631592c @erikrose erikrose committed Mar 19, 2013
Showing with 13 additions and 13 deletions.
  1. +13 −13 pyelasticsearch/client.py
View
@@ -5,7 +5,7 @@
from functools import wraps
from logging import getLogger
import re
-import six
+from six import iterkeys, string_types, integer_types, iteritems, PY3
from six.moves import xrange
try:
@@ -89,7 +89,7 @@ def decorate(*args, **kwargs):
# Make kwargs the map of normal kwargs and query_params the map of
# kwargs destined for query string params:
query_params = {}
- for k in list(six.iterkeys(kwargs)): # NOT iterkeys; we mutate kwargs
+ for k in list(iterkeys(kwargs)): # NOT iterkeys; we mutate kwargs
if k.startswith('es_'):
query_params[k[3:]] = kwargs.pop(k)
elif k in convertible_args:
@@ -118,7 +118,7 @@ def __init__(self, urls, timeout=60, max_retries=0, revival_delay=300):
:arg revival_delay: Number of seconds for which to avoid a server after
it times out or is uncontactable
"""
- if isinstance(urls, six.string_types):
+ if isinstance(urls, string_types):
urls = [urls]
urls = [u.rstrip('/') for u in urls]
self.servers = DowntimePronePool(urls, revival_delay)
@@ -147,22 +147,22 @@ def _concat(self, items):
# TODO: Why strip out _all?
if items is None:
return ''
- if isinstance(items, six.string_types):
+ if isinstance(items, string_types):
items = [items]
return ','.join(i for i in items if i != '_all')
@classmethod
def _to_query(cls, obj):
"""Convert a native-Python object to a query string representation."""
# Quick and dirty thus far
- if isinstance(obj, six.string_types):
+ if isinstance(obj, string_types):
return obj
if isinstance(obj, bool):
return 'true' if obj else 'false'
- if isinstance(obj, six.integer_types):
+ if isinstance(obj, integer_types):
return str(obj)
if isinstance(obj, float):
- return repr(obj) # str looses precision
+ return repr(obj) # str loses precision.
if isinstance(obj, (list, tuple)):
return ','.join(cls._to_query(o) for o in obj)
iso = _iso_datetime(obj)
@@ -208,7 +208,7 @@ def join_path(path_components):
if query_params:
path = '?'.join(
[path, urlencode(dict((k, self._to_query(v)) for k, v in
- six.iteritems(query_params)))])
+ iteritems(query_params)))])
kwargs = ({'data': self._encode_json(body) if encode_body else body}
if body else {})
@@ -476,7 +476,7 @@ def update(self, index, doc_type, id, script=None, params=None, lang=None,
def _search_or_count(self, kind, query, index=None, doc_type=None,
query_params=None):
- if isinstance(query, six.string_types):
+ if isinstance(query, string_types):
query_params['q'] = query
body = ''
else:
@@ -855,7 +855,7 @@ def from_python(self, value):
iso = _iso_datetime(value)
if iso:
return iso
- if not six.PY3 and isinstance(value, str):
+ if not PY3 and isinstance(value, str):
return unicode(value, errors='replace') # TODO: Be stricter.
if isinstance(value, set):
return list(value)
@@ -864,10 +864,10 @@ def from_python(self, value):
def to_python(self, value):
"""Convert values from ElasticSearch to native Python values."""
- if isinstance(value, (float, complex, list, tuple, bool) + six.integer_types):
+ if isinstance(value, (float, complex, list, tuple, bool) + integer_types):
return value
- if isinstance(value, six.string_types):
+ if isinstance(value, string_types):
possible_datetime = DATETIME_REGEX.search(value)
if possible_datetime:
@@ -889,7 +889,7 @@ def to_python(self, value):
# Try to handle most built-in types.
if isinstance(
converted_value,
- (list, tuple, set, dict, float, complex) + six.integer_types):
+ (list, tuple, set, dict, float, complex) + integer_types):
return converted_value
except Exception:
# If it fails (SyntaxError or its ilk) or we don't trust it,

0 comments on commit 3e8b8e5

Please sign in to comment.