diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2015-07-15 17:11:51 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2015-07-15 17:11:51 +0300 |
commit | b3aa1433e6cd41cdb3a6212ad60d5468d6f6d649 (patch) | |
tree | 0cddac3febd3c9d5a0de1dc4681d0836ce3ff93d | |
parent | 288d3c09c06af73ca6413b9692c06d379de319b1 (diff) | |
download | wit-b3aa1433e6cd41cdb3a6212ad60d5468d6f6d649.tar.gz wit-b3aa1433e6cd41cdb3a6212ad60d5468d6f6d649.tar.bz2 |
Get rid of globals
* wikimarkup.py (delim,otag,ctag)
(refstart): Now class attributes
-rw-r--r-- | wikimarkup.py | 73 |
1 files changed, 31 insertions, 42 deletions
diff --git a/wikimarkup.py b/wikimarkup.py index b765594..18e9a21 100644 --- a/wikimarkup.py +++ b/wikimarkup.py @@ -21,24 +21,23 @@ from types import * -__all__ = [ "BaseWikiMarkup", "WikiMarkup", - "envtypes" ] +__all__ = [ "BaseWikiMarkup", "WikiMarkup" ] -delim = re.compile("^==+|==+[ \\t]*$|(^----$)|^\\*+|^#+|^[;:]+|(\\[\\[)|\\[|(\\{\\{)|(\\]\\])|\\]|(\\}\\})|\\||(\\'\\'\\'?)|<") -otag = re.compile("<(?P<tag>[a-zA-Z0-9_]+)(?:\s+(?P<args>.+))?\s*(?P<closed>/)?>") -ctag = re.compile("</(?P<tag>[a-zA-Z0-9_]+)\s*>") -refstart = re.compile("^https?://") +class BaseWikiMarkup(object): + + delim = re.compile("^==+|==+[ \\t]*$|(^----$)|^\\*+|^#+|^[;:]+|(\\[\\[)|\\[|(\\{\\{)|(\\]\\])|\\]|(\\}\\})|\\||(\\'\\'\\'?)|<") + otag = re.compile("<(?P<tag>[a-zA-Z0-9_]+)(?:\s+(?P<args>.+))?\s*(?P<closed>/)?>") + ctag = re.compile("</(?P<tag>[a-zA-Z0-9_]+)\s*>") + refstart = re.compile("^https?://") -close_delim = { - '[': ']', - '[[': ']]', - '{{': '}}' -} - -# Environment types: -envtypes = { "*": [ "unnumbered", 0 ], - "#": [ "numbered", 0 ], - ";": [ "defn", 0 ], - ":": [ "defn", 1 ] - } + close_delim = { + '[': ']', + '[[': ']]', + '{{': '}}' + } -class BaseWikiMarkup(object): + # Environment types: + envtypes = { "*": [ "unnumbered", 0 ], + "#": [ "numbered", 0 ], + ";": [ "defn", 0 ], + ":": [ "defn", 1 ] + } @@ -158,12 +157,2 @@ class BaseWikiMarkup(object): - def rettext(self, text): - if text[-1] == '\n': - if text[0:-1] != '': - yield({ 'type': 'TEXT', - 'content': text[0:-1] }) - yield({ 'type': 'NL', - 'content': '\n' }) - else: - yield({ 'type': 'TEXT', 'content': text }) - def tokread(self): @@ -189,3 +178,3 @@ class BaseWikiMarkup(object): self.dprint(100, "LINE: %s", line[pos:]) - m = delim.search(line, pos) + m = self.delim.search(line, pos) @@ -198,3 +187,3 @@ class BaseWikiMarkup(object): if line[m.start(0)] == '<': - m = otag.match(line, pos) + m = self.otag.match(line, pos) if m: @@ -205,3 +194,3 @@ class BaseWikiMarkup(object): try: - m = ctag.match(line) + m = self.ctag.match(line) if m and m.group('tag') == 'nowiki': @@ -230,3 +219,3 @@ class BaseWikiMarkup(object): else: - m = ctag.match(line, pos) + m = self.ctag.match(line, pos) if m: @@ -245,3 +234,3 @@ class BaseWikiMarkup(object): content = m.group(0) - if content[0] in envtypes: + if content[0] in self.envtypes: t = { 'type': 'DELIM', @@ -426,3 +415,3 @@ class BaseWikiMarkup(object): self.dprint(80, "ENTER parse_ref, tok %s", tok) - if not (tok['type'] == 'TEXT' and refstart.match(tok['content'])): + if not (tok['type'] == 'TEXT' and self.refstart.match(tok['content'])): self.dprint(80, "LEAVE parse_ref=None") @@ -489,4 +478,4 @@ class BaseWikiMarkup(object): od = tok['content'] - if od in close_delim: - cd = close_delim[od] + if od in self.close_delim: + cd = self.close_delim[od] lev = 0 @@ -633,4 +622,4 @@ class BaseWikiMarkup(object): if tok['type'] == 'DELIM' \ - and tok['content'][0] in envtypes \ - and type == envtypes[tok['content'][0]][0]: + and tok['content'][0] in self.envtypes \ + and type == self.envtypes[tok['content'][0]][0]: if len(tok['content']) < lev: @@ -645,3 +634,3 @@ class BaseWikiMarkup(object): list.append({ 'type': 'ELT', - 'subtype': envtypes[tok['content'][0]][1], + 'subtype': self.envtypes[tok['content'][0]][1], 'content': elt }) @@ -717,4 +706,4 @@ class BaseWikiMarkup(object): return self.parse_header(tok['content']) - elif tok['content'][0] in envtypes: - type = envtypes[tok['content'][0]][0] + elif tok['content'][0] in self.envtypes: + type = self.envtypes[tok['content'][0]][0] lev = len(tok['content']) |