<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Filip Salomonsson | infix.se</title><link>http://infix.se/</link><description>My name is Filip Salomonsson. Yours is not.</description><language>en-us</language><lastBuildDate>Sun, 10 Jan 2010 20:17:09 +0200</lastBuildDate><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/infix" /><feedburner:info uri="infix" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>infix</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item><title>Vecka 1</title><link>http://feedproxy.google.com/~r/infix/~3/jy8Mgkatq0U/vecka-1</link><description>&lt;p&gt;Vecka 1 börjar ta slut. Förutom kundmöte, planering, och en del kodande för nöjes skull fick jag även lite tekniska problem. Ett avbrott på min vanliga internetanslutning tydliggjorde att det inte håller att stå utan alternativ i såna situationer.
&lt;/p&gt;
&lt;p&gt;&lt;a href="http://telenor.se/privat/mobilt-bredband/mobilt-bredband-kontant/index.html"&gt;Telenor Mobilt Bredband Kontant&lt;/a&gt; verkar så här långt som en bra backuplösning. 500 spänn för modem och sim-kort, och sedan kan man när som helst betala 90 kr för att ha uppkoppling i en vecka. Det verkar funka hur bra som helst, även under Linux, så det får bli veckans tips till egenföretagare.
&lt;/p&gt;
&lt;p&gt;Veckans bildminne blev ansiktsuttrycket på Telenor-säljaren när han just lovat 6 MBit nerströms och 1 Mbit upp, och jag pekade på kartongen han just gett mig där det stod 3 MBit ner och 0,3 upp. Säljare i telebranschen har ofta en avslappnad inställning till sanningen. Ett klart imageproblem.
&lt;/p&gt;
&lt;p&gt;Jag tröttnade också på att det är så förbålt meckigt att komma åt sina &amp;quot;favoriter&amp;quot; på Hemnet när man kommer in via ett bevakningsmail eller -RSS, och mockade upp &lt;a href="http://brizzly.com/pic/ZAU"&gt;ett exempel på hur de skulle kunna göras mer lättillgängliga&lt;/a&gt; direkt från andra bostadsbeskrivningar. Det ligger ett separat blogginlägg och gror där inne någonstans.
&lt;/p&gt;

&lt;h2&gt;Söndagslänkar&lt;/h2&gt;
&lt;ul&gt;
 &lt;li&gt;
     &lt;a href="http://www2.unt.se/avd/1,1826,MC=77-AV_ID=1000546,00.html"&gt;&amp;quot;Organiserat kaos&amp;quot; vid Ikeakurragömma&lt;/a&gt; - Hundratalet personer invaderar IKEA i Uppsala för att leka kurragömma; säkert obekvämt för vilket varuhus som helst, men &lt;a href="http://twitter.com/swefreddy"&gt;varuhuschefen&lt;/a&gt; får inte panik utan lånar ut en megafon och ber dem bara leka försiktigt. Snyggt hanterat. &lt;a href="http://twitter.com/ikeauppsala"&gt;Följ IKEA Uppsala på twitter&lt;/a&gt;.
 &lt;/li&gt;

 &lt;li&gt;
     &lt;a href="http://www.editorsweblog.org/newspaper/2010/01/financial_times_paywall_finally_pays_off.php"&gt;Financial Times' paywall finally pays off&lt;/a&gt; - Mycket intressant utveckling. FT har fördelen att deras journalistik är enormt värdefull. För &amp;quot;vanliga&amp;quot; dagstidningar är situationen en annan. Men det är kul att se positiva exempel!
 &lt;/li&gt;

 &lt;li&gt;
     &lt;a href="http://www.vinterwebb.se/2010/01/04/hundranorran-nu-startar-det/"&gt;Hundra:Norran&lt;/a&gt; - Tidningen Norra Västerbotten fyller hundra år, och passar på att officiellt byta till det namn det haft i folkmun sedan länge - &lt;a href="http://norran.se/"&gt;Norran&lt;/a&gt;. Snygg och okomplicerad nyprofilering.
 &lt;/li&gt;

 &lt;li&gt;
     &lt;a href="http://www.openjs.com/scripts/events/keyboard_shortcuts/"&gt;Handling Keyboard Shortcuts in JavaScript&lt;/a&gt; - Jag snubblade över det här Javascript-biblioteket för att hantera tangentbordskommandon. Otroligt elegant API. Nästa gång jag behöver sånt är det definitivt det här jag kommer att använda.
 &lt;/li&gt;

 &lt;li&gt;
     Ännu är det inte för sent att bli &lt;a href="http://blogg.svd.se/utvecklingsblogg?id=16453"&gt;frontend-utvecklare på svd.se&lt;/a&gt;. Sök senast den 15 januari.
 &lt;/li&gt;
