[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: One more issue in tests on Windows with Python 3

From: Daniel Shahaf <d.s_at_daniel.shahaf.name>
Date: Thu, 7 May 2020 17:46:21 +0000

Yasuhito FUTATSUKI wrote on Thu, 07 May 2020 20:46 +0900:
> I think it is need to escape characters in char *value when we print
> them as Python's str value. The patch below may work for this purpose,
> but I want someone to write more nice code :)

How about simply adding the human-readable value in a comment? —

[[[
Index: subversion/tests/cmdline/entries-dump.c
===================================================================
--- subversion/tests/cmdline/entries-dump.c (revision 1877310)
+++ subversion/tests/cmdline/entries-dump.c (working copy)
@@ -46,7 +46,23 @@ str_value(const char *name, const char *value)
   if (value == NULL)
     printf("e.%s = None\n", name);
   else
- printf("e.%s = '%s'\n", name, value);
+ {
+ svn_stringbuf_t *escaped_value;
+ SVN_ERR(svn_xml_escape_attr_cstring(&escaped_value, value, pool));
+
+ /* Print the human-readable value. */
+ assert(NULL == strchr(escaped_value->data, '\n'));
+ printf("# e.%s = %s\n", name, escaped_value->data);
+
+ /* Print the machine-readable value. */
+ printf("e.%s = (lambda x: x if isinstance(x, str) else "
+ "x.decode('utf-8', 'surrogateescape'))(b'", name);
+ while(*value)
+ {
+ printf("\\x%02x", (unsigned int)(unsigned char)*value++);
+ }
+ printf("')\n");
+ }
 }
 
 
]]]

Also, I propose to change the cast as above, because I think the
previous one wouldn't DTRT on platforms where 'char' is signed.

Cheers,

Daniel
Received on 2020-05-07 19:46:33 CEST

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.