see whatever…

jump to menu

February 3, 2008

cssutils 0.9.5a3, the namespaces release ;)

Filed under: CSS,cssutils — see @ 11:05 pm

I finally managed to squeeze out a new alpha release of cssutils. I mainly implemented namespaces with all their implications. Namespace rules have been parsed for some time now but until now it was quite easy to build style sheets which were invalid regarding namespace usage. This should be difficult now as all namespaces are checked if they are used before deletion or it is checked if they are declared before adding a new rule or selector.

Actually adding a rule should be much simpler now as I added a new method CSSStyleSheet.add(rule) which adds a rule at the appropriate position in the sheet. Until now one had to use .insertRule(rule, index) which now has a new parameter inOrder=False which may be used the same way as .add(rule) but the new method is still much simpler as only the rule to add needs to be given, no index (which could be None and meant “at the end” until now) but also no setting of inOrder=True.

All in all this release made me quite a few headaches as the namespaces had to be checked all the way from a selector using them via the relevant selectorList, CSSStyleRule, possible CSSMediaRule upto CSSStyleSheet. I also implemented analogous to CSSStyleSheet.encoding which reflects a CSSCharsetRule .namespaces which reflects all CSSNamespaceRules.

I also added quite a few tests which actually revealed quite a few embarrassing bugs…

The next steps before a final 0.9.5 release will probably be the improvement of the csscombine script and a first implementation of ViewCSS. Actually a prototype is already in the SVN in examples/ It uses lxml (which just got to 2.0) but it should be quite easy to use other libs. Maybe I finish these works till the end of the month, let’s see…

February 1, 2008

coincidence or pre-pycon release wants?

Filed under: CSS,cssutils,Python,XML — see @ 7:40 pm

Maybe just coincidence but at least two Python libraries (or tools) I frequently use just got or soon get a new release

  • Epydoc, a Python package documentation tool just released v3.0
  • lxml is close to 2.0 (2.0b2 is out and final 2.0 should be out latest next week)

maybe coincidence but maybe also because Pycon is coming up…

On a side note, cssutils will probably have a new release in the next week or two as well ;-)

UPDATE: lxml just got a definite 2.0 release.

January 2, 2008

cssutils ongoings

Filed under: CSS,cssutils — see @ 11:58 pm

I started to actually query the sheets cssutils already does parse. Selector specificity is halfway done (ugly word BTW) but during development I found some serious issues. The CSSStyleDeclaration retrieval methods all ignored the priority of a property and some other minor stuff. I think it is fixed now but I need to do some more tests. But I guess at least an initial 0.9.5 alpha is due soon.

On a sidenote, 0.9.4b1 had the most downloads in the first days since release of all cssutils versions ever. I don’t get too much feedback (bad as would like to hear more, good as I probably won’t have the time to cope with much more ;) ) but it seems CSS in general and therefor “CSS libraries” have become more important in the last years despite CSS being around even before 2000. I guess CSS is taken more seriously as it is used quite nicely for e.g. selectors in libs like jQuery or lxml.

(I know cssutils is not hardly as useful but I think it is getting somewhere currently)

December 29, 2007

cssutils 0.9.4b1

Filed under: CSS,cssutils — see @ 7:19 pm

I’ve put probably (if no major problems occcur) the last but in any case the first beta release of cssutils online. Mainly a few improvements and bugfixes, a bit more docs and a thing here or there. The main feature may be a “combine” script which resolves @import rules in a sheet. Idea is to have a simple “proxy” CSS loaded from an HTML page which then loads all other needed CSS files (for e.g. layout, modules, colors or however you structure your CSS files). For production the “combine” script should be run which resolves the @imports in the proxy script (no nested imports yet!) and saves the resulting SINGLE CSS files optionally minified for deployment. The HTML does not have to be changed as the proxy ideally contains all needed CSS rules now. But for development a nice structure of CSS files may be used and kept…

Inspired by the Yahoo HTML performance guides (google for it, too lazy too look for the link now but I realize writing this comment almost takes longer ;) ) which propose to cut down on HTTP requests (very simplified summarized…). CSS certainly may quite easy be combined. Javascript is not as easy as it has no direct “include” facility, should be possible though.

Anyway, cssutils 0.9.5 will (probably) be adding better support for selectors, ideally it will be possible to query a cssutils stylesheet for styles for certain elements or documents. As this means building the complete first C of CSS (the Cascade) this will probably take a bit longer. But I guess it will make cssutils at least a bit more useful than just being a very big pretty printer…

