comparison genshi/path.py @ 854:0d9e87c6cf6e

More work on reducing the size of the diff produced by 2to3.
author cmlenz
date Tue, 10 Nov 2009 22:53:21 +0000
parents 4376010bb97e
children 1e2be9fb3348
comparison
equal deleted inserted replaced
853:4376010bb97e 854:0d9e87c6cf6e
1 # -*- coding: utf-8 -*- 1 # -*- coding: utf-8 -*-
2 # 2 #
3 # Copyright (C) 2006-2008 Edgewall Software 3 # Copyright (C) 2006-2009 Edgewall Software
4 # All rights reserved. 4 # All rights reserved.
5 # 5 #
6 # This software is licensed as described in the file COPYING, which 6 # This software is licensed as described in the file COPYING, which
7 # you should have received as part of this distribution. The terms 7 # you should have received as part of this distribution. The terms
8 # are also available at http://genshi.edgewall.org/wiki/License. 8 # are also available at http://genshi.edgewall.org/wiki/License.
276 # pi[i] = NORMAL_PI[i + 1] 276 # pi[i] = NORMAL_PI[i + 1]
277 if len(f) == 0: 277 if len(f) == 0:
278 return [] 278 return []
279 pi = [0] 279 pi = [0]
280 s = 0 280 s = 0
281 for i in xrange(1, len(f)): 281 for i in range(1, len(f)):
282 while s > 0 and not nodes_equal(f[s], f[i]): 282 while s > 0 and not nodes_equal(f[s], f[i]):
283 s = pi[s-1] 283 s = pi[s-1]
284 if nodes_equal(f[s], f[i]): 284 if nodes_equal(f[s], f[i]):
285 s += 1 285 s += 1
286 pi.append(s) 286 pi.append(s)
535 for strategy_class in self.STRATEGIES: 535 for strategy_class in self.STRATEGIES:
536 if strategy_class.supports(path): 536 if strategy_class.supports(path):
537 self.strategies.append(strategy_class(path)) 537 self.strategies.append(strategy_class(path))
538 break 538 break
539 else: 539 else:
540 raise NotImplemented, "This path is not implemented" 540 raise NotImplemented('No strategy found for path')
541 541
542 def __repr__(self): 542 def __repr__(self):
543 paths = [] 543 paths = []
544 for path in self.paths: 544 for path in self.paths:
545 steps = [] 545 steps = []
665 ''.join([re.escape(t[0]) for t in _TOKENS]))).findall 665 ''.join([re.escape(t[0]) for t in _TOKENS]))).findall
666 666
667 def __init__(self, text, filename=None, lineno=-1): 667 def __init__(self, text, filename=None, lineno=-1):
668 self.filename = filename 668 self.filename = filename
669 self.lineno = lineno 669 self.lineno = lineno
670 self.tokens = filter(None, [dqstr or sqstr or number or token or name 670 self.tokens = [t for t in [dqstr or sqstr or number or token or name
671 for dqstr, sqstr, number, token, name in 671 for dqstr, sqstr, number, token, name in
672 self._tokenize(text)]) 672 self._tokenize(text)] if t]
673 self.pos = 0 673 self.pos = 0
674 674
675 # Tokenizer 675 # Tokenizer
676 676
677 @property 677 @property
Copyright (C) 2012-2017 Edgewall Software