Skip to content

Commit 54069f4

Browse files
committed
Improve Python-3 compatibility
* Use `TFL.Meta.BaM`, not class variable `__metaclass__` * Syntax : + Print function, not statement + Raise syntax + Except syntax * Iterator changes * unicode vs. str * Use `portable_repr`
1 parent 4e34f2c commit 54069f4

19 files changed

+246
-221
lines changed

_CNDB/_GTW/RST_addons.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Glasauergasse 32, A--1130 Wien, Austria. [email protected]
44
# #*** <License> ************************************************************#
55
# This module is part of the package CNDB.GTW.
6-
#
6+
#
77
# This module is licensed under the terms of the BSD 3-Clause License
88
# <http://www.c-tanzer.at/license/bsd_3c.html>.
99
# #*** </License> ***********************************************************#
@@ -172,7 +172,7 @@ def bindings (self) :
172172

173173
@Once_Property
174174
def head (self) :
175-
return unicode (self)
175+
return pyk.text_type (self)
176176
# end def head
177177

178178
# end class Node_Manager_Error

_CNDB/_OMP/Attr_Type.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Glasauergasse 32, A--1130 Wien, Austria. [email protected]
44
# #*** <License> ************************************************************#
55
# This module is part of the package CNDB.OMP.
6-
#
6+
#
77
# This module is licensed under the terms of the BSD 3-Clause License
88
# <http://www.c-tanzer.at/license/bsd_3c.html>.
99
# #*** </License> ***********************************************************#
@@ -38,19 +38,22 @@
3838
# ««revision-date»»···
3939
#--
4040

41-
from __future__ import absolute_import, division, print_function, unicode_literals
42-
43-
from math import log
41+
from __future__ import absolute_import, division
42+
from __future__ import print_function, unicode_literals
4443

44+
from _CNDB import CNDB
4545
from _MOM.import_MOM import *
4646
from _MOM.import_MOM import _A_Unit_, _A_Float_, _A_Named_Value_
47-
from _CNDB import CNDB
48-
import _CNDB._OMP
49-
from _TFL.I18N import _
50-
from _MOM._Attr.Number_Interval import A_Int_Interval_C
5147

5248
import _CNDB._OMP.Wireless_Mode
5349

50+
from _MOM._Attr.Number_Interval import A_Int_Interval_C
51+
52+
from _TFL.I18N import _
53+
from _TFL.pyk import pyk
54+
55+
from math import log
56+
5457
class A_Polarization (_A_Named_Value_) :
5558
"""Antenna polarisation"""
5659

@@ -203,7 +206,7 @@ class _Attributes :
203206

204207
# end class A_IP6_Netmask_Interval
205208

206-
__all__ = tuple (k for (k, v) in globals ().iteritems () if is_attr_type (v))
209+
__all__ = tuple (k for (k, v) in pyk.iteritems (globals ()) if is_attr_type (v))
207210

208211
if __name__ != "__main__" :
209212
CNDB.OMP._Export ("*")

_CNDB/_OMP/IP_Network.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Reichergasse 131, A--3411 Weidling, Austria. [email protected]
44
# #*** <License> ************************************************************#
55
# This module is part of the package CNDB.OMP.
6-
#
6+
#
77
# This module is licensed under the terms of the BSD 3-Clause License
88
# <http://www.c-tanzer.at/license/bsd_3c.html>.
99
# #*** </License> ***********************************************************#
@@ -258,8 +258,8 @@ class owner_or_expiration (Pred.Condition) :
258258
def allocate (self, mask_len, owner) :
259259
# FIXME: Don't allocate if self is electric
260260
# We need this when checking permissions on pools
261-
frm = self.find_closest_mask (mask_len)
262-
net_addr = frm.net_address.subnets (mask_len).next ()
261+
frm = self.find_closest_mask (mask_len)
262+
net_addr = next (frm.net_address.subnets (mask_len))
263263
return self._reserve (self, frm, net_addr, owner)
264264
# end def allocate
265265

