diff options
Diffstat (limited to 'sphinx/util/__init__.py')
| -rw-r--r-- | sphinx/util/__init__.py | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/sphinx/util/__init__.py b/sphinx/util/__init__.py index 756beaf6c..384925157 100644 --- a/sphinx/util/__init__.py +++ b/sphinx/util/__init__.py @@ -59,7 +59,7 @@ def docname_join(basedocname: str, docname: str) -> str: def path_stabilize(filepath: str) -> str: - "normalize path separater and unicode string" + "Normalize path separator and unicode string" newpath = filepath.replace(os.path.sep, SEP) return unicodedata.normalize('NFC', newpath) @@ -337,6 +337,23 @@ def parselinenos(spec: str, total: int) -> List[int]: return items +def force_decode(string: str, encoding: str) -> str: + """Forcibly get a unicode string out of a bytestring.""" + warnings.warn('force_decode() is deprecated.', + RemovedInSphinx50Warning, stacklevel=2) + if isinstance(string, bytes): + try: + if encoding: + string = string.decode(encoding) + else: + # try decoding with utf-8, should only work for real UTF-8 + string = string.decode() + except UnicodeError: + # last resort -- can't fail + string = string.decode('latin1') + return string + + def rpartition(s: str, t: str) -> Tuple[str, str]: """Similar to str.rpartition from 2.5, but doesn't return the separator.""" warnings.warn('rpartition() is now deprecated.', RemovedInSphinx50Warning, stacklevel=2) @@ -418,7 +435,7 @@ def split_full_qualified_name(name: str) -> Tuple[Optional[str], str]: A "full" qualified name means a string containing both module name and qualified name. - .. note:: This function imports module actually to check the exisitence. + .. note:: This function actually imports the module to check its existence. Therefore you need to mock 3rd party modules if needed before calling this function. """ |
