Changeset 9370:aeeeaea6690e in orange


Ignore:
Timestamp:
12/16/11 13:51:57 (2 years ago)
Author:
ales_erjavec <ales.erjavec@…>
Branch:
default
Convert:
4d297c0fe1e35eb7c82a241881dc28fcc4109d95
Message:

Removed urllib2_file.py. Using 'poster' for file uploading in serverfiles'

Location:
orange
Files:
1 deleted
1 edited

Legend:

Unmodified
Added
Removed
  • orange/Orange/misc/serverfiles.py

    r9349 r9370  
    118118socket.setdefaulttimeout(timeout) 
    119119 
     120import urllib 
    120121import urllib2 
    121122import base64 
    122  
    123 import urllib2_file  
    124 #switch to poster in the future 
    125 #import poster.streaminghttp as psh 
    126 #import poster.encode 
    127123 
    128124from orngMisc import ConsoleProgressBar 
     
    231227        self.searchinfo = None 
    232228 
    233     def _getOpener(self): 
    234         #commented lines are for poster 0.6 
    235         #handlers = [psh.StreamingHTTPHandler, psh.StreamingHTTPRedirectHandler, psh.StreamingHTTPSHandler] 
    236         #opener = urllib2.build_opener(*handlers) 
     229    def _getOpener(self, multipart=False): 
    237230        opener = urllib2.build_opener() 
    238231        return opener 
     
    392385        def do(): 
    393386            opener = self._getOpener() 
    394             #the next lines work for poster 0.6.0 
    395             #datagen, headers = poster.encode.multipart_encode(data) 
    396             #request = urllib2.Request(root+command, datagen, headers) 
    397  
     387             
    398388            if data: 
    399                 request = urllib2.Request(root+command, data) 
     389                if command == "upload": 
     390                    # Need to use poster to handle multipart post 
     391                    try: 
     392                        import poster.streaminghttp as psh 
     393                        import poster.encode 
     394                    except ImportError: 
     395                        raise ImportError("You need to install 'poster' (http://pypi.python.org/pypi/poster) to be able to upload files.") 
     396                 
     397                    handlers = [psh.StreamingHTTPHandler, psh.StreamingHTTPRedirectHandler, psh.StreamingHTTPSHandler] 
     398                    opener = urllib2.build_opener(*handlers) 
     399                    datagen, headers = poster.encode.multipart_encode(data) 
     400                    request = urllib2.Request(root+command, datagen, headers) 
     401                else: 
     402                    request = urllib2.Request(root+command, urllib.urlencode(data)) 
    400403            else: 
    401404                request = urllib2.Request(root+command) 
     
    407410             
    408411            return opener.open(request) 
     412                 
    409413        if repeat <= 0: 
    410414            return do() 
Note: See TracChangeset for help on using the changeset viewer.