cpython: 740e43eb8138 (original) (raw)

Mercurial > cpython

changeset 103616:740e43eb8138 2.7

Issue #27952: Get fixcid.py working with the re module [#27952]

Martin Panter vadmium+py@gmail.com
date Sun, 11 Sep 2016 09:48:57 +0000
parents afc0d4478083
children 5ca4c545dfe4
files Lib/test/test_tools.py Misc/NEWS Tools/scripts/fixcid.py
diffstat 3 files changed, 106 insertions(+), 14 deletions(-)[+] [-] Lib/test/test_tools.py 83 Misc/NEWS 7 Tools/scripts/fixcid.py 30

line wrap: on

line diff

--- a/Lib/test/test_tools.py +++ b/Lib/test/test_tools.py @@ -5,9 +5,11 @@ Tools directory of a Python checkout or """ import os +import runpy import sys import unittest import shutil +from cStringIO import StringIO import subprocess import sysconfig import tempfile @@ -359,6 +361,87 @@ class PindentTests(unittest.TestCase): self.pindent_test(clean, closed) +class FixcidTests(unittest.TestCase):

+

+

+

+

+ + def test_main(): test_support.run_unittest(*[obj for obj in globals().values() if isinstance(obj, type)])

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -191,6 +191,13 @@ Build

--- a/Tools/scripts/fixcid.py +++ b/Tools/scripts/fixcid.py @@ -88,9 +88,9 @@ def main(): sys.exit(bad)

Change this regular expression to select a different set of files

-Wanted = '^[a-zA-Z0-9_]+.[ch]$' +Wanted = r'^[a-zA-Z0-9_]+.[ch]$' def wanted(name):

def recursedown(dirname): dbg('recursedown(%r)\n' % (dirname,)) @@ -168,6 +168,7 @@ def fix(filename): if filename == '-': return 0 # Done in filter mode f.close() if not g: return 0 # No changes

# Finishing touch -- move files @@ -193,21 +194,21 @@ def fix(filename):

Tokenizing ANSI C (partly)

-Identifier = '(struct )?[a-zA-Z_][a-zA-Z0-9_]+' -String = '"([^\n\"]|\\.)"' -Char = ''([^\n\']|\\.)'' -CommentStart = '/*' -CommentEnd = '*/' +Identifier = '(struct )?[a-zA-Z_][a-zA-Z0-9_]+' +String = r'"([^\n\"]|\.)"' +Char = r"'([^\n\']|\.)'" +CommentStart = r'/*' +CommentEnd = r'*/' Hexnumber = '0[xX][0-9a-fA-F][uUlL]' Octnumber = '0[0-7][uUlL]' Decnumber = '[1-9][0-9][uUlL]' -Intnumber = Hexnumber + '|' + Octnumber + '|' + Decnumber +Intnumber = Hexnumber + '|' + Octnumber + '|' + Decnumber Exponent = '[eE][-+]?[0-9]+' -Pointfloat = '([0-9]+.[0-9]|.[0-9]+)(' + Exponent + ')?' +Pointfloat = r'([0-9]+.[0-9]|.[0-9]+)(' + Exponent + r')?' Expfloat = '[0-9]+' + Exponent -Floatnumber = Pointfloat + '|' + Expfloat -Number = Floatnumber + '|' + Intnumber +Floatnumber = Pointfloat + '|' + Expfloat +Number = Floatnumber + '|' + Intnumber

Anything else is an operator -- don't list this explicitly because of '/*'

@@ -228,9 +229,10 @@ def fixline(line):

 i = 0[](#l3.56)
 while i < len(line):[](#l3.57)

if Program is InsideCommentProgram: print '...',

else: print ' ',