# 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
        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

        rosterinfo_fn = {}
        rosterinfo_rh = {}
        rosterinfo_lg = {}
        rosterusers = set([])
        rostergroups = {}
        try:
            if olddb is None:
                return
            elif isinstance(olddb, str):
                db = bsddb3.hashopen(olddb, 'r')
            else: # dict
                db = olddb
            for k,v in db.items():

# 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

        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

        rosterinfo_fn = {}
        rosterinfo_rh = {}
        rosterinfo_lg = {}
        rosterusers = set([])
        rostergroups = {}
        try:
            if olddb is None:
                return
            elif isinstance(olddb, str):
                db = bsddb3.hashopen(olddb, 'r')
            else: # dict
                db = olddb
            for k,v in db.items():

                k = unutf8(k, 'illegal')