コード例 #1
0
ファイル: utils.py プロジェクト: tonthon/autonomie
def write_headers(request, filename, header):
    """
        Write the given headers to the current request
    """
    # Here enforce ascii chars and string object as content type
    header = force_ascii(header)
    request.response.content_type = str(header)
    request.response.headerlist.append(
            ('Content-Disposition',
             'attachment; filename="{0}"'.format(force_ascii(filename))))
    return request
コード例 #2
0
 def as_response(self, request):
     """
     Stream the file in the current request's response
     """
     request.response.content_type = self.mimetype
     request.response.headerlist.append(
         ('Content-Disposition',
          'attachment; filename={0}'.format(force_ascii(self.name))))
     request.response.write(self.datas)
     return request
コード例 #3
0
 def as_response(self, request):
     """
     Stream the file in the current request's response
     """
     request.response.content_type = self.mimetype
     request.response.headerlist.append(
         ('Content-Disposition',
          'attachment; filename={0}'.format(force_ascii(self.name))))
     request.response.write(self.datas)
     return request
コード例 #4
0
def format_lower_ascii(original_str):
    """
    Generate a lower ascii only string from the original one
    :param str original_str: The string to modify
    :returns: A modified string
    :rtype: str
    """
    result = original_str.lower()
    result = force_ascii(result)
    result = result.replace(' ', '_')
    return result
コード例 #5
0
def format_lower_ascii(original_str):
    """
    Generate a lower ascii only string from the original one
    :param str original_str: The string to modify
    :returns: A modified string
    :rtype: str
    """
    result = original_str.lower()
    result = force_ascii(result)
    result = result.replace(' ', '_')
    return result
コード例 #6
0
ファイル: statistics.py プロジェクト: lluc/autonomie
 def filename(self):
     return u"{0}.csv".format(ascii.force_ascii(self.context.title))
コード例 #7
0
def test_force_ascii():
    assert force_ascii("éco") == u"eco"
    assert force_ascii(5) == "5"
    assert force_ascii(u"éco") == "eco"
コード例 #8
0
 def filename(self):
     return u"{0}.csv".format(ascii.force_ascii(self.context.title))