classification
Title: msvc9compiler.py: TypeError: can't use a string pattern on a bytes-like object
Type: behavior Stage:
Components: Distutils Versions: Python 3.1, Python 3.2
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: tarek Nosy List: loewis, skrah, srid, tarek
Priority: normal Keywords: patch

Created on 2009-12-21 18:59 by srid, last changed 2009-12-21 23:45 by tarek. This issue is now closed.

Files
File name Uploaded Description Edit
3.1-byte-string.diff skrah, 2009-12-21 20:04
Messages (9)
msg96763 - (view) Author: Sridhar Ratnakumar (srid) Date: 2009-12-21 18:59
While building pywin32 with Py3k trunk (not release version), I get this 
traceback:

   Creating library build\temp.win32-
3.1\Release\win32\src\pywintypes31.lib and object buil
d\temp.win32-3.1\Release\win32\src\pywintypes31.exp
Traceback (most recent call last):
  File "setup3.py", line 16, in <module>
    exec(str(got))
...skipping...
  File "<string>", line 2194, in <module>
  File 
"C:\HOME\as\apy\branches\nightly\build\pyhg_branches_release3_1_maint-
win32-x86-hgti
\core.py", line 149, in setup
    dist.run_commands()
  File 
"C:\HOME\as\apy\branches\nightly\build\pyhg_branches_release3_1_maint-
win32-x86-hgti
\dist.py", line 919, in run_commands
    self.run_command(cmd)
  File 
"C:\HOME\as\apy\branches\nightly\build\pyhg_branches_release3_1_maint-
win32-x86-hgti
\dist.py", line 938, in run_command
    cmd_obj.run()
  File "<string>", line 619, in run
  File 
"C:\HOME\as\apy\branches\nightly\build\pyhg_branches_release3_1_maint-
win32-x86-hgti
\command\build.py", line 128, in run
    self.run_command(cmd_name)
  File 
"C:\HOME\as\apy\branches\nightly\build\pyhg_branches_release3_1_maint-
win32-x86-hgti
\cmd.py", line 315, in run_command
    self.distribution.run_command(command)
  File 
"C:\HOME\as\apy\branches\nightly\build\pyhg_branches_release3_1_maint-
win32-x86-hgti
\dist.py", line 938, in run_command
    cmd_obj.run()
  File 
"C:\HOME\as\apy\branches\nightly\build\pyhg_branches_release3_1_maint-
win32-x86-hgti
\command\build_ext.py", line 347, in run
p31-rrun\python\lib\distutils\ccompiler.py", line 791, in 
link_shared_object
    extra_preargs, extra_postargs, build_temp, target_lang)
  File "<string>", line 1384, in link
p31-rrun\python\lib\distutils\msvc9compiler.py", line 663, in link
    manifest_buf = re.sub(pattern, "", manifest_buf)
p31-rrun\python\lib\re.py", line 166, in sub
    return _compile(pattern, flags).sub(repl, string, count)
TypeError: can't use a string pattern on a bytes-like object
msg96764 - (view) Author: Sridhar Ratnakumar (srid) Date: 2009-12-21 19:01
Uh, cmd.exe seemed to have stripped some chars. Here's the full traceback: 
http://gist.github.com/261153
msg96765 - (view) Author: Sridhar Ratnakumar (srid) Date: 2009-12-21 19:47
Correction: I found this in branches/release3.1-maint (not trunk - which I 
never tried)
msg96766 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2009-12-21 20:04
I also raised this issue at the end of issue 4120 (which is closed).
I'll post the diff here, too.
msg96775 - (view) Author: Tarek Ziadé (tarek) * (Python committer) Date: 2009-12-21 22:15
Stefan's patch will do the trick. I am adding a test to make sure this
part is covered before I apply the patch
msg96776 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2009-12-21 22:24
I'd rather prefer if the manifest was opened in text mode. It should be
UTF-8 encoded (although ASCII would work as well).
msg96779 - (view) Author: Tarek Ziadé (tarek) * (Python committer) Date: 2009-12-21 23:02
sure, that's even simpler. I am adding a test and this simple fix.

Notice that this code could be replaced with some code that uses an xml
parser. I find the regexp patterns a bit inappropriate here because it
removes "<dependentAssembly></dependentAssembly>" in a second call, but
may leave an empty "<dependency></dependency>" as far as I understand
msg96780 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2009-12-21 23:05
As for using proper XML processing: that would be fine as well.

As for leaving an empty dependency element: in the original report, MAL
says that this is conforming. I found a schema file (from MS) which
agrees, and a textual documentation page that disagrees. The actual
implementation (atleast in Win7) also seems to agree: the loader would
(apparently) recognize the entire manifest even though it had this empty
dependency in it.
msg96784 - (view) Author: Tarek Ziadé (tarek) * (Python committer) Date: 2009-12-21 23:45
Ok thanks for the detailed info, Martin

I guess we could refactor it to an xml reader/writer if we need to do
more things in the future with these files.

I'll close this issue, as the mentioned problem is now fixed by using a
text mode. The test in test_msvc9compiler will make sure the XML file 
gets cleaned up by the regexp.

- done in r76993, r76995
- backported in r76996 and r76998 so the trunk behaves the same way.
- 2.6 stays unchanged, and keep using a binary mode.

Thanks all !
History
Date User Action Args
2009-12-21 23:45:26tareksetstatus: open -> closed

messages: + msg96784
2009-12-21 23:05:35loewissetmessages: + msg96780
2009-12-21 23:02:01tareksetmessages: + msg96779
2009-12-21 22:24:02loewissetmessages: + msg96776
2009-12-21 22:15:43tareksetnosy: + loewis
messages: + msg96775
2009-12-21 20:04:43skrahsetfiles: + 3.1-byte-string.diff
versions: + Python 3.1
nosy: + skrah

messages: + msg96766

keywords: + patch
2009-12-21 19:47:03sridsetmessages: + msg96765
2009-12-21 19:01:35sridsetmessages: + msg96764
2009-12-21 18:59:17sridcreate