pylons

Who's Online in Pylons

非 Y 不嫁゛ 提交于 2019-12-01 04:09:25
I currently have a Pylons application running with a basic user system set-up. I want to try and create a widget that shows the users that are currently logged on to the website. I'm not sure how I should handle this though; I'm not sure if pylons sessions being active are based on whether or not a user is actually on the web apps page or not, so I am seeking some ideas as to how I can work with what I already have possibly to accomplish this. There's several ways you can do it, depending on how accurate you want to be. The easiest, and first way to do it, use memecached or a persistent store

Who's Online in Pylons

萝らか妹 提交于 2019-12-01 02:25:53
问题 I currently have a Pylons application running with a basic user system set-up. I want to try and create a widget that shows the users that are currently logged on to the website. I'm not sure how I should handle this though; I'm not sure if pylons sessions being active are based on whether or not a user is actually on the web apps page or not, so I am seeking some ideas as to how I can work with what I already have possibly to accomplish this. 回答1: There's several ways you can do it,

Python from Python: restricting functionality? [duplicate]

非 Y 不嫁゛ 提交于 2019-11-30 20:28:59
Possible Duplicate: Python, safe, sandbox I'm building a corporate web system in Python which allows scripts to be uploaded and run serverside. Given I'm already developing in Python and its such a nice simple language, it seems like a good language to write the scripts in. However, there is a security hazard there, I want to block all function calls except a limited subset. Is there a mechanism I can use to do this, or some other technique? Do I need to use something else, Lua perhaps? I'm developing in Pyramid/Pylons. This is a terrible idea, but just to let you know about the option: You

Interactive debugging with nosetests in PyDev

故事扮演 提交于 2019-11-30 19:16:17
I'm using PyDev ( with Aptana ) to write and debug a Python Pylons app, and I'd like to step through the tests in the debugger. Is it possible to launch nosetests through PyDev and stop at breakpoints? Here is what i do to run nosetests using eclipse Pydev (Hope this will help you). first of all i create a python script and i put it in the root of my package directory : --Package | | -- runtest.py | | -- ... (others modules) and in runtest.py i put: import nose nose.main() now i go to in the menu Run -> Run configurations and i create a new configuration of Pydev Django i choose my package and

Stream a file to the HTTP response in Pylons

邮差的信 提交于 2019-11-30 13:59:33
I have a Pylons controller action that needs to return a file to the client. (The file is outside the web root, so I can't just link directly to it.) The simplest way is, of course, this: with open(filepath, 'rb') as f: response.write(f.read()) That works, but it's obviously inefficient for large files. What's the best way to do this? I haven't been able to find any convenient methods in Pylons to stream the contents of the file. Do I really have to write the code to read a chunk at a time myself from scratch? The correct tool to use is shutil.copyfileobj, which copies from one to the other a

Mark string as safe in Mako

不羁的心 提交于 2019-11-30 12:07:09
I'm using Pylons with Mako templates and I want to avoid typing this all the time: ${ h.some_function_that_outputs_html() | n } I want to somehow mark the function, or a variable as safe (you can do that in Django) so I don't have to pipe-en all the time. Any ideas? I just found out that if you put a html method in your class, then Mako will just call that method and output whatever it returns in the template. So I did: def __html__(self): return unicode(self) That's basically what h.literal does. According to the mako docs about filtering , you can set the default filters that are applied

SQLAlchemy printing raw SQL from create()

橙三吉。 提交于 2019-11-30 10:28:24
问题 I am giving Pylons a try with SQLAlchemy, and I love it, there is just one thing, is it possible to print out the raw SQL CREATE TABLE data generated from Table().create() before it's executed? 回答1: from sqlalchemy.schema import CreateTable print(CreateTable(table)) If you are using declarative syntax: print(CreateTable(Model.__table__)) Update: Since I have the accepted answer and there is important information in klenwell answer, I'll also add it here. You can get the SQL for your specific

Proper way to set object instance variables

最后都变了- 提交于 2019-11-30 08:24:20
I'm writing a class to insert users into a database, and before I get too far in, I just want to make sure that my OO approach is clean: class User(object): def setName(self,name): #Do sanity checks on name self._name = name def setPassword(self,password): #Check password length > 6 characters #Encrypt to md5 self._password = password def commit(self): #Commit to database >>u = User() >>u.setName('Jason Martinez') >>u.setPassword('linebreak') >>u.commit() Is this the right approach? Should I declare class variables up top? Should I use a _ in front of all the class variables to make them

Python from Python: restricting functionality? [duplicate]

心不动则不痛 提交于 2019-11-30 05:05:26
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Python, safe, sandbox I'm building a corporate web system in Python which allows scripts to be uploaded and run serverside. Given I'm already developing in Python and its such a nice simple language, it seems like a good language to write the scripts in. However, there is a security hazard there, I want to block all function calls except a limited subset. Is there a mechanism I can use to do this, or some other

Interactive debugging with nosetests in PyDev

廉价感情. 提交于 2019-11-30 03:51:42
问题 I'm using PyDev ( with Aptana ) to write and debug a Python Pylons app, and I'd like to step through the tests in the debugger. Is it possible to launch nosetests through PyDev and stop at breakpoints? 回答1: Here is what i do to run nosetests using eclipse Pydev (Hope this will help you). first of all i create a python script and i put it in the root of my package directory : --Package | | -- runtest.py | | -- ... (others modules) and in runtest.py i put: import nose nose.main() now i go to in