raise cmdutil.UserError("No comment entered.")
body = body.decode('utf-8')
elif args[1] == '-': # read body from stdin
- body = sys.stdin.read()
- if not body.endswith('\n'):
- body+='\n'
+ binary = not options.content_type.startswith("text/")
+ if not binary:
+ body = sys.stdin.read()
+ if not body.endswith('\n'):
+ body+='\n'
+ else: # read-in without decoding
+ body = sys.__stdin__.read()
else: # body = arg[1]
body = args[1]
if not body.endswith('\n'):
self._u_invoke_client("delete-id", path)
def _rcs_update(self, path):
pass
- def _rcs_get_file_contents(self, path, revision=None):
+ def _rcs_get_file_contents(self, path, revision=None, binary=False):
if revision == None:
- return RCS._rcs_get_file_contents(self, path, revision)
+ return RCS._rcs_get_file_contents(self, path, revision, binary=binary)
else:
status,output,error = \
self._invoke_client("file-find", path, revision)
if show_comments == True:
comout = self.comment_root.xml_thread(auto_name_map=True,
bug_shortname=shortname)
- ret += comout
+ ret += comout+'\n'
ret += '</bug>'
return ret
self._u_invoke_client("remove", "--force", path)
def _rcs_update(self, path):
pass
- def _rcs_get_file_contents(self, path, revision=None):
+ def _rcs_get_file_contents(self, path, revision=None, binary=False):
if revision == None:
- return RCS._rcs_get_file_contents(self, path, revision)
+ return RCS._rcs_get_file_contents(self, path, revision, binary=binary)
else:
status,output,error = \
self._u_invoke_client("cat","-r",revision,path)
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA
+import email.mime.base, email.encoders
import os
import os.path
import time
def _get_comment_body(self):
if self.rcs != None and self.sync_with_disk == True:
import rcs
- return self.rcs.get_file_contents(self.get_path("body"))
+ binary = not self.content_type.startswith("text/")
+ return self.rcs.get_file_contents(self.get_path("body"), binary=binary)
def _set_comment_body(self, old=None, new=None, force=False):
if (self.rcs != None and self.sync_with_disk == True) or force==True:
assert new != None, "Can't save empty comment"
- self.rcs.set_file_contents(self.get_path("body"), new)
+ binary = not self.content_type.startswith("text/")
+ self.rcs.set_file_contents(self.get_path("body"), new, binary=binary)
@Property
@change_hook_property(hook=_set_comment_body)
"""
if shortname == None:
shortname = self.uuid
+ if self.content_type.startswith("text/"):
+ body = (self.body or "").rstrip('\n')
+ else:
+ maintype,subtype = self.content_type.split('/',1)
+ msg = email.mime.base.MIMEBase(maintype, subtype)
+ msg.set_payload(self.body or "")
+ email.encoders.encode_base64(msg)
+ body = msg.as_string()
info = [("uuid", self.uuid),
("short-name", shortname),
("in-reply-to", self.in_reply_to),
("from", self._setting_attr_string("From")),
("date", self.time_string),
("content-type", self.content_type),
- ("body", (self.body or "").rstrip('\n'))]
+ ("body", body)]
lines = ["<comment>"]
for (k,v) in info:
if v not in [settings_object.EMPTY, None]:
lines.append("")
#lines.append(textwrap.fill(self.body or "",
# width=(79-indent)))
- lines.extend((self.body or "").splitlines())
+ if self.content_type.startswith("text/"):
+ lines.extend((self.body or "").splitlines())
+ else:
+ lines.append("Content type %s not printable. Try XML output instead" % self.content_type)
# some comments shouldn't be wrapped...
istring = ' '*indent
self._u_invoke_client("rm", "-f", path)
def _rcs_update(self, path):
self._rcs_add(path)
- def _rcs_get_file_contents(self, path, revision=None):
+ def _rcs_get_file_contents(self, path, revision=None, binary=False):
if revision == None:
- return RCS._rcs_get_file_contents(self, path, revision)
+ return RCS._rcs_get_file_contents(self, path, revision, binary=binary)
else:
arg = "%s:%s" % (revision,path)
status,output,error = self._u_invoke_client("show", arg)
self._u_invoke_client("rm", path)
def _rcs_update(self, path):
pass
- def _rcs_get_file_contents(self, path, revision=None):
+ def _rcs_get_file_contents(self, path, revision=None, binary=False):
if revision == None:
- return RCS._rcs_get_file_contents(self, path, revision)
+ return RCS._rcs_get_file_contents(self, path, revision, binary=binary)
else:
status,output,error = \
self._u_invoke_client("cat","-r",revision,path)
at path.
"""
pass
- def _rcs_get_file_contents(self, path, revision=None):
+ def _rcs_get_file_contents(self, path, revision=None, binary=False):
"""
Get the file contents as they were in a given revision.
Revision==None specifies the current revision.
"""
assert revision == None, \
"The %s RCS does not support revision specifiers" % self.name
- f = codecs.open(os.path.join(self.rootdir, path), "r", self.encoding)
+ if binary == False:
+ f = codecs.open(os.path.join(self.rootdir, path), "r", self.encoding)
+ else:
+ f = open(path, "rb")
contents = f.read()
f.close()
return contents
at path.
"""
self._rcs_update(self._u_rel_path(path))
- def get_file_contents(self, path, revision=None, allow_no_rcs=False):
+ def get_file_contents(self, path, revision=None, allow_no_rcs=False, binary=False):
"""
Get the file as it was in a given revision.
Revision==None specifies the current revision.
raise NoSuchFile(path)
if self._use_rcs(path, allow_no_rcs):
relpath = self._u_rel_path(path)
- contents = self._rcs_get_file_contents(relpath,revision)
+ contents = self._rcs_get_file_contents(relpath,revision,binary=binary)
else:
f = codecs.open(path, "r", self.encoding)
contents = f.read()
f.close()
return contents
- def set_file_contents(self, path, contents, allow_no_rcs=False):
+ def set_file_contents(self, path, contents, allow_no_rcs=False, binary=False):
"""
Set the file contents under version control.
"""
add = not os.path.exists(path)
- f = codecs.open(path, "w", self.encoding)
+ if binary == False:
+ f = codecs.open(path, "w", self.encoding)
+ else:
+ f = open(path, "wb")
f.write(contents)
f.close()
print "Message-ID: <%s@%s>" % (self["uuid"], DEFAULT_DOMAIN)
print "Date: %s" % self["date"]
print "From: %s" % self["from"]
- print "Content-Type: %s; charset=%s" % (self["content-type"], DEFAULT_ENCODING)
- print "Content-Transfer-Encoding: 8bit"
print "Subject: %s: %s" % (self["short-name"], bug["summary"])
if "in-reply-to" not in self.keys():
self["in-reply-to"] = bug["uuid"]
print "In-Reply-To: <%s@%s>" % (self["in-reply-to"], DEFAULT_DOMAIN)
- print ""
- print self["body"]
+ if self["content-type"].startswith("text/"):
+ print "Content-Transfer-Encoding: 8bit"
+ print "Content-Type: %s; charset=%s" % (self["content-type"], DEFAULT_ENCODING)
+ print ""
+ print self["body"]
+ else: # content type and transfer encoding already in XML MIME output
+ print self["body"]
print ""
class BE_list_handler (ContentHandler):