_CNDB/_OMP/Wireless_Mode.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# -*- coding: utf-8 -*-
2-
# Copyright (C) 2012 Mag. Christian Tanzer All rights reserved
2+
# Copyright (C) 2012-2014 Mag. Christian Tanzer All rights reserved
33
# Glasauergasse 32, A--1130 Wien, Austria. [email protected]
44
# #*** <License> ************************************************************#
55
# This module is part of the package CNDB.OMP.
6-
#
6+
#
77
# This module is licensed under the terms of the BSD 3-Clause License
88
# <http://www.c-tanzer.at/license/bsd_3c.html>.
99
# #*** </License> ***********************************************************#
@@ -30,6 +30,7 @@
3030
from _TFL import TFL
3131

3232
from _TFL.I18N import _, _T, _Tn
33+
from _TFL.pyk import pyk
3334

3435
import _TFL._Meta.Object
3536

@@ -49,17 +50,18 @@ def __str__ (cls) :
4950
# end def __str__
5051

5152
def _m_add (cls, name, Table) :
52-
name = unicode (name)
53+
name = pyk.text_type (name)
5354
assert name not in Table, "Name clash: `%s` <-> `%s`" % \
5455
(name, Table [name].__class__)
5556
Table [name] = cls
5657
# end def _m_add
5758

5859
# end class M_Wireless_Mode
5960

60-
class Wireless_Mode (TFL.Meta.Object) :
61+
class Wireless_Mode \
62+
(TFL.Meta.BaM (TFL.Meta.Object, metaclass = M_Wireless_Mode)) :
6163

62-
__metaclass__ = M_Wireless_Mode
64+
pass
6365

6466
# end class Wireless_Mode
6567

_CNDB/_OMP/__test__/Antenna.py

+17-18
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Glasauergasse 32, A--1130 Wien, Austria. [email protected]
44
# #*** <License> ************************************************************#
55
# This module is part of the package CNDB.OMP.__test__.
6-
#
6+
#
77
# This module is licensed under the terms of the BSD 3-Clause License
88
# <http://www.c-tanzer.at/license/bsd_3c.html>.
99
# #*** </License> ***********************************************************#
@@ -62,11 +62,10 @@
6262
... , polarization = "horizontal"
6363
... , raw = True
6464
... )
65-
>>> scope.commit ()
66-
Traceback (most recent call last):
67-
...
65+
>>> with expect_except (MOM.Error.Invariants) :
66+
... scope.commit ()
6867
Invariants: Condition `band_exists` : There must be at least one frequency band for the antenna. (number_of_bands >= 1)
69-
bands = ()
68+
bands =
7069
number_of_bands = 0 << len (bands)
7170
7271
>>> args = dict (left = at1, azimuth = "180", elevation_angle = 0, raw = True)
@@ -92,11 +91,11 @@
9291
9392
>>> akw = dict (polarization = "horizontal")
9493
>>> CNDB.Antenna.query_s (* CNDB.Antenna.raw_query_attrs (akw, akw)).all ()
95-
[CNDB.Antenna ((u'yagi1', u'', u''), u'3'), CNDB.Antenna ((u'yagi2', u'', u''), u'4'), CNDB.Antenna ((u'yagi2', u'', u''), u'6')]
94+
[CNDB.Antenna (('yagi1', '', ''), '3'), CNDB.Antenna (('yagi2', '', ''), '4'), CNDB.Antenna (('yagi2', '', ''), '6')]
9695
9796
>>> akw = dict (polarization = "vertical")
9897
>>> CNDB.Antenna.query_s (* CNDB.Antenna.raw_query_attrs (akw, akw)).all ()
99-
[CNDB.Antenna ((u'yagi1', u'', u''), u'1'), CNDB.Antenna ((u'yagi1', u'', u''), u'2')]
98+
[CNDB.Antenna (('yagi1', '', ''), '1'), CNDB.Antenna (('yagi1', '', ''), '2')]
10099
101100
>>> mgr = PAP.Person \\
102101
... (first_name = 'Ralf', last_name = 'Schlatterbeck', raw = True)
@@ -121,7 +120,7 @@
121120
True
122121
123122
>>> b.my_node
124-
CNDB.Node (u'nogps')
123+
CNDB.Node ('nogps')
125124
126125
>>> CNDB.Antenna.query (Q.interface == wl).count ()
127126
1
@@ -134,37 +133,37 @@
134133
135134
>>> for x in scope.CNDB.Net_Interface.query (Q.my_node.manager == mgr, sort_key = Q.pid) :
136135
... x
137-
CNDB.Wireless_Interface (((u'generic', u'', u''), (u'nogps', ), u'dev'), u'', u'wl')
136+
CNDB.Wireless_Interface ((('generic', '', ''), ('nogps', ), 'dev'), '', 'wl')
138137
139138
>>> for x in scope.CNDB.Wireless_Interface_uses_Antenna.query (Q.my_node.manager == mgr, sort_key = Q.pid) :
140139
... x
141-
CNDB.Wireless_Interface_uses_Antenna ((((u'generic', u'', u''), (u'nogps', ), u'dev'), u'', u'wl'), ((u'yagi2', u'', u''), u'6'))
140+
CNDB.Wireless_Interface_uses_Antenna (((('generic', '', ''), ('nogps', ), 'dev'), '', 'wl'), (('yagi2', '', ''), '6'))
142141
143142
>>> for x in scope.CNDB.Net_Device.query (Q.my_node.manager == mgr, sort_key = Q.pid) :
144143
... x
145-
CNDB.Net_Device ((u'generic', u'', u''), (u'nogps', ), u'dev')
146-
CNDB.Net_Device ((u'generic', u'', u''), (u'node2', ), u'dev2')
144+
CNDB.Net_Device (('generic', '', ''), ('nogps', ), 'dev')
145+
CNDB.Net_Device (('generic', '', ''), ('node2', ), 'dev2')
147146
148147
>>> for x in scope.CNDB.Net_Device.query (Q.my_node.owner == owner, sort_key = Q.pid) :
149148
... x
150-
CNDB.Net_Device ((u'generic', u'', u''), (u'node2', ), u'dev2')
149+
CNDB.Net_Device (('generic', '', ''), ('node2', ), 'dev2')
151150
152151
>>> for x in scope.CNDB.Antenna.query (Q.my_node.manager == mgr, sort_key = Q.pid) :
153152
... x
154-
CNDB.Antenna ((u'yagi2', u'', u''), u'6')
153+
CNDB.Antenna (('yagi2', '', ''), '6')
155154
156155
>>> for x in scope.CNDB.Node.query (Q.manager == mgr, sort_key = Q.pid) :
157156
... x
158-
CNDB.Node (u'nogps')
159-
CNDB.Node (u'node2')
157+
CNDB.Node ('nogps')
158+
CNDB.Node ('node2')
160159
161160
>>> for x in scope.CNDB.Node.query (Q.owner == mgr, sort_key = Q.pid) :
162161
... x
163-
CNDB.Node (u'nogps')
162+
CNDB.Node ('nogps')
164163
165164
>>> for x in scope.CNDB.Node.query (Q.owner == owner, sort_key = Q.pid) :
166165
... x
167-
CNDB.Node (u'node2')
166+
CNDB.Node ('node2')
168167
169168
"""
170169

_CNDB/_OMP/__test__/IP_Network.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Glasauergasse 32, A--1130 Wien, Austria. [email protected]
44
# #*** <License> ************************************************************#
55
# This module is part of the package CNDB.OMP.__test__.
6-
#
6+
#
77
# This module is licensed under the terms of the BSD 3-Clause License
88
# <http://www.c-tanzer.at/license/bsd_3c.html>.
99
# #*** </License> ***********************************************************#
@@ -457,7 +457,7 @@
457457
... , Q.ip_pool.cool_down_period != None
458458
... , sort_key = TFL.Sorted_By ("ip_pool.cool_down_period")
459459
... ).distinct ().all ()
460-
[CNDB.IP4_Network_in_IP4_Pool (("10.0.0.0/28", ), (u'rs_pool', )), CNDB.IP4_Network_in_IP4_Pool (("10.0.0.0/8", ), (u'ff_pool', ))]
460+
[CNDB.IP4_Network_in_IP4_Pool (("10.0.0.0/28", ), ('rs_pool', )), CNDB.IP4_Network_in_IP4_Pool (("10.0.0.0/8", ), ('ff_pool', ))]
461461

462462
>>> IPP_ETM = rs_pool.home_scope [rs_pool.ETM.ip_pool.P_Type]
463463
>>> IPP_ETM
@@ -472,14 +472,14 @@
472472
... , Q.ip_pool.cool_down_period != None
473473
... , sort_key = TFL.Sorted_By ("ip_pool.cool_down_period")
474474
... ).first ()
475-
CNDB.IP4_Network_in_IP4_Pool (("10.0.0.0/28", ), (u'rs_pool', ))
475+
CNDB.IP4_Network_in_IP4_Pool (("10.0.0.0/28", ), ('rs_pool', ))
476476

477477
>>> CNDB.IP4_Network_in_IP4_Pool.query \\
478478
... ( Q.ip_network.net_address.CONTAINS (rs_pool.net_address)
479479
... , Q.ip_pool.cool_down_period != None
480480
... , sort_key = TFL.Sorted_By ("ip_pool.cool_down_period")
481481
... ).distinct ().all ()
482-
[CNDB.IP4_Network_in_IP4_Pool (("10.0.0.0/28", ), (u'rs_pool', )), CNDB.IP4_Network_in_IP4_Pool (("10.0.0.0/8", ), (u'ff_pool', ))]
482+
[CNDB.IP4_Network_in_IP4_Pool (("10.0.0.0/28", ), ('rs_pool', )), CNDB.IP4_Network_in_IP4_Pool (("10.0.0.0/8", ), ('ff_pool', ))]
483483

484484
>>> CNDB.IP4_Network_in_IP4_Pool.query \\
485485
... ( Q.ip_network.net_address.CONTAINS (rs_pool.net_address)
@@ -856,10 +856,10 @@
856856
>>> id2 = CNDB.Net_Interface_in_IP_Network (wd, a4, mask_len = 24)
857857

858858
>>> il2
859-
CNDB.Wireless_Interface_in_IP4_Network ((((u'g', u'', u''), (u'nogps', ), u'dev'), u'', u'wl'), ("10.0.0.1", ))
859+
CNDB.Wireless_Interface_in_IP4_Network (((('g', '', ''), ('nogps', ), 'dev'), '', 'wl'), ("10.0.0.1", ))
860860

861861
>>> id2
862-
CNDB.Wired_Interface_in_IP4_Network ((((u'g', u'', u''), (u'nogps', ), u'dev'), u'', u'wd'), ("10.0.0.1", ))
862+
CNDB.Wired_Interface_in_IP4_Network (((('g', '', ''), ('nogps', ), 'dev'), '', 'wd'), ("10.0.0.1", ))
863863

864864
"""
865865

