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

Werkzeug 3 #405

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
[submodule "docs/_themes"]
path = docs/_themes
url = git://github.com/lepture/flask-sphinx-themes.git
1 change: 0 additions & 1 deletion docs/_themes
Submodule _themes deleted from 7baf93
36 changes: 14 additions & 22 deletions flask_oauthlib/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,18 @@
import oauthlib.oauth2
from copy import copy
from functools import wraps
from oauthlib.common import to_unicode, PY3, add_params_to_uri
from oauthlib.common import to_unicode, add_params_to_uri
from flask import request, redirect, json, session, current_app
from werkzeug import url_quote, url_decode, url_encode
from werkzeug import parse_options_header, cached_property
from werkzeug.http import parse_options_header
from urllib.parse import parse_qsl, quote, urlencode, urlparse, urljoin
from werkzeug.utils import cached_property
from .utils import to_bytes
try:
from urlparse import urljoin
import urllib2 as http
except ImportError:
from urllib import request as http
from urllib.parse import urljoin
log = logging.getLogger('flask_oauthlib')


if PY3:
string_types = (str,)
else:
string_types = (str, unicode)
log = logging.getLogger('flask_oauthlib')


__all__ = ('OAuth', 'OAuthRemoteApp', 'OAuthResponse', 'OAuthException')
Expand Down Expand Up @@ -132,9 +126,12 @@ def parse_response(resp, content, strict=False, content_type=None):

if ct != 'application/x-www-form-urlencoded' and strict:
return content
charset = options.get('charset', 'utf-8')
return url_decode(content, charset=charset).to_dict()

charset = options.get('charset', 'utf-8')
parsed = urlparse(content)
return parse_qsl(
parsed.query, encoding=charset, strict_parsing=strict, keep_blank_values=True
)

def prepare_request(uri, headers=None, data=None, method=None):
"""Make request parameters right."""
Expand All @@ -159,7 +156,7 @@ def encode_request_data(data, format):
if format == 'json':
return json.dumps(data or {}), 'application/json'
if format == 'urlencoded':
return url_encode(data or {}), 'application/x-www-form-urlencoded'
return urlencode(data or {}, encoding='application/x-www-form-urlencoded')
raise TypeError('Unknown format %r' % format)


Expand All @@ -185,11 +182,6 @@ def __init__(self, message, type=None, data=None):
self.data = data

def __str__(self):
if PY3:
return self.message
return self.message.encode('utf-8')

def __unicode__(self):
return self.message


Expand Down Expand Up @@ -384,7 +376,7 @@ def make_client(self, token=None):
if token:
if isinstance(token, (tuple, list)):
token = {'access_token': token[0]}
elif isinstance(token, string_types):
elif isinstance(token, str):
token = {'access_token': token}
client = oauthlib.oauth2.WebApplicationClient(
self.consumer_key, token=token
Expand Down Expand Up @@ -522,10 +514,10 @@ def authorize(self, callback=None, state=None, **kwargs):
if self.request_token_url:
token = self.generate_request_token(callback)[0]
url = '%s?oauth_token=%s' % (
self.expand_url(self.authorize_url), url_quote(token)
self.expand_url(self.authorize_url), quote(token)
)
if params:
url += '&' + url_encode(params)
url += '&' + urlencode(params)
else:
assert callback is not None, 'Callback is required for OAuth2'

Expand Down
4 changes: 2 additions & 2 deletions flask_oauthlib/contrib/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

import copy

from oauthlib.common import unicode_type, bytes_type
from oauthlib.common import unicode_type


__all__ = ['douban', 'dropbox', 'facebook', 'github', 'google', 'linkedin',
Expand Down Expand Up @@ -87,7 +87,7 @@ def make_scope_processor(default_scope):
def processor(**kwargs):
# request_token_params
scope = kwargs.pop('scope', [default_scope]) # default scope
if not isinstance(scope, (unicode_type, bytes_type)):
if not isinstance(scope, (unicode_type, bytes)):
scope = ','.join(scope) # allows list-style scope
request_token_params = kwargs.setdefault('request_token_params', {})
request_token_params.setdefault('scope', scope) # doesn't override
Expand Down
4 changes: 2 additions & 2 deletions flask_oauthlib/contrib/cache.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# coding: utf-8

from werkzeug.contrib.cache import NullCache, SimpleCache, FileSystemCache
from werkzeug.contrib.cache import MemcachedCache, RedisCache
from cachelib import NullCache, SimpleCache, FileSystemCache
from cachelib import MemcachedCache, RedisCache


class Cache(object):
Expand Down
2 changes: 1 addition & 1 deletion flask_oauthlib/provider/oauth1.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import logging
from functools import wraps
from werkzeug import cached_property
from werkzeug.utils import cached_property
from flask import request, redirect, url_for
from flask import make_response, abort
from oauthlib.oauth1 import RequestValidator
Expand Down
7 changes: 3 additions & 4 deletions flask_oauthlib/provider/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
from functools import wraps
from flask import request, url_for
from flask import redirect, abort
from werkzeug import cached_property
from werkzeug.utils import import_string
from werkzeug.utils import cached_property, import_string
from oauthlib import oauth2
from oauthlib.oauth2 import RequestValidator, Server
from oauthlib.common import to_unicode, add_params_to_uri
Expand Down Expand Up @@ -472,7 +471,7 @@ def decorated(*args, **kwargs):
# denied by user
e = oauth2.AccessDeniedError(state=request.values.get('state'))
return self._on_exception(e, e.in_uri(redirect_uri))

return self.confirm_authorization_request()
return decorated

Expand Down Expand Up @@ -502,7 +501,7 @@ def confirm_authorization_request(self):
return self._on_exception(e, e.in_uri(self.error_uri))
except oauth2.OAuth2Error as e:
log.debug('OAuth2Error: %r', e, exc_info=True)

# on auth error, we should preserve state if it's present according to RFC 6749
state = request.values.get('state')
if state and not e.state:
Expand Down
4 changes: 2 additions & 2 deletions flask_oauthlib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import base64
from flask import request, Response
from oauthlib.common import to_unicode, bytes_type
from oauthlib.common import to_unicode


def _get_uri_from_request(request):
Expand Down Expand Up @@ -41,7 +41,7 @@ def to_bytes(text, encoding='utf-8'):
"""Make sure text is bytes type."""
if not text:
return text
if not isinstance(text, bytes_type):
if not isinstance(text, bytes):
text = text.encode(encoding)
return text

Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
werkzeug>=3.0.1
Flask>=0.12.3
cachelib==0.1
mock==2.0.0
oauthlib==2.0.6
requests-oauthlib==0.8.0
Expand Down
2 changes: 0 additions & 2 deletions tests/_base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# coding: utf-8

import base64
import os
import sys
Expand Down
6 changes: 0 additions & 6 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from flask_oauthlib.client import encode_request_data
from flask_oauthlib.client import OAuthRemoteApp, OAuth
from flask_oauthlib.client import parse_response
from oauthlib.common import PY3

try:
import urllib2 as http
Expand Down Expand Up @@ -194,11 +193,6 @@ def test_token_types(self):

client_token = {'access_token': 'access token'}

if not PY3:
unicode_token = u'access token'
client = remote.make_client(token=unicode_token)
assert client.token == client_token

str_token = 'access token'
client = remote.make_client(token=str_token)
assert client.token == client_token
Expand Down