Skip to content

Commit

Permalink
implement all shortcuts of http methods without magic.
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyseek authored and lepture committed Jan 25, 2015
1 parent e81decc commit 280661d
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions flask_oauthlib/contrib/client/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os
import contextlib
import warnings
import functools
try:
from urllib.parse import urljoin
except ImportError:
Expand Down Expand Up @@ -133,16 +134,23 @@ def request(self, method, url, token=None, *args, **kwargs):
url = urljoin(self.endpoint_url, url)
return getattr(client, method)(url, *args, **kwargs)

# magic: generate methods which forward to self.client
def make_request_shortcut(method):
def shortcut(self, url, token=None, *args, **kwargs):
return self.request(method, url, token, *args, **kwargs)
shortcut.func_name = shortcut.__name__ = method
return shortcut
for method in forward_methods:
locals()[method] = make_request_shortcut(method)
del method
del make_request_shortcut
def head(self, *args, **kwargs):
return self.request('head', *args, **kwargs)

def get(self, *args, **kwargs):
return self.request('get', *args, **kwargs)

def post(self, *args, **kwargs):
return self.request('post', *args, **kwargs)

def put(self, *args, **kwargs):
return self.request('put', *args, **kwargs)

def delete(self, *args, **kwargs):
return self.request('delete', *args, **kwargs)

def patch(self, *args, **kwargs):
return self.request('patch', *args, **kwargs)


class OAuth1Application(BaseApplication):
Expand Down

0 comments on commit 280661d

Please sign in to comment.