# Path: xclib/dbmops.py
# def perform(args):
#     domain_db = bsddb3.hashopen(args.domain_db, 'c', 0o600)
#     if args.get:
#         print(unutf8(domain_db[utf8(args.get)], 'illegal'))
#     elif args.put:
#         domain_db[utf8(args.put[0])] = args.put[1]
#     elif args.delete:
#         del domain_db[utf8(args.delete)]
#     elif args.unload:
#         for k in list(domain_db.keys()):
#             print('%s\t%s' % (unutf8(k, 'illegal'), unutf8(domain_db[k], 'illegal')))
#         # Should work according to documentation, but doesn't
#         # for k, v in DOMAIN_DB.iteritems():
#         #     print k, '\t', v
#     elif args.load:
#         for line in sys.stdin:
#             k, v = line.rstrip('\r\n').split('\t', 1)
#             domain_db[utf8(k)] = v
#     domain_db.close()
# 
# Path: xclib/tests/iostub.py
# class iostub:
#     def stub_stdin(testcase_inst, inputs, ioclass=io.StringIO):
#         stdin = sys.stdin
# 
#         def cleanup():
#             sys.stdin = stdin
# 
#         testcase_inst.addCleanup(cleanup)
#         sys.stdin = ioclass(inputs)
#         if ioclass == io.BytesIO:
#             # Fake 'buffer' variable
#             sys.stdin.buffer = sys.stdin
# 
#     def stub_stdout(testcase_inst, ioclass=io.StringIO):
#         stdout = sys.stdout
# 
#         def cleanup():
#             sys.stdout = stdout
# 
#         testcase_inst.addCleanup(cleanup)
#         sys.stdout = ioclass()
#         if ioclass == io.BytesIO:
#             # Fake 'buffer' variable
#             sys.stdout.buffer = sys.stdout
# 
#     def stub_stdouts(testcase_inst, ioclass=io.StringIO):
#         stderr = sys.stderr
#         stdout = sys.stdout
# 
#         def cleanup():
#             sys.stderr = stderr
#             sys.stdout = stdout
# 
#         testcase_inst.addCleanup(cleanup)
#         sys.stderr = ioclass()
#         sys.stdout = ioclass()
#         if ioclass == io.BytesIO:
#             # Fake 'buffer' variable
#             sys.stdout.buffer = sys.stdout
#             sys.stderr.buffer = sys.stderr
# 
# Path: xclib/utf8.py
# def utf8(u, opts='strict'):
#     return u.encode('utf-8', opts)
# 
# Path: xclib/check.py
# def assertEqual(a, b):
#     if type(a) == type(b):
#         assertSimilar(a, b)
#     else:
#         raise AssertionError('Assertion failed: Type mismatch %r (%s) != %r (%s)' % (a, type(a), b, type(b)))


import sys
import os
import io
import bsddb3
import unittest
import tempfile
import logging
import subprocess
from argparse import Namespace
from xclib.dbmops import perform
from xclib.tests.iostub import iostub
from xclib.utf8 import utf8
from xclib.check import assertEqual
# Checks some database functions

class TestDBM(unittest.TestCase, iostub):

    @classmethod
    def setup_class(cls):
        global dbname, dbfile, dirname
        dirname = tempfile.mkdtemp()
        dbname = dirname + "/domains.db"
        dbfile = bsddb3.hashopen(dbname, 'c', 0o600)

    @classmethod
    def teardown_class(cls):
        dbfile.close()
        os.remove(dbname)

# Path: xclib/dbmops.py
# def perform(args):
#     domain_db = bsddb3.hashopen(args.domain_db, 'c', 0o600)
#     if args.get:
#         print(unutf8(domain_db[utf8(args.get)], 'illegal'))
#     elif args.put:
#         domain_db[utf8(args.put[0])] = args.put[1]
#     elif args.delete:
#         del domain_db[utf8(args.delete)]
#     elif args.unload:
#         for k in list(domain_db.keys()):
#             print('%s\t%s' % (unutf8(k, 'illegal'), unutf8(domain_db[k], 'illegal')))
#         # Should work according to documentation, but doesn't
#         # for k, v in DOMAIN_DB.iteritems():
#         #     print k, '\t', v
#     elif args.load:
#         for line in sys.stdin:
#             k, v = line.rstrip('\r\n').split('\t', 1)
#             domain_db[utf8(k)] = v
#     domain_db.close()
# 
# Path: xclib/tests/iostub.py
# class iostub:
#     def stub_stdin(testcase_inst, inputs, ioclass=io.StringIO):
#         stdin = sys.stdin
# 
#         def cleanup():
#             sys.stdin = stdin
# 
#         testcase_inst.addCleanup(cleanup)
#         sys.stdin = ioclass(inputs)
#         if ioclass == io.BytesIO:
#             # Fake 'buffer' variable
#             sys.stdin.buffer = sys.stdin
# 
#     def stub_stdout(testcase_inst, ioclass=io.StringIO):
#         stdout = sys.stdout
# 
#         def cleanup():
#             sys.stdout = stdout
# 
#         testcase_inst.addCleanup(cleanup)
#         sys.stdout = ioclass()
#         if ioclass == io.BytesIO:
#             # Fake 'buffer' variable
#             sys.stdout.buffer = sys.stdout
# 
#     def stub_stdouts(testcase_inst, ioclass=io.StringIO):
#         stderr = sys.stderr
#         stdout = sys.stdout
# 
#         def cleanup():
#             sys.stderr = stderr
#             sys.stdout = stdout
# 
#         testcase_inst.addCleanup(cleanup)
#         sys.stderr = ioclass()
#         sys.stdout = ioclass()
#         if ioclass == io.BytesIO:
#             # Fake 'buffer' variable
#             sys.stdout.buffer = sys.stdout
#             sys.stderr.buffer = sys.stderr
# 
# Path: xclib/utf8.py
# def utf8(u, opts='strict'):
#     return u.encode('utf-8', opts)
# 
# Path: xclib/check.py
# def assertEqual(a, b):
#     if type(a) == type(b):
#         assertSimilar(a, b)
#     else:
#         raise AssertionError('Assertion failed: Type mismatch %r (%s) != %r (%s)' % (a, type(a), b, type(b)))


# Path: xclib/tests/12_dbm_test.py
import sys
import os
import io
import bsddb3
import unittest
import tempfile
import logging
import subprocess
from argparse import Namespace
from xclib.dbmops import perform
from xclib.tests.iostub import iostub
from xclib.utf8 import utf8
from xclib.check import assertEqual

# Checks some database functions

class TestDBM(unittest.TestCase, iostub):

    @classmethod
    def setup_class(cls):
        global dbname, dbfile, dirname
        dirname = tempfile.mkdtemp()
        dbname = dirname + "/domains.db"
        dbfile = bsddb3.hashopen(dbname, 'c', 0o600)

    @classmethod
    def teardown_class(cls):
        dbfile.close()
        os.remove(dbname)

        os.rmdir(dirname)