-
Notifications
You must be signed in to change notification settings - Fork 35
Proposal to fix #154 (v2) #161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dmitry-lipetsk
merged 13 commits into
postgrespro:master
from
dmitry-lipetsk:master-fix154--v02
Dec 10, 2024
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f9ddd04
Proposal to fix #154 (v2)
dmitry-lipetsk 2bb38dc
[BUG FIX] PostgresNode::safe_psql did not respect "expect_error" para…
dmitry-lipetsk 45b8dc0
[BUG FIX] A problem in psql/safe_psql and 'input' data was fixed [loc…
dmitry-lipetsk f848a63
PostgresNode::safe_psql raises InvalidOperationException
dmitry-lipetsk db0744e
A problem with InvalidOperationException and flake8 is fixed
dmitry-lipetsk 5bb1510
A code style is fixed [flake8]
dmitry-lipetsk 31c7bce
[BUG FIX] Wrappers for psql use subprocess.PIPE for stdout and stderr
dmitry-lipetsk b013801
[BUG FIX] TestgresTests::test_safe_psql__expect_error uses rm_carriag…
dmitry-lipetsk c49ee4c
node.py is updated [formatting]
dmitry-lipetsk 6a0e714
Formatting
dmitry-lipetsk 3cc19d2
raise_error.py is moved into testgres/operations from testgres/helpers
dmitry-lipetsk 7b70e9e
Helpers.GetDefaultEncoding is added
dmitry-lipetsk cd0b5f8
Code normalization
dmitry-lipetsk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import locale | ||
|
||
|
||
class Helpers: | ||
def _make_get_default_encoding_func(): | ||
# locale.getencoding is added in Python 3.11 | ||
if hasattr(locale, 'getencoding'): | ||
return locale.getencoding | ||
|
||
# It must exist | ||
return locale.getpreferredencoding | ||
|
||
# Prepared pointer on function to get a name of system codepage | ||
_get_default_encoding_func = _make_get_default_encoding_func() | ||
|
||
def GetDefaultEncoding(): | ||
# | ||
# Original idea/source was: | ||
# | ||
# def os_ops.get_default_encoding(): | ||
# if not hasattr(locale, 'getencoding'): | ||
# locale.getencoding = locale.getpreferredencoding | ||
# return locale.getencoding() or 'UTF-8' | ||
# | ||
|
||
assert __class__._get_default_encoding_func is not None | ||
|
||
r = __class__._get_default_encoding_func() | ||
|
||
if r: | ||
assert r is not None | ||
assert type(r) == str # noqa: E721 | ||
assert r != "" | ||
return r | ||
|
||
# Is it an unexpected situation? | ||
return 'UTF-8' | ||
|
||
def PrepareProcessInput(input, encoding): | ||
if not input: | ||
return None | ||
|
||
if type(input) == str: # noqa: E721 | ||
if encoding is None: | ||
return input.encode(__class__.GetDefaultEncoding()) | ||
|
||
assert type(encoding) == str # noqa: E721 | ||
return input.encode(encoding) | ||
|
||
# It is expected! | ||
assert type(input) == bytes # noqa: E721 | ||
return input |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from ..exceptions import ExecUtilException | ||
from .helpers import Helpers | ||
|
||
|
||
class RaiseError: | ||
def UtilityExitedWithNonZeroCode(cmd, exit_code, msg_arg, error, out): | ||
assert type(exit_code) == int # noqa: E721 | ||
|
||
msg_arg_s = __class__._TranslateDataIntoString(msg_arg).strip() | ||
assert type(msg_arg_s) == str # noqa: E721 | ||
|
||
if msg_arg_s == "": | ||
msg_arg_s = "#no_error_message" | ||
|
||
message = "Utility exited with non-zero code. Error: `" + msg_arg_s + "`" | ||
raise ExecUtilException( | ||
message=message, | ||
command=cmd, | ||
exit_code=exit_code, | ||
out=out, | ||
error=error) | ||
|
||
def _TranslateDataIntoString(data): | ||
if type(data) == bytes: # noqa: E721 | ||
return __class__._TranslateDataIntoString__FromBinary(data) | ||
|
||
return str(data) | ||
|
||
def _TranslateDataIntoString__FromBinary(data): | ||
assert type(data) == bytes # noqa: E721 | ||
|
||
try: | ||
return data.decode(Helpers.GetDefaultEncoding()) | ||
except UnicodeDecodeError: | ||
pass | ||
|
||
return "#cannot_decode_text" | ||
|
||
def _BinaryIsASCII(data): | ||
assert type(data) == bytes # noqa: E721 | ||
|
||
for b in data: | ||
if not (b >= 0 and b <= 127): | ||
return False | ||
|
||
return True |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.