Ejemplo n.º 1
0
 def load(self):
     """load from self.config_fname into self.config_data
     if the file does not exist, create a new config_data
     """
     if not os.path.isfile(self.config_fname):
         nr_proxies = len(self.proxy_list)
         self.config_data = {'users_set': set(),
                             'proxy_list': self.proxy_list}
     else:
         self.config_data = util.file_pickle_load(self.config_fname)
         for p in self.proxy_list:
             found = False
             for c in self.config_data['proxy_list']:
                 if p.filename == c.filename:
                     found = True
             if not found:
                 self.config_data['proxy_list'].append(p)
     return
Ejemplo n.º 2
0
    def load(self, raise_on_error=False):
        try:
            # using it only for convenience (expiration, ... not used)
            data = util.file_pickle_load(self.fname)
        except:
            if raise_on_error:
                raise
            else:
                # default to empty history on error
                data = {}

        if type(data) != type({}):
            if raise_on_error:
                raise TypeError("History object not a dictionary: %s" % str(type(data)))
            else:
                # default to empty history on error
                data = {}

        self.data = data
Ejemplo n.º 3
0
 def load(self):
     """load from self.config_fname into self.config_data
     if the file does not exist, create a new config_data
     """
     if not os.path.isfile(self.config_fname):
         nr_proxies = len(self.proxy_list)
         self.config_data = {
             'users_set': set(),
             'proxy_list': self.proxy_list
         }
     else:
         self.config_data = util.file_pickle_load(self.config_fname)
         for p in self.proxy_list:
             found = False
             for c in self.config_data['proxy_list']:
                 if p.filename == c.filename:
                     found = True
             if not found:
                 self.config_data['proxy_list'].append(p)
     return
Ejemplo n.º 4
0
    def load(self, raise_on_error=False):
        try:
            # using it only for convenience (expiration, ... not used)
            data = util.file_pickle_load(self.fname)
        except:
            if raise_on_error:
                raise
            else:
                # default to empty history on error
                data = {}

        if not isinstance(data, dict):
            if raise_on_error:
                raise TypeError("History object not a dictionary: %s" %
                                str(type(data)))
            else:
                # default to empty history on error
                data = {}

        self.data = data
Ejemplo n.º 5
0
    def load(self):
        if not os.path.exists(self.config_fname):
            # no cache, create new cache structure from scratch
            self.config_data = {}
            user_map = {}
            self.config_data['first_free_index'] = 0
            nr_proxies = len(self.proxy_list)
            for i in range(nr_proxies):
                # use numbers for keys, so we are sure will not match to any user string
                self.add_proxy(user_map, self.proxy_list[i])
            self.config_data['user_map'] = user_map
        else:
            # load cache
            self.config_data = util.file_pickle_load(self.config_fname)

            # if proxies changed, remove old ones and insert the new ones
            cached_proxies = set(
            )  # here we will store the list of proxies in the cache

            user_map = self.config_data['user_map']

            # need to iterate, since not indexed by proxy name
            keys = user_map.keys()
            for type in user_map.keys():
                for trust_domain in user_map[type].keys():
                    for k in user_map[type][trust_domain].keys():
                        el = user_map[type][trust_domain][k]
                        el_proxy = el['proxy']
                        el_proxyname = el['proxy'].filename
                        found = False
                        for p in self.proxy_list:
                            if (p.filename == el_proxyname):
                                cached_proxies.add(el_proxyname)
                                found = True
                        if not found:
                            # cached proxy not used anymore... remove from cache
                            del user_map[type][trust_domain][k]
            for proxy in self.proxy_list:
                if proxy.filename not in cached_proxies:
                    self.add_proxy(user_map, proxy)
        return
Ejemplo n.º 6
0
    def load(self):
        if not os.path.exists(self.config_fname):
            # no cache, create new cache structure from scratch
            self.config_data = {}
            user_map = {}
            self.config_data['first_free_index'] = 0
            nr_proxies = len(self.proxy_list)
            for i in range(nr_proxies):
                # use numbers for keys, so we are sure will not match to any user string
                self.add_proxy(user_map,self.proxy_list[i]) 
            self.config_data['user_map'] = user_map
        else:
            # load cache
            self.config_data = util.file_pickle_load(self.config_fname)

            # if proxies changed, remove old ones and insert the new ones
            cached_proxies = set() # here we will store the list of proxies in the cache

            user_map = self.config_data['user_map']

            # need to iterate, since not indexed by proxy name
            keys = user_map.keys()
            for type in user_map.keys():
                for trust_domain in user_map[type].keys():
                    for k in user_map[type][trust_domain].keys():
                        el = user_map[type][trust_domain][k]
                        el_proxy = el['proxy']
                        el_proxyname = el['proxy'].filename
                        found=False
                        for p in self.proxy_list:
                            if (p.filename == el_proxyname):
                                cached_proxies.add(el_proxyname)
                                found=True
                        if not found:
                            # cached proxy not used anymore... remove from cache
                            del user_map[type][trust_domain][k]
            for proxy in self.proxy_list:
                if proxy.filename not in cached_proxies:
                    self.add_proxy(user_map,proxy) 
        return