pyramid

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

Static files for Pyramid Application on Elastic Beanstalk

只谈情不闲聊 提交于 2019-11-30 18:11:37
问题 I'm trying to serve some static css, png's, etc. from my Pyramid app that's hosted on Elastic Beanstalk. It works fine on my local machine but when I try to run on EB, neither the CSS nor the images are found. Here's the relevant code: From .ebextensions: option_settings: aws:elasticbeanstalk:container:python: WSGIPath: pyramid.wsgi aws:elasticbeanstalk:application: Application Healthcheck URL: /health aws:elasticbeanstalk:container:python:staticfiles: "/static/": "static/" From home.make

get table columns from sqlAlchemy table model

邮差的信 提交于 2019-11-30 17:43:42
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 column names from a for loop. ex: "col1", "col2", "col3".... etc This is pretty easy with regular sql but

Can I have multiple ini config files in Pyramid?

社会主义新天地 提交于 2019-11-30 14:10:28
问题 I'd like an equivalent of the Django One True Way settings layout: a shared base file, and then a production file and a development file, each of which import the shared base. Is this possible with Pyramid's config? 回答1: Yes that's possible. In one of my projects I have a production_base.ini file and all other production inis inherit from it: production_base.ini [app:main] use = egg:xxx maintenance_mode = False production_www.ini [app:main] use = config:production_base.ini maintenance_mode =

Pyramid stream response body

℡╲_俬逩灬. 提交于 2019-11-30 13:21:25
问题 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:

How can I serve temporary files from Python Pyramid

左心房为你撑大大i 提交于 2019-11-30 13:18:10
Currently, I'm just serving files like this: # view callable def export(request): response = Response(content_type='application/csv') # use datetime in filename to avoid collisions f = open('/temp/XML_Export_%s.xml' % datetime.now(), 'r') # this is where I usually put stuff in the file response.app_iter = f response.headers['Content-Disposition'] = ("attachment; filename=Export.xml") return response The problem with this is that I can't close or, even better, delete the file after the response has been returned. The file gets orphaned. I can think of some hacky ways around this, but I'm hoping

Pyramid: Custom 404 page returns as “200 OK”

旧时模样 提交于 2019-11-30 11:16:48
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? 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, you can affect the response object via request.response to modify its behavior. The renderer then fills in

Trying to catch integrity error with SQLAlchemy

别说谁变了你拦得住时间么 提交于 2019-11-30 11:14:32
I'm having problems with trying to catch an error. I'm using Pyramid/SQLAlchemy and made a sign up form with email as the primary key. The problem is when a duplicate email is entered it raises a IntegrityError, so I'm trying to catch that error and provide a message but no matter what I do I can't catch it, the error keeps appearing. try: new_user = Users(email, firstname, lastname, password) DBSession.add(new_user) return HTTPFound(location = request.route_url('new')) except IntegrityError: message1 = "Yikes! Your email already exists in our system. Did you forget your password?" I get the

Trying to get Pyramid running under Apache + mod_wsgi but it's failing

早过忘川 提交于 2019-11-30 10:22:18
I've got Apache2 running with mod_wsgi installed. I've confirmed that mod_wsgi actually works by following this . The problem comes when I try to get Pyramid running. I get an Internal Server Error and my Apache error log contains the exception: AssertionError: The EvalException middleware is not usable in a multi-process environment Here's my VHost: <VirtualHost *:80> ServerName pyramidtest.dev DocumentRoot /srv/pyramidtest.dev/www/ AssignUserID pyramidtest nogroup WSGIScriptAlias / /srv/pyramidtest.dev/pyramid/load.wsgi </VirtualHost> Here's my load.wsgi : import site site.addsitedir('/opt

ArgumentError: relationship expects a class or mapper argument

ぃ、小莉子 提交于 2019-11-30 07:23:18
问题 I am getting this strange error, and I'm saying strange because I made a change to an unrelated table. I am trying to query my tDevice table which looks like this: class TDevice(Base): __tablename__ = 'tDevice' ixDevice = Column(Integer, primary_key=True) ixDeviceType = Column(Integer, ForeignKey('tDeviceType.ixDeviceType'), nullable=False) ixSubStation = Column(Integer, ForeignKey('tSubStation.ixSubStation'), nullable=False) ixModel = Column(Integer, ForeignKey('tModel.ixModel'), nullable