MCPcopy Create free account
hub / github.com/gawel/pyquery / attr

Method attr

pyquery/pyquery.py:761–795  ·  view source on GitHub ↗

Attributes manipulation

(self, *args, **kwargs)

Source from the content-addressed store, hash-verified

759 # Attributes #
760 ##############
761 def attr(self, *args, **kwargs):
762 """Attributes manipulation
763 """
764
765 mapping = {'class_': 'class', 'for_': 'for'}
766
767 attr = value = no_default
768 length = len(args)
769 if length == 1:
770 attr = args[0]
771 attr = mapping.get(attr, attr)
772 elif length == 2:
773 attr, value = args
774 attr = mapping.get(attr, attr)
775 elif kwargs:
776 attr = {}
777 for k, v in kwargs.items():
778 attr[mapping.get(k, k)] = v
779 else:
780 raise ValueError('Invalid arguments %s %s' % (args, kwargs))
781
782 if not self:
783 return None
784 elif isinstance(attr, dict):
785 for tag in self:
786 for key, value in attr.items():
787 tag.set(key, value)
788 elif value is no_default:
789 return self[0].get(attr)
790 elif value is None:
791 return self.remove_attr(attr)
792 else:
793 for tag in self:
794 tag.set(attr, value)
795 return self
796
797 @with_camel_case_alias
798 def remove_attr(self, name):

Callers 12

heightMethod · 0.95
widthMethod · 0.95
_get_valueMethod · 0.80
_make_option_selectedMethod · 0.80
_set_valueMethod · 0.80
serialize_pairsMethod · 0.80
repMethod · 0.80
ids_minus_oneMethod · 0.80
test_closestMethod · 0.80
test_make_linkMethod · 0.80

Calls 2

remove_attrMethod · 0.95
itemsMethod · 0.80

Tested by 5

ids_minus_oneMethod · 0.64
test_closestMethod · 0.64
test_make_linkMethod · 0.64