pylons

Error handling with Python + Pylons

旧时模样 提交于 2019-12-10 22:11:26
问题 What is the proper way to handle errors with Python + Pylons? Say a user sets a password via a form that, when passed to a model class via the controller, throws an error because it's too short. How should that error be handled so that an error message gets displayed on the web page rather than the entire script terminating to an error page? Should there be any error handling in the controller itself? I hope I am explaining myself clearly. Thank you. 回答1: What are you using to validate your

Mocking away the url object in Pylons

前提是你 提交于 2019-12-10 18:26:40
问题 I want to test a method that calls the pylons.url object. However calling this in the tests leads to an error: TypeError: No object (name: url) has been registered for this thread So I'd like to replace the pylons.url object with a Mock from the mock library. @patch('pylons.url') def my_test(self, url_mock): ... However, this doesn't seem to replace the url object. Is there a way to mock out this object? 回答1: In order for patch to work you need to give it the full path to the variable in the

Pydev and Pylons inside virtual environment, auto completion won’t work

强颜欢笑 提交于 2019-12-10 17:55:44
问题 I have Pydev installed and running without problem with Python 2.6. I installed Pylons 0.9.7 RC 4 into virtual environment, then configured new interpreter to pint into virtual environment and this one is used for pylons project. My problem is that code auto completion does not work for a classes from base library (one that are installed with base python installation), and it works without any problem with classes from virtual environment. TIA 回答1: perhaps this or this would help BTW: I guess

Signal handling in Pylons

…衆ロ難τιáo~ 提交于 2019-12-10 16:38:06
问题 I have a pylons project where I need to update some in-memory structures periodically. This should be done on-demand. I decided to come up with a signal handler for this. User sends SIGUSR1 to the main pylons thread and it is handled by the project. This works except after handling the signal, the server crashes with following exception: File "/usr/lib/python2.6/SocketServer.py", line 264, in handle_request fd_sets = select.select([self], [], [], timeout) select.error: (4, 'Interrupted system

Should we use Pylons or PHP for our webapp?

一个人想着一个人 提交于 2019-12-10 15:28:44
问题 My friend and I are planning on building a sort of a forum type of webapp. We've used the major PHP frameworks but we're really thinking about using Python specifically the Pylons framework for our app. Although we're competent PHP programmers, we're somewhat noobs at Python (We could create practical scripts and such). But the thing is we really want to learn Python but by testing Pylons out it seems to be really difficult with all the numerous imports and all. What would you suggest? What

How can I check pooled connections in SQLAlchemy before handing them off to my application code?

只愿长相守 提交于 2019-12-10 13:22:15
问题 We have a slightly unreliable database server, for various reasons, and as a consequence sometimes the database connections used by my application vanish out from under it. The connections are SQLAlchemy 0.6.5 connections to a PostgreSQL db in a Pylons 1.0 web runtime. What I want is some way to catch most of these without a user-visible error; ideally, I'd test the connection at the pool level before returning it from the engine. I control the creation of the engine, so I'm okay there. What

benchmarking PHP vs Pylons

旧城冷巷雨未停 提交于 2019-12-10 11:29:24
问题 I want to benchmark PHP vs Pylons. I want my comparison of both to be as even as possible, so here is what I came up with: PHP 5.1.6 with APC, using a smarty template connecting to a MySQL database Python 2.6.1, using Pylons with a mako template connecting the the same MySQL database Is there anything that I should change in that setup to make it a more fair comparison? I'm going to run it on a spare server that has almost no activity, 2G of ram and 4 cores. Any suggestions of how I should or

Python try/except … function always returns false

て烟熏妆下的殇ゞ 提交于 2019-12-10 10:12:48
问题 I'm trying to figure out the problem in this short paragraph of code. Any help would be appreciated. Regardless of what I specify User.email to be, it always returns false. def add(self): #1 -- VALIDATE EMAIL ADDRESS #Check that e-mail has been completed try: #Validate if e-mail address is in correct format if (isAddressValid(self.email) == 0): self.errors['email'] = 'You have entered an invalid e-mail address'; return 0 except NameError: self.errors['email'] = 'Please enter your e-mail'

What is the method of doing nl2br in Genshi?

ⅰ亾dé卋堺 提交于 2019-12-09 23:14:18
问题 hiyas. I using Genshi+Pylons. please teach me, how use \n to <br/>tag in Genshi? I hope to obtain the same result as " nl2br " in php to change line. Or, does not the solution exist? i'm assign template to some text. (genshi template) <p>${c.message}</p> Im tried. case 1: (python code) c.message = """ foo bar """ NG. display result is "foo bar" case 2: (python code) c.message = """ foo<br /> bar """ NG. display result is "foo<br />bar". displayed escaped stirings! It was a same deal as <br/>

I'm using Pylons and having issues with response.set_cookie

六眼飞鱼酱① 提交于 2019-12-09 22:06:40
问题 I am thinking one of the versions of Pylons is different but I could not find an easy way to tell what versions I was running. In the first example I am fairly certain it is 0.9.7 and up using webob to set the cookie. This environment is setting the @ symbol to \100. As you can see in the other environment doing the exact same thing sets the value properly. Any assistance would be appreciated if you need further information let me know. Newer version of Pylons (I think) setting the value