Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions
kss.core.BeautifulSoup.PageElement Class Reference
Inheritance diagram for kss.core.BeautifulSoup.PageElement:
Inheritance graph
[legend]

List of all members.

Public Member Functions

def setup
def replaceWith
def extract
def insert
def findNext
def findAllNext
def findNextSibling
def findNextSiblings
def findPrevious
def findAllPrevious
def findPreviousSibling
def findPreviousSiblings
def findParent
def findParents
def nextGenerator
def nextSiblingGenerator
def previousGenerator
def previousSiblingGenerator
def parentGenerator
def substituteEncoding
def toEncoding

Public Attributes

 parent
 previous
 next
 previousSibling
 nextSibling

Static Public Attributes

 fetchNextSiblings = findNextSiblings
 fetchPrevious = findAllPrevious
 fetchPreviousSiblings = findPreviousSiblings
 fetchParents = findParents

Private Member Functions

def _lastRecursiveChild
def _findOne
def _findAll

Detailed Description

Contains the navigational information for some part of the page
(either a tag or a piece of text)

Definition at line 72 of file BeautifulSoup.py.


Member Function Documentation

def kss.core.BeautifulSoup.PageElement._findAll (   self,
  name,
  attrs,
  text,
  limit,
  generator,
  kwargs 
) [private]

Definition at line 277 of file BeautifulSoup.py.

00277 
00278     def _findAll(self, name, attrs, text, limit, generator, **kwargs):
00279         "Iterates over a generator looking for things that match."
00280 
00281         if isinstance(name, SoupStrainer):
00282             strainer = name
00283         else:
00284             # Build a SoupStrainer
00285             strainer = SoupStrainer(name, attrs, text, **kwargs)
00286         results = ResultSet(strainer)
00287         g = generator()
00288         while True:
00289             try:
00290                 i = g.next()
00291             except StopIteration:
00292                 break
00293             if i:
00294                 found = strainer.search(i)
00295                 if found:
00296                     results.append(found)
00297                     if limit and len(results) >= limit:
00298                         break
00299         return results

Here is the caller graph for this function:

def kss.core.BeautifulSoup.PageElement._findOne (   self,
  method,
  name,
  attrs,
  text,
  kwargs 
) [private]

Definition at line 270 of file BeautifulSoup.py.

00270 
00271     def _findOne(self, method, name, attrs, text, **kwargs):
00272         r = None
00273         l = method(name, attrs, text, 1, **kwargs)
00274         if l:
00275             r = l[0]
00276         return r
    

Here is the caller graph for this function:

Definition at line 130 of file BeautifulSoup.py.

00130 
00131     def _lastRecursiveChild(self):
00132         "Finds the last element beneath this object to be parsed."
00133         lastChild = self
00134         while hasattr(lastChild, 'contents') and lastChild.contents:
00135             lastChild = lastChild.contents[-1]
00136         return lastChild

Here is the caller graph for this function:

Destructively rips this element out of the tree.

Definition at line 102 of file BeautifulSoup.py.

00102 
00103     def extract(self):
00104         """Destructively rips this element out of the tree."""        
00105         if self.parent:
00106             try:
00107                 self.parent.contents.remove(self)
00108             except ValueError:
00109                 pass
00110 
00111         #Find the two elements that would be next to each other if
00112         #this element (and any children) hadn't been parsed. Connect
00113         #the two.        
00114         lastChild = self._lastRecursiveChild()
00115         nextElement = lastChild.next
00116 
00117         if self.previous:
00118             self.previous.next = nextElement
00119         if nextElement:
00120             nextElement.previous = self.previous
00121         self.previous = None
00122         lastChild.next = None
00123 
00124         self.parent = None        
00125         if self.previousSibling:
00126             self.previousSibling.nextSibling = self.nextSibling
00127         if self.nextSibling:
00128             self.nextSibling.previousSibling = self.previousSibling
00129         self.previousSibling = self.nextSibling = None       

Here is the call graph for this function:

Here is the caller graph for this function:

def kss.core.BeautifulSoup.PageElement.findAllNext (   self,
  name = None,
  attrs = {},
  text = None,
  limit = None,
  kwargs 
)
Returns all items that match the given criteria and appear
before after Tag in the document.

