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

Re: mailer.py commit says TypeError: must be unicode, not str

From: Kenneth Porter <shiva_at_sewingwitch.com>
Date: Wed, 31 Jan 2018 19:23:59 -0800

--On Tuesday, January 23, 2018 7:14 AM -0800 Kenneth Porter
<shiva_at_sewingwitch.com> wrote:

> File "/usr/lib64/python2.7/site-packages/svn/fs.py", line 87, in
> _dump_contents
> fp.write(chunk)
> TypeError: must be unicode, not str

Here's the code where this is going wrong. I think svn_stream_read is
returning a byte stream and the file object here is expecting a unicode
string. Is there a missing decode('utf-8') call? (I'm a very new Python
coder but have lots of experience in C++ and some understanding of unicode.)

Package is subversion-python-1.7.14-11.el7_4.x86_64 in CentOS 7.4.

>From /usr/lib64/python2.7/site-packages/svn/fs.py

  def _dump_contents(self, file, root, path, pool=None):
    fp = builtins.open(file, 'w+') # avoid namespace clash with
                                   # trimmed-down svn_fs_open()
    if path is not None:
      stream = file_contents(root, path, pool)
      try:
        while True:
          chunk = _svncore.svn_stream_read(stream,
_svncore.SVN_STREAM_CHUNK_SIZE)
          if not chunk:
            break
          fp.write(chunk)
      finally:
        _svncore.svn_stream_close(stream)
    fp.close()

BTW, I found this nice treatment of unicode in Python 2 and 3:

<https://nedbatchelder.com/text/unipain.html>
Received on 2018-02-01 04:26:38 CET

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

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