Exemple #1
0
 def file(self, name=None, ignoreCase=0):
     "Return POSTed file(s)"
     self._postInit()
     if ignoreCase:
         if name: name = string.lower(name)
         return spyceUtil.extractValue(self._fileL, name)
     else:
         return spyceUtil.extractValue(self._file, name)
Exemple #2
0
 def file(self, name=None, ignoreCase=0):
   "Return POSTed file(s)"
   self._postInit()
   if ignoreCase:
     if name: name = string.lower(name)
     return spyceUtil.extractValue(self._fileL, name)
   else:
     return spyceUtil.extractValue(self._file, name)
Exemple #3
0
 def post(self, name=None, default=None, ignoreCase=0):
     "Return POST parameter(s) list(s)"
     self._postInit()
     if ignoreCase:
         if name: name = string.lower(name)
         value = spyceUtil.extractValue(self._postL, name)
     else:
         value = spyceUtil.extractValue(self._post, name)
     return self.default(value, default)
Exemple #4
0
 def post(self, name=None, default=None, ignoreCase=0):
   "Return POST parameter(s) list(s)"
   self._postInit()
   if ignoreCase:
     if name: name = string.lower(name)
     value = spyceUtil.extractValue(self._postL, name)
   else:
     value = spyceUtil.extractValue(self._post, name)
   return self.default(value, default)
Exemple #5
0
 def get1(self, name=None, default=None, ignoreCase=0):
   "Return single GET parameter(s)"
   self._getInit()
   if ignoreCase:
     if name: name = string.lower(name)
     value = spyceUtil.extractValue(self._getL1, name)
   else:
     value = spyceUtil.extractValue(self._get1, name)
   return self.default(value, default)
Exemple #6
0
 def get1(self, name=None, default=None, ignoreCase=0):
     "Return single GET parameter(s)"
     self._getInit()
     if ignoreCase:
         if name: name = string.lower(name)
         value = spyceUtil.extractValue(self._getL1, name)
     else:
         value = spyceUtil.extractValue(self._get1, name)
     return self.default(value, default)
Exemple #7
0
 def sendHeaders(self):
     if self._httpheader and not self.headersSent:
         resultText = spyceUtil.extractValue(self.RETURN_CODE,
                                             self.returncode)
         self.origout.write('%s %s %s\n' %
                            (self._httpdHandler.request_version,
                             self.returncode, resultText))
         spyceCmd.spyceCmdlineResponse.sendHeaders(self)
Exemple #8
0
 def sendHeaders(self):
   if self.cgimode and not self.headersSent:
     resultText = spyceUtil.extractValue(self.RETURN_CODE, self.returncode)
     self.origout.write('Status: %3d "%s"\n' % (self.returncode, resultText))
     if not self.CT:
       self.setContentType('text/html')
     self.origout.write('Content-Type: %s\n' % self.CT)
     for h in self.headers:
       self.origout.write('%s: %s\n'%h)
     self.origout.write('\n')
     self.headersSent = 1
Exemple #9
0
 def sendHeaders(self):
     if self.cgimode and not self.headersSent:
         resultText = spyceUtil.extractValue(self.RETURN_CODE,
                                             self.returncode)
         self.origout.write('Status: %3d "%s"\n' %
                            (self.returncode, resultText))
         if not self.CT:
             self.setContentType('text/html')
         self.origout.write('Content-Type: %s\n' % self.CT)
         for h in self.headers:
             self.origout.write('%s: %s\n' % h)
         self.origout.write('\n')
         self.headersSent = 1
Exemple #10
0
 def env(self, name=None):
   if not self._env:
     self._env = {
       'REMOTE_ADDR': self._httpdHandler.client_address[0],
       'REMOTE_PORT': self._httpdHandler.client_address[1],
       'GATEWAY_INTERFACE': "CGI/1.1",
       'REQUEST_METHOD': self._httpdHandler.command,
       'REQUEST_URI': self._httpdHandler.path,
       'PATH_INFO': self._httpdHandler.pathinfo,
       'SERVER_SOFTWARE': 'spyce/%s' % spyce.__version__,
       'SERVER_PROTOCOL': self._httpdHandler.request_version,
       # 'SERVER_ADDR' ... '127.0.0.1'
       # 'SERVER_PORT' ... '80'
       # 'SERVER_NAME' ... 'mymachine.mydomain.com'
       # 'SERVER_SIGNATURE' ... ' Apache/1.3.22 Server at mymachine.mydomain.com Port 80'
       # 'SERVER_ADMIN'] ... '*****@*****.**'
       'DOCUMENT_ROOT': self._documentRoot,
       'QUERY_STRING': 
         string.join(string.split(self._httpdHandler.path, '?')[1:]) or '',
       'CONTENT_LENGTH': self.getHeader('Content-Length'),
       'CONTENT_TYPE': self.getHeader('Content-type'),
       'HTTP_USER_AGENT': self.getHeader('User-Agent'),
       'HTTP_ACCEPT': self.getHeader('Accept'),
       'HTTP_ACCEPT_ENCODING': self.getHeader('Accept-Encoding'),
       'HTTP_ACCEPT_LANGUAGE': self.getHeader('Accept-Language'),
       'HTTP_ACCEPT_CHARSET': self.getHeader('Accept-Charset'),
       'HTTP_COOKIE': self.getHeader('Cookie'),
       'HTTP_REFERER': self.getHeader('Referer'),
       'HTTP_HOST': self.getHeader('Host'),
       'HTTP_CONNECTION': self.getHeader('Connection'),
       'HTTP_KEEP_ALIVE': self.getHeader('Keep-alive'),
       # From ASP
       # AUTH_TYPE, 
       # APPL_PHYSICAL_PATH, 
       # REMOTE_HOST,
       # SERVER_PROTOCOL, 
       # SERVER_SOFWARE
     }
   return spyceUtil.extractValue(self._env, name)
Exemple #11
0
 def env(self, name=None):
     return spyceUtil.extractValue(self._in.subprocess_env, name)
Exemple #12
0
 def env(self, name=None):
     return spyceUtil.extractValue(self._env, name)
Exemple #13
0
 def getHeader(self, type=None):
   return spyceUtil.extractValue(self._headers, type)
Exemple #14
0
 def env(self, name=None):
   return spyceUtil.extractValue(self._env, name)
Exemple #15
0
 def getHeader(self, type=None):
   if type: type=string.lower(type)
   return spyceUtil.extractValue(self._headers.dict, type)
Exemple #16
0
 def getHeader(self, type=None):
     if type: type = string.lower(type)
     return spyceUtil.extractValue(self._headers.dict, type)
Exemple #17
0
 def sendHeaders(self):
   if self._httpheader and not self.headersSent:
     resultText = spyceUtil.extractValue(self.RETURN_CODE, self.returncode)
     self.origout.write('%s %s %s\n' % (self._httpdHandler.request_version, self.returncode, resultText))
     spyceCmd.spyceCmdlineResponse.sendHeaders(self)
Exemple #18
0
 def processDirective(self):
     # collect directive
     begin = self._tokenBegin
     self.popToken()
     directive = ''
     while self._tokenType not in [T_END, T_EOF]:
         if self._tokenType == T_TEXT:
             directive = directive + self._tokenText
         else:
             self.processUnexpected()
         end = self._tokenEnd
         self.popToken()
     directive = string.strip(directive)
     if not directive: self.processUnexpected()
     # process directives
     name, attrs = parseDirective(directive)
     if name == 'compact':
         compact_mode = COMPACT_FULL
         if attrs.has_key('mode'):
             mode = string.lower(attrs['mode'])
             if mode == 'off':
                 compact_mode = COMPACT_OFF
             elif mode == 'line':
                 compact_mode = COMPACT_LINE
             elif mode == 'space':
                 compact_mode = COMPACT_SPACE
             elif mode == 'full':
                 compact_mode = COMPACT_FULL
             else:
                 raise spyceException.spyceSyntaxError(
                     'invalid compacting mode "%s" specified' % mode,
                     (begin, end, directive, self._curfile))
         self._ast.addCompact(
             compact_mode,
             (begin, end, '<spyce compact directive>', self._curfile))
     elif name in ('module', 'import'):
         if not attrs.has_key('name') and not attrs.has_key('names'):
             raise spyceException.spyceSyntaxError(
                 'name or names attribute required',
                 (begin, end, directive, self._curfile))
         if attrs.has_key('names'):
             mod_names = filter(
                 None, map(string.strip, string.split(attrs['names'], ',')))
             for mod_name in mod_names:
                 self._ast.addModule(mod_name, None, None)
                 self._ast.addCode('%s.init()' % mod_name,
                                   (begin, end, directive, self._curfile))
         else:
             mod_name = attrs['name']
             mod_from = spyceUtil.extractValue(attrs, 'from')
             mod_as = spyceUtil.extractValue(attrs, 'as')
             mod_args = spyceUtil.extractValue(attrs, 'args', '')
             if mod_as: theName = mod_as
             else: theName = mod_name
             self._ast.addModule(mod_name, mod_from, mod_as)
             self._ast.addCode('%s.init(%s)' % (theName, mod_args),
                               (begin, end, directive, self._curfile))
     elif name in ('taglib', ):
         if not attrs.has_key('name') and not attrs.has_key('names'):
             raise spyceException.spyceSyntaxError(
                 'name or names attribute required',
                 (begin, end, directive, self._curfile))
         fullfile = os.path.join(self._curdir, self._curfile)
         if attrs.has_key('names'):
             taglib_names = filter(
                 None, map(string.strip, string.split(attrs['names'], ',')))
             for taglib_name in taglib_names:
                 self._tagChecker.loadLib(
                     taglib_name, None, None, fullfile,
                     (begin, end, directive, self._curfile))
                 self._ast.addTaglib(taglib_name)
                 self._load_taglib = 1
                 self._ast.addCode('taglib.load(%s)' % repr(taglib_name),
                                   (begin, end, directive, self._curfile))
         else:
             taglib_name = attrs['name']
             taglib_from = spyceUtil.extractValue(attrs, 'from')
             taglib_as = spyceUtil.extractValue(attrs, 'as')
             self._tagChecker.loadLib(
                 taglib_name, taglib_from, taglib_as, fullfile,
                 (begin, end, directive, self._curfile))
             self._ast.addTaglib(taglib_name, taglib_from, taglib_as)
             self._load_taglib = 1
             self._ast.addCode(
                 'taglib.load(%s, %s, %s)' %
                 (repr(taglib_name), repr(taglib_from), repr(taglib_as)),
                 (begin, end, directive, self._curfile))
     elif name == 'include':
         if not attrs.has_key('file'):
             raise spyceException.spyceSyntaxError(
                 'file attribute missing',
                 (begin, end, directive, self._curfile))
         filename = os.path.join(self._curdir, attrs['file'])
         f = None
         try:
             try:
                 f = open(filename)
                 buf = f.read()
             finally:
                 if f: f.close()
         except KeyboardInterrupt:
             raise
         except:
             raise spyceException.spyceSyntaxError(
                 'unable to open included file: %s' % filename,
                 (begin, end, directive, self._curfile))
         prev = (self._curdir, self._curfile, self._tokens, self._tokenType,
                 self._tokenText, self._tokenBegin, self._tokenEnd)
         self._curdir, self._curfile = os.path.dirname(filename), filename
         self._tokens = spyceTokenize4Parse(processMagic(buf))
         self.popToken()
         self.processSpyce()
         (self._curdir, self._curfile, self._tokens, self._tokenType,
          self._tokenText, self._tokenBegin, self._tokenEnd) = prev
     else:
         raise spyceException.spyceSyntaxError(
             'invalid spyce directive',
             (begin, end, directive, self._curfile))
 def processDirective(self):
   # collect directive
   begin = self._tokenBegin
   self.popToken()
   directive = ''
   while self._tokenType not in [T_END, T_EOF]:
     if self._tokenType==T_TEXT:
       directive = directive + self._tokenText
     else: self.processUnexpected()
     end = self._tokenEnd
     self.popToken()
   directive = string.strip(directive)
   if not directive: self.processUnexpected()
   # process directives
   name, attrs = parseDirective(directive)
   if name=='compact':
     compact_mode = COMPACT_FULL
     if attrs.has_key('mode'):
       mode = string.lower(attrs['mode'])
       if mode=='off':
         compact_mode = COMPACT_OFF
       elif mode=='line':
         compact_mode = COMPACT_LINE
       elif mode=='space':
         compact_mode = COMPACT_SPACE
       elif mode=='full':
         compact_mode = COMPACT_FULL
       else:
         raise spyceException.spyceSyntaxError('invalid compacting mode "%s" specified'%mode, (begin, end, directive, self._curfile))
     self._ast.addCompact(compact_mode, (begin, end, '<spyce compact directive>', self._curfile))
   elif name in ('module', 'import'):
     if not attrs.has_key('name') and not attrs.has_key('names'):
       raise spyceException.spyceSyntaxError('name or names attribute required', (begin, end, directive, self._curfile) )
     if attrs.has_key('names'):
       mod_names = filter(None, map(string.strip, string.split(attrs['names'],',')))
       for mod_name in mod_names:
         self._ast.addModule(mod_name, None, None)
         self._ast.addCode('%s.init()'%mod_name, (begin, end, directive, self._curfile))
     else:
       mod_name = attrs['name']
       mod_from = spyceUtil.extractValue(attrs, 'from')
       mod_as = spyceUtil.extractValue(attrs, 'as')
       mod_args = spyceUtil.extractValue(attrs, 'args', '')
       if mod_as: theName=mod_as
       else: theName=mod_name
       self._ast.addModule(mod_name, mod_from, mod_as)
       self._ast.addCode('%s.init(%s)'%(theName,mod_args), (begin, end, directive, self._curfile))
   elif name in ('taglib',):
     if not attrs.has_key('name') and not attrs.has_key('names'):
       raise spyceException.spyceSyntaxError('name or names attribute required', (begin, end, directive, self._curfile) )
     fullfile = os.path.join(self._curdir, self._curfile)
     if attrs.has_key('names'):
       taglib_names = filter(None, map(string.strip, string.split(attrs['names'],',')))
       for taglib_name in taglib_names:
         self._tagChecker.loadLib(taglib_name, None, None, fullfile, (begin, end, directive, self._curfile))
         self._ast.addTaglib(taglib_name)
         self._load_taglib = 1
         self._ast.addCode('taglib.load(%s)'%repr(taglib_name), (begin, end, directive, self._curfile))
     else:
       taglib_name = attrs['name']
       taglib_from = spyceUtil.extractValue(attrs, 'from')
       taglib_as = spyceUtil.extractValue(attrs, 'as')
       self._tagChecker.loadLib(taglib_name, taglib_from, taglib_as, fullfile, (begin, end, directive, self._curfile))
       self._ast.addTaglib(taglib_name, taglib_from, taglib_as)
       self._load_taglib = 1
       self._ast.addCode('taglib.load(%s, %s, %s)'%(repr(taglib_name), repr(taglib_from), repr(taglib_as)), (begin, end, directive, self._curfile))
   elif name=='include':
     if not attrs.has_key('file'):
       raise spyceException.spyceSyntaxError('file attribute missing', (begin, end, directive, self._curfile) )
     filename = os.path.join(self._curdir, attrs['file'])
     f = None
     try:
       try:
         f = open(filename)
         buf = f.read()
       finally:
         if f: f.close()
     except KeyboardInterrupt: raise
     except:
       raise spyceException.spyceSyntaxError('unable to open included file: %s'%filename, (begin, end, directive, self._curfile) )
     prev = (self._curdir, self._curfile, self._tokens,
       self._tokenType, self._tokenText, self._tokenBegin, self._tokenEnd)
     self._curdir, self._curfile = os.path.dirname(filename), filename
     self._tokens = spyceTokenize4Parse(processMagic(buf))
     self.popToken()
     self.processSpyce()
     (self._curdir, self._curfile, self._tokens,
       self._tokenType, self._tokenText, self._tokenBegin, self._tokenEnd) = prev
   else:
     raise spyceException.spyceSyntaxError('invalid spyce directive', (begin, end, directive, self._curfile) )