Move configuration to jogobot module

Use custom Error classes
This commit is contained in:
2015-09-15 21:21:05 +02:00
parent db5bb7401e
commit b514eb5c42

View File

@@ -115,13 +115,13 @@ class RedFamParser( RedFam ):
"""
# Define the timestamp format
__timestamp_format = "%H:%M, %d. %b. %Y"
__timestamp_format = jogobot.timestamp_format
# Define section heading re.pattern
__sectionhead_pat = re.compile( r"^(=+)(.*\[\[.+\]\].*\[\[.+\]\].*)\1" )
# Define timestamp re.pattern
__timestamp_pat = re.compile( r"(\d{2}:\d{2}), (\d{1,2}). (Jan|Feb|Mär|Apr|Mai|Jun|Jul|Aug|Sep|Okt|Nov|Dez).? (\d{4})" ) # noqa
__timestamp_pat = re.compile( jogobot.timestamp_regex )
# Textpattern for recognisation of done-notices
__done_notice = ":<small>Archivierung dieses Abschnittes \
@@ -199,11 +199,11 @@ class RedFamParser( RedFam ):
wikilink_pat = re.compile( r"\[\[([^\[\]\|]*)(\]\]|\|)" )
# Parse content of heading for generating section links later
match = self.__sectionhead_pat.search( heading )
match = type( self ).__sectionhead_pat.search( heading )
if match:
self._heading = match.group(2).lstrip()
else:
raise ValueError( "Heading is not valid" )
raise RedFamHeadingError( heading )
# We get the pages in first [0] element iterating over
# wikilink_pat.findall( line )
@@ -424,3 +424,16 @@ class RedFamHashError( RedFamError ):
calc=calculatedHash )
super().__init__( message )
class RedFamHeadingError ( RedFamError ):
"""
Raised when given RedFamHeading does not match __sectionhead_pat Regex
"""
def __init__( self, heading ):
message = "Error while trying to parse section heading. Given heading \
'{heading}' does not match RegEx".format(
heading=heading )
super().__init__( message )