CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes | Properties | Private Member Functions
BeautifulSoup.Tag Class Reference
Inheritance diagram for BeautifulSoup.Tag:
BeautifulSoup.PageElement BeautifulSoup.BeautifulStoneSoup BeautifulSoup.BeautifulSOAP BeautifulSoup.BeautifulSoup BeautifulSoup.RobustXMLParser BeautifulSoup.SimplifyingSOAPParser BeautifulSoup.ICantBelieveItsBeautifulSoup BeautifulSoup.MinimalSoup BeautifulSoup.RobustHTMLParser BeautifulSoup.RobustWackAssHTMLParser BeautifulSoup.RobustInsanelyWackAssHTMLParser

Public Member Functions

def __call__ (self, args, kwargs)
 
def __contains__ (self, x)
 
def __delitem__ (self, key)
 
def __eq__ (self, other)
 
def __getattr__ (self, tag)
 
def __getitem__ (self, key)
 
def __init__ (self, parser, name, attrs=None, parent=None, previous=None)
 
def __iter__ (self)
 
def __len__ (self)
 
def __ne__ (self, other)
 
def __nonzero__ (self)
 
def __repr__ (self, encoding=DEFAULT_OUTPUT_ENCODING)
 
def __setitem__ (self, key, value)
 
def __str__ (self, encoding=DEFAULT_OUTPUT_ENCODING, prettyPrint=False, indentLevel=0)
 
def __unicode__ (self)
 
def childGenerator (self)
 
def clear (self)
 
def decompose (self)
 
def fetchText (self, text=None, recursive=True, limit=None)
 
def find (self, name=None, attrs={}, recursive=True, text=None, kwargs)
 
def findAll (self, name=None, attrs={}, recursive=True, text=None, limit=None, kwargs)
 
def firstText (self, text=None, recursive=True)
 
def get (self, key, default=None)
 
def getString (self)
 
def getText (self, separator=u"")
 
def has_key (self, key)
 
def index (self, element)
 
def prettify (self, encoding=DEFAULT_OUTPUT_ENCODING)
 
def recursiveChildGenerator (self)
 
def renderContents (self, encoding=DEFAULT_OUTPUT_ENCODING, prettyPrint=False, indentLevel=0)
 
def setString (self, string)
 
- Public Member Functions inherited from BeautifulSoup.PageElement
def append (self, tag)
 
def extract (self)
 
def findAllNext (self, name=None, attrs={}, text=None, limit=None, kwargs)
 
def findAllPrevious (self, name=None, attrs={}, text=None, limit=None, kwargs)
 
def findNext (self, name=None, attrs={}, text=None, kwargs)
 
def findNextSibling (self, name=None, attrs={}, text=None, kwargs)
 
def findNextSiblings (self, name=None, attrs={}, text=None, limit=None, kwargs)
 
def findParent (self, name=None, attrs={}, kwargs)
 
def findParents (self, name=None, attrs={}, limit=None, kwargs)
 
def findPrevious (self, name=None, attrs={}, text=None, kwargs)
 
def findPreviousSibling (self, name=None, attrs={}, text=None, kwargs)
 
def findPreviousSiblings (self, name=None, attrs={}, text=None, limit=None, kwargs)
 
def insert (self, position, newChild)
 
def nextGenerator (self)
 
def nextSiblingGenerator (self)
 
def parentGenerator (self)
 
def previousGenerator (self)
 
def previousSiblingGenerator (self)
 
def replaceWith (self, replaceWith)
 
def replaceWithChildren (self)
 
def setup (self, parent=None, previous=None)
 
def substituteEncoding (self, str, encoding=None)
 
def toEncoding (self, s, encoding=None)
 

Public Attributes

 attrMap
 
 attrs
 
 containsSubstitutions
 
 contents
 
 convertHTMLEntities
 
 convertXMLEntities
 
 escapeUnrecognizedEntities
 
 hidden
 
 isSelfClosing
 
 name
 
 parserClass
 
- Public Attributes inherited from BeautifulSoup.PageElement
 next
 
 nextSibling
 
 parent
 
 previous
 
 previousSibling
 

Properties

 string = property(getString, setString)
 
 text = property(getText)
 

Private Member Functions

def _convertEntities (self, match)
 
def _getAttrMap (self)
 

Detailed Description

Represents a found HTML tag with its attributes and contents.

Definition at line 506 of file BeautifulSoup.py.

Constructor & Destructor Documentation

def BeautifulSoup.Tag.__init__ (   self,
  parser,
  name,
  attrs = None,
  parent = None,
  previous = None 
)

Definition at line 536 of file BeautifulSoup.py.

Referenced by BeautifulSoup.Tag._convertEntities().

536  previous=None):
537  "Basic constructor."
538 
539  # We don't actually store the parser object: that lets extracted
540  # chunks be garbage-collected
541  self.parserClass = parser.__class__
542  self.isSelfClosing = parser.isSelfClosingTag(name)
543  self.name = name
544  if attrs is None:
545  attrs = []
546  elif isinstance(attrs, dict):
547  attrs = attrs.items()
548  self.attrs = attrs
549  self.contents = []
550  self.setup(parent, previous)
551  self.hidden = False
553  self.convertHTMLEntities = parser.convertHTMLEntities
554  self.convertXMLEntities = parser.convertXMLEntities
555  self.escapeUnrecognizedEntities = parser.escapeUnrecognizedEntities
556 
557  # Convert any HTML, XML, or numeric entities in the attribute values.
558  convert = lambda(k, val): (k,
559  re.sub("&(#\d+|#x[0-9a-fA-F]+|\w+);",
560  self._convertEntities,
561  val))
562  self.attrs = map(convert, self.attrs)
563 
def setup(self, parent=None, previous=None)
def _convertEntities(self, match)

