Example #1
0
    def parse(self, biiresponse):
        if isinstance(self.cell, VirtualCell):
            biiresponse.error("You're trying to parse a virtual file: %s" % self.cell.name)
            return False

        try:
            if self.content.parser is None:
                self.content.parser = parser_factory(self.cell.type, self.cell.name.cell_name)
            if self.content.parser:
                self.content.parse()
                self.cell.hasMain = self.content.parser.has_main_function()
                self.cell.dependencies.update_declarations(self.content.parser.explicit_declarations)
        except Exception as e:
            logger.error(str(e))
            biiresponse.error("Error parsing %s file" % self.cell.name)
Example #2
0
def make_content(brl, lang=BiiType(UNKNOWN), read_file=True):
    '''Reads a test file as binary or systext depending on lang
    Parameters:
        brl: BlockCellName or ID
    '''
    if isinstance(lang, int):
        lang = BiiType(lang)
    binary = lang.is_binary()
    if isinstance(brl, basestring):
        name = '/'.join(brl.split('/')[1:])
        parser = parser_factory(lang, brl.split('/')[-1])
    if read_file:
        blob = Blob(path=testfileutils.file_path(name), is_binary=binary)
    else:
        blob = Blob("Blob example content", is_binary=binary)
    return Content(brl, blob, parser)
Example #3
0
def make_content(brl, lang=BiiType(UNKNOWN), read_file=True):
    '''Reads a test file as binary or systext depending on lang
    Parameters:
        brl: BlockCellName or ID
    '''
    if isinstance(lang, int):
        lang = BiiType(lang)
    binary = lang.is_binary()
    if isinstance(brl, basestring):
        name = '/'.join(brl.split('/')[1:])
        parser = parser_factory(lang, brl.split('/')[-1])
    if read_file:
        blob = Blob(path=testfileutils.file_path(name), is_binary=binary)
    else:
        blob = Blob("Blob example content", is_binary=binary)
    return Content(brl, blob, parser)
Example #4
0
    def parse(self, biiresponse):
        if isinstance(self.cell, VirtualCell):
            biiresponse.error("You're trying to parse a virtual file: %s" %
                              self.cell.name)
            return False

        try:
            if self.content.parser is None:
                self.content.parser = parser_factory(self.cell.type,
                                                     self.cell.name.cell_name)
            if self.content.parser:
                self.content.parse()
                self.cell.hasMain = self.content.parser.has_main_function()
                self.cell.dependencies.update_declarations(
                    self.content.parser.explicit_declarations)
        except Exception as e:
            logger.error(str(e))
            biiresponse.error("Error parsing %s file" % self.cell.name)
Example #5
0
 def _process_leaves(self, virtual_cell, realizations, biiout):
     '''for a virtual cell, creates the leaves if they don't exist
     @param virtual_cell: the cell that serves as base
     @param realizations: a set to add the leaves BlockCellNames
     @param biiout: biiout
     '''
     block_cell_name = virtual_cell.name
     for leave in virtual_cell.resource_leaves:
         realizations.add(leave)
         try:
             cell = self.block_holder[leave.cell_name].cell
         except KeyError:
             #The leave it is pointing does not exist
             biiout.info('%s virtual realization not existing, creating it' % leave)
             cell = SimpleCell(leave)
             cell.type = virtual_cell.type
             content = Content(leave, Blob(""), created=True)
             content.parser = parser_factory(cell.type, cell.name.cell_name)
             self.block_holder.add_resource(Resource(cell, content))
         cell.container = block_cell_name
Example #6
0
def make_variable_content(brl, lang=BiiType(UNKNOWN), up_limit=2048):
    '''Generates a content with variable size, from 0 byte to 2kb. Returns the content'''
    size = random.choice(range(up_limit))
    blob = Blob(generate_text(size), False)
    parser = parser_factory(lang, brl.cell_name)
    return Content(brl, blob, parser)
Example #7
0
def make_too_big_content(brl, lang=BiiType(UNKNOWN)):
    blob_load = load(testfileutils.file_path("limits/largefile.txt"))
    blob = Blob(blob_load, is_binary=True)
    parser = parser_factory(lang, brl.cell_name)
    return Content(brl, blob, parser)
Example #8
0
def make_variable_content(brl, lang=BiiType(UNKNOWN), up_limit=2048):
    '''Generates a content with variable size, from 0 byte to 2kb. Returns the content'''
    size = random.choice(range(up_limit))
    blob = Blob(generate_text(size), False)
    parser = parser_factory(lang, brl.cell_name)
    return Content(brl, blob, parser)
Example #9
0
def make_too_big_content(brl, lang=BiiType(UNKNOWN)):
    blob = Blob(path=testfileutils.file_path("limits/largefile.txt"), is_binary=True)
    parser = parser_factory(lang, brl.cell_name)
    return Content(brl, blob, parser)