Skip to content

Commit

Permalink
fix cache flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesturk committed Jan 22, 2015
1 parent ec2863b commit 9d069f6
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions scrapelib/cache.py
Expand Up @@ -10,10 +10,8 @@
import string
import requests
import sqlite3
try:
import json
except:
import simplejson as json
import json


class CachingSession(requests.Session):
def __init__(self, cache_storage=None):
Expand Down Expand Up @@ -160,7 +158,7 @@ def get(self, orig_key):
# TODO: resp.request = request
return resp
except IOError:
return None
return None

def set(self, key, response):
"""Set cache entry for key with contents of response."""
Expand Down Expand Up @@ -217,7 +215,7 @@ def set(self, key, response):
mod = response.headers.pop('last-modified', None)
status = int(response.status_code)
rec = (key, status, mod, response.encoding, response.content,
json.dumps(dict(response.headers)))
json.dumps(dict(response.headers)))
with self._conn:
self._conn.execute("DELETE FROM cache WHERE key=?", (key, ))
self._conn.execute("INSERT INTO cache VALUES (?,?,?,?,?,?)", rec)
Expand Down Expand Up @@ -250,8 +248,7 @@ def get(self, key):
def clear(self):
"""Remove all records from cache."""
with self._conn:
_ = self._conn.execute('DELETE FROM cache')
self._conn.execute('DELETE FROM cache')

def __del__(self):
self._conn.close()

0 comments on commit 9d069f6

Please sign in to comment.