Definition at line 203 of file BeautifulSoup.py.

00203 
00204                     **kwargs):
00205         """Returns all items that match the given criteria and appear
00206         before after Tag in the document."""
00207         return self._findAll(name, attrs, text, limit, self.nextGenerator)

Here is the call graph for this function:

Here is the caller graph for this function:

def kss.core.BeautifulSoup.PageElement.findAllPrevious (   self,
  name = None,
  attrs = {},
  text = None,
  limit = None,
  kwargs 
)
Returns all items that match the given criteria and appear
before this Tag in the document.

Definition at line 228 of file BeautifulSoup.py.

00228 
00229                         **kwargs):
00230         """Returns all items that match the given criteria and appear
00231         before this Tag in the document."""
00232         return self._findAll(name, attrs, text, limit, self.previousGenerator,
                           **kwargs)

Here is the call graph for this function:

Here is the caller graph for this function:

def kss.core.BeautifulSoup.PageElement.findNext (   self,
  name = None,
  attrs = {},
  text = None,
  kwargs 
)
Returns the first item that matches the given criteria and
appears after this Tag in the document.

Definition at line 197 of file BeautifulSoup.py.

00197 
00198     def findNext(self, name=None, attrs={}, text=None, **kwargs):
00199         """Returns the first item that matches the given criteria and
00200         appears after this Tag in the document."""
00201         return self._findOne(self.findAllNext, name, attrs, text, **kwargs)

Here is the call graph for this function:

def kss.core.BeautifulSoup.PageElement.findNextSibling (   self,
  name = None,
  attrs = {},
  text = None,
  kwargs 
)
Returns the closest sibling to this Tag that matches the
given criteria and appears after this Tag in the document.

Definition at line 208 of file BeautifulSoup.py.

00208 
00209     def findNextSibling(self, name=None, attrs={}, text=None, **kwargs):
00210         """Returns the closest sibling to this Tag that matches the
00211         given criteria and appears after this Tag in the document."""
00212         return self._findOne(self.findNextSiblings, name, attrs, text,
00213                              **kwargs)

Here is the call graph for this function:

def kss.core.BeautifulSoup.PageElement.findNextSiblings (   self,
  name = None,
  attrs = {},
  text = None,
  limit = None,
  kwargs 
)
Returns the siblings of this Tag that match the given
criteria and appear after this Tag in the document.

Definition at line 215 of file BeautifulSoup.py.

00215 
00216                          **kwargs):
00217         """Returns the siblings of this Tag that match the given
00218         criteria and appear after this Tag in the document."""
00219         return self._findAll(name, attrs, text, limit,
                             self.nextSiblingGenerator, **kwargs)

Here is the call graph for this function:

Here is the caller graph for this function:

def kss.core.BeautifulSoup.PageElement.findParent (   self,
  name = None,
  attrs = {},
  kwargs 
)
Returns the closest parent of this Tag that matches the given
criteria.

Definition at line 249 of file BeautifulSoup.py.

00249 
00250     def findParent(self, name=None, attrs={}, **kwargs):
00251         """Returns the closest parent of this Tag that matches the given
00252         criteria."""
00253         # NOTE: We can't use _findOne because findParents takes a different
00254         # set of arguments.
00255         r = None
00256         l = self.findParents(name, attrs, 1)
00257         if l:
00258             r = l[0]
00259         return r

Here is the call graph for this function:

def kss.core.BeautifulSoup.PageElement.findParents (   self,
  name = None,
  attrs = {},
  limit = None,
  kwargs 
)
Returns the parents of this Tag that match the given
criteria.

Definition at line 260 of file BeautifulSoup.py.

00260 
00261     def findParents(self, name=None, attrs={}, limit=None, **kwargs):
00262         """Returns the parents of this Tag that match the given
00263         criteria."""
00264 
00265         return self._findAll(name, attrs, None, limit, self.parentGenerator,
                             **kwargs)

Here is the call graph for this function:

Here is the caller graph for this function:

def kss.core.BeautifulSoup.PageElement.findPrevious (   self,
  name = None,
  attrs = {},
  text = None,
  kwargs 
)
Returns the first item that matches the given criteria and
appears before this Tag in the document.

