Explorar el Código

Merge pull request #64 from marciof/develop

Token creation speedup
tags/v0.3.3
Ben Kurtovic hace 10 años
padre
commit
f94031c248
Se han modificado 1 ficheros con 9 adiciones y 11 borrados
  1. +9
    -11
      mwparserfromhell/parser/tokens.py

+ 9
- 11
mwparserfromhell/parser/tokens.py Ver fichero

@@ -34,15 +34,12 @@ from ..compat import py3k, str

__all__ = ["Token"]

class Token(object):
class Token (dict):
"""A token stores the semantic meaning of a unit of wikicode."""

def __init__(self, **kwargs):
super(Token, self).__setattr__("_kwargs", kwargs)

def __repr__(self):
args = []
for key, value in self._kwargs.items():
for key, value in self.items():
if isinstance(value, str) and len(value) > 100:
args.append(key + "=" + repr(value[:97] + "..."))
else:
@@ -50,18 +47,19 @@ class Token(object):
return "{0}({1})".format(type(self).__name__, ", ".join(args))

def __eq__(self, other):
if isinstance(other, type(self)):
return self._kwargs == other._kwargs
return False
return isinstance(other, type(self)) and dict.__eq__(self, other)

def __ne__(self, other):
return not self.__eq__(other)

def __getattr__(self, key):
return self._kwargs.get(key)
return self.get(key)

def __setattr__(self, key, value):
self._kwargs[key] = value
self[key] = value

def __delattr__(self, key):
del self._kwargs[key]
del self[key]


def make(name):


Cargando…
Cancelar
Guardar