Exemplo n.º 1
0
    def __call__(self, handler, target_dir, params, direct):
        scgi = get_scgi()

        # *REMEMBER*: Do not print the 'form'. Python's cgi module will
        # parse the whole file to memory in order to print it, which is
        # certainly an issue for large file uploads.
        #
        # *NOTE*: The functionality is invoked from the constructor!
        #

        if direct:
            environ = scgi.env.copy()
            environ['CTK_hack__target_path'] = target_dir

            # Receive the POST
            form = FieldStorage_Direct(fp=scgi.rfile,
                                       environ=environ,
                                       keep_blank_values=1)

            # Callback
            return handler(form['file'].filename, target_dir,
                           form['file'].filename, params)

        # Upload to a temporal file
        os_fd, target_path = tempfile.mkstemp(prefix='CTK_upload_',
                                              dir=target_dir)

        environ = scgi.env.copy()
        environ['CTK_hack__os_fd'] = str(os_fd)

        form = FieldStorage_Temporal(fp=scgi.rfile,
                                     environ=environ,
                                     keep_blank_values=1)
        return handler(form['file'].filename, target_dir, target_path, params)
Exemplo n.º 2
0
   def __call__ (self, handler, target_dir, params, direct):
       scgi = get_scgi()

       # *REMEMBER*: Do not print the 'form'. Python's cgi module will
       # parse the whole file to memory in order to print it, which is
       # certainly an issue for large file uploads.
       #
       # *NOTE*: The functionality is invoked from the constructor!
       #

       if direct:
           environ = scgi.env.copy()
           environ['CTK_hack__target_path'] = target_dir

           # Receive the POST
           form = FieldStorage_Direct (fp=scgi.rfile, environ=environ, keep_blank_values=1)

           # Callback
           return handler (form['file'].filename, target_dir,
                           form['file'].filename, params)

       # Upload to a temporal file
       os_fd, target_path = tempfile.mkstemp (prefix='CTK_upload_', dir=target_dir)

       environ = scgi.env.copy()
       environ['CTK_hack__os_fd'] = str(os_fd)

       form = FieldStorage_Temporal (fp=scgi.rfile, environ=environ, keep_blank_values=1)
       return handler (form['file'].filename, target_dir, target_path, params)
Exemplo n.º 3
0
    def __init__ (self, host, req, props=None):
        Box.__init__ (self)
        self._url_local = '/proxy_widget_%d' %(self.uniq_id)

        if props:
            self.props = props
        else:
            self.props = {}

        if host == None:
           scgi = get_scgi()
           host = scgi.env['HTTP_HOST']

        self._async = self.props.pop('async', True)
        self.id     = 'proxy%d'%(self.uniq_id)

        # Register the proxy path
        publish (self._url_local, ProxyRequest, host=host, req=req)
Exemplo n.º 4
0
    def __init__ (self, url, props={}):
        Dialog.__init__ (self, props.copy())

        scgi = get_scgi()
        self += Proxy (scgi.env['HTTP_HOST'], url)