| CARVIEW |
- Source
- Commits
- Network (48)
- Issues (10)
- Graphs
-
Branch:
master
click here to add a description
click here to add a homepage
-
The NotFound and InternalError handlers are special... which is confusing when you want to use some of the other error handlers (like Forbidden or Unauthorized) in the same way.
I propose making them all a little more uniform. Here's an untested patch to illustrate my intent:
https://pastebin.com/TgB6LH5qComments
-
Cf: https://groups.google.com/group/webpy/browse_thread/thread/ea49983d0d839fa6?pli=1
from web import form from web.utils import storify f = form.Form( form.Checkbox('contact_me', checked=True, description='spam_me') ) f.fill(kw=dict()) # no adding. assert '''checked="checked"''' in f.render() f = form.Form( form.Checkbox('contact_me', checked=False, description='spam_me') ) f.fill(kw=dict()) # no adding. assert '''checked="checked"''' not in f.render() f.fill(kw=dict(contact_me=True)) # add it. assert '''checked="checked"''' in f.render(), "didn't fill in"'fill' is just a shorthand to 'valididates()', which doesn't know how to
do much except set the 'value' attribute.I observe in my tests that indeed, submitted forms don't "stay"
checked. Validators just seem to look at the 'value' attribute, and
that is it. (cf. the _validate method).The hackish solution is to wire in that "checked means value is valid"
thing yourself. Ugly though!Comments
Please log in to comment. -
The reloader does not appear to reload external modules under lighttpd. The reloader works as expected under the dev server although you must ensure that the modules are imported as "import x" and not as "from y import x".
Comments
Please log in to comment. -
When using subapplications regexes, the top level url definitions behave differently then regexes in subapplications. This is an example based on code in https://webpy.org/cookbook/subapp.
blog.py:
import web urls = ( "", "reblog", "/(blog|Blog)", "blog" #change from original ) class reblog: def GET(self): raise web.seeother('/') class blog: def GET(self, path): return "blog " + path app_blog = web.application(urls, locals())code.py
import web import blog urls = ( "/(blog|Blog)", blog.app_blog, #change from original # "/blog", blog.app_blog, "/(.*)", "index" ) class index: def GET(self, path): return "hello " + path app = web.application(urls, locals()) if __name__ == "__main__": app.run()The regex /(blog|Blog) is the same in blog.py and code.py however request GET https://localhost:1111/blog/Blog does not return the expected result. If the regex is commented out in code.py and replaced with the line below it GET request returns an expected result.
Comments
Please log in to comment. -
2 comments Created 5 months ago by fhsmValidation of forms with value attribute set to an intwont fixIf the value attribute of a dropdown or radio button element is set to an integer and validation of the form containing that element fails the element's state is lost in the redisplayed form.
If the following form was submitted with the textbox left blank and the first radio button selected the form displayed after validation would show an empty textbox and no radio button selected.
simple_form = form.Form( form.Textbox('test', form.notnull, ), form.Radio('example', [1,2,3,4], ) )I think this happens because the form post is u/str and thus the value checks fail. Maybe this could be fixed by converting the values to strings for the test of equality in the render functions for these elements.
243c243 < if self.value == value: select_p = ' selected="selected"' --- > if self.value == str(value): select_p = ' selected="selected"' 266c266 < if self.value == arg: --- > if self.value == str(arg):Comments
anandology Thu Aug 26 00:13:45 -0700 2010 | linkI don't see a problem with this behavior. I think it is okay to assume that the Dropdown options must be strings.
If we implicitly convert value to string before comparison, we might get into more trouble. Explicit is better than implicit!
Please log in to comment.The problem is that ints are already being implicitly converted when the are rendered but the validation logic doesn't acknowledge this. The library allows forms to be defined with int values (ex: form.Radio in the OP) so it should be able to handle their validation, even though they have been converted by the HTML round trip.
Either the validation logic needs to be changed to account for the implicit conversion when the ints described in the form object are returned from HTML or the form object needs to restrict the ability to define ints as values in recognition of the inability to mantain type when rendered.
I don't have a strong opinion about which is better but it's clear that the current behavior is buggy. It should not be possible to define a form that can't keep track of its own state during during validation b/c of datatypes.
-
I used this example code to reproduce the error:
in the forms.py
result = data.all_categories() # this method return all records of table category in GAE/big table format.
args = [(row.key().id(), row.title) for row in result]
new_post = form.Form(form.Dropdown('category', args), form.Textbox('title'), form.Textarea('text'), form.Dropdown('language', [('pt', 'Portuguese'), ('en','English')]),
form.Button('Submit!')in code.py
class Post:
def GET(self): frm = forms.new_post() return render.full(render.form(frm)) def POST(self): global last_updated frm = forms.new_post() if frm.validates(): # in this point the error. data.save_entry(frm.d) last_updated = data.last_updated() raise web.seeother('/') else: return render.full(render.form(frm))IMHO the root cause of the problem is the 'big table' format, I say this because the form generated by the GET method is correct(It has the Category A, Category B) but when I submit the form and the forms.validates() is called the error occurs.
The problem is in the forms.py in this function:
def attrget(obj, attr, value=None):if hasattr(obj, 'has_key') and obj.has_key(attr): return obj[attr] if hasattr(obj, attr): return getattr(obj, attr) return valuegenerate this error:
: 'unicode' object has no attribute
'has_key'args = ("'unicode' object has no attribute 'has_key'",) message = "'unicode' object has no attribute 'has_key'"Comments
Please log in to comment.LeandroSeverino Tue May 25 05:50:09 -0700 2010 | linkI don't know if this is the best approach, but I have a solution to this problem in this thread:
https://groups.google.com/group/webpy/browse_thread/thread/484cb3fadac5de32/94634856c335d001#94634856c335d001 -
wsgi.errors: str object has no attribute write
7 comments Created 3 months ago by vectartToday I'm update my Debian server and got the error:
Traceback (most recent call last): File "/usr/lib/pymodules/python2.6/web/wsgiserver/__init__.py", line 1174, in communicate req.respond() File "/usr/lib/pymodules/python2.6/web/wsgiserver/__init__.py", line 544, in respond self._respond() File "/usr/lib/pymodules/python2.6/web/wsgiserver/__init__.py", line 556, in _respond response = self.wsgi_app(self.environ, self.start_response) File "/usr/lib/pymodules/python2.6/web/httpserver.py", line 237, in __call__ return self.app(environ, xstart_response) File "/usr/lib/pymodules/python2.6/web/httpserver.py", line 212, in __call__ return self.app(environ, start_response) File "/usr/lib/pymodules/python2.6/web/httpserver.py", line 237, in __call__ return self.app(environ, xstart_response) File "/usr/lib/pymodules/python2.6/web/application.py", line 293, in wsgi start_resp(status, headers) File "/usr/lib/pymodules/python2.6/web/httpserver.py", line 233, in xstart_response out = start_response(status, response_headers, *args) File "/usr/lib/pymodules/python2.6/web/httpserver.py", line 234, in xstart_response self.log(status, environ) File "/usr/lib/pymodules/python2.6/web/httpserver.py", line 251, in log print >> outfile, utils.safestr(msg) AttributeError: 'str' object has no attribute 'write'It's just when I run application.
When I'm use request emulation, it's okay.Comments
anandology Sun Aug 29 23:15:38 -0700 2010 | linkCan you provide a sample program to reproduce the error?
Reproduced
2010-09-27 13:14:08: (mod_fastcgi.c.2711) FastCGI-stderr: Traceback (most recent call last): File "/usr/lib/pymodules/python2.6/flup/server/fcgi_base.py", line 558, in run protocolStatus, appStatus = self.server.handler(self) File "/usr/lib/pymodules/python2.6/flup/server/fcgi_base.py", line 1118, in handler result = self.application(environ, start_response) File "/usr/lib/pymodules/python2.6/web/application.py", line 282, in wsgi result = self.handle_with_processors() File "/usr/lib/pymodules/python2.6/web/application.py", line 252, in handle_with_processors return process(self.processors) File "/usr/lib/pymodules/python2.6/web/application.py", line 248, in process print >> web.debug, traceback.format_exc() File "/usr/lib/pymodules/python2.6/web/webapi.py", line 339, in _debugwrite out.write(x) AttributeError: 'str' object has no attribute 'write'And when I'm run application as stand-alone server I have another log
Traceback (most recent call last): File "/usr/lib/pymodules/python2.6/web/wsgiserver/__init__.py", line 1174, in communicate req.respond() File "/usr/lib/pymodules/python2.6/web/wsgiserver/__init__.py", line 544, in respond self._respond() File "/usr/lib/pymodules/python2.6/web/wsgiserver/__init__.py", line 556, in _respond response = self.wsgi_app(self.environ, self.start_response) File "/usr/lib/pymodules/python2.6/web/httpserver.py", line 237, in __call__ return self.app(environ, xstart_response) File "/usr/lib/pymodules/python2.6/web/httpserver.py", line 212, in __call__ return self.app(environ, start_response) File "/usr/lib/pymodules/python2.6/web/application.py", line 282, in wsgi result = self.handle_with_processors() File "/usr/lib/pymodules/python2.6/web/application.py", line 252, in handle_with_processors return process(self.processors) File "/usr/lib/pymodules/python2.6/web/application.py", line 248, in process print >> web.debug, traceback.format_exc() File "/usr/lib/pymodules/python2.6/web/webapi.py", line 339, in _debugwrite out.write(x) AttributeError: 'str' object has no attribute 'write'So if you'll needed I can open my github-repo with the buggy code.
anandology Mon Sep 27 03:38:55 -0700 2010 | linkcan you please attach a sample program to reproduce that?
Please log in to comment.It's more than just simple program :-)
I was give access for you at
https://github.com/vectart/homepageFor run it, ubuntu packages needed to install:
python-redis redis-server python-utidylib python-zsiand https://code.google.com/p/py-dom-xpath/
File homepage.conf describe host configuration for Lighttpd
But also you can just runrun.pyThanks you for the interest to solve that bug!
-
Traceback (most recent call last): File "/Users/bonkabonka/pypy-1.3/site-packages/web/wsgiserver/__init__.py", line 1174, in communicate req.respond() File "/Users/bonkabonka/pypy-1.3/site-packages/web/wsgiserver/__init__.py", line 544, in respond self._respond() File "/Users/bonkabonka/pypy-1.3/site-packages/web/wsgiserver/__init__.py", line 556, in _respond response = self.wsgi_app(self.environ, self.start_response) File "/Users/bonkabonka/pypy-1.3/site-packages/web/httpserver.py", line 201, in __call__ return self.app(environ, xstart_response) File "/Users/bonkabonka/pypy-1.3/site-packages/web/application.py", line 273, in wsgi self.load(env) File "/Users/bonkabonka/pypy-1.3/site-packages/web/application.py", line 372, in load ctx[k] = safeunicode(v) AttributeError: ThreadedDict instance has no attribute '__setitem__'Comments
Please log in to comment. -
It is not currently possible to nest subapplications as such:
/issue -> issue.app /issue/([0-9,a-f]{8}) -> issue.app /issue/([0-9,a-f]{8})/tests -> tests.app /issue/([0-9,a-f]{8})/tests/([0-9,a-f]{8}) -> tests.app
While this doesn't fit into the model of Web.Py, since there is no mechanism to pass the first issue id to the sub-application, it could be retro-fitted by simply adding a variable to webapi.ctx.
Comments
Please log in to comment. -
Hi,
I am using web.py as an embedded webserver in my app. Because there is no way to set the port served programatically I have to do this
import sys; sys.argv[1] = '8080' #Yuck self.app = web.application(xxxx) thread.start_new_thread(self.app.run, ())Otherwise webpy assumes the first command line argument it its port (which it is not as my app has many other command line args)
Comments
anandology Wed Aug 25 21:42:21 -0700 2010 | linkHow about making it take from web.config if specified? Something like this:
web.config.default_port = 8090
app.run()I guess that would be sufficient, however I would prefer it be per application (config is global, right?).
Although not needed in my case, someone else might wish to run multiple servers on different ports.
Actually I just saw that config seems to hold other global state (smtp config for example), so there is precident.
web.config.default_port makes sense in that case.
anandology Thu Aug 26 00:20:47 -0700 2010 | linkwe might want to support specifying the interface too.
127.0.0.1to bind only on localhost.
Should we call itdefault_bind_address?web.ctx.default_bind_address = '127.0.0.1:9000'or just port:
web.ctx.default_bind_address = 9000Please log in to comment.How about just calling it interface?
web.ctx.default_interface = 127.0.0.1:9000And, in the port only case
web.ctx.default_interface = :9000(i.e. starts with ':')
- © 2010 GitHub Inc. All rights reserved.
- Terms of Service
- Privacy
- Security
Keyboard Shortcuts
Site wide shortcuts
- s
- Focus site search
- ?
- Bring up this help dialog
Commit list
- j
- Move selected down
- k
- Move selected up
- t
- Open tree
- p
- Open parent
- c or o or enter
- Open commit
Pull request list
- j
- Move selected down
- k
- Move selected up
- o or enter
- Open issue
Issues
- j
- Move selected down
- k
- Move selected up
- x
- Toggle select target
- o or enter
- Open issue
- I
- Mark selected as read
- U
- Mark selected as unread
- e
- Close selected
- y
- Remove selected from view
- c
- Create issue
- l
- Create label
- i
- Back to inbox
- u
- Back to issues
- /
- Focus issues search
Network Graph
- ← or h
- Scroll left
- → or l
- Scroll right
- ↑ or k
- Scroll up
- ↓ or j
- Scroll down
- t
- Toggle visibility of head labels
- shift ← or shift h
- Scroll all the way left
- shift → or shift l
- Scroll all the way right
- shift ↑ or shift k
- Scroll all the way up
- shift ↓ or shift j
- Scroll all the way down



This makes sense to me. Anand?
The diff was screwed so I applied this to my fork:
https://github.com/aaronsw/webpy/commit/348f1f436f63ff05c6a021bf114c5006bbf2b974
Having different behavior for notfound and NotFound is very confusing. I think what I've implemented is a bad hack. I think we should find a better solution to that.