diff options
author | Stuart Rackham <srackham@methods.co.nz> | 2012-07-10 14:34:36 +1200 |
---|---|---|
committer | Stuart Rackham <srackham@methods.co.nz> | 2012-07-10 14:34:36 +1200 |
commit | 51ed824032039e3aabb306fad9a4ee45ab1d1fb8 (patch) | |
tree | 42901ff14898e914412b1bf07026e543add90d83 | |
parent | 2e5863118c36b703417119515e8bf6086e57d9d6 (diff) | |
download | asciidoc-51ed824032039e3aabb306fad9a4ee45ab1d1fb8.tar.gz |
- Increased default maxiumum include depth from 5 to 10.
- Emit warning if maximum include depth is exceeded.
- Suppress repeated console messages.
-rwxr-xr-x | asciidoc.py | 14 | ||||
-rw-r--r-- | doc/asciidoc.txt | 2 |
2 files changed, 10 insertions, 6 deletions
diff --git a/asciidoc.py b/asciidoc.py index c91c544..03d660e 100755 --- a/asciidoc.py +++ b/asciidoc.py @@ -174,14 +174,18 @@ class Message: # argument. Has no effect when set to None. self.linenos = None self.messages = [] + self.prev_msg = '' def stdout(self,msg): print msg def stderr(self,msg=''): + if msg == self.prev_msg: # Suppress repeated messages. + return self.messages.append(msg) if __name__ == '__main__': sys.stderr.write('%s: %s%s' % (self.PROG, msg, os.linesep)) + self.prev_msg = msg def verbose(self, msg,linenos=True): if config.verbose: @@ -4087,7 +4091,7 @@ class Reader1: self.parent = None # Included reader's parent reader. self._lineno = 0 # The last line read from file object f. self.current_depth = 0 # Current include depth. - self.max_depth = 5 # Initial maxiumum allowed include depth. + self.max_depth = 10 # Initial maxiumum allowed include depth. self.bom = None # Byte order mark (BOM). self.infile = None # Saved document 'infile' attribute. self.indir = None # Saved document 'indir' attribute. @@ -4153,6 +4157,7 @@ class Reader1: warnings = attrs.get('warnings', True) # Don't process include macro once the maximum depth is reached. if self.current_depth >= self.max_depth: + message.warning('maximum include depth exceeded') return result # Perform attribute substitution on include macro file name. fname = subs_attrs(mo.group('target')) @@ -4193,7 +4198,7 @@ class Reader1: try: val = int(attrs['tabsize']) if not val >= 0: - raise ValueError, "not >= 0" + raise ValueError, 'not >= 0' self.tabsize = val except ValueError: raise EAsciiDoc, 'illegal include macro tabsize argument' @@ -4203,11 +4208,10 @@ class Reader1: try: val = int(attrs['depth']) if not val >= 1: - raise ValueError, "not >= 1" + raise ValueError, 'not >= 1' self.max_depth = self.current_depth + val except ValueError: - raise EAsciiDoc, 'illegal include macro depth argument' - + raise EAsciiDoc, "include macro: illegal 'depth' argument" # Process included file. message.verbose('include: ' + fname, linenos=False) self.open(fname) diff --git a/doc/asciidoc.txt b/doc/asciidoc.txt index af64866..90ccdd3 100644 --- a/doc/asciidoc.txt +++ b/doc/asciidoc.txt @@ -2799,7 +2799,7 @@ headers. Example: subsequent nested includes (not applicable to `include1` macro which does not process nested includes). Setting 'depth' to '1' disables nesting inside the included file. By default, nesting is limited to - a depth of five. + a depth of ten. - If the he 'warnings' attribute is set to 'False' (or any other Python literal that evaluates to boolean false) then no warning message is printed if the included file does not exist. By default 'warnings' |