You are viewing a plain text version of this content. The canonical link for it is here.
Posted to mod_python-commits@quetz.apache.org by gr...@apache.org on 2003/07/11 03:37:39 UTC

cvs commit: httpd-python/Doc modpython2.tex modpython3.tex modpython4.tex modpython5.tex

grisha      2003/07/10 18:37:39

  Modified:    Doc      modpython2.tex modpython3.tex modpython4.tex
                        modpython5.tex
  Log:
  Fixed the formatting of Python examples which got messed up after last
  reformat of documents. Also added a note about req.user's dependence on
  get_basic_auth_pw().
  
  Revision  Changes    Path
  1.15      +6 -6      httpd-python/Doc/modpython2.tex
  
  Index: modpython2.tex
  ===================================================================
  RCS file: /home/cvs/httpd-python/Doc/modpython2.tex,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- modpython2.tex	30 Jun 2003 19:52:55 -0000	1.14
  +++ modpython2.tex	11 Jul 2003 01:37:39 -0000	1.15
  @@ -200,9 +200,9 @@
   
     \begin{verbatim}
       <Directory /some/directory/htdocs/test> 
  -    AddHandler python-program .py
  -    PythonHandler mptest 
  -    PythonDebug On 
  +        AddHandler python-program .py
  +	PythonHandler mptest 
  +	PythonDebug On 
       </Directory>
     \end{verbatim}
   
  @@ -223,8 +223,8 @@
       from mod_python import apache
   
       def handler(req):
  -    req.write("Hello World!")
  -    return apache.OK 
  +        req.write("Hello World!")
  +	return apache.OK 
     \end{verbatim}
   
   \item
  @@ -250,7 +250,7 @@
   
   \item Try running Apache from the command line in single process mode:
     \begin{verbatim}
  -    ./httpd -DONE_PROCESS
  +    ./httpd -X
     \end{verbatim}
     This prevents it from backgrounding itself and may provide some useful
     information.
  
  
  
  1.15      +78 -78    httpd-python/Doc/modpython3.tex
  
  Index: modpython3.tex
  ===================================================================
  RCS file: /home/cvs/httpd-python/Doc/modpython3.tex,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- modpython3.tex	30 Jun 2003 19:52:56 -0000	1.14
  +++ modpython3.tex	11 Jul 2003 01:37:39 -0000	1.15
  @@ -41,14 +41,14 @@
   
   \begin{verbatim}
     <html>
  -  Please provide feedback below:
  +      Please provide feedback below:
     <p>                           
     <form action="form.py/email" method="POST">
   
  -  Name: <input type="text" name="name"><br>
  -  Email: <input type="text" name="email"><br>
  -  Comment: <textarea name="comment" rows=4 cols=20></textarea><br>
  -  <input type="submit">
  +      Name:    <input type="text" name="name"><br>
  +      Email:   <input type="text" name="email"><br>
  +      Comment: <textarea name="comment" rows=4 cols=20></textarea><br>
  +      <input type="submit">
   
     </form>
     </html>  
  @@ -59,51 +59,50 @@
   \filenq{form.py}, like this:
   
   \begin{verbatim}
  -  import smtplib
  +import smtplib
   
  -  WEBMASTER = "webmaster"   # webmaster e-mail
  -  SMTP_SERVER = "localhost" # your SMTP server
  +WEBMASTER = "webmaster"   # webmaster e-mail
  +SMTP_SERVER = "localhost" # your SMTP server
   
  -  def email(req, name, email, comment):
  +def email(req, name, email, comment):
   
  -  # make sure the user provided all the parameters
  -  if not (name and email and comment):
  -  return "A required parameter is missing, \
  -  please go back and correct the error"
  +    # make sure the user provided all the parameters
  +    if not (name and email and comment):
  +        return "A required parameter is missing, \
  +	       please go back and correct the error"
   
  -  # create the message text
  -  msg = """\
  -  From: %s                                                                                                                                           
  -  Subject: feedback
  -  To: %s
  +    # create the message text
  +    msg = """\
  +From: %s                                                                                                                                           
  +Subject: feedback
  +To: %s
   
  -  I have the following comment:
  +I have the following comment:
   
  -  %s
  +%s
   
  -  Thank You,
  +Thank You,
   
  -  %s                                                                                                                                                 
  +%s
   
  -  """ % (email, WEBMASTER, comment, name)
  +""" % (email, WEBMASTER, comment, name)
   
  -  # send it out
  -  conn = smtplib.SMTP(SMTP_SERVER)
  -  conn.sendmail(email, [WEBMASTER], msg)
  -  conn.quit()
  +    # send it out
  +    conn = smtplib.SMTP(SMTP_SERVER)
  +    conn.sendmail(email, [WEBMASTER], msg)
  +    conn.quit()
   
  -  # provide feedback to the user
  -  s = """\
  -  <html>
  +    # provide feedback to the user
  +    s = """\
  +<html>
   
  -  Dear %s,<br>                                                                                                                                       
  +Dear %s,<br>                                                                                                                                       
  +Thank You for your kind comments, we
  +will get back to you shortly.
   
  -  Thank You for your kind comments, we
  -  will get back to you shortly.
  +</html>""" % name
   
  -  </html>""" % name
  -
  -  return s
  +    return s
   \end{verbatim}
   
   When the user clicks the Submit button, the publisher handler will
  @@ -174,9 +173,9 @@
   Let's pretend we have the following configuration: 
   \begin{verbatim}
     <Directory /mywebdir>
  -  AddHandler python-program .py
  -  PythonHandler myscript
  -  PythonDebug On
  +      AddHandler python-program .py
  +      PythonHandler myscript
  +      PythonDebug On
     </Directory>
   \end{verbatim}
   
  @@ -187,14 +186,14 @@
   this:
   
   \begin{verbatim}
  -  from mod_python import apache
  +from mod_python import apache
   
  -  def handler(req):
  +def handler(req):
   
  -  req.content_type = "text/plain"
  -  req.write("Hello World!")
  +    req.content_type = "text/plain"
  +    req.write("Hello World!")
   
  -  return apache.OK
  +    return apache.OK
   \end{verbatim}    
   
   Here is what's going to happen: The \code{AddHandler} directive tells
  @@ -243,7 +242,7 @@
   
     \item
       \begin{verbatim}
  -      from mod_python import apache
  +from mod_python import apache
       \end{verbatim}
   
       This imports the apache module which provides us the interface to
  @@ -252,7 +251,7 @@
   
     \item
       \begin{verbatim}
  -      def handler(req):
  +def handler(req):
       \end{verbatim}
   
       \index{handler} This is our \dfn{handler} function declaration. It
  @@ -273,7 +272,7 @@
   
     \item
       \begin{verbatim}
  -      req.content_type = "text/plain"
  +req.content_type = "text/plain"
       \end{verbatim}
   
       This sets the content type to \samp{text/plain}. The default is usually
  @@ -282,7 +281,7 @@
   
     \item
       \begin{verbatim}
  -      req.write("Hello World!")
  +req.write("Hello World!")
       \end{verbatim}
   
       This writes the \samp{Hello World!} string to the client. (Did I really
  @@ -290,7 +289,7 @@
   
     \item
       \begin{verbatim}
  -      return apache.OK
  +return apache.OK
       \end{verbatim}
   
       This tells Apache that everything went OK and that the request has
  @@ -330,10 +329,10 @@
   
   \begin{verbatim}
     <Directory /mywebdir>
  -  AddHandler python-program .py
  -  PythonHandler myscript
  -  PythonAuthenHandler myscript
  -  PythonDebug On
  +      AddHandler python-program .py
  +      PythonHandler myscript
  +      PythonAuthenHandler myscript
  +      PythonDebug On
     </Directory>
   \end{verbatim}
   
  @@ -348,13 +347,13 @@
   
   \begin{verbatim}
     <Directory /mywebdir>
  -  AddHandler python-program .py
  -  PythonHandler myscript
  -  PythonAuthenHandler myscript
  -  PythonDebug On
  -  AuthType Basic
  -  AuthName "Restricted Area"
  -  require valid-user
  +     AddHandler python-program .py
  +     PythonHandler myscript
  +     PythonAuthenHandler myscript
  +     PythonDebug On
  +     AuthType Basic
  +     AuthName "Restricted Area"
  +     require valid-user
     </Directory>
   \end{verbatim}          
   
  @@ -364,17 +363,17 @@
   
   \begin{verbatim}
   
  -  from mod_python import apache
  +from mod_python import apache
   
  -  def authenhandler(req):
  +def authenhandler(req):
   
  -  user = req.user
  -  pw = req.get_basic_auth_pw()
  +    pw = req.get_basic_auth_pw()
  +    user = req.user
   
  -  if user == "spam" and pw == "eggs":
  -  return apache.OK
  -  else:
  -  return apache.HTTP_UNAUTHORIZED
  +    if user == "spam" and pw == "eggs":
  +       return apache.OK
  +    else:
  +       return apache.HTTP_UNAUTHORIZED
   \end{verbatim}  
   
   Let's look at this line by line: 
  @@ -383,7 +382,7 @@
   
   \item
     \begin{verbatim}
  -    def authenhandler(req):
  +def authenhandler(req):
     \end{verbatim}
   
     This is the handler function declaration. This one is called
  @@ -394,25 +393,26 @@
   
   \item
     \begin{verbatim}
  -    user = req.user
  +    pw = req.get_basic_auth_pw()
     \end{verbatim}
     
  -  This is how you obtain the username that the user entered. 
  +  This is how we obtain the password. The basic HTTP authentication
  +  transmits the password in base64 encoded form to make it a little
  +  bit less obvious. This function decodes the password and returns it
  +  as a string. Note that we have to call this function before obtaining
  +  the user name.
   
   \item
     \begin{verbatim}
  -    pw = req.get_basic_auth_pw()
  +    user = req.user
     \end{verbatim}
     
  -  This is how we obtain the password. The basic HTTP authentication
  -  transmits the password in base64 encoded form to make it a little
  -  bit less obvious. This function decodes the password and returns it
  -  as a string.
  +  This is how you obtain the username that the user entered. 
   
   \item
     \begin{verbatim}
       if user == "spam" and pw == "eggs":
  -    return apache.OK
  +        return apache.OK
     \end{verbatim}
   
     We compare the values provided by the user, and if they are what we
  @@ -424,7 +424,7 @@
   \item
     \begin{verbatim}
       else:
  -    return apache.HTTP_UNAUTHORIZED 
  +        return apache.HTTP_UNAUTHORIZED 
     \end{verbatim}
   
     Else, we tell Apache to return \constant{HTTP_UNAUTHORIZED} to the
  
  
  
  1.37      +34 -31    httpd-python/Doc/modpython4.tex
  
  Index: modpython4.tex
  ===================================================================
  RCS file: /home/cvs/httpd-python/Doc/modpython4.tex,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- modpython4.tex	3 Jul 2003 14:13:36 -0000	1.36
  +++ modpython4.tex	11 Jul 2003 01:37:39 -0000	1.37
  @@ -144,7 +144,7 @@
   e.g.
   
   \begin{verbatim}
  -  raise apache.SERVER_RETURN, apache.HTTP_FORBIDDEN
  +raise apache.SERVER_RETURN, apache.HTTP_FORBIDDEN
   \end{verbatim}
   
   Handlers can send content to the client using the \method{req.write()}
  @@ -163,12 +163,12 @@
   An example of a minimalistic handler might be: 
   
   \begin{verbatim}
  -  from mod_python import apache
  +from mod_python import apache
   
  -  def requesthandler(req):
  -  req.content_type = "text/plain"
  -  req.write("Hello World!")
  -  return apache.OK
  +def requesthandler(req):
  +    req.content_type = "text/plain"
  +    req.write("Hello World!")
  +    return apache.OK
   \end{verbatim}
   
   \section{Overview of a Filter Handler\label{pyapi-filter}}
  @@ -212,17 +212,17 @@
   like:
   
   \begin{verbatim}
  -  from mod_python import apache
  -
  -  def outputfilter(filter):
  +from mod_python import apache
  +  
  +def outputfilter(filter):
   
  -  s = filter.read()
  -  while s:
  -  filter.write(s.upper())
  -  s = filter.read()
  +    s = filter.read()
  +    while s:
  +        filter.write(s.upper())
  +	s = filter.read()
   
  -  if s is None:
  -  filter.close()
  +    if s is None:
  +        filter.close()
   
   \end{verbatim}
   
  @@ -265,14 +265,14 @@
   Contents of \filenq{echo.py} file:
   
   \begin{verbatim}
  -  from mod_python import apache
  +from mod_python import apache
   
  -  def connectionhandler(conn):
  +def connectionhandler(conn):
   
  -  while 1:
  -  conn.write(conn.readline())
  +    while 1:
  +        conn.write(conn.readline())
   
  -  return apache.OK
  +    return apache.OK
   \end{verbatim}
   
   \section{\module{apache} -- Access to Apache Internals.}
  @@ -296,7 +296,7 @@
   It is best imported like this:
   
   \begin{verbatim}
  -  from mod_python import apache
  +from mod_python import apache
   \end{verbatim}
   
   \module{mod_python.apache} module defines the following functions and
  @@ -470,9 +470,9 @@
     like:
   
     \begin{verbatim}
  -    if manager:
  +if manager:
       req.add_handler("PythonHandler", "menu::admin")
  -    else:
  +else:
       req.add_handler("PythonHandler", "menu::basic")
     \end{verbatim}                              
   
  @@ -905,6 +905,9 @@
     If an authentication check is made, this will hold the user
     name. Same as CGI \envvar{REMOTE_USER}.
     \emph{(Read-Only})
  +  \begin{notice}
  +    \method{req.get_basic_auth_pw()} must be called prior to using this value.
  +  \end{notice}
   \end{memberdesc}
   
   \begin{memberdesc}[request]{ap_auth_type}
  @@ -960,7 +963,7 @@
     constants that should be used to access elements of this
     tuple. Example:
     \begin{verbatim}
  -    fname = req.finfo[apache.FINFO_FNAME]
  +fname = req.finfo[apache.FINFO_FNAME]
     \end{verbatim}
     \emph{(Read-Only})
   \end{memberdesc}
  @@ -971,7 +974,7 @@
     The \code{apache} module defines a set of \constant{URI_*} constants that
     should be used to access elements of this tuple. Example:
     \begin{verbatim}
  -    fname = req.parsed_uri[apache.URI_PATH]
  +fname = req.parsed_uri[apache.URI_PATH]
     \end{verbatim}
     \emph{(Read-Only})
   \end{memberdesc}
  @@ -1289,7 +1292,7 @@
   
   The recommended way of using this module is:
   \begin{verbatim}
  -  from mod_python import util
  +from mod_python import util
   \end{verbatim}
   
   \begin{seealso}
  @@ -1550,8 +1553,8 @@
   
       Here is an example of getting a single \class{Cookie} instance:
       \begin{verbatim}
  -      mycookies = Cookie.parse("spam=eggs; expires=Sat, 14-Jun-2003 02:42:36 GMT")
  -      spamcookie = mycookies["spam"]
  +mycookies = Cookie.parse("spam=eggs; expires=Sat, 14-Jun-2003 02:42:36 GMT")
  +spamcookie = mycookies["spam"]
       \end{verbatim}
   
       \begin{notice}
  @@ -1736,7 +1739,7 @@
     <html>
     <%
     for n in range(3):
  -  # This indent will persist
  +      # This indent will persist
     %>
     <p>This paragraph will be 
     repeated 3 times.</p>
  @@ -1753,8 +1756,8 @@
     req.write("""<html>
     """)
     for n in range(3):
  -  # This indent will persist
  -  req.write("""
  +      # This indent will persist
  +      req.write("""
     <p>This paragraph will be
     repeated 3 times.</p>
     """)
  
  
  
  1.15      +7 -7      httpd-python/Doc/modpython5.tex
  
  Index: modpython5.tex
  ===================================================================
  RCS file: /home/cvs/httpd-python/Doc/modpython5.tex,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- modpython5.tex	30 Jun 2003 19:52:57 -0000	1.14
  +++ modpython5.tex	11 Jul 2003 01:37:39 -0000	1.15
  @@ -210,14 +210,14 @@
   An example authentication handler might look like this: 
   
   \begin{verbatim}
  -  def authenhandler(req):
  +def authenhandler(req):
   
  -  pw = req.get_basic_auth_pw()
  -  user = req.connection.user     
  -  if user == "spam" and pw == "eggs":
  -  return apache.OK
  -  else:
  -  return apache.HTTP_UNAUTHORIZED
  +    pw = req.get_basic_auth_pw()
  +    user = req.connection.user     
  +    if user == "spam" and pw == "eggs":
  +        return apache.OK
  +    else:
  +        return apache.HTTP_UNAUTHORIZED
   \end{verbatim}    
   
   \begin{notice}