/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk

« back to all changes in this revision

Viewing changes to mandos

  • Committer: Teddy Hogeborn
  • Date: 2019-08-10 15:19:47 UTC
  • Revision ID: teddy@recompile.se-20190810151947-wyw7cetrh1pvtw37
Simplification of Python 3 compatibility code

Normally, "class Foo:" in Python 2 creates a "classic" class, but in
Python 3, all classes are "new-style" classes, which you can get in
Python 2 by doing "class Foo(object):", i.e. inheriting from "object".
But, you can also get a new-style classes from "class Foo:" in Python
2 by setting the global "__metaclass__" variable to "type", which
makes the code less cluttered.  Note: it is still necessary to inherit
from "object" in Python 2 to get a new-style class if the class is
otherwise inheriting only from "classic" classes.

* mandos: Set "__metaclass__ = type" globally for Python 2, and remove
          inheriting from "object" in all places possible.
* mandos-ctl: - '' -

Show diffs side-by-side

added added

removed removed

Lines of Context:
88
88
import xml.dom.minidom
89
89
import inspect
90
90
 
 
91
if sys.version_info.major == 2:
 
92
    __metaclass__ = type
 
93
 
91
94
# Try to find the value of SO_BINDTODEVICE:
92
95
try:
93
96
    # This is where SO_BINDTODEVICE is in Python 3.3 (or 3.4?) and
183
186
    pass
184
187
 
185
188
 
186
 
class PGPEngine(object):
 
189
class PGPEngine:
187
190
    """A simple class for OpenPGP symmetric encryption & decryption"""
188
191
 
189
192
    def __init__(self):
279
282
 
280
283
 
281
284
# Pretend that we have an Avahi module
282
 
class avahi(object):
 
285
class avahi:
283
286
    """This isn't so much a class as it is a module-like namespace."""
284
287
    IF_UNSPEC = -1               # avahi-common/address.h
285
288
    PROTO_UNSPEC = -1            # avahi-common/address.h
319
322
    pass
320
323
 
321
324
 
322
 
class AvahiService(object):
 
325
class AvahiService:
323
326
    """An Avahi (Zeroconf) service.
324
327
 
325
328
    Attributes:
507
510
 
508
511
 
509
512
# Pretend that we have a GnuTLS module
510
 
class gnutls(object):
 
513
class gnutls:
511
514
    """This isn't so much a class as it is a module-like namespace."""
512
515
 
513
516
    library = ctypes.util.find_library("gnutls")
576
579
        pass
577
580
 
578
581
    # Classes
579
 
    class Credentials(object):
 
582
    class Credentials:
580
583
        def __init__(self):
581
584
            self._c_object = gnutls.certificate_credentials_t()
582
585
            gnutls.certificate_allocate_credentials(
586
589
        def __del__(self):
587
590
            gnutls.certificate_free_credentials(self._c_object)
588
591
 
589
 
    class ClientSession(object):
 
592
    class ClientSession:
590
593
        def __init__(self, socket, credentials=None):
591
594
            self._c_object = gnutls.session_t()
592
595
            gnutls_flags = gnutls.CLIENT
818
821
    connection.close()
819
822
 
820
823
 
821
 
class Client(object):
 
824
class Client:
822
825
    """A representation of a client host served by this server.
823
826
 
824
827
    Attributes:
2213
2216
    del _interface
2214
2217
 
2215
2218
 
2216
 
class ProxyClient(object):
 
2219
class ProxyClient:
2217
2220
    def __init__(self, child_pipe, key_id, fpr, address):
2218
2221
        self._pipe = child_pipe
2219
2222
        self._pipe.send(('init', key_id, fpr, address))
2492
2495
        return hex_fpr
2493
2496
 
2494
2497
 
2495
 
class MultiprocessingMixIn(object):
 
2498
class MultiprocessingMixIn:
2496
2499
    """Like socketserver.ThreadingMixIn, but with multiprocessing"""
2497
2500
 
2498
2501
    def sub_process_main(self, request, address):
2510
2513
        return proc
2511
2514
 
2512
2515
 
2513
 
class MultiprocessingMixInWithPipe(MultiprocessingMixIn, object):
 
2516
class MultiprocessingMixInWithPipe(MultiprocessingMixIn):
2514
2517
    """ adds a pipe to the MixIn """
2515
2518
 
2516
2519
    def process_request(self, request, client_address):
2531
2534
 
2532
2535
 
2533
2536
class IPv6_TCPServer(MultiprocessingMixInWithPipe,
2534
 
                     socketserver.TCPServer, object):
 
2537
                     socketserver.TCPServer):
2535
2538
    """IPv6-capable TCP server.  Accepts 'None' as address and/or port
2536
2539
 
2537
2540
    Attributes: