Upgrade to Django 3.2
This commit is contained in:
parent
c1f710c9ac
commit
409d2e3115
23 changed files with 1469 additions and 151 deletions
|
@ -1,17 +1,37 @@
|
|||
from django.utils import six
|
||||
from typing import AnyStr, Optional, overload
|
||||
|
||||
|
||||
@overload
|
||||
def utf8bytes(maybe_text: AnyStr) -> bytes:
|
||||
pass
|
||||
|
||||
|
||||
@overload
|
||||
def utf8bytes(maybe_text: None) -> None:
|
||||
pass
|
||||
|
||||
|
||||
def utf8bytes(maybe_text):
|
||||
if maybe_text is None:
|
||||
return
|
||||
if isinstance(maybe_text, six.binary_type):
|
||||
return None
|
||||
if isinstance(maybe_text, bytes):
|
||||
return maybe_text
|
||||
return maybe_text.encode("utf-8")
|
||||
|
||||
|
||||
def utf8text(maybe_bytes, errors="strict"):
|
||||
@overload
|
||||
def utf8text(maybe_bytes: AnyStr, errors="strict") -> str:
|
||||
pass
|
||||
|
||||
|
||||
@overload
|
||||
def utf8text(maybe_bytes: None, errors="strict") -> None:
|
||||
pass
|
||||
|
||||
|
||||
def utf8text(maybe_bytes, errors="strict") -> Optional[str]:
|
||||
if maybe_bytes is None:
|
||||
return
|
||||
if isinstance(maybe_bytes, six.text_type):
|
||||
return None
|
||||
if isinstance(maybe_bytes, str):
|
||||
return maybe_bytes
|
||||
return maybe_bytes.decode("utf-8", errors)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue