Exemplo n.º 1
0
 def _check_docstrings(self,obj,errors):
     import enchant
     if hasattr(obj,"__doc__"):
         skip_errors = [w for w in getattr(obj,"_DOC_ERRORS",[])]
         chkr = enchant.checker.SpellChecker("en_AU",obj.__doc__,filters=[enchant.tokenize.URLFilter])
         for err in chkr:
             if len(err.word) == 1:
                 continue
             if err.word.lower() in self.WORDS:
                 continue
             if skip_errors and skip_errors[0] == err.word:
                 skip_errors.pop(0)
                 continue
             errors.append((obj,err.word,err.wordpos))
             msg = "\nDOCSTRING SPELLING ERROR: %s %s %d %s\n" % (obj,err.word,err.wordpos,chkr.suggest())
             printf([msg],file=sys.stderr)
     #  Find and yield all child objects that should be checked
     for name in dir(obj):
         if name.startswith("__"):
             continue
         child = getattr(obj,name)
         if hasattr(child,"__file__"):
             if not hasattr(globals(),"__file__"):
                 continue
             if not child.__file__.startswith(os.path.dirname(__file__)):
                 continue
         else:
             cmod = getattr(child,"__module__",None)
             if not cmod:
                 cclass = getattr(child,"__class__",None)
                 cmod = getattr(cclass,"__module__",None)
             if cmod and not cmod.startswith("enchant"):
                 continue
         yield child
Exemplo n.º 2
0
    def read_command(self):
        try:
            cmd = raw_input(">> ") # Python 2.x
        except NameError:
            cmd = input(">> ") # Python 3.x
        cmd = cmd.strip()

        if cmd.isdigit():
            repl = int(cmd)
            suggs = self.error.suggest()
            if repl >= len(suggs):
                printf([warning("No suggestion number"), repl])
                return False
            printf([success("Replacing '%s' with '%s'" % (color(self.error.word, color='red'),color(suggs[repl], color='green')))])
            self.error.replace(suggs[repl])
            return True

        if cmd[0] == "R":
            if not cmd[1:].isdigit():
                printf([warning("Badly formatted command (try 'help')")])
                return False
            repl = int(cmd[1:])
            suggs = self.error.suggest()
            if repl >= len(suggs):
                printf([warning("No suggestion number"), repl])
                return False
            self.error.replace_always(suggs[repl])
            return True

        if cmd == "i":
            return True

        if cmd == "I":
            self.error.ignore_always()
            return True

        if cmd == "a":
            self.error.add()
            return True

        if cmd == "e":
            repl = raw_input(info("New Word: "))
            self.error.replace(repl.strip())
            return True

        if cmd == "q":
            self._stop = True
            return True

        if "help".startswith(cmd.lower()):
            self.print_help()
            return False

        printf([warning("Badly formatted command (try 'help')")])
        return False
Exemplo n.º 3
0
    def read_command(self):
        cmd = raw_input(">> ")
        cmd = cmd.strip()

        if cmd.isdigit():
            repl = int(cmd)
            suggs = self.error.suggest()
            if repl >= len(suggs):
                printf(["No suggestion number", repl])
                return False
            printf(
                ["Replacing '%s' with '%s'" % (self.error.word, suggs[repl])])
            self.error.replace(suggs[repl])
            return True

        if cmd[0] == "R":
            if not cmd[1:].isdigit():
                printf(["Badly formatted command (try 'help')"])
                return False
            repl = int(cmd[1:])
            suggs = self.error.suggest()
            if repl >= len(suggs):
                printf(["No suggestion number", repl])
                return False
            self.error.replace_always(suggs[repl])
            return True

        if cmd == "i":
            return True

        if cmd == "I":
            self.error.ignore_always()
            return True

        if cmd == "a":
            self.error.add()
            return True

        if cmd == "e":
            repl = raw_input("New Word: ")
            self.error.replace(repl.strip())
            return True

        if cmd == "q":
            self._stop = True
            return True

        if "help".startswith(cmd.lower()):
            self.print_help()
            return False

        printf(["Badly formatted command (try 'help')"])
        return False
Exemplo n.º 4
0
 def run(self):
     """Run the spellchecking loop."""
     self._stop = False
     for err in self._checker:
         self.error = err
         printf(["ERROR:", err.word])
         printf(["HOW ABOUT:", err.suggest()])
         status = self.read_command()
         while not status and not self._stop:
             status = self.read_command()
         if self._stop:
                 break
Exemplo n.º 5
0
 def read_command(self):
     cmd = raw_input(">> ")
     cmd = cmd.strip()
     
     if cmd.isdigit():
         repl = int(cmd)
         suggs = self.error.suggest()
         if repl >= len(suggs):
             printf(["No suggestion number", repl])
             return False
         printf(["Replacing '%s' with '%s'" % (self.error.word,suggs[repl])])
         self.error.replace(suggs[repl])
         return True
     
     if cmd[0] == "R":
         if not cmd[1:].isdigit():
             printf(["Badly formatted command (try 'help')"])
             return False
         repl = int(cmd[1:])
         suggs = self.error.suggest()
         if repl >= len(suggs):
             printf(["No suggestion number", repl])
             return False
         self.error.replace_always(suggs[repl])
         return True
     
     if cmd == "i":
         return True
     
     if cmd == "I":
         self.error.ignore_always()
         return True
         
     if cmd == "a":
         self.error.add()
         return True
     
     if cmd == "e":
         repl = raw_input("New Word: ")
         self.error.replace(repl.strip())
         return True
          
     if cmd == "q":
         self._stop = True
         return True
     
     if "help".startswith(cmd.lower()):
         self.print_help()
         return False
     
     printf(["Badly formatted command (try 'help')"])
     return False
Exemplo n.º 6
0
def _test():
    from enchant.checker import SpellChecker
    text = "This is sme text with a fw speling errors in it. Here are a fw more to tst it ut."
    printf(["BEFORE:", text])
    chk_dlg = GtkSpellCheckerDialog()
    chk_dlg.show()
    chk_dlg.connect('delete_event', gtk.main_quit)

    chkr = SpellChecker("en_US",text)

    chk_dlg.setSpellChecker(chkr)
    chk_dlg.updateUI()
    gtk.main()
Exemplo n.º 7
0
def _test():
    from enchant.checker import SpellChecker
    text = "This is sme text with a fw speling errors in it. Here are a fw more to tst it ut."
    printf(["BEFORE:", text])
    chk_dlg = GtkSpellCheckerDialog()
    chk_dlg.show()
    chk_dlg.connect('delete_event', gtk.main_quit)

    chkr = SpellChecker("en_US", text)

    chk_dlg.setSpellChecker(chkr)
    chk_dlg.updateUI()
    gtk.main()
Exemplo n.º 8
0
 def print_suggestions(self):
     """Prints out the suggestions for a given error
     This function will add vertical pipes to separate choices
     as well as the index of the replacement as expected by the replace function.
     I don't believe zero indexing is a problem as long as the user can see the numbers :)
     """
     result = ""
     suggestions = self.error.suggest()
     for index, sugg in enumerate(suggestions):
         if index is 0:
             result = result + color(str(index), color='yellow') + ": " + color(sugg, color='bold')
         else:
             result = result + " | " + color(str(index), color='yellow') + ": " + color(sugg, color='bold')
     printf([info("HOW ABOUT:"), result])
Exemplo n.º 9
0
def _test():
    class TestDialog(wxSpellCheckerDialog):
        def __init__(self,*args):
            wxSpellCheckerDialog.__init__(self,*args)
            wx.EVT_CLOSE(self,self.OnClose)
        def OnClose(self,evnt):
            if self._checker is not None:
                printf(["AFTER:", self._checker.get_text()])
            self.Destroy()
    from enchant.checker import SpellChecker
    text = "This is sme text with a fw speling errors in it. Here are a fw more to tst it ut."
    printf(["BEFORE:", text])
    app = wx.PySimpleApp()
    dlg = TestDialog()
    chkr = SpellChecker("en_US",text)
    dlg.SetSpellChecker(chkr)
    dlg.Show()
    app.MainLoop()
