class RarWrapper(object): ''' ArchiveWrapper for rarfiles ''' ImplementsInterface(IArchiveWrapper) def __init__(self, filename): from ._rarfile import Rarfile self.wrapped = Rarfile().CreateRarFile(filename) def ListFilenames(self): from ben10.filesystem import StandardizePath return [ StandardizePath(i) for i in self.wrapped.namelist() if not i.endswith('/') ] def ListDirs(self): result = [] for i in self.ListFilenames(): if self.wrapped.getinfo(i).isdir(): result.append(i) else: result.append(os.path.dirname(i)) return sorted(result) def ReadFile(self, filename): return self.wrapped.read(filename)
class ZipWrapper(object): ''' ArchiveWrapper for zipfiles ''' ImplementsInterface(IArchiveWrapper) def __init__(self, filename): import zipfile self.wrapped = zipfile.ZipFile(filename) @Implements(IArchiveWrapper.ListFilenames) def ListFilenames(self): from ben10.filesystem import StandardizePath return [ StandardizePath(i) for i in self.wrapped.namelist() if not i.endswith('/') ] @Implements(IArchiveWrapper.ListDirs) def ListDirs(self): result = set() for i in self.wrapped.namelist(): if i.endswith('/'): result.add(i[:-1]) else: result.add(os.path.dirname(i)) return sorted(result) @Implements(IArchiveWrapper.ReadFile) def ReadFile(self, filename): return self.wrapped.read(filename)
class C(object): ImplementsInterface(_InterfM4) def m4(self): '' def m3(self, arg1, arg2): ''
class C(object): ImplementsInterface(I) def foo(self, a, b=None): '' def bar(self): ''
class My(object): ImplementsInterface(_InterfM1) def m1(self): return 'm1' def m2(self): ''
class A(object): ImplementsInterface(InterfSetItem) def __setitem__(self, id, subject): self.set = (id, subject) def __getitem__(self, id): return self.set
class Zoo(object): ImplementsInterface(IZoo) def __init__(self, value): self.zoo = value
class B(object): ImplementsInterface(_InterfM1) def m1(self): ''
class A(object): ImplementsInterface(IAdaptable) def GetAdapter(self, interface_class): if interface_class == _InterfM1: return B()
class Zoo(object): ImplementsInterface(IZoo)
class C2B(object): ImplementsInterface(I2) def M2(self): ''
class My3(object): ImplementsInterface(_InterfM3) def m3(self, arg1, arg2): ''
class My2(object): ImplementsInterface(_InterfM2) def m2(self): ''
class NoCheck(object): ImplementsInterface(_InterfM1, no_init_check=True)
class Old2: ImplementsInterface(_InterfM1, old_style=True) # but do not really implements
class Old: ImplementsInterface(_InterfM1, old_style=True) def m1(self): ''
class FlawedZoo(object): ImplementsInterface(IZoo) def __init__(self, value): ''
class Bar(object): ImplementsInterface(IBar) def something(self, stuff): ''
class Foo(object): ImplementsInterface(I1) ImplementsInterface(I2) def Method2(self): ''
class C(object): ImplementsInterface(I) def foo(self): ''
class Foo(object): ImplementsInterface(IFoo) def __call__(self, bar): ''
class D(C): ImplementsInterface(I2) def bar(self): ''
class C(object): ImplementsInterface(I)
class B(A): ImplementsInterface(_InterfM2) def m2(self): ''