Re: [Tutor] Determine Filetype

2009-09-20 Thread Alan Gauld

ad...@gg-lab.net wrote:

The search feature of the web site is quite effective! :-)



simple to be used if you're looking for a very common word ("in") and
don't know other keys to find it.


To be honest I was being a bit optimistic but I did
just type "in" for the search and the first 5 or so
hits had all the right bits...

Alan G

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Determine Filetype

2009-09-20 Thread ad...@gg-lab.net
Thankyou guys.

> The search feature of the web site is quite effective! :-)

Alan, i know that every site has a search function, but they're not so
simple to be used if you're looking for a very common word ("in") and
don't know other keys to find it.

Regards,
Giorgio
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Determine Filetype

2009-09-19 Thread Alan Gauld

ad...@gg-lab.net wrote:


if OBJECT in LIST:

Well, but i'd like to read the page of the python tutorial regarding
this. I'm not able to locate it. Can you help me?


Not everything is covered in the odfficial tutorial, its only meant to 
be an introduction to the language.


You should find it in the reference documents.
Look about half way down section 5.9 in the language refeence for example.

but it turnsout section 5.7 of the tutorial does have a description of 
in



The search feature of the web site is quite effective! :-)

Alan G
http://www.alan-g.me.uk


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Determine Filetype

2009-09-19 Thread Sander Sweers
On Sat, 2009-09-19 at 17:36 +0200, ad...@gg-lab.net wrote:
> if OBJECT in LIST:
> 
> Well, but i'd like to read the page of the python tutorial regarding
> this. I'm not able to locate it. Can you help me?

When in the python interpreter type help('in') and you should have all
info you need about this.

Greets
Sander

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Determine Filetype

2009-09-19 Thread ad...@gg-lab.net
2009/9/19 Sander Sweers :
> On Sat, 2009-09-19 at 17:20 +0200, ad...@gg-lab.net wrote:
>> I want to check the extension of an uploaded file. So i've created a
>> list with allowed extensions:
>>
>> enabled_ext = ['gif', 'jpeg', 'png', 'bmp', 'tiff']
>
> If this does not change make it s tuple. It does not change what is
> written below.
>
>> How can i create a simple if that check if the file ext (file_ext) is
>> in the list?
>
> The below idle session should help you figure it out.
>
 enabled_ext = ('gif', 'jpeg', 'png', 'bmp', 'tiff')
 'gif' in enabled_ext
> True
>
> Greets
> Sander
>
> A: Because it messes up the order in which people normally read text.
> Q: Why is top-posting such a bad thing?
> A: Top-posting.
> Q: What is the most annoying thing in e-mail?
>
> ___
> Tutor maillist  -  tu...@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>

Sander, sorry for the top-posting, it's the default in GMail. This is
one of my first times in a mailing list, so it's possible i'm doing
something wrong. Sorry again for it.

I've replied to my mail, as i've found what i was looking for:

if OBJECT in LIST:

Well, but i'd like to read the page of the python tutorial regarding
this. I'm not able to locate it. Can you help me?

Thankyou
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Determine Filetype

2009-09-19 Thread Sander Sweers
On Sat, 2009-09-19 at 17:20 +0200, ad...@gg-lab.net wrote:
> I want to check the extension of an uploaded file. So i've created a
> list with allowed extensions:
> 
> enabled_ext = ['gif', 'jpeg', 'png', 'bmp', 'tiff']

If this does not change make it s tuple. It does not change what is
written below.

> How can i create a simple if that check if the file ext (file_ext) is
> in the list?

The below idle session should help you figure it out.

>>> enabled_ext = ('gif', 'jpeg', 'png', 'bmp', 'tiff')
>>> 'gif' in enabled_ext
True

Greets
Sander

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Determine Filetype

2009-09-19 Thread ad...@gg-lab.net
if file_ext in enabled_ext

Found an example some seconds ago in another mailing lists. I'm not
able to find the python tutorial that describes this statement. Can
you help me please?

