pyramid

Pyramid stream response body

情到浓时终转凉″ 提交于 2019-11-30 07:03:17
I'm trying to stream Server-Sent Events from my Pyramid application, but I can't figure out how to stream the response body from my view. Here's the test view I'm using (it totally doesn't implement SSE, it's just to work out the streaming portion): @view_config(route_name='iter_test') def iter_test(request): import time def test_iter(): i = 0 while True: i += 1 if i == 5: raise StopIteration yield str(time.time()) print time.time() time.sleep(1) return test_iter() This produces ValueError: Could not convert return value of the view callable function pdiff.views.iter_test into a response

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

Pyramid and .ini configuration

孤人 提交于 2019-11-30 04:56:23
Each Pyramid application has an associated .ini file that contains its settings. For example, a default might look like: [app:main] use = egg:MyProject pyramid.reload_templates = true pyramid.debug_authorization = false pyramid.debug_notfound = false pyramid.debug_routematch = false ... I am wondering if it is possible to add your own configuration values in there, and read them at run-time (mostly from a view callable). For instance, I might want to have [app:main] blog.title = "Custom blog name" blog.comments_enabled = true ... Or is it better to have a separate .ini file and parse it during

get table columns from sqlAlchemy table model

断了今生、忘了曾经 提交于 2019-11-30 01:10:47
问题 I have a table where I would like to fetch all the column names however after browsing the interwebs I could not find a way that works. This is what my table looks like: class myTable(Base): __tablename__ = 'myTable' col1 = Column(Integer, primary_key=True) col2 = Column(Unicode(10)) col3 = Column(Integer) col4 = Column(Numeric(10, 6)) col5 = Column(Numeric(6,3)) col6 = Column(Numeric(6,3)) child = relationship('tChild', backref=backref('children')) I would like to be able to print all the

SQLAlchemy - Getting a list of tables

自闭症网瘾萝莉.ら 提交于 2019-11-30 01:06:32
I couldn't find any information about this in the documentation, but how can I get a list of tables created in SQLAlchemy? I used the class method to create the tables. SingleNegationElimination All of the tables are collected in the tables attribute of the SQLAlchemy MetaData object. To get a list of the names of those tables: >>> metadata.tables.keys() ['posts', 'comments', 'users'] If you're using the declarative extension, then you probably aren't managing the metadata yourself. Fortunately, the metadata is still present on the baseclass, >>> Base = sqlalchemy.ext.declarative.declarative

How do I split models.py into different files for different models in Pyramid?

放肆的年华 提交于 2019-11-30 00:41:27
I am new to pyramid and have been struggling to make some changes to my project. I am trying to split my models/Classes into individual files instead of a single models.py file. In order to do so I have removed the old models.py and created a models folder with __init__.py file along with one file for each class. In __init__.py I imported the class by using from .Foo import Foo . This makes the views work correctly and they can initialize an object. But running the initializedb script does not create new tables as it did when I had all the models in a single models.py. It does not create the

Debug Pylons application through Eclipse

我的梦境 提交于 2019-11-29 23:18:50
I have Eclipse setup with PyDev and love being able to debug my scripts/apps. I've just started playing around with Pylons and was wondering if there is a way to start up the paster server through Eclipse so I can debug my webapp? Create a new launch configuration (Python Run) Main tab Use paster-script.py as main module (you can find it in the Scripts sub-directory in your python installation directory) Don't forget to add the root folder of your application in the PYTHONPATH zone Arguments Set the base directory to the root folder also. As Program Arguments use "serve development.ini" (or

Count of related records in many-to-many relationship

半腔热情 提交于 2019-11-29 17:13:37
I am trying to buit a classmethod, which returns number of members associated with a project. I tried: # method of class Project @classmethod def member_count(cls, project_id): return Session.query(ProjectMember).\ filter(ProjectMember.project_id==project_id).count() The many-to-many relationship is defined as: class Member(Base): __tablename__ = 'member' id = Column(Integer, primary_key=True) login = Column(String(50), unique=True, nullable=False) project_list = relationship("ProjectMember", backref="member") class Project(Base): __tablename__ = 'project' id = Column(Integer, primary_key=True

Pyramid Replacing Double Forward-Slash in URL Matchdict

爱⌒轻易说出口 提交于 2019-11-29 16:48:58
Essentially, I'm just building an API redirection route inside of Pyramid to process cross-domain AJAX requests without using JSONP. I've added a route, like so: config.add_route("api","/api/{url:.*}") with which I want to capture URLs like so: http://domain.com/api/http://location.of/other/api However, when grabbing the captured URL suffix out of the Request matchdict, I get the following: http:/location.of/other/api I'm guessing some escaping has been done during URL processing/matching? How can I avoid this, and get the desired URL with two forward slashes? Even if I pass the URL in as a

Pyramid: Custom 404 page returns as “200 OK”

半世苍凉 提交于 2019-11-29 16:43:55
问题 I have a custom 404 view defined in my Pyramid app: @view_config(context=HTTPNotFound, renderer='404.pt') def not_found(self, request): return {} It works fine, except that the HTTP status code sent with the content is 200 OK, which is not OK by any means. I'm having the same problem with 403 Forbidden. How can I get Pyramid to send the correct status code? 回答1: The exception view is a separate view that provides a spot for you to do whatever you want. Just like any view that uses a renderer,