&lt;/ul&gt;&lt;img src="http://feeds.feedburner.com/~r/infix/~4/jy8Mgkatq0U" height="1" width="1"/&gt;</description><author>filip.salomonsson@gmail.com</author><pubDate>Sun, 10 Jan 2010 20:17:09 +0200</pubDate><guid isPermaLink="false">http://infix.se/2010/01/10/vecka-1</guid><feedburner:origLink>http://infix.se/2010/01/10/vecka-1</feedburner:origLink></item><item><title>Vecka 0</title><link>http://feedproxy.google.com/~r/infix/~3/qNmKUHhvfOk/vecka-0</link><description>&lt;p&gt;2005 började jag undervisa i språkteknologi på Uppsala universitet. Sedan 2007 har jag jobbat i ett forskningsprojekt där. I torsdags tog min anställning slut.
&lt;/p&gt;
&lt;p&gt;Nu är jag egen företagare på heltid, och hjälper företag att vara så värdefulla som möjligt för sina kunder på webben. Jag behöver slipa på min elevator pitch, men tills vidare får vi nöja oss med det där. Det handlar om att göra webbtjänster mindre irriterande och mer hjälpsamma.
&lt;/p&gt;
&lt;p&gt;Det här är vecka 0, som jag avslutar med att &lt;a href="http://fibban.fleecelabs.se/2009/12/punktinsats-nr-2-skaffa-inkorgar.html"&gt;tömma inkorgen&lt;/a&gt; och planera för vecka 1.
&lt;/p&gt;

&lt;h2&gt;Söndagslänkar&lt;/h2&gt;
&lt;ul&gt;
 &lt;li&gt;
     &lt;a href="http://www.flickr.com/photos/laserbread/sets/72157612019716787/"&gt;Make Something Cool Every Day 2009&lt;/a&gt; - 
&lt;a href="http://www.flickr.com/people/laserbread/"&gt;Brock Davis&lt;/a&gt; gjorde något kreativt (och coolt!) varje dag under 2009 och la ut det på Flickr.
 &lt;/li&gt;

 &lt;li&gt;
     &lt;a href="http://twitter.com/KathySierra"&gt;Kathy Sierra&lt;/a&gt; kontrar för 2010 med &lt;a href="http://www.flickr.com/photos/36275436@N06/sets/72157623117369440/"&gt;Something Ridiculous Every Day&lt;/a&gt;. Kan vara värt att hålla ögonen på.
 &lt;/li&gt;

 &lt;li&gt;
     &lt;a href="http://www.usatoday.com/"&gt;USA Today&lt;/a&gt; bygger om, och de har &lt;a href="http://www.usatoday.com/news/early-look-homepage.htm"&gt;en 2-minuters video som visar upplägget i stora drag&lt;/a&gt;. Jag noterar särskilt att de uttryckligen nämner snabbhet som en feature.
 &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Tömma inkorgen, var det. &lt;a href="http://www.flickr.com/photos/infix/4204016355/"&gt;Hugaligen&lt;/a&gt;.
&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/infix/~4/qNmKUHhvfOk" height="1" width="1"/&gt;</description><author>filip.salomonsson@gmail.com</author><pubDate>Sun, 03 Jan 2010 21:18:59 +0200</pubDate><guid isPermaLink="false">http://infix.se/2010/01/03/vecka-0</guid><feedburner:origLink>http://infix.se/2010/01/03/vecka-0</feedburner:origLink></item><item><title>Profile this</title><link>http://feedproxy.google.com/~r/infix/~3/x5KaIlVru1E/profile-this</link><description>&lt;p&gt;Consider a very small python program, &lt;code&gt;test.py&lt;/code&gt;:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;label = &amp;quot;foo&amp;quot;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;And then consider profiling that program with the very nice &lt;a href="http://docs.python.org/library/profile.html"&gt;cProfile&lt;/a&gt; module:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ python -m cProfile test.py
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Finally, consider the consequences:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Traceback (most recent call last):
  File &amp;quot;.../lib/python2.5/runpy.py&amp;quot;, line 95, in run_module
    filename, loader, alter_sys)
  File &amp;quot;.../lib/python2.5/runpy.py&amp;quot;, line 52, in _run_module_code
    mod_name, mod_fname, mod_loader)
  File &amp;quot;.../lib/python2.5/runpy.py&amp;quot;, line 32, in _run_code
    exec code in run_globals
  File &amp;quot;.../lib/python2.5/cProfile.py&amp;quot;, line 190, in &amp;lt;module&amp;gt;
    main()
  File &amp;quot;.../lib/python2.5/cProfile.py&amp;quot;, line 183, in main
    run('execfile(%r)' % (sys.argv[0],), options.outfile, options.sort)
  File &amp;quot;.../lib/python2.5/cProfile.py&amp;quot;, line 36, in run
    result = prof.print_stats(sort)
  File &amp;quot;.../lib/python2.5/cProfile.py&amp;quot;, line 81, in print_stats
    pstats.Stats(self).strip_dirs().sort_stats(sort).print_stats()
  File &amp;quot;.../lib/python2.5/pstats.py&amp;quot;, line 92, in __init__
    self.init(arg)
  File &amp;quot;.../lib/python2.5/pstats.py&amp;quot;, line 106, in init
    self.load_stats(arg)
  File &amp;quot;.../lib/python2.5/pstats.py&amp;quot;, line 130, in load_stats
    arg.create_stats()
  File &amp;quot;.../lib/python2.5/cProfile.py&amp;quot;, line 92, in create_stats
    self.snapshot_stats()
  File &amp;quot;.../lib/python2.5/cProfile.py&amp;quot;, line 100, in snapshot_stats
    func = label(entry.code)
