This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: TypeError: can't use a string pattern on a bytes-like object
Type: behavior Stage:
Components: Distutils Versions: Python 3.1, Python 3.2
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 2022-04-11 14:56 by admin. This issue is now closed.

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 

   Creating library build\temp.win32-
3.1\Release\win32\src\pywintypes31.lib and object buil
Traceback (most recent call last):
  File "", line 16, in <module>
  File "<string>", line 2194, in <module>
\", line 149, in setup
\", line 919, in run_commands
\", line 938, in run_command
  File "<string>", line 619, in run
\command\", line 128, in run
\", line 315, in run_command
\", line 938, in run_command
\command\", line 347, in run
p31-rrun\python\lib\distutils\", line 791, in 
    extra_preargs, extra_postargs, build_temp, target_lang)
  File "<string>", line 1384, in link
p31-rrun\python\lib\distutils\", line 663, in link
    manifest_buf = re.sub(pattern, "", manifest_buf)
p31-rrun\python\lib\", 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:
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 !
Date User Action Args
2022-04-11 14:56:55adminsetgithub: 51805
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