Member Function Documentation

def BeautifulSoup.Tag.__call__ (   self,
  args,
  kwargs 
)
Calling a tag like a function is the same as calling its
findAll() method. Eg. tag('a') returns a list of all the A tags
found within this tag.

Definition at line 655 of file BeautifulSoup.py.

References apply(), and BeautifulSoup.Tag.findAll().

655  def __call__(self, *args, **kwargs):
656  """Calling a tag like a function is the same as calling its
657  findAll() method. Eg. tag('a') returns a list of all the A tags
658  found within this tag."""
659  return apply(self.findAll, args, kwargs)
660 
def __call__(self, args, kwargs)
def findAll(self, name=None, attrs={}, recursive=True, text=None, limit=None, kwargs)
Vec apply(Vec v, F f)
Definition: ExtVec.h:83
def BeautifulSoup.Tag.__contains__ (   self,
  x 
)

Definition at line 623 of file BeautifulSoup.py.

References BeautifulSoup.Tag.contents.

623  def __contains__(self, x):
624  return x in self.contents
625 
def __contains__(self, x)
def BeautifulSoup.Tag.__delitem__ (   self,
  key 
)

Definition at line 644 of file BeautifulSoup.py.

References BeautifulSoup.Tag._getAttrMap(), BeautifulSoup.Tag.attrMap, and BeautifulSoup.Tag.attrs.

644  def __delitem__(self, key):
645  "Deleting tag[key] deletes all 'key' attributes for the tag."
646  for item in self.attrs:
647  if item[0] == key:
648  self.attrs.remove(item)
649  #We don't break because bad HTML can define the same
650  #attribute multiple times.
651  self._getAttrMap()
652  if self.attrMap.has_key(key):
653  del self.attrMap[key]
654 
def _getAttrMap(self)
def __delitem__(self, key)
def BeautifulSoup.Tag.__eq__ (   self,
  other 
)
Returns true iff this tag has the same name, the same attributes,
and the same contents (recursively) as the given tag.

NOTE: right now this will return false if two tags have the
same attributes in a different order. Should this be fixed?

Definition at line 669 of file BeautifulSoup.py.

References BeautifulSoup.Tag.attrs, BeautifulSoup.Tag.contents, AlignableObjectId::entry.name, TmModule.name, cond::persistency::TAG::NAME.name, cond::persistency::GLOBAL_TAG::NAME.name, cond::persistency::RUN_INFO::RUN_NUMBER.name, cond::persistency::TAG::TIME_TYPE.name, cond::persistency::GLOBAL_TAG::VALIDITY.name, cond::persistency::RUN_INFO::START_TIME.name, cond::persistency::TAG::OBJECT_TYPE.name, cond::persistency::GLOBAL_TAG::DESCRIPTION.name, cond::persistency::RUN_INFO::END_TIME.name, cond::persistency::TAG::SYNCHRONIZATION.name, cond::persistency::GLOBAL_TAG::RELEASE.name, cond::persistency::TAG::END_OF_VALIDITY.name, cond::persistency::GLOBAL_TAG::SNAPSHOT_TIME.name, cond::persistency::TAG::DESCRIPTION.name, cond::persistency::GTEditorData.name, cond::persistency::GLOBAL_TAG::INSERTION_TIME.name, cond::persistency::TAG::LAST_VALIDATED_TIME.name, cond::persistency::TAG::INSERTION_TIME.name, nanoaod::MergeableCounterTable::SingleColumn< T >.name, cond::persistency::TAG::MODIFICATION_TIME.name, preexistingValidation.PreexistingValidation.name, PixelDCSObject< T >::Item.name, cond::persistency::GTProxyData.name, cond::TimeTypeSpecs.name, lumi::TriggerInfo.name, alignment.Alignment.name, PixelEndcapLinkMaker::Item.name, cond::persistency::GLOBAL_TAG_MAP::GLOBAL_TAG_NAME.name, PixelBarrelLinkMaker::Item.name, cond::persistency::GLOBAL_TAG_MAP::RECORD.name, cond::persistency::GLOBAL_TAG_MAP::LABEL.name, cond::persistency::GLOBAL_TAG_MAP::TAG_NAME.name, cms::DDAlgoArguments.name, ExpressionHisto< T >.name, MEtoEDM< T >::MEtoEDMObject.name, XMLProcessor::_loaderBaseConfig.name, cond::persistency::PAYLOAD::HASH.name, cond::persistency::PAYLOAD::OBJECT_TYPE.name, cond::persistency::PAYLOAD::DATA.name, cond::persistency::PAYLOAD::STREAMER_INFO.name, genericValidation.GenericValidation.name, cond::persistency::PAYLOAD::VERSION.name, cond::persistency::PAYLOAD::INSERTION_TIME.name, nanoaod::MergeableCounterTable::VectorColumn< T >.name, h4DSegm.name, PhysicsTools::Calibration::Variable.name, TrackerSectorStruct.name, cond::TagInfo_t.name, cond::persistency::IOV::TAG_NAME.name, cond::persistency::IOV::SINCE.name, Mapper::definition< ScannerT >.name, cond::persistency::IOV::PAYLOAD_HASH.name, classes.MonitorData.name, cond::persistency::IOV::INSERTION_TIME.name, MuonGeometrySanityCheckPoint.name, classes.OutputData.name, h2DSegm.name, nanoaod::FlatTable::Column.name, geometry.Structure.name, cond::persistency::TAG_LOG::TAG_NAME.name, cond::persistency::TAG_LOG::EVENT_TIME.name, cond::persistency::TAG_LOG::USER_NAME.name, cond::persistency::TAG_LOG::HOST_NAME.name, cond::persistency::TAG_LOG::COMMAND.name, cond::persistency::TAG_LOG::ACTION.name, cond::persistency::TAG_LOG::USER_TEXT.name, plotscripts.SawTeethFunction.name, crabFunctions.CrabTask.name, hTMaxCell.name, and BeautifulSoup.Tag.name.