def _test():
    class TestDialog(wxSpellCheckerDialog):
        def __init__(self,*args):
            wxSpellCheckerDialog.__init__(self,*args)
            wx.EVT_CLOSE(self,self.OnClose)
        def OnClose(self,evnt):
            chkr = dlg.GetSpellChecker()
            if chkr is not None:
                printf(["AFTER:", chkr.get_text()])
            self.Destroy()
    from enchant.checker import SpellChecker
    text = "This is sme text with a fw speling errors in it. Here are a fw more to tst it ut."
    printf(["BEFORE:", text])
    app = wx.PySimpleApp()
    dlg = TestDialog()
    chkr = SpellChecker("en_US",text)
    dlg.SetSpellChecker(chkr)
    dlg.Show()
    app.MainLoop()
Exemplo n.º 11
0
def _test():
  class TestDialog(wxSpellCheckerDialog):
    def __init__(self, *args):
      wxSpellCheckerDialog.__init__(self, *args)
      wx.EVT_CLOSE(self, self.OnClose)

    def OnClose(self, evnt):
      if self._checker is not None:
        printf(["AFTER:", self._checker.get_text()])
      self.Destroy()

  from enchant.checker import SpellChecker
  text = "Alinuța are mre."
  printf(["BEFORE:", text])
  app = wx.PySimpleApp()
  dlg = TestDialog()
  chkr = SpellChecker("ro_RO", text)
  dlg.SetSpellChecker(chkr)
  dlg.Show()
  app.MainLoop()
Exemplo n.º 12
0
    def print_error(self):
        """print the spelling error to the console.

        Prints the misspelled word along with 100 characters of
        context on either side.  This number was arbitrarily chosen
        and could be modified to be tunable or changed entirely.
        It seems to be enough context to be helpful though
        """
        error_string = self._build_context(self.error.get_text(), self.error.word, self.error.wordpos)
        printf([error("ERROR: %s" % color(self.error.word, color='red'))])
        printf([info("")])
        printf([info(error_string)])
        printf([info("")])
Exemplo n.º 13
0
 def run_on_file(self,infile,outfile=None,enc=None):
     """Run spellchecking on the named file.
     This method can be used to run the spellchecker over the named file.
     If <outfile> is not given, the corrected contents replace the contents
     of <infile>.  If <outfile> is given, the corrected contents will be
     written to that file.  Use "-" to have the contents written to stdout.
     If <enc> is given, it specifies the encoding used to read the
     file's contents into a unicode string.  The output will be written
     in the same encoding.
     """
     inStr = "".join(file(infile,"r").readlines())
     if enc is not None:
         inStr = inStr.decode(enc)
     self._checker.set_text(inStr)
     begin_msg = "Beginning spell check of %s" % infile
     printf([info(begin_msg)])
     printf([info("-" * len(begin_msg))])
     self.run()
     printf([success("Completed spell check of %s" % infile)])
     outStr = self._checker.get_text()
     if enc is not None:
         outStr = outStr.encode(enc)
     if outfile is None:
         outF = file(infile,"w")
     elif outfile == "-":
         outF = sys.stdout
     else:
         outF = file(outfile,"w")
     outF.write(outStr)
     outF.close()
Exemplo n.º 14
0
 def print_error(self):
     """Prints the misspelled word along with 100 characters of
     context on either side.  This number was arbitrarily chosen
     and could be modified to be tunable or changed entirely.
     It seems to be enough context to be helpful though
     """
     error_string = self.error.leading_context(100) + color(self.error.word, color='red') + self.error.trailing_context(100)
     printf([error("ERROR: %s" % color(self.error.word, color='red'))])
     printf([info("")])
     for line in error_string.split("\n"):
         printf([info(line)])
Exemplo n.º 15
0
 def run(self):
     """Run the spellchecking loop."""
     self._stop = False
     for err in self._checker:
         self.error = err
         printf(["ERROR:", err.word])
         printf(["HOW ABOUT:", err.suggest()])
         status = self.read_command()
         while not status and not self._stop:
             status = self.read_command()
         if self._stop:
             break
     printf(["DONE"])
Exemplo n.º 16
0
 def OnClose(self, evnt):
     chkr = dlg.GetSpellChecker()
     if chkr is not None:
         printf(["AFTER:", chkr.get_text()])
     self.Destroy()
Exemplo n.º 17
0
 def OnClose(self,evnt):
     if self._checker is not None:
         printf(["AFTER:", self._checker.get_text()])
     self.Destroy()
Exemplo n.º 18
0
 def _onIgnore(self, w, *args):
     printf(["ignore"])
     self._advance()
