Commit 095c7541 by Gabriel Falcao

refactoring @jssevestre's pull request

parent bcbe832f
...@@ -86,21 +86,12 @@ class Language(object): ...@@ -86,21 +86,12 @@ class Language(object):
return '<Language "%s">' % self.code return '<Language "%s">' % self.code
def __getattr__(self, attr): def __getattr__(self, attr):
pattern = [u'first_of_', u'last_of'] for pattern in [ur'^first_of_', ur'^last_of']:
if re.match(pattern, attr):
name = re.sub(pattern, u'', attr)
return unicode(getattr(self, name, u'').split(u"|")[0])
if not re.match(u"(.*)_of_(.*)", attr): return super(Language, self).__getattribute__(attr)
return super(Language, self).__getattribute__(attr)
elif re.match(u'%s' % pattern[0], attr):
name = re.sub(r'^first_of_', u'', attr)
return unicode(getattr(self, name, u'').split(u"|")[0])
elif re.match(u'%s' %pattern[1], attr):
name = re.sub(r'^last_of_', u'', attr)
return unicode(getattr(self, name, u'').split(u"|")[-1])
else:
# raise exception
pass
@property @property
def non_capturable_scenario_separator(self): def non_capturable_scenario_separator(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment