Skip to content

Commit

Permalink
getting py2 working...
Browse files Browse the repository at this point in the history
  • Loading branch information
barakalon committed Mar 26, 2018
1 parent f1cab19 commit e3eabe7
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 27 deletions.
7 changes: 7 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
SOQL
====

.. image:: https://travis-ci.org/plangrid/soql.svg?branch=master
:target: https://travis-ci.org/plangrid/soql
:alt: CI Status

.. image:: https://badge.fury.io/py/soql.svg
:target: https://badge.fury.io/py/soql
:alt: PyPI status

|
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
pytest

-e .
8 changes: 4 additions & 4 deletions soql/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from __future__ import absolute_import
from datetime import datetime, date

import six
from dateutil.parser import parse
from dateutil.tz import tzutc

Expand Down Expand Up @@ -112,9 +111,10 @@ def serialize(self, value):

class String(Column):
def _coerce(self, value):
if not isinstance(value, six.string_types):
value = str(value)
return six.u(value)
try:
return str(value)
except UnicodeEncodeError:
return value


class Integer(Column):
Expand Down
12 changes: 5 additions & 7 deletions soql/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from dateutil.tz import tzutc

from soql.utils import AttrDict
from soql.utils import to_unicode


# The various operations you can perform in SOQL
Expand Down Expand Up @@ -91,17 +92,14 @@ def __init__(self, child_nodes, sep=''):
self.child_nodes = child_nodes
self.sep = sep

def as_string(self):
return self.sep.join([str(node) for node in self.child_nodes])
def _as_string(self, method):
return self.sep.join([method(node) for node in self.child_nodes])

def __unicode__(self):
return six.u(self.as_string())
return to_unicode(self._as_string(to_unicode))

def __str__(self):
return str(self.as_string())

def __bytes__(self):
return six.b(self.as_string())
return str(self._as_string(str))


class Grouped(Node):
Expand Down
8 changes: 2 additions & 6 deletions soql/path_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
"""
from __future__ import absolute_import

import six

from soql.attributes import Relationship
from soql.nodes import ColumnPath
from soql.utils import to_unicode


class PathBuilder(object):
Expand Down Expand Up @@ -145,10 +144,7 @@ def __getattr__(self, item):
return self.extend_path(item=item)

def __unicode__(self):
return six.u(self.get_column_node())
return to_unicode(self.get_column_node())

def __str__(self):
return str(self.get_column_node())

def __bytes__(self):
return six.b(self.get_column_node())
8 changes: 2 additions & 6 deletions soql/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
from collections import OrderedDict
from copy import copy

import six

from soql.nodes import SubqueryClause
from soql.nodes import OrderByClause
from soql.nodes import Count
from soql.nodes import SelectClause
from soql.path_builder import PathBuilder
from soql.utils import to_unicode


class SelectClauseIsntValidSubquery(Exception):
Expand Down Expand Up @@ -195,14 +194,11 @@ def subquery(self):

def __unicode__(self):
"""Converts the instance to a SOQL string."""
return six.u(self._get_select_clause())
return to_unicode(self._get_select_clause())

def __str__(self):
return str(self._get_select_clause())

def __bytes__(self):
return six.b(self._get_select_clause())

def _get_columns(self):
if self._count:
return [Count()]
Expand Down
7 changes: 7 additions & 0 deletions soql/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@
:copyright: Copyright 2018 PlanGrid, Inc., see AUTHORS.
:license: MIT, see LICENSE for details.
"""
import sys


class AttrDict(dict):
"""This is just a little convenience class to make dealing with
static sets prettier."""
def __getattr__(self, attr):
return self[attr]


if sys.version_info[0] < 3:
to_unicode = unicode
else:
to_unicode = str
5 changes: 2 additions & 3 deletions tests/helpers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import six
from soql.utils import to_unicode


class SoqlAssertions(object):
def assertSoqlEqual(self, node, soql):
self.assertEqual(six.u(str(node)), six.u(soql))
self.assertEqual(six.b(str(node)), six.b(soql))
self.assertEqual(to_unicode(node), to_unicode(soql))
5 changes: 4 additions & 1 deletion tests/test_attributes.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import unittest
from datetime import datetime, date

Expand Down Expand Up @@ -44,7 +47,7 @@ def test_coerce(self):
attr = attributes.String('Attr')
self.assertEqual(attr.coerce(1), '1')
self.assertEqual(attr.coerce('1'), '1')
self.assertEqual(attr.coerce(u'\xe9'), u'\xe9')
self.assertEqual(attr.coerce('), ')
self.assertRaises(NullSalesforceColumnError, attr.coerce, None)

def test_nullable(self):
Expand Down

0 comments on commit e3eabe7

Please sign in to comment.