Added exception and handler for non-alphabetic words in the
creator. This prevents creating words in the grid with numbers
or non-alphabetic symbols.
self.word = word
self.length = length
self.word = word
self.length = length
+# exception for words containing non-alpha characters
+class WordCharsException (Exception):
+ def __init__ (self, word):
+ self.word = word
+
# exception for intersecting words
class IntersectWordException (Exception):
def __init__ (self, word, length):
# exception for intersecting words
class IntersectWordException (Exception):
def __init__ (self, word, length):
# if the grid is frozen then abort
self.assert_unfrozen_grid ()
# if the grid is frozen then abort
self.assert_unfrozen_grid ()
+ # if the word has non-alphabetic characters
+ if not word.isalpha ():
+ raise WordCharsException (word)
+
# if the word length greater than totalrows - startrow
if len(word) > self.rows - row:
raise TooLongWordException (word, len(word))
# if the word length greater than totalrows - startrow
if len(word) > self.rows - row:
raise TooLongWordException (word, len(word))
# if the grid is frozen then abort
self.assert_unfrozen_grid ()
# if the grid is frozen then abort
self.assert_unfrozen_grid ()
+ # if the word has non-alphabetic characters
+ if not word.isalpha ():
+ raise WordCharsException (word)
+
# is the word length greater than totalcols - startcol?
if len(word) > self.cols - col:
raise TooLongWordException (word, len(word))
# is the word length greater than totalcols - startcol?
if len(word) > self.cols - col:
raise TooLongWordException (word, len(word))
sys.stderr.write ("Word intersects badly with another word!\n")
except crosswordpuzzle.FrozenGridException:
sys.stderr.write ("Word cannot be added to a frozen puzzle.\n")
sys.stderr.write ("Word intersects badly with another word!\n")
except crosswordpuzzle.FrozenGridException:
sys.stderr.write ("Word cannot be added to a frozen puzzle.\n")
+ except crosswordpuzzle.WordCharsException:
+ sys.stderr.write ("Non-word characters in word. Cannot add.\n")
# Export to image/HTML
def on_export_image (self, solution=True):
# Export to image/HTML
def on_export_image (self, solution=True):