Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
c9423109
Commit
c9423109
authored
Feb 22, 2011
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Factor-out common code for helper classes.
parent
16fe75e4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
4 additions
and
20 deletions
+4
-20
Lib/collections/__init__.py
Lib/collections/__init__.py
+1
-1
Lib/string.py
Lib/string.py
+3
-19
No files found.
Lib/collections/__init__.py
View file @
c9423109
...
...
@@ -633,7 +633,7 @@ class Counter(dict):
########################################################################
### ChainMap (helper for configparser)
### ChainMap (helper for configparser
and string.Template
)
########################################################################
class
_ChainMap
(
MutableMapping
):
...
...
Lib/string.py
View file @
c9423109
...
...
@@ -46,23 +46,7 @@ def capwords(s, sep=None):
####################################################################
import re as _re
class _multimap:
"""
Helper
class
for
combining
multiple
mappings
.
Used
by
.{
safe_
,}
substitute
()
to
combine
the
mapping
and
keyword
arguments
.
"""
def __init__(self, primary, secondary):
self._primary = primary
self._secondary = secondary
def __getitem__(self, key):
try:
return self._primary[key]
except KeyError:
return self._secondary[key]
from collections import _ChainMap
class _TemplateMetaclass(type):
pattern = r"""
...
...
@@ -116,7 +100,7 @@ class Template(metaclass=_TemplateMetaclass):
if not args:
mapping = kws
elif kws:
mapping = _
multim
ap(kws, args[0])
mapping = _
ChainM
ap(kws, args[0])
else:
mapping = args[0]
# Helper function for .sub()
...
...
@@ -142,7 +126,7 @@ class Template(metaclass=_TemplateMetaclass):
if not args:
mapping = kws
elif kws:
mapping = _
multim
ap(kws, args[0])
mapping = _
ChainM
ap(kws, args[0])
else:
mapping = args[0]
# Helper function for .sub()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment