#!/usr/bin/env python # pythfilter.py v1.5.5, written by Matthias Baas (baas@ira.uka.de) # Doxygen filter which can be used to document Python source code. # Classes (incl. methods) and functions can be documented. # Every comment that begins with ## is literally turned into an # Doxygen comment. Consecutive comment lines are turned into # comment blocks (-> /** ... */). # All the stuff is put inside a namespace with the same name as # the source file. # Conversions: # ============ # ##-blocks -> /** ... */ # "class name(base): ..." -> "class name : public base {...}" # "def name(params): ..." -> "name(params) {...}" # Changelog: # 21.01.2003: Raw (r"") or unicode (u"") doc string will now be properly # handled. (thanks to Richard Laager for the patch) # 22.12.2003: Fixed a bug where no function names would be output for "def" # blocks that were not in a class. # (thanks to Richard Laager for the patch) # 12.12.2003: Implemented code to handle static and class methods with # this logic: Methods with "self" as the first argument are # non-static. Methods with "cls" are Python class methods, # which translate into static methods for Doxygen. Other # methods are assumed to be static methods. As should be # obvious, this logic doesn't take into account if the method # is actually setup as a classmethod() or a staticmethod(), # just if it follows the normal conventions. # (thanks to Richard Laager for the patch) # 11.12.2003: Corrected #includes to use os.path.sep instead of ".". Corrected # namespace code to use "::" instead of ".". # (thanks to Richard Laager for the patch) # 11.12.2003: Methods beginning with two underscores that end with # something other than two underscores are considered private # and are handled accordingly. # (thanks to Richard Laager for the patch) # 03.12.2003: The first parameter of class methods (self) is removed from # the documentation. # 03.11.2003: The module docstring will be used as namespace documentation # (thanks to Joe Bronkema for the patch) # 08.07.2003: Namespaces get a default documentation so that the namespace # and its contents will show up in the generated documentation. # 05.02.2003: Directories will be delted during synchronization. # 31.01.2003: -f option & filtering entire directory trees. # 10.08.2002: In base classes the '.' will be replaced by '::' # 18.07.2002: * and ** will be translated into arguments # 18.07.2002: Argument lists may contain default values using constructors. # 18.06.2002: Support for ## public: # 21.01.2002: from ... import will be translated to "using namespace ...;" # TODO: "from ... import *" vs "from ... import names" # TODO: Using normal imports: name.name -> name::name # 20.01.2002: #includes will be placed in front of the namespace ###################################################################### # The program is written as a state machine with the following states: # # - OUTSIDE The current position is outside any comment, # class definition or function. # # - BUILD_COMMENT Begins with first "##". # Ends with the first token that is no "##" # at the same column as before. # # - BUILD_CLASS_DECL Begins with "class". # Ends with ":" # - BUILD_CLASS_BODY Begins just after BUILD_CLASS_DECL. # The first following token (which is no comment) # determines indentation depth. # Ends with a token that has a smaller indendation. # # - BUILD_DEF_DECL Begins with "def". # Ends with ":". # - BUILD_DEF_BODY Begins just after BUILD_DEF_DECL. # The first following token (which is no comment) # determines indentation depth. # Ends with a token that has a smaller indendation. import getopt import glob import os.path import re import shutil import string import sys import token import tokenize from stat import * OUTSIDE = 0 BUILD_COMMENT = 1 BUILD_CLASS_DECL = 2 BUILD_CLASS_BODY = 3 BUILD_DEF_DECL = 4 BUILD_DEF_BODY = 5 IMPORT = 6 IMPORT_OP = 7 IMPORT_APPEND = 8 # Output file st
<div class="highlight"><pre><span class="kn">import</span> <span class="nn">requests</span>
<span class="kn">from</span> <span class="nn">libpathod</span> <span class="kn">import</span> <span class="n">test</span>


<span class="k">class</span> <span class="nc">Test</span><span class="p">:</span>

    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Testing the requests module with</span>
<span class="sd">        a pathod instance started for</span>
<span class="sd">        each test.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">setUp</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">d</span> <span class="o">=</span> <span class="n">test</span><span class="o">.</span><span class="n">Daemon</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">tearDown</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">d</span><span class="o">.</span><span class="n">shutdown</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">test_simple</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="c"># Get a URL for a pathod spec</span>
        <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">d</span><span class="o">.</span><span class="n">p</span><span class="p">(</span><span class="s">&quot;200:b@100&quot;</span><span class="p">)</span>
        <span class="c"># ... and request it</span>
        <span class="n">r</span> <span class="o">=</span> <span class="n">requests</span><span class="o">.</span><span class="n">put</span><span class="p">(</span><span class="n">url</span><span class="p">)</span>

        <span class="c"># Check the returned data</span>
        <span class="k">assert</span> <span class="n">r</span><span class="o">.</span><span class="n">status_code</span> <span class="o">==</span> <span class="mi">200</span>
        <span class="k">assert</span> <span class="nb">len</span><span class="p">(</span><span class="n">r</span><span class="o">.</span><span class="n">content</span><span class="p">)</span> <span class="o">==</span> <span class="mi">100</span>

        <span class="c"># Check pathod&#39;s internal log</span>
        <span class="n">log</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">d</span><span class="o">.</span><span class="n">last_log</span><span class="p">()[</span><span class="s">&quot;request&quot;</span><span class="p">]</span>
        <span class="k">assert</span> <span class="n">log</span><span class="p">[</span><span class="s">&quot;method&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;PUT&quot;</span>
</pre></div>