summaryrefslogtreecommitdiff
path: root/sphinx/util/__init__.py
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2021-12-11 22:59:56 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2021-12-11 22:59:56 +0900
commit5563f672eccd3aa93c304ba6bac04ee2360b8c4e (patch)
tree48f26368337d0f2c3322aecd5a3e3db85c1b1682 /sphinx/util/__init__.py
parent1227799abf0d0e3dafa0d61461cf613468e894df (diff)
parentc6fc5dff5334dc04c7858f2752a5e2c22f25eaeb (diff)
downloadsphinx-git-5563f672eccd3aa93c304ba6bac04ee2360b8c4e.tar.gz
Merge branch '4.x' into fix-footnote-in-info
Diffstat (limited to 'sphinx/util/__init__.py')
-rw-r--r--sphinx/util/__init__.py21
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.
"""