Skip to content
Browse files

Fixed OperationalError with non-latin1 characters

  • Loading branch information...
1 parent 424c8ff commit d49041bffa7598289f54c9301f09e89df5ab856a @caio committed
Showing with 18 additions and 7 deletions.
  1. +18 −7 cookiepot.py
View
25 cookiepot.py
@@ -1,5 +1,4 @@
#!/usr/bin/python
-# -*- coding: utf-8 -*-
import cookielib
import os
@@ -11,14 +10,17 @@
class CookiePot(object):
- """The CookiePot class centralizes methods to extract cookie info from
+ """Cookie Extration Class.
+
+ The CookiePot class centralizes methods to extract cookie info from
the most common web browsers out there.
"""
def __init__(self, domain_pattern=''):
"""Contructor.
- If desired, `default_pattern` may be given to fetch only cookies from
- a specific domain.
+
+ If desired, `default_pattern` may be given to fetch only cookies
+ from a specific domain.
"""
self.pattern = domain_pattern
@@ -51,7 +53,10 @@ def _profile_walker(self, path, filename):
def seamonkey_cookies(self, pattern=None, path='~/.mozilla/default',
cookie_file='cookies.txt'):
- """Fetches cookies stored on SeaMonkey profiles in the user home.
+ """Gets cookies from the SeaMonkey browser.
+
+ Fetches cookies stored on SeaMonkey profiles in the user
+ homedir.
"""
if pattern is None:
pattern = self.pattern
@@ -90,6 +95,7 @@ def firefox_cookies(self, pattern=None, path='~/.mozilla/firefox',
cookies = []
for db in self._profile_walker(base_path, cookie_file):
connection = sqlite3.connect(db, timeout=1)
+ connection.text_factory = str
cursor = connection.cursor()
try:
cursor.execute(operation, [match])
@@ -105,6 +111,7 @@ def firefox_cookies(self, pattern=None, path='~/.mozilla/firefox',
tmp.seek(0)
database_file.close()
connection = sqlite3.connect(tmp.name)
+ connection.text_factory = str
cursor = connection.cursor()
cursor.execute(operation, [match])
tmp.close() # }}}
@@ -125,7 +132,9 @@ def firefox_cookies(self, pattern=None, path='~/.mozilla/firefox',
def get_cookies(self, pattern=None):
- """Returns every available cookie from CookiePot's known sources.
+ """Fetches cookies from all browsers.
+
+ Returns every available cookie from CookiePot's known sources.
"""
if pattern is None:
pattern = self.pattern
@@ -140,7 +149,9 @@ def get_cookies(self, pattern=None):
def make_lwp_cookiejar(self, filename=None, pattern=None):
- """Creates a `LWPCookieJar` object with every known cookie.
+ """Returns a LTPCookieJar with cookies set.
+
+ Creates a `LWPCookieJar` object with every known cookie.
The `filename` parameter is used for the cookiejar creation and is
relative to the cwd, if set.
"""

0 comments on commit d49041b

Please sign in to comment.
Something went wrong with that request. Please try again.