コード例 #1
0
def check_pause(current_time):
    """
    Check if pause time has been reached
    Function should only be called if status is STATUS_PAUSED

    Parameters:
        current_time (int): The current epoch time value

    """
    if config.unpausetime < current_time:
        print('Unpause time reached')
        blockparser = BlockParser(config.dns_blockip)
        blockparser.enable_blockling()
        config.status -= STATUS_PAUSED
        config.status += STATUS_ENABLED
        config.unpausetime = 0
コード例 #2
0
ファイル: docbuilder.py プロジェクト: sonyxperiadev/adt
    def parse(self, filename):
        """
        Parses a single file, reading in all available documentation blocks.

        :param filename: Name of the file to document.
        :returns: Reference to the DocBuilder for chaining.
        """
        BlockParser.reset()
        with open(filename, 'r') as f:
            while True:
                block = BlockParser.next_block(filename, f)
                if block is None:
                    break
                else:
                    if block:
                        self._blocks.append(block)
        return self
コード例 #3
0
def change_status():
    """

    """
    print('Changing status of NoTrack')

    blockparser = BlockParser(config.dns_blockip)

    if config.status & STATUS_ENABLED:
        blockparser.enable_blockling()
    else:
        blockparser.disable_blocking()
コード例 #4
0
def blocklist_update():
    """
    Once a day update of the NoTrack blocklists
    """
    print('Updating Blocklist')

    blockparser = BlockParser(config.dns_blockip)
    blockparser.load_blconfig()
    blockparser.create_blocklist()  #Create / Update Blocklists
    time.sleep(6)  #Prevent race condition
    ntrkparser.readblocklist()  #Reload the blocklist on the log parser
    set_lastrun_times()
コード例 #5
0
def build_block_parser(md_instance, **kwargs):
    """ Build the default block parser used by Markdown. """
    parser = BlockParser(md_instance)
    parser.blockprocessors["empty"] = EmptyBlockProcessor(parser)
    parser.blockprocessors["indent"] = ListIndentProcessor(parser)
    parser.blockprocessors["code"] = CodeBlockProcessor(parser)
    parser.blockprocessors["hashheader"] = HashHeaderProcessor(parser)
    parser.blockprocessors["setextheader"] = SetextHeaderProcessor(parser)
    parser.blockprocessors["hr"] = HRProcessor(parser)
    parser.blockprocessors["olist"] = OListProcessor(parser)
    parser.blockprocessors["ulist"] = UListProcessor(parser)
    parser.blockprocessors["quote"] = BlockQuoteProcessor(parser)
    parser.blockprocessors["paragraph"] = ParagraphProcessor(parser)
    return parser
コード例 #6
0
def build_block_parser(md_instance, **kwargs):
    """ Build the default block parser used by Markdown. """
    parser = BlockParser(md_instance)
    parser.blockprocessors['empty'] = EmptyBlockProcessor(parser)
    parser.blockprocessors['indent'] = ListIndentProcessor(parser)
    parser.blockprocessors['code'] = CodeBlockProcessor(parser)
    parser.blockprocessors['hashheader'] = HashHeaderProcessor(parser)
    parser.blockprocessors['setextheader'] = SetextHeaderProcessor(parser)
    parser.blockprocessors['hr'] = HRProcessor(parser)
    parser.blockprocessors['olist'] = OListProcessor(parser)
    parser.blockprocessors['ulist'] = UListProcessor(parser)
    parser.blockprocessors['quote'] = BlockQuoteProcessor(parser)
    parser.blockprocessors['paragraph'] = ParagraphProcessor(parser)
    return parser
コード例 #7
0
ファイル: blockprocessors.py プロジェクト: connoryang/1v1dec
def build_block_parser(md_instance, **kwargs):
    parser = BlockParser(md_instance)
    parser.blockprocessors['empty'] = EmptyBlockProcessor(parser)
    parser.blockprocessors['indent'] = ListIndentProcessor(parser)
    parser.blockprocessors['code'] = CodeBlockProcessor(parser)
    parser.blockprocessors['hashheader'] = HashHeaderProcessor(parser)
    parser.blockprocessors['setextheader'] = SetextHeaderProcessor(parser)
    parser.blockprocessors['hr'] = HRProcessor(parser)
    parser.blockprocessors['olist'] = OListProcessor(parser)
    parser.blockprocessors['ulist'] = UListProcessor(parser)
    parser.blockprocessors['quote'] = BlockQuoteProcessor(parser)
    parser.blockprocessors['paragraph'] = ParagraphProcessor(parser)
    return parser
