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

Remove viewitems() as it breaks compatibility with python<2.7 #81

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
24 changes: 12 additions & 12 deletions sunburnt/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def __init__(self, name, indexed=None, stored=None, required=False, multiValued=
elif self.name.endswith("*"):
self.wildcard_at_start = False
else:
raise SolrError("Dynamic fields must have * at start or end of name (field %s)" %
raise SolrError("Dynamic fields must have * at start or end of name (field %s)" %
self.name)

def match(self, name):
Expand All @@ -153,7 +153,7 @@ def match(self, name):

def normalize(self, value):
""" Normalize the given value according to the field type.

This method does nothing by default, returning the given value
as is. Child classes may override this method as required.
"""
Expand Down Expand Up @@ -192,7 +192,7 @@ def from_solr(self, value):
try:
return unicode(value)
except UnicodeError:
raise SolrError("%s could not be coerced to unicode (field %s)" %
raise SolrError("%s could not be coerced to unicode (field %s)" %
(value, self.name))


Expand All @@ -207,7 +207,7 @@ def normalize(self, value):
elif value.lower() == "false":
return False
else:
raise ValueError("sorry, I only understand simple boolean strings (field %s)" %
raise ValueError("sorry, I only understand simple boolean strings (field %s)" %
self.name)
return bool(value)

Expand All @@ -217,7 +217,7 @@ def from_user_data(self, value):
try:
return str(value)
except (TypeError, ValueError):
raise SolrError("Could not convert data to binary string (field %s)" %
raise SolrError("Could not convert data to binary string (field %s)" %
self.name)

def to_solr(self, value):
Expand All @@ -232,7 +232,7 @@ def normalize(self, value):
try:
v = self.base_type(value)
except (OverflowError, TypeError, ValueError):
raise SolrError("%s is invalid value for %s (field %s)" %
raise SolrError("%s is invalid value for %s (field %s)" %
(value, self.__class__, self.name))
if v < self.min or v > self.max:
raise SolrError("%s out of range for a %s (field %s)" %
Expand Down Expand Up @@ -477,7 +477,7 @@ def field_factory(self, field_node, field_type_classes, dynamic):
attrib_translator = {"true": True, "1": True, "false": False, "0": False}
def translate_attributes(self, attribs):
return dict((k, self.attrib_translator.get(v, v))
for k, v in attribs.items())
for k, v in attribs.iteritems())

def missing_fields(self, field_names):
return [name for name in set(self.fields.keys()) - set(field_names)
Expand All @@ -494,7 +494,7 @@ def check_fields(self, field_names, required_atts=None):
if not field:
undefined_field_names.append(field_name)
else:
for k, v in required_atts.items():
for k, v in required_atts.iteritems():
if getattr(field, k) != v:
raise SolrError("Field '%s' does not have %s=%s" % (field_name, k, v))
if undefined_field_names:
Expand Down Expand Up @@ -553,7 +553,7 @@ def parse_result_doc_json(self, doc):
# Note: for efficiency's sake this modifies the original dict
# in place. This doesn't make much difference on 20 documents
# but it does on 20,000
for name, value in doc.viewitems():
for name, value in doc.iteritems():
field_class = self.match_field(name)
# If the field type is a string then we don't need to modify it
if isinstance(field_class, SolrUnicodeField):
Expand Down Expand Up @@ -597,7 +597,7 @@ def doc(self, doc):
else:
return self.DOC(*reduce(operator.add,
[self.fields(name, values)
for name, values in doc.items()]))
for name, values in doc.iteritems()]))

def add(self, docs):
if hasattr(docs, "items") or not hasattr(docs, "__iter__"):
Expand Down Expand Up @@ -687,7 +687,7 @@ def from_response_json(cls, response):
except KeyError:
return SolrFacetCounts()
facet_fields = {}
for facet_field, facet_values in facet_counts_dict['facet_fields'].viewitems():
for facet_field, facet_values in facet_counts_dict['facet_fields'].iteritems():
facets = []
# Change each facet list from [a, 1, b, 2, c, 3 ...] to
# [(a, 1), (b, 2), (c, 3) ...]
Expand Down Expand Up @@ -754,7 +754,7 @@ def from_json(cls, schema, jsonmsg):
self.facet_counts = SolrFacetCounts.from_response_json(doc)
self.highlighting = doc.get("highlighting", {})
self.more_like_these = dict((k, SolrResult.from_json(schema, v))
for (k, v) in doc.get('moreLikeThis', {}).viewitems())
for (k, v) in doc.get('moreLikeThis', {}).iteritems())
if len(self.more_like_these) == 1:
self.more_like_this = self.more_like_these.values()[0]
else:
Expand Down