Re: Using DB-API with Pyramid
On 2/10/11 6:40 PM, Christopher Weimann wrote: I'm using DB-API in my Pylons app as described in on this wiki page. http://wiki.pylonshq.com/display/pylonscookbook/Using+the+DB-API+in+Pylons The gist of which is to add the following to lib/app_globals.py from pylons import config import psycopg2 from DBUtils.PooledDB import PooledDB class Globals(object): def __init__(self): self.pool = PooledDB( psycopg2, 5, database=config['app_conf']['pool.database'], user=config['app_conf']['pool.user'], host=config['app_conf']['pool.host'] ) then in a controller you can get a connection with conn = g.pool.connection() How would I do the equivalent with Pyramid? This is untested, but i think you could do something like this in your startup code:: from pyramid.registry import global_registry global_registry.pool = PooledDB(...) Then in your view code, or anywhere you have a request object, you should be able to get at it via `request.registry.pool`. -r -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to pylons-discuss@googlegroups.com. To unsubscribe from this group, send email to pylons-discuss+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
Re: Pyramid status update / sprints.
I can confirm a problem with FF 3.6.13 on Ubuntu. Carlos de la Guardia On Thu, Feb 10, 2011 at 12:10 PM, Juliusz Gonera wrote: > Andrew Sawyers wrote: >> >> Looks good on mine as well: Firefox (OS X) > > This is how I see it on Firefox 3.6.13 (Ubuntu Karmic): > http://i.imgur.com/id0ox.png > > I don't have problems with any other web site. > Note: When I refresh (Ctrl+Shift+R) for a fraction of a second, until the > headings font is loaded everything is OK and then suddenly the headings jump > (when correct headings font appears). > > -- > Juliusz Gonera > http://juliuszgonera.com/ > > -- > You received this message because you are subscribed to the Google Groups > "pylons-discuss" group. > To post to this group, send email to pylons-discuss@googlegroups.com. > To unsubscribe from this group, send email to > pylons-discuss+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/pylons-discuss?hl=en. > > -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to pylons-discuss@googlegroups.com. To unsubscribe from this group, send email to pylons-discuss+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
Noob Question: REST App Server ...
Gentlefolk, I've searched your archive and I cannot find a discussion of how to build just a REST app server in Pylons. A little background: I am an iOS developer and I specialize in developing apps that interface via REST to both my client's and public app servers. When pressed, I will also write a simple REST app server. For good reasons, which I support, my client prefers to write their app server in Python. My experience is with Ruby. They, nonetheless, still want me to write the app server in Python. Hence, my asking the below questions. I want a server to implement the following sample routes: https://api.example.com/1/routeA/route1.json https://api.example.com/1/routeB/route2.json https://api.example.com/1/routeB/route3.json I will potentially use all 4 REST verbs: GET, PUT, POST and DELETE. Due to the mobile nature of my apps, most interactions will use the idempotent methods GET and PUT. I only wish to have JSON responses -- no HTML, no text. If I was doing this in Ruby, I would start with a nice little framework called Sinatra. It is, in essence, just a routes server. If I need to, I can bring in a Rails subsystem, such as ActiveRecord. I want to have small stack on my Python based REST app server. I have looked at both django-piston and django-tastypie. While I haven't ruled them out, they are tied to Django. Hence, if I used them, I would likely have a pretty heavyweight app server. >From my initial skim of your feature description, you support a routes system. Because the Pylons community touts the modularity of Pylons, I was hoping that I could run a system with just Python and the Pylons routing engine. If I need access to a database model, I suspect I can always bring in SQLAlchemy. Hence, should Pylons be my development home? Does it really support a modular style where I eject most of the framework from my runtime? Or is it "yet another monolithic MVC framework"? In addition to the Pylons book, is there another book I should be reading to grok the Pythonic (Pylonic?) path? Has someone else implemented a thin REST app server in Pylons? Thank you in advance for any insight you may care to share, Andrew -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to pylons-discuss@googlegroups.com. To unsubscribe from this group, send email to pylons-discuss+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
problem in pylons web application
i got error while running my pylons application.it show error in lib/helpers.py file . code of helper.py is as follow from formbuild.helpers import field from formbuild import start_with_layout as form_start, end_with_layout as form_end from webhelpers.html.tags import * from routes import url_for error is look like as follow: Traceback (most recent call last): File "/home/varsha_mca3/virtualenv-1.5.1/env/bin/paster", line 8, in load_entry_point('PasteScript==1.7.3', 'console_scripts', 'paster')() File "/home/varsha_mca3/virtualenv-1.5.1/env/lib/python2.6/site-packages/PasteScript-1.7.3-py2.6.egg/paste/script/command.py", line 84, in run invoke(command, command_name, options, args[1:]) File "/home/varsha_mca3/virtualenv-1.5.1/env/lib/python2.6/site-packages/PasteScript-1.7.3-py2.6.egg/paste/script/command.py", line 123, in invoke exit_code = runner.run(args) File "/home/varsha_mca3/virtualenv-1.5.1/env/lib/python2.6/site-packages/PasteScript-1.7.3-py2.6.egg/paste/script/command.py", line 218, in run result = self.command() File "/home/varsha_mca3/virtualenv-1.5.1/env/lib/python2.6/site-packages/PasteScript-1.7.3-py2.6.egg/paste/script/serve.py", line 276, in command relative_to=base, global_conf=vars) File "/home/varsha_mca3/virtualenv-1.5.1/env/lib/python2.6/site-packages/PasteScript-1.7.3-py2.6.egg/paste/script/serve.py", line 313, in loadapp **kw) File "/home/varsha_mca3/virtualenv-1.5.1/env/lib/python2.6/site-packages/PasteDeploy-1.3.4-py2.6.egg/paste/deploy/loadwsgi.py", line 203, in loadapp return loadobj(APP, uri, name=name, **kw) File "/home/varsha_mca3/virtualenv-1.5.1/env/lib/python2.6/site-packages/PasteDeploy-1.3.4-py2.6.egg/paste/deploy/loadwsgi.py", line 223, in loadobj global_conf=global_conf) File "/home/varsha_mca3/virtualenv-1.5.1/env/lib/python2.6/site-packages/PasteDeploy-1.3.4-py2.6.egg/paste/deploy/loadwsgi.py", line 247, in loadcontext global_conf=global_conf) File "/home/varsha_mca3/virtualenv-1.5.1/env/lib/python2.6/site-packages/PasteDeploy-1.3.4-py2.6.egg/paste/deploy/loadwsgi.py", line 270, in _loadconfig return loader.get_context(object_type, name, global_conf) File "/home/varsha_mca3/virtualenv-1.5.1/env/lib/python2.6/site-packages/PasteDeploy-1.3.4-py2.6.egg/paste/deploy/loadwsgi.py", line 401, in get_context section) File "/home/varsha_mca3/virtualenv-1.5.1/env/lib/python2.6/site-packages/PasteDeploy-1.3.4-py2.6.egg/paste/deploy/loadwsgi.py", line 423, in _context_from_use object_type, name=use, global_conf=global_conf) File "/home/varsha_mca3/virtualenv-1.5.1/env/lib/python2.6/site-packages/PasteDeploy-1.3.4-py2.6.egg/paste/deploy/loadwsgi.py", line 353, in get_context global_conf=global_conf) File "/home/varsha_mca3/virtualenv-1.5.1/env/lib/python2.6/site-packages/PasteDeploy-1.3.4-py2.6.egg/paste/deploy/loadwsgi.py", line 247, in loadcontext global_conf=global_conf) File "/home/varsha_mca3/virtualenv-1.5.1/env/lib/python2.6/site-packages/PasteDeploy-1.3.4-py2.6.egg/paste/deploy/loadwsgi.py", line 277, in _loadegg return loader.get_context(object_type, name, global_conf) File "/home/varsha_mca3/virtualenv-1.5.1/env/lib/python2.6/site-packages/PasteDeploy-1.3.4-py2.6.egg/paste/deploy/loadwsgi.py", line 553, in get_context object_type, name=name) File "/home/varsha_mca3/virtualenv-1.5.1/env/lib/python2.6/site-packages/PasteDeploy-1.3.4-py2.6.egg/paste/deploy/loadwsgi.py", line 579, in find_egg_entry_point possible.append((entry.load(), protocol, entry.name)) File "/home/varsha_mca3/virtualenv-1.5.1/env/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg/pkg_resources.py", line 1954, in load File "/home/varsha_mca3/virtualenv-1.5.1/env/pylonsforum/pylonsforum/config/middleware.py", line 12, in from pylonsforum.config.environment import load_environment File "/home/varsha_mca3/virtualenv-1.5.1/env/pylonsforum/pylonsforum/config/environment.py", line 10, in import pylonsforum.lib.helpers File "/home/varsha_mca3/virtualenv-1.5.1/env/pylonsforum/pylonsforum/lib/helpers.py", line 6, in from formbuild.helpers import field ImportError: No module named helpers -- View this message in context: http://pylons-discuss.1595796.n2.nabble.com/problem-in-pylons-web-application-tp6011175p6011175.html Sent from the pylons-discuss mailing list archive at Nabble.com. -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to pylons-discuss@googlegroups.com. To unsubscribe from this group, send email to pylons-discuss+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
Using DB-API with Pyramid
I'm using DB-API in my Pylons app as described in on this wiki page. http://wiki.pylonshq.com/display/pylonscookbook/Using+the+DB-API+in+Pylons The gist of which is to add the following to lib/app_globals.py from pylons import config import psycopg2 from DBUtils.PooledDB import PooledDB class Globals(object): def __init__(self): self.pool = PooledDB( psycopg2, 5, database=config['app_conf']['pool.database'], user=config['app_conf']['pool.user'], host=config['app_conf']['pool.host'] ) then in a controller you can get a connection with conn = g.pool.connection() How would I do the equivalent with Pyramid? -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to pylons-discuss@googlegroups.com. To unsubscribe from this group, send email to pylons-discuss+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
Re: Unclear behaviour of formencode.Schema with UnicodeString items
After thinking about this more it would probably be better if UnicodeString just had a parameter that turned coercion of everything but instances of basestring and None off. Or maybe another validator was created that did that. It makes more sense for the validator that is assigned that key to respond to both lists and non-lists. What outcome do you actually want? Only the first or last thing from the list to get validated? Or an error if there is more than one thing ? Here is a validator I hacked together from the String and UnicodeString validators that only accepts None and basestrings. None and non-unicode strings are both converted to unicode. class StrictUnicodeString(FancyValidator): "" min = None max = None not_empty = None convert_none = True encoding = 'utf-8' messages = { 'notString': "Please enter a string", 'tooLong': "Enter a value less than %(max)i characters long", 'tooShort': "Enter a value %(min)i characters long or more", 'badEncoding' : "Invalid data or incorrect encoding", } def __initargs__(self, new_attrs): if self.not_empty is None and self.min: self.not_empty = True def __init__(self, input_encoding=None, output_encoding=None, convert_none=True, **kw): FancyValidator.__init__(self, **kw) self.input_encoding = input_encoding or self.encoding self.output_encoding = output_encoding or self.encoding self.convert_none = convert_none def _to_python(self, value, state): """ Converts to unicode. """ if self.convert_none and value is None: value = u'' if not isinstance(value, basestring): raise Invalid(self.message('notString', state), value, state) if not isinstance(value, unicode): try: value = unicode(value, self.input_encoding) except UnicodeDecodeError: raise Invalid(self.message('badEncoding', state), value, state) return value def _from_python(self, value, state): """ Converts to a bytestring. """ if not isinstance(value, unicode): if hasattr(value, '__unicode__'): value = unicode(value) else: value = str(value) if isinstance(value, unicode): value = value.encode(self.output_encoding) return value def validate_other(self, value, state): if (self.max is not None and value is not None and len(value) > self.max): raise Invalid(self.message('tooLong', state, max=self.max), value, state) if (self.min is not None and (not value or len(value) < self.min)): raise Invalid(self.message('tooShort', state, min=self.min), value, state) def empty_value(self, value): return u'' -Ian On Thu, Feb 10, 2011 at 2:52 PM, Maxim Avanov wrote: > Hi, Ian. Thanks for reply. > > >If you want to be EXTRA strict then you could try ConfirmType and > UnicodeString combined in an All validator to catch this error. Or something > to that effect. > > This solution will work, but I wouldn't like to use it for several > reasons. First of all, we already have a huge code base that > intensively uses UnicodeStrings. Surely, we could define our own > UnicodeString validator like below, > > UnicodeString = > formencode.All(formencode.ConfirmType(subclass=unicode), > formencode.UnicodeString()) > > but we trying to keep our design clean. Moreover, "All" and > "ConfirmType" require extra validation steps (and hence more function > calls). I think it has to be solved in more generic and concise way > (i.e. in formencode's internal api level). > > > Also note that someone could actually send ?username=[u'John', u'Mike'] > in > > the query which would exhibit similar behavior. > > Yes, and it is the place where the inconsistency of validators > behaviour comes. if we'd have an unified behaviour for all single- > value validators (Int, UnicodeString, Bool etc.) we could get > "[u'John', u'Mike']" result only for "/?username=[u'John', u'Mike']" > request. But now, we can get the same result by the two different > requests - by "/?username=[u'John', u'Mike']" and by "/? > username=John&username=Mike". This shouldn't be allowed. And it's not > allowed for all single-value validators except the UnicodeString. > > > If we don't use mixed then how do we get the multiple values when we want > > them? > > We might explicitly specify our expectations with ForEach() and Set() > validators. > formencode's FancyValidator could internally test currently running > validator by calling something like > > isinstance(current_validator, ForEach) > > and then perform appropriate actions for this case (i.e. call single- > value validator for each found item wit
Re: Unclear behaviour of formencode.Schema with UnicodeString items
Hi, Ian. Thanks for reply. >If you want to be EXTRA strict then you could try ConfirmType and >UnicodeString combined in an All validator to catch this error. Or something >to that effect. This solution will work, but I wouldn't like to use it for several reasons. First of all, we already have a huge code base that intensively uses UnicodeStrings. Surely, we could define our own UnicodeString validator like below, UnicodeString = formencode.All(formencode.ConfirmType(subclass=unicode), formencode.UnicodeString()) but we trying to keep our design clean. Moreover, "All" and "ConfirmType" require extra validation steps (and hence more function calls). I think it has to be solved in more generic and concise way (i.e. in formencode's internal api level). > Also note that someone could actually send ?username=[u'John', u'Mike'] in > the query which would exhibit similar behavior. Yes, and it is the place where the inconsistency of validators behaviour comes. if we'd have an unified behaviour for all single- value validators (Int, UnicodeString, Bool etc.) we could get "[u'John', u'Mike']" result only for "/?username=[u'John', u'Mike']" request. But now, we can get the same result by the two different requests - by "/?username=[u'John', u'Mike']" and by "/? username=John&username=Mike". This shouldn't be allowed. And it's not allowed for all single-value validators except the UnicodeString. > If we don't use mixed then how do we get the multiple values when we want > them? We might explicitly specify our expectations with ForEach() and Set() validators. formencode's FancyValidator could internally test currently running validator by calling something like isinstance(current_validator, ForEach) and then perform appropriate actions for this case (i.e. call single- value validator for each found item with the same key). P.S. I hope Ian Bicking will see this topic and give his opinion all about this, as I might miss something important here. On Feb 9, 6:38 am, Ian Wilson wrote: > Hi, > > I think this behavior happens because mixed is used > herehttps://bitbucket.org/ianb/formencode/src/d95237b33f3c/formencode/api > If you don't want that to happen ever then I think you need to cast params > to a regular dictionary, with something like dict(request.params.items()). > This will silently ignore one of the names though which might be worse. > > If you want to be EXTRA strict then you could try ConfirmType and > UnicodeString combined in an All validator to catch this error. Or > something to that effect. > > Also note that someone could actually send ?username=[u'John', u'Mike'] in > the query which would exhibit similar behavior. So as far as I can tell if > that is a problem you'd need to validate it either way. > > I agree that this might be misleading but its a difficult problem to solve. > If we don't use mixed then how do we get the multiple values when we want > them? I think formencode might just need better internal integration with > multiple value dictionaries so that different types don't show up depending > on the input. It tries to be input agnostic though. > > -Ian > > On Tue, Feb 8, 2011 at 10:25 AM, Maxim Avanov wrote: > > > > > > > Here's an example. > > > # = > > from formencode import Schema, Invalid > > from formencode.validators import UnicodeString, Int > > from webob import Request > > > class StrictSchema(Schema): > > allow_extra_fields = False > > > class IntegerTestSchema(StrictSchema): > > testfield = Int(not_empty=True) > > > class StringTestSchema(StrictSchema): > > testfield = UnicodeString(not_empty=True) > > > # Testing. > > # = > > req = Request.blank('/?testfield=111') > > print IntegerTestSchema.to_python(req.params) > > > # This raises an exception > > req = Request.blank('/?testfield=111&testfield=222') > > try: > > IntegerTestSchema.to_python(req.params) > > except Invalid as e: > > print "Caught Exception: {0}".format(e) > > > req = Request.blank('/?testfield=aaa') > > print StringTestSchema.to_python(req.params) > > > # This will be passed successfully (!) > > # The output will be {'testfield': u"[u'aaa', u'bbb']"} > > req = Request.blank('/?testfield=aaa&testfield=bbb') > > print StringTestSchema.to_python(req.params) > > > # > > > Please note we do not use formencode.ForEach() or formencode.Set() > > here. I think this is very unclear behaviour. > > Imagine an UsernameValidator (or something related to "not-so-strict- > > string-validator"). Instead of indicating an input error, we show the > > service realization details to our users -- "{'username': u"[u'John', > > u'Mike']"}" - "Ok. This is Python list inside the dict". > > > According to WebOb documentation (http://pythonpaste.org/webob/ > > #multidict), we probably should use request.GET.getone() instead of > > request.GET.getall(). > > > -- > > You received this message because you are subscribed to the Google Groups
Re: Uncertain about traversal and mongodb
Hi, You can also have a look at this excellent document: http://www.muthukadan.net/docs/zca.html On Thu, Feb 10, 2011 at 8:51 PM, Bobby wrote: > The answer is to use the adapter pattern. > > An explanation in Zope > http://wiki.zope.org/zope3/ZopeGuideComponents > > A great explanation of the adapter pattern is here: > http://ginstrom.com/scribbles/2009/03/27/the-adapter-pattern-in-python/ > > An example using sqlalchemy; > http://lists.repoze.org/pipermail/repoze-dev/2009-November/002292.html > > -- > You received this message because you are subscribed to the Google Groups > "pylons-discuss" group. > To post to this group, send email to pylons-discuss@googlegroups.com. > To unsubscribe from this group, send email to > pylons-discuss+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/pylons-discuss?hl=en. > > -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to pylons-discuss@googlegroups.com. To unsubscribe from this group, send email to pylons-discuss+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
Re: Uncertain about traversal and mongodb
The answer is to use the adapter pattern. An explanation in Zope http://wiki.zope.org/zope3/ZopeGuideComponents A great explanation of the adapter pattern is here: http://ginstrom.com/scribbles/2009/03/27/the-adapter-pattern-in-python/ An example using sqlalchemy; http://lists.repoze.org/pipermail/repoze-dev/2009-November/002292.html -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to pylons-discuss@googlegroups.com. To unsubscribe from this group, send email to pylons-discuss+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
Re: Pyramid status update / sprints.
Thanks for pointing it out... On Feb 10, 1:10 pm, Juliusz Gonera wrote: > Andrew Sawyers wrote: > > Looks good on mine as well: Firefox (OS X) > > This is how I see it on Firefox 3.6.13 (Ubuntu > Karmic):http://i.imgur.com/id0ox.png > > I don't have problems with any other web site. > Note: When I refresh (Ctrl+Shift+R) for a fraction of a second, until > the headings font is loaded everything is OK and then suddenly the > headings jump (when correct headings font appears). > > -- > Juliusz Gonerahttp://juliuszgonera.com/ -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to pylons-discuss@googlegroups.com. To unsubscribe from this group, send email to pylons-discuss+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
Re: Pyramid status update / sprints.
Andrew Sawyers wrote: Looks good on mine as well: Firefox (OS X) This is how I see it on Firefox 3.6.13 (Ubuntu Karmic): http://i.imgur.com/id0ox.png I don't have problems with any other web site. Note: When I refresh (Ctrl+Shift+R) for a fraction of a second, until the headings font is loaded everything is OK and then suddenly the headings jump (when correct headings font appears). -- Juliusz Gonera http://juliuszgonera.com/ -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to pylons-discuss@googlegroups.com. To unsubscribe from this group, send email to pylons-discuss+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
Re: Pyramid status update / sprints.
Looks good on mine as well: Firefox (OS X) Cheers, Andrew On 2/10/11 9:38 AM, "David Eisner" wrote: > On Thu, Feb 10, 2011 at 12:22 PM, Juliusz Gonera wrote: >> >> Is something wrong with my browser or the design is totally messed up on >> http://pylonsproject.org/ ? > > Looks OK on my browser (Chrome): > > http://i.imgur.com/Xf3dc.png > > -David -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to pylons-discuss@googlegroups.com. To unsubscribe from this group, send email to pylons-discuss+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
Re: Pyramid status update / sprints.
On Thu, Feb 10, 2011 at 12:22 PM, Juliusz Gonera wrote: > > Is something wrong with my browser or the design is totally messed up on > http://pylonsproject.org/ ? Looks OK on my browser (Chrome): http://i.imgur.com/Xf3dc.png -David -- David Eisner http://cradle.brokenglass.com -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to pylons-discuss@googlegroups.com. To unsubscribe from this group, send email to pylons-discuss+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
Re: Pyramid status update / sprints.
Blaise Laflamme wrote: David, Pylons Project has it's own website for about a week now at pylonsproject.org. Both Pyramid and Pylons (the framework) have their own sections under /projects. It could make sense to have their own subdomain but unlike Apache we currently don't have as much «official projects» as them. We definitely need to drive traffic to pylonsproject.org for the main entry than on docs.pylonsproject.org. Is something wrong with my browser or the design is totally messed up on http://pylonsproject.org/ ? -- Juliusz Gonera http://juliuszgonera.com/ -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to pylons-discuss@googlegroups.com. To unsubscribe from this group, send email to pylons-discuss+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.