From 3f92751e15669538fa74f387a2f8a8717bb9e348 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Mon, 25 Oct 2010 14:50:13 -0400 Subject: simplify zcml replacement --- pyramid/fixers/fix_bfg_imports.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pyramid/fixers/fix_bfg_imports.py b/pyramid/fixers/fix_bfg_imports.py index e53973469..94327cd4b 100644 --- a/pyramid/fixers/fix_bfg_imports.py +++ b/pyramid/fixers/fix_bfg_imports.py @@ -167,22 +167,26 @@ class FixBfgImports(fixer_base.BaseFix): if new_name: node.replace(Name(new_name, prefix=bare_name.prefix)) -BFG_INCLUDES_RE = ( - r'include\s+?package\s*?=\s*?[\'\"]repoze\.bfg\.includes[\'\"]') BFG_NS_RE = ( r'xmlns\s*?=\s*?[\'\"]http://namespaces\.repoze\.org/bfg[\'\"]') +BFG_IN_ATTR = ( + r'[\'\"]\s*?(repoze\.bfg)(.*?)[\'\"]') -INCLUDES = re.compile(BFG_INCLUDES_RE, re.MULTILINE) + +ATTR = re.compile(BFG_IN_ATTR, re.MULTILINE) NS = re.compile(BFG_NS_RE, re.MULTILINE) +def replace(match): + return '"pyramid%s"' % match.group(2) + def fix_zcml(path): for root, dirs, files in os.walk(path): for file in files: if file.endswith('.zcml'): absfile = os.path.join(root, file) text = open(absfile, 'rb').read() - newt =INCLUDES.sub('include package="pyramid.includes"', text) - newt = NS.sub('xmlns="http://pylonshq.com/pyramid"', newt) + newt = NS.sub('xmlns="http://pylonshq.com/pyramid"', text) + newt = ATTR.sub(replace, newt) if text != newt: newf = open(absfile, 'wb') newf.write(newt) -- cgit v1.2.3