CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Public Attributes | Private Member Functions
BeautifulSoup.SoupStrainer Class Reference

Public Member Functions

def __init__
 
def __init__
 
def __str__
 
def __str__
 
def search
 
def search
 
def searchTag
 
def searchTag
 

Public Attributes

 attrs
 
 name
 
 text
 

Private Member Functions

def _matches
 
def _matches
 

Detailed Description

Encapsulates a number of ways of matching a markup element (tag or
text).

Definition at line 841 of file BeautifulSoup.py.

Constructor & Destructor Documentation

def BeautifulSoup.SoupStrainer.__init__ (   self,
  name = None,
  attrs = {},
  text = None,
  kwargs 
)

Definition at line 845 of file BeautifulSoup.py.

Referenced by BeautifulSoup.SoupStrainer.__init__().

846  def __init__(self, name=None, attrs={}, text=None, **kwargs):
847  self.name = name
848  if isString(attrs):
849  kwargs['class'] = attrs
850  attrs = None
851  if kwargs:
852  if attrs:
853  attrs = attrs.copy()
854  attrs.update(kwargs)
855  else:
856  attrs = kwargs
857  self.attrs = attrs
858  self.text = text
def BeautifulSoup.SoupStrainer.__init__ (   self,
  name = None,
  attrs = {},
  text = None,
  kwargs 
)

Definition at line 845 of file BeautifulSoup.py.

References BeautifulSoup.SoupStrainer.__init__(), BeautifulSoup.SoupStrainer.attrs, BeautifulSoup.isString(), cond::TagInfo.name, entry.name, genericValidation.GenericValidation.name, TmModule.name, ora::RecordSpecImpl::Item.name, alignment.Alignment.name, PixelDCSObject< class >::Item.name, lumi::TriggerInfo.name, XMLHTRZeroSuppressionLoader::_loaderBaseConfig.name, XMLRBXPedestalsLoader::_loaderBaseConfig.name, cond::TimeTypeSpecs.name, PixelEndcapLinkMaker::Item.name, PixelBarrelLinkMaker::Item.name, Mapper::definition< ScannerT >.name, ExpressionHisto< T >.name, MEtoEDM< T >::MEtoEDMObject.name, XMLProcessor::_loaderBaseConfig.name, PhysicsTools::Calibration::Variable.name, h4DSegm.name, MuonGeometrySanityCheckPoint.name, h2DSegm.name, plotscripts.SawTeethFunction.name, hTMaxCell.name, BeautifulSoup.SoupStrainer.name, TmCcu.text, TmApvPair.text, TmModule.text, TmPsu.text, and BeautifulSoup.SoupStrainer.text.

846  def __init__(self, name=None, attrs={}, text=None, **kwargs):
847  self.name = name
848  if isString(attrs):
849  kwargs['class'] = attrs
850  attrs = None
851  if kwargs:
852  if attrs:
853  attrs = attrs.copy()
854  attrs.update(kwargs)
855  else:
856  attrs = kwargs
857  self.attrs = attrs
858  self.text = text

Member Function Documentation

def BeautifulSoup.SoupStrainer.__str__ (   self)

Definition at line 859 of file BeautifulSoup.py.

References BeautifulSoup.SoupStrainer.attrs, cond::TagInfo.name, entry.name, genericValidation.GenericValidation.name, TmModule.name, ora::RecordSpecImpl::Item.name, alignment.Alignment.name, PixelDCSObject< class >::Item.name, XMLHTRZeroSuppressionLoader::_loaderBaseConfig.name, XMLRBXPedestalsLoader::_loaderBaseConfig.name, lumi::TriggerInfo.name, cond::TimeTypeSpecs.name, PixelEndcapLinkMaker::Item.name, PixelBarrelLinkMaker::Item.name, Mapper::definition< ScannerT >.name, MEtoEDM< T >::MEtoEDMObject.name, ExpressionHisto< T >.name, XMLProcessor::_loaderBaseConfig.name, PhysicsTools::Calibration::Variable.name, h4DSegm.name, MuonGeometrySanityCheckPoint.name, h2DSegm.name, plotscripts.SawTeethFunction.name, hTMaxCell.name, BeautifulSoup.SoupStrainer.name, TmCcu.text, TmApvPair.text, TmModule.text, TmPsu.text, and BeautifulSoup.SoupStrainer.text.

Referenced by BeautifulSoup.SoupStrainer.__str__().

860  def __str__(self):
861  if self.text:
862  return self.text
863  else:
864  return "%s|%s" % (self.name, self.attrs)
def BeautifulSoup.SoupStrainer.__str__ (   self)

Definition at line 859 of file BeautifulSoup.py.

References BeautifulSoup.SoupStrainer.__str__(), BeautifulSoup.SoupStrainer.attrs, cond::TagInfo.name, entry.name, genericValidation.GenericValidation.name, TmModule.name, ora::RecordSpecImpl::Item.name, alignment.Alignment.name, PixelDCSObject< class >::Item.name, XMLHTRZeroSuppressionLoader::_loaderBaseConfig.name, XMLRBXPedestalsLoader::_loaderBaseConfig.name, lumi::TriggerInfo.name, cond::TimeTypeSpecs.name, PixelEndcapLinkMaker::Item.name, PixelBarrelLinkMaker::Item.name, Mapper::definition< ScannerT >.name, ExpressionHisto< T >.name, MEtoEDM< T >::MEtoEDMObject.name, XMLProcessor::_loaderBaseConfig.name, PhysicsTools::Calibration::Variable.name, h4DSegm.name, MuonGeometrySanityCheckPoint.name, h2DSegm.name, plotscripts.SawTeethFunction.name, hTMaxCell.name, BeautifulSoup.SoupStrainer.name, TmCcu.text, TmApvPair.text, TmModule.text, TmPsu.text, and BeautifulSoup.SoupStrainer.text.

860  def __str__(self):
861  if self.text:
862  return self.text
863  else:
864  return "%s|%s" % (self.name, self.attrs)
def BeautifulSoup.SoupStrainer._matches (   self,
  markup,
  matchAgainst 
)
private

Definition at line 928 of file BeautifulSoup.py.

References BeautifulSoup.SoupStrainer._matches(), BeautifulSoup.isList(), BeautifulSoup.isString(), and list().

929  def _matches(self, markup, matchAgainst):
930  #print "Matching %s against %s" % (markup, matchAgainst)
931  result = False
932  if matchAgainst == True and type(matchAgainst) == types.BooleanType:
933  result = markup != None
934  elif callable(matchAgainst):
935  result = matchAgainst(markup)
936  else:
937  #Custom match methods take the tag as an argument, but all
938  #other ways of matching match the tag name as a string.
939  if isinstance(markup, Tag):
940  markup = markup.name
941  if markup is not None and not isString(markup):
942  markup = unicode(markup)
943  #Now we know that chunk is either a string, or None.
944  if hasattr(matchAgainst, 'match'):
945  # It's a regexp object.
946  result = markup and matchAgainst.search(markup)
947  elif (isList(matchAgainst)
948  and (markup is not None or not isString(matchAgainst))):
949  result = markup in matchAgainst
950  elif hasattr(matchAgainst, 'items'):
951  result = markup.has_key(matchAgainst)
952  elif matchAgainst and isString(markup):
953  if isinstance(markup, unicode):
954  matchAgainst = unicode(matchAgainst)
955  else:
956  matchAgainst = str(matchAgainst)
957 
958  if not result:
959  result = matchAgainst == markup
960  return result
def BeautifulSoup.SoupStrainer._matches (   self,
  markup,
  matchAgainst 
)
private

Definition at line 928 of file BeautifulSoup.py.

References BeautifulSoup.isList(), and BeautifulSoup.isString().

Referenced by BeautifulSoup.SoupStrainer._matches(), BeautifulSoup.SoupStrainer.search(), and BeautifulSoup.SoupStrainer.searchTag().

929  def _matches(self, markup, matchAgainst):
930  #print "Matching %s against %s" % (markup, matchAgainst)
931  result = False
932  if matchAgainst == True and type(matchAgainst) == types.BooleanType:
933  result = markup != None
934  elif callable(matchAgainst):
935  result = matchAgainst(markup)
936  else:
937  #Custom match methods take the tag as an argument, but all
938  #other ways of matching match the tag name as a string.
939  if isinstance(markup, Tag):
940  markup = markup.name
941  if markup is not None and not isString(markup):
942  markup = unicode(markup)
943  #Now we know that chunk is either a string, or None.
944  if hasattr(matchAgainst, 'match'):
945  # It's a regexp object.
946  result = markup and matchAgainst.search(markup)
947  elif (isList(matchAgainst)
948  and (markup is not None or not isString(matchAgainst))):
949  result = markup in matchAgainst
950  elif hasattr(matchAgainst, 'items'):
951  result = markup.has_key(matchAgainst)
952  elif matchAgainst and isString(markup):
953  if isinstance(markup, unicode):
954  matchAgainst = unicode(matchAgainst)
955  else:
956  matchAgainst = str(matchAgainst)
957 
958  if not result:
959  result = matchAgainst == markup
960  return result
def BeautifulSoup.SoupStrainer.search (   self,
  markup 
)

Definition at line 902 of file BeautifulSoup.py.

References BeautifulSoup.SoupStrainer._matches(), BeautifulSoup.isList(), BeautifulSoup.isString(), BeautifulSoup.SoupStrainer.search(), BeautifulSoup.SoupStrainer.searchTag(), TmCcu.text, TmApvPair.text, TmModule.text, TmPsu.text, and BeautifulSoup.SoupStrainer.text.

903  def search(self, markup):
904  #print 'looking for %s in %s' % (self, markup)
905  found = None
906  # If given a list of items, scan it for a text element that
907  # matches.
908  if isList(markup) and not isinstance(markup, Tag):
909  for element in markup:
910  if isinstance(element, NavigableString) \
911  and self.search(element):
912  found = element
913  break
914  # If it's a Tag, make sure its name or attributes match.
915  # Don't bother with Tags if we're searching for text.
916  elif isinstance(markup, Tag):
917  if not self.text:
918  found = self.searchTag(markup)
919  # If it's text, make sure the text matches.
920  elif isinstance(markup, NavigableString) or \
921  isString(markup):
922  if self._matches(markup, self.text):
923  found = markup
924  else:
925  raise Exception, "I don't know how to match against a %s" \
926  % markup.__class__
927  return found
def BeautifulSoup.SoupStrainer.search (   self,
  markup 
)

Definition at line 902 of file BeautifulSoup.py.

References BeautifulSoup.SoupStrainer._matches(), BeautifulSoup.isList(), BeautifulSoup.isString(), BeautifulSoup.SoupStrainer.search(), BeautifulSoup.SoupStrainer.searchTag(), TmCcu.text, TmApvPair.text, TmModule.text, TmPsu.text, and BeautifulSoup.SoupStrainer.text.

Referenced by BeautifulSoup.SoupStrainer.search().

903  def search(self, markup):
904  #print 'looking for %s in %s' % (self, markup)
905  found = None
906  # If given a list of items, scan it for a text element that
907  # matches.
908  if isList(markup) and not isinstance(markup, Tag):
909  for element in markup:
910  if isinstance(element, NavigableString) \
911  and self.search(element):
912  found = element
913  break
914  # If it's a Tag, make sure its name or attributes match.
915  # Don't bother with Tags if we're searching for text.
916  elif isinstance(markup, Tag):
917  if not self.text:
918  found = self.searchTag(markup)
919  # If it's text, make sure the text matches.
920  elif isinstance(markup, NavigableString) or \
921  isString(markup):
922  if self._matches(markup, self.text):
923  found = markup
924  else:
925  raise Exception, "I don't know how to match against a %s" \
926  % markup.__class__
927  return found
def BeautifulSoup.SoupStrainer.searchTag (   self,
  markupName = None,
  markupAttrs = {} 
)

Definition at line 865 of file BeautifulSoup.py.

References BeautifulSoup.SoupStrainer._matches(), cond::TagInfo.name, entry.name, genericValidation.GenericValidation.name, TmModule.name, ora::RecordSpecImpl::Item.name, alignment.Alignment.name, PixelDCSObject< class >::Item.name, lumi::TriggerInfo.name, XMLRBXPedestalsLoader::_loaderBaseConfig.name, XMLHTRZeroSuppressionLoader::_loaderBaseConfig.name, cond::TimeTypeSpecs.name, PixelEndcapLinkMaker::Item.name, PixelBarrelLinkMaker::Item.name, Mapper::definition< ScannerT >.name, MEtoEDM< T >::MEtoEDMObject.name, ExpressionHisto< T >.name, XMLProcessor::_loaderBaseConfig.name, PhysicsTools::Calibration::Variable.name, h4DSegm.name, MuonGeometrySanityCheckPoint.name, h2DSegm.name, plotscripts.SawTeethFunction.name, hTMaxCell.name, and BeautifulSoup.SoupStrainer.name.

Referenced by BeautifulSoup.SoupStrainer.search(), and BeautifulSoup.SoupStrainer.searchTag().

866  def searchTag(self, markupName=None, markupAttrs={}):
867  found = None
868  markup = None
869  if isinstance(markupName, Tag):
870  markup = markupName
871  markupAttrs = markup
872  callFunctionWithTagData = callable(self.name) \
873  and not isinstance(markupName, Tag)
874 
875  if (not self.name) \
876  or callFunctionWithTagData \
877  or (markup and self._matches(markup, self.name)) \
878  or (not markup and self._matches(markupName, self.name)):
879  if callFunctionWithTagData:
880  match = self.name(markupName, markupAttrs)
881  else:
882  match = True
883  markupAttrMap = None
884  for attr, matchAgainst in self.attrs.items():
885  if not markupAttrMap:
886  if hasattr(markupAttrs, 'get'):
887  markupAttrMap = markupAttrs
888  else:
889  markupAttrMap = {}
890  for k,v in markupAttrs:
891  markupAttrMap[k] = v
892  attrValue = markupAttrMap.get(attr)
893  if not self._matches(attrValue, matchAgainst):
894  match = False
895  break
896  if match:
897  if markup:
898  found = markup
899  else:
900  found = markupName
901  return found
def BeautifulSoup.SoupStrainer.searchTag (   self,
  markupName = None,
  markupAttrs = {} 
)

