see whatever…

jump to menu

October 23, 2007

SVN $LastChangedDate$

Filed under: Life,Programming,Python — see @ 7:55 pm

In the cssutils sources I use the line __date__ = '$LastChangedDate$' in every file. I never figured this may be the source for any problem but it actually is.

Issue #10 in cssutils issue tracker is put up by an Argentine who had a problem with an accented “é” in the source. I never put it there. I do have some tests with non-ASCII characters in some of the testcases but specified an encoding in theses Python source files with the standard # -*- coding: utf-8 -*- as the 1st (or 2nd if a she-bang is present) line (actually in most cases # -*- coding: iso-8859-1 -*- as most tests use german umlauts which are the easiest to type on my german keyboard ;) ). But not in the where the problem occured and which is just plain ASCII.

But if you check out the files from the SVN the $LastChangedDate$ is replaced according to the locale you work in (or specify explicitly). This in my case is german so the result is something like __date__ = '$LastChangedDate: 2007-10-23 19:30:59 +0200 (Di, 23 Okt 2007) $'. Notice the “Di” which is short for “Dienstag” (Tuesday). It seems that in Argentine (which is basically spanish [shame on my not even knowing this stuff properly :( ]) some days actually have accented characters in them so the resulting string actually contains non-ASCII characters which then result in an invalid Python file – if no source encoding is specified (which I guess should be UTF-8 as e.g. ISO-8859-1 may work but I am not sure).

Very interesting…

For now I just added the encoding to only but I fear need to do this for any file :(

I guess a workaround would be to specify another encoding when checking out from Subversion. I also guess this problem will happen quite often as IMHO most English speaking people do mostly still use ASCII source code only. Even in widely used languages like Java I think this will be a problem.

October 22, 2007


Filed under: Music — see @ 9:17 pm

via Sean McGrath

October 21, 2007

Why we curse…

Filed under: Life — see @ 1:46 pm

very long but also very interesting and amusing: Why we curse.

Via Ned Batchelder

(BTW, hardly any point to do another post but just for me to “refind” it…)

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).

October 13, 2007

ads that look like content and even worse…

Filed under: Death — see @ 11:47 pm

Ads that look like actual content but are not are known for quite some time now, the first I personally noticed were ads in FACE (print) magazine (R.I.P.) some years ago which looked like normal articles but actually were ads only noticeable by some small print “Adverticement” hidden in a corner.

Website ads use the same technique of masking ads as content but I never seen one as bold as on (may not be the only site using this kind of “marketing”):


It actually looks like the yellow Internet Explorer warning bar at the top of the window which normally is used by the browser (and not the websites content) to show infos about a missing plugin or problem with a site (I think the Firefox bar coming up if e.g. you try to install a plugin from an unknown site looks similar). To do something like this in print one would have to put in a fake TOC or use the actual page numbering for ads I guess…

IMHO this kind of ad is more like phishing than ad (maybe one can consider any ad a kind of “phishing”). Anyway it does make the website absolutely non-trustworthy. In this case not very important as it is a forum about hifi stuff (probably visited mostly by freaks like me ;) ) but I also guess this will inspire other sites to do something like this…

BTW, is there a word like “inspire” which the here intended negative notion?

October 9, 2007

bringing Windows down, esp Vista…

Filed under: Uncategorized — see @ 6:24 pm

There is quite an easy way to bring almost any Windows down (I somehow remember also Ubuntu had this problem). Just insert a CD or DVD in the drive and somehow try to mess with the automatic things that now try to figure out what to do. I burned a backup DVD today (BTW with the very good – but very slow too – and free CDBurnerXP) and when done I wanted to look at the contents to check it. CDBurnerXP (like Nero etc) ejects a DVD when finished and I just put it in again and started the Windows Explorer. This messed up Vista so much that both CDBurnerXP and the WE both crushed down and also the complete OS went downhill. Vista seemed to work and I could open the task manager and try to kill both processes but that did not do what it should. Also logging off did not help. It took about 10 minutes to get to the Vista welcome screen with the message “logging off” but during that it just hang and I had no further patience (after about 30 minutes all in all during which I did something completely different in my room of course) and just pressed the power button. Not very nice but I guess no normal user would even wait this long neither longer and I doubt Vista would have gotten out of it then…

Is it so difficult to write a CD/DVD driver that it does not bring a complete OS down to its knees??

BTW, other than that I am quite pleased with Vista which I installed during the weekend (after upgrading my CPU as well :) ). Installation of Vista itself took about 1 hour after which I installed all needed drivers which took another few hours but I had no real problems during this. I recall installing XP some years ago (yes, only 1 install in about 4 years, so I guess XP is quite stable although I tried out lots of tools and other software) was a major hassle as some drivers (mainboard or graphics or IDE? I do not really remember) had to be installed in a specific order. If not the whole install was messed up so I had had to start all over again. Vista did not break down at all although this was my first install and it does seem to have spread some tools all over the place (at least not where they are in earlier versions of Windows) so it took me longer to get aquainted than expected. Differences from 95 to 98 to NT to 2k to XP were not half as high as between XP and Vista…

So OS and Hardware did install quite well and also most software does work as expected. I noticed that I hardly use any buyware anymore although I have bought quite a few licenses in the last years. Things like ACDsee which I used in version 3 for years now (old but fast) is not really needed anymore as the explorer does all the things I want anyhow. I now use CDBurnerXP although I have Nero which came with my DVD-Burner.
I was almost surprised that Photoshop 6 works (which BTW I got with my digital camera about 6 years ago. I know, the camera (which was expensive at its time) sucks today, but I still like Photoshop, even this old version. And today I guess there is no room for an expensive software bundle with cheap cameras). But I also installed Paint.NET which is quite nice.

Another thing that is more convenient these days is that quite a lot of software does not need to be installed at all anymore. I use Scite (a simple exe), Eclipse (I think there is not even an installer), but also stuff like Thunderbird comes as a standalone exe now. Normally made for USB-sticks but they are very convenient on a normal HDD too.

Powered by WordPress