Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1060)

Side by Side Diff: third_party/google-endpoints/libpasteurize/fixes/feature_base.py

Issue 2666783008: Add google-endpoints to third_party/. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 u"""
2 Base classes for features that are backwards-incompatible.
3
4 Usage:
5 features = Features()
6 features.add(Feature("py3k_feature", "power< 'py3k' any* >", "2.7"))
7 PATTERN = features.PATTERN
8 """
9
10 pattern_unformatted = u"%s=%s" # name=pattern, for dict lookups
11 message_unformatted = u"""
12 %s is only supported in Python %s and above."""
13
14 class Feature(object):
15 u"""
16 A feature has a name, a pattern, and a minimum version of Python 2.x
17 required to use the feature (or 3.x if there is no backwards-compatible
18 version of 2.x)
19 """
20 def __init__(self, name, PATTERN, version):
21 self.name = name
22 self._pattern = PATTERN
23 self.version = version
24
25 def message_text(self):
26 u"""
27 Format the above text with the name and minimum version required.
28 """
29 return message_unformatted % (self.name, self.version)
30
31 class Features(set):
32 u"""
33 A set of features that generates a pattern for the features it contains.
34 This set will act like a mapping in that we map names to patterns.
35 """
36 mapping = {}
37
38 def update_mapping(self):
39 u"""
40 Called every time we care about the mapping of names to features.
41 """
42 self.mapping = dict([(f.name, f) for f in iter(self)])
43
44 @property
45 def PATTERN(self):
46 u"""
47 Uses the mapping of names to features to return a PATTERN suitable
48 for using the lib2to3 patcomp.
49 """
50 self.update_mapping()
51 return u" |\n".join([pattern_unformatted % (f.name, f._pattern) for f in iter(self)])
52
53 def __getitem__(self, key):
54 u"""
55 Implement a simple mapping to get patterns from names.
56 """
57 return self.mapping[key]
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698