Ticket #648: comment_tag.diff
File comment_tag.diff, 2.3 KB (added by , 18 years ago) |
---|
-
__init__.py
66 66 TOKEN_TEXT = 0 67 67 TOKEN_VAR = 1 68 68 TOKEN_BLOCK = 2 69 TOKEN_COMMENT = 3 69 70 70 71 # template syntax constants 71 72 FILTER_SEPARATOR = '|' 72 73 FILTER_ARGUMENT_SEPARATOR = ':' 73 74 VARIABLE_ATTRIBUTE_SEPARATOR = '.' 75 COMMENT_TAG_START = '{#' 76 COMMENT_TAG_END = '#}' 74 77 BLOCK_TAG_START = '{%' 75 78 BLOCK_TAG_END = '%}' 76 79 VARIABLE_TAG_START = '{{' … … 85 88 UNKNOWN_SOURCE="<unknown source>" 86 89 87 90 # match a variable or block tag and capture the entire tag, including start/end delimiters 88 tag_re = re.compile('(%s.*?%s|%s.*?%s)' % (re.escape(BLOCK_TAG_START), re.escape(BLOCK_TAG_END), 89 re.escape(VARIABLE_TAG_START), re.escape(VARIABLE_TAG_END))) 91 tag_re = re.compile('(%s.*?%s|%s.*?%s|%s.*?%s)' % (re.escape(BLOCK_TAG_START), re.escape(BLOCK_TAG_END), 92 re.escape(VARIABLE_TAG_START), re.escape(VARIABLE_TAG_END), 93 re.escape(COMMENT_TAG_START), re.escape(COMMENT_TAG_END))) 90 94 91 95 # global dictionary of libraries that have been loaded using get_library 92 96 libraries = {} … … 163 167 164 168 class Token(object): 165 169 def __init__(self, token_type, contents): 166 "The token_type must be TOKEN_TEXT, TOKEN_VAR or TOKEN_BLOCK"170 "The token_type must be TOKEN_TEXT, TOKEN_VAR, TOKEN_BLOCK, or TOKEN_COMMENT" 167 171 self.token_type, self.contents = token_type, contents 168 172 169 173 def __str__(self): 170 174 return '<%s token: "%s...">' % \ 171 ({TOKEN_TEXT: 'Text', TOKEN_VAR: 'Var', TOKEN_BLOCK: 'Block' }[self.token_type],175 ({TOKEN_TEXT: 'Text', TOKEN_VAR: 'Var', TOKEN_BLOCK: 'Block', TOKEN_COMMENT: 'Comment'}[self.token_type], 172 176 self.contents[:20].replace('\n', '')) 173 177 174 178 def split_contents(self): … … 191 195 token = Token(TOKEN_VAR, token_string[len(VARIABLE_TAG_START):-len(VARIABLE_TAG_END)].strip()) 192 196 elif token_string.startswith(BLOCK_TAG_START): 193 197 token = Token(TOKEN_BLOCK, token_string[len(BLOCK_TAG_START):-len(BLOCK_TAG_END)].strip()) 198 elif token_string.startswith(COMMENT_TAG_START): 199 token = Token(TOKEN_COMMENT, '') 194 200 else: 195 201 token = Token(TOKEN_TEXT, token_string) 196 202 return token