TypeError: 'str' object is not callable
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;(File paths shortened because mine are horribly long.)
&lt;/p&gt;
&lt;p&gt;Now consider stabbing your heart out with a fork. Though perhaps I should see if I can fix it instead, and submit a patch.
&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/infix/~4/x5KaIlVru1E" height="1" width="1"/&gt;</description><author>filip.salomonsson@gmail.com</author><pubDate>Thu, 03 Sep 2009 16:40:34 +0200</pubDate><guid isPermaLink="false">http://infix.se/2009/09/03/profile-this</guid><feedburner:origLink>http://infix.se/2009/09/03/profile-this</feedburner:origLink></item><item><title>An excercise in syntax abuse</title><link>http://feedproxy.google.com/~r/infix/~3/cQWsMwrn8BU/excercise-syntax-abuse</link><description>&lt;p&gt;Or, a random act of senselessness (which is a nice word).
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; class s(str):
...     def __sub__(self, other):
...         return &amp;quot;&amp;quot;.join(chr(c) for c in range(ord(self), ord(other)+1))
... 
&amp;gt;&amp;gt;&amp;gt; s(&amp;quot;a&amp;quot;) - s(&amp;quot;g&amp;quot;)
'abcdefg'
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Never do this sort of shit. Thank you.
&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/infix/~4/cQWsMwrn8BU" height="1" width="1"/&gt;</description><author>filip.salomonsson@gmail.com</author><pubDate>Thu, 18 Jun 2009 16:01:05 +0200</pubDate><guid isPermaLink="false">http://infix.se/2009/06/18/excercise-syntax-abuse</guid><feedburner:origLink>http://infix.se/2009/06/18/excercise-syntax-abuse</feedburner:origLink></item><item><title>Streamxmlwriter 0.2 released</title><link>http://feedproxy.google.com/~r/infix/~3/WGW5JkK5OY8/streamxmlwriter-02-released</link><description>&lt;p&gt;I just uploaded &lt;a href="http://pypi.python.org/pypi/streamxmlwriter/0.2"&gt;streamxmlwriter 0.2&lt;/a&gt; to PyPI. 
&lt;/p&gt;
&lt;p&gt;Streamxmlwriter is my library for flexible size-independent XML writing, including pretty-printing and custom attribute sorting. Try it out (both &lt;code&gt;easy_install streamxmlwriter&lt;/code&gt; and &lt;code&gt;pip install streamxmlwriter&lt;/code&gt; should work) or dig through &lt;a href="http://github.com/infixfilip/streamxmlwriter/tree/master"&gt;the source code on GitHub&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;Namespace support is still experimental, and the documentation is a bit on the thin side, but you should be able to use it for Real Work. (I do.)
&lt;/p&gt;
&lt;p&gt;I'll show it off in a post of its own when it's a bit more mature.
&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/infix/~4/WGW5JkK5OY8" height="1" width="1"/&gt;</description><author>filip.salomonsson@gmail.com</author><pubDate>Sun, 10 May 2009 22:56:40 +0200</pubDate><guid isPermaLink="false">http://infix.se/2009/05/10/streamxmlwriter-02-released</guid><feedburner:origLink>http://infix.se/2009/05/10/streamxmlwriter-02-released</feedburner:origLink></item><item><title>Text-safe XML processing with iterparse</title><link>http://feedproxy.google.com/~r/infix/~3/LwYWqssmVB8/text-safe-xml-processing-with-iterparse</link><description>&lt;p&gt;The ElementTree API makes XML processing in Python a breeze, and the
   iterparse function alone can probably handle 80% of your XML
   processing needs. I love it.
&lt;/p&gt;
&lt;p&gt;But did you know you can lose data with it if you're not careful?
&lt;/p&gt;
&lt;p&gt;Don't worry - it's not a bug, but there are edge cases you should be
   aware of.
&lt;/p&gt;

&lt;h2&gt;The problem&lt;/h2&gt;
&lt;p&gt;&lt;a href="http://docs.python.org/library/xml.etree.elementtree.html"&gt;The documentation is clear&lt;/a&gt;:
&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;iterparse() only guarantees that it has seen the &amp;quot;&amp;gt;&amp;quot; character of a
   starting tag when it emits a &amp;quot;start&amp;quot; event, so the attributes are
   defined, but the contents of the text and tail attributes are
   undefined at that point. The same applies to the element children;
   they may or may not be present.
&lt;/p&gt;
&lt;p&gt;If you need a fully populated element, look for &amp;quot;end&amp;quot; events instead.
&lt;/p&gt;
&lt;/blockquote&gt;&lt;p&gt;As a rule, you should only use &lt;code&gt;start&lt;/code&gt; events to inspect and/or modify
   the element's tag and its attributes.
&lt;/p&gt;
&lt;p&gt;You probably knew that already.
&lt;/p&gt;
&lt;p&gt;If you follow the link from &lt;a href="http://effbot.org/zone/element-iterparse.htm"&gt;Fredrik Lundh's iterparse
page&lt;/a&gt; to a python-sig message from 2005, you'll see
   something that may not be as well known: the availability of the
   &lt;code&gt;tail&lt;/code&gt; attribute during &lt;code&gt;end&lt;/code&gt; events isn't guaranteed either.
&lt;/p&gt;
&lt;p&gt;You may not have known that.
&lt;/p&gt;
&lt;p&gt;The suggested remedy for the &lt;code&gt;text&lt;/code&gt; attribute is simple: only touch it
   on &lt;code&gt;end&lt;/code&gt; events. In most cases, you never even look at &lt;code&gt;start&lt;/code&gt; events
   anyway, so that's a fine solution.
&lt;/p&gt;
&lt;p&gt;But what about &lt;code&gt;tail&lt;/code&gt;? It's very rare that I ever use xml documents
   that has tail data, but when I do, this is an important issue. To be
   sure not to lose data, you'll have do &lt;em&gt;something&lt;/em&gt; about it.
&lt;/p&gt;
&lt;p&gt;Luckily, there's a simple solution, but first, let's look at why this
   happens.
&lt;/p&gt;

&lt;h2&gt;The cause&lt;/h2&gt;
&lt;p&gt;It all has to do with how the parsing works.
&lt;/p&gt;
&lt;p&gt;&lt;code&gt;iterparse&lt;/code&gt; feeds data to the parser in 16-kilobyte chunks, and it
   fires off all events it can for each chunk. Then the events are handed
   over to you, one by one.
&lt;/p&gt;
&lt;p&gt;Say there's a &lt;code&gt;foo&lt;/code&gt; element whose contents is the text &amp;quot;hello&amp;quot;.
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;...&amp;lt;foo&amp;gt;hello&amp;lt;/foo&amp;gt;...
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;As long as all of the text is in the same chunk as the preceeding &amp;quot;&amp;gt;&amp;quot;, the &lt;code&gt;text&lt;/code&gt; attribute
   will be set during the &lt;code&gt;start&lt;/code&gt; event. We can try it out:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; import xml.etree.cElementTree as etree
&amp;gt;&amp;gt;&amp;gt; from cStringIO import StringIO
&amp;gt;&amp;gt;&amp;gt; doc = StringIO(&amp;quot;&amp;lt;doc&amp;gt;&amp;lt;foo&amp;gt;hello&amp;lt;/foo&amp;gt;&amp;lt;/doc&amp;gt;&amp;quot;)
&amp;gt;&amp;gt;&amp;gt; for event, elem in etree.iterparse(doc, (&amp;quot;start&amp;quot;, &amp;quot;end&amp;quot;)):
...     print event, elem.tag, elem.text or &amp;quot;&amp;quot;
... 
start doc
start foo hello
end foo hello
end doc
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;On the other hand, if a chunk ends in the middle of that text (or
   immediately after the start tag, before the text), &lt;code&gt;iterparse&lt;/code&gt; will
   hand you a &lt;code&gt;start&lt;/code&gt; event for the &lt;code&gt;foo&lt;/code&gt; element without the text
   attribute set, and the parser comes back and sets it when it's
   processing the next chunk and reaches the end of the element.
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;          |
...&amp;lt;foo&amp;gt;he|llo&amp;lt;/foo&amp;gt;...
          |
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Let's trigger this by adding a long comment before the &lt;code&gt;foo&lt;/code&gt; element.
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; padding = &amp;quot;x&amp;quot; * 16365
&amp;gt;&amp;gt;&amp;gt; doc2 = StringIO(&amp;quot;&amp;lt;doc&amp;gt;&amp;lt;!--%s--&amp;gt;&amp;lt;foo&amp;gt;hello&amp;lt;/foo&amp;gt;&amp;lt;/doc&amp;gt;&amp;quot; % padding)
&amp;gt;&amp;gt;&amp;gt; for event, elem in etree.iterparse(doc2, (&amp;quot;start&amp;quot;, &amp;quot;end&amp;quot;)):
...     print event, elem.tag, elem.text or &amp;quot;&amp;quot;
... 
start doc
start foo
end foo hello
end doc
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now the chunk ends after &amp;quot;he&amp;quot;, and this time the &lt;code&gt;foo&lt;/code&gt; element's
   &lt;code&gt;text&lt;/code&gt; attribute isn't set during the &lt;code&gt;start&lt;/code&gt; event.
