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

Method css

pyquery/pyquery.py:909–946  ·  view source on GitHub ↗

css attributes manipulation

(self, *args, **kwargs)

Source from the content-addressed store, hash-verified

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

Callers 2

hideMethod · 0.95
showMethod · 0.95

Calls 3

itemsMethod · 0.80
appendMethod · 0.80
joinMethod · 0.80

Tested by

no test coverage detected