BTW, I need to define which CSS hacks survive cssutils. I guess mostly hacks in the bounds of valid CSS will survive, currently the only non-valid hack “$propname” (used for IE) does survive. Anyway, something for next year ;)

December 2, 2007

cssutils 0.9.4a4 released

Filed under: CSS,cssutils — see @ 7:46 pm

Again a new alpha version has been released, not that it is really more alpha than all betas or even full releases before but mostly as it is not “fully” tested.

For the future I am not really sure where to go. I guess focusing on improvement of the usage of the library (simplify API e.g.) would be the best. cssutils till now is just a lib which can parse a given CSS and enhance/change it on the level of specific rules or build a new CSS from scratch. It is not possible to “render” anything but not even possible to query it on maybe a given HTML or XML document or a given CSS selector. So I guess the heavy work like reading the Cascade properly or get a single property value for a given element from a given CSS style sheet set can be built on top of it but rightfully should be part of cssutils.

It started as a pretty printer which it does not that bad, CSS hacks might get lost though and also not all CSS possible constructs are parsed as they should, try e.g. an advanced PrinceXML CSS sheet and see what is lost. Validation of simple (not necessarily short of course) sheets does work quite well too. It is not as bad as it sounds I guess – the average CSS should be handled quite well (and other CSS implementations have their problems too) but still sometimes it makes me fell depressed having done so much but hardly enough…

Generally cssutil should have more uses than that. Problem as always is time and also as most CSS implementation lack a full compliant implementation (even Operas or Firefox) I fear cssutils can only be even worse ;)

Let’s see how much time I can spare over christmas, maybe I try something like a query functionality…

October 21, 2007

cssutils 0.9.4a1

Filed under: CSS,cssutils — see @ 12:11 am

oops, this has been a lot of work… Originally I planned to add a few new features like MediaQueries in the new release but as Walter wanted to maybe add his tokenizer to the lib I actually rewrote the complete cssutils tokenizer and parser as well. I am not sure if it is faster or slower now but it should be more to the specs (optimizations may come later…).

The old tokenizer was really unwieldy and a bit of a mess. It gave a list of Token objects.

The new one actually just emits token tuples and is more or less a generator (there are some not very elegant things later in the parser which work around problems I had with generators (there is no “peek” method which would be very handy) but all in all this is a bit simpler).

The tokenizer itself uses the actual productions from the spec as regexes which is much shorter and easier to compare with the specs. There are a few special cases (the order of regexes or how incomplete stylesheets can still be “completed” by the tokenizer and not later by the parser). The parser also should able to chew more than to older one.

Only real problem was which spec to choose. It seems as CSS 3 is not final yet CSS2.1 should be used but there are some problems too. Just today I found the errata for CSS2.1, not many and I knew the @charset problem before. Still it seems the myriad of different specs in different stages (CSS 2.1, Errata, Selector, spec, DOM Level 2 CSS and stylesheets, CSSOM) plus the real world (browser) implementations and things I personally think should be in the lib (keeping CSS hacks or get access to multiple same named property values) made (and make) it really difficult to decide which to use and where to look. As I do not have too much time for this project (luckily I had a few days off so could do quite a lot actually) this makes it even more difficult.

Anyway, 0.9.4a1 is out and as the test cases grow (and validate) the release is hopefully not too bad. I guess if browsers take a few years to (almost) comply to the specs a lib like cssutils is not doing too bad. Ok I know, browsers need to display something too which cssutils does not even attempt but still there is hardly even a decent CSS editor out there (Aptana is probably the best I know of).

October 14, 2007

Deprecation decorator

Filed under: CSS,cssutils,Python — see @ 12:55 pm

I was looking for a simple way to “deprecate” methods (in cssutils). For now I use warnings directly but thought a decorator would be easier and clearer (I never really used decorators yet). A bit of googling gave two different options, a simple decorator function which is part of the DecoratorLibrary which is sufficient for most tasks I guess. But I was looking for a deprecation decorator which can handle an individual message which contains information about how to avoid the deprecated method. I found this parameterized decorator example and customized it for my needs:

class Deprecated(object):
    """This is a decorator which can be used to mark functions
    as deprecated. It will result in a warning being emitted
    when the function is used.

    It accepts a single paramter ``msg`` which is shown with the warning.
    It should contain information which function or method to use instead.
    def __init__(self, msg):
        self.msg = msg

    def __call__(self, func):
        def newFunc(*args, **kwargs):
            import warnings
            warnings.warn("Call to deprecated method %r. %s" %
                            (func.__name__, self.msg),
            return func(*args, **kwargs)
        newFunc.__name__ = func.__name__
        newFunc.__doc__ = func.__doc__
        return newFunc

So it is actually a mixture of both decorator options. A simple class using the decorator may be:

class Calc(object):
    """a simple test calculator

    >>> c = Calc()
    >>> c.add(1, 2)
    >>>, 2) # BTW, is it possible to catch warnings with doctest?

    def add(self, x, y):
        "adds x and y"
        return x+y

    @Deprecated('Use Calc.add() instead.')
    def plus(self, x, y):
        "adds x and y"
        return self.add(x,y)

When used gives the following output

c = Calc()
print,2) DeprecationWarning: Call to deprecated method
 'plus'. Use Calc.add() instead.

I think this is quite useful and I guess I’ll use this in cssutils. There certainly is something similar out there but it was quite interesting to look a bit into decorators at all.

UPDATE: Please see the comment by Matt (decorator module).

August 12, 2007

cssutils ongoings

Filed under: CSS,cssutils — see @ 4:08 pm

Walter Dörwald is currently helping a lot in improving cssutils. So it makes a lot of sense using the Google Codes SVN. Documentation is building up a bit, currently I am writing it in reStructuredText, I do not know yet how (and if) it will find its way in the GCs wiki.

Implementation of CSSValue and subclasses has begun. It will probable take quite a while for a next release (some weeks I guess) which will probably be a new 0.9.3 alpha release. 0.9.2 in in beta 3 now which is probably the last 0.9.2 release.

I always tried to avoided implementing CSSValue etc as it is quite a big area which takes a long time to implement and is somehow not easy to understand (at least for me ;) ). How the different interfaces should play together seems not very clear.

One specific point is why CSSStyleDeclaration.getPropertyCSSValue() for shorthand values should return “None” (null). It seems to make sense to simply return a CSSValueList. Maybe I do not understand this interface right, but it does seem overkill just to use it for values like “border-width: 1px 2px 3px 4px” which I guess it solely should be used for regarding the spec.

Also: If “border-width: 1px 2px” ist set which sets all 4 borders, should the CSSValueList have 2 or 4 values? I still have to decide on this.

Anyway, for now e.g. “background: #fff url(x.gif)” returns a CSSValueList with 2 items of CSSPrimitiveValue in it.

The whole thing gets a bit more complicated as I try to implement or at least “know” newer specs like CSS3 color (e.g. rgba() or hsl()) as well and maybe even include these even as they are not final yet.

I guess browser support for CSS took so long (and is still buggy or unreliable across different vendors and of course not nearly complete) as the specs are not the easiest. cssutils is a library to use stylesheets only, it does not even attempt to render them. Currently there is not even a way to say “I give you an element and you tell me its properties”… Hopefully this will come through time…

Anyway, great to have help and also actual use cases for the lib.

April 5, 2007

CSS naked day

Filed under: CSS — see @ 7:20 pm

better late than never… I stripped the main website of styles as it is CSS naked day today. I was a bit late (it is 20:16 in Germany now) but anyway, I guess I let it like that till late tomorrow.

I only stripped styles from cthedot not including this blog which uses more or less a basic WordPress theme hardly worth the effort. As cthedot is still more or less handweaved it is actually a bit of work to do it. I guess I really should rework the background of the site a bit. It’s quite small and so it is like that for some years now and I plan it from time to time to at least use SSI or simple PHP includes but never really came round to it. I guess I am just to busy with other stuff…

January 27, 2007

updated CSS white-space property tests

Filed under: CSS — see @ 6:01 pm

An embarrassing typo on the CSS white-space property test page (thanks Joel!) made me redo the whole page. I added tests for IE 5.01 and redid all tests on the browsers I currently have accesss to which are IE 5.01, 5.5, 6, 7, Opera 8.5 and Firefox I still don’t really get how white-space: pre-line actually should look like but the others are clear now and hopefully my findings are correct now.

If you have different results or results for other browsers (Safari anyone?) please let me know.

« Newer PostsOlder Posts »

Powered by WordPress