Repository navigation
Conversation
397b5aa to
131cf60
Compare
c1ef13a to
70d1b84
Compare
| whether to do a stat() on the file afterwards to confirm the file | ||
| size (since 1.7.7) | ||
| :param str encoding: | ||
| encoding for file paths/names and content (default: utf8) |
There was a problem hiding this comment.
The encoding and errors parameters are not used for the content because putfo uses binary mode.
There was a problem hiding this comment.
I guess you refer to the following part:
with self.file(
remotepath, "wb", encoding=encoding, errors=errors
) as fr:
Right, it's in binary mode, but that's just the content, the file path might be non uft8 though. And just below that part the stat method is also used, which takes these parameters to get the actual remote path in the remote encoding.
Actually, this remotepath over there might need encoding too. I'm not sure... I'll try and test this week. (All you need is a VM or Docker with an OS using an encoding different from utf8...)
-> remotepath.decode("utf-8", errors).encode(encoding, errors)
There was a problem hiding this comment.
Update:
self.file is an object of open and open takes encoding and errors as parameter. Encoding and errors in open decodes the file name/path.
In other words: Everything should be correct here. You didn't dig deep enough, I guess.
There was a problem hiding this comment.
What I mean is that the comment for the parameter should be:
encoding for file paths/names (default: utf8)
I think the current comment leads misleading. In fact, the encoding parameter is not used for the content.
| else: | ||
|
|
||
| def __next__(self): | ||
| def __next__(self, encoding="utf8", errors="strict"): |
There was a problem hiding this comment.
The __next__ method doesn't have arguments. It is unable to use the arguments because Python iterator directly invokes it.
Instead, I suggest:
- Add
encodinganderrorsparameters to__init__method and store to the instance attributes - Use the attributes here
There was a problem hiding this comment.
I see. I should have noticed that....
I'll try and see what to do best. Thanks.
There was a problem hiding this comment.
I fixed this and merged the newest commits from the main branch.
There was a problem hiding this comment.
I think readline should use self.encoding and self.errors and remove added arguments, because passing two parameters to __init__.
|
By the way... How about having a encoding parameters at SFTPClient's init instead of every method (list etc) |
07d1988 to
2779500
Compare
|
The new commit removes all encoding/errors parameters from SFTPClients methods and puts them instead into the constructor and the from_transport method. |
|
I will have to merge this manually over and over again if it won't get merged/pulled... |
|
merged current main into this pull request. |
bskinn
left a comment
There was a problem hiding this comment.
I have a couple of questions, and a suggestion for additional tests.
Thanks for putting together a PR for this!
| try: | ||
| folder_contents = sftp.listdir(sftp.FOLDER) | ||
| self.assertEqual(["canard.txt"], folder_contents) | ||
| TestCase().assertEqual(["canard.txt"], folder_contents) |
There was a problem hiding this comment.
What is your reasoning behind this replacement? This seems like it will unnecessarily create a new, empty TestCase instance for each assert, instead of just using the one that already exists in the form of self.
There was a problem hiding this comment.
Hmm? I don't remember changing this myself. I'll check when I come home tomorrow night.
Thank you.
| else: | ||
| try: | ||
| return test_method(testself) | ||
| return test_method(testself, sftp) |
There was a problem hiding this comment.
I'm relatively unfamiliar with the guts of the test suite, but what does adding the sftp here accomplish? I don't see anything obvious in any of the other changes where this is used.
| @patch("paramiko.channel.ChannelFile._set_mode") | ||
| def test_defaults_to_unbuffered_reading(self, setmode): | ||
| self.klass(Channel(None)) | ||
| self.klass(Channel(None), encoding="utf8", errors="strict") |
There was a problem hiding this comment.
You've added encoding="utf8" cases to many tests, but I don't see any tests that probe compatibility with other encodings. Those would be good to add.
There was a problem hiding this comment.
Right. In the first place this is supposed to "not break the current tests".
Adding one or two different test cases where the system does not use utf8 would be very welcome. I'll try to put something together, but I'm not yet sure at how to do it.
We have to keep in mind that there are two different problems: Encoding of file content and encoding of file paths including system messages. (Welcome message on login and error messages etc)
There was a problem hiding this comment.
Ah, I see -- with this PR, you're going for a ~zero-effect change, making sure that adding the encoding and errors arguments didn't break anything in the default utf8 use case? Thus, setting the stage for future development/testing when new encodings enter the mix?
There was a problem hiding this comment.
Yes. That's right 🙂
If things break at the base level, further coding and testing will get messy and difficult.
Continuation of original pull request #1716
Cloned the current main branch and added my function parameters. No much change. Fixed 2 failing tests too.
Optional parameters are "encoding" with default to utf8 and "errors" with default to "strict".
You could add a paramiko global or something to avoid the need to pass the encoding/errors parameters each time.
Best regards,
Hakaishi