!C99Shell v. 2.0 [PHP 7 Update] [25.02.2019]!

Software: Apache/2.2.16 (Debian). PHP/5.3.3-7+squeeze19 

uname -a: Linux mail.tri-specialutilitydistrict.com 2.6.32-5-amd64 #1 SMP Tue May 13 16:34:35 UTC
2014 x86_64
 

uid=33(www-data) gid=33(www-data) groups=33(www-data) 

Safe-mode: OFF (not secure)

/usr/share/doc/python-twisted-web/howto/web-in-60/   drwxr-xr-x
Free 129.71 GB of 142.11 GB (91.27%)
Home    Back    Forward    UPDIR    Refresh    Search    Buffer    Encoder    Tools    Proc.    FTP brute    Sec.    SQL    PHP-code    Update    Feedback    Self remove    Logout    


Viewing file:     error-handling.html (8.33 KB)      -rw-r--r--
Select action/file-type:
(+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
Twisted Documentation: Error Handling

Error Handling

    In this example we'll extend dynamic dispatch to return a 404 (not found) response when a client requests a non-existent URL.

    As in the previous examples, we'll start with Site, Resource, and reactor imports:

    1 2 3

    from twisted.web.server import Site from twisted.web.resource import Resource from twisted.internet import reactor

    Next, we'll add one more import. NoResource is one of the pre-defined error resources provided by Twisted Web. It generates the necessary 404 response code and renders a simple html page telling the client there is no such resource.

    1

    from twisted.web.error import NoResource

    Next, we'll define a custom resource which does some dynamic URL dispatch. This example is going to be just like the previous one, where the path segment is interpreted as a year; the difference is that this time we'll handle requests which don't conform to that pattern by returning the not found response:

    1 2 3 4 5 6 7 8

    class Calendar(Resource): def getChild(self, name, request): try: year = int(name) except ValueError: return NoResource() else: return YearPage(year)

    Aside from including the definition of YearPage from the previous example, the only other thing left to do is the normal Site and reactor setup. Here's the complete code for this example:

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28

    from twisted.web.server import Site from twisted.web.resource import Resource from twisted.internet import reactor from twisted.web.error import NoResource from calendar import calendar class YearPage(Resource): def __init__(self, year): Resource.__init__(self) self.year = year def render_GET(self, request): return "<html><body><pre>%s</pre></body></html>" % (calendar(self.year),) class Calendar(Resource): def getChild(self, name, request): try: year = int(name) except ValueError: return NoResource() else: return YearPage(year) root = Calendar() factory = Site(root) reactor.listenTCP(8880, factory) reactor.run()

    This server hands out the same calendar views as the one from the previous installment, but it will also hand out a nice error page with a 404 response when a request is made for a URL which cannot be interpreted as a year.

    Index

    Version: 10.1.0

    :: Command execute ::

    Enter:
     
    Select:
     

    :: Search ::
      - regexp 

    :: Upload ::
     
    [ Read-Only ]

    :: Make Dir ::
     
    [ Read-Only ]
    :: Make File ::
     
    [ Read-Only ]

    :: Go Dir ::
     
    :: Go File ::
     

    --[ c99shell v. 2.0 [PHP 7 Update] [25.02.2019] maintained by KaizenLouie | C99Shell Github | Generation time: 0.0082 ]--