def macro_call(macro_name, args, kwargs):
    """ allow the programmer to perform limited processing on the server by passing macro names and args

    :new_key - the key name the macro will create
    :args[0] - macro name
    :args[1:] - any arguments
    :code - the value of the keyword item
    :kwargs - the connection keyword dictionary. ??key has been removed
    --> the value to put in for kwargs['name'] = value
    """
    if isinstance(args, (str, unicode)):
        args = [
            args
        ]  # the user forgot to pass a sequence, so make a string into args[0]
    new_key = args[0]
    try:
        if macro_name == "is64bit":
            if is64bit.Python():  # if on 64 bit Python
                return new_key, args[1]  # return first argument
            else:
                try:
                    return new_key, args[
                        2]  # else return second argument (if defined)
                except IndexError:
                    return new_key, ''  # else return blank

        elif macro_name == "getuser":  # get the name of the user the server is logged in under
            if not new_key in kwargs:
                import getpass
                return new_key, getpass.getuser()

        elif macro_name == "getnode":  # get the name of the computer running the server
            import platform
            try:
                return new_key, args[1] % platform.node()
            except IndexError:
                return new_key, platform.node()

        elif macro_name == "getenv":  # expand the server's environment variable args[1]
            try:
                dflt = args[2]  # if not found, default from args[2]
            except IndexError:  # or blank
                dflt = ''
            return new_key, os.environ.get(args[1], dflt)

        elif macro_name == "auto_security":
            if not 'user' in kwargs or not kwargs[
                    'user']:  # missing, blank, or Null username
                return new_key, 'Integrated Security=SSPI'
            return new_key, 'User ID=%(user)s; Password=%(password)s' % kwargs

        elif macro_name == "find_temp_test_path":  # helper function for testing ado operation -- undocumented
            import tempfile, os
            return new_key, os.path.join(tempfile.gettempdir(),
                                         'adodbapi_test', args[1])

        raise ValueError('Unknown connect string macro=%s' % macro_name)
    except:
        raise ValueError('Error in macro processing %s %s' %
                         (macro_name, repr(args)))
Example #2
0
import platform
import sys
import random

import is64bit
import setuptestframework

if sys.version_info >= (3, 0):
    import tryconnection3 as tryconnection
else:
    import tryconnection2 as tryconnection

print((sys.version))
node = platform.node()
try:
    print(('node=%s: is64bit.os()= %s, is64bit.Python()= %s' % (node, is64bit.os(), is64bit.Python())))
except:
    pass

try:
    onWindows = bool(sys.getwindowsversion())  # seems to work on all versions of Python
except:
    onWindows = False

# create a random name for temporary table names
_alphabet = "PYFGCRLAOEUIDHTNTQJKXBMWVZ1234567890"  # yes, I do use a dvorak keyboard!
tmp = ''.join([random.choice(_alphabet) for x in range(9)])
mdb_name = 'xx_' + tmp + '.mdb'
testfolder = setuptestframework.maketemp()

if '--package' in sys.argv:
Example #3
0
import platform
import sys
import random

import is64bit
import setuptestframework
if sys.version_info >= (3, 0):
    import tryconnection3 as tryconnection
else:
    import tryconnection2 as tryconnection

print((sys.version))
node = platform.node()
try:
    print(('node=%s: is64bit.os()= %s, is64bit.Python()= %s' %
           (node, is64bit.os(), is64bit.Python())))
except:
    pass

try:
    onWindows = bool(
        sys.getwindowsversion())  # seems to work on all versions of Python
except:
    onWindows = False

# create a random name for temporary table names
_alphabet = "PYFGCRLAOEUIDHTNTQJKXBMWVZ1234567890"  # yes, I do use a dvorak keyboard!
tmp = ''.join([random.choice(_alphabet) for x in range(9)])
mdb_name = 'xx_' + tmp + '.mdb'
testfolder = setuptestframework.maketemp()
print("Tested with dbapi20 %s" % dbapi20.__version__)


node = platform.node()
if node == "novelt2":
    _computername = '127.0.0.1'
    _databasename = 'vernon'
    connStr = "Provider=SQLOLEDB.1; Integrated Security=SSPI; Initial Catalog=%s;Data Source=%s" %(_databasename, _computername)
elif node == "z-PC":
    _computername = "25.223.161.222"
    _databasename='adotest'
    _username = '******'
    _password = '******'
    _driver="PostgreSQL Unicode"
    _provider = ''
    if is64bit.Python():
        _driver += '(x64)'
        _provider = 'Provider=MSDASQL;'
    connStr = '%sDriver={%s};Server=%s;Database=%s;uid=%s;pwd=%s;' % \
                  (_provider,_driver,_computername,_databasename,_username,_password)
else:  # ACCESS data base is known to fail some tests.
    testmdb = setuptestframework.makemdb(testfolder)
    connStr = r"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + testmdb
print('Using Connection String='+connStr)

class test_adodbapi(dbapi20.DatabaseAPI20Test):
    driver = adodbapi
    connect_args =  (connStr,)
    connect_kw_args = {}

    def __init__(self,arg):
Example #5
0
# #  Skip down to the next "# #" line --
# #  -- the things you need to change are below it.
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
import platform
import sys
import random

import is64bit
import setuptestframework
import tryconnection

print("\nPython", sys.version)
node = platform.node()
try:
    print('node=%s, is64bit.os()= %s, is64bit.Python()= %s' %
          (node, is64bit.os(), is64bit.Python()))
except:
    pass

if '--help' in sys.argv:
    print("""Valid command-line switches are:
    --package - create a temporary test package, run 2to3 if needed.
    --all - run all possible tests
    --time - loop over time format tests (including mxdatetime if present)
    --nojet - do not test against an ACCESS database file
    --mssql - test against Microsoft SQL server
    --pg - test against PostgreSQL
    --mysql - test against MariaDB
    --remote= - test unsing remote server at= (experimental) 
    """)
    exit()