Referenced by SequenceTypes._UnarySequenceOperator.__ne__().

669  def __eq__(self, other):
670  """Returns true iff this tag has the same name, the same attributes,
671  and the same contents (recursively) as the given tag.
672 
673  NOTE: right now this will return false if two tags have the
674  same attributes in a different order. Should this be fixed?"""
675  if other is self:
676  return True
677  if not hasattr(other, 'name') or not hasattr(other, 'attrs') or not hasattr(other, 'contents') or self.name != other.name or self.attrs != other.attrs or len(self) != len(other):
678  return False
679  for i in range(0, len(self.contents)):
680  if self.contents[i] != other.contents[i]:
681  return False
682  return True
683 
def __eq__(self, other)
def BeautifulSoup.Tag.__getattr__ (   self,
  tag 
)

Definition at line 661 of file BeautifulSoup.py.

References __class__< T >.__class__(), pat::__class__.__class__(), StringMap.find(), pos::PixelConfig.find(), ESCondObjectContainer< T >.find(), AlignableMap.find(), HcalIndexLookup.find(), Book.find(), DTBufferTree< Key, Content >.find(), cms::DDAlgoArguments.find(), EcalCondObjectContainer< T >.find(), EcalCondTowerObjectContainer< T >.find(), EcalContainer< DetId, T >.find(), LutXml.find(), HBHELinearMap.find(), cond::persistency::RunInfoProxy.find(), cond::SmallWORMDict.find(), edm::TriggerResults.find(), l1t::IntervalManager< TimeType, PayloadType >.find(), cond::persistency::IOVProxy.find(), edm::MapOfVectors< K, T >.find(), edm::SortedCollection< T, SORT >.find(), edm::DataFrameContainer.find(), edm::DetSetVector< T >.find(), data_sources.json_data_node.find(), edm::AssociationMap< Tag >.find(), edm::DetSetRefVector< T, C >.find(), edm::Trie< T >.find(), cmdline::CmdLine.find(), PhysicsTools::Calibration::MVAComputerContainer.find(), edmNew::DetSetVector< T >.find(), and BeautifulSoup.Tag.find().

Referenced by VarParsing.VarParsing.setType().

661  def __getattr__(self, tag):
662  #print "Getattr %s.%s" % (self.__class__, tag)
663  if len(tag) > 3 and tag.rfind('Tag') == len(tag)-3:
664  return self.find(tag[:-3])
665  elif tag.find('__') != 0:
666  return self.find(tag)
667  raise AttributeError, "'%s' object has no attribute '%s'" % (self.__class__, tag)
668 
def __getattr__(self, tag)
def find(self, name=None, attrs={}, recursive=True, text=None, kwargs)
def BeautifulSoup.Tag.__getitem__ (   self,
  key 
)
tag[key] returns the value of the 'key' attribute for the tag,
and throws an exception if it's not there.

Definition at line 610 of file BeautifulSoup.py.

References BeautifulSoup.Tag._getAttrMap().

610  def __getitem__(self, key):
611  """tag[key] returns the value of the 'key' attribute for the tag,
612  and throws an exception if it's not there."""
613  return self._getAttrMap()[key]
614 
def _getAttrMap(self)
def __getitem__(self, key)
def BeautifulSoup.Tag.__iter__ (   self)

Definition at line 615 of file BeautifulSoup.py.

References BeautifulSoup.Tag.contents.

615  def __iter__(self):
616  "Iterating over a tag iterates over its contents."
617  return iter(self.contents)
618 
def BeautifulSoup.Tag.__len__ (   self)

Definition at line 619 of file BeautifulSoup.py.

References BeautifulSoup.Tag.contents.

619  def __len__(self):
620  "The length of a tag is the length of its list of contents."
621  return len(self.contents)
622 
def BeautifulSoup.Tag.__ne__ (   self,
  other 
)
Returns true iff this tag is not identical to the other tag,
as defined in __eq__.

Definition at line 684 of file BeautifulSoup.py.

684  def __ne__(self, other):
685  """Returns true iff this tag is not identical to the other tag,
686  as defined in __eq__."""
687  return not self == other
688 
def __ne__(self, other)
def BeautifulSoup.Tag.__nonzero__ (   self)

Definition at line 626 of file BeautifulSoup.py.

Referenced by Types.bool.__bool__().

626  def __nonzero__(self):
627  "A tag is non-None even if it has no contents."
628  return True
629 
def __nonzero__(self)
def BeautifulSoup.Tag.__repr__ (   self,
  encoding = DEFAULT_OUTPUT_ENCODING 
)
def BeautifulSoup.Tag.__setitem__ (   self,
  key,
  value 
)
Setting tag[key] sets the value of the 'key' attribute for the
tag.

Definition at line 630 of file BeautifulSoup.py.

References BeautifulSoup.Tag._getAttrMap(), BeautifulSoup.Tag.attrMap, and BeautifulSoup.Tag.attrs.

630  def __setitem__(self, key, value):
631  """Setting tag[key] sets the value of the 'key' attribute for the
632  tag."""
633  self._getAttrMap()
634  self.attrMap[key] = value
635  found = False
636  for i in range(0, len(self.attrs)):
637  if self.attrs[i][0] == key:
638  self.attrs[i] = (key, value)
639  found = True
640  if not found:
641  self.attrs.append((key, value))
642  self._getAttrMap()[key] = value
643 
def _getAttrMap(self)
def __setitem__(self, key, value)
def BeautifulSoup.Tag.__str__ (   self,
  encoding = DEFAULT_OUTPUT_ENCODING,
  prettyPrint = False,
  indentLevel = 0 
)
Returns a string or Unicode representation of this tag and
its contents. To get Unicode, pass None for encoding.

NOTE: since Python's HTML parser consumes whitespace, this
method is not certain to reproduce the whitespace present in
the original string.

Definition at line 697 of file BeautifulSoup.py.

References BeautifulSoup.PageElement._sub_entity(), BeautifulSoup.Tag.attrs, BeautifulSoup.Tag.containsSubstitutions, BeautifulSoup.Tag.hidden, BeautifulSoup.Tag.isSelfClosing, join(), AlignableObjectId::entry.name, cond::persistency::TAG::NAME.name, TmModule.name, cond::persistency::GLOBAL_TAG::NAME.name, cond::persistency::RUN_INFO::RUN_NUMBER.name, cond::persistency::TAG::TIME_TYPE.name, cond::persistency::GLOBAL_TAG::VALIDITY.name, cond::persistency::RUN_INFO::START_TIME.name, cond::persistency::TAG::OBJECT_TYPE.name, cond::persistency::GLOBAL_TAG::DESCRIPTION.name, cond::persistency::RUN_INFO::END_TIME.name, cond::persistency::TAG::SYNCHRONIZATION.name, cond::persistency::GLOBAL_TAG::RELEASE.name, cond::persistency::TAG::END_OF_VALIDITY.name, cond::persistency::GLOBAL_TAG::SNAPSHOT_TIME.name, cond::persistency::TAG::DESCRIPTION.name, cond::persistency::GTEditorData.name, cond::persistency::GLOBAL_TAG::INSERTION_TIME.name, cond::persistency::TAG::LAST_VALIDATED_TIME.name, cond::persistency::TAG::INSERTION_TIME.name, nanoaod::MergeableCounterTable::SingleColumn< T >.name, cond::persistency::TAG::MODIFICATION_TIME.name, preexistingValidation.PreexistingValidation.name, PixelDCSObject< T >::Item.name, cond::persistency::GTProxyData.name, lumi::TriggerInfo.name, cond::TimeTypeSpecs.name, alignment.Alignment.name, PixelEndcapLinkMaker::Item.name, cond::persistency::GLOBAL_TAG_MAP::GLOBAL_TAG_NAME.name, PixelBarrelLinkMaker::Item.name, cond::persistency::GLOBAL_TAG_MAP::RECORD.name, cond::persistency::GLOBAL_TAG_MAP::LABEL.name, cond::persistency::GLOBAL_TAG_MAP::TAG_NAME.name, ExpressionHisto< T >.name, MEtoEDM< T >::MEtoEDMObject.name, cms::DDAlgoArguments.name, XMLProcessor::_loaderBaseConfig.name, cond::persistency::PAYLOAD::HASH.name, cond::persistency::PAYLOAD::OBJECT_TYPE.name, cond::persistency::PAYLOAD::DATA.name, cond::persistency::PAYLOAD::STREAMER_INFO.name, cond::persistency::PAYLOAD::VERSION.name, genericValidation.GenericValidation.name, cond::persistency::PAYLOAD::INSERTION_TIME.name, nanoaod::MergeableCounterTable::VectorColumn< T >.name, h4DSegm.name, PhysicsTools::Calibration::Variable.name, cond::TagInfo_t.name, TrackerSectorStruct.name, cond::persistency::IOV::TAG_NAME.name, cond::persistency::IOV::SINCE.name, Mapper::definition< ScannerT >.name, cond::persistency::IOV::PAYLOAD_HASH.name, classes.MonitorData.name, cond::persistency::IOV::INSERTION_TIME.name, MuonGeometrySanityCheckPoint.name, classes.OutputData.name, h2DSegm.name, nanoaod::FlatTable::Column.name, geometry.Structure.name, cond::persistency::TAG_LOG::TAG_NAME.name, cond::persistency::TAG_LOG::EVENT_TIME.name, cond::persistency::TAG_LOG::USER_NAME.name, cond::persistency::TAG_LOG::HOST_NAME.name, cond::persistency::TAG_LOG::COMMAND.name, cond::persistency::TAG_LOG::ACTION.name, cond::persistency::TAG_LOG::USER_TEXT.name, plotscripts.SawTeethFunction.name, crabFunctions.CrabTask.name, hTMaxCell.name, BeautifulSoup.Tag.name, BeautifulSoup.PageElement.nextSibling, BeautifulSoup.Tag.renderContents(), BeautifulSoup.PageElement.substituteEncoding(), and BeautifulSoup.PageElement.toEncoding().

Referenced by edmStreamStallGrapher.Point.__repr__(), BeautifulSoup.Tag.__repr__(), BeautifulSoup.Tag.__unicode__(), and BeautifulSoup.Tag.prettify().

