git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 4/6] git-p4: python3: basestring workaround

From
Luke Diamand <luke@diamand.org>
Date
Jun 19, 2018, 08:04 UTC
Message-ID
<20180619080411.6554-5-luke@diamand.org>
In-Reply-To
<20180619080411.6554-4-luke@diamand.org>
In Python3, basestring no longer exists, so use this workaround.
Signed-off-by: Luke Diamand <luke@diamand.org>
---
 git-p4.py | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
diff --git a/git-p4.py b/git-p4.py
index 67865d14aa..f127ebce27 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -27,6 +27,22 @@
 import ctypes
 import errno
 
+# support basestring in python3
+try:
+    unicode = unicode
+except NameError:
+    # 'unicode' is undefined, must be Python 3
+    str = str
+    unicode = str
+    bytes = bytes
+    basestring = (str,bytes)
+else:
+    # 'unicode' exists, must be Python 2
+    str = str
+    unicode = unicode
+    bytes = str
+    basestring = basestring
+
 try:
     from subprocess import CalledProcessError
 except ImportError:
-- 
2.18.0.rc1.242.g61856ae69a
Previous: Luke DiamandNext: Luke Diamand
Message 5 of 8 in “git-p4: small step towards Python3 support”
  1. 0/6 git-p4: small step towards Python3 supportLuke Diamand, Jun 19, 2018
  2. 1/6 git-p4: python3: replace <> with !=Luke Diamand, Jun 19, 2018
  3. 2/6 git-p4: python3: replace dict.has_key(k) with "k in dict"Luke Diamand, Jun 19, 2018
  4. 3/6 git-p4: python3: remove backticksLuke Diamand, Jun 19, 2018
  5. 4/6 git-p4: python3: basestring workaroundLuke Diamand, Jun 19, 2018
  6. 5/6 git-p4: python3: use print() functionLuke Diamand, Jun 19, 2018
  7. 6/6 git-p4: python3: fix octal constantsLuke Diamand, Jun 19, 2018
  8. Eric SunshineJun 19, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.