Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Static Public Attributes | Static Private Attributes
kupu.python.spellcheck.SpellChecker Class Reference

List of all members.

Public Member Functions

def __init__
def __del__
def check
def read_line
def write_line
def read_char
def reconnect

Public Attributes

 chin

Static Public Attributes

tuple reg_unknown = re.compile('^& (.*?) \d* \d*: (.*)$', re.U)
tuple reg_unknown_no_replacement = re.compile('^\# (.*?) \d*.*$', re.U)

Static Private Attributes

int __allow_access_to_unprotected_subobjects__ = 1

Detailed Description

Simple spell checker, uses ispell (or aspell) with pipes

Definition at line 17 of file spellcheck.py.


Constructor & Destructor Documentation

Definition at line 25 of file spellcheck.py.

00025 
00026     def __init__(self):
00027         self.chout, self.chin = popen2.popen2(COMMAND)
00028         # throw away intro
00029         self.read_line()

Definition at line 30 of file spellcheck.py.

00030 
00031     def __del__(self):
00032         self.chout.close()
00033         self.chin.close()


Member Function Documentation

def kupu.python.spellcheck.SpellChecker.check (   self,
  text 
)
checks a line of text

    returns None if spelling was okay, and an HTML string with words 
    that weren't recognized marked (with a span class="wrong_spelling")

Definition at line 34 of file spellcheck.py.

00034 
00035     def check(self, text):
00036         """checks a line of text
00037         
00038             returns None if spelling was okay, and an HTML string with words 
00039             that weren't recognized marked (with a span class="wrong_spelling")
00040         """
00041         result = {}
00042         for line in text.split('\n'):
00043             line = line.strip()
00044             if line:
00045                 self.write_line(line)
00046             while 1:
00047                 resline = self.read_line()
00048                 if not resline.strip():
00049                     break
00050                 if resline.strip() != '*':
00051                     match = self.reg_unknown.match(resline)
00052                     have_replacement = True
00053                     if not match:
00054                         match = self.reg_unknown_no_replacement.match(resline)
00055                         have_replacement = False
00056                     assert match, 'Unknown formatted line: %s' % resline
00057                     word = match.group(1)
00058                     if result.has_key(word):
00059                         continue
00060                     replacements = []
00061                     if have_replacement:
00062                         replacements = match.group(2).split(', ')
00063                     result[word] = replacements
00064         return result

Here is the call graph for this function:

Definition at line 87 of file spellcheck.py.

00087 
00088     def read_char(self):
00089         try:
00090             return self.chout.read(1)
00091         except IOError:
00092             self.reconnect()
00093             return self.chout.read(1)
00094         raise

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 65 of file spellcheck.py.

00065 
00066     def read_line(self):
00067         buf = []
00068         while 1:
00069             char = self.read_char()
00070             if not char:
00071                 return ''
00072             if char == '\n':
00073                 return ''.join(buf)
00074             buf.append(char)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 95 of file spellcheck.py.

00095 
00096     def reconnect(self):
00097         try:
00098             self.chout.close()
00099         except IOError:
00100             pass
00101         try:
00102             self.chin.close()
00103         except IOError:
00104             pass
00105         self.chout, self.chin = popen2.popen2(COMMAND)

Here is the caller graph for this function:

Definition at line 75 of file spellcheck.py.

00075 
00076     def write_line(self, line):
00077         try:
00078             self.chin.write('%s\n' % line)
00079             self.chin.flush()
00080             return
00081         except IOError:
00082             self.reconnect()
00083             self.chin.write('%s\n' % line)
00084             self.chin.flush()
00085             return
00086         raise

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 20 of file spellcheck.py.

Definition at line 26 of file spellcheck.py.

tuple kupu.python.spellcheck.SpellChecker.reg_unknown = re.compile('^& (.*?) \d* \d*: (.*)$', re.U) [static]

Definition at line 22 of file spellcheck.py.

tuple kupu.python.spellcheck.SpellChecker.reg_unknown_no_replacement = re.compile('^\# (.*?) \d*.*$', re.U) [static]

Definition at line 23 of file spellcheck.py.


The documentation for this class was generated from the following file: