Re: Multiple questions about i18n / pluralization in Pyramid
Hello again, this is a follow-up to my own post. I'm slowly working my way towards the light ;-) 1/ After looking at the docs and the source code, I'm more and more convinced that Babel can't handle pluralization. Do you have any hint on the issue? All my apologies to Babel developers. Babel DOES handle pluralization perfectly indeed. The steps of the solution would be: def aview(request): _ = request.translate _p = request.localizer.pluralize print _(uHello, world) print _p(uHello, ${n} world, uHello, ${n} worlds, 5, domain=foo, mapping={'n': 5}) Then, extract messages using: python setup.py extract_messages -k _p The -k _p option instructs Babel to also extract messages from _p() calls, in addition to _() calls. Now, what remains to be done is let Babel know how to handle the parameters of _p(). So, I'm now turning my attention to babel/messages/extract.py and: lingua/extractors/python.py 4/ A solution might be to use a separate PO file for additional translations. This is the way I am exploring now. I've created an extra.po file and compiled it to extra.mo, but it's not taken into account. Yet. That solution probably wouldn't work, because I understand the po.files must be named after the translation domain (let's say, foo). So, the right way would do to create a second locale directory beside the first one, e.g. locale_extra, initialize it properly, and declare it in Pyramid'a configurator using: config.add_translation_dirs('foo:locale/', 'foo:locale_extra/') 5/ I've also to find out how to use multiple domains in my app (among other problems, how to localize deform widgets - the tutorial didn't work for me...) I must have bee very tired when I wrote this. Two days later, colander and deform translations suddenly started working :D Laurent. -- You received this message because you are subscribed to the Google Groups pylons-discuss group. To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discuss+unsubscr...@googlegroups.com. To post to this group, send email to pylons-discuss@googlegroups.com. Visit this group at http://groups.google.com/group/pylons-discuss?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: Trouble storing Suds SOAP client in Configurator registry
Thanks! I will take a look at that. On Tue, May 28, 2013 at 4:50 PM, Michael Merickel mmeri...@gmail.com wrote: FWIW, if you need a threadsafe connection pool and are already using SQLAlchemy for something else, the QueuePool is not db-api specific at all and can be reused for arbitrary connection pooling. On Tue, May 28, 2013 at 2:47 PM, ian marcinkowski ianmarcinkow...@gmail.com wrote: I know how difficult things are without the traceback; I was mostly looking for a suggestion exactly like yours in the hopes that it would push me in the right direction. I actually didn't even get a traceback, as my application crashed hard enough that it did not output an error. According to a few locations online, the Suds Client object is not threadsafe, so that could have something to do with it. I am reimplementing this with a threadsafe connection pool instead. On Mon, May 27, 2013 at 12:37 PM, Michael Merickel mmeri...@gmail.com wrote: It's *really* difficult for the internet to help debug your problems without a full traceback. You're basically asking if anyone has seen this exact problem before because they have no other context to help them out. Anyway, Pyramid does not copy anything that is in the settings or the registry. Are you sure your client is threadsafe? If you're touching a non-threadsafe object from multiple request threads then anything could happen. On Mon, May 27, 2013 at 8:47 AM, ian marcinkowski ianmarcinkow...@gmail.com wrote: Attaching my Suds Client to the registry did not help, but I will keep that pattern in mind. Thanks! On Thu, May 23, 2013 at 3:35 PM, Michael Merickel mmeri...@gmail.com wrote: The settings dictionary is copied once when you pass it into the configurator, and it is supposed to be a shallow copy. new_settings = {} new_settings.update(settings) That doesn't explain your issue though. A likely fix is just to follow the pattern I use, which is to leave the settings dictionary for primitive types. Services and utilities are things I attach to the registry itself (it's a dict too). On Thu, May 23, 2013 at 2:19 PM, ian marcinkowski ianmarcinkow...@gmail.com wrote: Are objects modified when they are saved in the Configurator registry.settings dictionary? I am trying to store a Suds SOAP Client in the registry which can be cloned in my view-callables so I can avoid re-parsing that WSDL document. When I am trying to clone the Suds Client that has been stored in the registry, my app is crashing horribly due to a maximum recursion limit reached exception. Some code: In my app __init__.py: def main(global_config, **app_settings): settings = {} ... settings['soap_client'] = suds.client.Client('file:///service.wsdl', username='foo', password='bar') config = Configurator(settings=settings, ...) return config.make_wsgi_app() view-callable.py def view(request): cloned_soap_client = request.registry.settings['soap_client'].clone() -- Induces Max. Recursion exception return cloned_soap_client.service.SomeMethod() If I drop in to a PDB terminal inside of my application's main() function and try cloneing settings['soap_client'] I do not encounter this recursion limit. Sure, this is probably an bug with the Suds client, but I'm not sure how toreproduce it outside of my application. Thoughts? -- Ian Marcinkowski ianmarcinkow...@gmail.com -- You received this message because you are subscribed to the Google Groups pylons-discuss group. To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discuss+unsubscr...@googlegroups.com. To post to this group, send email to pylons-discuss@googlegroups.com. Visit this group at http://groups.google.com/group/pylons-discuss?hl=en. For more options, visit https://groups.google.com/groups/opt_out. -- You received this message because you are subscribed to the Google Groups pylons-discuss group. To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discuss+unsubscr...@googlegroups.com. To post to this group, send email to pylons-discuss@googlegroups.com. Visit this group at http://groups.google.com/group/pylons-discuss?hl=en. For more options, visit https://groups.google.com/groups/opt_out. -- Ian Marcinkowski ianmarcinkow...@gmail.com -- You received this message because you are subscribed to the Google Groups pylons-discuss group. To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discuss+unsubscr...@googlegroups.com. To post to this group, send email to pylons-discuss@googlegroups.com. Visit this group at http://groups.google.com/group/pylons-discuss?hl=en. For more options, visit https://groups.google.com/groups/opt_out. -- You
Re: Multiple questions about i18n / pluralization in Pyramid [SOLVED]
Hello again, one final word, in case someone is interested (apart from me, I mean ;-)) Then, extract messages using: python setup.py extract_messages -k _p More precisely: python setup.py extract_messages -k _p:1,2 The argument _p:1,2 will tell Babel that arguments 1 and 2 of function _p are translation strings. Now, what remains to be done is let Babel know how to handle the parameters of _p(). So, I'm now turning my attention to babel/messages/extract.py and: lingua/extractors/python.py The python extractor in Lingua is hard-coded to consider arg1 as a translation string, and arg2 as a default value (this is derived from the signature of the TranslationString constructor). I was able to work around the problem by subclassing the PythonExtractor class, so that I'm using arg2 for plurals instead of default: - import tokenize from lingua.extractors.python import PythonExtractor as BasePythonExtractor class PythonExtractor(BasePythonExtractor): def stateWaiting(self, ttype, tstring, lineno): if ttype == tokenize.NAME and tstring in self.keywords: self.state = self.stateKeywordSeen self.msg = dict(lineno=lineno, func=tstring) def addMessage(self, msg): if not msg.get('label'): return default = msg.get('default') if default: messages = (u''.join(msg['label']), u''.join(default)) else: messages = u''.join(msg['label']) self.messages.append( (msg['lineno'], msg['func'], messages, [])) extract_python = PythonExtractor() - As regards Mako, the default extractor handles pluralization out of the box. As far as I'm concerned, all my localization problems are solved :-) Laurent. -- You received this message because you are subscribed to the Google Groups pylons-discuss group. To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discuss+unsubscr...@googlegroups.com. To post to this group, send email to pylons-discuss@googlegroups.com. Visit this group at http://groups.google.com/group/pylons-discuss?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
unit/functional test issue with SQLAlchemy
Hi, First of all, thanks for all the hard work and quality that goes into Pyramid to Chris and his team! At my job, we're using Pyramid to do a massive migration from both legacy ASP code and also Pylons code. I'm doing some unit and functional tests on my views and I have a couple of questions. First, for all of its benefits, I've sometimes found the Zope Transaction Manager to be a big pain at times, but a lot of code has been assuming it's use, so for better or worse, we're stuck with it. The first issue relates to using WebTest for full-framework functional testing: how does one get session objects attached to the request object when WebTest (TestApp) uses WebOb's request object and not Pyramid's request object and all of its goodies? Will I have to subclass WebTest objects and add Pyramid features? Is there an easier way? For now, I went with attaching a session dict to a DummyRequest() testing object and just calling view code ala a simple unit test...but...for certain views that brings me to problem number two: SQLAlchemy appears to complain about a scoped session already existing, and throws a strange error on the tearDown() of a bit of data that happens within the view. It seems to be trying to UPDATE (during the tearDown()) the table that gets INSERTED to within the view code being called by the unit test. The unit test of course sets upand tears down its own tables and data. I have no problem with such things when views under unit test are doing simple queries, but once they start to INSERT and such, SQLAlchemy refuses to behave. I've tried countless options, and spent literally hours working around SQLAlchemy and the Zope TM, but in this particular case, I'm stuck and could use some other people's insight. Here's some code to show what's going on, followed by errors reported: from tests/__init__.py: def _initTestingDB(): from sqlalchemy import create_engine from pyramid_helios.models.meta import ( DBSession, Base ) engine = create_engine('sqlite://') Base.metadata.create_all(engine) DBSession.configure(bind=engine) return engine, DBSession class UnitTest(unittest.TestCase): ''' Base class for tests ''' def setUp(self): template_dir = os.path.join(os.path.dirname( os.path.dirname(os.path.abspath(__file__))), 'templates') self.config = testing.setUp(settings={'production' : 'false', 'test_mode' : 'true', 'letters.pdf.formsdir' :'$(here)s/forms', 'notepad_provider' : 'null', 'mako.directories' : template_dir, 'email_to_test' : 'm...@mycompany.com', 'email_to' : 'webt...@mycompany.com', 'email.paperless.name' : 'alert thing' 'email.paperless.address' : 'testale...@mycompany.com' }) self.config.include('pyramid_helios.lib.email.testing') self.engine, self.session = _initTestingDB() from pyramid_helios import models self.env = models self.dbfixture = SQLAlchemyFixture( env=models, engine=self.engine, style=NamedDataStyle() ) def tearDown(self): ''' Clears away any existing objects between tests. ''' self.session.remove() testing.tearDown() here's the view I'm testing: @view_config(route_name='payment_cc_setup') def payment_cc_setup(request): ''' This is the popup response to registering a card. The contents will be displayed within a 'fancybox' JavaScript popup''' needed variables from the request and session: session = request.session refn = session['refn'] log.debug('refn from session is %s' % refn) if request.params['Result'] == 'ERROR': message = request.params['MESSAGE'] return Response('''We detect the presence of an error. The message sent was: brbr %s''' % message) else: rrno = request.params['RRNO'] description = request.params['CARD_TYPE'] + ' ending in ' + request.params['PAYMENT_ACCOUNT'] cc_exp_date = request.params['CARD_EXPIRE'] transaction.get() ses = DBSession() ses.begin(subtransactions=True) ses.add(SavedAccts(refnum='2234123412', rrno=rrno, description=description, cc_exp_date=cc_exp_date, full_name='', transactiontime=datetime.datetime.now())) ses.flush() return Response('''You have successfully
issue(s) with unit and functional tests and Zope TM/SQLAlchemy
Hi all, First, thanks to Chris M. and the whole Pyramid team for a wonderful piece of software! Now, to my questions: I'm hitting a real wall, after having spend hours and hours trying to figure out various permutation of setup for this. I'd like to know a couple of things: how to best simulate session objects using webTest (TestApp) since the request object in WebTest is webob's, not pyramidsright now, I'm manually simulating a session by just unit testing (not functional framework testing) by attaching a session-like dict to DummyRequest() and calling m view code that way. Which is fine, BUT, I also get issues with SQLAlchemy indirectly this way, which leads me to: What's up with this IntegrityError? It happens on tearDown, and it seems to be something automatic that I can't control, and I must be doing something wrong. I've literally chased my tail for hours chasing this down, and could use some fresh insight. Any help would be greatly appreciated! Here's my test setup and unit test: def _initTestingDB(): from sqlalchemy import create_engine from pyramid_helios.models.meta import ( DBSession, Base ) engine = create_engine('sqlite://') Base.metadata.create_all(engine) DBSession.configure(bind=engine) return engine, DBSession class UnitTest(unittest.TestCase): ''' Base class for tests ''' def setUp(self): template_dir = os.path.join(os.path.dirname( os.path.dirname(os.path.abspath(__file__))), 'templates') self.config = testing.setUp(settings={'production' : 'false', 'test_mode' : 'true', 'letters.pdf.formsdir' :'$(here)s/forms', 'notepad_provider' : 'null', 'mako.directories' : template_dir, 'email_to_test' : 'm...@mycompany.com', 'email_to' : 'm...@mycompany.com', 'email.paperless.name' : 'alert', 'email.paperless.address' : 'testale...@mycompany.com' }) self.config.include('pyramid_helios.lib.email.testing') self.engine, self.session = _initTestingDB() from pyramid_helios import models self.env = models self.dbfixture = SQLAlchemyFixture( env=models, engine=self.engine, style=NamedDataStyle() ) def tearDown(self): ''' Clears away any existing objects between tests. ''' self.session.remove() testing.tearDown() def test_setup(self): req = DummyRequest() req.session = {'refn' : '2234123412'} req.method = 'POST' req.params = {#some_params blah blah} resp = setup(req) self.assertIn('success', resp.body) #self.session.begin(subtransactions=True) #q = self.session.query(MyModel).filter(MyModel.refnum=='2234123412').all() q = ''' SELECT * from model WHERE refnum=='2234123412' ''' rows = self.session.connection().execute(q).fetchall() print 'rows.description is %s' % rows[0].description assert rows[0].description == 'some description' ### Here's the view being tested: @view_config(route_name='my_route_name') def setup(request): needed variables from the request and session: session = request.session refn = session['refn'] log.debug('refn from session is %s' % refn) if request.params['Result'] == 'ERROR': message = request.params['MESSAGE'] return Response('''Error. The message sent was: brbr %s''' % message) else: #param stuff # .some other stuff transaction.get() ses = DBSession() ses.begin(subtransactions=True) ses.add(MyModel(refnum='2234123412', description=description, full_name='', transactiontime=datetime.datetime.now())) ses.flush() return Response('''success.') # Here's the error report from 'nosetests': E/home/ajohnson/venv/migration/pyramid_helios/pyramid_helios/tests/__init__.py:46: SAWarning: At least one scoped session is already present. configure() can not affect sessions that have already been created. DBSession.configure(bind=engine) . == ERROR: test_setup(.) -- Traceback (most recent call last): File
Re: pyramid_persona and unexpected logout behavior
Georges, Thank you for the new version, but I believe the issue that I encountered is different. I believe the customized login view sample code is incomplete (at least for persona novices). Isn't the user already logged in via persona by the time the login function determines that the email is not in the whitelist? If so, shouldn't the client be redirected to a url that will automatically call navigator.id.logout? Perhaps a comment similar to the following will suffice: def login(request): email = verify_login('email') if email not in whitelist: request.session.flash('Sorry, you are not on the list') return {'redirect': '/'} # note: redirected url must call navigator.id.logout Here's another change that you may want to make to __init__.py: Instead of: authn_policy = AuthTktAuthenticationPolicy(secret, hashalg='sha512') Allow users to set a groupfinder callback: groupfinder = settings.get('persona.groupfinder', None) authn_policy = AuthTktAuthenticationPolicy(secret, hashalg='sha512', callback=groupfinder) Thank you again for your work on the pyramid_persona library. It is much appreciated. Peter On Thursday, May 23, 2013 10:41:38 AM UTC-4, Georges Dubus wrote: Hello I just uploaded a new version that should solve your problem. It change the way to redefine the login view, so please update yours according to https://pyramid_persona.readthedocs.org/en/latest/customization.html#do-extra-work-or-verification-at-login. Can you tell me if it solved your problem ? Georges Le mardi 14 mai 2013 20:58:21 UTC+2, Peter Santoro a écrit : I'm fairly new to pyramid and mozilla persona and I would greatly appreciate some assistance with a problem I'm having. Following the pyramid_persona documentation, I did manage to get persona working (or so I thought). I then tried customizing my login process as discussed on https://pyramid_persona.readthedocs.org/en/latest/customization.html. In the customized login example given, the login function redirects to '/' if the verified email is not on the whitelist. I'm redirecting to a loggedout view that calls navigator.id.logout() inside $(document).ready. According to https://developer.mozilla.org/en-US/docs/Mozilla/Persona/The_implementor_s_guide/Call_logout%28%29_after_a_failed_login?redirectlocale=en-USredirectslug=Persona%2FThe_implementor_s_guide%2FCall_logout%28%29_after_a_failed_login, you must call navigator.id.logout() on a failed login to avoid an endless loop of failed login attempts. The documentation on https://developer.mozilla.org/en-US/docs/DOM/navigator.id.logout further states: This function does not make the browser clear the user's certificate and signing key. So after calling logout(), a new login attempt may or may not ask the user for a new password, depending on the freshness of the certificate their identity provider gave them.*However, it will certainly prompt the user to select an email address and confirm that they want to sign in.* I'm not seeing the behavior where the user is prompted to select an email address and confirm they want to sign in. After logging out via the pyramid_persona logout button or as a result of using an email address not on my whitelist (both paths do call navigator.id.logout), if I attempt to go to one of the application's urls which require permissions, I'm redirected to the forbidden view (with the mozilla persona login button). This redirection is expected behavior, but it then immediately executes the login sequence without hitting the mozilla persona login button. To prevent the auto-relogin behavior, I also have to go to https://login.persona.org and click the Sign Out button after logging out of the application. I get this auto-relogin behavior whether I use my customized login view or the one provided by pyramid_persona. I'm sure I'm doing something wrong and I would appreciate some pointers on how to correct this issue. I just found these, so maybe it's not me? https://github.com/mozilla/browserid/issues/3386 https://github.com/mozilla/browserid/pull/3398 Thank you in advance for your assistance, Peter -- You received this message because you are subscribed to the Google Groups pylons-discuss group. To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discuss+unsubscr...@googlegroups.com. To post to this group, send email to pylons-discuss@googlegroups.com. Visit this group at http://groups.google.com/group/pylons-discuss?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: unicode error?
Thank you, Jonathan - this line in my development.ini makes the mako templates use the utf8 decoder: mako.default_filters = decode.utf8 ... and for the pyodbc+mssql utf8 issue, the trick seemed to be to use Python 3.2 instead of 2.7 (I didn't try others), then this got the data decoded from the db correctly: engine = engine_from_config(settings, 'sqlalchemy.', connect_args = {'mssql.charset': 'UTF-8'}) -- You received this message because you are subscribed to the Google Groups pylons-discuss group. To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discuss+unsubscr...@googlegroups.com. To post to this group, send email to pylons-discuss@googlegroups.com. Visit this group at http://groups.google.com/group/pylons-discuss?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: pyramid_persona and unexpected logout behavior
i'm not sure if this applies or not, but Safari doesn't accept cookies on a redirect. Most (possibly all) of the other browsers do. So if you're setting a cookie and then redirecting, Safari ignores it. -- You received this message because you are subscribed to the Google Groups pylons-discuss group. To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discuss+unsubscr...@googlegroups.com. To post to this group, send email to pylons-discuss@googlegroups.com. Visit this group at http://groups.google.com/group/pylons-discuss?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
scribe logging (thrift) under pryramid ?
has anyone here done logging with scribe under pyramid? if so, a few quick questions: 1. which library did you use ? or did you just install the default lib ? 2. do you know if it's safe to use a global thrift Transport , thrift Protocol or Scribe Client - or if they should be per-request ? -- You received this message because you are subscribed to the Google Groups pylons-discuss group. To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discuss+unsubscr...@googlegroups.com. To post to this group, send email to pylons-discuss@googlegroups.com. Visit this group at http://groups.google.com/group/pylons-discuss?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: Collect presentation material
I think that's a useful idea. Suggest using: github.com/Pylons/pyramid_presentations ...which would be consistent with: github.com/Pylons/pyramid_* // lots of repos with this pattern ...and would clearly indicate the presentations are for pyramid. I noticed that GitHub has a service called Speaker Deck, and there are a lot of Pyramid-related presentations there. https://speakerdeck.com/search?q=pyramid --steve On 5/29/13 at 11:59 AM, rachid.bel...@gmail.com (Rach Belaid) pronounced: Hello We started 2 months ago the first Pyramid meetup in London. It makes me realize that It can be a bit tricky to find a talk ideas, or being able to adjust it to the right audience level (newcomers, or already pyramid users) That made me think that it could be helpful to centralize some talks material via a github repo on which people could add their slideshow via pull request... eg: github.com/Pylons/presentation .. Like that anybody who want to start a new meetup in its town, could pick talks ideas from it and even a pre-made presentation if it don't feel like building one from scratch. eg: I have done a Keynote template which follow the Pyramid/Pylons colors scheme and I'm now doing a new template for reveal.js that I will be happy to contribute. It's just an idea and suggestion at this stage but I will be keen to submit any material that I will do. Let me know what you think? Steve Piercy, Soquel, CA -- You received this message because you are subscribed to the Google Groups pylons-discuss group. To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discuss+unsubscr...@googlegroups.com. To post to this group, send email to pylons-discuss@googlegroups.com. Visit this group at http://groups.google.com/group/pylons-discuss?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: Collect presentation material
On Wed, 2013-05-29 at 11:59 -0700, Rach Belaid wrote: Hello We started 2 months ago the first Pyramid meetup in London. It makes me realize that It can be a bit tricky to find a talk ideas, or being able to adjust it to the right audience level (newcomers, or already pyramid users) That made me think that it could be helpful to centralize some talks material via a github repo on which people could add their slideshow via pull request... eg: github.com/Pylons/presentation .. Like that anybody who want to start a new meetup in its town, could pick talks ideas from it and even a pre-made presentation if it don't feel like building one from scratch. eg: I have done a Keynote template which follow the Pyramid/Pylons colors scheme and I'm now doing a new template for reveal.js that I will be happy to contribute. It's just an idea and suggestion at this stage but I will be keen to submit any material that I will do. Let me know what you think? Sounds good to me, although instead of a centralized repository it might be better to just put a list of links to presentation sources in e.g. http://docs.pylonsproject.org/en/latest/ (maybe a Presentation Sources link under Promote). - C -- You received this message because you are subscribed to the Google Groups pylons-discuss group. To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discuss+unsubscr...@googlegroups.com. To post to this group, send email to pylons-discuss@googlegroups.com. Visit this group at http://groups.google.com/group/pylons-discuss?hl=en. For more options, visit https://groups.google.com/groups/opt_out.