~mterry/duplicity/gdrive

« back to all changes in this revision

Viewing changes to duplicity/static.py

  • Committer: bescoto
  • Date: 2002-10-29 01:49:46 UTC
  • Revision ID: vcs-imports@canonical.com-20021029014946-3m4rmm5plom7pl6q
Initial checkin

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2002 Ben Escoto
 
2
#
 
3
# This file is part of rdiff-backup.
 
4
#
 
5
# rdiff-backup is free software; you can redistribute it and/or modify
 
6
# it under the terms of the GNU General Public License as published by
 
7
# the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA
 
8
# 02139, USA; either version 2 of the License, or (at your option) any
 
9
# later version; incorporated herein by reference.
 
10
 
 
11
"""MakeStatic and MakeClass
 
12
 
 
13
These functions are used to make all the instance methods in a class
 
14
into static or class methods.
 
15
 
 
16
"""
 
17
 
 
18
class StaticMethodsError(Exception): pass
 
19
 
 
20
def MakeStatic(cls):
 
21
        """turn instance methods into static ones
 
22
 
 
23
        The methods (that don't begin with _) of any class that
 
24
        subclasses this will be turned into static methods.
 
25
 
 
26
        """
 
27
        for name in dir(cls):
 
28
                if name[0] != "_":
 
29
                        cls.__dict__[name] = staticmethod(cls.__dict__[name])
 
30
 
 
31
def MakeClass(cls):
 
32
        """Turn instance methods into classmethods.  Ignore _ like above"""
 
33
        for name in dir(cls):
 
34
                if name[0] != "_":
 
35
                        cls.__dict__[name] = classmethod(cls.__dict__[name])