Mercurial > genshi > mirror
comparison markup/core.py @ 73:1da51d718391 trunk
Some more performance tweaks.
author | cmlenz |
---|---|
date | Wed, 12 Jul 2006 18:47:39 +0000 |
parents | c40a5dcd2b55 |
children | f5ec6d4a61e4 |
comparison
equal
deleted
inserted
replaced
72:ee092ccb3af1 | 73:1da51d718391 |
---|---|
295 | 295 |
296 If the `quotes` parameter is set to `False`, the \" character is left | 296 If the `quotes` parameter is set to `False`, the \" character is left |
297 as is. Escaping quotes is generally only required for strings that are | 297 as is. Escaping quotes is generally only required for strings that are |
298 to be used in attribute values. | 298 to be used in attribute values. |
299 """ | 299 """ |
300 if isinstance(text, cls): | 300 if not text: |
301 return cls() | |
302 if type(text) is cls: | |
301 return text | 303 return text |
302 text = unicode(text) | 304 text = unicode(text).replace('&', '&') \ |
303 if not text or isinstance(text, cls): | 305 .replace('<', '<') \ |
304 return cls() | 306 .replace('>', '>') |
305 text = text.replace('&', '&') \ | |
306 .replace('<', '<') \ | |
307 .replace('>', '>') | |
308 if quotes: | 307 if quotes: |
309 text = text.replace('"', '"') | 308 text = text.replace('"', '"') |
310 return cls(text) | 309 return cls(text) |
311 escape = classmethod(escape) | 310 escape = classmethod(escape) |
312 | 311 |
395 return self.uri == other.uri | 394 return self.uri == other.uri |
396 return self.uri == other | 395 return self.uri == other |
397 | 396 |
398 def __getitem__(self, name): | 397 def __getitem__(self, name): |
399 return QName(self.uri + u'}' + name) | 398 return QName(self.uri + u'}' + name) |
400 | |
401 __getattr__ = __getitem__ | 399 __getattr__ = __getitem__ |
402 | 400 |
403 def __repr__(self): | 401 def __repr__(self): |
404 return '<Namespace "%s">' % self.uri | 402 return '<Namespace "%s">' % self.uri |
405 | 403 |