diff --git a/wscript b/wscript index 09e57868..24053999 100644 --- a/wscript +++ b/wscript @@ -204,28 +204,29 @@ def process_decorators(body): return "\n".join(accu+all_deco) def sfilter(path): - if sys.version_info[0] >= 3 and Options.options.strip_comments: - f = open(path, "rb") - try: - tk = tokenize.tokenize(f.readline) - next(tk) # the first one is always tokenize.ENCODING for Python 3, ignore it - cnt = process_tokens(tk) - finally: - f.close() - elif Options.options.strip_comments and path.endswith('.py'): - f = open(path, "r") - try: - cnt = process_tokens(tokenize.generate_tokens(f.readline)) - finally: - f.close() - else: - f = open(path, "r") - try: - cnt = f.read() - finally: - f.close() if path.endswith('.py') : + if Options.options.strip_comments: + if sys.version_info[0] >= 3: + f = open(path, "rb") + try: + tk = tokenize.tokenize(f.readline) + next(tk) # the first one is always tokenize.ENCODING for Python 3, ignore it + cnt = process_tokens(tk) + finally: + f.close() + else: + f = open(path, "r") + try: + cnt = process_tokens(tokenize.generate_tokens(f.readline)) + finally: + f.close() + else: + f = open(path, "r") + try: + cnt = f.read() + finally: + f.close() # WARNING: since we now require python 2.4, we do not process the decorators anymore # if you need such a thing, uncomment the code below: #cnt = process_decorators(cnt) @@ -233,6 +234,13 @@ def sfilter(path): # cnt = 'import sys\nif sys.hexversion < 0x020400f0: from sets import Set as set\n' + cnt cnt = '#! /usr/bin/env python\n# encoding: utf-8\n# WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file\n\n' + cnt + else: + f = open(path, "r") + try: + cnt = f.read() + finally: + f.close() + if sys.hexversion > 0x030000f0: return (io.BytesIO(cnt.encode('utf-8')), len(cnt), cnt) return (io.BytesIO(cnt), len(cnt), cnt)