Definition at line 222 of file BeautifulSoup.py.

00222 
00223     def findPrevious(self, name=None, attrs={}, text=None, **kwargs):
00224         """Returns the first item that matches the given criteria and
00225         appears before this Tag in the document."""
00226         return self._findOne(self.findAllPrevious, name, attrs, text, **kwargs)

Here is the call graph for this function:

def kss.core.BeautifulSoup.PageElement.findPreviousSibling (   self,
  name = None,
  attrs = {},
  text = None,
  kwargs 
)
Returns the closest sibling to this Tag that matches the
given criteria and appears before this Tag in the document.

Definition at line 235 of file BeautifulSoup.py.

00235 
00236     def findPreviousSibling(self, name=None, attrs={}, text=None, **kwargs):
00237         """Returns the closest sibling to this Tag that matches the
00238         given criteria and appears before this Tag in the document."""
00239         return self._findOne(self.findPreviousSiblings, name, attrs, text,
00240                              **kwargs)

Here is the call graph for this function:

def kss.core.BeautifulSoup.PageElement.findPreviousSiblings (   self,
  name = None,
  attrs = {},
  text = None,
  limit = None,
  kwargs 
)
Returns the siblings of this Tag that match the given
criteria and appear before this Tag in the document.

Definition at line 242 of file BeautifulSoup.py.

00242 
00243                              limit=None, **kwargs):
00244         """Returns the siblings of this Tag that match the given
00245         criteria and appear before this Tag in the document."""
00246         return self._findAll(name, attrs, text, limit,
                             self.previousSiblingGenerator, **kwargs)

Here is the call graph for this function:

Here is the caller graph for this function:

def kss.core.BeautifulSoup.PageElement.insert (   self,
  position,
  newChild 
)

Definition at line 137 of file BeautifulSoup.py.

00137 
00138     def insert(self, position, newChild):
00139         if (isinstance(newChild, basestring)
00140             or isinstance(newChild, unicode)) \
00141             and not isinstance(newChild, NavigableString):
00142             newChild = NavigableString(newChild)        
00143 
00144         position =  min(position, len(self.contents))
00145         if hasattr(newChild, 'parent') and newChild.parent != None:
00146             # We're 'inserting' an element that's already one
00147             # of this object's children. 
00148             if newChild.parent == self:
00149                 index = self.find(newChild)
00150                 if index and index < position:
00151                     # Furthermore we're moving it further down the
00152                     # list of this object's children. That means that
00153                     # when we extract this element, our target index
00154                     # will jump down one.
00155                     position = position - 1
00156             newChild.extract()
00157             
00158         newChild.parent = self
00159         previousChild = None
00160         if position == 0:
00161             newChild.previousSibling = None
00162             newChild.previous = self
00163         else:
00164             previousChild = self.contents[position-1]
00165             newChild.previousSibling = previousChild
00166             newChild.previousSibling.nextSibling = newChild
00167             newChild.previous = previousChild._lastRecursiveChild()
00168         if newChild.previous:
00169             newChild.previous.next = newChild        
00170 
00171         newChildsLastElement = newChild._lastRecursiveChild()
00172 
00173         if position >= len(self.contents):
00174             newChild.nextSibling = None
00175             
00176             parent = self
00177             parentsNextSibling = None
00178             while not parentsNextSibling:
00179                 parentsNextSibling = parent.nextSibling
00180                 parent = parent.parent
00181                 if not parent: # This is the last element in the document.
00182                     break
00183             if parentsNextSibling:
00184                 newChildsLastElement.next = parentsNextSibling
00185             else:
00186                 newChildsLastElement.next = None
00187         else:
00188             nextChild = self.contents[position]            
00189             newChild.nextSibling = nextChild            
00190             if newChild.nextSibling:
00191                 newChild.nextSibling.previousSibling = newChild
00192             newChildsLastElement.next = nextChild
00193 
00194         if newChildsLastElement.next:
00195             newChildsLastElement.next.previous = newChildsLastElement
00196         self.contents.insert(position, newChild)

Here is the caller graph for this function:

Definition at line 302 of file BeautifulSoup.py.

