Permalink
Browse files

web.py upgrade

  • Loading branch information...
1 parent c1face8 commit 417b9d2be7cf87b31b93ebc5612f0c9a9958a34f @aaronsw committed Jun 18, 2008
Showing with 264 additions and 112 deletions.
  1. +8 −3 blog.py
  2. +11 −7 petition.py
  3. +1 −1 static/style.css
  4. +4 −0 templates/petition_list.html
  5. +1 −1 templates/petitionform.html
  6. +2 −2 utils/forms.py
  7. +1 −1 vendor/webpy.dev/.bzr/branch/last-revision
  8. BIN vendor/webpy.dev/.bzr/checkout/dirstate
  9. +14 −11 vendor/webpy.dev/.bzr/checkout/merge-hashes
  10. +8 −1 vendor/webpy.dev/.bzr/repository/inventory.kndx
  11. BIN vendor/webpy.dev/.bzr/repository/inventory.knit
  12. +5 −1 ...repository/knits/34/75@2c515a54-6b0d-0410-94c8-a23cf037ada6%3a%3atrunk%252%46web%252%46db.py.kndx
  13. BIN ...repository/knits/34/75@2c515a54-6b0d-0410-94c8-a23cf037ada6%3a%3atrunk%252%46web%252%46db.py.knit
  14. +3 −1 vendor/webpy.dev/.bzr/repository/knits/35/db.py-20071224144004-24ism0ixynr7qv0v-4.kndx
  15. BIN vendor/webpy.dev/.bzr/repository/knits/35/db.py-20071224144004-24ism0ixynr7qv0v-4.knit
  16. +3 −1 .../knits/37/188@2c515a54-6b0d-0410-94c8-a23cf037ada6%3a%3atrunk%252%46web%252%46application.py.kndx
  17. BIN .../knits/37/188@2c515a54-6b0d-0410-94c8-a23cf037ada6%3a%3atrunk%252%46web%252%46application.py.knit
  18. +2 −1 .../.bzr/repository/knits/44/129@2c515a54-6b0d-0410-94c8-a23cf037ada6%3a%3atrunk%252%46setup.py.kndx
  19. BIN .../.bzr/repository/knits/44/129@2c515a54-6b0d-0410-94c8-a23cf037ada6%3a%3atrunk%252%46setup.py.knit
  20. +2 −1 vendor/webpy.dev/.bzr/repository/knits/6f/webtest.py-20071224144004-24ism0ixynr7qv0v-6.kndx
  21. BIN vendor/webpy.dev/.bzr/repository/knits/6f/webtest.py-20071224144004-24ism0ixynr7qv0v-6.knit
  22. +2 −1 vendor/webpy.dev/.bzr/repository/knits/d9/doctests.py-20071224144004-24ism0ixynr7qv0v-5.kndx
  23. BIN vendor/webpy.dev/.bzr/repository/knits/d9/doctests.py-20071224144004-24ism0ixynr7qv0v-5.knit
  24. +2 −1 vendor/webpy.dev/.bzr/repository/knits/e2/application.py-20080104061149-fu62x4nc9hbs6ukn-1.kndx
  25. BIN vendor/webpy.dev/.bzr/repository/knits/e2/application.py-20080104061149-fu62x4nc9hbs6ukn-1.knit
  26. +8 −1 vendor/webpy.dev/.bzr/repository/revisions.kndx
  27. BIN vendor/webpy.dev/.bzr/repository/revisions.knit
  28. +2 −2 vendor/webpy.dev/setup.py
  29. +26 −0 vendor/webpy.dev/test/application.py
  30. +3 −4 vendor/webpy.dev/test/db.py
  31. +1 −1 vendor/webpy.dev/test/doctests.py
  32. +3 −3 vendor/webpy.dev/test/webtest.py
  33. +42 −3 vendor/webpy.dev/web/application.py
  34. +107 −55 vendor/webpy.dev/web/db.py
  35. +1 −2 vendor/webpy.dev/web/webapi.py
  36. +2 −7 webapp.py
