Skip to content
This repository has been archived by the owner on Feb 10, 2023. It is now read-only.

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim Fulton committed Nov 21, 2014
2 parents 97dab08 + 594ab05 commit f7b6cf2
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 26 deletions.
4 changes: 4 additions & 0 deletions bobo/README.txt
Expand Up @@ -22,6 +22,10 @@ To learn more. visit: http://bobo.digicool.com
Change History
==============

- Bobo will encode Unicode URLs for redirects automatically.

- Bobo will pass resource function arguments from data in JSON request bodies.

2.2.0 2014-07-10
----------------

Expand Down
2 changes: 2 additions & 0 deletions bobo/src/bobo.py
Expand Up @@ -345,6 +345,8 @@ def redirect(url, status=302, body=None,
"""
if body is None:
body = u'See %s' % url
if isinstance(url, unicode):
url = url.encode('utf-8')
response = webob.Response(status=status, headerlist=[('Location', url)])
response.content_type = content_type
response.unicode_body = body
Expand Down
8 changes: 8 additions & 0 deletions bobodoctestumentation/src/bobodoctestumentation/main.test
Expand Up @@ -336,3 +336,11 @@ Ordering
>>> app = makeapp(bobo_resources='bobo.testmodule1')
>>> app.get('/o').text
'f3'


Automatic encoding of redirect destinations
-------------------------------------------

>>> response = bobo.redirect(u"http://www.\u0113xample.com/")
>>> response.headers["location"]
'http://www.\xc4\x93xample.com/'
8 changes: 8 additions & 0 deletions bobodoctestumentation/src/bobodoctestumentation/more.txt
Expand Up @@ -1087,3 +1087,11 @@ with an Allow header.
>>> app.request('/users/54321',
... method="OPTIONS", status=405).headers["Allow"]
'GET, HEAD, POST, PUT'


Automatic encoding of redirect destinations
-------------------------------------------

Since URLs are often computed based on request data, it's easy for
applications to generate Unicode URLs. For this reason, unicode URL's
passed to ``bobo.redirect`` are UTF-8 encoded.
60 changes: 34 additions & 26 deletions bootstrap.py
Expand Up @@ -56,39 +56,48 @@
"file to be used."))
parser.add_option("-f", "--find-links",
help=("Specify a URL to search for buildout releases"))
parser.add_option("--allow-site-packages",
action="store_true", default=False,
help=("Let bootstrap.py use existing site packages"))


options, args = parser.parse_args()

######################################################################
# load/install setuptools

to_reload = False
try:
import pkg_resources
import setuptools
if options.allow_site_packages:
import setuptools
import pkg_resources
from urllib.request import urlopen
except ImportError:
ez = {}

try:
from urllib.request import urlopen
except ImportError:
from urllib2 import urlopen

# XXX use a more permanent ez_setup.py URL when available.
exec(urlopen('https://bitbucket.org/pypa/setuptools/raw/0.7.2/ez_setup.py'
).read(), ez)
setup_args = dict(to_dir=tmpeggs, download_delay=0)
ez['use_setuptools'](**setup_args)

if to_reload:
reload(pkg_resources)
import pkg_resources
# This does not (always?) update the default working set. We will
# do it.
for path in sys.path:
if path not in pkg_resources.working_set.entries:
pkg_resources.working_set.add_entry(path)
from urllib2 import urlopen

ez = {}
exec(urlopen('https://bootstrap.pypa.io/ez_setup.py').read(), ez)

if not options.allow_site_packages:
# ez_setup imports site, which adds site packages
# this will remove them from the path to ensure that incompatible versions
# of setuptools are not in the path
import site
# inside a virtualenv, there is no 'getsitepackages'.
# We can't remove these reliably
if hasattr(site, 'getsitepackages'):
for sitepackage_path in site.getsitepackages():
sys.path[:] = [x for x in sys.path if sitepackage_path not in x]

setup_args = dict(to_dir=tmpeggs, download_delay=0)
ez['use_setuptools'](**setup_args)
import setuptools
import pkg_resources

# This does not (always?) update the default working set. We will
# do it.
for path in sys.path:
if path not in pkg_resources.working_set.entries:
pkg_resources.working_set.add_entry(path)

######################################################################
# Install buildout
Expand Down Expand Up @@ -149,8 +158,7 @@ def _final_version(parsed_version):
import subprocess
if subprocess.call(cmd, env=dict(os.environ, PYTHONPATH=setuptools_path)) != 0:
raise Exception(
"Failed to execute command:\n%s",
repr(cmd)[1:-1])
"Failed to execute command:\n%s" % repr(cmd)[1:-1])

######################################################################
# Import and run buildout
Expand Down

0 comments on commit f7b6cf2

Please sign in to comment.