コード例 #8
0
ファイル: main.py プロジェクト: TimTosi/spelunker
import clusterizer.Clusterizer as Clusterizer


def initConfig():
    if os.path.isfile("./config.ini") != True:
        print "config.ini missing."
        return False
    config = ConfigParser.ConfigParser()
    config.read("./config.ini")
    settings = {}
    dirName = config.get("Config", "dataDirectory")
    settings["dirList"] = sorted(glob.glob(''.join([dirName, "blk*.dat"])))
    databaseName = config.get("Config", "databaseName")
    userName = config.get("Config", "userName")
    userPassword = config.get("Config", "userPassword")
    if not databaseName or not userName:
        print "Error: Database name or User Name is missing."
        exit()
    settings["dbCredentials"] = "dbname='%s' user='******' password='******'" % (
        databaseName, userName, userPassword)
    return settings


if __name__ == '__main__':
    settings = initConfig()
    db = DatabaseWrapper.DatabaseWrapper(settings["dbCredentials"])
    db.setDatabaseEnv()
    parser = BlockParser.BlockParser(db, settings)
    parser.parse()
    clusterizer = Clusterizer.Clusterizer(db)
    clusterizer.clusterize()
コード例 #9
0
 def __init__(self, file_name):
     # имя файла
     self.file_name = file_name
     # данные в файле
     self.__parser = BlockParser()
コード例 #10
0
class FileOperator:
    def __init__(self, file_name):
        # имя файла
        self.file_name = file_name
        # данные в файле
        self.__parser = BlockParser()

    def load_encrypted_file_into_memory(self, key=None):
        """
        Загружает данные из файла в парсер
        если Key - не None, то перед этим происходит дешифровка
        считанных данных по этому ключу
        :param key: Ключ шифрования
        """
        with open(self.file_name, 'rb') as f:
            operational_data = bytearray(f.read())
        if key is not None:
            current_encryptor = Encryptor(key)
            for pointer in range(int(len(operational_data) / 8)):
                operational_data[pointer * 8:pointer * 8 +
                                 8] = current_encryptor.encrypt_decrypt_block(
                                     operational_data[pointer * 8:pointer * 8 +
                                                      8])
        self.__parser.load_array(operational_data)

    def load_data_into_file(self, key=None):
        """
        Загружает данные из парсера в файл.
        Если key - не None, то данные перед этим шифруются
        :param key:  Ключ шифрования
        """
        if key is not None:
            self.__encrypt_decrypt_data_in_memory(key)
        result = self.__parser.get_result()
        with open(self.file_name, 'wb') as f:
            for line in result:
                for block in line:
                    f.write(block)

    def add_line_to_memory(self, line):
        """
        Записывает строку в парсер
        :param line:  записываемая строка
        """
        self.__parser.parse_line(line)

    def get_data_from_memory(self):
        """
        Считывает весь массив байтов в парсере
        :return: массив байтов
        """
        return self.__parser.get_result()

    def __encrypt_decrypt_data_in_memory(self, key):
        """
        По ключу зашифровывает данные в парсере
        :param key: Ключ шифрования
        """
        current_encryptor = Encryptor(key)
        current_encryptor.drop_key_pointer()
        data_snapshot = self.__parser.get_result()
        for line_num, line in enumerate(data_snapshot):
            for block_num, block in enumerate(line):
                self.__parser.replace_block(
                    line_num, block_num,
                    current_encryptor.encrypt_decrypt_block(block))

    def extract_readable_data(self):
        """
        Удаляет все данные из блоков, возвращая их в пригодном для использования виде
        :return: список строк
        """
        result_list = list()
        dp_line = self.__parser.rebuild_line()
        while dp_line is not None:
            result_list.append(dp_line)
            dp_line = self.__parser.rebuild_line()
        return result_list