mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-07-17 16:15:47 +00:00
64d204228a
It includes the translation template files (POT) as well as translation files (PO) developer through the Transifex platform by our awesome translators. It also includes tools to generate the translation template files, generate a special translation file with the longest strigns of all translations, and a tool to download translations from Transifex into the right game folders automatically. Fixes #67 This was SVN commit r14955.
46 lines
968 B
Python
46 lines
968 B
Python
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
HTTP-related utility functions.
|
|
"""
|
|
|
|
import gzip
|
|
try:
|
|
import cStringIO as StringIO
|
|
except ImportError:
|
|
import StringIO
|
|
|
|
|
|
def _gzip_decode(gzip_data):
|
|
"""
|
|
Unzip gzipped data and return them.
|
|
|
|
:param gzip_data: Gzipped data.
|
|
:returns: The actual data.
|
|
"""
|
|
try:
|
|
gzip_data = StringIO.StringIO(gzip_data)
|
|
gzip_file = gzip.GzipFile(fileobj=gzip_data)
|
|
data = gzip_file.read()
|
|
return data
|
|
finally:
|
|
gzip_data.close()
|
|
|
|
|
|
def http_response(response):
|
|
"""
|
|
Return the response of a HTTP request.
|
|
|
|
If the response has been gzipped, gunzip it first.
|
|
|
|
:param response: The raw response of a HTTP request.
|
|
:returns: A response suitable to be used by clients.
|
|
"""
|
|
metadata = response.info()
|
|
data = response.read()
|
|
response.close()
|
|
if metadata.get('content-encoding') == 'gzip':
|
|
return _gzip_decode(data)
|
|
else:
|
|
return data
|