

def getPOSTCharset(ctx):
    'Locate the unicode encoding of the POST\'ed form data.\n\n    To work reliably you must do the following:\n\n      - set the form\'s enctype attribute to \'multipart/form-data\'\n      - set the form\'s accept-charset attribute, probably to \'utf-8\'\n      - add a hidden form field called \'_charset_\'\n\n    For instance::\n\n      <form action="foo" method="post" enctype="multipart/form-data" accept-charset="utf-8">\n        <input type="hidden" name="_charset_" />\n        ...\n      </form>\n    '
    from nevow import inevow
    request = inevow.IRequest(ctx)
    charset = request.args.get('_charset_', [None])[0]
    if charset:
        return charset
    contentType = request.received_headers.get('content-type')
    if contentType:
        charset = dict([s.strip().split('=') for s in contentType.split(';')[1:]]).get('charset')
        if charset:
            return charset
    return 'utf-8'

dataset/ETHPy150Open twisted/nevow/nevow/util.py getPOSTCharset/original