Hi Stefan,<br><br>Thanks for the code review :) Only just noticed this.<br><br><div class="gmail_quote">On Wed, May 25, 2011 at 3:10 PM, Stefan Behnel <span dir="ltr">&lt;<a href="mailto:stefan_ml@behnel.de">stefan_ml@behnel.de</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Sithembewena Lloyd Dube, <a href="tel:25.05.2011%2014" value="+12505201114" target="_blank">25.05.2011 14</a>:40:<div class="im">
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Thanks for all your suggestions. I read up on gzip and urllib and also<br>
learned in the process that I could use urllib2 as its the latest form of<br>
that library.<br>
<br>
Herewith my solution: I don&#39;t know how elegant it is, but it works just<br>
fine.<br>
<br>
def get_contests():<br>
      url = &#39;<br>
<a href="http://xml.matchbook.com/xmlfeed/feed?sport-id=&amp;vendor=TEST&amp;sport-name=&amp;short-name=Po" target="_blank">http://xml.matchbook.com/xmlfeed/feed?sport-id=&amp;vendor=TEST&amp;sport-name=&amp;short-name=Po</a><br>

&#39;<br>
      req = urllib2.Request(url)<br>
      req.add_header(&#39;accept-encoding&#39;,&#39;gzip/deflate&#39;)<br>
      opener = urllib2.build_opener()<br>
      response = opener.open(req)<br>
</blockquote>
<br></div>
This is ok.<div class="im"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
      compressed_data = response.read()<br>
      compressed_stream = StringIO.StringIO(compressed_data)<br>
      gzipper = gzip.GzipFile(fileobj=compressed_stream)<br>
      data = gzipper.read()<br>
</blockquote>
<br></div>
This should be simplifiable to<br>
<br>
   uncompressed_stream = gzip.GzipFile(fileobj=response)<div class="im"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
      current_path = os.path.realpath(MEDIA_ROOT + &#39;/xml-files/d.xml&#39;)<br>
      data_file = open(current_path, &#39;w&#39;)<br>
      data_file.write(data)<br>
      data_file.close()<br>
      xml_data = ET.parse(open(current_path, &#39;r&#39;))<br>
</blockquote>
<br></div>
And this subsequently becomes<br>
<br>
   xml_data = ET.parse(uncompressed_stream)<div class="im"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
      contest_list = []<br>
      for contest_parent_node in xml_data.getiterator(&#39;contest&#39;):<br>
</blockquote>
<br></div>
Take a look at ET.iterparse().<div class="im"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
           contest = Contest()<br>
           for contest_child_node in contest_parent_node:<br>
                if (contest_child_node.tag == &quot;name&quot; and<br>
contest_child_node.text is not None and contest_child_node.text != &quot;&quot;):<br>
                     <a href="http://contest.name" target="_blank">contest.name</a> = contest_child_node.text<br>
                if (contest_child_node.tag == &quot;league&quot; and<br>
contest_child_node.text is not None and contest_child_node.text != &quot;&quot;):<br>
                    contest.league = contest_child_node.text<br>
                if (contest_child_node.tag == &quot;acro&quot; and<br>
contest_child_node.text is not None and contest_child_node.text != &quot;&quot;):<br>
                    contest.acro = contest_child_node.text<br>
                if (contest_child_node.tag == &quot;time&quot; and<br>
contest_child_node.text is not None and contest_child_node.text != &quot;&quot;):<br>
                    contest.time = contest_child_node.text<br>
                if (contest_child_node.tag == &quot;home&quot; and<br>
contest_child_node.text is not None and contest_child_node.text != &quot;&quot;):<br>
                    contest.home = contest_child_node.text<br>
                if (contest_child_node.tag == &quot;away&quot; and<br>
contest_child_node.text is not None and contest_child_node.text != &quot;&quot;):<br>
                    contest.away = contest_child_node.text<br>
</blockquote>
<br></div>
This is screaming for a simplification, such as<br>
<br>
   for child in contest_parent_node:<br>
       if child.tag in (&#39;name&#39;, &#39;league&#39;, ...): # etc.<br>
           if child.text:<br>
               setattr(context, child.tag, child.text)<div><div></div><div class="h5"><br>
<br>
<br>
Stefan<br>
<br>
_______________________________________________<br>
Tutor maillist  -  <a href="mailto:Tutor@python.org" target="_blank">Tutor@python.org</a><br>
To unsubscribe or change subscription options:<br>
<a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Regards,<br>Sithembewena Lloyd Dube<br>