Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Rip out the unused to_python. Fixes #25. Refs #42.

  • Loading branch information...
commit 4266529eaefb96af0a8e99017740cbb56608dbe4 1 parent 56f7787
@erikrose erikrose authored
Showing with 0 additions and 50 deletions.
  1. +0 −36 pyelasticsearch/client.py
  2. +0 −14 pyelasticsearch/tests.py
View
36 pyelasticsearch/client.py
@@ -909,42 +909,6 @@ def from_python(self, value):
return value
- def to_python(self, value):
- """Convert values from ElasticSearch to native Python values."""
- if isinstance(value, (float, complex, list, tuple, bool) + integer_types):
- return value
-
- if isinstance(value, string_types):
- possible_datetime = DATETIME_REGEX.search(value)
-
- if possible_datetime:
- date_values = possible_datetime.groupdict()
-
- for dk, dv in date_values.items():
- date_values[dk] = int(dv)
-
- return datetime(
- date_values['year'], date_values['month'],
- date_values['day'], date_values['hour'],
- date_values['minute'], date_values['second'])
-
- try:
- # This is slightly gross but it's hard to tell otherwise what the
- # string's original type might have been. Be careful who you trust.
- converted_value = eval(value)
-
- # Try to handle most built-in types.
- if isinstance(
- converted_value,
- (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,
- # continue on.
- pass
-
- return value
-
def _iso_datetime(value):
"""
View
14 pyelasticsearch/tests.py
@@ -683,20 +683,6 @@ def test_encoding(self):
self.assertEqual(self.conn.from_python([1, 2, 3]), [1, 2, 3])
self.assertEqual(self.conn.from_python({'a': 1, 'b': 3, 'c': 2}), {'a': 1, 'b': 3, 'c': 2})
- def test_decoding(self):
- """Test decoding a bunch of types."""
- self.assertEqual(self.conn.to_python(u'abc'), u'abc')
- self.assertEqual(self.conn.to_python(u''), u'')
- self.assertEqual(self.conn.to_python(123), 123)
- self.assertEqual(self.conn.to_python(12.2), 12.2)
- self.assertEqual(self.conn.to_python(True), True)
- self.assertEqual(self.conn.to_python(False), False)
- self.assertEqual(self.conn.to_python('2011-12-30T00:00:00'), datetime(2011, 12, 30))
- self.assertEqual(self.conn.to_python('2011-12-30T11:59:32'), datetime(2011, 12, 30, 11, 59, 32))
- self.assertEqual(self.conn.to_python([1, 2, 3]), [1, 2, 3])
- self.assertEqual(self.conn.to_python(set(['a', 'b', 'c'])), set(['a', 'b', 'c']))
- self.assertEqual(self.conn.to_python({'a': 1, 'b': 3, 'c': 2}), {'a': 1, 'b': 3, 'c': 2})
-
if __name__ == '__main__':
unittest.main()
Please sign in to comment.
Something went wrong with that request. Please try again.