Parcourir la source

Merge pull request #64 from marciof/develop

Token creation speedup
tags/v0.3.3
Ben Kurtovic il y a 10 ans
Parent
révision
f94031c248
1 fichiers modifiés avec 9 ajouts et 11 suppressions
  1. +9
    -11
      mwparserfromhell/parser/tokens.py

+ 9
- 11
mwparserfromhell/parser/tokens.py Voir le fichier

@@ -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):


Chargement…
Annuler
Enregistrer