diff options
| author | Michael Merickel <michael@merickel.org> | 2011-07-06 02:28:24 -0500 |
|---|---|---|
| committer | Michael Merickel <michael@merickel.org> | 2011-07-06 02:28:47 -0500 |
| commit | 648a9ee498dc1a02ab79bc4e29dcb1d2b1697e45 (patch) | |
| tree | a7467cf22e0d6ec9382ebbb1de962a4ac2fd9e02 | |
| parent | 26d135bae9aa1b24774a76053b22e9202e0421bb (diff) | |
| download | pyramid-648a9ee498dc1a02ab79bc4e29dcb1d2b1697e45.tar.gz pyramid-648a9ee498dc1a02ab79bc4e29dcb1d2b1697e45.tar.bz2 pyramid-648a9ee498dc1a02ab79bc4e29dcb1d2b1697e45.zip | |
Replaced the manual parsing with python's ConfigParser.
| -rw-r--r-- | pyramid/paster.py | 41 |
1 files changed, 7 insertions, 34 deletions
diff --git a/pyramid/paster.py b/pyramid/paster.py index 2e732bce4..0360a57bb 100644 --- a/pyramid/paster.py +++ b/pyramid/paster.py @@ -2,11 +2,11 @@ import os import re import sys from code import interact +from ConfigParser import ConfigParser import zope.deprecation from paste.deploy import loadapp -from paste.script.command import BadCommand from paste.script.command import Command from pyramid.scripting import get_root @@ -82,44 +82,17 @@ class PShellCommand(PCommand): dest='disable_ipython', help="Don't use IPython even if it is available") - _pshell_section_re = re.compile(r'^\s*\[\s*pshell\s*\]\s*$') - _section_re = re.compile(r'^\s*\[') + ConfigParser = ConfigParser # testing def pshell_file_config(self, filename): - vars = { - 'here': os.path.dirname(filename), - '__file__': filename, - } - f = open(filename) - lines = f.readlines() - f.close() - lineno = 1 - # find the pshell section - while lines: - if self._pshell_section_re.search(lines[0]): - lines.pop(0) - break - lines.pop(0) - lineno += 1 - # parse pshell section for key/value pairs resolver = DottedNameResolver(None) self.loaded_objects = {} self.object_help = {} - for line in lines: - lineno += 1 - line = line.strip() - if not line or line.startswith('#'): - continue - if self._section_re.search(line): - break - if '=' not in line: - raise BadCommand('Missing = in %s at %s: %r' - % (filename, lineno, line)) - name, value = line.split('=', 1) - name = name.strip() - value = value.strip() % vars - self.loaded_objects[name] = resolver.maybe_resolve(value) - self.object_help[name] = value + config = ConfigParser() + config.read(filename) + for k, v in config.items('pshell'): + self.loaded_objects[k] = resolver.maybe_resolve(v) + self.object_help[k] = v def command(self, IPShell=_marker): # IPShell passed to command method is for testing purposes |
