Jim Gallacher wrote:
How about this? (Excuse the LateX)

\class{Field} instances have the following attributes:

...

  \begin{memberdesc}{file}
    This is a file-like object. For file uploads it points to a
    \class{TemporaryFile} instance. (For more information see
    TemporaryFile in the standard python
   \citetitle[http://docs.python.org/lib/module-tempfile.html]{tempfile}
    module).

    For simple values, it is a \class{StringIO} object, so you
    can read simple string values via this attribute instead of using
    the \member{value} attribute as well.
  \end{memberdesc}

Looks good.  Reading this probably answers your question after next.

I guess where I'm getting hung-up is in trying to understand why this is important. Why do you need to know if it's a file object or a file-like object?

It's important to know how to handle information coming in from a POST, because generically I may not know whether a field named "the_file" is intended as a string file name (from type="text") or a file (from type="file"). I don't know what the semantics of the form being submitted are, but I need to do something different with strings and files.

First you're talking about file vs. file-like object, and then file vs string. When you say string do you mean StringIO or StringField. If it's just a case of StringField vs any of the file-like objects, why not just use hasattr(field_thing, 'read')?

Because if the Field is a string value, the file attribute is a StringIO (or cStringIO), which has a read attribute. hasattr(field_thing, 'read') should *always* return True no matter what the Field stores (see documentation above).

I don't know what it is about this issue, but every time I look at it I feel like my IQ has dropped a couple of points. Since this is a limited resource already I don't want to lose any more of it.

Fair enough. I can check to see if file is a StringIO, or a cStringIO, but that's assuming that some Python implemention doesn't decide to return one of those from a tempfile.TemporaryFile call. It's probably not important enough for most people anyway since they're using publisher or something similar.

Sorry to have wasted time on this.

Nick

Reply via email to