Back to index

python-biopython  1.60
Public Member Functions | Public Attributes
Bio.Nexus.Nexus.CharBuffer Class Reference

List of all members.

Public Member Functions

def __init__
def peek
def peek_nonwhitespace
def next
def next_nonwhitespace
def skip_whitespace
def next_until
def peek_word
def next_word
def rest

Public Attributes

 buffer

Detailed Description

Helps reading NEXUS-words and characters from a buffer.

Definition at line 39 of file Nexus.py.


Constructor & Destructor Documentation

def Bio.Nexus.Nexus.CharBuffer.__init__ (   self,
  string 
)

Definition at line 41 of file Nexus.py.

00041 
00042     def __init__(self,string):
00043         if string:
00044             self.buffer=list(string)
00045         else:
00046             self.buffer=[]
    

Here is the caller graph for this function:


Member Function Documentation

Definition at line 60 of file Nexus.py.

00060 
00061     def next(self):
00062         if self.buffer:
00063             return self.buffer.pop(0)
00064         else:
00065             return None

Here is the caller graph for this function:

Definition at line 66 of file Nexus.py.

00066 
00067     def next_nonwhitespace(self):
00068         while True:
00069             p=self.next()
00070             if p is None:
00071                 break
00072             if p not in WHITESPACE: 
00073                 return p
00074         return None

Here is the call graph for this function:

Here is the caller graph for this function:

def Bio.Nexus.Nexus.CharBuffer.next_until (   self,
  target 
)

Definition at line 79 of file Nexus.py.

00079 
00080     def next_until(self,target):
00081         for t in target:
00082             try:
00083                 pos=self.buffer.index(t)
00084             except ValueError:
00085                 pass
00086             else:
00087                 found=''.join(self.buffer[:pos])
00088                 self.buffer=self.buffer[pos:]
00089                 return found
00090         else:
00091             return None

Return the next NEXUS word from a string.

This deals with single and double quotes, whitespace and punctuation.

Definition at line 95 of file Nexus.py.

00095 
00096     def next_word(self):
00097         """Return the next NEXUS word from a string.
00098 
00099         This deals with single and double quotes, whitespace and punctuation.
00100         """
00101 
00102         word=[]
00103         quoted=False
00104         first=self.next_nonwhitespace()                                   # get first character
00105         if not first:                                       # return empty if only whitespace left
00106             return None
00107         word.append(first)
00108         if first=="'":                                      # word starts with a quote
00109             quoted="'"
00110         elif first=='"':
00111             quoted='"'
00112         elif first in PUNCTUATION:                          # if it's punctuation, return immediately
00113             return first
00114         while True:             
00115             c=self.peek()
00116             if c==quoted:                                      # a quote?
00117                 word.append(self.next())                    # store quote 
00118                 if self.peek()==quoted:                        # double quote
00119                     skip=self.next()                        # skip second quote 
00120                 elif quoted:                                # second single quote ends word
00121                     break
00122             elif quoted:
00123                 word.append(self.next())                              # if quoted, then add anything
00124             elif not c or c in PUNCTUATION or c in WHITESPACE:        # if not quoted and special character, stop 
00125                 break
00126             else:
00127                 word.append(self.next())                    # standard character
00128         return ''.join(word)
                

Here is the call graph for this function:

Definition at line 47 of file Nexus.py.

00047 
00048     def peek(self):
00049         if self.buffer:
00050             return self.buffer[0]
00051         else:
00052             return None

Here is the caller graph for this function:

Definition at line 53 of file Nexus.py.

00053 
00054     def peek_nonwhitespace(self):
00055         b=''.join(self.buffer).strip()
00056         if b:
00057             return b[0]
00058         else:
00059             return None
                
def Bio.Nexus.Nexus.CharBuffer.peek_word (   self,
  word 
)

Definition at line 92 of file Nexus.py.

00092 
00093     def peek_word(self,word):
00094         return ''.join(self.buffer[:len(word)])==word
    
Return the rest of the string without parsing.

Definition at line 129 of file Nexus.py.

00129 
00130     def rest(self):
00131         """Return the rest of the string without parsing."""
00132         return ''.join(self.buffer)

Definition at line 75 of file Nexus.py.

00075 
00076     def skip_whitespace(self):
00077         while self.buffer[0] in WHITESPACE:
00078             self.buffer=self.buffer[1:]
    

Member Data Documentation

Definition at line 43 of file Nexus.py.


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