Definition at line 865 of file BeautifulSoup.py.

References BeautifulSoup.SoupStrainer._matches(), cond::TagInfo.name, entry.name, genericValidation.GenericValidation.name, TmModule.name, ora::RecordSpecImpl::Item.name, alignment.Alignment.name, PixelDCSObject< class >::Item.name, lumi::TriggerInfo.name, XMLHTRZeroSuppressionLoader::_loaderBaseConfig.name, XMLRBXPedestalsLoader::_loaderBaseConfig.name, cond::TimeTypeSpecs.name, PixelEndcapLinkMaker::Item.name, PixelBarrelLinkMaker::Item.name, Mapper::definition< ScannerT >.name, ExpressionHisto< T >.name, MEtoEDM< T >::MEtoEDMObject.name, XMLProcessor::_loaderBaseConfig.name, PhysicsTools::Calibration::Variable.name, h4DSegm.name, MuonGeometrySanityCheckPoint.name, h2DSegm.name, plotscripts.SawTeethFunction.name, hTMaxCell.name, BeautifulSoup.SoupStrainer.name, and BeautifulSoup.SoupStrainer.searchTag().

866  def searchTag(self, markupName=None, markupAttrs={}):
867  found = None
868  markup = None
869  if isinstance(markupName, Tag):
870  markup = markupName
871  markupAttrs = markup
872  callFunctionWithTagData = callable(self.name) \
873  and not isinstance(markupName, Tag)
874 
875  if (not self.name) \
876  or callFunctionWithTagData \
877  or (markup and self._matches(markup, self.name)) \
878  or (not markup and self._matches(markupName, self.name)):
879  if callFunctionWithTagData:
880  match = self.name(markupName, markupAttrs)
881  else:
882  match = True
883  markupAttrMap = None
884  for attr, matchAgainst in self.attrs.items():
885  if not markupAttrMap:
886  if hasattr(markupAttrs, 'get'):
887  markupAttrMap = markupAttrs
888  else:
889  markupAttrMap = {}
890  for k,v in markupAttrs:
891  markupAttrMap[k] = v
892  attrValue = markupAttrMap.get(attr)
893  if not self._matches(attrValue, matchAgainst):
894  match = False
895  break
896  if match:
897  if markup:
898  found = markup
899  else:
900  found = markupName
901  return found

Member Data Documentation

BeautifulSoup.SoupStrainer.attrs

Definition at line 856 of file BeautifulSoup.py.

Referenced by BeautifulSoup.SoupStrainer.__init__(), BeautifulSoup.SoupStrainer.__str__(), and BeautifulSoup.Tag._invert().

BeautifulSoup.SoupStrainer.name

Definition at line 846 of file BeautifulSoup.py.

Referenced by dirstructure.Directory.__create_pie_image(), dqm_interfaces.DirID.__eq__(), dirstructure.Directory.__get_full_path(), dirstructure.Comparison.__get_img_name(), dataset.Dataset.__getFileInfoList(), cuy.divideElement.__init__(), cuy.plotElement.__init__(), cuy.additionElement.__init__(), cuy.superimposeElement.__init__(), cuy.graphElement.__init__(), BeautifulSoup.SoupStrainer.__init__(), dirstructure.Comparison.__make_image(), dirstructure.Directory.__repr__(), dqm_interfaces.DirID.__repr__(), dirstructure.Comparison.__repr__(), BeautifulSoup.SoupStrainer.__str__(), BeautifulSoup.Tag._invert(), dirstructure.Directory.calcStats(), python.rootplot.utilities.Hist.divide(), python.rootplot.utilities.Hist.divide_wilson(), TreeCrawler.Package.dump(), utils.StatisticalTest.get_status(), dirstructure.Directory.print_report(), BeautifulSoup.SoupStrainer.searchTag(), python.rootplot.utilities.Hist.TGraph(), python.rootplot.utilities.Hist.TH1F(), and Vispa.Views.PropertyView.Property.valueChanged().

BeautifulSoup.SoupStrainer.text

Definition at line 857 of file BeautifulSoup.py.

Referenced by BeautifulSoup.SoupStrainer.__init__(), Vispa.Views.TableView.TableWidgetItem.__lt__(), BeautifulSoup.SoupStrainer.__str__(), and BeautifulSoup.SoupStrainer.search().