Pylons Reference Documentation Release 1.0.2

Total Page:16

File Type:pdf, Size:1020Kb

Pylons Reference Documentation Release 1.0.2 Pylons Reference Documentation Release 1.0.2 Ben Bangert, Graham Higgins, James Gardner, Philip Jenvey July 22, 2015 Contents 1 Getting Started 1 1.1 Requirements..............................................1 1.2 Installing................................................1 1.3 Creating a Pylons Project.......................................2 1.4 Running the application........................................4 1.5 Hello World...............................................4 2 Concepts of Pylons 7 2.1 The ‘Why’ of a Pylons Project.....................................7 2.2 WSGI Applications...........................................7 2.3 WSGI Middleware...........................................8 2.4 Controller Dispatch.......................................... 10 2.5 Paster.................................................. 10 2.6 Loading the Application........................................ 11 3 Controllers 13 3.1 Standard Controllers.......................................... 15 3.2 Using the WSGI Controller to provide a WSGI service...................... 17 3.3 Using the REST Controller with a RESTful API........................... 18 3.4 Using the XML-RPC Controller for XML-RPC requests...................... 21 4 Views 25 4.1 Templates................................................ 27 4.2 Passing Variables to Templates.................................... 27 4.3 Default Template Variables...................................... 28 4.4 Configuring Template Engines.................................... 29 4.5 Custom render() functions..................................... 30 4.6 Templating with Mako......................................... 31 5 Models 33 5.1 About the model............................................ 34 5.2 Model Basics.............................................. 35 5.3 Organizing............................................... 37 5.4 Creating a Model............................................ 37 5.5 Adding a Relation........................................... 38 5.6 Creating the Database......................................... 39 5.7 A brief guide to using model objects in the Controller....................... 39 5.8 Logging................................................. 44 i 5.9 About SQLAlchemy.......................................... 44 6 Advanced Models 47 6.1 Advanced SQLAlchemy........................................ 47 6.2 Non-SQLAlchemy libraries...................................... 51 6.3 Object Databases............................................ 51 6.4 Popular No-SQL Databases...................................... 52 7 Configuration 53 7.1 Runtime Configuration........................................ 53 7.2 Environment.............................................. 55 7.3 URL Configuration........................................... 55 7.4 Middleware............................................... 57 7.5 Application Setup........................................... 59 8 Logging 61 8.1 Logging messages........................................... 61 8.2 Basic Logging configuration..................................... 62 8.3 Filtering log messages......................................... 63 8.4 Advanced Configuration....................................... 63 8.5 Request logging with Paste’s TransLogger............................. 64 8.6 Logging to wsgi.errors......................................... 65 9 Helpers 69 9.1 Pagination................................................ 69 9.2 Secure Form Tag Helpers....................................... 74 10 Forms 75 10.1 The basics................................................ 75 10.2 Getting Started............................................. 75 10.3 Using the Helpers........................................... 76 10.4 File Uploads............................................... 77 10.5 Validating user input with FormEncode............................... 78 10.6 Other Form Tools............................................ 81 11 Internationalization and Localization 83 11.1 Introduction............................................... 83 11.2 Getting Started............................................. 84 11.3 Using Babel............................................... 85 11.4 Back To Work.............................................. 87 11.5 Testing the Application........................................ 87 11.6 Fallback Languages.......................................... 88 11.7 Translations Within Templates.................................... 89 11.8 Lazy Translations............................................ 90 11.9 Producing a Python Egg........................................ 91 11.10 Plural Forms.............................................. 91 11.11 Summary................................................ 92 11.12 Further Reading............................................ 92 11.13 babel.core – Babel core classes.................................. 92 11.14 babel.localedata — Babel locale data............................. 102 11.15 babel.dates – Babel date classes................................. 102 11.16 babel.numbers – Babel number classes.............................. 103 12 Sessions 107 12.1 Sessions................................................. 107 ii 12.2 The Session Object........................................... 107 12.3 Configuring the Session........................................ 108 12.4 Storing SQLAlchemy mapped objects in Beaker sessions..................... 109 12.5 Custom and caching middleware.................................. 109 12.6 Using Session in Internationalization................................. 109 12.7 Using Session in Secure Forms.................................... 110 12.8 Hacking the session for no cookies.................................. 110 12.9 Using middleware (Beaker) with a composite app......................... 110 13 Caching 113 13.1 Types of Caching............................................ 113 13.2 Namespaces and Keys......................................... 114 13.3 Configuring............................................... 114 13.4 Browser-Side.............................................. 115 13.5 Controller Actions........................................... 116 13.6 Templates................................................ 117 13.7 Arbitrary Functions.......................................... 117 13.8 Fragments................................................ 118 14 Unit and functional testing 119 14.1 Unit Testing with webtest ...................................... 119 14.2 Example: Testing a Controller.................................... 120 14.3 Testing Pylons Objects......................................... 121 14.4 Testing Your Own Objects....................................... 122 14.5 Unit Testing............................................... 123 14.6 Functional Testing........................................... 123 15 Errors, Troubleshooting, and Debugging 125 15.1 Error Middleware........................................... 125 15.2 Interactive Debugging......................................... 126 15.3 E-mailing Errors............................................ 128 15.4 Programmatically Handling Errors................................. 128 16 Upgrading 131 16.1 1.0 -> 1.0.1................................................ 131 16.2 0.9.7 -> 1.0................................................ 131 17 Packaging and Deployment Overview 135 17.1 Egg Files................................................. 135 17.2 Installing as a Non-root User..................................... 135 17.3 Understanding the Setup Process.................................. 136 17.4 Deploying the Application...................................... 138 17.5 Advanced Usage............................................ 138 18 Running Pylons Apps with Other Web Servers 139 18.1 Using Fast-CGI............................................. 139 18.2 Apache Configuration......................................... 140 18.3 PrefixMiddleware........................................... 140 18.4 Using Java Web Servers with Jython................................. 141 19 Documenting Your Application 143 19.1 Introduction............................................... 143 19.2 Tutorial................................................. 143 19.3 Learning ReStructuredText...................................... 144 19.4 Using Docstrings............................................ 144 iii 19.5 Using doctest.............................................. 145 19.6 Summary................................................ 145 20 Distributing Your Application 147 20.1 Running Your Application...................................... 148 21 Python 2.3 Installation Instructions 149 21.1 Advice of end of support for Python 2.3 .............................. 149 21.2 Preparation............................................... 149 21.3 System-wide Install.......................................... 149 22 Windows Notes 151 22.1 For Win2K or WinXP.......................................... 151 22.2 For Windows 95, 98 and ME..................................... 152 22.3 Finally.................................................. 152 23 Pylons on Jython 153 23.1 Installation............................................... 153 23.2 Deploying to Java Web servers.................................... 153 24 Security policy for bugs 155 24.1 Receiving Security Updates...................................... 155 24.2 Reporting Security Issues....................................... 155 24.3 Minimising Risk............................................ 156 25 WSGI support 157 25.1 Paste
Recommended publications
  • Pylons Reference Documentation Release 1.0.2
    Pylons Reference Documentation Release 1.0.2 Ben Bangert, Graham Higgins, James Gardner, Philip Jenvey January 12, 2018 Contents 1 Getting Started 1 1.1 Requirements...............................................1 1.2 Installing.................................................1 1.3 Creating a Pylons Project........................................3 1.4 Running the application.........................................4 1.5 Hello World...............................................4 2 Concepts of Pylons 7 2.1 The ‘Why’ of a Pylons Project......................................7 2.2 WSGI Applications...........................................8 2.3 WSGI Middleware............................................8 2.4 Controller Dispatch........................................... 10 2.5 Paster................................................... 10 2.6 Loading the Application......................................... 11 3 Controllers 13 3.1 Standard Controllers........................................... 14 3.2 Using the WSGI Controller to provide a WSGI service......................... 16 3.3 Using the REST Controller with a RESTful API............................ 17 3.4 Using the XML-RPC Controller for XML-RPC requests........................ 20 4 Views 23 4.1 Templates................................................. 24 4.2 Passing Variables to Templates...................................... 24 4.3 Default Template Variables....................................... 25 4.4 Configuring Template Engines...................................... 26 4.5 Custom
    [Show full text]
  • LAMP and the REST Architecture Step by Step Analysis of Best Practice
    LAMP and the REST Architecture Step by step analysis of best practice Santiago Gala High Sierra Technology S.L.U. Minimalistic design using a Resource Oriented Architecture What is a Software Platform (Ray Ozzie ) ...a relevant and ubiquitous common service abstraction Creates value by leveraging participants (e- cosystem) Hardware developers (for OS level platforms) Software developers Content developers Purchasers Administrators Users Platform Evolution Early stage: not “good enough” solution differentiation, innovation, value flows Later: modular architecture, commoditiza- tion, cloning no premium, just speed to market and cost driven The platform effect - ossification, followed by cloning - is how Chris- tensen-style modularity comes to exist in the software industry. What begins as a value-laden proprietary platform becomes a replaceable component over time, and the most successful of these components finally define the units of exchange that power commodity networks. ( David Stutz ) Platform Evolution (II) Example: PostScript Adobe Apple LaserWriter Aldus Pagemaker Desktop Publishing Linotype imagesetters NeWS (Display PostScript) OS X standards (XSL-FO -> PDF, Scribus, OOo) Software Architecture ...an abstraction of the runtime elements of a software system during some phase of its oper- ation. A system may be composed of many lev- els of abstraction and many phases of opera- tion, each with its own software architecture. Roy Fielding (REST) What is Architecture? Way to partition a system in components
    [Show full text]
  • A Learner's Guide to Programming Using the Python Language.Pdf
    Advance Praise for Head First Programming “Head First Programming does a great job teaching programming using an iterative process. Add a little, explain a little, make the program a little better. This is how programming works in the real world and Head First Programming makes use of that in a teaching forum. I recommend this book to anyone who wants to start dabbling in programming but doesn’t know where to start. I’d also recommend this book to anyone not necessarily new to programming, but curious about Python. It’s a great intro to programming in general and programming Python specifically.” — Jeremy Jones, Coauthor of Python for Unix and Linux System Administration “David Griffiths and Paul Barry have crafted the latest gem in the Head First series. Do you use a computer, but are tired of always using someone else’s software? Is there something you wish your computer would do but wasn’t programmed for? In Head First Programming, you’ll learn how to write code and make your computer do things your way.” — Bill Mietelski, Software Engineer “Head First Programming provides a unique approach to a complex subject. The early chapters make excellent use of metaphors to introduce basic programming concepts used as a foundation for the rest of the book. This book has everything, from web development to graphical user interfaces and game programming.” — Doug Hellmann, Senior Software Engineer, Racemi “A good introduction to programming using one of the best languages around, Head First Programming uses a unique combination of visuals, puzzles, and exercises to teach programming in a way that is approachable and fun.” — Ted Leung, Principal Software Engineer, Sun Microsystems Praise for other Head First books “Kathy and Bert’s Head First Java transforms the printed page into the closest thing to a GUI you’ve ever seen.
    [Show full text]
  • Openstack Security Guide April 26, 2014 Current
    OpenStack Security Guide April 26, 2014 current OpenStack Security Guide current (2014-04-26) Copyright © 2013 OpenStack Foundation Some rights reserved. This book provides best practices and conceptual information about securing an OpenStack cloud. Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. http://creativecommons.org/licenses/by/3.0/legalcode i TM OpenStack Security Guide April 26, 2014 current Table of Contents Preface ................................................................................................ 11 Conventions ................................................................................. 11 Document change history ............................................................ 11 1. Acknowledgments ............................................................................. 1 2. Why and how we wrote this book ..................................................... 3 Objectives ...................................................................................... 3 How .............................................................................................. 3 How to contribute to this book ..................................................... 7 3. Introduction to OpenStack ................................................................. 9 Cloud types ................................................................................... 9 OpenStack service overview ......................................................... 11 4. Security Boundaries and Threats
    [Show full text]
  • Pydap Documentation Release 3.2
    Pydap Documentation Release 3.2 Roberto De Almeida May 24, 2017 Contents 1 Quickstart 3 2 Help 5 3 Documentation 7 3.1 Using the client..............................................7 3.2 Running a server............................................. 15 3.3 Handlers................................................. 18 3.4 Responses................................................ 22 3.5 Developer documentation........................................ 24 3.6 License.................................................. 34 4 Indices and tables 35 i ii Pydap Documentation, Release 3.2 Pydap is a pure Python library implementing the Data Access Protocol, also known as DODS or OPeNDAP. You can use Pydap as a client to access hundreds of scientific datasets in a transparent and efficient way through the internet; or as a server to easily distribute your data from a variety of formats. Contents 1 Pydap Documentation, Release 3.2 2 Contents CHAPTER 1 Quickstart You can install the latest version (3.2) using pip. After installing pip you can install Pydap with this command: $ pip install Pydap This will install Pydap together with all the required dependencies. You can now open any remotely served dataset, and Pydap will download the accessed data on-the-fly as needed: >>> from pydap.client import open_url >>> dataset= open_url('http://test.opendap.org/dap/data/nc/coads_climatology.nc') >>> var= dataset['SST'] >>> var.shape (12, 90, 180) >>> var.dtype dtype('>f4') >>> data= var[0,10:14,10:14] # this will download data from the server >>> data <GridType with
    [Show full text]
  • Comparison of Web Server Software from Wikipedia, the Free Encyclopedia
    Create account Log in Article Talk Read Edit ViewM ohrisetory Search Comparison of web server software From Wikipedia, the free encyclopedia Main page This article is a comparison of web server software. Contents Featured content Contents [hide] Current events 1 Overview Random article 2 Features Donate to Wikipedia 3 Operating system support Wikimedia Shop 4 See also Interaction 5 References Help 6 External links About Wikipedia Community portal Recent changes Overview [edit] Contact page Tools Server Developed by Software license Last stable version Latest release date What links here AOLserver NaviSoft Mozilla 4.5.2 2012-09-19 Related changes Apache HTTP Server Apache Software Foundation Apache 2.4.10 2014-07-21 Upload file Special pages Apache Tomcat Apache Software Foundation Apache 7.0.53 2014-03-30 Permanent link Boa Paul Phillips GPL 0.94.13 2002-07-30 Page information Caudium The Caudium Group GPL 1.4.18 2012-02-24 Wikidata item Cite this page Cherokee HTTP Server Álvaro López Ortega GPL 1.2.103 2013-04-21 Hiawatha HTTP Server Hugo Leisink GPLv2 9.6 2014-06-01 Print/export Create a book HFS Rejetto GPL 2.2f 2009-02-17 Download as PDF IBM HTTP Server IBM Non-free proprietary 8.5.5 2013-06-14 Printable version Internet Information Services Microsoft Non-free proprietary 8.5 2013-09-09 Languages Jetty Eclipse Foundation Apache 9.1.4 2014-04-01 Čeština Jexus Bing Liu Non-free proprietary 5.5.2 2014-04-27 Galego Nederlands lighttpd Jan Kneschke (Incremental) BSD variant 1.4.35 2014-03-12 Português LiteSpeed Web Server LiteSpeed Technologies Non-free proprietary 4.2.3 2013-05-22 Русский Mongoose Cesanta Software GPLv2 / commercial 5.5 2014-10-28 中文 Edit links Monkey HTTP Server Monkey Software LGPLv2 1.5.1 2014-06-10 NaviServer Various Mozilla 1.1 4.99.6 2014-06-29 NCSA HTTPd Robert McCool Non-free proprietary 1.5.2a 1996 Nginx NGINX, Inc.
    [Show full text]
  • Arxiv:1903.01950V2 [Cs.OS] 20 Nov 2019
    Pyronia: Intra-Process Access Control for IoT Applications Marcela S. Melara, David H. Liu, Michael J. Freedman Princeton University Abstract recognize_face() function could allow an attacker to steal the application’s private authentication token by upload Third-party code plays a critical role in IoT applications, this file to an unauthorized remote server. Meanwhile, the which generate and analyze highly privacy-sensitive data. application developer only expected recognize_face() to Unlike traditional desktop and server settings, IoT devices access the image file face.jpg. mostly run a dedicated, single application. As a result, This is an especially serious problem for IoT because vulnerabilities in third-party libraries within a process most devices run a single, dedicated application that has pose a much bigger threat than on traditional platforms. access to all sensors on the device. In other words, third- We present Pyronia, a fine-grained access control sys- party code does not run with least privilege [48]. tem for IoT applications written in high-level languages. Now, these threats are not IoT-specific. A large body of Pyronia exploits developers’ coarse-grained expectations prior research has sought to restrict untrusted third-party about how imported third-party code operates to restrict code in desktop, mobile, and cloud applications (e.g., [10, access to files, devices, and specific network destinations, 11,14,19,21,24,36,41,54,55,59,65 –67]). However, these at the granularity of individual functions. To efficiently traditional compute settings face more complex security protect such sensitive OS resources, Pyronia combines challenges. Mobile devices, desktops, and even IoT hubs, three techniques: system call interposition, stack inspec- run multiple mutually distrusting applications; further, tion, and memory domains.
    [Show full text]
  • Chaussette Documentation Release 1.3.0
    Chaussette Documentation Release 1.3.0 Tarek Ziade Sep 27, 2017 Contents 1 Usage 3 1.1 Running a plain WSGI application....................................3 1.2 Running a Django application......................................3 1.3 Running a Python Paste application...................................3 2 Using Chaussette in Circus 5 3 Using Chaussette in Supervisor7 4 Backends 9 5 Rationale and Design 11 6 Useful links 13 i ii Chaussette Documentation, Release 1.3.0 Chaussette is a WSGI server you can use to run your Python WSGI applications. The particularity of Chaussette is that it can either bind a socket on a port like any other server does or run against already opened sockets. That makes Chaussette the best companion to run a WSGI or Django stack under a process and socket manager, such as Circus or Supervisor. Contents 1 Chaussette Documentation, Release 1.3.0 2 Contents CHAPTER 1 Usage You can run a plain WSGI application, a Django application, or a Paste application. To get all options, just run chaussette –help. Running a plain WSGI application Chaussette provides a console script you can launch against a WSGI application, like any WSGI server out there: $ chaussette mypackage.myapp Application is <function myapp at 0x104d97668> Serving on localhost:8080 Using <class chaussette.backend._wsgiref.ChaussetteServer at 0x104e58d50> as a backend Running a Django application Chaussette allows you to run a Django project. You just need to provide the Python import path of the WSGI application, commonly located in the Django project’s wsgi.py file. For further information about how the wsgi. py file should look like see the Django documentation.
    [Show full text]
  • Red Hat Enterprise Linux 7 7.8 Release Notes
    Red Hat Enterprise Linux 7 7.8 Release Notes Release Notes for Red Hat Enterprise Linux 7.8 Last Updated: 2021-03-02 Red Hat Enterprise Linux 7 7.8 Release Notes Release Notes for Red Hat Enterprise Linux 7.8 Legal Notice Copyright © 2021 Red Hat, Inc. The text of and illustrations in this document are licensed by Red Hat under a Creative Commons Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is available at http://creativecommons.org/licenses/by-sa/3.0/ . In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must provide the URL for the original version. Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law. Red Hat, Red Hat Enterprise Linux, the Shadowman logo, the Red Hat logo, JBoss, OpenShift, Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries. Linux ® is the registered trademark of Linus Torvalds in the United States and other countries. Java ® is a registered trademark of Oracle and/or its affiliates. XFS ® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States and/or other countries. MySQL ® is a registered trademark of MySQL AB in the United States, the European Union and other countries. Node.js ® is an official trademark of Joyent. Red Hat is not formally related to or endorsed by the official Joyent Node.js open source or commercial project.
    [Show full text]
  • The Pyramid Web Application Development Framework Version 1.1
    The Pyramid Web Application Development Framework Version 1.1 Chris McDonough CONTENTS Front Matteri Copyright, Trademarks, and Attributions iii Attributions............................................ iv Print Production.......................................... iv Contacting The Publisher..................................... iv HTML Version and Source Code................................. iv Typographical Conventionsv Author Introduction vii Audience............................................. vii Book Content........................................... viii The Genesis of repoze.bfg .................................. viii The Genesis of Pyramid...................................... ix Thanks............................................... ix I Narrative Documentation1 1 Pyramid Introduction3 1.1 What Is The Pylons Project?................................4 1.2 Pyramid and Other Web Frameworks............................4 2 Installing Pyramid7 2.1 Before You Install......................................7 2.1.1 If You Don’t Yet Have A Python Interpreter (UNIX)...............7 2.1.2 If You Don’t Yet Have A Python Interpreter (Windows)..............9 2.2 Installing Pyramid on a UNIX System...........................9 2.2.1 Installing the virtualenv Package....................... 10 2.2.2 Creating the Virtual Python Environment..................... 10 2.2.3 Installing Pyramid Into the Virtual Python Environment............. 11 2.3 Installing Pyramid on a Windows System......................... 11 2.4 Installing Pyramid on Google App Engine........................
    [Show full text]
  • The Jumpgate Definitive Guide
    THE JUMPGATE DEFINITIVE GUIDE Compiled by: Odiche Special Thanks to: NETDEVIL© NewDawn IkeProf RazorKiss Lady Dracoe SpaceDrake Zalty’s And all the Pilots I have forgotten to thank! FACTIONS Solrain: Medium-fast ships, heavy, fast-recharging shields. A little light on firepower, lots of flexibility in ship loadout because of a large number of MODx slots. (MODx are worth reading up on in JOSSH). All Solrain ships have buckets of cargo space... the Solrain Fighter-class ship, the Intensity can carry a full set of equipment in it's hold to re-equip a downed squadmate. The Solrain Bomber and Medium Fighter are top-of-the-line, and they have a good Light Transport as well. Solrain ships are fairly forgiving for a new pilot; the glut of Flashfire MODxes they can equip can ensure their survival in situations where any other ship would be gunned down before it could escape. Solrain ships often utilize hit and run techniques in combat to gain the maximum advantage from their fast-recharging shields. Solrain ships can generally re-equip to a fairly good degree from their home stations. Solrain are typically RPed (Roleplayed) as greedy, profiteering traders. Which they are. Assassins, Mercenaries, Pirates, Traders, or Factionalists. To piss off a Solrain pilot, call him a Smurf. Quantar: Usually have the fastest ships in a given class. They also have a medium load- out of MODx slots. Quantar ships rely on maneuvrability to evade incoming fire; the Quantar fighters, the Typhoon, is an ideal wolf-pack ship. Their speed can carry them out of most trouble; only scouts or an Intensity can really catch them up, and if you are a skilled pilot, you can evade and escape from those also.
    [Show full text]
  • Comparative Study on Python Web Frameworks: Flask and Django
    Devndra Ghimire Comparative study on Python web frameworks: Flask and Django Metropolia University of Applied Sciences Bachelor of Engineering Media Engineering Bachelor’s Thesis 5 May 2020 Abstract Devndra Ghimire Author(s) Comparative study on Python web frameworks: Flask and Title Django. Number of Pages 37 pages + 0 appendices Date 5 May 2010 Degree Bachelor of Engineering Degree Programme Media Engineering Specialisation option Software Engineering Instructor(s) Kari Salo, Senior Lecturer The purpose of the thesis was to the study the various features, advantages, and the limita- tion of two web development frameworks for Python programming language. It aims to com- pare the usage of Django and Flask frameworks from a novice point of view. The theoretical part of the thesis presents the various types of programming languages and web technolo- gies. In the practical part, however, the study is divided into two parts, each part observing the respective web application framework. In order to perform the comparison, a social network and eCommerce like application was built for Flask and Django respectively. The comparison was started by developing the social network application first with Flask and finished with the e-commerce application using Django. Python programing language, SQLite database for the backend and HTML, JavaS- cript, and Ajax were used for the frontend technology. At the end of the project, both appli- cations were deployed to the cloud platform called Heroku. After the comparison, it was found that the most significant advantages of Flask were that it provides simplicity, flexibility, fine-grained control and quick and easy to learn. On the other hand, Django was easy to work with because of its extensive features and support for librar- ies.
    [Show full text]