testing/web-platform/tests/resource-timing/resources/gzip_xml.py
author Valentin Gosu <valentin.gosu@gmail.com>
Wed, 15 Feb 2017 20:03:41 +0100
changeset 343119 c3a4bae5fc8db328f9f8559a65b28c235743bc10
parent 343118 e776663ecbb4df20c2ed612cbaf5d5e2808ab6bb
child 343121 fe960e54cc30c906643e94b2ff0a64cb51df74c6
permissions -rw-r--r--
Bug 919391 - (fix) Use os.path.join instead a=testonly MozReview-Commit-ID: 4YMGhQtzf3c

import gzip as gzip_module
from cStringIO import StringIO
import os

def main(request, response):
    dir_path = os.path.dirname(os.path.realpath(__file__))
    file_path = os.path.join(dir_path, 'resource_timing_test0.xml')
    f = open(file_path, 'r')
    output = f.read()

    out = StringIO()
    with gzip_module.GzipFile(fileobj=out, mode="w") as f:
      f.write(output)
    output = out.getvalue()

    headers = [("Content-type", "text/plain"),
               ("Content-Encoding", "gzip"),
               ("Content-Length", len(output))]

    return headers, output