Parcourir la source

Rename some things, fixes, strip()

tags/v0.1
Ben Kurtovic il y a 12 ans
Parent
révision
d9c4b4f765
2 fichiers modifiés avec 12 ajouts et 9 suppressions
  1. +3
    -3
      mwparserfromhell/nodes/template.py
  2. +9
    -6
      mwparserfromhell/string_mixin.py

+ 3
- 3
mwparserfromhell/nodes/template.py Voir le fichier

@@ -59,14 +59,14 @@ class Template(Node):
return True return True
return False return False


def get_param(self, name):
def get(self, name):
name = name.strip() if isinstance(name, basestring) else unicode(name) name = name.strip() if isinstance(name, basestring) else unicode(name)
for param in self.params: for param in self.params:
if param.name.strip() == name: if param.name.strip() == name:
return param return param
raise ValueError(name) raise ValueError(name)


def add_param(self, name, value, showkey=None):
def add(self, name, value, showkey=None):
name, value = parse_anything(name), parse_anything(value) name, value = parse_anything(name), parse_anything(value)
surface_text = value.filter_text(recursive=False) surface_text = value.filter_text(recursive=False)
for node in surface_text: for node in surface_text:
@@ -93,7 +93,7 @@ class Template(Node):
else: else:
self.params.append(Parameter(name, value, showkey)) # CONFORM TO FORMATTING CONVENTIONS? self.params.append(Parameter(name, value, showkey)) # CONFORM TO FORMATTING CONVENTIONS?


def remove_param(self, name, keep_field=False): # DON'T MESS UP NUMBERING WITH show_key = False AND keep_field = False
def remove(self, name, keep_field=False): # DON'T MESS UP NUMBERING WITH show_key = False AND keep_field = False
name = name.strip() if isinstance(name, basestring) else unicode(name) name = name.strip() if isinstance(name, basestring) else unicode(name)
for param in self.params: for param in self.params:
if param.name.strip() == name: if param.name.strip() == name:


+ 9
- 6
mwparserfromhell/string_mixin.py Voir le fichier

@@ -33,32 +33,32 @@ class StringMixIn(object):
raise NotImplementedError() raise NotImplementedError()


def __lt__(self, other): def __lt__(self, other):
if isinstance(other, StringMixin):
if isinstance(other, StringMixIn):
return unicode(self) < unicode(other) return unicode(self) < unicode(other)
return unicode(self) < other return unicode(self) < other


def __le__(self, other): def __le__(self, other):
if isinstance(other, StringMixin):
if isinstance(other, StringMixIn):
return unicode(self) <= unicode(other) return unicode(self) <= unicode(other)
return unicode(self) <= other return unicode(self) <= other


def __eq__(self, other): def __eq__(self, other):
if isinstance(other, StringMixin):
if isinstance(other, StringMixIn):
return unicode(self) == unicode(other) return unicode(self) == unicode(other)
return unicode(self) == other return unicode(self) == other


def __ne__(self, other): def __ne__(self, other):
if isinstance(other, StringMixin):
if isinstance(other, StringMixIn):
return unicode(self) != unicode(other) return unicode(self) != unicode(other)
return unicode(self) != other return unicode(self) != other


def __gt__(self, other): def __gt__(self, other):
if isinstance(other, StringMixin):
if isinstance(other, StringMixIn):
return unicode(self) > unicode(other) return unicode(self) > unicode(other)
return unicode(self) > other return unicode(self) > other


def __ge__(self, other): def __ge__(self, other):
if isinstance(other, StringMixin):
if isinstance(other, StringMixIn):
return unicode(self) >= unicode(other) return unicode(self) >= unicode(other)
return unicode(self) >= other return unicode(self) >= other


@@ -82,3 +82,6 @@ class StringMixIn(object):


def replace(self, old, new, count): def replace(self, old, new, count):
return unicode(self).replace(old, new, count) return unicode(self).replace(old, new, count)

def strip(self, chars=None):
return unicode(self).strip(chars)

Chargement…
Annuler
Enregistrer