&lt;/p&gt;
&lt;p&gt;The issue with &lt;code&gt;tail&lt;/code&gt; is exactly the same. We can trigger this by
   using a long comment again. This time, we'll use an empty &lt;code&gt;foo&lt;/code&gt;
   element. The first chunk now ends after the &amp;quot;h&amp;quot; in &amp;quot;hello&amp;quot;.
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; doc3 = StringIO(&amp;quot;&amp;lt;doc&amp;gt;&amp;lt;!--%s--&amp;gt;&amp;lt;foo/&amp;gt;hello&amp;lt;/doc&amp;gt;&amp;quot; % padding)
&amp;gt;&amp;gt;&amp;gt; for event, elem in etree.iterparse(doc3, (&amp;quot;start&amp;quot;, &amp;quot;end&amp;quot;)):
...     print event, elem.tag, elem.tail or &amp;quot;&amp;quot;
... 
start doc 
start foo 
end foo 
end doc
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;No tail text to be seen.
&lt;/p&gt;

&lt;h2&gt;The solution&lt;/h2&gt;
&lt;p&gt;Both &lt;code&gt;text&lt;/code&gt; and &lt;code&gt;tail&lt;/code&gt; data ends when another start or end tag occurs.
   Both of these trigger new events, so we can use a wrapper that stays
   one step ahead, making sure the next event has always been triggered
   before it let's us see the current one.
