----- Original Message ----- > On 05/23/2012 06:55 PM, Bohuslav Kabrda wrote: > >> # monkey patch ZipFile to behave like TarFile > >> ZipFile.getmembers = ZipFile.infolist > >> ZipFile.extractfile = ZipFile.open > >> ZipFile.open = ZipFile # this line is at fault here > >> ZipInfo.name = ZipInfo.filename > >> > >> Real zipfile.ZipFile.open opens member of archive not an archive > >> itself. > >> So in code above z.read(info.filename) ends up calling ZipFile > >> instead > >> of real zipfile.ZipFile.open, providing wrong aruments. > >> > >> -- > >> Zart > > > > Thanks a lot... I didn't know that all the modules get imported > > during install... I guess moving that code somewhere to the > > archive class will do fine. > > Is monkeypatching really necessary here? Monkeypatching affects > global > process state (i.e. class definitions in imported modules), so it's a > fairly extreme approach to the problem of inconsistent method names > that > prevent duck-typing. It's generally preferable to use a wrapper class > or > a custom subclass to adapt between the two APIs at the point of use > rather than changing state that can be seen by every other module > that > gets imported into the same process. > > Cheers, > Nick. >
I agree that monkey patching is not necessary, but it certainly makes things easier. I considered creating the wrapper class, but monkey patching just seemed as a better option ATM. Having said that, I'm open to any suggestions and I will rethink this as the library grows much larger than I previously thought it would. > -- > Nick Coghlan > Red Hat Infrastructure Engineering & Development, Brisbane > _______________________________________________ > python-devel mailing list > [email protected] > https://admin.fedoraproject.org/mailman/listinfo/python-devel -- Regards, Bohuslav "Slavek" Kabrda. _______________________________________________ python-devel mailing list [email protected] https://admin.fedoraproject.org/mailman/listinfo/python-devel
