Merge lp:~mterry/duplicity/drop-static into lp:duplicity/0.6

Proposed by Michael Terry
Status: Merged
Merged at revision: 976
Proposed branch: lp:~mterry/duplicity/drop-static
Merge into: lp:duplicity/0.6
Diff against target: 268 lines (+13/-137)
4 files modified
duplicity/lazy.py (+13/-4)
duplicity/static.py (+0/-46)
po/POTFILES.in (+0/-1)
testing/tests/test_static.py (+0/-86)
To merge this branch: bzr merge lp:~mterry/duplicity/drop-static
Reviewer Review Type Date Requested Status
duplicity-team Pending
Review via email: mp+216456@code.launchpad.net

Description of the change

Drop static.py.

This is some of the oldest code in duplicity! A bzr blame says it is unmodified (except for whitespace / comment changes) since revision 1.

But it's not needed anymore. Not really even since we updated to python2.4, which introduced the @staticmethod decorator. So this branch drops it and its test file.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'duplicity/lazy.py'
--- duplicity/lazy.py 2013-12-27 06:39:00 +0000
+++ duplicity/lazy.py 2014-04-18 14:36:20 +0000
@@ -23,46 +23,51 @@
2323
24import os24import os
2525
26from duplicity.static import * #@UnusedWildImport
27
2826
29class Iter:27class Iter:
30 """Hold static methods for the manipulation of lazy iterators"""28 """Hold static methods for the manipulation of lazy iterators"""
3129
30 @staticmethod
32 def filter(predicate, iterator): #@NoSelf31 def filter(predicate, iterator): #@NoSelf
33 """Like filter in a lazy functional programming language"""32 """Like filter in a lazy functional programming language"""
34 for i in iterator:33 for i in iterator:
35 if predicate(i):34 if predicate(i):
36 yield i35 yield i
3736
37 @staticmethod
38 def map(function, iterator): #@NoSelf38 def map(function, iterator): #@NoSelf
39 """Like map in a lazy functional programming language"""39 """Like map in a lazy functional programming language"""
40 for i in iterator:40 for i in iterator:
41 yield function(i)41 yield function(i)
4242
43 @staticmethod
43 def foreach(function, iterator): #@NoSelf44 def foreach(function, iterator): #@NoSelf
44 """Run function on each element in iterator"""45 """Run function on each element in iterator"""
45 for i in iterator:46 for i in iterator:
46 function(i)47 function(i)
4748
49 @staticmethod
48 def cat(*iters): #@NoSelf50 def cat(*iters): #@NoSelf
49 """Lazily concatenate iterators"""51 """Lazily concatenate iterators"""
50 for iter in iters:52 for iter in iters:
51 for i in iter:53 for i in iter:
52 yield i54 yield i
5355
56 @staticmethod
54 def cat2(iter_of_iters): #@NoSelf57 def cat2(iter_of_iters): #@NoSelf
55 """Lazily concatenate iterators, iterated by big iterator"""58 """Lazily concatenate iterators, iterated by big iterator"""
56 for iter in iter_of_iters:59 for iter in iter_of_iters:
57 for i in iter:60 for i in iter:
58 yield i61 yield i
5962
63 @staticmethod
60 def empty(iter): #@NoSelf64 def empty(iter): #@NoSelf
61 """True if iterator has length 0"""65 """True if iterator has length 0"""
62 for i in iter: #@UnusedVariable66 for i in iter: #@UnusedVariable
63 return None67 return None
64 return 168 return 1
6569
70 @staticmethod
66 def equal(iter1, iter2, verbose = None, operator = lambda x, y: x == y): #@NoSelf71 def equal(iter1, iter2, verbose = None, operator = lambda x, y: x == y): #@NoSelf
67 """True if iterator 1 has same elements as iterator 272 """True if iterator 1 has same elements as iterator 2
6873
@@ -88,6 +93,7 @@
88 print "End when i2 = %s" % (i2,)93 print "End when i2 = %s" % (i2,)
89 return None94 return None
9095
96 @staticmethod
91 def Or(iter): #@NoSelf97 def Or(iter): #@NoSelf
92 """True if any element in iterator is true. Short circuiting"""98 """True if any element in iterator is true. Short circuiting"""
93 i = None99 i = None
@@ -96,6 +102,7 @@
96 return i102 return i
97 return i103 return i
98104
105 @staticmethod
99 def And(iter): #@NoSelf106 def And(iter): #@NoSelf
100 """True if all elements in iterator are true. Short circuiting"""107 """True if all elements in iterator are true. Short circuiting"""
101 i = 1108 i = 1
@@ -104,6 +111,7 @@
104 return i111 return i
105 return i112 return i
106113
114 @staticmethod
107 def len(iter): #@NoSelf115 def len(iter): #@NoSelf
108 """Return length of iterator"""116 """Return length of iterator"""
109 i = 0117 i = 0
@@ -114,6 +122,7 @@
114 return i122 return i
115 i = i+1123 i = i+1
116124
125 @staticmethod
117 def foldr(f, default, iter): #@NoSelf126 def foldr(f, default, iter): #@NoSelf
118 """foldr the "fundamental list recursion operator"?"""127 """foldr the "fundamental list recursion operator"?"""
119 try:128 try:
@@ -122,6 +131,7 @@
122 return default131 return default
123 return f(next, Iter.foldr(f, default, iter))132 return f(next, Iter.foldr(f, default, iter))
124133
134 @staticmethod
125 def foldl(f, default, iter): #@NoSelf135 def foldl(f, default, iter): #@NoSelf
126 """the fundamental list iteration operator.."""136 """the fundamental list iteration operator.."""
127 while 1:137 while 1:
@@ -131,6 +141,7 @@
131 return default141 return default
132 default = f(default, next)142 default = f(default, next)
133143
144 @staticmethod
134 def multiplex(iter, num_of_forks, final_func = None, closing_func = None): #@NoSelf145 def multiplex(iter, num_of_forks, final_func = None, closing_func = None): #@NoSelf
135 """Split a single iterater into a number of streams146 """Split a single iterater into a number of streams
136147
@@ -191,8 +202,6 @@
191202
192 return tuple(map(make_iterator, range(num_of_forks)))203 return tuple(map(make_iterator, range(num_of_forks)))
193204
194MakeStatic(Iter)
195
196205
197class IterMultiplex2:206class IterMultiplex2:
198 """Multiplex an iterator into 2 parts207 """Multiplex an iterator into 2 parts
199208
=== removed file 'duplicity/static.py'
--- duplicity/static.py 2009-04-01 15:07:45 +0000
+++ duplicity/static.py 1970-01-01 00:00:00 +0000
@@ -1,46 +0,0 @@
1# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
2#
3# Copyright 2002 Ben Escoto <ben@emerose.org>
4# Copyright 2007 Kenneth Loafman <kenneth@loafman.com>
5#
6# This file is part of duplicity.
7#
8# Duplicity is free software; you can redistribute it and/or modify it
9# under the terms of the GNU General Public License as published by the
10# Free Software Foundation; either version 2 of the License, or (at your
11# option) any later version.
12#
13# Duplicity is distributed in the hope that it will be useful, but
14# WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16# General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with duplicity; if not, write to the Free Software Foundation,
20# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
22"""MakeStatic and MakeClass
23
24These functions are used to make all the instance methods in a class
25into static or class methods.
26
27"""
28
29class StaticMethodsError(Exception): pass
30
31def MakeStatic(cls):
32 """turn instance methods into static ones
33
34 The methods (that don't begin with _) of any class that
35 subclasses this will be turned into static methods.
36
37 """
38 for name in dir(cls):
39 if name[0] != "_":
40 cls.__dict__[name] = staticmethod(cls.__dict__[name])
41
42def MakeClass(cls):
43 """Turn instance methods into classmethods. Ignore _ like above"""
44 for name in dir(cls):
45 if name[0] != "_":
46 cls.__dict__[name] = classmethod(cls.__dict__[name])
470
=== modified file 'po/POTFILES.in'
--- po/POTFILES.in 2014-04-17 19:34:23 +0000
+++ po/POTFILES.in 2014-04-18 14:36:20 +0000
@@ -16,7 +16,6 @@
16duplicity/log.py16duplicity/log.py
17duplicity/robust.py17duplicity/robust.py
18duplicity/misc.py18duplicity/misc.py
19duplicity/static.py
20duplicity/diffdir.py19duplicity/diffdir.py
21duplicity/lazy.py20duplicity/lazy.py
22duplicity/backends/_cf_pyrax.py21duplicity/backends/_cf_pyrax.py
2322
=== removed file 'testing/tests/test_static.py'
--- testing/tests/test_static.py 2014-04-16 02:43:43 +0000
+++ testing/tests/test_static.py 1970-01-01 00:00:00 +0000
@@ -1,86 +0,0 @@
1# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
2#
3# Copyright 2002 Ben Escoto <ben@emerose.org>
4# Copyright 2007 Kenneth Loafman <kenneth@loafman.com>
5#
6# This file is part of duplicity.
7#
8# Duplicity is free software; you can redistribute it and/or modify it
9# under the terms of the GNU General Public License as published by the
10# Free Software Foundation; either version 2 of the License, or (at your
11# option) any later version.
12#
13# Duplicity is distributed in the hope that it will be useful, but
14# WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16# General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with duplicity; if not, write to the Free Software Foundation,
20# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
22import helper
23import unittest, types, sys
24
25from duplicity.static import * #@UnusedWildImport
26
27helper.setup()
28
29class D:
30 def foo(x, y): #@NoSelf
31 return x, y
32 def bar(self, x):
33 return 3, x
34 def _hello(self):
35 return self
36
37MakeStatic(D)
38
39
40class C:
41 _a = 0
42 def get(cls): #@NoSelf
43 return cls._a
44 def inc(cls): #@NoSelf
45 cls._a = cls._a + 1
46
47MakeClass(C)
48
49
50class StaticMethodsTest(unittest.TestCase):
51 """Test StaticMethods module"""
52 def testType(self):
53 """Methods should have type StaticMethod"""
54 assert type(D.foo) is types.FunctionType
55 assert type(D.bar) is types.FunctionType
56
57 def testStatic(self):
58 """Methods should be callable without instance"""
59 assert D.foo(1,2) == (1,2)
60 assert D.bar(3,4) == (3,4)
61
62 def testBound(self):
63 """Methods should also work bound"""
64 d = D()
65 assert d.foo(1,2) == (1,2)
66 assert d.bar(3,4) == (3,4)
67
68 def testStatic_(self):
69 """_ Methods should be untouched"""
70 d = D()
71 self.assertRaises(TypeError, d._hello, 4)
72 assert d._hello() is d
73
74
75class ClassMethodsTest(unittest.TestCase):
76 def test(self):
77 """Test MakeClass function"""
78 assert C.get() == 0
79 C.inc()
80 assert C.get() == 1
81 C.inc()
82 assert C.get() == 2
83
84
85if __name__ == "__main__":
86 unittest.main()

Subscribers

People subscribed via source and target branches

to all changes: