Hi, Thanks for the hint, however, they only applies to tar archive file (give by path) and not to 'file objects' as you get from "file = self.cleaned_data['file']" in django models.
More specifically, how to make class tarfile to handle django.core.files.uploadedfile.InMemoryUploadedFile objects. Any help is always welcome. Thanks in advance, Alan On Tue, Dec 23, 2008 at 12:09, Paul van der Linden <p...@soulbase.nl> wrote: > > Hi, > look at the module reference at python documentation: > http://www.python.org/doc/2.5.2/lib/module-tarfile.html > You can see there an is_tarfile to check if it is a tar file, or you can > use TarFileCompat to check if it is a tar_gzipped file. > Alan wrote: > > Hi There, > > > > So I have a form where users can upload zip and tgz file. In my def > > clean_file() for class MyForm, I can clean zip files smoothly and now > > I am trying the same for a tgz file but missing things. > > > > First, fileobj = self.cleaned_data['file'] will return a fileobj, so I > > tried: > > > > tar = tarfile.open(fileobj=fileobj) > > > > but then I cannot do anything with 'tar'. I mean, tar.list() returns > > nothing. Even worse, my fileobj can be any thing, a 'zip' for example, > > and tarfile.open doesn't seem to check for that as it does if it was a > > file like 'myfile.tgz' or 'myfile.zip', failing to open for the former. > > > > I tried google and also StringIO, but without success. All I want is > > to check if the supposed tgz file is a valid tgz file as I do for a > > zip file. > > > > Many thanks in avance, > > Alan > > > > -- > > Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate > > Department of Biochemistry, University of Cambridge. > > 80 Tennis Court Road, Cambridge CB2 1GA, UK. > > >>http://www.bio.cam.ac.uk/~awd28 <http://www.bio.cam.ac.uk/%7Eawd28><< > > > > > > > > > > -- Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate Department of Biochemistry, University of Cambridge. 80 Tennis Court Road, Cambridge CB2 1GA, UK. >>http://www.bio.cam.ac.uk/~awd28<< --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---