'Check for valid arguments and environment to spawnProcess.
@return: A two element tuple giving values to use when creating the
process.  The first element of the tuple is a C{list} of C{bytes}
giving the values for argv of the child process.  The second element
of the tuple is either L{None} if C{env} was L{None} or a C{dict}
mapping C{bytes} environment keys to C{bytes} environment values.'

def _checkProcessArgs(self, args, env):

    defaultEncoding = sys.getfilesystemencoding()
    def argChecker(arg):
        '\n                                                Return    either    L{bytes}    or    L{None}.        If    the    given    value    is    not\n                                                allowable    for    some    reason,    L{None}    is    returned.        Otherwise,    a\n                                                possibly    different    object    which    should    be    used    in    place    of    arg    is\n                                                returned.        This    forces    unicode    encoding    to    happen    now,    rather    than\n                                                implicitly    later.\n                                                '
        if isinstance(arg, unicode):
            try:
                arg = arg.encode(defaultEncoding)
            except UnicodeEncodeError:
                return None
        if (isinstance(arg, bytes) and ('\x00' not in arg)):
            return arg
        return None
    if (not isinstance(args, (tuple, list))):
        raise TypeError('Arguments    must    be    a    tuple    or    list')
    outputArgs = []
    for arg in args:
        arg = argChecker(arg)
        if (arg is None):
            raise TypeError('Arguments    contain    a    non-string    value')
        else:
            outputArgs.append(arg)
    outputEnv = None
    if (env is not None):
        outputEnv = {}
        for (key, val) in iteritems(env):
            key = argChecker(key)
            if (key is None):
                raise TypeError('Environment    contains    a    non-string    key')
            val = argChecker(val)
            if (val is None):
                raise TypeError('Environment    contains    a    non-string    value')
            outputEnv[key] = val
    return (outputArgs, outputEnv)
