Opened 10 years ago

Closed 10 years ago

# P4Python doesn't accept unicode type as the parameters

Reported by: Owned by: kenjin ttressieres normal PerforcePlugin blocker 0.10

### Description

I installed sandbox/vc-refactoring 0.10dev code (as of 5/18/06) from svn, and P4Python 0.6 on Fedora Core 4. I followed the installation guide, but got errors telling P4Python.run() method doesn't accept unicode type as the parameter. I whipped up a patch, which simply added a method to encode to ASCII, and the problem is fixed. The patch is not suitable to apply the real code, but it should give a hint for the fix. (For example, I could localize the encoding in a method and simply invoke it. ) I'm not sure why other users don't encounter the problem, but I guess it may be related to the fact that Fedora Core uses UTF-8 as the character encoding.

### comment:1 Changed 10 years ago by bjornswift

In my opinion, this is not a bug within Trac's Perforce plugin but with the Python Perforce bindings. The plugin should use Unicode internally and be able to pass them onto P4. This however, is open for debate.

I patched p4.py some time ago, and sent them to P4Python's maintainer some days back. The changes are here, for those who are interested:

19d19
< from types import *
132c131
<         return map(str, result)
---
>         return result
325,327d324
<         if type(value) is UnicodeType:
<             value = str(value)
<


### comment:2 Changed 10 years ago by lewisbaker

• Resolution set to fixed
• Status changed from new to closed

The latest version, 0.4.1, uses PyPerforce which supports unicode strings natively and automatically encodes strings using the current P4CHARSET.

However, the plugin still needs to choose an encoding to use to convert between unicode and str strings when the Perforce server isn't running in Unicode mode so that it can handle any extended characters (the default encoding of ASCII causes errors for such characters).

Version 0.4.1 assumes the encoding is ISO-8859-1 if the Perforce server isn't running in Unicode mode.

The plugin now uses unicode strings throughout and only performs any encoding of the string at the boundary to Perforce.