# Path: common/serialize.py
# def serialize(self, result):
#     text = ''
#     for r in result:
#         text += str(r) + ': ' + str(result[r]) + '\n'
#     return text


import sys
import json
import os
import random
    import cgi
        import traceback
from common import serialize
from get_credit import get_credit
    from flup.server.cgi import WSGIServer
    rdict = { 'format' : 'text',
              'cmd' : 'history',
              'book' : '',
              'page' : '',
              'image' : '',
              'lang' : '' }
    for name in field:
        rdict[name] = field[name].value
    rdict['book'] = split_param(rdict['book'])
    rdict['page'] = split_param(rdict['page'])
    rdict['image'] = split_param(rdict['image'])

    if rdict['lang'] in [ 'www', '' ]:
        rdict['lang'] = 'old'

    return rdict

def handle_query(params, start_response):
    # Avoid to flood log.
    if not random.randint(0, 100) % 100:
        print >> sys.stderr, params

    # FIXME: handle ill formed request (400)
    result = get_credit(domain = params['lang'],
                        family = 'wikisource',
                        books = params['book'],
                        pages = params['page'],
                        images = params['image'])

    serializer = get_serializer(params['format'])

# Path: common/serialize.py
# def serialize(self, result):
#     text = ''
#     for r in result:
#         text += str(r) + ': ' + str(result[r]) + '\n'
#     return text


# Path: history_credit/credits.py
import sys
import json
import os
import random
    import cgi
        import traceback
from common import serialize
from get_credit import get_credit
    from flup.server.cgi import WSGIServer

    rdict = { 'format' : 'text',
              'cmd' : 'history',
              'book' : '',
              'page' : '',
              'image' : '',
              'lang' : '' }
    for name in field:
        rdict[name] = field[name].value
    rdict['book'] = split_param(rdict['book'])
    rdict['page'] = split_param(rdict['page'])
    rdict['image'] = split_param(rdict['image'])

    if rdict['lang'] in [ 'www', '' ]:
        rdict['lang'] = 'old'

    return rdict

def handle_query(params, start_response):
    # Avoid to flood log.
    if not random.randint(0, 100) % 100:
        print >> sys.stderr, params

    # FIXME: handle ill formed request (400)
    result = get_credit(domain = params['lang'],
                        family = 'wikisource',
                        books = params['book'],
                        pages = params['page'],
                        images = params['image'])

    serializer = get_serializer(params['format'])

    text = serializer.serialize(result)