Beispiel #1
0
    def do_POST(self):
        """ Posts to the server
        """
        parsed_path = urlparse(self.path)
        parsed_qs = parse_qs(parsed_path.query)

        if parsed_path.path == '/cow':
            try:
                parsed_message = parsed_qs['msg'][0]
                bunny = cow.Bunny()
                msg = bunny.milk(parsed_message)
                json_message = json.dumps({'content': msg})
                self.send_response(200)
                self.send_header('Content-Type', 'application/json')
                self.end_headers()
                self.wfile.write(json_message.encode())
                return

            except KeyError:
                self.send_response(400)
                self.end_headers()
                dragon = cow.DragonAndCow()
                msg = dragon.milk('400 Bad Request')
                self.wfile.write(msg.encode())
        else:
            self.send_response(404)
            self.end_headers()
            dragon = cow.DragonAndCow()
            msg = dragon.milk('404 Not Found')
            self.wfile.write(msg.encode())
Beispiel #2
0
    def do_GET(self):
        """ sets a status code, sets headers, sets body, and ends headers
        """
        raw_html = dedent('''
        <html>
        <head>
            <title> cowsay </title>
        </head>
        <body>
            <header>
                <nav>
                <ul>
                    <li><a href="/cow">cowsay</a></li>
                </ul>
                </nav>
            <header>
            <main>
                <!-- project description defining how users can further interact with the application -->
            </main>
        </body>
        </html>''')
        parsed_path = urlparse(self.path)
        parsed_qs = parse_qs(parsed_path.query)

        if parsed_path.path == '/':
            self.send_response(200)
            self.send_header('Content-Type', 'text/html')
            self.end_headers()
            self.wfile.write(raw_html.encode())
            return

        elif parsed_path.path == '/cow':
            try:
                parsed_message = parsed_qs['msg'][0]
                bunny = cow.Bunny()
                msg = bunny.milk(parsed_message)
                self.send_response(200)
                self.send_header('Content-Type', 'text/html')
                self.end_headers()
                self.wfile.write(msg.encode())
                return

            except KeyError:
                self.send_response(400)
                self.end_headers()
                dragon = cow.DragonAndCow()
                msg = dragon.milk('400 Bad Request')
                self.wfile.write(msg.encode())
        else:
            self.send_response(404)
            self.end_headers()
            dragon = cow.DragonAndCow()
            msg = dragon.milk('404 Not Found')
            self.wfile.write(msg.encode())

        self.send_response(404)
        self.end_headers()
Beispiel #3
0
    "?": "..--..",
    "'": ".----.",
    "-": "-....-",
    "/": "-..-.",
    "@": ".--.-.",
    "=": "-...-",
    " ": "/"
}

decode_morse = dict(
    (morse_char, char) for (char, morse_char) in encode_morse.items())

cowList = {
    "cow": cow.Cowacter(),
    "hellokitty": cow.HelloKitty(),
    "bunny": cow.Bunny(),
    "cheese": cow.Cheese(),
    "milk": cow.Milk(),
    "bong": cow.BongCow(),
    "eyes": cow.Eyes(),
    "legitvore": cow.HeadInCow(),
    "666": cow.Satanic(),
    "frogs": cow.BudFrogs(),
    "daemon": cow.Daemon(),
    "moofasa": cow.Moofasa(),
    "mutilated": cow.Mutilated(),
    "skeleton": cow.Skeleton(),
    "small": cow.Small(),
    "sodomized": cow.Sodomized(),
    "garfield": cow.Stimpy(),
    "tux": cow.Tux(),