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

Fully Functional Python 3 - using requests in place of urllib2 #17

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
11e71ce
Python 2 to 3 adjusted urllib with requests. All but Tutorials pass t…
daniel-butler May 14, 2018
c0f771b
updated to pass more tests
daniel-butler May 15, 2018
48eca89
engine updated - working now
daniel-butler May 15, 2018
8e08202
Updated tests to match the new 2.8 server responses. Updated the get-…
daniel-butler May 19, 2018
620d101
new project request sends default options correctly
daniel-butler May 19, 2018
9424910
new project function cleaned up
daniel-butler May 19, 2018
85be17b
Update README.rst
daniel-butler May 19, 2018
e6e32e1
reorder columns fixed. All tests pass!
daniel-butler May 20, 2018
1d718f7
Merge remote-tracking branch 'origin/master'
daniel-butler May 20, 2018
ae21e08
moved pieces around to make it more readable
daniel-butler May 20, 2018
3351412
renamed google file to open
daniel-butler May 20, 2018
84e9fec
updated command url to be an fString
daniel-butler May 20, 2018
79e24b8
corrected test for test_editing
daniel-butler May 20, 2018
c33602f
get operations command added
daniel-butler May 20, 2018
a22c9dc
added apply operations using a python dictionary. Also closed the ope…
daniel-butler May 22, 2018
ad1dae0
updated for 3.0-beta changed facet 'l' needs to be a string and
daniel-butler Jun 3, 2018
a8dded8
tests updated for server versions 2.0, 2.1, 2.5 and 2.8
daniel-butler Jun 21, 2018
417e366
updated for pep8
daniel-butler Jun 21, 2018
bb13a72
update to comply with pep8
daniel-butler Jun 21, 2018
fd0066f
updated to comply with pep8
daniel-butler Jun 21, 2018
568ba04
updated to comply with pep8
daniel-butler Jun 21, 2018
e8cd4b2
updated test to look for M or F in lines. Was looking in the entire c…
daniel-butler Jun 21, 2018
e0f75fe
updated for pep8
daniel-butler Jun 21, 2018
1c78ad6
updated for pep8
daniel-butler Jun 21, 2018
65c9814
updated test to be correct
daniel-butler Jun 21, 2018
159b4a3
updated test to be correct
daniel-butler Jun 21, 2018
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
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Installation
(Someone with more familiarity with python's byzantine collection of installation
frameworks is very welcome to improve/"best practice" all this.)

#. Install dependencies, which currently is ``urllib2_file``:
#. Install dependencies, which currently is ``requests``:

``sudo pip install -r requirements.txt``

Expand Down
File renamed without changes.
File renamed without changes.
40 changes: 20 additions & 20 deletions google/refine/facet.py → open/refine/facet.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>

import json
import re


Expand All @@ -40,18 +39,18 @@ def __init__(self, column, facet_type, **options):
self.type = facet_type
self.name = column
self.column_name = column
for k, v in options.items():
for k, v in list(options.items()):
setattr(self, k, v)

def as_dict(self):
return dict([(to_camel(k), v) for k, v in self.__dict__.items()
return dict([(to_camel(k), v) for k, v in list(self.__dict__.items())
if v is not None])


class TextFilterFacet(Facet):
def __init__(self, column, query, **options):
super(TextFilterFacet, self).__init__(
column, query=query, case_sensitive=False, facet_type='text',
column, query = query, case_sensitive=False, facet_type='text',
mode='text', **options)


Expand All @@ -60,8 +59,7 @@ def __init__(self, column, selection=None, expression='value',
omit_blank=False, omit_error=False, select_blank=False,
select_error=False, invert=False, **options):
super(TextFacet, self).__init__(
column,
facet_type='list',
column, facet_type='list',
omit_blank=omit_blank,
omit_error=omit_error,
select_blank=select_blank,
Expand All @@ -81,7 +79,7 @@ def include(self, value):
for s in self.selection:
if s['v']['v'] == value:
return
self.selection.append({'v': {'v': value, 'l': value}})
self.selection.append({'v': {'v': value, 'l': str(value)}})
return self

def exclude(self, value):
Expand Down Expand Up @@ -132,7 +130,7 @@ def __init__(self, column, **options):


# Capitalize 'From' to get around python's reserved word.
#noinspection PyPep8Naming
# noinspection PyPep8Naming
class NumericFacet(Facet):
def __init__(self, column, From=None, to=None, expression='value',
select_blank=True, select_error=True, select_non_numeric=True,
Expand All @@ -159,8 +157,8 @@ class FacetResponse(object):
"""Class for unpacking an individual facet response."""
def __init__(self, facet):
self.name = None
for k, v in facet.items():
if isinstance(k, bool) or isinstance(k, basestring):
for k, v in list(facet.items()):
if isinstance(k, bool) or isinstance(k, str):
setattr(self, from_camel(k), v)
self.choices = {}

Expand Down Expand Up @@ -226,6 +224,11 @@ def set_facets(self, *facets):
for facet in facets:
self.add_facet(facet)

def add_facet(self, facet):
# Record the facet's object id so facet response can be looked up by id
self.facet_index_by_id[id(facet)] = len(self.facets)
self.facets.append(facet)

def facets_response(self, response):
"""Unpack a compute-facets response."""
return FacetsResponse(self, response)
Expand All @@ -235,15 +238,11 @@ def __len__(self):

def as_json(self):
"""Return a JSON string suitable for use as a POST parameter."""
return json.dumps({
'facets': [f.as_dict() for f in self.facets], # XXX how with json?
d = {
'facets': [f.as_dict() for f in self.facets],
'mode': self.mode,
})

def add_facet(self, facet):
# Record the facet's object id so facet response can be looked up by id
self.facet_index_by_id[id(facet)] = len(self.facets)
self.facets.append(facet)
}
return str(d)

def remove_all(self):
"""Remove all facets."""
Expand All @@ -268,7 +267,7 @@ def __init__(self, criteria=None):
criteria = [criteria]
for criterion in criteria:
# A string criterion defaults to a string sort on that column
if isinstance(criterion, basestring):
if isinstance(criterion, str):
criterion = {
'column': criterion,
'valueType': 'string',
Expand All @@ -280,7 +279,8 @@ def __init__(self, criteria=None):
self.criteria.append(criterion)

def as_json(self):
return json.dumps({'criteria': self.criteria})
d = {'criteria': self.criteria}
return str(d)

def __len__(self):
return len(self.criteria)
2 changes: 1 addition & 1 deletion google/refine/history.py → open/refine/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

class HistoryEntry(object):
# N.B. e.g. **response['historyEntry'] won't work as keys are unicode :-/
#noinspection PyUnusedLocal
# noinspection PyUnusedLocal
def __init__(self, history_entry_id=None, time=None, description=None, **kwargs):
if history_entry_id is None:
raise ValueError('History entry id must be set')
Expand Down
Loading