-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from hannseman/master
Add access to APIKey object, repeated url parameters, django <1.5 fixes
- Loading branch information
Showing
11 changed files
with
84 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,34 @@ | ||
import hmac | ||
import urllib2 | ||
from hashlib import sha1 | ||
from django.utils.encoding import force_unicode | ||
from django.utils.encoding import smart_str, force_unicode | ||
|
||
|
||
def get_sign(secret, querystring=None, **params): | ||
""" | ||
Return sign for querystring. | ||
Logic: | ||
- Sort querystring by parameter keys | ||
- Sort querystring by parameter keys and by value if two or more parameter keys share the same name | ||
- URL encode sorted querystring | ||
- Generate a hex digested hmac/sha1 hash using given secret | ||
""" | ||
if querystring: | ||
params = dict(param.split('=') for param in querystring.split('&')) | ||
sorted_params = ((key, params[key]) for key in sorted(params.keys())) | ||
sorted_params = [] | ||
for key, value in sorted(params.items(), key=lambda x: x[0]): | ||
if isinstance(value, basestring): | ||
sorted_params.append((key, value)) | ||
else: | ||
try: | ||
value = list(value) | ||
except TypeError, e: | ||
assert 'is not iterable' in str(e) | ||
value = smart_str(value) | ||
sorted_params.append((key, value)) | ||
else: | ||
sorted_params.extend((key, item) for item in sorted(value)) | ||
param_list = ('='.join((field, force_unicode(value))) for field, value in sorted_params) | ||
validation_string = force_unicode('&'.join(param_list)) | ||
return hmac.new(str(secret), urllib2.quote(validation_string.encode('utf-8')), sha1).hexdigest() | ||
validation_string = smart_str('&'.join(param_list)) | ||
validation_string = urllib2.quote(validation_string) | ||
return hmac.new(str(secret), validation_string, sha1).hexdigest() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,14 @@ | ||
""" | ||
Based entirely on Django's own ``setup.py``. | ||
""" | ||
#!/usr/bin/env python | ||
|
||
import codecs | ||
import os | ||
import sys | ||
from distutils.command.install_data import install_data | ||
from distutils.command.install import INSTALL_SCHEMES | ||
try: | ||
from setuptools import setup | ||
except ImportError: | ||
from distutils.core import setup # NOQA | ||
|
||
|
||
class osx_install_data(install_data): | ||
# On MacOS, the platform-specific lib dir is at: | ||
# /System/Library/Framework/Python/.../ | ||
# which is wrong. Python 2.5 supplied with MacOS 10.5 has an Apple-specific | ||
# fix for this in distutils.command.install_data#306. It fixes install_lib | ||
# but not install_data, which is why we roll our own install_data class. | ||
|
||
def finalize_options(self): | ||
# By the time finalize_options is called, install.install_lib is set to | ||
# the fixed directory, so we set the installdir to install_lib. The | ||
# install_data class uses ('install_data', 'install_dir') instead. | ||
self.set_undefined_options('install', ('install_lib', 'install_dir')) | ||
install_data.finalize_options(self) | ||
|
||
if sys.platform == "darwin": | ||
cmdclasses = {'install_data': osx_install_data} | ||
else: | ||
cmdclasses = {'install_data': install_data} | ||
|
||
|
||
def fullsplit(path, result=None): | ||
""" | ||
Split a pathname into components (the opposite of os.path.join) in a | ||
platform-neutral way. | ||
""" | ||
if result is None: | ||
result = [] | ||
head, tail = os.path.split(path) | ||
if head == '': | ||
return [tail] + result | ||
if head == path: | ||
return result | ||
return fullsplit(head, [tail] + result) | ||
|
||
# Tell distutils to put the data_files in platform-specific installation | ||
# locations. See here for an explanation: | ||
# http://groups.google.com/group/comp.lang.python/browse_thread/thread/35ec7b2fed36eaec/2105ee4d9e8042cb | ||
for scheme in INSTALL_SCHEMES.values(): | ||
scheme['data'] = scheme['purelib'] | ||
|
||
# Compile the list of packages available, because distutils doesn't have | ||
# an easy way to do this. | ||
packages, data_files = [], [] | ||
root_dir = os.path.dirname(__file__) | ||
if root_dir != '': | ||
os.chdir(root_dir) | ||
form_dir = 'formapi' | ||
|
||
for dirpath, dirnames, filenames in os.walk(form_dir): | ||
# Ignore dirnames that start with '.' | ||
if os.path.basename(dirpath).startswith("."): | ||
continue | ||
if '__init__.py' in filenames: | ||
packages.append('.'.join(fullsplit(dirpath))) | ||
elif filenames: | ||
data_files.append([dirpath, [os.path.join(dirpath, f) for f in filenames]]) | ||
|
||
from setuptools import setup, find_packages | ||
|
||
version = __import__('formapi').__version__ | ||
import formapi | ||
|
||
setup( | ||
name="django-formapi", | ||
version=version, | ||
version=formapi.__version__, | ||
|
||
description="Django API creation with signed requests utilizing forms for validation.", | ||
long_description=codecs.open( | ||
|
@@ -86,12 +20,13 @@ def fullsplit(path, result=None): | |
author="Hannes Ljungberg", | ||
author_email="[email protected]", | ||
url="https://github.com/5monkeys/django-formapi", | ||
download_url="https://github.com/5monkeys/django-formapi/tarball/%s" % (version,), | ||
download_url="https://github.com/5monkeys/django-formapi/tarball/%s" % (formapi.__version__,), | ||
keywords=["django", "formapi", "api", "rpc", "signed", "request", "form", "validation"], | ||
platforms=['any'], | ||
license='MIT', | ||
classifiers=[ | ||
"Programming Language :: Python", | ||
'Programming Language :: Python :: 2', | ||
"Programming Language :: Python :: 2.6", | ||
"Programming Language :: Python :: 2.7", | ||
'Framework :: Django', | ||
|
@@ -103,9 +38,8 @@ def fullsplit(path, result=None): | |
'Topic :: Utilities', | ||
'Topic :: Software Development :: Libraries :: Python Modules', | ||
], | ||
cmdclass=cmdclasses, | ||
data_files=data_files, | ||
packages=packages, | ||
packages=find_packages(), | ||
include_package_data=True, | ||
install_requires=['django-uuidfield'], | ||
tests_require=['Django', 'django-uuidfield', 'pytz'], | ||
test_suite='run_tests.main', | ||
|