_CNDB/_OMP/__test__/Nodes.py

+9-12
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Glasauergasse 32, A--1130 Wien, Austria. [email protected]
44
# #*** <License> ************************************************************#
55
# This module is part of the package CNDB.OMP.__test__.
6-
#
6+
#
77
# This module is licensed under the terms of the BSD 3-Clause License
88
# <http://www.c-tanzer.at/license/bsd_3c.html>.
99
# #*** </License> ***********************************************************#
@@ -73,7 +73,7 @@
7373
... )
7474
>>> node1.address = adr
7575
>>> node1.address
76-
PAP.Address (u'example 23', u'1010', u'wien', u'austria')
76+
PAP.Address ('example 23', '1010', 'wien', 'austria')
7777
7878
>>> gps2 = dict (lat = "48.367088", lon = "16.187672")
7979
>>> node3 = CNDB.Node \\
@@ -107,9 +107,8 @@
107107
>>> ir2 = CNDB.Net_Interface_in_IP4_Network (wr, a3, mask_len = 24)
108108
>>> il2 = CNDB.Net_Interface_in_IP4_Network (wl, a4, mask_len = 24)
109109
110-
>>> irx = CNDB.Net_Interface_in_IP4_Network (wr, ax, mask_len = 22) # doctest:+ELLIPSIS
111-
Traceback (most recent call last):
112-
...
110+
>>> with expect_except (MOM.Error.Invariants) :
111+
... irx = CNDB.Net_Interface_in_IP4_Network (wr, ax, mask_len = 22) # doctest:+ELLIPSIS
113112
Invariants: Condition `valid_mask_len` : The `mask_len` must match the one of `right` or of any
114113
network containing `right`. (mask_len in possible_mask_lens)
115114
mask_len = 22
@@ -120,9 +119,8 @@
120119
>>> net2 = CNDB.IP4_Network (net_address = '10.0.0.0/8', owner = mgr, raw = True)
121120
>>> a2_1 = net2.reserve (Adr ('10.139.187.0/27'))
122121
>>> a2_2 = net2.reserve (Adr ('10.139.187.2'))
123-
>>> a2_f = net2.reserve (Adr ('10.139.187.0/27'))
124-
Traceback (most recent call last):
125-
...
122+
>>> with expect_except (CNDB.OMP.Error.Address_Already_Used) :
123+
... a2_f = net2.reserve (Adr ('10.139.187.0/27'))
126124
Address_Already_Used: Address 10.139.187.0/27 already in use by 'Schlatterbeck Ralf'
127125
128126
>>> at1 = CNDB.Antenna_Type \\
@@ -259,11 +257,10 @@
259257
260258
>>> node1 = CNDB.Node (name = "nogps", manager = mgr, position = None, raw = True)
261259
>>> node1.owner
262-
PAP.Person (u'schlatterbeck', u'ralf', u'', u'')
260+
PAP.Person ('schlatterbeck', 'ralf', '', '')
263261
264-
>>> node4 = CNDB.Node (name = "node4", manager = mgr, owner = node1)
265-
Traceback (most recent call last):
266-
...
262+
>>> with expect_except (MOM.Error.Wrong_Type) :
263+
... node4 = CNDB.Node (name = "node4", manager = mgr, owner = node1)
267264
Wrong_Type: Node 'nogps' not eligible for attribute owner,
268265
must be instance of Subject
269266

_CNDB/_OMP/__test__/RST.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Glasauergasse 32, A--1130 Wien, Austria. [email protected]
44
# #*** <License> ************************************************************#
55
# This module is part of the package CNDB.OMP.__test__.
6-
#
6+
#
77
# This module is licensed under the terms of the BSD 3-Clause License
88
# <http://www.c-tanzer.at/license/bsd_3c.html>.
99
# #*** </License> ***********************************************************#
@@ -81,8 +81,8 @@ def fixtures (self, scope) :
8181
8282
>>> CC = GTW.RST.MOM.Client.Requester (R.prefix, verify = False)
8383
>>> r = CC.get ("")
84-
>>> r._url
85-
u'http://localhost:9999/'
84+
>>> prepr (r._url)
85+
'http://localhost:9999/'
8686
8787
>>> r = show (R.get ("/v1/CNDB-Node"))
8888
{ 'json' :

0 commit comments

Comments
 (0)