2009/9/19 ad...@gg-lab.net :
> Ops, i have another question, it seems very simple.
>
> I want to check the extension of an uploaded file. So i've created a
> list with allowed extensions:
>
> enabled_ext = ['gif', 'jpeg', 'png', 'bmp', 'tiff']
>
> How can i create a simple if that check if the file ext (file_ext) is
> in the list?
>
> I've searched in the python tutorial, but have not been able to find
> any example that uses an if statement combined with a list.
>
> Thankyou again
>
> 2009/9/19 ad...@gg-lab.net :
>> Hi All,
>>
>> the solution was in the link i've posted before. If i use:
>>
>> type = imghdr.what('img.test', image.data)
>>
>> The imghdr modules ignore the filename (first argument) and takes the
>> second as a data stream assumed to contain the filetype.
>>
>> The solution only works for images, but that's what i need. I think
>> that right now is not possible to generally determine the mimetype for
>> all types of files on GAE, because some libraries are missing. Anyway,
>> i'll send a mail to the gae mailing list, and if find a solution i'll
>> post it here.
>>
>> Thankyou all guys.
>>
>> 2009/9/19 Sander Sweers :
>>> On Fri, 2009-09-18 at 16:48 -0400, Kent Johnson wrote:
 > So, the __init__.py file of the GAE evinronment's ctypes library is
 > broken, as it's importing from a package that doesn't exist. Right?

 Probably ctypes is not supported in GAE, that would be a pretty big
 security hole.
>>>
>>> There is a pure python implementation on pypi [1]. It states it is in
>>> alpha and missing some features. Never used it myself though...
>>>
>>> Greets
>>> Sander
>>>
>>> [1] http://pypi.python.org/pypi/pymagic/0.1
>>>
>>> ___
>>> Tutor maillist  -  tu...@python.org
>>> To unsubscribe or change subscription options:
>>> http://mail.python.org/mailman/listinfo/tutor
>>>
>>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Determine Filetype

2009-09-19 Thread ad...@gg-lab.net
Ops, i have another question, it seems very simple.

I want to check the extension of an uploaded file. So i've created a
list with allowed extensions:

enabled_ext = ['gif', 'jpeg', 'png', 'bmp', 'tiff']

How can i create a simple if that check if the file ext (file_ext) is
in the list?

I've searched in the python tutorial, but have not been able to find
any example that uses an if statement combined with a list.

Thankyou again

2009/9/19 ad...@gg-lab.net :
> Hi All,
>
> the solution was in the link i've posted before. If i use:
>
> type = imghdr.what('img.test', image.data)
>
> The imghdr modules ignore the filename (first argument) and takes the
> second as a data stream assumed to contain the filetype.
>
> The solution only works for images, but that's what i need. I think
> that right now is not possible to generally determine the mimetype for
> all types of files on GAE, because some libraries are missing. Anyway,
> i'll send a mail to the gae mailing list, and if find a solution i'll
> post it here.
>
> Thankyou all guys.
>
> 2009/9/19 Sander Sweers :
>> On Fri, 2009-09-18 at 16:48 -0400, Kent Johnson wrote:
>>> > So, the __init__.py file of the GAE evinronment's ctypes library is
>>> > broken, as it's importing from a package that doesn't exist. Right?
>>>
>>> Probably ctypes is not supported in GAE, that would be a pretty big
>>> security hole.
>>
>> There is a pure python implementation on pypi [1]. It states it is in
>> alpha and missing some features. Never used it myself though...
>>
>> Greets
>> Sander
>>
>> [1] http://pypi.python.org/pypi/pymagic/0.1
>>
>> ___
>> Tutor maillist  -  tu...@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Determine Filetype

2009-09-19 Thread ad...@gg-lab.net
Hi All,

the solution was in the link i've posted before. If i use:

type = imghdr.what('img.test', image.data)

The imghdr modules ignore the filename (first argument) and takes the
second as a data stream assumed to contain the filetype.

The solution only works for images, but that's what i need. I think
that right now is not possible to generally determine the mimetype for
all types of files on GAE, because some libraries are missing. Anyway,
i'll send a mail to the gae mailing list, and if find a solution i'll
post it here.

Thankyou all guys.

2009/9/19 Sander Sweers :
> On Fri, 2009-09-18 at 16:48 -0400, Kent Johnson wrote:
>> > So, the __init__.py file of the GAE evinronment's ctypes library is
>> > broken, as it's importing from a package that doesn't exist. Right?
>>
>> Probably ctypes is not supported in GAE, that would be a pretty big
>> security hole.
>
> There is a pure python implementation on pypi [1]. It states it is in
> alpha and missing some features. Never used it myself though...
>
> Greets
> Sander
>
> [1] http://pypi.python.org/pypi/pymagic/0.1
>
> ___
> Tutor maillist  -  tu...@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Determine Filetype

2009-09-19 Thread Sander Sweers
On Fri, 2009-09-18 at 16:48 -0400, Kent Johnson wrote:
> > So, the __init__.py file of the GAE evinronment's ctypes library is
> > broken, as it's importing from a package that doesn't exist. Right?
> 
> Probably ctypes is not supported in GAE, that would be a pretty big
> security hole.

There is a pure python implementation on pypi [1]. It states it is in
alpha and missing some features. Never used it myself though...

Greets
Sander

[1] http://pypi.python.org/pypi/pymagic/0.1

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Determine Filetype

2009-09-18 Thread Kent Johnson
On Fri, Sep 18, 2009 at 4:10 PM, ad...@gg-lab.net  wrote:

> Ok, so magic is not installed on GAE. I've then uploaded it and it
> loaded succesfully. New error:
>
> No module named _ctypes
>
> And, reading the full debug i got this:
>
> File "/base/python_dist/lib/python2.5/ctypes/__init__.py", line 10, in 
> 
>    from _ctypes import Union, Structure, Array
>
> So, the __init__.py file of the GAE evinronment's ctypes library is
> broken, as it's importing from a package that doesn't exist. Right?

Probably ctypes is not supported in GAE, that would be a pretty big
security hole.

Kent
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Determine Filetype

2009-09-18 Thread ad...@gg-lab.net
Ok, a good news for me:

i've modified my script, adding a:

import magic

line at the top of it. But I got this error:

No module named magic

Ok, so magic is not installed on GAE. I've then uploaded it and it
loaded succesfully. New error:

No module named _ctypes

And, reading the full debug i got this:

File "/base/python_dist/lib/python2.5/ctypes/__init__.py", line 10, in 
from _ctypes import Union, Structure, Array

So, the __init__.py file of the GAE evinronment's ctypes library is
broken, as it's importing from a package that doesn't exist. Right?
Maybe i'm doing something wrong.

Thankyou

2009/9/18 ad...@gg-lab.net :
> Oh, i'm sorry.
>
> I've read the README, but haven't noticed that
>
> m.from_buffer(open("testdata/test.pdf").read(1024))
>
> was exactly what i was looking for.
>
> Ok, i'll try it and let you know :D
>
> 2009/9/18 Kent Johnson :
>> On Fri, Sep 18, 2009 at 2:21 PM, ad...@gg-lab.net  wrote:
>>> Hi Emile,
>>>
>>> that functions requires a filename/path.
>>
>> Did you even look at the link? There is a from_buffer() method also.
>>
>> Kent
>>
>>> 2009/9/18 Emile van Sebille :
>>
 I'd take a look at python-magic at
 http://hupp.org/adam/hg/python-magic/file/d3cd83e5a773 where the example
 shows that you can do:

 # For MIME types
>>> mime = magic.Magic(mime=True)
>>> mime.from_file("testdata/test.pdf")
 'application/pdf'
>>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Determine Filetype

