+ import urllib2
+
+ # Try and play nice with HTTP servers unless something goes wrong. We don't
+ # really care about this cache so it can be somewhere volatile
+ h = False
+ if 'httplib2' in sys.modules:
+ try: h = httplib2.Http('.httplib2-cache')
+ except OSError: h = httplib2.Http()
+
+ if not options.stdin and (not http or not 'httplib2' in sys.modules):
+ import urllib2
+
+ try:
+ content = u and (h and h.request(url)[1] or urllib2.urlopen(url).read())
+ except (ValueError, urllib2.URLError), e:
+ sys.stderr.write('%s\n'%e)
+ sys.exit(1)
+
+ if not u:
+ try: content = open(os.path.abspath(url),'r').read()
+ except (IOError, OSError), e:
+ sys.stderr.write('%s\n'%e)
+ sys.exit(1)
+
+ # RFC5545 and RFC5546 Calendars should be generated UTF-8 and we need to
+ # be able to read ANSI as well. This should take care of us.
+ content = unicode(content, encoding='utf-8')