Logo Search packages:      
Sourcecode: gallery-uploader version File versions  Download package

def guplib::gallery::Gallery::request (   self,
  command,
  version,
  arguments,
  file_info = None 
)

Send a request to the remote server. Returns a dictionary with
the resulting variables.

command - the command to be send
version - command version
arguments - dictionary with the arguments to the command
file_info - a tuple with the field name and the filename to be added
  in the body

Definition at line 198 of file gallery.py.

00198                                                                     :
        '''Send a request to the remote server. Returns a dictionary with
        the resulting variables.

        command - the command to be send
        version - command version
        arguments - dictionary with the arguments to the command
        file_info - a tuple with the field name and the filename to be added
          in the body'''
        if not self.logged and not command == 'login':
            # hate those hardcoded options
            self.login()

        logging.debug('Opening request with "%s"', self.url)
        boundary = '------GUP_Boundary'

        # those are the default fields
        data = {
                'g2_controller'            : 'remote:GalleryRemote',
                'g2_form[cmd]'             : command,
                'g2_form[protocol_version]': str(version),
                'g2_authToken'             : self.last_authtoken
                }
        data.update(arguments)

        request = urllib2.Request(self.url)
        request.add_header('User-agent', 'GUP %s' % (__revision__))
        request.add_header('Content-type', 
                'multipart/form-data; boundary=%s' % boundary)
        request.add_header('Accept', 'text/plain')
        if self.cookie is not None:
            self.cookie.add_cookie_header(request)
        else:
            cookiejar = cookielib.CookieJar()
            cookie_opener = urllib2.build_opener(
                    urllib2.HTTPCookieProcessor(cookiejar))
            urllib2.install_opener(cookie_opener)

        request.add_data(_multipart(boundary, data, file_info))

        response = urllib2.urlopen(request)

        if self.cookie is None:
            self.cookie = cookiejar

        data = response.read()
        logging.debug('== DATA ==')
        logging.debug(data)
        logging.debug('== /DATA ==')

        status = 0
        return_value = []

        for line in data.split('\n'):
            if len(line) == 0:
                continue

            if line[0] == '#':
                continue

            values = line.split('=')
            if len(values) < 2:
                continue

            if values[0] == 'status':
                status = int(values[1])
            elif values[0] == 'auth_token':
                self.last_authtoken = values[1]

            return_value.append( (values[0], values[1]) )

        return (status, return_value)

    def login(self):


Generated by  Doxygen 1.6.0   Back to index