Add Accessor.openText() as context manager for openAddress() #76
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The commits on this PR depend on the 1st commit:
It adds
Accessor.openText()
as a new API to make uses likeConfigParser().read_file(TextIO)
which needTextIO
(IO[str]
). It replaces calls like these (change commit: a97be27?diff=split)with:
It makes it easy to use
TextIO
(IO[str]
) withxcp.accessor
on Python3 by using a context manager which takes care of closing all buffers/readers after leaving the context:xcp/accessor.py
:openText()
: Context manager to read text from addrAdd
Accessor.openText()
as context manager to wrapopenAddress()
withio.TextIOWrapper
(if needed which is what Yann Dirson did as well in PR Testsuite driven py3 #17/Initial Python3 support with Test-Driven-Development enforced by CI (with git diff coverage and diff lint checking) + mypy, pyre and pytype #27):Accessor.openText()
:TextIOWrapper
(or instance ofIO[str]
) orFalse
TextIOWrapper
and the underlyingfile
It is intented for use in
xcp.repository
and in any other user requiring text as string without having to call.decode()
after reading the returned file object.xcp/repository.py
: UseAccessor.openText()
forConfigParser()
Use
Accessor.openText()
in_getVersion()
forConfigParser().read_file()
.It simplifies
_getVersion()
dramatically and causesAccessor.openText()
to be tested withxcp.accessor.FileAccessor
andxcp.accessor.HTTPAccessor
.tests/test_mountingaccessor.py: Test MountingAccessor.openText()
Test openText() with subclasses of xcp.accessor.MountingAccessor
tests/test_ftpaccessor.py: Test FTPAccessor.openText()
New test: Download a text file containing UTF-8 using
FTPAccessor.openText()
and compare the returned string.tests/test_httpaccessor.py: Add test for HTTPAccessor.openText()
Add test to get text containing UTF-8 using HTTPAccessor.openText() and compare the returned decoded string contents.
tests/test_httpaccessor.py: Split assert_http_get_request_data()
Split
assert_http_get_request_data()
usingcontextlib.contextmanager