Skip to content

Commit

Permalink
using 'with' statement with urllib2
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelmartins committed Aug 13, 2010
1 parent 8a470bd commit fee2700
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions marrie.py
Expand Up @@ -30,6 +30,7 @@
import sys
import urllib2
from ConfigParser import ConfigParser
from contextlib import closing
from xml.dom.minidom import parse as parseXML

config_file = '''\
Expand Down Expand Up @@ -126,9 +127,8 @@ def __init__(self, config, id):
def list_chapters(self):
url = self.podcast[self.id]
try:
fp = urllib2.urlopen(url)
rss = parseXML(fp)
fp.close()
with closing(urllib2.urlopen(url)) as fp:
rss = parseXML(fp)
except:
raise RuntimeError('Failed to parse the RSS feed: %s' % url)
enclosure = rss.getElementsByTagName('enclosure')
Expand Down

0 comments on commit fee2700

Please sign in to comment.