r47244 - initial review comments
hawkowl-TA+aISz0psMTMxyoc4vAAJOcrHinNvQL0E9HWUfgJXw@public.gmane.org Thu, 14 Apr 2016 21:03:02 -0600 (MDT)
| Newsgroups | gmane.comp.python.twisted.commits |
|---|---|
| Message-ID | <[email protected]> |
Author: hawkowl
Date: Thu Apr 14 21:02:58 2016
New Revision: 47244
Modified:
branches/moar-windows-8025-7/.gitignore
branches/moar-windows-8025-7/twisted/internet/_dumbwin32proc.py
branches/moar-windows-8025-7/twisted/python/compat.py
Log:
initial review comments
Modified: branches/moar-windows-8025-7/.gitignore
==============================================================================
--- branches/moar-windows-8025-7/.gitignore (original)
+++ branches/moar-windows-8025-7/.gitignore Thu Apr 14 21:02:58 2016
@@ -15,4 +15,4 @@
*.lock
apidocs/
.vs/
-*.pyproj
\ No newline at end of file
+*.pyproj
Modified: branches/moar-windows-8025-7/twisted/internet/_dumbwin32proc.py
==============================================================================
--- branches/moar-windows-8025-7/twisted/internet/_dumbwin32proc.py (original)
+++ branches/moar-windows-8025-7/twisted/internet/_dumbwin32proc.py Thu Apr 14 21:02:58 2016
@@ -28,7 +28,7 @@
from zope.interface import implementer
from twisted.internet.interfaces import IProcessTransport, IConsumer, IProducer
-from twisted.python.compat import items, _PY3, unicode
+from twisted.python.compat import items, _PY3, unicode, _maybeMBCS
from twisted.python.win32 import quoteArguments
from twisted.internet import error
@@ -177,14 +177,14 @@
env.update(environment or {})
if _PY3:
- # Make sure all the arguments are str
- args = [x.decode('mbcs') if isinstance(x, bytes) else x
- for x in args]
+ # Make sure all the arguments are Unicode.
+ args = [_maybeMBCS(x) for x in args]
cmdline = quoteArguments(args)
- if _PY3 and isinstance(command, bytes):
- command = command.decode('mbcs')
+ if _PY3:
+ # The command, too, needs to be Unicode.
+ command = _maybeMBCS(command)
# TODO: error detection here. See #2787 and #4184.
def doCreate():
@@ -202,11 +202,8 @@
newenv = {}
for key, value in items(env):
- if not isinstance(value, unicode):
- value = value.decode('mbcs')
-
- if not isinstance(key, unicode):
- key = key.decode('mbcs')
+ key = _maybeMBCS(key)
+ value = _maybeMBCS(value)
newenv[key] = value
Modified: branches/moar-windows-8025-7/twisted/python/compat.py
==============================================================================
--- branches/moar-windows-8025-7/twisted/python/compat.py (original)
+++ branches/moar-windows-8025-7/twisted/python/compat.py Thu Apr 14 21:02:58 2016
@@ -702,6 +702,24 @@
+def _maybeMBCS(s):
+ """
+ Convert C{s} to a L{unicode} string, if required.
+
+ @param s: The string to convert.
+ @type s: L{bytes} or L{unicode}
+
+ @rtype: L{unicode}
+ """
+ assert os.name == "win32"
+ assert type(s) in [bytes, unicode]
+
+ if isinstance(s, bytes):
+ return s.decode('mbcs')
+ return s
+
+
+
__all__ = [
"reraise",
"execfile",
@@ -735,4 +753,5 @@
"_b64encodebytes",
"_b64decodebytes",
"_bytesChr",
+ "_maybeMBCS",
]