Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 608

Show
Ignore:
Timestamp:
09/04/05 21:27:38
Author:
mikerobi
Message:

HTTPClientError renamed HTTPStatusError, removed some outdated session documentation

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/_cpcgifs.py

    r586 r608  
    3333            cgi.FieldStorage.__init__(self, *args, **kwds) 
    3434        except ValueError: 
    35             ec = cherrypy._cperror.HTTPClientError 
    36             raise ec(status=413) 
     35            raise cherrypy.HTTPStatusError(status=413) 
    3736 
    3837    def read_lines_to_eof(self): 
  • trunk/cherrypy/_cperror.py

    r606 r608  
    173173_missing = object() 
    174174 
    175 class HTTPClientError(Error): 
     175class HTTPStatusError(Error): 
    176176    """Exception raised when the client has made an error in its request.""" 
    177177     
     
    191191 
    192192 
    193 class NotFound(HTTPClientError): 
     193class NotFound(HTTPStatusError): 
    194194    """ Happens when a URL couldn't be mapped to any class.method """ 
    195195     
    196196    def __init__(self, path): 
    197197        self.args = (path,) 
    198         HTTPClientError.__init__(self, 404) 
     198        HTTPStatusError.__init__(self, 404) 
  • trunk/cherrypy/_cphttptools.py

    r607 r608  
    288288                applyFilters('onEndResource') 
    289289        except: 
    290             # This includes HTTPClientError and NotFound 
     290            # This includes HTTPStatusError and NotFound 
    291291            handleError(sys.exc_info()) 
    292292     
     
    420420        # _cpOnError and _cpOnHTTPError will probably change cherrypy.response.body. 
    421421        # They may also change the headerMap, etc. 
    422         if sys.exc_info()[0] is cherrypy._cperror.HTTPClientError: 
     422        if sys.exc_info()[0] is cherrypy.HTTPStatusError: 
    423423            _cputil.getSpecialAttribute('_cpOnHTTPError')() 
    424424        else: 
  • trunk/cherrypy/lib/cptools.py

    r606 r608  
    206206        cherrypy.response.headerMap['Content-Range'] = "bytes */%s" % content_length 
    207207        message = "Invalid Range (first-byte-pos greater than Content-Length)" 
    208         raise cherrypy.HTTPClientError(416, message) 
     208        raise cherrypy.HTTPStatusError(416, message) 
    209209     
    210210    return result 
  • trunk/cherrypy/tutorial/tut10_http_errors.py

    r607 r608  
    4040        # raise an error based on the get query 
    4141        code = int(code) 
    42         HTTPClientError = cherrypy._cperror.HTTPClientError 
    43         raise HTTPClientError(status = code) 
     42        raise cherrypy.HTTPStatusError(status = code) 
    4443    error.exposed = True 
    4544 
  • trunk/cherrypy/tutorial/tutorial.conf

    r605 r608  
    33server.threadPool = 10 
    44server.environment = "production" 
    5 # server.showTracebacks = True 
     5server.showTracebacks = True 
    66# server.logToScreen = False 
  • trunk/docs/book/xml/apireference.xml

    r583 r608  
    215215      <listitem> 
    216216        <section> 
     217          <title>cherrypy.server.restart()</title> 
     218          <para> 
     219            Restart the CherryPy Server. 
     220          </para> 
     221        </section> 
     222      </listitem> 
     223      <listitem> 
     224        <section> 
    217225          <title>cherrypy.server.onStartServerList</title> 
    218226          <para> 
     
    288296    <title>cherrypy exceptions</title> 
    289297    <itemizedlist> 
    290       <listitem> 
    291         <section> 
    292           <title>cherrypy.HTTPRedirect</title> 
    293         </section> 
    294       </listitem> 
    295       <listitem> 
    296         <section> 
    297           <title>cherrypy.NotFound</title> 
    298         </section> 
    299       </listitem> 
     298         
     299      <listitem> 
     300        <section> 
     301            <title>cherrypy.HTTPStatusError</title> 
     302            <para> 
     303                This exception can be used to automatically send a response  
     304                using a http status code, with an appropriate error page. 
     305            </para> 
     306        </section> 
     307      </listitem> 
     308       
     309      <listitem> 
     310        <section> 
     311            <title>cherrypy.HTTPRedirect</title> 
     312            This exception will force a HTTP redirect. 
     313        </section> 
     314      </listitem> 
     315       
     316      <listitem> 
     317        <section> 
     318            <title>cherrypy.NotFound</title> 
     319            This exception is raised when CherryPy is unable to map a 
     320            requested path to an internal method. 
     321        </section> 
     322      </listitem> 
     323     
    300324    </itemizedlist> 
    301325  </section> 
  • trunk/docs/book/xml/sessions.xml

    r513 r608  
    55  <abstract> 
    66    <para> CherryPy 2.1 includes a powerful sessions system provided via a new "sessionFilter". The 
    7       old sessions system was difficult to extend and was not thread safe. The new system addresses 
    8       these issues and includes several powerful new features. </para> 
     7        old sessions system was difficult to extend and was not thread safe. 
     8    </para> 
    99  </abstract> 
    10   <section id="sessionfeaturs"> 
    11     <title>Session Features</title> 
    12     <itemizedlist> 
    13       <listitem>Multiple Storage Types</listitem> 
    14       <listitem>Thread Safety</listitem> 
    15       <listitem>Easy to extend</listitem> 
    16       <listitem>Session Caching</listitem> 
    17       <listitem>Multiple Named Sessions</listitem> 
    18     </itemizedlist> 
    19   </section> 
    20   <section id="sessionconfig"> 
    21     <title>Session Configuration</title> 
    22   </section> 
    23   <section id="usingsessions"> 
    24     <title>Using Sessions</title> 
    25     <section> 
    26       <title>SessionDicts</title> 
    27       <para> All session data is accessed through an instance of a SessionDict class. SesssionDicts 
    28         provide a dictionary like interface. </para> 
    29       <para> The following dictionary methods are provided: <itemizedlist> 
    30           <listitem>__setitem__(key, value)</listitem> 
    31           <listitem>__getitem__(key) </listitem> 
    32           <listitem>get(key, default) </listitem> 
    33           <listitem>__iter__()</listitem> 
    34         </itemizedlist> SessionDicts also provide the following attributes: <itemizedlist> 
    35           <listitem>sessionKey (read only)</listitem> 
    36           <listitem>lastAccess (read only)</listitem> 
    37           <listitem>createdAt (read only)</listitem> 
    38           <listitem>timeout </listitem> 
    39         </itemizedlist> 
    40       </para> 
    41     </section> 
    42     <!-- end SessionDict section --> 
    43     <section> 
    44       <!-- cherrypy.sessions section --> 
    45       <title>cherrypy.session</title> 
    46       <para> cherrypy.session is the single point of access for all session data. At the beginning 
    47         of each request, the sessionFilter checks for any sessions that may have been defined for 
    48         the requested portion of the site. For each defined session, a SessionDict is created and is 
    49         added as an attribute of cherrypy.session. </para> 
    50       <para> For example, given a session named "checkoutSession", all data for this session will be 
    51         accessible through: "cherrypy.sessions.checkoutSession" </para> 
    52       <example> 
    53         <title>cherrypy.session</title> 
    54         <para> This code iterates over a list of items in a shopping cart, and computes The total 
    55           cost of all items. </para> 
    56         <programlisting> 
    57           totalCost = 0.0 
    58            
    59           for item in cherrypy.sessions.checkoutSession[&apos;shoppingCart&apos;]: 
    60               totalCost += item.cost 
    61         </programlisting> 
    62       </example> 
    63       <section> 
    64         <title>The default session</title> 
    65         <para> By default, the sessionFilter provides a session named "default", which is accessed 
    66           through "cherrypy.sessions.default". As a shortcut the ".default" can be ommited and 
    67           "cherrypy.sessions" will behave like a dictionary. Session attributes, such as 
    68           "cookieName", can only be retrieved through cherrypy.sessions.default. </para> 
    69         <para> Unless there is a clear advantage to having more that one named session, the default 
    70           session should be used to store all session data. The default session may (in the future) 
    71           be optimized to provide superior performance than that of custom named sessions. </para> 
    72       </section> 
    73       <!-- end default session section --> 
    74     </section> 
    75     <!-- end of cherrypy.sessions section --> 
    76     <section> 
    77       <!-- session configuration --> 
    78       <title>Session Configuration</title> 
    79       <itemizedlist> 
    80         <listitem> 
    81           <section> 
    82             <title>sessionFilter.on</title> 
    83             <para> Can be True or False. Will toggle on/off all sessions within the current path. By 
    84               default the session filter is turned off. </para> 
    85           </section> 
    86         </listitem> 
    87       </itemizedlist> 
    88       <para> These settings are common to all storage types. </para> 
    8910      <itemizedlist> 
    9011        <listitem> 
     
    10021            <title>sessionFilter.storageType</title> 
    10122            <para> The storagType is the string name of the storage type for sessionName. The built 
    102               in storageType are: &apos;ram&apos;, &apos;file&apos;, 
    103               &apos;anydb&apos;, &apos;sqlobject&apos;. If the storageType does not 
    104               match one of the built in storage adaptors a special attribute look up is performed. 
    105               If ommited the storageType will default to &apos;ram&apos;. </para> 
     23              in storageType are: &apos;ram&apos;, &apos;file&apos;,</para> 
    10624          </section> 
    10725        </listitem> 
     
    11937          </section> 
    12038        </listitem> 
    121         <listitem> 
    122           <section> 
    123             <title>sessionFilter.cookiePrefix</title> 
    124             <para> The cookiePrefix is prepended to the beginning of every session cookie name. 
    125             </para> 
    126           </section> 
    127         </listitem> 
    128         <listitem> 
    129           <section> 
    130             <title>sessionFilter.keyGenerator</title> 
    131             <para> keyGenerator is a python function that generates new session keys. </para> 
    132           </section> 
    133         </listitem> 
    13439      </itemizedlist> 
    135       <example> 
    136         <title>Session Configuration</title> 
    137         <para> </para> 
    138         <programlisting> 
    139           class MyBBS: 
    140               # create a session named &apos;admin&apos; using the SessionStorageClass 
    141               def __init__(self): 
    142                   cherrypy.config.update({ 
    143                                       &apos;global&apos;    : { &apos;sessionFilter.on&apos; : True }, 
    144                                       &apos;/site/bbs&apos; : { 
    145                                                       &apos;sessionFilter.sessionsList&apos;    : [&apos;bbs&apos;], 
    146                                                       &apos;sessionFilter.bbs.storageType&apos; : &apos;ram&apos;, 
    147                                                       &apos;sessionFilter.bbs.timeout&apos;     : 25 
    148                                                     } 
    149                                    }) 
    150               def admin(self): 
    151                   if cherrypy.session.admin[&apos;user&apos;] != "root": 
    152                   return "you are not root" 
    153               admin.exposed = True 
    154         </programlisting> 
    155       </example> 
    156     </section> 
    157     <!-- end sessionconfiguration --> 
    158   </section> 
    159   <section id="sessionstoragetypes"> 
    160     <title>Session Storage Types</title> 
    161     <para>CherryPy includes several session storage backends: ram, file, anydb, sqlobject</para> 
    162     <section> 
    163       <title>ram storage</title> 
    164       <para> The ram adaptor stores all session data in memory. It is the only storage adaptor 
    165         capable of holding any Python object, including those that are not-picklable, such as file 
    166         handles, sockets, and running generators. When using ream sessions, keep in mind that all 
    167         session data is lost when the server shuts down, even during auto-reloads. </para> 
    168       <para> The ram adaptor has no additional configuration options. </para> 
    169     </section> 
    170     <!-- end ram storage section --> 
    171     <section> 
    172       <title>file storage</title> 
    173       <para> The file storage adaptor pickles the data for each session and stores it in separate 
    174         files. Cleaning up expired sessions is a slow operation, because it requires unpickling 
    175         every session file. </para> 
    176       <itemizedlist> 
    177         <listitem>Additional Configuration Options  
    178             <itemizedlist> 
    179             <listitem>storagePath : The path to the directory where the session files will be 
    180                 stored. The default value is ".sessiondata"  
    181             </listitem> 
    182           </itemizedlist> 
    183         </listitem> 
    184       </itemizedlist> 
    185     </section> 
    186     <!-- end file storage section --> 
    187     <section> 
    188       <title>anydb storage</title> 
    189       <para> The anydb storage adaptor stores session data using the shelve module, which in turn 
    190         uses the anydb module. The andyb adaptor can only be used to store picklable objects. </para> 
    191       <itemizedlist> 
    192         <listitem>Additional Configuration Options 
    193           <itemizedlist> 
    194           <listitem>storagePath : The path to the directory where the database files will be stored. By default, 
    195               the filter will create a file based on the session name. 
    196           </listitem> 
    197           <listitem>dbFile : An absolute path pointing to the database file to use with the session.  
    198           </listitem> 
    199           </itemizedlist> 
    200         </listitem> 
    201       </itemizedlist> 
    202     </section> 
    203     <!-- end anydb storage section --> 
    204     <section> 
    205       <title>Relational Storage</title> 
    206       <para> With relational database adaptors, all data is stored in a relational database table. 
    207         Due to the nature of relational databases, there are several restrictions on how data can be 
    208         stored. Each session is stored as a single row in the session table. The session table must 
    209         be created with a column for each variable needed by the application. This makes it 
    210         impossible to store arbitrary key/value pairs, as can be done using several of the other 
    211         storage adaptors. In addition, relational databases also place restrictions on the type of 
    212         data that can be stored in each column. Attempting to store the wrong type of data in a 
    213         session variable will result in an error. </para> 
    214       <para> Despite these restrictions, storing session data in relational database has many 
    215         advantages. This approach allows session data to be integrated into an existing relational 
    216         database, which dynamic web applications often use anyway. This approach allows for a level 
    217         of scalability not possible with other storage adaptors. In addition, by using a networked 
    218         database server, session data can be easily shared between a cluster of web servers. </para> 
    219       <section> 
    220         <title>sqlobject storage</title> 
    221         <para> The sqlobject adaptors can be used with any database supported by sqlobject. </para> 
    222       </section> 
    223       <!-- end sqlobject storage section --> 
    224       <section> 
    225         <title>pydo storage</title> 
    226         <para> A PyDO2 adaptor will be included in the future. </para> 
    227       </section> 
    228     </section> 
    229     <!-- end relational storage section --> 
    230   </section> 
    231   <!-- end sessionstoragetyps section --> 
    232   <section id="customsessionstorage"> 
    233     <title>Writing Custom Session Storage Drivers</title> 
    234     <section> 
    235       <title>BaseSessionDict</title> 
    236       <para> BaseSessionDict is the base class for the dictionary-like class used to access session 
    237         data. SessionDicts implement the most frequently used features of Python dictionaries. DO 
    238         NOT add new features to a custom SessionDict class, as it could break compatibility with 
    239         other storage adaptor. Sometimes it is not necessary to write a custom SessionDict class 
    240         because the sessionFilter includes a SimpleSessionDict. The SimpleSessionDict is used by 
    241         several storage adaptor and may be adequate for a custom storage adaptor. </para> 
    242     </section> 
    243     <section> 
    244       <title>BaseAdaptor</title> 
    245       <para> BaseSession is the base class for all session storage adaptor. There are a number of 
    246         methods that must be implemented by every storage adaptor. </para> 
    247     </section> 
    248   </section> 
    24940</section> 
  • trunk/docs/book/xml/templateindependant.xml

    r512 r608  
    1111    <para>CherryPy has been reported to be working with all the main templating systems:</para> 
    1212    <itemizedlist> 
    13         <listitem>Cheetah</listitem> 
    14         <listitem>XSLT</listitem> 
    15         <listitem>CherryTemplate</listitem> 
    16         <listitem>HTMLTemplate</listitem> 
    17         <listitem>Kid</listitem> 
    18         <listitem>Zope Page Template</listitem> 
     13        <listitem> 
     14            <ulink url="http://www.cheetahtemplate.org">Cheetah</ulink> 
     15        </listitem> 
     16        <listitem> 
     17            <ulink url="http://www.w3.org/TR/xslt"> 
     18                XSLT 
     19            </ulink> 
     20            </listitem> 
     21        <listitem> 
     22            <ulink url="http://cherrytemplate.python-hosting.com/"> 
     23                CherryTemplate 
     24            </ulink> 
     25        </listitem> 
     26        <listitem> 
     27            <ulink url="http://freespace.virgin.net/hamish.sanderson/htmltemplate.html"> 
     28                HTMLTemplate 
     29            </ulink> 
     30        </listitem> 
     31        <listitem> 
     32            <ulink url="http://lesscode.org/projects/kid"> 
     33                Kid 
     34            </ulink> 
     35        </listitem> 
     36        <listitem> 
     37            <ulink url="http://www.zope.org/DevHome/Wikis/DevSite/Projects/ZPT/FrontPage"> 
     38                Zope Page Template 
     39            </ulink> 
     40        </listitem> 
    1941    </itemizedlist> 
    2042    <para>You will find recipes on how to use them on the CherryPy website.</para> 

Hosted by WebFaction

Log in as guest/cpguest to create tickets