697  prettyPrint=False, indentLevel=0):
698  """Returns a string or Unicode representation of this tag and
699  its contents. To get Unicode, pass None for encoding.
700 
701  NOTE: since Python's HTML parser consumes whitespace, this
702  method is not certain to reproduce the whitespace present in
703  the original string."""
704 
705  encodedName = self.toEncoding(self.name, encoding)
706 
707  attrs = []
708  if self.attrs:
709  for key, val in self.attrs:
710  fmt = '%s="%s"'
711  if isinstance(val, basestring):
712  if self.containsSubstitutions and '%SOUP-ENCODING%' in val:
713  val = self.substituteEncoding(val, encoding)
714 
715  # The attribute value either:
716  #
717  # * Contains no embedded double quotes or single quotes.
718  # No problem: we enclose it in double quotes.
719  # * Contains embedded single quotes. No problem:
720  # double quotes work here too.
721  # * Contains embedded double quotes. No problem:
722  # we enclose it in single quotes.
723  # * Embeds both single _and_ double quotes. This
724  # can't happen naturally, but it can happen if
725  # you modify an attribute value after parsing
726  # the document. Now we have a bit of a
727  # problem. We solve it by enclosing the
728  # attribute in single quotes, and escaping any
729  # embedded single quotes to XML entities.
730  if '"' in val:
731  fmt = "%s='%s'"
732  if "'" in val:
733  # TODO: replace with apos when
734  # appropriate.
735  val = val.replace("'", "&squot;")
736 
737  # Now we're okay w/r/t quotes. But the attribute
738  # value might also contain angle brackets, or
739  # ampersands that aren't part of entities. We need
740  # to escape those to XML entities too.
741  val = self.BARE_AMPERSAND_OR_BRACKET.sub(self._sub_entity, val)
742 
743  attrs.append(fmt % (self.toEncoding(key, encoding),
744  self.toEncoding(val, encoding)))
745  close = ''
746  closeTag = ''
747  if self.isSelfClosing:
748  close = ' /'
749  else:
750  closeTag = '</%s>' % encodedName
751 
752  indentTag, indentContents = 0, 0
753  if prettyPrint:
754  indentTag = indentLevel
755  space = (' ' * (indentTag-1))
756  indentContents = indentTag + 1
757  contents = self.renderContents(encoding, prettyPrint, indentContents)
758  if self.hidden:
759  s = contents
760  else:
761  s = []
762  attributeString = ''
763  if attrs:
764  attributeString = ' ' + ' '.join(attrs)
765  if prettyPrint:
766  s.append(space)
767  s.append('<%s%s%s>' % (encodedName, attributeString, close))
768  if prettyPrint:
769  s.append("\n")
770  s.append(contents)
771  if prettyPrint and contents and contents[-1] != "\n":
772  s.append("\n")
773  if prettyPrint and closeTag:
774  s.append(space)
775  s.append(closeTag)
776  if prettyPrint and closeTag and self.nextSibling:
777  s.append("\n")
778  s = ''.join(s)
779  return s
780 
def toEncoding(self, s, encoding=None)
def renderContents(self, encoding=DEFAULT_OUTPUT_ENCODING, prettyPrint=False, indentLevel=0)
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def substituteEncoding(self, str, encoding=None)
def BeautifulSoup.Tag.__unicode__ (   self)
def BeautifulSoup.Tag._convertEntities (   self,
  match 
)
private
Used in a call to re.sub to replace HTML, XML, and numeric
entities with the appropriate Unicode characters. If HTML
entities are being converted, any unrecognized entities are
escaped.

Definition at line 510 of file BeautifulSoup.py.

References BeautifulSoup.Tag.__init__(), BeautifulSoup.Tag.convertHTMLEntities, BeautifulSoup.Tag.convertXMLEntities, BeautifulSoup.Tag.escapeUnrecognizedEntities, and createfilelist.int.

510  def _convertEntities(self, match):
511  """Used in a call to re.sub to replace HTML, XML, and numeric
512  entities with the appropriate Unicode characters. If HTML
513  entities are being converted, any unrecognized entities are
514  escaped."""
515  x = match.group(1)
516  if self.convertHTMLEntities and x in name2codepoint:
517  return unichr(name2codepoint[x])
518  elif x in self.XML_ENTITIES_TO_SPECIAL_CHARS:
519  if self.convertXMLEntities:
520  return self.XML_ENTITIES_TO_SPECIAL_CHARS[x]
521  else:
522  return u'&%s;' % x
523  elif len(x) > 0 and x[0] == '#':
524  # Handle numeric entities
525  if len(x) > 1 and x[1] == 'x':
526  return unichr(int(x[2:], 16))
527  else:
528  return unichr(int(x[1:]))
529 
530  elif self.escapeUnrecognizedEntities:
531  return u'&amp;%s;' % x
532  else:
533  return u'&%s;' % x
534 
def _convertEntities(self, match)
def BeautifulSoup.Tag._getAttrMap (   self)
private
Initializes a map representation of this tag's attributes,
if not already initialized.

Definition at line 864 of file BeautifulSoup.py.

Referenced by BeautifulSoup.Tag.__delitem__(), BeautifulSoup.Tag.__getitem__(), BeautifulSoup.Tag.__setitem__(), BeautifulSoup.Tag.get(), and BeautifulSoup.Tag.has_key().

864  def _getAttrMap(self):
865  """Initializes a map representation of this tag's attributes,
866  if not already initialized."""
867  if not getattr(self, 'attrMap'):
868  self.attrMap = {}
869  for (key, value) in self.attrs:
870  self.attrMap[key] = value
871  return self.attrMap
872 
def _getAttrMap(self)
def BeautifulSoup.Tag.childGenerator (   self)

Definition at line 874 of file BeautifulSoup.py.

References BeautifulSoup.Tag.contents.

Referenced by BeautifulSoup.Tag.findAll().

