# Path: scrypture/webapi.py
# class WebAPI(flask_wtf.Form):
# class PassHTTPAuthorizationHeader(requests.auth.AuthBase):
# def text_input(*args, **kwargs):
# def list_input(*args, **kwargs):
# def line_input(*args, **kwargs):
# def password_input(*args, **kwargs):
# def radio_field(*args, **kwargs):
# def submit_button(*args, **kwargs):
# def multiple_input(*args, **kwargs):
# def checkbox_field(*args, **kwargs):
# def file_field(*args, **kwargs):
#     def __init__(self, header):
#     def __call__(self, r):


import argparse
import sys
import re
import csv
import json
import StringIO
from scrypture import webapi
    headers = set()
    for json_row in json_input:
        headers.update(json_row.keys())

    csv_io = StringIO.StringIO()
    csv_out = csv.DictWriter(csv_io,headers)
    csv_out.writeheader()
    for json_row in json_input:
        csv_out.writerow(json_row)
    csv_io.seek(0)
    return csv_io.read()

### CLI ###

def main():
    """"This main function implements the CLI"""
    parser = argparse.ArgumentParser(description='Do something awesome')
    parser.add_argument('input_file', nargs=1,
                        type=argparse.FileType('r'))
    parser.add_argument('-o', '--outfile', nargs='?',
                        type=argparse.FileType('w'), default=sys.stdout)
    args = parser.parse_args()

    print(json_to_csv(args.input_file[0].read()), file=args.outfile)

if __name__ == '__main__':
    main()

### WebAPI ###


# Path: scrypture/webapi.py
# class WebAPI(flask_wtf.Form):
# class PassHTTPAuthorizationHeader(requests.auth.AuthBase):
# def text_input(*args, **kwargs):
# def list_input(*args, **kwargs):
# def line_input(*args, **kwargs):
# def password_input(*args, **kwargs):
# def radio_field(*args, **kwargs):
# def submit_button(*args, **kwargs):
# def multiple_input(*args, **kwargs):
# def checkbox_field(*args, **kwargs):
# def file_field(*args, **kwargs):
#     def __init__(self, header):
#     def __call__(self, r):


# Path: scrypture/demo_scripts/Utils/json_to_csv.py
import argparse
import sys
import re
import csv
import json
import StringIO
from scrypture import webapi

    headers = set()
    for json_row in json_input:
        headers.update(json_row.keys())

    csv_io = StringIO.StringIO()
    csv_out = csv.DictWriter(csv_io,headers)
    csv_out.writeheader()
    for json_row in json_input:
        csv_out.writerow(json_row)
    csv_io.seek(0)
    return csv_io.read()

### CLI ###

def main():
    """"This main function implements the CLI"""
    parser = argparse.ArgumentParser(description='Do something awesome')
    parser.add_argument('input_file', nargs=1,
                        type=argparse.FileType('r'))
    parser.add_argument('-o', '--outfile', nargs='?',
                        type=argparse.FileType('w'), default=sys.stdout)
    args = parser.parse_args()

    print(json_to_csv(args.input_file[0].read()), file=args.outfile)

if __name__ == '__main__':
    main()

### WebAPI ###


class WebAPI(webapi.WebAPI):