mirror of
https://github.com/jazzband/django-downloadview.git
synced 2026-05-14 10:33:15 +00:00
18 lines
461 B
Python
18 lines
461 B
Python
"""Utility functions."""
|
|
import re
|
|
|
|
|
|
charset_pattern = re.compile(r'charset=(?P<charset>.+)$', re.I | re.U)
|
|
|
|
|
|
def content_type_to_charset(content_type):
|
|
"""Return charset part of content-type header.
|
|
|
|
>>> from django_downloadview.utils import content_type_to_charset
|
|
>>> content_type_to_charset('text/html; charset=utf-8')
|
|
'utf-8'
|
|
|
|
"""
|
|
match = re.search(charset_pattern, content_type)
|
|
if match:
|
|
return match.group('charset')
|