# 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
        ns = self.mkns(load=True)
        perform(ns)
        assertEqual(dbfile[b'example.ch'], b'XmplScrt\thttps://example.ch/index.php/apps/ojsxc/ajax/externalApi.php\texample.ch\t')
        assertEqual(dbfile[b'example.de'], b'NothrXampl\thttps://nothing\t')
        assert b'example.net' not in dbfile

    def test_02_put(self):
        ns = self.mkns(put=[u'example.net', u'dummy'])
        perform(ns)
        ns = self.mkns(get=u'example.net')
        perform(ns)
        dbfile = bsddb3.hashopen(dbname, 'c', 0o600)
        assert b'example.net' in dbfile
        assertEqual(dbfile[b'example.net'], b'dummy')
        dbfile.close()

    def test_03_get(self):
        self.stub_stdout(ioclass=io.StringIO)
        ns = self.mkns(get=u'example.net')
        perform(ns)
        self.assertEqual(sys.stdout.getvalue(), u'dummy\n')

    def test_04_delete(self):
        ns = self.mkns(delete=u'example.de')
        perform(ns)

    def test_05_unload(self):
        expected = [b'example.net', b'example.ch']
        self.stub_stdout(ioclass=io.StringIO)
        ns = self.mkns(unload=True)

# 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

        ns = self.mkns(load=True)
        perform(ns)
        assertEqual(dbfile[b'example.ch'], b'XmplScrt\thttps://example.ch/index.php/apps/ojsxc/ajax/externalApi.php\texample.ch\t')
        assertEqual(dbfile[b'example.de'], b'NothrXampl\thttps://nothing\t')
        assert b'example.net' not in dbfile

    def test_02_put(self):
        ns = self.mkns(put=[u'example.net', u'dummy'])
        perform(ns)
        ns = self.mkns(get=u'example.net')
        perform(ns)
        dbfile = bsddb3.hashopen(dbname, 'c', 0o600)
        assert b'example.net' in dbfile
        assertEqual(dbfile[b'example.net'], b'dummy')
        dbfile.close()

    def test_03_get(self):
        self.stub_stdout(ioclass=io.StringIO)
        ns = self.mkns(get=u'example.net')
        perform(ns)
        self.assertEqual(sys.stdout.getvalue(), u'dummy\n')

    def test_04_delete(self):
        ns = self.mkns(delete=u'example.de')
        perform(ns)

    def test_05_unload(self):
        expected = [b'example.net', b'example.ch']
        self.stub_stdout(ioclass=io.StringIO)
        ns = self.mkns(unload=True)

        perform(ns)