Skip to content

Commit

Permalink
Merge 8bdb9c7 into 9f75848
Browse files Browse the repository at this point in the history
  • Loading branch information
waghanza committed Jul 1, 2019
2 parents 9f75848 + 8bdb9c7 commit 54594fd
Show file tree
Hide file tree
Showing 43 changed files with 498 additions and 751 deletions.
27 changes: 26 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
language: python

# because python3.7 is not available on trusty
# @see https://github.com/travis-ci/travis-ci/issues/9815
dist: xenial

# Test on python3
python:
- '2.7'
- 3.5 # debian
- 3.6 # ubuntu / amazonlinux
- 3.7 # fedora
- nightly

# Allow failures on cpython nightly build
matrix:
fast_finish: true
allow_failures:
- python: nightly

install:
- pip install -r cyclone/tests/test_requirements.txt
- pip install coveralls

# cyclone has to be installed
# so as trial (twisted test framework) could run
before_script: python setup.py install

script: coverage run `which trial` cyclone
after_success: coveralls

# deploy on pypi
# only on 3.6 (avoid multiple deployment)
deploy:
provider: pypi
user: fiorix
Expand All @@ -14,4 +38,5 @@ deploy:
on:
tags: true
branch: master
condition: $TRAVIS_PYTHON_VERSION = 3.6
distributions: "sdist bdist_wheel"
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ Cyclone
=======