874  def childGenerator(self):
875  # Just use the iterator from the contents
876  return iter(self.contents)
877 
def childGenerator(self)
def BeautifulSoup.Tag.clear (   self)
def BeautifulSoup.Tag.decompose (   self)
Recursively destroys the contents of this tree.

Definition at line 781 of file BeautifulSoup.py.

References BeautifulSoup.Tag.contents, and BeautifulSoup.PageElement.extract().

781  def decompose(self):
782  """Recursively destroys the contents of this tree."""
783  self.extract()
784  if len(self.contents) == 0:
785  return
786  current = self.contents[0]
787  while current is not None:
788  next = current.next
789  if isinstance(current, Tag):
790  del current.contents[:]
791  current.parent = None
792  current.previous = None
793  current.previousSibling = None
794  current.next = None
795  current.nextSibling = None
796  current = next
797 
def BeautifulSoup.Tag.fetchText (   self,
  text = None,
  recursive = True,
  limit = None 
)

Definition at line 856 of file BeautifulSoup.py.

References BeautifulSoup.Tag.findAll().

856  def fetchText(self, text=None, recursive=True, limit=None):
857  return self.findAll(text=text, recursive=recursive, limit=limit)
858 
def fetchText(self, text=None, recursive=True, limit=None)
def findAll(self, name=None, attrs={}, recursive=True, text=None, limit=None, kwargs)
def BeautifulSoup.Tag.find (   self,
  name = None,
  attrs = {},
  recursive = True,
  text = None,
  kwargs 
)
Return only the first child of this Tag matching the given
criteria.

Definition at line 825 of file BeautifulSoup.py.

References BeautifulSoup.Tag.findAll().

Referenced by BeautifulSoup.Tag.__getattr__(), BeautifulSoup.Tag.firstText(), and BeautifulSoup.Tag.renderContents().

825  **kwargs):
826  """Return only the first child of this Tag matching the given
827  criteria."""
828  r = None
829  l = self.findAll(name, attrs, recursive, text, 1, **kwargs)
830  if l:
831  r = l[0]
832  return r
def findAll(self, name=None, attrs={}, recursive=True, text=None, limit=None, kwargs)
def BeautifulSoup.Tag.findAll (   self,
  name = None,
  attrs = {},
  recursive = True,
  text = None,
  limit = None,
  kwargs 
)
Extracts a list of Tag objects that match the given
criteria.  You can specify the name of the Tag and any
attributes you want the Tag to have.

The value of a key-value pair in the 'attrs' map can be a
string, a list of strings, a regular expression object, or a
callable that takes a string and returns whether or not the
string matches for some custom definition of 'matches'. The
same is true of the tag name.

Definition at line 836 of file BeautifulSoup.py.

References BeautifulSoup.PageElement._findAll(), BeautifulSoup.Tag.childGenerator(), and BeautifulSoup.Tag.recursiveChildGenerator().

Referenced by BeautifulSoup.Tag.__call__(), BeautifulSoup.Tag.fetchText(), and BeautifulSoup.Tag.find().

836  limit=None, **kwargs):
837  """Extracts a list of Tag objects that match the given
838  criteria. You can specify the name of the Tag and any
839  attributes you want the Tag to have.
840 
841  The value of a key-value pair in the 'attrs' map can be a
842  string, a list of strings, a regular expression object, or a
843  callable that takes a string and returns whether or not the
844  string matches for some custom definition of 'matches'. The
845  same is true of the tag name."""
846  generator = self.recursiveChildGenerator
847  if not recursive:
848  generator = self.childGenerator
849  return self._findAll(name, attrs, text, limit, generator, **kwargs)
def childGenerator(self)
def recursiveChildGenerator(self)
def _findAll(self, name, attrs, text, limit, generator, kwargs)
def BeautifulSoup.Tag.firstText (   self,
  text = None,
  recursive = True 
)
def BeautifulSoup.Tag.get (   self,
  key,
  default = None 
)
def BeautifulSoup.Tag.getString (   self)

Definition at line 564 of file BeautifulSoup.py.

References BeautifulSoup.Tag.contents.

564  def getString(self):
565  if (len(self.contents) == 1
566  and isinstance(self.contents[0], NavigableString)):
567  return self.contents[0]
568 
def BeautifulSoup.Tag.getText (   self,
  separator = u"" 
)

Definition at line 576 of file BeautifulSoup.py.

References BeautifulSoup.PageElement._lastRecursiveChild(), and BeautifulSoup.Tag.contents.

576  def getText(self, separator=u""):
577  if not len(self.contents):
578  return u""
579  stopNode = self._lastRecursiveChild().next
580  strings = []
581  current = self.contents[0]
582  while current is not stopNode:
583  if isinstance(current, NavigableString):
584  strings.append(current.strip())
585  current = current.next
586  return separator.join(strings)
587 
def getText(self, separator=u"")
def BeautifulSoup.Tag.has_key (   self,
  key 
)

Definition at line 607 of file BeautifulSoup.py.

References BeautifulSoup.Tag._getAttrMap().

607  def has_key(self, key):
608  return self._getAttrMap().has_key(key)
609 
def _getAttrMap(self)
def has_key(self, key)
def BeautifulSoup.Tag.index (   self,
  element 
)

Definition at line 601 of file BeautifulSoup.py.

References BeautifulSoup.Tag.contents.

Referenced by BeautifulSoup.PageElement.insert().

601  def index(self, element):
602  for i, child in enumerate(self.contents):
603  if child is element:
604  return i
605  raise ValueError("Tag.index: element not in tag")
606 
def index(self, element)
def BeautifulSoup.Tag.prettify (   self,
  encoding = DEFAULT_OUTPUT_ENCODING 
)
def BeautifulSoup.Tag.recursiveChildGenerator (   self)

