Ejemplo n.º 1
0
    def _readFile(self, reparse):
        fp = expandpath(self._filepath)
        file = open(fp, 'rb')
        try:
            data = file.read()
        finally: file.close()

        # parse parameters
        parameters={}
        start = data.find('<dtml-comment>')
        end   = data.find('</dtml-comment>')
        if start==-1 or end==-1 or start>end:
            raise ValueError,'Could not find parameter block'
        block = data[start+14:end]

        for line in block.split('\n'):
            pair = line.split(':',1)
            if len(pair)!=2:
                continue
            parameters[pair[0].strip().lower()]=pair[1].strip()

        # check for required an optional parameters
        try:            
            title =         parameters.get('title','')
            connection_id = parameters.get('connection id',parameters['connection_id'])
            arguments =     parameters.get('arguments','')
            max_rows =      parameters.get('max_rows',1000)
            max_cache =     parameters.get('max_cache',100)
            cache_time =    parameters.get('cache_time',0)            
        except KeyError,e:
            raise ValueError,"The '%s' parameter is required but was not supplied" % e
Ejemplo n.º 2
0
    def _readFile(self, reparse):
        fp = expandpath(self._filepath)
        file = open(fp, 'rb')
        try:
            data = file.read()
        finally:
            file.close()

        # parse parameters
        parameters = {}
        start = data.find('<dtml-comment>')
        end = data.find('</dtml-comment>')
        if start == -1 or end == -1 or start > end:
            raise ValueError, 'Could not find parameter block'
        block = data[start + 14:end]

        for line in block.split('\n'):
            pair = line.split(':', 1)
            if len(pair) != 2:
                continue
            parameters[pair[0].strip().lower()] = pair[1].strip()

        # check for required an optional parameters
        try:
            title = parameters.get('title', '')
            connection_id = parameters.get('connection id',
                                           parameters['connection_id'])
            arguments = parameters.get('arguments', '')
            max_rows = parameters.get('max_rows', 1000)
            max_cache = parameters.get('max_cache', 100)
            cache_time = parameters.get('cache_time', 0)
        except KeyError, e:
            raise ValueError, "The '%s' parameter is required but was not supplied" % e
Ejemplo n.º 3
0
 def _readFile(self, reparse):
     fp = expandpath(self._filepath)
     file = open(fp, 'rb')
     try:
         data = file.read()
     finally:
         file.close()
     self.write(data)
Ejemplo n.º 4
0
 def _readFile(self, reparse):
     fp = expandpath(self._filepath)
     file = open(fp, 'r')  # not 'rb', as this is a text file!
     try:
         data = file.read()
     finally:
         file.close()
     if reparse:
         try:
             del self.content_type
         except (AttributeError, KeyError):
             pass
         self.write(data)
     self._readMetadata()
Ejemplo n.º 5
0
    def _readMetadata(self):
        # re-read .metadata file if it exists
        e_fp = expandpath(self._filepath) + '.metadata'
        if os.path.exists(e_fp):

            # XXX I can't get this to work with FSMetdata
            # so I will do it manually >:(

            metadata = file(e_fp)
            for line in metadata:
                try:
                    k, v = line.replace('\n', '').split('=')
                    if k.strip() == 'value_paths':
                        value_paths = [p.strip() for p in v.split(',')]
                except:
                    pass

            self.value_paths = value_paths
Ejemplo n.º 6
0
 def _readFile(self, reparse):
     fp = expandpath(self._filepath)
     file = open(fp, 'rb')
     try: data = file.read()
     finally: file.close()
     self.write(data)