Stefan Fuhrmann <[email protected]> writes:
>> The new condition looks fairly suspicious.
>
> Sure, but no worse than before.
I think it's actually worse than before, as now it looks like this function
was updated for Python 3, whereas in fact it gets all the special cases
like "value[0] == '-'" wrong. And we will probably trip over this in the
future.
How about doing it as in the attached patch?
Regards,
Evgeny Kotkov
Index: subversion/tests/cmdline/svntest/actions.py
===================================================================
--- subversion/tests/cmdline/svntest/actions.py (revision 1743638)
+++ subversion/tests/cmdline/svntest/actions.py (working copy)
@@ -2103,30 +2103,49 @@ def create_failing_post_commit_hook(repo_dir):
'@echo Post-commit hook failed 1>&2\n'
'@exit 1\n')
+def _make_temp_file(contents):
+ """ Create a unique temporary file with the specified CONTENTS
+ and return its path. """
+ from tempfile import mkstemp
+ (fd, path) = mkstemp()
+ os.close(fd)
+ file = open(path, 'wb')
+ file.write(contents)
+ file.flush()
+ file.close()
+ return path
+
# set_prop can be used for properties with NULL characters which are not
# handled correctly when passed to subprocess.Popen() and values like "*"
# which are not handled correctly on Windows.
def set_prop(name, value, path, expected_re_string=None, force=None):
"""Set a property with specified value"""
+ if isinstance(value, bytes):
+ file = _make_temp_file(value)
+ elif isinstance(value, str):
+ if value and (value[0] == '-' or '\x00' in value or
+ sys.platform == 'win32'):
+ file = _make_temp_file(value.encode())
+ else:
+ file = None
+ else:
+ raise TypeError(value)
+
if not force:
propset = ('propset',)
else:
propset = ('propset', '--force')
- if value and (isinstance(value, bytes) or
- (value[0] == '-' or '\x00' in value or sys.platform ==
'win32')):
- from tempfile import mkstemp
- (fd, value_file_path) = mkstemp()
- os.close(fd)
- value_file = open(value_file_path, 'wb')
- value_file.write(value)
- value_file.flush()
- value_file.close()
- propset += ('-F', value_file_path, name, path)
- exit_code, out, err = main.run_svn(expected_re_string, *propset)
- os.remove(value_file_path)
+ if file is not None:
+ propset += ('-F', file, name, path)
else:
propset += (name, value, path)
+
+ try:
exit_code, out, err = main.run_svn(expected_re_string, *propset)
+ finally:
+ if file is not None:
+ os.remove(file)
+
if expected_re_string:
if not expected_re_string.startswith(".*"):
expected_re_string = ".*(" + expected_re_string + ")"