Definition at line 878 of file BeautifulSoup.py.

References BeautifulSoup.PageElement._lastRecursiveChild(), and BeautifulSoup.Tag.contents.

Referenced by BeautifulSoup.Tag.findAll().

879  if not len(self.contents):
880  raise StopIteration
881  stopNode = self._lastRecursiveChild().next
882  current = self.contents[0]
883  while current is not stopNode:
884  yield current
885  current = current.next
886 
887 
888 # Next, a couple classes to represent queries and their results.
def recursiveChildGenerator(self)
def BeautifulSoup.Tag.renderContents (   self,
  encoding = DEFAULT_OUTPUT_ENCODING,
  prettyPrint = False,
  indentLevel = 0 
)
Renders the contents of this tag as a string in the given
encoding. If encoding is None, returns a Unicode string..

Definition at line 802 of file BeautifulSoup.py.

References BeautifulSoup.Tag.find(), and join().

Referenced by BeautifulSoup.Tag.__str__(), and BeautifulSoup.Tag.prettify().

802  prettyPrint=False, indentLevel=0):
803  """Renders the contents of this tag as a string in the given
804  encoding. If encoding is None, returns a Unicode string.."""
805  s=[]
806  for c in self:
807  text = None
808  if isinstance(c, NavigableString):
809  text = c.__str__(encoding)
810  elif isinstance(c, Tag):
811  s.append(c.__str__(encoding, prettyPrint, indentLevel))
812  if text and prettyPrint:
813  text = text.strip()
814  if text:
815  if prettyPrint:
816  s.append(" " * (indentLevel-1))
817  s.append(text)
818  if prettyPrint:
819  s.append("\n")
820  return ''.join(s)
821 
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def BeautifulSoup.Tag.setString (   self,
  string 
)
Replace the contents of the tag with a string

Definition at line 569 of file BeautifulSoup.py.

References reco::ClusterCompatibility.append(), svgfig.SVG.append(), BeautifulSoup.PageElement.append(), ReducedTrackerTreeVariables.clear(), EopVariables.clear(), CastorCalibrationsSet.clear(), TkOffTreeVariables.clear(), StringMap.clear(), TrackerTreeVariables.clear(), AlignmentErrors.clear(), AlignmentErrorsExtended.clear(), Alignments.clear(), NumberOfDevices.clear(), CastorCalibrationWidthsSet.clear(), edm::reftobase::RefVectorHolderBase.clear(), OOTPileupCorrectionColl.clear(), HcalCalibrationsSet.clear(), HcalCalibrationWidthsSet.clear(), StorableDoubleMap< T >.clear(), EcalCondObjectContainer< T >.clear(), edm::BranchChildren.clear(), EcalContainer< DetId, T >.clear(), edm::reftobase::RefVectorHolder< REFV >.clear(), edm::reftobase::BaseVectorHolder< T >.clear(), CSCALCTDigi.clear(), HcalIndexLookup.clear(), HcalItemColl< Item >.clear(), CSCCLCTPreTriggerDigi.clear(), CSCCLCTDigi.clear(), helper::ClusterStorer.clear(), edm::reftobase::IndirectVectorHolder< T >.clear(), ClusterCollectionFP420.clear(), RecoCollectionFP420.clear(), TrackCollectionFP420.clear(), DigiCollectionFP420.clear(), KDTreeLinkerAlgo< DATA >.clear(), CSCCorrelatedLCTDigi.clear(), reco::PattRecoTree< ScaleType, Cluster >.clear(), ClhepEvaluator.clear(), OpticalAlignMeasurementInfo.clear(), SiPixelPerformanceSummary.clear(), SegmentToTrackAssociator.clear(), pos::PixelROCStatus.clear(), edm::reftobase::VectorHolder< T, REFV >.clear(), HBHEChannelInfo.clear(), edm::OrphanHandleBase.clear(), AlignmentParameterSelector.clear(), ME0TriggerDigi.clear(), HcalItemArrayColl< Item, N >.clear(), edm::ParentageRegistry.clear(), HLTPerformanceInfo::Module.clear(), CSCTriggerContainer< T >.clear(), edm::RefToBaseVector< T >.clear(), edm::StreamedProduct.clear(), DTBufferTree< Key, Content >.clear(), DrawIteration.clear(), edm::ThinnedAssociationsHelper.clear(), KDTreeNodes< DATA >.clear(), cond::Iov_t.clear(), OpticalAlignParam.clear(), edm::HandleBase.clear(), SiStripQuality.clear(), edm::TrieFactory< T >.clear(), SiStripDelay.clear(), DDI::Store< N, I, K >.clear(), cond::Tag_t.clear(), TrackerDetToDTCELinkCablingMap.clear(), edm::Association< C >.clear(), SiPixelCalibDigiProducer.clear(), edm::DetSet< T >.clear(), edm::ProcessHistory.clear(), MuonResidualsFromTrack.clear(), CTPPSRPAlignmentCorrectionsData.clear(), edm::PtrVectorBase.clear(), HLTPerformanceInfo::Path.clear(), l1t::IntervalManager< TimeType, PayloadType >.clear(), BXVector< T >.clear(), edm::AssociationVector< KeyRefProd, CVal, KeyRef, SizeType, KeyReferenceHelper >.clear(), DTCCBConfig.clear(), OpticalAlignInfo.clear(), StudyHLT.clear(), DDXMLElement.clear(), FQueue< T >.clear(), DTLVStatus.clear(), edm::BasicHandle.clear(), DTT0.clear(), edm::RefVectorBase< KEY >.clear(), DTTPGParameters.clear(), DTRangeT0.clear(), AlignmentParameterSelector::PXBDetIdRanges.clear(), DTHVStatus.clear(), edm::TrieNode< T >.clear(), DTReadOutMapping.clear(), edm::OwnArray< T, MAX_SIZE, P >.clear(), reco::FlavorHistoryEvent.clear(), AlignmentParameterSelector::PXFDetIdRanges.clear(), edm::AssociationMap< Tag >.clear(), edm::RefVector< C, T, F >.clear(), DTPerformance.clear(), DTTtrig.clear(), AlignmentParameterSelector::TIBDetIdRanges.clear(), DTStatusFlag.clear(), HLTPerformanceInfo.clear(), edm::OwnVector< T, P >.clear(), edm::ValueMap< T >.clear(), DTDeadFlag.clear(), AlignmentParameterSelector::TIDDetIdRanges.clear(), AlignmentParameterSelector::TOBDetIdRanges.clear(), DTMtime.clear(), pos::PixelFEDCard.clear(), math::Graph< N, E >.clear(), AlignmentParameterSelector::TECDetIdRanges.clear(), edm::Trie< T >.clear(), reco::HitPattern.clear(), and BeautifulSoup.Tag.clear().