00302 
00303     def nextGenerator(self):
00304         i = self
00305         while i:
00306             i = i.next
00307             yield i

Here is the caller graph for this function:

Definition at line 308 of file BeautifulSoup.py.

00308 
00309     def nextSiblingGenerator(self):
00310         i = self
00311         while i:
00312             i = i.nextSibling
00313             yield i

Here is the caller graph for this function:

Definition at line 326 of file BeautifulSoup.py.

00326 
00327     def parentGenerator(self):
00328         i = self
00329         while i:
00330             i = i.parent
00331             yield i

Here is the caller graph for this function:

Definition at line 314 of file BeautifulSoup.py.

00314 
00315     def previousGenerator(self):
00316         i = self
00317         while i:
00318             i = i.previous
00319             yield i

Here is the caller graph for this function:

Definition at line 320 of file BeautifulSoup.py.

00320 
00321     def previousSiblingGenerator(self):
00322         i = self
00323         while i:
00324             i = i.previousSibling
00325             yield i

Here is the caller graph for this function:

def kss.core.BeautifulSoup.PageElement.replaceWith (   self,
  replaceWith 
)

Definition at line 88 of file BeautifulSoup.py.

00088 
00089     def replaceWith(self, replaceWith):        
00090         oldParent = self.parent
00091         myIndex = self.parent.contents.index(self)
00092         if hasattr(replaceWith, 'parent') and replaceWith.parent == self.parent:
00093             # We're replacing this element with one of its siblings.
00094             index = self.parent.contents.index(replaceWith)
00095             if index and index < myIndex:
00096                 # Furthermore, it comes before this element. That
00097                 # means that when we extract it, the index of this
00098                 # element will change.
00099                 myIndex = myIndex - 1
00100         self.extract()        
00101         oldParent.insert(myIndex, replaceWith)
        

Here is the call graph for this function:

def kss.core.BeautifulSoup.PageElement.setup (   self,
  parent = None,
  previous = None 
)
Sets up the initial relations between this element and
other elements.

Definition at line 76 of file BeautifulSoup.py.

00076 
00077     def setup(self, parent=None, previous=None):
00078         """Sets up the initial relations between this element and
00079         other elements."""        
00080         self.parent = parent
00081         self.previous = previous
00082         self.next = None
00083         self.previousSibling = None
00084         self.nextSibling = None
00085         if self.parent and self.parent.contents:
00086             self.previousSibling = self.parent.contents[-1]
00087             self.previousSibling.nextSibling = self

def kss.core.BeautifulSoup.PageElement.substituteEncoding (   self,
  str,
  encoding = None 
)

Definition at line 333 of file BeautifulSoup.py.

00333 
00334     def substituteEncoding(self, str, encoding=None):
00335         encoding = encoding or "utf-8"
00336         return str.replace("%SOUP-ENCODING%", encoding)    

Here is the caller graph for this function:

def kss.core.BeautifulSoup.PageElement.toEncoding (   self,
  s,
  encoding = None 
)
Encodes an object to a string in some encoding, or to Unicode.
.

Definition at line 337 of file BeautifulSoup.py.

00337 
00338     def toEncoding(self, s, encoding=None):
00339         """Encodes an object to a string in some encoding, or to Unicode.
00340         ."""
00341         if isinstance(s, unicode):
00342             if encoding:
00343                 s = s.encode(encoding)
00344         elif isinstance(s, str):
00345             if encoding:
00346                 s = s.encode(encoding)
00347             else:
00348                 s = unicode(s)
00349         else:
00350             if encoding:
00351                 s  = self.toEncoding(str(s), encoding)
00352             else:
00353                 s = unicode(s)
00354         return s

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 220 of file BeautifulSoup.py.

Definition at line 266 of file BeautifulSoup.py.

Definition at line 233 of file BeautifulSoup.py.

Definition at line 247 of file BeautifulSoup.py.

Definition at line 81 of file BeautifulSoup.py.

Definition at line 83 of file BeautifulSoup.py.

Definition at line 79 of file BeautifulSoup.py.

Reimplemented in kss.core.BeautifulSoup.BeautifulStoneSoup.

Definition at line 80 of file BeautifulSoup.py.

Definition at line 82 of file BeautifulSoup.py.


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