Attributes manipulation
(self, *args, **kwargs)
| 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): |