Skip to content

Commit 47b7912

Browse files
authored
Merge pull request #33 from flaker/update_python_3_pr
Update the Python 3 PR
2 parents 8fa882e + 5deacd2 commit 47b7912

File tree

8 files changed

+229
-233
lines changed

8 files changed

+229
-233
lines changed

History.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
0.6.0 / 2017-06-19
2+
==================
3+
* Added: Python 3 compatibility
4+
* Fixed: Non running tests
5+
16
0.5.2 / 2017-02-02
27
==================
38
* Fixed: packaging for Pypi

README.md

+18-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
A small class to help connect to the OpenX Enterprise API. As of version 0.5.0 it uses
44
[requests_oauthlib](https://github.com/requests/requests-oauthlib) instead of oauth2.
55

6-
It currently supports Python 2.6 - 2.7, with 3.x support coming in the future.
6+
It currently supports Python 2.6 - 3.5.
77

88
As of version 0.4.0, ox3apiclient supports API v2. If your instance is v2,
99
set the api_path option to "/ox/4.0".
@@ -121,3 +121,20 @@ ox = ox3apiclient.Client(
121121

122122
ox.logon(email, password)
123123
````
124+
125+
# To run these tests. Install nose (pip install nose)
126+
# and run nosetests -sxv tests/ from the root dir
127+
128+
## Tests
129+
130+
Install nose
131+
132+
````bash
133+
pip install nose
134+
````
135+
136+
and run the following command line from the root:
137+
138+
````bash
139+
nosetests -sxv tests/
140+
````

ox3apiclient/__init__.py

+20-18
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
# -*- coding: utf-8 -*-
22

3-
import ConfigParser
4-
import cookielib
3+
from six.moves import configparser as ConfigParser
4+
from six.moves import http_cookiejar as cookielib
55
import logging
66
import mimetypes
77
from pprint import pformat
88
import random
99
import json
10-
from urlparse import parse_qs, urlparse
10+
from six.moves.urllib.parse import parse_qs, urlparse
1111

1212
import requests
1313
from requests_oauthlib import OAuth1
1414

15-
__version__ = '0.5.2'
15+
__version__ = '0.6.0'
1616

1717
REQUEST_TOKEN_URL = 'https://sso.openx.com/api/index/initiate'
1818
ACCESS_TOKEN_URL = 'https://sso.openx.com/api/index/token'
@@ -123,9 +123,9 @@ def log_request(self, response):
123123
self.logger.debug("%s: %s" % (k, v))
124124
self.logger.debug('====={0:=<45}'.format('OX3 api call response body'))
125125
try:
126-
self.logger.debug(pformat(json.loads(response.content)))
126+
self.logger.debug(pformat(json.loads(response.text)))
127127
except ValueError:
128-
self.logger.debug("%s" % response.content)
128+
self.logger.debug("%s" % response.text)
129129
self.logger.debug('====={0:=<45}'.format('OX3 api call finished'))
130130

131131
def request(self, url, method='GET', headers=None, data=None, sign=False,
@@ -164,8 +164,8 @@ def fetch_request_token(self):
164164
response = self._session.post(url=self.request_token_url, auth=oauth, timeout=self.timeout)
165165
self.log_request(response)
166166
if response.status_code != 200:
167-
raise OAuthException("OAuth token request failed (%s) %s" % (response.status_code, response.content))
168-
credentials = parse_qs(response.content)
167+
raise OAuthException("OAuth token request failed (%s) %s" % (response.status_code, response.text))
168+
credentials = parse_qs(response.text)
169169
self._token = {'key': credentials['oauth_token'][0],
170170
'secret': credentials['oauth_token_secret'][0]}
171171
return self._token
@@ -192,10 +192,10 @@ def authorize_token(self, email=None, password=None):
192192
response = self._session.post(url=self.authorization_url, data=data, timeout=self.timeout)
193193
self.log_request(response)
194194
if response.status_code != 200:
195-
raise OAuthException("OAuth login failed (%s) %s" % (response.status_code, response.content))
195+
raise OAuthException("OAuth login failed (%s) %s" % (response.status_code, response.text))
196196

197197
# set token verifier
198-
self._token['verifier'] = parse_qs(response.content)['oauth_verifier'][0]
198+
self._token['verifier'] = parse_qs(response.text)['oauth_verifier'][0]
199199

200200
def fetch_access_token(self):
201201
"""Helper method to fetch and set access token.
@@ -212,8 +212,8 @@ def fetch_access_token(self):
212212
response = self._session.post(url=self.access_token_url, auth=oauth, timeout=self.timeout)
213213
self.log_request(response)
214214
if response.status_code != 200:
215-
raise OAuthException("OAuth token verification failed (%s) %s" % (response.status_code, response.content))
216-
self._token = parse_qs(response.content)['oauth_token'][0]
215+
raise OAuthException("OAuth token verification failed (%s) %s" % (response.status_code, response.text))
216+
self._token = parse_qs(response.text)['oauth_token'][0]
217217
return self._token
218218

219219
def validate_session(self):
@@ -244,7 +244,7 @@ def validate_session(self):
244244
if self.api_path == API_PATH_V1:
245245
response = self._session.put(url=self._resolve_url('/a/session/validate'), timeout=self.timeout)
246246
self.log_request(response)
247-
return response.content
247+
return response.text
248248

249249
def logon(self, email=None, password=None):
250250
"""Returns self after authentication.
@@ -276,7 +276,7 @@ def logoff(self):
276276

277277
response = self._session.delete(url=self.access_token_url, auth=oauth, timeout=self.timeout)
278278
if response.status_code != 204:
279-
raise OAuthException("OAuth token deletion failed (%s) %s" % (response.status_code, response.content))
279+
raise OAuthException("OAuth token deletion failed (%s) %s" % (response.status_code, response.text))
280280
else:
281281
raise UnknownAPIFormatError(
282282
'Unrecognized API path: %s' % self.api_path)
@@ -305,13 +305,13 @@ def _resolve_url(self, url):
305305

306306
def _response_value(self, response):
307307
""" Utility method. Returns decoded json. If the response content cannot be decoded, then
308-
the content is returned.
308+
the text is returned.
309309
310310
"""
311311
try:
312312
return response.json()
313313
except ValueError:
314-
return response.content
314+
return response.text
315315

316316
def get(self, url):
317317
"""Issue a GET request to the given URL or API shorthand
@@ -377,7 +377,7 @@ def upload_creative(self, account_id, file_path):
377377
"""
378378
# Thanks to nosklo for his answer on SO:
379379
# http://stackoverflow.com/a/681182
380-
boundary = '-----------------------------' + str(int(random.random()*1e10))
380+
boundary = '-----------------------------' + str(int(random.random() * 1e10))
381381
parts = []
382382

383383
# Set account ID part.
@@ -392,7 +392,8 @@ def upload_creative(self, account_id, file_path):
392392
parts.append('Content-Type: %s' % mimetypes.guess_type(file_path)[0] or 'application/octet-stream')
393393
parts.append('')
394394
# TODO: catch errors with opening file.
395-
parts.append(open(file_path, 'r').read())
395+
with open(file_path, 'r') as f:
396+
parts.append(f.read())
396397

397398
parts.append('--' + boundary + '--')
398399
parts.append('')
@@ -479,6 +480,7 @@ def client_from_file(file_path='.ox3rc', env=None):
479480

480481
return client
481482

483+
482484
# The exposed API has moved to using Client instead of OX3APIClient, but create
483485
# a temporary alias for backwards compatibility.
484486
OX3APIClient = Client

setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
'Programming Language :: Python',
2727
'Programming Language :: Python :: 2.6',
2828
'Programming Language :: Python :: 2.7',
29+
'Programming Language :: Python :: 3',
2930
'Programming Language :: Python :: Implementation :: CPython',
3031
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
3132
'Topic :: Software Development :: Libraries',

tests/__init__.py

-4
This file was deleted.

tests/client.py

-205
This file was deleted.

0 commit comments

Comments
 (0)