Beispiel #1
0
    def do_GET(self):
        m = re.fullmatch(r"/chinook/customer", self.path)
        if m:
            data = customer_list()
        else:
            m = re.fullmatch(r'/chinook/invoice/customer/(\d+)', self.path)
            if m:
                cust_id = int(m.group(1))
                data = invoices_for_customer(cust_id)
            else:
                m = re.fullmatch(r"/chinook/invoice-item/invoice/(\d+)", self.path)
                if m:
                    inv_id = int(m.group(1))
                    data = items_for_invoice(inv_id)
                else:
                    m = re.fullmatch("/chinook/invoice-item/invoice/customer", self.path)
                    if m:
                        data = items_invoices_customers()
                    else:
                        data = None

        if data:
            self.send_response(200)
            self.send_header("content-type", "text/html")
            self.end_headers()
            edat = dumps(data)
            logging.debug(edat)
            self.wfile.write(edat.encode("utf-8"))
        else:
            self.send_response(404)
            self.send_header("content-type", "text/html")
            self.end_headers()
            self.wfile.write("invalid path: {}".format(self.path).encode("utf-8"))
Beispiel #2
0
    def do_GET(self):
        pass
        # decide which path is being used
        # self.path is the path from the request

        m = re.fullmatch("/chinook/customer", self.path)

        if m:
            # matches the first regex
            data = chinook_services.customer_list()
        else:
            # did not match
            m = re.fullmatch(r"/chinook/invoice/customer/(\d+)", self.path)
            if m:
                cust_id = int(m.group(1))
                data = chinook_services.invoices_for_customer(cust_id)
            else:
                m = re.fullmatch(r"/chinook/invoice-item/invoice/(\d+)",
                                 self.path)
                if m:
                    invoice_id = int(m.group(1))
                    data = chinook_services.items_for_invoice(invoice_id)
                else:
                    m = re.fullmatch(r"/chinook/items/invoices/customers",
                                     self.path)
                    data = chinook_services.items_invoices_customers()
                    if m:
                        pass
                    else:
                        data = None

        # send appropriate response back

        if data:
            # path matched, good response
            self.send_response(200)
            self.send_header("content-type", "application/json")
            self.end_headers()
            jdata = json_with_dates.dumps(data)
            self.wfile.write(jdata.encode("UTF-8"))
        else:
            # path did not match
            self.send_response(404)
            self.send_header("content-type", "text/html")
            self.end_headers()
            self.wfile.write("invalid path: {}".format(
                self.path).encode("utf-8"))
def items(customer_id):
    response.content_type = "application/json"
    data = invoice_items_for_customer(customer_id)
    return dumps(data)
def customers():
    response.content_type = "application/json"
    data = customer_list()
    return dumps(data)
def items_invoices_customers_all():
    response.content_type = "application/json"
    data = items_invoices_customers()
    return dumps(data)