summaryrefslogtreecommitdiff
path: root/numpy/distutils/cpuinfo.py
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2013-03-28 17:13:53 -0600
committerCharles Harris <charlesr.harris@gmail.com>2013-04-02 11:23:58 -0600
commit09a52ed47bb26498c97a579ce1147861df696d84 (patch)
tree39bbddec620188f8cf09a5eb51370b0db1236219 /numpy/distutils/cpuinfo.py
parenta939f2aa83e7d37d5e35e7c2a8c539c59f682598 (diff)
downloadnumpy-09a52ed47bb26498c97a579ce1147861df696d84.tar.gz
2to3: Apply `imports` fixer.
The `imports` fixer deals with the standard packages that have been renamed, removed, or methods that have moved. cPickle -- removed, use pickle commands -- removed, getoutput, getstatusoutput moved to subprocess urlparse -- removed, urlparse moved to urllib.parse cStringIO -- removed, use StringIO or io.StringIO copy_reg -- renamed copyreg _winreg -- renamed winreg ConfigParser -- renamed configparser __builtin__ -- renamed builtins In the case of `cPickle`, it is imported as `pickle` when python < 3 and performance may be a consideration, but otherwise plain old `pickle` is used. Dealing with `StringIO` is a bit tricky. There is an `io.StringIO` function in the `io` module, available since Python 2.6, but it expects unicode whereas `StringIO.StringIO` expects ascii. The Python 3 equivalent is then `io.BytesIO`. What I have done here is used BytesIO for anything that is emulating a file for testing purposes. That is more explicit than using a redefined StringIO as was done before we dropped support for Python 2.4 and 2.5. Closes #3180.
Diffstat (limited to 'numpy/distutils/cpuinfo.py')
-rw-r--r--numpy/distutils/cpuinfo.py26
1 files changed, 16 insertions, 10 deletions
diff --git a/numpy/distutils/cpuinfo.py b/numpy/distutils/cpuinfo.py
index 1e2d9379c..aaf642691 100644
--- a/numpy/distutils/cpuinfo.py
+++ b/numpy/distutils/cpuinfo.py
@@ -18,10 +18,12 @@ __all__ = ['cpu']
import sys, re, types
import os
-if sys.version_info[0] < 3:
- from commands import getstatusoutput
-else:
+
+if sys.version_info[0] >= 3:
from subprocess import getstatusoutput
+else:
+ from commands import getstatusoutput
+
import warnings
import platform
@@ -488,25 +490,29 @@ class Win32CPUInfo(CPUInfoBase):
info = []
try:
#XXX: Bad style to use so long `try:...except:...`. Fix it!
- import _winreg
+ if sys.version_info[0] >= 3:
+ import winreg
+ else:
+ import _winreg as winreg
+
prgx = re.compile(r"family\s+(?P<FML>\d+)\s+model\s+(?P<MDL>\d+)"\
"\s+stepping\s+(?P<STP>\d+)",re.IGNORECASE)
- chnd=_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, self.pkey)
+ chnd=winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, self.pkey)
pnum=0
while 1:
try:
- proc=_winreg.EnumKey(chnd,pnum)
- except _winreg.error:
+ proc=winreg.EnumKey(chnd,pnum)
+ except winreg.error:
break
else:
pnum+=1
info.append({"Processor":proc})
- phnd=_winreg.OpenKey(chnd,proc)
+ phnd=winreg.OpenKey(chnd,proc)
pidx=0
while True:
try:
- name,value,vtpe=_winreg.EnumValue(phnd,pidx)
- except _winreg.error:
+ name,value,vtpe=winreg.EnumValue(phnd,pidx)
+ except winreg.error:
break
else:
pidx=pidx+1