Mercurial > p > roundup > code
comparison roundup/cgi/TAL/TALInterpreter.py @ 1309:309f125f86cc
removed use of string/strop from TAL/TALInterpreter
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Sat, 16 Nov 2002 07:43:22 +0000 |
| parents | b9988e118055 |
| children | 8dc60d87ab42 |
comparison
equal
deleted
inserted
replaced
| 1308:bd71c43f0911 | 1309:309f125f86cc |
|---|---|
| 17 | 17 |
| 18 import sys | 18 import sys |
| 19 import getopt | 19 import getopt |
| 20 | 20 |
| 21 from cgi import escape | 21 from cgi import escape |
| 22 from string import join, lower, rfind | |
| 23 try: | |
| 24 from strop import lower, rfind | |
| 25 except ImportError: | |
| 26 pass | |
| 27 | 22 |
| 28 try: | 23 try: |
| 29 from cStringIO import StringIO | 24 from cStringIO import StringIO |
| 30 except ImportError: | 25 except ImportError: |
| 31 from StringIO import StringIO | 26 from StringIO import StringIO |
| 161 assert self.scopeLevel == 0 | 156 assert self.scopeLevel == 0 |
| 162 if self.col > 0: | 157 if self.col > 0: |
| 163 self._stream_write("\n") | 158 self._stream_write("\n") |
| 164 self.col = 0 | 159 self.col = 0 |
| 165 | 160 |
| 166 def stream_write(self, s, | 161 def stream_write(self, s, len=len): |
| 167 len=len, rfind=rfind): | |
| 168 self._stream_write(s) | 162 self._stream_write(s) |
| 169 i = rfind(s, '\n') | 163 i = s.rfind('\n') |
| 170 if i < 0: | 164 if i < 0: |
| 171 self.col = self.col + len(s) | 165 self.col = self.col + len(s) |
| 172 else: | 166 else: |
| 173 self.col = len(s) - (i + 1) | 167 self.col = len(s) - (i + 1) |
| 174 | 168 |
| 270 # Drop all METAL attributes at a use-depth above one. | 264 # Drop all METAL attributes at a use-depth above one. |
| 271 return 0, name, value | 265 return 0, name, value |
| 272 # Clear 'entering' flag | 266 # Clear 'entering' flag |
| 273 macs[-1][2] = 0 | 267 macs[-1][2] = 0 |
| 274 # Convert or drop depth-one METAL attributes. | 268 # Convert or drop depth-one METAL attributes. |
| 275 i = rfind(name, ":") + 1 | 269 i = name.rfind(":") + 1 |
| 276 prefix, suffix = name[:i], name[i:] | 270 prefix, suffix = name[:i], name[i:] |
| 277 if suffix == "define-macro": | 271 if suffix == "define-macro": |
| 278 # Convert define-macro as we enter depth one. | 272 # Convert define-macro as we enter depth one. |
| 279 name = prefix + "use-macro" | 273 name = prefix + "use-macro" |
| 280 value = macs[-1][0] # Macro name | 274 value = macs[-1][0] # Macro name |
| 294 def attrAction_tal(self, item): | 288 def attrAction_tal(self, item): |
| 295 name, value, action = item[:3] | 289 name, value, action = item[:3] |
| 296 if action > 1: | 290 if action > 1: |
| 297 return self.attrAction(item) | 291 return self.attrAction(item) |
| 298 ok = 1 | 292 ok = 1 |
| 299 if self.html and lower(name) in BOOLEAN_HTML_ATTRS: | 293 if self.html and name.lower() in BOOLEAN_HTML_ATTRS: |
| 300 evalue = self.engine.evaluateBoolean(item[3]) | 294 evalue = self.engine.evaluateBoolean(item[3]) |
| 301 if evalue is self.Default: | 295 if evalue is self.Default: |
| 302 if action == 1: # Cancelled insert | 296 if action == 1: # Cancelled insert |
| 303 ok = 0 | 297 ok = 0 |
| 304 elif evalue: | 298 elif evalue: |
| 422 if text is self.Default: | 416 if text is self.Default: |
| 423 self.interpret(stuff[1]) | 417 self.interpret(stuff[1]) |
| 424 return | 418 return |
| 425 s = escape(text) | 419 s = escape(text) |
| 426 self._stream_write(s) | 420 self._stream_write(s) |
| 427 i = rfind(s, '\n') | 421 i = s.rfind('\n') |
| 428 if i < 0: | 422 if i < 0: |
| 429 self.col = self.col + len(s) | 423 self.col = self.col + len(s) |
| 430 else: | 424 else: |
| 431 self.col = len(s) - (i + 1) | 425 self.col = len(s) - (i + 1) |
| 432 bytecode_handlers["insertText"] = do_insertText | 426 bytecode_handlers["insertText"] = do_insertText |
