On Wed, Aug 24, 2011 at 12:18:53AM -0700, Reid Price wrote:
> On Tue, Aug 23, 2011 at 2:05 PM, Ben Pfaff <[email protected]> wrote:
> > escapes[i] = u"\\u%04x" % i
> >
> > def __dump_string(stream, s):
> > - stream.write(u"\"")
> > - for c in s:
> > - x = ord(c)
> > - escape = escapes.get(x)
> > - if escape:
> > - stream.write(escape)
> > - else:
> > - stream.write(c)
> > - stream.write(u"\"")
> > + stream.write(u'"%s"' % ''.join([escapes.get(ord(c), c) for c in s]))
> >
> You can drop the [] here as well. This will use an iterator instead,
> which avoids the construction of an intermediate list.
>
> stream.write(u'"%s"' % ''.join(escapes.get(ord(c), c) for c in s))
Thanks, applied.
> Another thing in passing, could use the unicode cast here, which
> ends up being about the same number of characters
>
> stream.write(unicode(''.join(escapes.get(ord(c), c) for c in s)))
That omits the "" from the text written to the string. Restoring the
"" requires % or + anyway.
Thanks,
Ben.
_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev