@@ -67,48 +67,46 @@ def __init__(self, addr):
67
67
self .function = - 1
68
68
self .index = - 1
69
69
70
- if isinstance (addr , six .string_types ):
71
-
72
- res = VALID_SBDFI .match (addr )
73
- if res :
74
- groups = res .groupdict ()
70
+ if not isinstance (addr , six .string_types ):
71
+ raise TypeError ("String expected" )
75
72
76
- if "segment" in groups and groups ["segment" ] is not None :
77
- self .segment = int (groups ["segment" ], 16 )
78
- else :
79
- self .segment = 0
73
+ res = VALID_SBDFI .match (addr )
74
+ if res :
75
+ groups = res .groupdict ()
80
76
81
- self . bus = int ( groups ["bus" ], 16 )
82
- if not ( 0 <= self .bus < 2 ** 8 ):
83
- raise ValueError ( "Bus '%d' out of range 0 <= bus < 256"
84
- % ( self .bus ,))
77
+ if "segment" in groups and groups ["segment" ] is not None :
78
+ self .segment = int ( groups [ "segment" ], 16 )
79
+ else :
80
+ self .segment = 0
85
81
86
- self .device = int (groups ["device " ], 16 )
87
- if not ( 0 <= self .device < 2 ** 5 ):
88
- raise ValueError ("Device '%d' out of range 0 <= device < 32 "
89
- % (self .device ,))
82
+ self .bus = int (groups ["bus " ], 16 )
83
+ if not ( 0 <= self .bus < 2 ** 8 ):
84
+ raise ValueError ("Bus '%d' out of range 0 <= bus < 256 "
85
+ % (self .bus ,))
90
86
91
- self .function = int (groups ["function " ], 16 )
92
- if not ( 0 <= self .function < 2 ** 3 ):
93
- raise ValueError ("Function '%d' out of range 0 <= device "
94
- "< 8" % (self .function ,))
87
+ self .device = int (groups ["device " ], 16 )
88
+ if not ( 0 <= self .device < 2 ** 5 ):
89
+ raise ValueError ("Device '%d' out of range 0 <= device < 32 "
90
+ % (self .device ,))
95
91
96
- if "index" in groups and groups [ "index" ] is not None :
97
- self .index = int ( groups [ "index" ])
98
- else :
99
- self . index = 0
92
+ self . function = int ( groups [ "function" ], 16 )
93
+ if not ( 0 <= self .function < 2 ** 3 ):
94
+ raise ValueError ( "Function '%d' out of range 0 <= device "
95
+ "< 8" % ( self . function ,))
100
96
101
- self .integer = (int (self .segment << 16 |
102
- self .bus << 8 |
103
- self .device << 3 |
104
- self .function ) << 8 |
105
- self .index )
106
- return
97
+ if "index" in groups and groups ["index" ] is not None :
98
+ self .index = int (groups ["index" ])
99
+ else :
100
+ self .index = 0
107
101
108
- raise ValueError ("Unrecognised PCI address '%s'" % addr )
102
+ self .integer = (int (self .segment << 16 |
103
+ self .bus << 8 |
104
+ self .device << 3 |
105
+ self .function ) << 8 |
106
+ self .index )
107
+ return
109
108
110
- else :
111
- raise TypeError ("String expected" )
109
+ raise ValueError ("Unrecognised PCI address '%s'" % addr )
112
110
113
111
114
112
def __str__ (self ):
0 commit comments