Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/sphinx-doc/sphinx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2020-02-01 04:58:28 +0300
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2020-02-01 05:45:47 +0300
commit7d6374d983cc757e8bb7911da13f2dce7d69ec36 (patch)
treebb4bab106f7fd051384b5f800476a5c2d88b2d38 /sphinx/testing
parent41032572a5101add1d674a81722e648b9af6d6a5 (diff)
testing: Add Path.read_text() and Path.read_bytes()
To migrate pathlib.Path in future, compatibile methods are needed for our Path class.
Diffstat (limited to 'sphinx/testing')
-rw-r--r--sphinx/testing/path.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/sphinx/testing/path.py b/sphinx/testing/path.py
index 1c883af2f..4c3702e3d 100644
--- a/sphinx/testing/path.py
+++ b/sphinx/testing/path.py
@@ -10,8 +10,11 @@ import builtins
import os
import shutil
import sys
+import warnings
from typing import Any, Callable, IO, List
+from sphinx.deprecation import RemovedInSphinx50Warning
+
FILESYSTEMENCODING = sys.getfilesystemencoding() or sys.getdefaultencoding()
@@ -138,6 +141,14 @@ class path(str):
"""
Returns the text in the file.
"""
+ warnings.warn('Path.text() is deprecated. Please use read_text() instead.',
+ RemovedInSphinx50Warning, stacklevel=2)
+ return self.read_text(encoding, **kwargs)
+
+ def read_text(self, encoding: str = 'utf-8', **kwargs: Any) -> str:
+ """
+ Returns the text in the file.
+ """
with open(self, encoding=encoding, **kwargs) as f:
return f.read()
@@ -145,6 +156,14 @@ class path(str):
"""
Returns the bytes in the file.
"""
+ warnings.warn('Path.bytes() is deprecated. Please use read_bytes() instead.',
+ RemovedInSphinx50Warning, stacklevel=2)
+ return self.read_bytes()
+
+ def read_bytes(self) -> builtins.bytes:
+ """
+ Returns the bytes in the file.
+ """
with open(self, mode='rb') as f:
return f.read()