Back to index

plone3  3.1.7
Public Member Functions | Static Public Attributes
ATContentTypes.lib.urlupload.URLUpload Class Reference
Inheritance diagram for ATContentTypes.lib.urlupload.URLUpload:
Inheritance graph
[legend]
Collaboration diagram for ATContentTypes.lib.urlupload.URLUpload:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def loadFileFromURL
def setUrlUpload
def getUrlUpload

Static Public Attributes

tuple security = ClassSecurityInfo()

Detailed Description

Definition at line 60 of file urlupload.py.


Member Function Documentation

Always return the default value since we don't store the url

Definition at line 120 of file urlupload.py.

00120 
00121     def getUrlUpload(self, **kwargs):
00122         """Always return the default value since we don't store the url
00123         """
00124         return self.getField('urlUpload').default
00125 
00126 InitializeClass(URLUpload)

Here is the call graph for this function:

def ATContentTypes.lib.urlupload.URLUpload.loadFileFromURL (   self,
  url,
  contenttypes = () 
)
Loads a file from an url using urllib2

You can use contenttypes to restrict uploaded content types like:
    ('image',) for all image content types
    ('image/jpeg', 'image/png') only jpeg and png

May raise an urllib2.URLError based exception or InvalidContentType

returns file_handler, mimetype, filename, size_in_bytes

Definition at line 65 of file urlupload.py.

00065 
00066     def loadFileFromURL(self, url, contenttypes=()):
00067         """Loads a file from an url using urllib2
00068 
00069         You can use contenttypes to restrict uploaded content types like:
00070             ('image',) for all image content types
00071             ('image/jpeg', 'image/png') only jpeg and png
00072 
00073         May raise an urllib2.URLError based exception or InvalidContentType
00074 
00075         returns file_handler, mimetype, filename, size_in_bytes
00076         """
00077         fh = urllib2.urlopen(url)
00078 
00079         info = fh.info()
00080         mimetype = info.get('content-type', 'application/octetstream')
00081         size = info.get('content-length', None)
00082 
00083         # scheme, netloc, path, parameters, query, fragment
00084         path = urlparse.urlparse(fh.geturl())[2]
00085         if path.endswith('/'):
00086             pos = -2
00087         else:
00088             pos = -1
00089         filename = path.split('/')[pos]
00090 
00091         success = False
00092         for ct in contenttypes:
00093             if ct.find('/') == -1:
00094                 if mimetype[:mimetype.find('/')] == ct:
00095                     success = True
00096                     break
00097             else:
00098                 if mimetype == ct:
00099                     success = True
00100                     break
00101         if not contenttypes:
00102             success = True
00103         if not success:
00104             raise InvalidContentType, mimetype
00105 
00106         return fh, mimetype, filename, size

Here is the caller graph for this function:

def ATContentTypes.lib.urlupload.URLUpload.setUrlUpload (   self,
  value,
  kwargs 
)
Upload a file from URL

Definition at line 108 of file urlupload.py.

00108 
00109     def setUrlUpload(self, value, **kwargs):
00110         """Upload a file from URL
00111         """
00112         if not value:
00113             return
00114         # XXX no error catching
00115         fh, mimetype, filename, size = self.loadFileFromURL(value,
00116                                            contenttypes=('image',))
00117         mutator = self.getPrimaryField().getMutator(self)
00118         mutator(fh.read(), mimetype=mimetype, filename=filename)

Here is the call graph for this function:


Member Data Documentation

tuple ATContentTypes.lib.urlupload.URLUpload.security = ClassSecurityInfo() [static]

Definition at line 62 of file urlupload.py.


The documentation for this class was generated from the following file: