cssutils.parseStyle

104 views
Skip to first unread message

Walter Dörwald

unread,
Dec 12, 2010, 2:52:54 AM12/12/10
to cssutils
Hello all!

I like the new function cssutils.parseStyle() for parsing HTML style
attributes. I have been using:

cssutils.parseString(u"a{{{}}}".format(value))

However I would like to be able to replace URLs in the generated
CSSStyleDeclaration, and cssutils.replaceUrls() doesn't seem to accept a
CSSStyleDeclaration object as argument.

Would it make sense to extend cssutils.replaceUrls() so that I can call
it with a CSSStyleDeclaration argument?

Servus,
Walter

see

unread,
Dec 12, 2010, 5:37:15 AM12/12/10
to cssutils
hi Walter,
This should be pretty easy. As I am in the process of changing quite a
lot I could add this for the next alpha release (this month). So you
suggest::

cssutils.replaceUrls(CSSStyleDeclaration(...))

instead of the now required CSSStyleSheet argument? One could even
consider

cssutils.replaceUrls(style=styleAttributeString)

but maybe it is too much in a single function...

thanks
Christof

P.S.: Obviously not much traffic here, I almost thought about closing
this group all together. Any thoughts?

see

unread,
Dec 12, 2010, 7:45:57 AM12/12/10
to cssutils
I actually implemented this in trunk. Please check it out. (No release
yet, maybe today or in the next week)

Walter Dörwald

unread,
Dec 13, 2010, 6:13:33 AM12/13/10
to see, cssutils
On 12.12.10 11:37, see wrote:

> hi Walter,
>
>> I like the new function cssutils.parseStyle() for parsing HTML style
>> attributes. I have been using:
>>
>> cssutils.parseString(u"a{{{}}}".format(value))
>>
>> However I would like to be able to replace URLs in the generated
>> CSSStyleDeclaration, and cssutils.replaceUrls() doesn't seem to accept a
>> CSSStyleDeclaration object as argument.
>>
>> Would it make sense to extend cssutils.replaceUrls() so that I can call
>> it with a CSSStyleDeclaration argument?
>
> This should be pretty easy. As I am in the process of changing quite a
> lot I could add this for the next alpha release (this month). So you
> suggest::
>
> cssutils.replaceUrls(CSSStyleDeclaration(...))
>
> instead of the now required CSSStyleSheet argument?

Exactly.

> One could even
> consider
>
> cssutils.replaceUrls(style=styleAttributeString)
>
> but maybe it is too much in a single function...

IMHO this is too much. And it is unsymmetric. replaceUrls() does the
parsing, but the result isn't serialized again.

> thanks
> Christof
>
> P.S.: Obviously not much traffic here, I almost thought about closing
> this group all together. Any thoughts?

As long as there's not much effort for managing the mailing list (and
there are subscribers ;)) you should keep it open.

Servus,
Walter


Walter Dörwald

unread,
Dec 13, 2010, 11:04:50 AM12/13/10
to see, cssutils
On 12.12.10 13:45, see wrote:

> I actually implemented this in trunk. Please check it out. (No release
> yet, maybe today or in the next week)

Works perfectly, however I'm wondering why you're using:

type(sheetOrStyle) != css.CSSStyleDeclaration

instead of

not isinstance(sheetOrStyle, css.CSSStyleDeclaration)

Servus,
Walter

Christof

unread,
Dec 13, 2010, 2:45:18 PM12/13/10
to Walter Dörwald, cssutils
no particular reason. I always wonder what the best approach to this is.

not isinstance( seems simpler. guess I just change it, thanks!

Walter Dörwald

unread,
Dec 14, 2010, 5:18:58 AM12/14/10
to Christof, cssutils
On 13.12.10 20:45, Christof wrote:
> On 13.12.2010 17:04, Walter Dörwald wrote:
>> On 12.12.10 13:45, see wrote:
>>
>>> I actually implemented this in trunk. Please check it out. (No release
>>> yet, maybe today or in the next week)
>> Works perfectly, however I'm wondering why you're using:
>>
>> type(sheetOrStyle) != css.CSSStyleDeclaration
>>
>> instead of
>>
>> not isinstance(sheetOrStyle, css.CSSStyleDeclaration)
>>
>> Servus,
>> Walter
> no particular reason. I always wonder what the best approach to this is.

isinstance() is the canonical approach.

> not isinstance( seems simpler. guess I just change it, thanks!

The difference between the two test is that the test via type() doesn't
handle subclasses, isinstance() does.

Servus,
Walter

Reply all
Reply to author
Forward
0 new messages