File tree Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Original file line number Diff line number Diff line change 8
8
import datetime
9
9
import odml .tools .xmlparser
10
10
from hashlib import md5
11
+ py3 = True
11
12
try :
12
13
import urllib .request as urllib2
13
14
except ImportError :
14
15
import urllib2
16
+ py3 = False
15
17
import threading
16
18
17
-
18
19
CACHE_AGE = datetime .timedelta (days = 1 )
19
20
20
21
@@ -36,12 +37,15 @@ def cache_load(url):
36
37
or datetime .datetime .fromtimestamp (os .path .getmtime (cache_file )) < \
37
38
datetime .datetime .now () - CACHE_AGE :
38
39
try :
39
- data = urllib2 .urlopen (url ).read ()
40
+ data = urllib2 .urlopen (url ).read (). decode ( "latin1" )
40
41
except Exception as e :
41
42
print ("failed loading '%s': %s" % (url , e ))
42
43
return
43
44
fp = open (cache_file , "w" )
44
- fp .write (str (data ))
45
+ if py3 :
46
+ fp .write (data )
47
+ else :
48
+ fp .write (data .encode ('latin1' ))
45
49
fp .close ()
46
50
return open (cache_file )
47
51
@@ -97,4 +101,8 @@ def deferred_load(self, url):
97
101
98
102
99
103
if __name__ == "__main__" :
100
- f = cache_load ('http://portal.g-node.org/odml/terminologies/v1.0/analysis/analysis.xml' )
104
+ print ("Terminologies!" )
105
+ t = Terminologies ()
106
+ t .load ('http://portal.g-node.org/odml/terminologies/v1.0/terminologies.xml' )
107
+ # t.load('http://portal.g-node.org/odml/terminologies/v1.0/analysis/power_spectrum.xml')
108
+
Original file line number Diff line number Diff line change 8
8
"""
9
9
#TODO make this module a parser class, allow arguments (e.g. skip_errors=1 to parse even broken documents)
10
10
import sys
11
-
12
11
from odml import format
13
12
from lxml import etree as ET
14
13
from lxml .builder import E
15
-
16
14
# this is needed for py2exe to include lxml completely
17
15
from lxml import _elementpath as _dummy
18
16
You can’t perform that action at this time.
0 commit comments