View
11 blog.py
@@ -1,9 +1,10 @@
import web
urls = (
- '/blog/', 'index',
- '/blog/feed', 'feed',
- '/blog/(.*)', 'post',
+ '', 'reblog',
+ '/', 'index',
+ '/feed', 'feed',
+ '/(.*)', 'post',
)
render = web.template.render('templates/', base='base')
@@ -272,4 +273,8 @@ def GET(self, name):
else:
raise web.notfound
+class reblog:
+ def GET(self):
+ raise web.seeother('/')
+
app = web.application(urls, globals())
View
@@ -6,11 +6,15 @@
from settings import db, render
urls = (
- '/c/', 'index',
- '/c/new/', 'new',
- '/c/(.*)', 'petition'
+ '', 'redir',
+ '/', 'index',
+ '/new', 'new',
+ '/(.*)', 'petition'
)
-
+
+class redir:
+ def GET(self): raise web.seeother('/')
+
class index:
def GET(self):
petitions = db.select('petition', what='id, title', order='created desc').list()
@@ -39,7 +43,7 @@ def POST(self):
db.insert('signatory', seqname=False, user_id=owner_id, petition_id=p.id)
helpers.setcookie('wd_email', p.email)
helpers.set_msg("Congratulations, you've created your petition. Now share it with all your friends.")
- return web.seeother('/c/%s' % p.id)
+ return web.seeother('/%s' % p.id)
else:
return render.petitionform(pform)
@@ -96,7 +100,7 @@ def POST_password(self, pid):
i = web.input()
if form.validates(i):
insert_password(i)
- raise web.seeother('/c/%s' % pid)
+ raise web.seeother('/%s' % pid)
else:
return self.GET(pid, passwordform=form)
@@ -105,7 +109,7 @@ def POST_sign(self, pid):
i = web.input()
if form.validates(i):
take_signature(i, pid)
- return web.seeother('/c/%s' % pid)
+ return web.seeother('/%s' % pid)
else:
return self.GET(pid, signform=form)
View
@@ -24,7 +24,7 @@ th { text-align: left;}
h1 { font-weight: normal; }
h1 a, h1 img { color: white; text-decoration: none; border: 0; }
table.interest_group_ratings td { text-align: right; }
-th, td { padding-left: 0.5em; } /* space out the columns a bit */
+th, td { padding-left: 0.5em; vertical-align: top; } /* space out the columns a bit */
table.interest_group_support td, th { text-align: left; }
.explain { color: #999; margin-top: -.5em; font-size: smaller;}
@@ -2,7 +2,11 @@
$var title: Recent petitions
+<p><a href="/c/new">Start a new petition...</a></p>
+
<ul>
$for p in petitions:
<li><a href="/c/$p.id">$p.title</a></li>
</ul>
+
+<p><a href="/c/new">Start a new petition...</a></p>
@@ -2,7 +2,7 @@
$var title: New petition
-<form name="petition" method="POST" action="/c/new/">
+<form name="petition" method="POST" action="/c/new">
$if not form.valid: <p class="error">Please try again after fixing the errors highlighted below:</p>
$:form.render()
<input type="submit" value="Submit"/>
View
@@ -14,8 +14,8 @@ def doesnotexist(pid):
form.Textbox('id',
form.notnull,
form.Validator('ID already exists, Choose a different one.', doesnotexist),
- post='(this becomes a part of your petition URL)',
- description='Petition ID:',
+ pre='http://watchdog.net/c/',
+ description='URL:',
size='30'),
form.Textarea('description', description="Description:", rows='20', cols='80'),
form.Textbox('email',
@@ -1 +1 @@
-229 aaronsw@frabjous.local-20080507190053-rk2uln4j6q0kbwcn
+236 anand@bodhi-20080609122919-1fcellws7tp73dzt
Binary file not shown.
@@ -1,18 +1,21 @@
BZR merge-modified list format 1
-file_id: 75@2c515a54-6b0d-0410-94c8-a23cf037ada6::trunk%2Fweb%2F__init__.py
-hash: 6d1221d61a0076de78c0ffebe9ba27510bca794f
-
file_id: 75@2c515a54-6b0d-0410-94c8-a23cf037ada6::trunk%2Fweb%2Fdb.py
-hash: 5f2b0e6bdfadd720d61eb5173f6cc3af3989dc61
-
-file_id: webopenid.py-20080423000651-9d5zyrzhe3it6xd1-1
-hash: 164004bfb3b908f2ec0c82db6f3060a8630e2b72
+hash: b18b9c89916f63d998ffccd7366a80f7ab838522
file_id: db.py-20071224144004-24ism0ixynr7qv0v-4
-hash: 7d7e9d361e8598dc792aae5746e1e811d10c627e
+hash: e4893eff60a5724e74888e634180e1b291940574
+
+file_id: application.py-20080104061149-fu62x4nc9hbs6ukn-1
+hash: cd191ed5f55866ec7bc82a2dc79c5a031d6617e4
file_id: webtest.py-20071224144004-24ism0ixynr7qv0v-6
-hash: 2ebf51532da533acb04cad626846893c39ea7929
+hash: 1dd9d2058cd24d99927961f13d86148150fda09f
+
+file_id: doctests.py-20071224144004-24ism0ixynr7qv0v-5
+hash: dbf2c1b99885a1f0d055255a48d301a524bfa734
+
+file_id: 129@2c515a54-6b0d-0410-94c8-a23cf037ada6::trunk%2Fsetup.py
+hash: 3a5e3216d3d09202330a78bec20bf668dbf7392b
-file_id: 75@2c515a54-6b0d-0410-94c8-a23cf037ada6::trunk%2Fweb%2Fhttp.py
-hash: 3585f0bfb61ed5f457c14a76d8557c84ef491190
+file_id: 188@2c515a54-6b0d-0410-94c8-a23cf037ada6::trunk%2Fweb%2Fapplication.py
+hash: 909f0172b62c03f550d0b8171478a4f47f952a23
@@ -241,4 +241,11 @@ aaronsw@frabjous.local-20080423235130-k7g5ujwtipsvp0h8 line-delta 111446 289 236
anand@bodhi-20080501032419-oc97up88pdrt3bpm line-delta 111735 406 237 :
anand@bodhi-20080501033721-dls5lrujbg3xp7xn line-delta 112141 279 238 :
aaronsw@frabjous.local-20080507185357-v2qx2p6dqpuu8plo line-delta 112420 288 239 :
-aaronsw@frabjous.local-20080507190053-rk2uln4j6q0kbwcn line-delta 112708 299 240 :
+aaronsw@frabjous.local-20080507190053-rk2uln4j6q0kbwcn line-delta 112708 299 240 :
+anand@bodhi.local-20080517120955-8oz0k2c9n4mpjum6 line-delta 113007 362 241 :
+anand@bodhi-20080527082449-skj0x4j717v4bayx line-delta 113369 407 242 :
+anand@bodhi-20080527092234-luhs08o155df9j6o fulltext 113776 2446 243 :
+anand@bodhi.local-20080601051344-s5oijuqhot1v6yo3 line-delta 116222 283 244 :
+anand@bodhi-20080601174913-4xikqwtqsk5r46o7 line-delta 116505 397 245 :
+anand@bodhi-20080604040704-zvx77bcfr6oyw416 line-delta 116902 387 246 :
+anand@bodhi-20080609122919-1fcellws7tp73dzt line-delta 117289 277 247 :
Binary file not shown.
@@ -32,4 +32,8 @@ anand@bodhi-20080417064101-e7q81z6a17p9yy6u line-delta 34101 685 27 :
aaronsw@frabjous.local-20080420131848-kps8q3qrnmp9isya line-delta 34786 851 28 :
anand@bodhi-20080501032419-oc97up88pdrt3bpm line-delta 35637 858 29 :
anand@bodhi-20080501033721-dls5lrujbg3xp7xn line-delta 36495 501 30 :
-aaronsw@frabjous.local-20080507185357-v2qx2p6dqpuu8plo line-delta 36996 548 31 :
+aaronsw@frabjous.local-20080507185357-v2qx2p6dqpuu8plo line-delta 36996 548 31 :
+anand@bodhi.local-20080517120955-8oz0k2c9n4mpjum6 line-delta 37544 501 32 :
+anand@bodhi-20080527082449-skj0x4j717v4bayx line-delta 38045 736 33 :
+anand@bodhi-20080527092234-luhs08o155df9j6o line-delta 38781 470 34 :
+anand@bodhi.local-20080601051344-s5oijuqhot1v6yo3 line-delta 39251 320 35 :
@@ -4,4 +4,6 @@ anandology@gmail.com-20071224152002-hmablr4avsk2rz1e fulltext 0 520 :
anandology@gmail.com-20080104054819-1ybcvgcch1ky6i89 line-delta 520 718 0 :
anandology@gmail.com-20080218150912-j98dt7zbcrh4ukaf fulltext 1238 1012 1 :
anand@bodhi-20080417064101-e7q81z6a17p9yy6u line-delta 2250 249 2 :
-anand@bodhi-20080501032419-oc97up88pdrt3bpm line-delta 2499 262 3 :
+anand@bodhi-20080501032419-oc97up88pdrt3bpm line-delta 2499 262 3 :
+anand@bodhi.local-20080517120955-8oz0k2c9n4mpjum6 line-delta 2761 233 4 :
+anand@bodhi-20080527082449-skj0x4j717v4bayx line-delta 2994 169 5 :
@@ -19,4 +19,6 @@ aaronsw@frabjous.local-20080417222158-7udin5ya0z0ba1mv line-delta 24321 494 14 1
aaronsw@frabjous.local-20080417222922-wgo21xvd2kvbt3qb line-delta 24815 178 15 :
anand@bodhi-20080420115346-t0oumys1ke1i2ixp line-delta 24993 244 16 :
aaronsw@frabjous.local-20080420131929-re8mbchpe9rkvpni line-delta 25237 194 17 :
-aaronsw@frabjous.local-20080420132242-mmrnjyxka0x00d6v line-delta 25431 130 18 :
+aaronsw@frabjous.local-20080420132242-mmrnjyxka0x00d6v line-delta 25431 130 18 :
+anand@bodhi-20080601174913-4xikqwtqsk5r46o7 line-delta 25561 621 19 :
+anand@bodhi-20080604040704-zvx77bcfr6oyw416 line-delta 26182 341 20 :
@@ -6,4 +6,5 @@ svn-v3-none:2c515a54-6b0d-0410-94c8-a23cf037ada6::162 line-delta 533 165 1 :
svn-v3-none:2c515a54-6b0d-0410-94c8-a23cf037ada6::165 line-delta 698 136 2 :
svn-v3-none:2c515a54-6b0d-0410-94c8-a23cf037ada6::169 fulltext 834 430 3 :
svn-v3-none:2c515a54-6b0d-0410-94c8-a23cf037ada6::181 line-delta 1264 136 4 :
-anandology@gmail.com-20070920031457-zmtdvq9rn837poo9 line-delta 1400 122 5 :
+anandology@gmail.com-20070920031457-zmtdvq9rn837poo9 line-delta 1400 122 5 :
+anand@bodhi-20080609122919-1fcellws7tp73dzt line-delta 1522 177 6 :
@@ -2,4 +2,5 @@
anandology@gmail.com-20071224152002-hmablr4avsk2rz1e fulltext 0 1550 :
anandology@gmail.com-20080218150912-j98dt7zbcrh4ukaf line-delta 1550 245 0 :
-anand@bodhi-20080501032419-oc97up88pdrt3bpm line-delta 1795 230 1 :
+anand@bodhi-20080501032419-oc97up88pdrt3bpm line-delta 1795 230 1 :
+anand@bodhi-20080527082449-skj0x4j717v4bayx line-delta 2025 228 2 :
@@ -1,4 +1,5 @@
# bzr knit index 8
anandology@gmail.com-20071224152002-hmablr4avsk2rz1e fulltext 0 281 :
-anandology@gmail.com-20080218150912-j98dt7zbcrh4ukaf line-delta 281 192 0 :
+anandology@gmail.com-20080218150912-j98dt7zbcrh4ukaf line-delta 281 192 0 :
+anand@bodhi-20080604040704-zvx77bcfr6oyw416 line-delta 473 192 1 :
@@ -1,4 +1,5 @@
# bzr knit index 8
anandology@gmail.com-20080104070833-gv1iff7dl7ihqvws fulltext 0 646 :
-anand@bodhi-20080417041245-3eurpwmlcvnj602i line-delta 646 420 0 :
+anand@bodhi-20080417041245-3eurpwmlcvnj602i line-delta 646 420 0 :
+anand@bodhi-20080601174913-4xikqwtqsk5r46o7 line-delta 1066 396 1 :
@@ -241,4 +241,11 @@ aaronsw@frabjous.local-20080423235130-k7g5ujwtipsvp0h8 fulltext 72682 371 236 :
anand@bodhi-20080501032419-oc97up88pdrt3bpm fulltext 73053 367 237 :
anand@bodhi-20080501033721-dls5lrujbg3xp7xn fulltext 73420 351 238 :
aaronsw@frabjous.local-20080507185357-v2qx2p6dqpuu8plo fulltext 73771 384 239 :
-aaronsw@frabjous.local-20080507190053-rk2uln4j6q0kbwcn fulltext 74155 372 240 :
+aaronsw@frabjous.local-20080507190053-rk2uln4j6q0kbwcn fulltext 74155 372 240 :
+anand@bodhi.local-20080517120955-8oz0k2c9n4mpjum6 fulltext 74527 388 241 :
+anand@bodhi-20080527082449-skj0x4j717v4bayx fulltext 74915 356 242 :
+anand@bodhi-20080527092234-luhs08o155df9j6o fulltext 75271 381 243 :
+anand@bodhi.local-20080601051344-s5oijuqhot1v6yo3 fulltext 75652 365 244 :
+anand@bodhi-20080601174913-4xikqwtqsk5r46o7 fulltext 76017 379 245 :
+anand@bodhi-20080604040704-zvx77bcfr6oyw416 fulltext 76396 361 246 :
+anand@bodhi-20080609122919-1fcellws7tp73dzt fulltext 76757 364 247 :
Binary file not shown.
@@ -5,12 +5,12 @@
from distutils.core import setup
setup(name='web.py',
- version='0.22',
+ version='0.3',
description='web.py: makes web apps',
author='Aaron Swartz',
author_email='me@aaronsw.com',
url=' http://webpy.org/',
- packages=['web', 'web.wsgiserver'],
+ packages=['web', 'web.wsgiserver', 'web.contrib'],
long_description="Think about the ideal way to write a web app. Write the code to make it happen.",
license="Public domain",
platforms=["any"],
@@ -71,6 +71,32 @@ def GET(self, name):
response = app.request('/b/foo?x=2')
self.assertEquals(response.status, '301 Moved Permanently')
self.assertEquals(response.headers['Location'], 'http://0.0.0.0:8080/hello/foo?x=2')
+
+ def test_subdirs(self):
+ urls = (
+ "/(.*)", "blog"
+ )
+ class blog:
+ def GET(self, path):
+ return "blog " + path
+ app_blog = web.application(urls, locals())
+
+ urls = (
+ "/blog", app_blog,
+ "/(.*)", "index"
+ )
+ class index:
+ def GET(self, path):
+ return "hello " + path
+ app = web.application(urls, locals())
+
+ self.assertEquals(app.request('/blog/foo').data, 'blog foo')
+ self.assertEquals(app.request('/foo').data, 'hello foo')
+
+ def processor(handler):
+ return web.ctx.path + ":" + handler()
+ app.add_processor(processor)
+ self.assertEquals(app.request('/blog/foo').data, '/blog/foo:blog foo')
if __name__ == '__main__':
webtest.main()
@@ -68,10 +68,9 @@ def testNestedTransactions(self):
self.assertRows(2)
def testPooling(self):
- db = webtest.setup_database(self.dbname)
- db.hasPooling = True
- import DBUtils
- self.assertTrue(isinstance(db.ctx.db, DBUtils.PooledDB.PooledDB))
+ db = webtest.setup_database(self.dbname, pooling=True)
+ self.assertEquals(db.ctx.db.__class__.__module__, 'DBUtils.PooledDB')
+ db.select('person', limit=1)
def test_multiple_insert(self):
db = webtest.setup_database(self.dbname)
@@ -3,7 +3,7 @@
import webtest
def suite():
- modules = ["web.utils", "web.db", "web.net", "web.wsgi", "web.http", "web.webapi", "web.request", "web.session"]
+ modules = ["web.utils", "web.db", "web.net", "web.wsgi", "web.http", "web.webapi", "web.request", "web.session", "web.application"]
return webtest.doctest_suite(modules)
if __name__ == "__main__":
@@ -119,11 +119,11 @@ def suite(module_names):
suite.addTest(module_suite(mod))
return suite
-def setup_database(dbname):
+def setup_database(dbname, pooling=False):
if dbname == 'sqlite':
- db = web.database(dbn=dbname, db='webpy.db')
+ db = web.database(dbn=dbname, db='webpy.db', pooling=pooling)
else:
- db = web.database(dbn=dbname, db='webpy', user='scott', pw='tiger')
+ db = web.database(dbn=dbname, db='webpy', user='scott', pw='tiger', pooling=pooling)
if '-v' in sys.argv:
db.printing = True
@@ -347,13 +347,40 @@ def is_class(o): return isinstance(o, (types.ClassType, type))
def _match(self, mapping, value):
for pat, what in utils.group(mapping, 2):
- if isinstance(what, basestring):
- what, result = utils.re_subm('^' + pat + '$', what, web.ctx.path)
+ if isinstance(what, application):
+ if value.startswith(pat):
+ f = lambda: self._delegate_sub_application(pat, what)
+ return f, None
+ else:
+ continue
+ elif isinstance(what, basestring):
+ what, result = utils.re_subm('^' + pat + '$', what, value)
else:
- result = utils.re_compile('^' + pat + '$').match(web.ctx.path)
+ result = utils.re_compile('^' + pat + '$').match(value)
+
if result: # it's a match
return what, [x and urllib.unquote(x) for x in result.groups()]
return None, None
+
+ def _delegate_sub_application(self, dir, app):
+ """Deletes request to sub application `app` rooted at the directory `dir`.
+ The home, homepath, path and fullpath values in web.ctx are updated to mimic request
+ to the subapp and are restored after it is handled.
+
+ @@Any issues with when used with yield?
+ """
+ try:
+ oldctx = web.storage(web.ctx)
+ web.ctx.home += dir
+ web.ctx.homepath += dir
+ web.ctx.path = web.ctx.path[len(dir):]
+ web.ctx.fullpath = web.ctx.fullpath[len(dir):]
+ return app.handle()
+ finally:
+ web.ctx.home = oldctx.home
+ web.ctx.homepath = oldctx.homepath
+ web.ctx.path = oldctx.path
+ web.ctx.fullpath = oldctx.fullpath
class auto_application(application):
"""Application similar to `application` but urls are constructed
@@ -437,6 +464,18 @@ def handle(self):
host = web.ctx.host.split(':')[0] #strip port
fn, args = self._match(self.mapping, host)
return self._delegate(fn, self.fvars, args)
+
+ def _match(self, mapping, value):
+ for pat, what in utils.group(mapping, 2):
+ if isinstance(what, basestring):
+ what, result = utils.re_subm('^' + pat + '$', what, value)
+ else:
+ result = utils.re_compile('^' + pat + '$').match(value)
+
+ if result: # it's a match
+ return what, [x and urllib.unquote(x) for x in result.groups()]
+ return None, None
+
class combine_applications(application):
"""Combines a list of applications into single application.
Oops, something went wrong.

0 comments on commit 417b9d2

Please sign in to comment.