# Path: xclib/utf8.py
# def unutf8(u, opts='strict'):
#     if opts == 'illegal':
#         try:
#             return u.decode('utf-8', 'strict')
#         except UnicodeError:
#             dec = u.decode('utf-8', 'ignore')
#             logging.error('Illegal UTF-8 sequence: %r' % dec)
#             sys.stderr.write('Illegal UTF-8 sequence: %r\n' % dec)
#             traceback.print_exc()
#             return 'illegal-utf8-sequence-' + dec
#     else:
#         return u.decode('utf-8', opts)


import bsddb3
import sqlite3
import os
import time
import logging
from datetime import datetime
from xclib.utf8 import unutf8
                     VALUES (?, ?, ?, ?, ?)''', (k, pwhash, ts1, tsv, tsa))
            if isinstance(olddb, str):
                db.close()
        except bsddb3.db.DBError as e:
            logging.error('Trouble converting %s: %s' % (olddb, e))

    def db_upgrade_roster(self, olddb):
        logging.debug('Upgrading roster from %s' % olddb)
        try:
            self.conn.execute('''CREATE TABLE rosterinfo
                          (jid          TEXT PRIMARY KEY,
                           fullname     TEXT,
                           grouplist    TEXT,
                           responsehash TEXT,
                           last_update  TIMESTAMP DEFAULT CURRENT_TIMESTAMP)''')
        except sqlite3.OperationalError as e:
            logging.warning('Cannot create `domains` table; maybe multiple processes started in parallel? %s' % str(e))
            # Try to get out of the way of a parallel updater
            time.sleep(1)
            # Continue, in case a previous table creation was aborted
        try:
            self.conn.execute('''CREATE TABLE rostergroups
                          (groupname    TEXT PRIMARY KEY,
                           userlist     TEXT)''')
        except sqlite3.OperationalError as e:
            logging.warning('Cannot create `domains` table; maybe multiple processes started in parallel? %s' % str(e))
            # Try to get out of the way of a parallel updater
            time.sleep(1)
            # Someone else already created the table; he probably also
            # migrated it

# Path: xclib/utf8.py
# def unutf8(u, opts='strict'):
#     if opts == 'illegal':
#         try:
#             return u.decode('utf-8', 'strict')
#         except UnicodeError:
#             dec = u.decode('utf-8', 'ignore')
#             logging.error('Illegal UTF-8 sequence: %r' % dec)
#             sys.stderr.write('Illegal UTF-8 sequence: %r\n' % dec)
#             traceback.print_exc()
#             return 'illegal-utf8-sequence-' + dec
#     else:
#         return u.decode('utf-8', opts)


# Path: xclib/db.py
import bsddb3
import sqlite3
import os
import time
import logging
from datetime import datetime
from xclib.utf8 import unutf8

                     VALUES (?, ?, ?, ?, ?)''', (k, pwhash, ts1, tsv, tsa))
            if isinstance(olddb, str):
                db.close()
        except bsddb3.db.DBError as e:
            logging.error('Trouble converting %s: %s' % (olddb, e))

    def db_upgrade_roster(self, olddb):
        logging.debug('Upgrading roster from %s' % olddb)
        try:
            self.conn.execute('''CREATE TABLE rosterinfo
                          (jid          TEXT PRIMARY KEY,
                           fullname     TEXT,
                           grouplist    TEXT,
                           responsehash TEXT,
                           last_update  TIMESTAMP DEFAULT CURRENT_TIMESTAMP)''')
        except sqlite3.OperationalError as e:
            logging.warning('Cannot create `domains` table; maybe multiple processes started in parallel? %s' % str(e))
            # Try to get out of the way of a parallel updater
            time.sleep(1)
            # Continue, in case a previous table creation was aborted
        try:
            self.conn.execute('''CREATE TABLE rostergroups
                          (groupname    TEXT PRIMARY KEY,
                           userlist     TEXT)''')
        except sqlite3.OperationalError as e:
            logging.warning('Cannot create `domains` table; maybe multiple processes started in parallel? %s' % str(e))
            # Try to get out of the way of a parallel updater
            time.sleep(1)
            # Someone else already created the table; he probably also
            # migrated it

            return