2009-09-18 Thread ad...@gg-lab.net
Oh, i'm sorry.

I've read the README, but haven't noticed that

m.from_buffer(open("testdata/test.pdf").read(1024))

was exactly what i was looking for.

Ok, i'll try it and let you know :D

2009/9/18 Kent Johnson :
> On Fri, Sep 18, 2009 at 2:21 PM, ad...@gg-lab.net  wrote:
>> Hi Emile,
>>
>> that functions requires a filename/path.
>
> Did you even look at the link? There is a from_buffer() method also.
>
> Kent
>
>> 2009/9/18 Emile van Sebille :
>
>>> I'd take a look at python-magic at
>>> http://hupp.org/adam/hg/python-magic/file/d3cd83e5a773 where the example
>>> shows that you can do:
>>>
>>> # For MIME types
>> mime = magic.Magic(mime=True)
>> mime.from_file("testdata/test.pdf")
>>> 'application/pdf'
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Determine Filetype

2009-09-18 Thread Kent Johnson
On Fri, Sep 18, 2009 at 2:21 PM, ad...@gg-lab.net  wrote:
> Hi Emile,
>
> that functions requires a filename/path.

Did you even look at the link? There is a from_buffer() method also.

Kent

> 2009/9/18 Emile van Sebille :

>> I'd take a look at python-magic at
>> http://hupp.org/adam/hg/python-magic/file/d3cd83e5a773 where the example
>> shows that you can do:
>>
>> # For MIME types
> mime = magic.Magic(mime=True)
> mime.from_file("testdata/test.pdf")
>> 'application/pdf'
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Determine Filetype

2009-09-18 Thread ad...@gg-lab.net
Hi Emile,

that functions requires a filename/path. Just like this one (for images)

http://docs.python.org/library/imghdr.html

Ok, i don't have a filename. I get the file from a BLOB in a db. Any idea?

Thankyou for your precious help.

2009/9/18 Emile van Sebille :
> On 9/18/2009 10:05 AM ad...@gg-lab.net said...
>>
>> Hi,
>>
>> i'm putting file in a DB as BLOB entries. To serve them, i need to
>> take Content-Type headers.
>>
>> So, i'm looking for a function that returnes the filetype, given a data
>> str.
>>
>> I've found many other topics like this in python mail-archive, but any
>> of them contains the solution.
>>
>> Can you help me, please?
>
> I'd take a look at python-magic at
> http://hupp.org/adam/hg/python-magic/file/d3cd83e5a773 where the example
> shows that you can do:
>
> # For MIME types
 mime = magic.Magic(mime=True)
 mime.from_file("testdata/test.pdf")
> 'application/pdf'
>
>
> HTH,
>
> Emile
>
>
>
>
>
>>
>> Thankyou!
>> ___
>> Tutor maillist  -  tu...@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>
> ___
> Tutor maillist  -  tu...@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Determine Filetype

2009-09-18 Thread Emile van Sebille

On 9/18/2009 10:05 AM ad...@gg-lab.net said...

Hi,

i'm putting file in a DB as BLOB entries. To serve them, i need to
take Content-Type headers.

So, i'm looking for a function that returnes the filetype, given a data str.

I've found many other topics like this in python mail-archive, but any
of them contains the solution.

Can you help me, please?


I'd take a look at python-magic at 
http://hupp.org/adam/hg/python-magic/file/d3cd83e5a773 where the example 
shows that you can do:


# For MIME types
>>> mime = magic.Magic(mime=True)
>>> mime.from_file("testdata/test.pdf")
'application/pdf'


HTH,

Emile







Thankyou!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Determine Filetype

2009-09-18 Thread ad...@gg-lab.net
Hi,

i'm putting file in a DB as BLOB entries. To serve them, i need to
take Content-Type headers.

So, i'm looking for a function that returnes the filetype, given a data str.

I've found many other topics like this in python mail-archive, but any
of them contains the solution.

Can you help me, please?

Thankyou!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor