Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit45b8dc0

Browse files
[BUG FIX] A problem in psql/safe_psql and 'input' data was fixed [local_op]
Both LocalOperations::exec_command and RemoteOperations::exec_command were updated.
1 parent2bb38dc commit45b8dc0

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

‎testgres/node.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,18 @@ def _psql(
10051005
username=None,
10061006
input=None,
10071007
**variables):
1008+
asserttype(variables)==dict# noqa: E721
1009+
1010+
#
1011+
# We do not support encoding. It may be added later. Ok?
1012+
#
1013+
ifinputisNone:
1014+
pass
1015+
eliftype(input)==bytes:# noqa: E721
1016+
pass
1017+
else:
1018+
raiseException("Input data must be None or bytes.")
1019+
10081020
dbname=dbnameordefault_dbname()
10091021

10101022
psql_params= [

‎testgres/operations/helpers.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
classHelpers:
2+
defPrepareProcessInput(input,encoding):
3+
ifnotinput:
4+
returnNone
5+
6+
iftype(input)==str:# noqa: E721
7+
ifencodingisNone:
8+
returninput.encode()
9+
10+
asserttype(encoding)==str# noqa: E721
11+
returninput.encode(encoding)
12+
13+
# It is expected!
14+
asserttype(input)==bytes# noqa: E721
15+
returninput

‎testgres/operations/local_ops.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
from ..exceptionsimportExecUtilException
1313
from .os_opsimportConnectionParams,OsOperations,pglib,get_default_encoding
14+
from .helpersimportHelpers
1415
from ..helpers.raise_errorimportRaiseError
1516

1617
try:
@@ -58,6 +59,8 @@ def _process_output(encoding, temp_file_path):
5859
returnoutput,None# In Windows stderr writing in stdout
5960

6061
def_run_command__nt(self,cmd,shell,input,stdin,stdout,stderr,get_process,timeout,encoding):
62+
# TODO: why don't we use the data from input?
63+
6164
withtempfile.NamedTemporaryFile(mode='w+b',delete=False)astemp_file:
6265
stdout=temp_file
6366
stderr=subprocess.STDOUT
@@ -79,6 +82,10 @@ def _run_command__nt(self, cmd, shell, input, stdin, stdout, stderr, get_process
7982
returnprocess,output,error
8083

8184
def_run_command__generic(self,cmd,shell,input,stdin,stdout,stderr,get_process,timeout,encoding):
85+
input_prepared=None
86+
ifnotget_process:
87+
input_prepared=Helpers.PrepareProcessInput(input,encoding)# throw
88+
8289
process=subprocess.Popen(
8390
cmd,
8491
shell=shell,
@@ -89,7 +96,7 @@ def _run_command__generic(self, cmd, shell, input, stdin, stdout, stderr, get_pr
8996
ifget_process:
9097
returnprocess,None,None
9198
try:
92-
output,error=process.communicate(input=input.encode(encoding)ifinputelseNone,timeout=timeout)
99+
output,error=process.communicate(input=input_prepared,timeout=timeout)
93100
ifencoding:
94101
output=output.decode(encoding)
95102
error=error.decode(encoding)

‎testgres/operations/remote_ops.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from ..exceptionsimportExecUtilException
1717
from ..helpers.raise_errorimportRaiseError
1818
from .os_opsimportOsOperations,ConnectionParams,get_default_encoding
19+
from .helpersimportHelpers
1920

2021
error_markers= [b'error',b'Permission denied',b'fatal',b'No such file or directory']
2122

@@ -70,6 +71,10 @@ def exec_command(self, cmd, wait_exit=False, verbose=False, expect_error=False,
7071
asserttype(expect_error)==bool# noqa: E721
7172
asserttype(ignore_errors)==bool# noqa: E721
7273

74+
input_prepared=None
75+
ifnotget_process:
76+
input_prepared=Helpers.PrepareProcessInput(input,encoding)# throw
77+
7378
ssh_cmd= []
7479
ifisinstance(cmd,str):
7580
ssh_cmd= ['ssh',self.ssh_dest]+self.ssh_args+ [cmd]
@@ -80,7 +85,7 @@ def exec_command(self, cmd, wait_exit=False, verbose=False, expect_error=False,
8085
returnprocess
8186

8287
try:
83-
result,error=process.communicate(input,timeout=timeout)
88+
result,error=process.communicate(input=input_prepared,timeout=timeout)
8489
exceptsubprocess.TimeoutExpired:
8590
process.kill()
8691
raiseExecUtilException("Command timed out after {} seconds.".format(timeout))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp