Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax error: except (ConnectionError, TransportError), e: #1

Open
wants to merge 7 commits into
base: py3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions django_elasticsearch/contrib/restframework/restframework2.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from rest_framework.filters import DjangoFilterBackend

from django_elasticsearch.models import EsIndexable
from django.utils import six


from elasticsearch import NotFoundError
Expand Down Expand Up @@ -75,7 +76,7 @@ def filter_queryset(self, request, queryset, view):

filterable = getattr(view, 'filter_fields', [])
filters = dict([(k, v)
for k, v in request.GET.iteritems()
for k, v in six.iteritems(request.GET)
if k in filterable])

q = queryset.query(query).filter(**filters)
Expand Down Expand Up @@ -147,7 +148,7 @@ def list(self, request, *args, **kwargs):
def dispatch(self, request, *args, **kwargs):
try:
r = super(IndexableModelMixin, self).dispatch(request, *args, **kwargs)
except (ConnectionError, TransportError), e:
except (ConnectionError, TransportError) as e:
# reset object list
self.queryset = None
self.es_failed = True
Expand Down
5 changes: 3 additions & 2 deletions django_elasticsearch/contrib/restframework/restframework3.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from rest_framework.filters import DjangoFilterBackend

from django_elasticsearch.models import EsIndexable
from django.utils import six


try:
Expand Down Expand Up @@ -38,7 +39,7 @@ def filter_queryset(self, request, queryset, view):

filterable = getattr(view, 'filter_fields', [])
filters = dict([(k, v)
for k, v in request.GET.iteritems()
for k, v in six.iteritems(request.GET)
if k in filterable])

q = queryset.query(query).filter(**filters)
Expand Down Expand Up @@ -87,7 +88,7 @@ def filter_queryset(self, queryset):
def dispatch(self, request, *args, **kwargs):
try:
r = super(IndexableModelMixin, self).dispatch(request, *args, **kwargs)
except (ConnectionError, TransportError), e:
except (ConnectionError, TransportError) as e:
# reset object list
self.queryset = None
self.es_failed = True
Expand Down
3 changes: 2 additions & 1 deletion django_elasticsearch/managers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import json
from django.utils import six
try:
import importlib
except ImportError: # python < 2.7
Expand Down Expand Up @@ -87,7 +88,7 @@ def check_cluster(self):

def get_serializer(self, **kwargs):
serializer = self.model.Elasticsearch.serializer_class
if isinstance(serializer, basestring):
if isinstance(serializer, basestring if six.PY2 else str):
module, kls = self.model.Elasticsearch.serializer_class.rsplit(".", 1)
mod = importlib.import_module(module)
return getattr(mod, kls)(self.model, **kwargs)
Expand Down
6 changes: 3 additions & 3 deletions django_elasticsearch/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from django.db.models import FieldDoesNotExist
from django.db.models.fields.related import ManyToManyField

from django.utils import six

class EsSerializer(object):
def serialize(self, instance):
Expand Down Expand Up @@ -81,7 +81,7 @@ def deserialize(self, source):
Returns a model instance
"""
attrs = {}
for k, v in source.iteritems():
for k, v in six.iteritems(source):
try:
attrs[k] = self.deserialize_field(source, k)
except (AttributeError, FieldDoesNotExist):
Expand Down Expand Up @@ -145,7 +145,7 @@ def nested_serialize(self, rel):
return obj

# Fallback on a dict with id + __unicode__ value of the related model instance.
return dict(id=rel.pk, value=unicode(rel))
return dict(id=rel.pk, value=six.text_type(rel))

def format(self, instance):
# from a model instance to a dict
Expand Down
4 changes: 2 additions & 2 deletions django_elasticsearch/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


def nested_update(d, u):
for k, v in u.iteritems():
for k, v in u.items():
if isinstance(v, collections.Mapping):
r = nested_update(d.get(k, {}), v)
d[k] = r
Expand All @@ -20,4 +20,4 @@ def dict_depth(d, depth=0):
if not isinstance(d, dict) or not d:
return depth
return max(dict_depth(v, depth + 1)
for k, v in d.iteritems())
for k, v in d.items())