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

Re: [PATCH] Python mailer hook script for Windows

From: Max Bowsher <maxb_at_ukf.net>
Date: 2004-12-14 22:14:40 CET

Prucha, Brett A wrote:
> --- mailer_orig.py Mon Aug 09 17:32:32 2004
> +++ mailer.py Tue Dec 14 10:41:49 2004
> @@ -20,6 +20,7 @@
> import ConfigParser
> import time
> import popen2
> +import StringIO
> import cStringIO
> import smtplib
> import re
> @@ -69,6 +70,9 @@
> subject = prefix + ' ' + self.subject
> else:
> subject = self.subject
> + if len(subject) > 200:
> + tmp = StringIO.StringIO(subject)
> + subject = tmp.read(197) + "..."
> hdrs = 'From: %s\n' \
> 'To: %s\n' \
> 'Subject: %s\n' \

What's wrong with a simple slice?

  subject = subject[:197] + "..."

> @@ -94,11 +98,16 @@
> def run(self, cmd):
> # we're holding everything in memory, so we may as well read the
> # entire diff into memory and stash that into the buffer
> - pipe_ob = popen2.Popen3(cmd)
> - self.write(pipe_ob.fromchild.read())
> -
> - # wait on the child so we don't end up with a billion zombies
> - pipe_ob.wait()
> + tmp = ""
> + for i in cmd:
> + if len(tmp) > 0:
> + tmp = tmp + " "
> + if re.search("[ ,\t]", i) == None:
> + tmp = tmp + i
> + else:
> + tmp = tmp + "\"" + i + "\""
> + ps = os.popen2(tmp)
> + self.write(ps[1].read())
>
> def finish(self):
> server = smtplib.SMTP(self.cfg.general.smtp_hostname)

Sorry, this is not acceptable, because it makes the UNIX case worse.

The UNIX case should continue to pass a list of arguments, not a string,
since this avoids the need to do any quoting at all. Indeed, given the
comment about zombies, the code should probably stay exactly the same in the
UNIX case.

Meanwhile, the Win32 case should just quote everything, rather than
bothering with regexps, and might as well cope with embedded " characters
too.

The below code snippet is part-way there:

-------
[File-scope]

if sys.platform == "win32":
  def escape_shell_arg(str):
    return '"' + string.replace(str, '"', '"^""') + '"'

...

[In run()]

if sys.platform == "win32":
  cmd = string.join(map(escape_shell_arg, cmd))
  # do stuff
else:
  # as existing
-------

Max.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Tue Dec 14 22:16:36 2004

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