Exemplo n.º 19
0
 def print_help(self):
     printf([info(color("0", color='yellow') + ".." + color("N", color='yellow') + ":\t" + color("replace", color='bold') + " with the numbered suggestion")])
     printf([info(color("R", color='cyan') + color("0", color='yellow') + ".." + color("R", color='cyan') + color("N", color='yellow') + ":\t" + color("always replace", color='bold') + " with the numbered suggestion")])
     printf([info(color("i", color='cyan') + ":\t\t" + color("ignore", color='bold') + " this word")])
     printf([info(color("I", color='cyan') + ":\t\t" + color("always ignore", color='bold') + " this word")])
     printf([info(color("a", color='cyan') + ":\t\t" + color("add", color='bold') + " word to personal dictionary")])
     printf([info(color("e", color='cyan') + ":\t\t" + color("edit", color='bold') + " the word")])
     printf([info(color("q", color='cyan') + ":\t\t" + color("quit", color='bold') + " checking")])
     printf([info(color("h", color='cyan') + ":\t\tprint this " + color("help", color='bold') + " message")])
     printf([info("----------------------------------------------------")])
     self.print_suggestions()
Exemplo n.º 20
0
 def _onIgnoreAll(self, w, *args):
     printf(["ignore all"])
     self._checker.ignore_always()
     self._advance()
Exemplo n.º 21
0
 def _onIgnore(self,w,*args):
     printf(["ignore"])
     self._advance()
Exemplo n.º 22
0
 def OnClose(self, evnt):
     if self._checker is not None:
         printf(["AFTER:", self._checker.get_text()])
     self.Destroy()
Exemplo n.º 23
0
 def _onIgnoreAll(self,w,*args):
     printf(["ignore all"])
     self._checker.ignore_always()
     self._advance()
Exemplo n.º 24
0
 def _onReplace(self,*args):
     printf(["Replace"])
     repl = self._getRepl()
     self._checker.replace(repl)
     self._advance()
Exemplo n.º 25
0
 def _onReplace(self, *args):
     printf(["Replace"])
     repl = self._getRepl()
     self._checker.replace(repl)
     self._advance()
Exemplo n.º 26
0
 def _onReplaceAll(self, *args):
     printf(["Replace all"])
     repl = self._getRepl()
     self._checker.replace_always(repl)
     self._advance()
Exemplo n.º 27
0
 def OnClose(self, evnt):
     chkr = dlg.GetSpellChecker()
     if chkr is not None:
         printf(["AFTER:", chkr.get_text()])
     self.Destroy()
Exemplo n.º 28
0
 def _onReplaceAll(self,*args):
     printf(["Replace all"])
     repl = self._getRepl()
     self._checker.replace_always(repl)
     self._advance()
Exemplo n.º 29
0
 def print_help(self):
     printf(["0..N:    replace with the numbered suggestion"])
     printf(["R0..rN:  always replace with the numbered suggestion"])
     printf(["i:       ignore this word"])
     printf(["I:       always ignore this word"])
     printf(["a:       add word to personal dictionary"])
     printf(["e:       edit the word"])
     printf(["q:       quit checking"])
     printf(["h:       print this help message"])
     printf(["----------------------------------------------------"])
     printf(["HOW ABOUT:", self.error.suggest()])
Exemplo n.º 30
0
 def print_help(self):
     printf(["0..N:    replace with the numbered suggestion"])
     printf(["R0..rN:  always replace with the numbered suggestion"])
     printf(["i:       ignore this word"])
     printf(["I:       always ignore this word"])
     printf(["a:       add word to personal dictionary"])
     printf(["e:       edit the word"])
     printf(["q:       quit checking"])
     printf(["h:       print this help message"])
     printf(["----------------------------------------------------"])
     printf(["HOW ABOUT:", self.error.suggest()])
Exemplo n.º 31
0
 def _onButtonPress(self,widget,event):
     if event.type == gtk.gdk._2BUTTON_PRESS:
         printf(["Double click!"])
         self._onReplace()
Exemplo n.º 32
0
 def _onButtonPress(self, widget, event):
     if event.type == gtk.gdk._2BUTTON_PRESS:
         printf(["Double click!"])
         self._onReplace()