From f73bcb10a56298d0321d53a03ee160cd91a195f6 Mon Sep 17 00:00:00 2001 From: elijahcapricorn Date: Mon, 8 May 2017 15:13:05 +0300 Subject: [PATCH] shelve.open fails on corrupted files --- resources/proxy/antizapret.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/resources/proxy/antizapret.py b/resources/proxy/antizapret.py index c2e8758..eee5f43 100644 --- a/resources/proxy/antizapret.py +++ b/resources/proxy/antizapret.py @@ -1,10 +1,9 @@ # -*- coding: utf-8 -*- -import os, re, fnmatch, threading, urllib2, time, shelve +import os, re, fnmatch, threading, urllib2, time, shelve, anydbm from contextlib import contextmanager, closing from functions import log, debug, tempdir -LOCKS = {} PAC_URL = "http://antizapret.prostovpn.org/proxy.pac" CACHE_DIR = tempdir() USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36" @@ -20,7 +19,11 @@ def config(): try: CONFIG_LOCK.acquire() filename = os.path.join(CACHE_DIR, "antizapret.pac_config2") - shelf = shelve.open(filename) + try: + shelf = shelve.open(filename) + except anydbm.error: + os.remove(filename) + shelf = shelve.open(filename) created_at = 0 data = {} @@ -108,5 +111,4 @@ def url_get(url, params={}, headers={}, post = None): return data except urllib2.HTTPError as e: log("[antizapret]: HTTP Error(%s): %s" % (e.errno, e.strerror)) - return None - + return None \ No newline at end of file