css attributes manipulation
(self, *args, **kwargs)
| 907 | return self |
| 908 | |
| 909 | def css(self, *args, **kwargs): |
| 910 | """css attributes manipulation |
| 911 | """ |
| 912 | |
| 913 | attr = value = no_default |
| 914 | length = len(args) |
| 915 | if length == 1: |
| 916 | attr = args[0] |
| 917 | elif length == 2: |
| 918 | attr, value = args |
| 919 | elif kwargs: |
| 920 | attr = kwargs |
| 921 | else: |
| 922 | raise ValueError('Invalid arguments %s %s' % (args, kwargs)) |
| 923 | |
| 924 | if isinstance(attr, dict): |
| 925 | for tag in self: |
| 926 | stripped_keys = [key.strip().replace('_', '-') |
| 927 | for key in attr.keys()] |
| 928 | current = [el.strip() |
| 929 | for el in (tag.get('style') or '').split(';') |
| 930 | if el.strip() |
| 931 | and el.split(':')[0].strip() not in stripped_keys] |
| 932 | for key, value in attr.items(): |
| 933 | key = key.replace('_', '-') |
| 934 | current.append('%s: %s' % (key, value)) |
| 935 | tag.set('style', '; '.join(current)) |
| 936 | elif isinstance(value, basestring): |
| 937 | attr = attr.replace('_', '-') |
| 938 | for tag in self: |
| 939 | current = [ |
| 940 | el.strip() |
| 941 | for el in (tag.get('style') or '').split(';') |
| 942 | if (el.strip() and |
| 943 | not el.split(':')[0].strip() == attr.strip())] |
| 944 | current.append('%s: %s' % (attr, value)) |
| 945 | tag.set('style', '; '.join(current)) |
| 946 | return self |
| 947 | |
| 948 | css = FlexibleElement(pget=css, pset=css) |
| 949 |