[Python-Dev] Null bytes in source code
Tim Peters
tim@zope.com
Tue, 25 Sep 2001 17:50:55 -0400
[Greg Ward]
> Weird: in the current CVS, certain files in Lib have null bytes (ASCII
> 0) in them. Install-time byte-compilation complains about this, so
> "make install" fails.
>
> Eg. here's what "less Lib/reconvert.py" shows me me:
>
> ------------------------------------------------------------------------
> #! /usr/bin/env python1.5
>
> r"""Convert old ("regex") regular expressions to new syntax ("re").
>
> When imported as a module, there are two functions, with their own
> strings:
>
> convert(s, syntax=None) -- convert a regex regular expression
> to re syntax
>
> ^@^@^@^@te(s) -- return a quoted string literal
> [...]
> ------------------------------------------------------------------------
>
> Those "^@"'s are really ASCII 0 -- I checked with "od -c".
>
> Am I on drugs here?
This is a problem with running on a system other than Windows <wink>. I get
this output from the attached program:
checking .py files in C:\Code\python\Lib
checked 165 files
checking .py files in C:\Code\python\Lib\test
checked 201 files
import os
dir = os.getcwd()
print "checking .py files in", dir
count = 0
for fname in os.listdir(dir):
if fname.endswith('.py'):
count += 1
f = file(fname, 'rb')
guts = f.read()
i = guts.find('\x00')
if i >= 0:
print "Whoa! Null byte at offset", i, "in", fname
f.close()
print "checked", count, "files"
no-nulls-under-a-real-os-ly y'rs - tim