[![Build Status](https://travis-ci.org/fiorix/cyclone.svg?branch=master)](https://travis-ci.org/fiorix/cyclone)
[![Coverage Status](https://coveralls.io/repos/github/fiorix/cyclone/badge.svg?branch=master)](https://coveralls.io/github/fiorix/cyclone?branch=master)
[![Supported Python versions](https://pypi.org/project/cyclone)](https://img.shields.io/pypi/pyversions/cyclone.svg)

Cyclone is a web server framework for Python, that implements the Tornado API
as a Twisted protocol.

:warning: `cyclone` does not support `python` **2.x** anymore :warning:

See http://cyclone.io for details.

Installation
Expand Down
2 changes: 1 addition & 1 deletion appskel/default/modname/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@ def my_parse_config(filename):
def parse_config(filename):
try:
return my_parse_config(filename)
except Exception as e:
except Exception, e:
print("Error parsing %s: %s" % (filename, e))
sys.exit(1)
2 changes: 1 addition & 1 deletion appskel/default/modname/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def setup(cls, conf):
def _ping_mysql():
try:
yield cls.mysql.runQuery("select 1")
except Exception as e:
except Exception, e:
log.msg("MySQL ping error:", e)
else:
if conf["mysql_settings"].debug:
Expand Down
4 changes: 2 additions & 2 deletions appskel/default/modname/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def get(self):
if self.redis:
try:
response = yield self.redis.get("foo")
except Exception as e:
except Exception, e:
log.msg("Redis query failed: %s" % str(e))
raise cyclone.web.HTTPError(503) # Service Unavailable
else:
Expand All @@ -65,7 +65,7 @@ def get(self):
if self.mysql:
try:
response = yield self.mysql.runQuery("select now()")
except Exception as e:
except Exception, e:
log.msg("MySQL query failed: %s" % str(e))
raise cyclone.web.HTTPError(503) # Service Unavailable
else:
Expand Down
2 changes: 1 addition & 1 deletion appskel/signup/modname/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,6 @@ def my_parse_config(filename):
def parse_config(filename):
try:
return my_parse_config(filename)
except Exception as e:
except Exception, e:
print("Error parsing %s: %s" % (filename, e))
sys.exit(1)
2 changes: 1 addition & 1 deletion appskel/signup/modname/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def setup(cls, conf):
def _ping_mysql():
try:
yield cls.mysql.runQuery("select 1")
except Exception as e:
except Exception, e:
log.msg("MySQL ping error:", e)
else:
if conf["mysql_settings"].debug:
Expand Down
4 changes: 2 additions & 2 deletions appskel/signup/modname/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def post(self):

try:
r = yield cyclone.mail.sendmail(self.settings.email_settings, msg)
except Exception as e:
except Exception, e:
# delete password from redis
yield self.redis.delete(k)

Expand Down Expand Up @@ -337,7 +337,7 @@ def post(self):

try:
r = yield cyclone.mail.sendmail(self.settings.email_settings, msg)
except Exception as e:
except Exception, e:
# do not delete from redis
# yield self.redis.delete(k)

Expand Down
58 changes: 21 additions & 37 deletions cyclone/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,10 @@ def _on_auth(self, user):
import hashlib
import hmac
import time
import urllib
from urllib import parse as urllib_parse
import uuid

try:
import urlparse # py2
except ImportError:
import urllib.parse as urlparse # py3

try:
import urllib.parse as urllib_parse # py3
except ImportError:
import urllib as urllib_parse # py2

try:
long # py2
except NameError:
long = int # py3


class OpenIdMixin(object):
"""Abstract implementation of OpenID and Attribute Exchange.
Expand Down Expand Up @@ -114,15 +101,15 @@ def get_authenticated_user(self, callback):
postdata=urllib_parse.urlencode(args)).addBoth(callback)

def _openid_args(self, callback_uri, ax_attrs=[], oauth_scope=None):
url = urlparse.urljoin(self.request.full_url(), callback_uri)
url = urllib_parse.urljoin(self.request.full_url(), callback_uri)
args = {
"openid.ns": "http://specs.openid.net/auth/2.0",
"openid.claimed_id":
"http://specs.openid.net/auth/2.0/identifier_select",
"openid.identity":
"http://specs.openid.net/auth/2.0/identifier_select",
"openid.return_to": url,
"openid.realm": urlparse.urljoin(url, '/'),
"openid.realm": urllib_parse.urljoin(url, '/'),
"openid.mode": "checkid_setup",
}
if ax_attrs:
Expand Down Expand Up @@ -291,7 +278,7 @@ def _oauth_request_token_url(self, callback_uri=None, extra_params=None):
if callback_uri == "oob":
args["oauth_callback"] = "oob"
elif callback_uri:
args["oauth_callback"] = urlparse.urljoin(
args["oauth_callback"] = urllib_parse.urljoin(
self.request.full_url(), callback_uri)
if extra_params:
args.update(extra_params)
Expand All @@ -314,7 +301,7 @@ def _on_request_token(self, authorize_url, callback_uri, response):
self.finish(authorize_url + "?" + urllib_parse.urlencode(args))
return
elif callback_uri:
args["oauth_callback"] = urlparse.urljoin(
args["oauth_callback"] = urllib_parse.urljoin(
self.request.full_url(), callback_uri)
self.redirect(authorize_url + "?" + urllib_parse.urlencode(args))

Expand Down Expand Up @@ -820,11 +807,11 @@ def authenticate_redirect(self, callback_uri=None, cancel_uri=None,
"v": "1.0",
"fbconnect": "true",
"display": "page",
"next": urlparse.urljoin(self.request.full_url(), callback_uri),
"next": urllib_parse.urljoin(self.request.full_url(), callback_uri),
"return_session": "true",
}
if cancel_uri:
args["cancel_url"] = urlparse.urljoin(
args["cancel_url"] = urllib_parse.urljoin(
self.request.full_url(), cancel_uri)
if extended_permissions:
if isinstance(extended_permissions, (unicode_type, bytes_type)):
Expand Down Expand Up @@ -908,7 +895,7 @@ def _on_stream(self, stream):
args["api_key"] = self.settings["facebook_api_key"]
args["v"] = "1.0"
args["method"] = method
args["call_id"] = str(long(time.time() * 1e6))
args["call_id"] = str(int(time.time() * 1e6))
args["format"] = "json"
args["sig"] = self._signature(args)
url = "http://api.facebook.com/restserver.php?" + \
Expand Down Expand Up @@ -940,7 +927,7 @@ def _parse_response(self, callback, response):
return
try:
json = escape.json_decode(response.body)
except:
except Exception:
log.msg("Invalid JSON from Facebook: %r" % response.body)
callback(None)
return
Expand All @@ -954,7 +941,7 @@ def _parse_response(self, callback, response):
def _signature(self, args):
parts = ["%s=%s" % (n, args[n]) for n in sorted(args.keys())]
body = "".join(parts) + self.settings["facebook_secret"]
if isinstance(body, unicode):
if isinstance(body, str):
body = body.encode("utf-8")
return hashlib.md5(body).hexdigest()

Expand All @@ -966,7 +953,7 @@ class FacebookGraphMixin(OAuth2Mixin):
_OAUTH_NO_CALLBACKS = False

def get_authenticated_user(self, redirect_uri, client_id, client_secret,
code, callback, extra_fields=None):
code, callback, extra_fields=None):
"""Handles the login for the Facebook user, returning a user object.
Example usage::
Expand Down Expand Up @@ -1014,7 +1001,7 @@ def _on_login(self, user):
def _on_access_token(self, redirect_uri, client_id, client_secret,
callback, fields, response):
if response.error:
log.warning('Facebook auth error: %s' % str(response))
log.msg('Facebook auth error: %s' % str(response))
callback(None)
return

Expand Down Expand Up @@ -1045,7 +1032,7 @@ def _on_get_user_info(self, callback, session, fields, user):
callback(fieldmap)

def facebook_request(self, path, callback, access_token=None,
post_args=None, **args):
post_args=None, **args):
"""Fetches the given relative API path, e.g., "/btaylor/picture"
If the request is a POST, post_args should be provided. Query
Expand Down Expand Up @@ -1090,14 +1077,13 @@ def _on_post(self, new_entry):
callback = self.async_callback(self._on_facebook_request, callback)
if post_args is not None:
httpclient.fetch(url, method="POST",
postdata=urllib_parse.urlencode(post_args)).addCallback(callback)
postdata=urllib_parse.urlencode(post_args)).addCallback(callback)
else:
httpclient.fetch(url).addCallback(callback)

def _on_facebook_request(self, callback, response):
if response.error:
log.warning("Error response %s fetching %s", response.error,
response.request.url)
log.msg("Error response %s fetching %s", response.error, response.request.url)
callback(None)
return
callback(escape.json_decode(response.body))
Expand All @@ -1108,7 +1094,7 @@ def _oauth_signature(consumer_token, method, url, parameters={}, token=None):
See http://oauth.net/core/1.0/#signing_process
"""
parts = urlparse.urlparse(url)
parts = urllib_parse.urlparse(url)
scheme, netloc, path = parts[:3]
normalized_url = scheme.lower() + "://" + netloc.lower() + path

Expand All @@ -1133,7 +1119,7 @@ def _oauth10a_signature(consumer_token,
See http://oauth.net/core/1.0a/#signing_process
"""
parts = urlparse.urlparse(url)
parts = urllib_parse.urlparse(url)
scheme, netloc, path = parts[:3]
normalized_url = scheme.lower() + "://" + netloc.lower() + path

Expand All @@ -1144,10 +1130,8 @@ def _oauth10a_signature(consumer_token,
for k, v in sorted(parameters.items())))

base_string = "&".join(_oauth_escape(e) for e in base_elems)
key_elems = [escape.utf8(
urllib_parse.quote(consumer_token["secret"], safe='~'))]
key_elems.append(escape.utf8(
urllib_parse.quote(token["secret"], safe='~') if token else ""))
key_elems = [escape.utf8(urllib_parse.quote(consumer_token["secret"], safe='~'))]
key_elems.append(escape.utf8(urllib_parse.quote(token["secret"], safe='~') if token else ""))
key = "&".join(key_elems)

hash = hmac.new(key, escape.utf8(base_string), hashlib.sha1)
Expand All @@ -1161,7 +1145,7 @@ def _oauth_escape(val):


def _oauth_parse_response(body):
p = escape.parse_qs(body, keep_blank_values=False)
p = urllib_parse.parse_qs(body, keep_blank_values=False)
token = dict(key=p["oauth_token"][0], secret=p["oauth_token_secret"][0])

# Add the extra parameters the Provider included to the token
Expand Down

0 comments on commit 54594fd

Please sign in to comment.