Skip to content

Commit

Permalink
Merge pull request #788 from hugapi/develop
Browse files Browse the repository at this point in the history
2.5.1 hotfix release
  • Loading branch information
timothycrosley committed May 9, 2019
2 parents 241499d + 1f6491b commit 610b1ed
Show file tree
Hide file tree
Showing 123 changed files with 3,896 additions and 2,879 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 2.5.0
current_version = 2.5.1

[bumpversion:file:.env]

Expand Down
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fi

export PROJECT_NAME=$OPEN_PROJECT_NAME
export PROJECT_DIR="$PWD"
export PROJECT_VERSION="2.5.0"
export PROJECT_VERSION="2.5.1"

if [ ! -d "venv" ]; then
if ! hash pyvenv 2>/dev/null; then
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ Ideally, within a virtual environment.

Changelog
=========
### 2.5.1 hotfix - May 9, 2019
- Fixed issue #784 - POST requests broken on 2.5.0
- Optimizations and simplification of async support, taking advantadge of Python3.4 deprecation.
- Fix issue #785: Empty query params are not ignored on 2.5.0
- Added support for modifying falcon API directly on startup
- Initial `black` formatting of code base, in preperation for CI enforced code formatting

### 2.5.0 - May 4, 2019
- Updated to latest Falcon: 2.0.0
- Added support for Marshmallow 3
Expand Down
2 changes: 1 addition & 1 deletion CODING_STANDARD.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Coding Standard
=========
Any submission to this project should closely follow the [PEP 8](https://www.python.org/dev/peps/pep-0008/) coding guidelines with the exceptions:

1. Lines can be up to 120 characters long.
1. Lines can be up to 100 characters long.
2. Single letter or otherwise nondescript variable names are prohibited.

Standards for new hug modules
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Account Requirements:

Base System Requirements:

- Python3.3+
- Python3.5+
- Python3-venv (included with most Python3 installations but some Ubuntu systems require that it be installed separately)
- bash or a bash compatible shell (should be auto-installed on Linux / Mac)
- [autoenv](https://github.com/kennethreitz/autoenv) (optional)
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/http/bobo_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import bobo


@bobo.query('/text', content_type='text/plain')
@bobo.query("/text", content_type="text/plain")
def text():
return 'Hello, world!'
return "Hello, world!"


app = bobo.Application(bobo_resources=__name__)
4 changes: 2 additions & 2 deletions benchmarks/http/bottle_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
app = bottle.Bottle()


@app.route('/text')
@app.route("/text")
def text():
return 'Hello, world!'
return "Hello, world!"
3 changes: 1 addition & 2 deletions benchmarks/http/cherrypy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@


class Root(object):

@cherrypy.expose
def text(self):
return 'Hello, world!'
return "Hello, world!"


app = cherrypy.tree.mount(Root())
Expand Down
7 changes: 3 additions & 4 deletions benchmarks/http/falcon_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@


class Resource(object):

def on_get(self, req, resp):
resp.status = falcon.HTTP_200
resp.content_type = 'text/plain'
resp.body = 'Hello, world!'
resp.content_type = "text/plain"
resp.body = "Hello, world!"


app = falcon.API()
app.add_route('/text', Resource())
app.add_route("/text", Resource())
4 changes: 2 additions & 2 deletions benchmarks/http/flask_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
app = flask.Flask(__name__)


@app.route('/text')
@app.route("/text")
def text():
return 'Hello, world!'
return "Hello, world!"
4 changes: 2 additions & 2 deletions benchmarks/http/hug_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import hug


@hug.get('/text', output_format=hug.output_format.text, parse_body=False)
@hug.get("/text", output_format=hug.output_format.text, parse_body=False)
def text():
return 'Hello, World!'
return "Hello, World!"


app = hug.API(__name__).http.server()
6 changes: 3 additions & 3 deletions benchmarks/http/muffin_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import muffin

app = muffin.Application('web')
app = muffin.Application("web")


@app.register('/text')
@app.register("/text")
def text(request):
return 'Hello, World!'
return "Hello, World!"
6 changes: 3 additions & 3 deletions benchmarks/http/pyramid_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
from pyramid.config import Configurator


@view_config(route_name='text', renderer='string')
@view_config(route_name="text", renderer="string")
def text(request):
return 'Hello, World!'
return "Hello, World!"


config = Configurator()

config.add_route('text', '/text')
config.add_route("text", "/text")

config.scan()
app = config.make_wsgi_app()
6 changes: 2 additions & 4 deletions benchmarks/http/tornado_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@

class TextHandler(tornado.web.RequestHandler):
def get(self):
self.write('Hello, world!')
self.write("Hello, world!")


application = tornado.web.Application([
(r"/text", TextHandler),
])
application = tornado.web.Application([(r"/text", TextHandler)])

if __name__ == "__main__":
application.listen(8000)
Expand Down
13 changes: 6 additions & 7 deletions benchmarks/internal/argument_populating.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
from hug.decorators import auto_kwargs
from hug.introspect import generate_accepted_kwargs

DATA = {'request': None}
DATA = {"request": None}


class Timer(object):

def __init__(self, name):
self.name = name

Expand All @@ -26,25 +25,25 @@ def my_method_with_kwargs(name, request=None, **kwargs):
pass


with Timer('generate_kwargs'):
accept_kwargs = generate_accepted_kwargs(my_method, ('request', 'response', 'version'))
with Timer("generate_kwargs"):
accept_kwargs = generate_accepted_kwargs(my_method, ("request", "response", "version"))

for test in range(100000):
my_method(test, **accept_kwargs(DATA))


with Timer('auto_kwargs'):
with Timer("auto_kwargs"):
wrapped_method = auto_kwargs(my_method)

for test in range(100000):
wrapped_method(test, **DATA)


with Timer('native_kwargs'):
with Timer("native_kwargs"):
for test in range(100000):
my_method_with_kwargs(test, **DATA)


with Timer('no_kwargs'):
with Timer("no_kwargs"):
for test in range(100000):
my_method(test, request=None)
2 changes: 1 addition & 1 deletion docker/template/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
from handlers import birthday, hello


@hug.extend_api('')
@hug.extend_api("")
def api():
return [hello, birthday]
2 changes: 1 addition & 1 deletion docker/template/handlers/hello.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


@hug.get("/hello")
def hello(name: str="World"):
def hello(name: str = "World"):
return "Hello, {name}".format(name=name)
42 changes: 22 additions & 20 deletions examples/authentication.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'''A basic example of authentication requests within a hug API'''
"""A basic example of authentication requests within a hug API"""
import hug
import jwt

Expand All @@ -9,10 +9,10 @@
# on successful authentication. Naturally, this is a trivial demo, and a much
# more robust verification function is recommended. This is for strictly
# illustrative purposes.
authentication = hug.authentication.basic(hug.authentication.verify('User1', 'mypassword'))
authentication = hug.authentication.basic(hug.authentication.verify("User1", "mypassword"))


@hug.get('/public')
@hug.get("/public")
def public_api_call():
return "Needs no authentication"

Expand All @@ -21,9 +21,9 @@ def public_api_call():
# Directives can provide computed input parameters via an abstraction
# layer so as not to clutter your API functions with access to the raw
# request object.
@hug.get('/authenticated', requires=authentication)
@hug.get("/authenticated", requires=authentication)
def basic_auth_api_call(user: hug.directives.user):
return 'Successfully authenticated with user: {0}'.format(user)
return "Successfully authenticated with user: {0}".format(user)


# Here is a slightly less trivial example of how authentication might
Expand All @@ -40,10 +40,10 @@ def __init__(self, user_id, api_key):


def api_key_verify(api_key):
magic_key = '5F00832B-DE24-4CAF-9638-C10D1C642C6C' # Obviously, this would hit your database
magic_key = "5F00832B-DE24-4CAF-9638-C10D1C642C6C" # Obviously, this would hit your database
if api_key == magic_key:
# Success!
return APIUser('user_foo', api_key)
return APIUser("user_foo", api_key)
else:
# Invalid key
return None
Expand All @@ -52,33 +52,35 @@ def api_key_verify(api_key):
api_key_authentication = hug.authentication.api_key(api_key_verify)


@hug.get('/key_authenticated', requires=api_key_authentication) # noqa
@hug.get("/key_authenticated", requires=api_key_authentication) # noqa
def basic_auth_api_call(user: hug.directives.user):
return 'Successfully authenticated with user: {0}'.format(user.user_id)
return "Successfully authenticated with user: {0}".format(user.user_id)


def token_verify(token):
secret_key = 'super-secret-key-please-change'
secret_key = "super-secret-key-please-change"
try:
return jwt.decode(token, secret_key, algorithm='HS256')
return jwt.decode(token, secret_key, algorithm="HS256")
except jwt.DecodeError:
return False


token_key_authentication = hug.authentication.token(token_verify)


@hug.get('/token_authenticated', requires=token_key_authentication) # noqa
@hug.get("/token_authenticated", requires=token_key_authentication) # noqa
def token_auth_call(user: hug.directives.user):
return 'You are user: {0} with data {1}'.format(user['user'], user['data'])
return "You are user: {0} with data {1}".format(user["user"], user["data"])


@hug.post('/token_generation') # noqa
@hug.post("/token_generation") # noqa
def token_gen_call(username, password):
"""Authenticate and return a token"""
secret_key = 'super-secret-key-please-change'
mockusername = 'User2'
mockpassword = 'Mypassword'
if mockpassword == password and mockusername == username: # This is an example. Don't do that.
return {"token" : jwt.encode({'user': username, 'data': 'mydata'}, secret_key, algorithm='HS256')}
return 'Invalid username and/or password for user: {0}'.format(username)
secret_key = "super-secret-key-please-change"
mockusername = "User2"
mockpassword = "Mypassword"
if mockpassword == password and mockusername == username: # This is an example. Don't do that.
return {
"token": jwt.encode({"user": username, "data": "mydata"}, secret_key, algorithm="HS256")
}
return "Invalid username and/or password for user: {0}".format(username)
4 changes: 2 additions & 2 deletions examples/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@


@hug.cli(version="1.0.0")
def cli(name: 'The name', age: hug.types.number):
def cli(name: "The name", age: hug.types.number):
"""Says happy birthday to a user"""
return "Happy {age} Birthday {name}!\n".format(**locals())


if __name__ == '__main__':
if __name__ == "__main__":
cli.interface.cli()
14 changes: 7 additions & 7 deletions examples/cli_object.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import hug

API = hug.API('git')
API = hug.API("git")


@hug.object(name='git', version='1.0.0', api=API)
@hug.object(name="git", version="1.0.0", api=API)
class GIT(object):
"""An example of command like calls via an Object"""

@hug.object.cli
def push(self, branch='master'):
return 'Pushing {}'.format(branch)
def push(self, branch="master"):
return "Pushing {}".format(branch)

@hug.object.cli
def pull(self, branch='master'):
return 'Pulling {}'.format(branch)
def pull(self, branch="master"):
return "Pulling {}".format(branch)


if __name__ == '__main__':
if __name__ == "__main__":
API.cli()
4 changes: 2 additions & 2 deletions examples/cors_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
api.http.add_middleware(hug.middleware.CORSMiddleware(api, max_age=10))


@hug.get('/demo')
@hug.get("/demo")
def get_demo():
return {'result': 'Hello World'}
return {"result": "Hello World"}
2 changes: 1 addition & 1 deletion examples/cors_per_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


@hug.get()
def cors_supported(cors: hug.directives.cors="*"):
def cors_supported(cors: hug.directives.cors = "*"):
return "Hello world!"
Loading

0 comments on commit 610b1ed

Please sign in to comment.