569  def setString(self, string):
570  """Replace the contents of the tag with a string"""
571  self.clear()
572  self.append(string)
573 
def setString(self, string)

Member Data Documentation

BeautifulSoup.Tag.attrMap
BeautifulSoup.Tag.attrs
BeautifulSoup.Tag.containsSubstitutions

Definition at line 552 of file BeautifulSoup.py.

Referenced by BeautifulSoup.Tag.__str__().

BeautifulSoup.Tag.contents
BeautifulSoup.Tag.convertHTMLEntities
BeautifulSoup.Tag.convertXMLEntities
BeautifulSoup.Tag.escapeUnrecognizedEntities

Definition at line 555 of file BeautifulSoup.py.

Referenced by BeautifulSoup.Tag._convertEntities().

BeautifulSoup.Tag.hidden

Definition at line 551 of file BeautifulSoup.py.

Referenced by BeautifulSoup.Tag.__str__().

BeautifulSoup.Tag.isSelfClosing

Definition at line 542 of file BeautifulSoup.py.

Referenced by BeautifulSoup.Tag.__str__().

BeautifulSoup.Tag.name

Definition at line 543 of file BeautifulSoup.py.

Referenced by ElectronMVAID.ElectronMVAID.__call__(), FWLite.ElectronMVAID.__call__(), dirstructure.Directory.__create_pie_image(), DisplayManager.DisplayManager.__del__(), dqm_interfaces.DirID.__eq__(), BeautifulSoup.Tag.__eq__(), dirstructure.Directory.__get_full_path(), dirstructure.Comparison.__get_img_name(), dataset.Dataset.__getDataType(), dataset.Dataset.__getFileInfoList(), dirstructure.Comparison.__make_image(), core.autovars.NTupleVariable.__repr__(), core.autovars.NTupleObjectType.__repr__(), core.autovars.NTupleObject.__repr__(), core.autovars.NTupleCollection.__repr__(), dirstructure.Directory.__repr__(), dqm_interfaces.DirID.__repr__(), dirstructure.Comparison.__repr__(), config.Service.__setattr__(), config.CFG.__str__(), counter.Counter.__str__(), average.Average.__str__(), BeautifulSoup.Tag.__str__(), BeautifulSoup.SoupStrainer.__str__(), FWLite.WorkingPoints._reformat_cut_definitions(), core.autovars.NTupleObjectType.addSubObjects(), core.autovars.NTupleObjectType.addVariables(), core.autovars.NTupleObjectType.allVars(), dirstructure.Directory.calcStats(), validation.Sample.digest(), python.rootplot.utilities.Hist.divide(), python.rootplot.utilities.Hist.divide_wilson(), DisplayManager.DisplayManager.Draw(), TreeCrawler.Package.dump(), core.autovars.NTupleVariable.fillBranch(), core.autovars.NTupleObject.fillBranches(), core.autovars.NTupleCollection.fillBranchesScalar(), core.autovars.NTupleCollection.fillBranchesVector(), core.autovars.NTupleCollection.get_cpp_declaration(), core.autovars.NTupleCollection.get_cpp_wrapper_class(), core.autovars.NTupleCollection.get_py_wrapper_class(), utils.StatisticalTest.get_status(), production_tasks.Task.getname(), dataset.CMSDataset.getPrimaryDatasetEntries(), dataset.PrivateDataset.getPrimaryDatasetEntries(), VIDSelectorBase.VIDSelectorBase.initialize(), personalPlayback.Applet.log(), core.autovars.NTupleVariable.makeBranch(), core.autovars.NTupleObject.makeBranches(), core.autovars.NTupleCollection.makeBranchesScalar(), core.autovars.NTupleCollection.makeBranchesVector(), dirstructure.Directory.print_report(), dataset.BaseDataset.printInfo(), dataset.Dataset.printInfo(), production_tasks.MonitorJobs.run(), BeautifulSoup.SoupStrainer.searchTag(), python.rootplot.utilities.Hist.TGraph(), python.rootplot.utilities.Hist.TH1F(), Vispa.Views.PropertyView.Property.valueChanged(), counter.Counter.write(), and average.Average.write().

BeautifulSoup.Tag.parserClass

Definition at line 541 of file BeautifulSoup.py.

Property Documentation

BeautifulSoup.Tag.string = property(getString, setString)
static

Definition at line 574 of file BeautifulSoup.py.

BeautifulSoup.Tag.text = property(getText)
static