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
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
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
def filename(self): return u"{0}.csv".format(ascii.force_ascii(self.context.title))
def test_force_ascii(): assert force_ascii("éco") == u"eco" assert force_ascii(5) == "5" assert force_ascii(u"éco") == "eco"