&lt;/p&gt;
&lt;p&gt;Here's our &amp;quot;delayed iterator&amp;quot;:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;def delayediter(iterable):
    iterable = iter(iterable)
    prev = iterable.next()
    for item in iterable:
        yield prev
        prev = item
    yield prev
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Let's try it out on the last two examples above.
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; doc2.seek(0) # &amp;quot;rewind&amp;quot; the stringio object
&amp;gt;&amp;gt;&amp;gt; context = etree.iterparse(doc2, (&amp;quot;start&amp;quot;, &amp;quot;end&amp;quot;))
&amp;gt;&amp;gt;&amp;gt; for event, elem in delayediter(context):
...     print event, elem.tag, elem.text or &amp;quot;&amp;quot;
... 
start doc 
start foo hello
end foo hello
end doc 
&amp;gt;&amp;gt;&amp;gt; doc3.seek(0)
&amp;gt;&amp;gt;&amp;gt; context = etree.iterparse(doc3, (&amp;quot;start&amp;quot;, &amp;quot;end&amp;quot;))
&amp;gt;&amp;gt;&amp;gt; for event, elem in delayediter(context):
...     print event, elem.tag, elem.tail or &amp;quot;&amp;quot;
... 
start doc 
start foo 
end foo hello
end doc
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Success! This works both for Fredrik Lundh's ElementTree (which is in
   the standard library since python 2.5) and for Stefan Behnel's
   excellent &lt;a href="http://codespeak.net/lxml/"&gt;lxml&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;So, from no on, all your iterparsing should be text-safe. (With
   &lt;code&gt;lxml&lt;/code&gt;, there are still special cases where this may not quite
   suffice, but we'll come back to that another time.) Happy coding!
&lt;/p&gt;
&lt;p&gt;Agree? Disagree? Found a bug? Talk back at
   &lt;a href="mailto:filip.salomonsson@gmail.com"&gt;filip.salomonsson@gmail.com&lt;/a&gt;.
&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/infix/~4/LwYWqssmVB8" height="1" width="1"/&gt;</description><author>filip.salomonsson@gmail.com</author><pubDate>Sun, 10 May 2009 22:09:55 +0200</pubDate><guid isPermaLink="false">http://infix.se/2009/05/10/text-safe-xml-processing-with-iterparse</guid><feedburner:origLink>http://infix.se/2009/05/10/text-safe-xml-processing-with-iterparse</feedburner:origLink></item><item><title>Hoho!</title><link>http://feedproxy.google.com/~r/infix/~3/DZuDImHtxWY/hoho</link><description>&lt;p&gt;Vad tyst det är här.
&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/infix/~4/DZuDImHtxWY" height="1" width="1"/&gt;</description><author>filip.salomonsson@gmail.com</author><pubDate>Fri, 03 Oct 2008 19:23:47 +0200</pubDate><guid isPermaLink="false">http://infix.se/2008/10/03/hoho</guid><feedburner:origLink>http://infix.se/2008/10/03/hoho</feedburner:origLink></item><item><title>From business to buttons</title><link>http://feedproxy.google.com/~r/infix/~3/B0E9tuz0SxQ/businesstobuttons</link><description>&lt;p&gt;Per Axbom har bloggat dagrapporter från konferensen &lt;a href="http://www.businesstobuttons.tv"&gt;From Business to Buttons&lt;/a&gt; i Malmö:
&lt;/p&gt;
&lt;ul&gt;
 &lt;li&gt;
     &lt;a href="http://www.axbom.se/business-to-buttons-dag1-2008"&gt;Business to Buttons, dag 1, 2008&lt;/a&gt;
 &lt;/li&gt;

 &lt;li&gt;
     &lt;a href="http://www.axbom.se/business-to-buttons-dag2-2008"&gt;Business to Buttons, dag 2, 2008&lt;/a&gt;
 &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Såväl Axbom som Johan Berndtsson från &lt;a href="http://www.inuse.se/"&gt;inUse&lt;/a&gt; (och  några till) har också fyllt på i &lt;a href="http://jaiku.com/channel/FBTB"&gt;FBTBs Jaiku-kanal&lt;/a&gt; under konferensen.
&lt;/p&gt;
&lt;p&gt;(Passa för all del också på att kolla in &lt;a href="http://www.inuse.se/"&gt;inUse nya webbplats&lt;/a&gt;, som de skeppade lagom i tid till konferensen. Aj på URLerna, men stiligt.)
&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/infix/~4/B0E9tuz0SxQ" height="1" width="1"/&gt;</description><author>filip.salomonsson@gmail.com</author><pubDate>Sat, 14 Jun 2008 17:37:55 +0200</pubDate><guid isPermaLink="false">http://infix.se/2008/06/14/businesstobuttons</guid><feedburner:origLink>http://infix.se/2008/06/14/businesstobuttons</feedburner:origLink></item><item><title>Visible whitespace in the shell</title><link>http://feedproxy.google.com/~r/infix/~3/1_Vupje3QAo/visible-whitespace-shell</link><description>&lt;p&gt;Bash alias of the day. Stuff this into your &lt;code&gt;~/.bashrc&lt;/code&gt;:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;alias visws=&amp;quot;sed -e 's/ /\o033[37m\xc2\xb7\o033[0m/g' \
                 -e 's/\t/\o033[37m \xe2\x86\x92  \o033[0m/g' \
                 -e 's/\r/\o033[37m\xe2\x86\xb5\o033[0m/g'&amp;quot;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then pipe anything to &lt;code&gt;visws&lt;/code&gt;, and you'll get spaces, tabs and carriage returns shown in grey as sweet unicode characters (which my django-driven blog cannot show you, embarrasingly). Dots and arrows, basically.
&lt;/p&gt;
&lt;p&gt;(This will only work if your terminal encoding is utf-8. But it is, right?)
&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;: To be clear, the &amp;quot;cannot show you&amp;quot; part is &lt;em&gt;my&lt;/em&gt; fault, not django's.
&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Bonus&lt;/strong&gt;: Here it is in action.
&lt;/p&gt;
&lt;div class="huge figure"&gt;&lt;a href="http://www.flickr.com/photos/infix/2527647296/" title="visws by lillalammet, on Flickr"&gt;&lt;img src="http://farm4.static.flickr.com/3256/2527647296_118aa10b4c_o.png" width="632" height="126" alt="Screenshot of visws" /&gt;&lt;/a&gt;&lt;img src="http://feeds.feedburner.com/~r/infix/~4/1_Vupje3QAo" height="1" width="1"/&gt;</description><author>filip.salomonsson@gmail.com</author><pubDate>Fri, 23 May 2008 14:45:06 +0200</pubDate><guid isPermaLink="false">http://infix.se/2008/05/23/visible-whitespace-shell</guid><feedburner:origLink>http://infix.se/2008/05/23/visible-whitespace-shell</feedburner:origLink></item><item><title>Saknad</title><link>http://feedproxy.google.com/~r/infix/~3/hmn69Z52ftQ/saknad</link><description>&lt;p&gt;Har du saknat mig?
&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/infix/~4/hmn69Z52ftQ" height="1" width="1"/&gt;</description><author>filip.salomonsson@gmail.com</author><pubDate>Sat, 03 May 2008 00:24:06 +0200</pubDate><guid isPermaLink="false">http://infix.se/2008/05/03/saknad</guid><feedburner:origLink>http://infix.se/2008/05/03/saknad</feedburner:origLink></item><item><title>Kairo vadå?</title><link>http://feedproxy.google.com/~r/infix/~3/R7NGVtesdl0/kairo-vada</link><description>&lt;p&gt;Är det bara jag, eller har diverse undersökningar från &lt;a href="http://www.kairosfuture.com/sv"&gt;Kairos Future&lt;/a&gt; ganska plötsligt börjat dyka upp precis över-jävla-allt?
&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/infix/~4/R7NGVtesdl0" height="1" width="1"/&gt;</description><author>filip.salomonsson@gmail.com</author><pubDate>Thu, 14 Feb 2008 17:26:04 +0200</pubDate><guid isPermaLink="false">http://infix.se/2008/02/14/kairo-vada</guid><feedburner:origLink>http://infix.se/2008/02/14/kairo-vada</feedburner:origLink></item><item><title>Alternativ stavning</title><link>http://feedproxy.google.com/~r/infix/~3/rtFDW5LygcI/alternativ-stavning</link><description>&lt;p&gt;Den här informationen får jag om jag utan eftertanke rycker ut sladden ur telefonen (som fungerar som USB-disk):
&lt;/p&gt;
&lt;div class="medium figure"&gt;&lt;img src="/static/0802-eject.png" alt="" /&gt;&lt;/div&gt;

&lt;p&gt;Och så här ser menyn ut som jag får när jag högerklickar på telefonens ikon på skrivbordet:
&lt;/p&gt;
&lt;div class="medium figure"&gt;&lt;img src="/static/0802-unmount.png" alt="" /&gt;&lt;/div&gt;

&lt;p&gt;Ibland är hjälpen inte så hjälpsam.
&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/infix/~4/rtFDW5LygcI" height="1" width="1"/&gt;</description><author>filip.salomonsson@gmail.com</author><pubDate>Tue, 12 Feb 2008 23:31:22 +0200</pubDate><guid isPermaLink="false">http://infix.se/2008/02/12/alternativ-stavning</guid><feedburner:origLink>http://infix.se/2008/02/12/alternativ-stavning</feedburner:origLink></item><item><title>Hemnet: scener ur ett äktenskap</title><link>http://feedproxy.google.com/~r/infix/~3/flZoLz9QtMg/hemnet-scener-ur-ett-aktenskap</link><description>&lt;p&gt;&lt;a href="http://www.hemnet.se/"&gt;Hemnet&lt;/a&gt; är ett samarbete mellan Sveriges
   mäklare och två stora tidningar. Så här &lt;a href="http://www.hemnet.se/support/om"&gt;skriver de själva&lt;/a&gt;:
&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;Varje månad besöker omkring en miljon människor Hemnet för att leta
   ny bostad, följa prisutveckling och utbud. På Hemnet visas cirka
   800 000 bostadsbeskrivningar per dygn.
&lt;/p&gt;
&lt;/blockquote&gt;&lt;p&gt;Känn på det en stund. &lt;strong&gt;En miljon människor som
någorlunda aktivt söker efter något att köpa, oftast för
miljonbelopp.&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;Med såna förutsättningar kunde man tro att man som bostadssökande
   skulle formligen överösas med kärlek när man tittar förbi, men &lt;strong&gt;när man
kommer till Hemnet är det något helt annat än kärlek man möts av&lt;/strong&gt;.
&lt;/p&gt;
&lt;p&gt;Som av en händelse spanar jag lite efter en lägenhet. En tvåa i
   Uppsala vore trevligt. Vi kollar.
&lt;/p&gt;
&lt;div class="medium figure"&gt;&lt;img src="/static/0802-hemnet-1.png" alt="" /&gt;&lt;/div&gt;

&lt;p&gt;Nämenhej, älskling. Okej, jag väljer Uppsala län och Uppsala kommun.
   Något område vill jag inte ange, så mina ögon dras direkt till knappen
   &amp;quot;Sök bostad&amp;quot;. Det är ju exakt vad jag vill göra! Jag klickar!
&lt;/p&gt;
&lt;div class="medium figure"&gt;&lt;img src="/static/0802-hemnet-2.png" alt="" /&gt;&lt;/div&gt;

&lt;p&gt;Jaha, kära du, det var två delar kvar? Okej. Jag har inte så specifika
   krav, så jag väljer bara ett maxpris i listan.
&lt;/p&gt;
&lt;div class="small figure"&gt;&lt;img src="/static/0802-hemnet-kryssruta.png" alt="" /&gt;&lt;/div&gt;

&lt;p&gt;Jag vet inte riktigt vad &amp;quot;Övrigt&amp;quot; kan vara för boendeform, men jag
   tror inte det är något för mig. En bostadsrätt är det jag söker. Men
   vad vill de att jag ska skriva i textfältet där intill? Jag klickar
   lite osäkert i den och märker att &lt;strong&gt;det är en
kryssruta, som de har lyckats få att inte se ut som en
kryssruta&lt;/strong&gt;, genom att ändra dess storlek. Tack. Nästa.
&lt;/p&gt;
&lt;div class="medium figure"&gt;&lt;img src="/static/0802-hemnet-3.png" alt="" /&gt;&lt;/div&gt;

&lt;p&gt;Visningsalternativ? Visningsdatum? Hej, hallå, vänta. &lt;strong&gt;Det här
förhållandet går för fort fram!&lt;/strong&gt; Jag är inte redo för någon visning!
&lt;/p&gt;
&lt;p&gt;Jag inser efter ett ögonblick att &amp;quot;visningsalternativ&amp;quot; trots allt inte
   syftar på lägenhetsvisning, utan på hur sökresultaten ska visas. Puh.
   Snacka om begreppsförvirring.
&lt;/p&gt;
&lt;p&gt;Nåväl, jag börjar vara lite trött på formulär och sugen på resultat,
   så jag struntar i resten, klickar på &amp;quot;Visa lista&amp;quot; och håller tummarna.
   Hårt.
&lt;/p&gt;
&lt;div class="huge figure"&gt;&lt;img src="/static/0802-hemnet-lista.png" alt="" /&gt;&lt;/div&gt;

&lt;p&gt;Yes! Till slut får jag min efterlängtade lista. Visserligen i form av
   en hemsk tabell med många brister, men det kan vi ta en annan dag.
&lt;/p&gt;
&lt;p&gt;&lt;span class="highlight"&gt;&lt;strong&gt;Tyvärr, Hemnet. Det är inte jag; det är du.&lt;/strong&gt;&lt;/span&gt;
&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/infix/~4/flZoLz9QtMg" height="1" width="1"/&gt;</description><author>filip.salomonsson@gmail.com</author><pubDate>Sun, 03 Feb 2008 21:35:49 +0200</pubDate><guid isPermaLink="false">http://infix.se/2008/02/03/hemnet-scener-ur-ett-aktenskap</guid><feedburner:origLink>http://infix.se/2008/02/03/hemnet-scener-ur-ett-aktenskap</feedburner:origLink></item><item><title>Feed cleanup: links dropped</title><link>http://feedproxy.google.com/~r/infix/~3/__MnJ6mHvUU/feed-cleanup-links-dropped</link><description>&lt;p&gt;To those who care: my main RSS feed will no longer include my del.icio.us link posts. If you feel you'll miss them, feel free to subscribe to &lt;a href="http://del.icio.us/rss/infix"&gt;my del.icio.us feed&lt;/a&gt;.
&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/infix/~4/__MnJ6mHvUU" height="1" width="1"/&gt;</description><author>filip.salomonsson@gmail.com</author><pubDate>Fri, 01 Feb 2008 17:26:48 +0200</pubDate><guid isPermaLink="false">http://infix.se/2008/02/01/feed-cleanup-links-dropped</guid><feedburner:origLink>http://infix.se/2008/02/01/feed-cleanup-links-dropped</feedburner:origLink></item><item><title>Improv Everywhere: Frozen Grand Central</title><link>http://feedproxy.google.com/~r/infix/~3/EVc-OHyh7dc/frozen-grand-central</link><description>&lt;p&gt;Improv Everywhere always make me smile. In &lt;a href="http://www.improveverywhere.com/2008/01/31/frozen-grand-central/"&gt;their latest scene&lt;/a&gt;, 207 people froze in time on cue in New York's Grand Central Station. They stood frozen for five minutes, and then went on as normal.
&lt;/p&gt;
&lt;p&gt;&lt;object width="448" height="366" data="http://flash.revver.com/player/1.0/player.swf?mediaId=648644" type="application/x-shockwave-flash" id="revvervideoa17743d6aebf486ece24053f35e1aa23"&gt;&lt;param name="Movie" value="http://flash.revver.com/player/1.0/player.swf?mediaId=648644"&gt;&lt;/param&gt;&lt;param name="FlashVars" value="allowFullScreen=true"&gt;&lt;/param&gt;&lt;param name="AllowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="AllowScriptAccess" value="always"&gt;&lt;/param&gt;&lt;embed type="application/x-shockwave-flash" src="http://flash.revver.com/player/1.0/player.swf?mediaId=648644" pluginspage="http://www.macromedia.com/go/getflashplayer" allowScriptAccess="always" flashvars="allowFullScreen=true" allowfullscreen="true" height="366" width="448"&gt;&lt;/embed&gt;&lt;/object&gt;
&lt;/p&gt;
&lt;p&gt;There is no way to not love this.
&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/infix/~4/EVc-OHyh7dc" height="1" width="1"/&gt;</description><author>filip.salomonsson@gmail.com</author><pubDate>Fri, 01 Feb 2008 17:03:36 +0200</pubDate><guid isPermaLink="false">http://infix.se/2008/02/01/frozen-grand-central</guid><feedburner:origLink>http://infix.se/2008/02/01/frozen-grand-central</feedburner:origLink></item></channel></rss>
