Python errno.ENOEXEC Examples

The following are 13 code examples of errno.ENOEXEC(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module errno , or try the search function .
Example #1
Source File: test_bus.py    From charms.reactive with Apache License 2.0 6 votes vote down vote up
def test_test(self, Popen):
        handler = reactive.bus.ExternalHandler('filepath')
        Popen.return_value.communicate.return_value = ('output', None)

        Popen.return_value.returncode = 0
        assert handler.test()

        Popen.return_value.returncode = 1
        assert not handler.test()
        Popen.assert_called_with(['filepath', '--test'], stdout=reactive.bus.subprocess.PIPE, env='env')

        e = Popen.side_effect = OSError()
        e.errno = errno.ENOEXEC
        self.assertRaises(reactive.bus.BrokenHandlerException, handler.test)
        e.errno = errno.ENOENT
        self.assertRaises(OSError, handler.test) 
Example #2
Source File: adb_wrapper.py    From Jandroid with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _RunAdbCmd(cls, args, timeout=None, retries=None, device_serial=None,
                 check_error=True, cpu_affinity=None,
                 ensure_logs_on_timeout=False):
    timeout = timeout_retry.CurrentTimeoutThreadGroup().GetRemainingTime()
    if ensure_logs_on_timeout:
      timeout = 0.95 * timeout
    try:
      status, output = cmd_helper.GetCmdStatusAndOutputWithTimeout(
          cls._BuildAdbCmd(args, device_serial, cpu_affinity=cpu_affinity),
          timeout, env=cls._ADB_ENV)
    except OSError as e:
      if e.errno in (errno.ENOENT, errno.ENOEXEC):
        raise device_errors.NoAdbError(msg=str(e))
      else:
        raise

    # Best effort to catch errors from adb; unfortunately adb is very
    # inconsistent with error reporting so many command failures present
    # differently.
    if status != 0 or (check_error and output.startswith('error:')):
      not_found_m = _DEVICE_NOT_FOUND_RE.match(output)
      device_waiting_m = _WAITING_FOR_DEVICE_RE.match(output)
      if (device_waiting_m is not None
          or (not_found_m is not None and
              not_found_m.group('serial') == device_serial)):
        raise device_errors.DeviceUnreachableError(device_serial)
      else:
        raise device_errors.AdbCommandFailedError(
            args, output, status, device_serial)

    return output
  # pylint: enable=unused-argument 
Example #3
Source File: adb_wrapper.py    From Jandroid with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _RunAdbCmd(cls, args, timeout=None, retries=None, device_serial=None,
                 check_error=True, cpu_affinity=None,
                 ensure_logs_on_timeout=False):
    timeout = timeout_retry.CurrentTimeoutThreadGroup().GetRemainingTime()
    if ensure_logs_on_timeout:
      timeout = 0.95 * timeout
    try:
      status, output = cmd_helper.GetCmdStatusAndOutputWithTimeout(
          cls._BuildAdbCmd(args, device_serial, cpu_affinity=cpu_affinity),
          timeout, env=cls._ADB_ENV)
    except OSError as e:
      if e.errno in (errno.ENOENT, errno.ENOEXEC):
        raise device_errors.NoAdbError(msg=str(e))
      else:
        raise

    # Best effort to catch errors from adb; unfortunately adb is very
    # inconsistent with error reporting so many command failures present
    # differently.
    if status != 0 or (check_error and output.startswith('error:')):
      not_found_m = _DEVICE_NOT_FOUND_RE.match(output)
      device_waiting_m = _WAITING_FOR_DEVICE_RE.match(output)
      if (device_waiting_m is not None
          or (not_found_m is not None and
              not_found_m.group('serial') == device_serial)):
        raise device_errors.DeviceUnreachableError(device_serial)
      else:
        raise device_errors.AdbCommandFailedError(
            args, output, status, device_serial)

    return output
  # pylint: enable=unused-argument 
Example #4
Source File: adb_wrapper.py    From Jandroid with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _RunAdbCmd(cls, args, timeout=None, retries=None, device_serial=None,
                 check_error=True, cpu_affinity=None,
                 ensure_logs_on_timeout=False):
    timeout = timeout_retry.CurrentTimeoutThreadGroup().GetRemainingTime()
    if ensure_logs_on_timeout:
      timeout = 0.95 * timeout
    try:
      status, output = cmd_helper.GetCmdStatusAndOutputWithTimeout(
          cls._BuildAdbCmd(args, device_serial, cpu_affinity=cpu_affinity),
          timeout, env=cls._ADB_ENV)
    except OSError as e:
      if e.errno in (errno.ENOENT, errno.ENOEXEC):
        raise device_errors.NoAdbError(msg=str(e))
      else:
        raise

    # Best effort to catch errors from adb; unfortunately adb is very
    # inconsistent with error reporting so many command failures present
    # differently.
    if status != 0 or (check_error and output.startswith('error:')):
      not_found_m = _DEVICE_NOT_FOUND_RE.match(output)
      device_waiting_m = _WAITING_FOR_DEVICE_RE.match(output)
      if (device_waiting_m is not None
          or (not_found_m is not None and
              not_found_m.group('serial') == device_serial)):
        raise device_errors.DeviceUnreachableError(device_serial)
      else:
        raise device_errors.AdbCommandFailedError(
            args, output, status, device_serial)

    return output
  # pylint: enable=unused-argument 
Example #5
Source File: bus.py    From charms.reactive with Apache License 2.0 5 votes vote down vote up
def test(self):
        """
        Call the external handler to test whether it should be invoked.
        """
        # flush to ensure external process can see flags as they currently
        # are, and write flags (flush releases lock)
        unitdata.kv().flush()
        try:
            proc = subprocess.Popen([self._filepath, '--test'], stdout=subprocess.PIPE, env=os.environ)
        except OSError as oserr:
            if oserr.errno == errno.ENOEXEC:
                raise BrokenHandlerException(self._filepath)
            raise
        self._test_output, _ = proc.communicate()
        return proc.returncode == 0 
Example #6
Source File: test_socket.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def testUnresolvedAddress(self):
        try:
            self.s.connect( ('non.existent.server', PORT) )
        except socket.gaierror, gaix:
            self.failUnlessEqual(gaix[0], errno.ENOEXEC) 
Example #7
Source File: target.py    From yotta with Apache License 2.0 5 votes vote down vote up
def start(self, builddir, program, forward_args):
        ''' Launch the specified program. Uses the `start` script if specified
            by the target, attempts to run it natively if that script is not
            defined.
        '''
        child = None
        try:
            prog_path = self.findProgram(builddir, program)
            if prog_path is None:
                return

            start_env, start_vars = self.buildProgEnvAndVars(prog_path, builddir)
            if self.getScript('start'):
                cmd = [
                    os.path.expandvars(string.Template(x).safe_substitute(**start_vars))
                    for x in self.getScript('start')
                ] + forward_args
            else:
                cmd = shlex.split('./' + prog_path) + forward_args

            logger.debug('starting program: %s', cmd)
            child = subprocess.Popen(
                cmd, cwd = builddir, env = start_env
            )
            child.wait()
            if child.returncode:
                return "process exited with status %s" % child.returncode
            child = None
        except OSError as e:
            import errno
            if e.errno == errno.ENOEXEC:
                return ("the program %s cannot be run (perhaps your target "+
                        "needs to define a 'start' script to start it on its "
                        "intended execution target?)") % prog_path
        finally:
            if child is not None:
                _tryTerminate(child) 
Example #8
Source File: test_socket.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def testUnresolvedAddress(self):
        try:
            self.s.connect( ('non.existent.server', PORT) )
        except socket.gaierror, gaix:
            self.failUnlessEqual(gaix[0], errno.ENOEXEC) 
Example #9
Source File: construct_setups.py    From f5-openstack-agent with Apache License 2.0 4 votes vote down vote up
def _construct_file(setup_cfg, setup, fmt, start):
    if not os.path.isfile(setup) or not os.access(setup, os.R_OK):
        print(setup + " does not exist or is not readable")
        exit_cleanly(error_number=errno.ENOSYS)
    contents = _read_in_cfgs(setup_cfg)
    parsed_reqs = map(lambda x: (x.req), p_reqs(setup, session="pkg"))
    if not parsed_reqs:
        print("Nothing to do!\n%s\nDoes not contain any reqs parsable!" %
              setup)
        exit_cleanly(error_number=0)
    try:
        base_dir = os.path.dirname(setup_cfg)
        if not os.path.isdir(base_dir):
            try:
                os.mkdir(base_dir)
            except OSError as Error:
                if Error.errno != errno.EEXIST:
                    raise
        with open(setup_cfg, 'w') as fh:
            pkg_type = ''
            if contents:
                while contents:
                    fh.write(contents.popleft())
            fh.write(start)
            for count in range(len(parsed_reqs)):
                req = parsed_reqs[count]
                if 'Depends' in start:
                    # special case for debian...
                    name = str(req.name) if 'python-' in str(req.name) else \
                        'python-' + str(req.name)
                    pkg_type = 'deb'
                else:
                    name = str(req.name)
                    pkg_type = 'rpm'
                specifier = str(req.specifier)
                if '==' in specifier:
                    handle_equals(fh, fmt, name, specifier, pkg_type=pkg_type)
                    continue
                else:
                    relation_oper = re.compile('([><=]{1,2})(.*)')
                    match = relation_oper.search(specifier)
                    if match:
                        specifier = ' '.join(match.groups())
                    else:
                        print("Error: the format of dependencies can not be parsed")
                        exit_cleanly(error_number=errno.ENOEXEC)
                    fh.write(fmt % (name, specifier))
                if count != len(parsed_reqs) - 1:
                    fh.write('\n    ')
            fh.write("\n")  # some packages require a new line
    except AssertionError as Error:
        raise ValueError(str(Error))
    except IOError as Error:
        print(Error)
        exit_cleanly(error_number=errno.EIO) 
Example #10
Source File: _socket.py    From CTFCrackTools-V2 with GNU General Public License v3.0 4 votes vote down vote up
def getaddrinfo(host, port, family=AF_UNSPEC, socktype=0, proto=0, flags=0):
    if family is None:
        family = AF_UNSPEC
    if socktype is None:
        socktype = 0
    if not family in [AF_INET, AF_INET6, AF_UNSPEC]:
        raise gaierror(errno.EIO, 'ai_family not supported')
    host = _getaddrinfo_get_host(host, family, flags)
    port = _getaddrinfo_get_port(port, flags)
    if socktype not in [0, SOCK_DGRAM, SOCK_STREAM]:
        raise error(errno.ESOCKTNOSUPPORT, "Socket type is not supported")
    filter_fns = []
    filter_fns.append({
        AF_INET:   lambda x: isinstance(x, java.net.Inet4Address),
        AF_INET6:  lambda x: isinstance(x, java.net.Inet6Address),
        AF_UNSPEC: lambda x: isinstance(x, java.net.InetAddress),
    }[family])
    if host in [None, ""]:
        if flags & AI_PASSIVE:
             hosts = {AF_INET: [INADDR_ANY], AF_INET6: [IN6ADDR_ANY_INIT], AF_UNSPEC: [INADDR_ANY, IN6ADDR_ANY_INIT]}[family]
        else:
             hosts = ["localhost"]
    else:
        hosts = [host]
    results = []
    for h in hosts:
        try:
            all_by_name = java.net.InetAddress.getAllByName(h)
        except java.net.UnknownHostException:
            raise gaierror(errno.ENOEXEC, 'nodename nor servname provided, or not known')

        for a in all_by_name:
            if len([f for f in filter_fns if f(a)]):
                family = {java.net.Inet4Address: AF_INET, java.net.Inet6Address: AF_INET6}[a.getClass()]
                if flags & AI_CANONNAME:
                    canonname = str(a.getCanonicalHostName())
                else:
                    canonname = ""
                sockaddr = str(a.getHostAddress())
                # TODO: Include flowinfo and scopeid in a 4-tuple for IPv6 addresses
                sock_tuple = {AF_INET : _ipv4_address_t, AF_INET6 : _ipv6_address_t}[family](sockaddr, port, a)
                if socktype == 0:
                    socktypes = [SOCK_DGRAM, SOCK_STREAM]
                else:
                    socktypes = [socktype]
                for result_socktype in socktypes:
                    result_proto = {SOCK_DGRAM: IPPROTO_UDP, SOCK_STREAM: IPPROTO_TCP}[result_socktype]
                    if proto in [0, result_proto]:
                        # The returned socket will only support the result_proto
                        # If this does not match the requested proto, don't return it
                        results.append((family, result_socktype, result_proto, canonname, sock_tuple))
    return results 
Example #11
Source File: _socket.py    From CTFCrackTools-V2 with GNU General Public License v3.0 4 votes vote down vote up
def getaddrinfo(host, port, family=AF_UNSPEC, socktype=0, proto=0, flags=0):
    if family is None:
        family = AF_UNSPEC
    if socktype is None:
        socktype = 0
    if not family in [AF_INET, AF_INET6, AF_UNSPEC]:
        raise gaierror(errno.EIO, 'ai_family not supported')
    host = _getaddrinfo_get_host(host, family, flags)
    port = _getaddrinfo_get_port(port, flags)
    if socktype not in [0, SOCK_DGRAM, SOCK_STREAM]:
        raise error(errno.ESOCKTNOSUPPORT, "Socket type is not supported")
    filter_fns = []
    filter_fns.append({
        AF_INET:   lambda x: isinstance(x, java.net.Inet4Address),
        AF_INET6:  lambda x: isinstance(x, java.net.Inet6Address),
        AF_UNSPEC: lambda x: isinstance(x, java.net.InetAddress),
    }[family])
    if host in [None, ""]:
        if flags & AI_PASSIVE:
             hosts = {AF_INET: [INADDR_ANY], AF_INET6: [IN6ADDR_ANY_INIT], AF_UNSPEC: [INADDR_ANY, IN6ADDR_ANY_INIT]}[family]
        else:
             hosts = ["localhost"]
    else:
        hosts = [host]
    results = []
    for h in hosts:
        try:
            all_by_name = java.net.InetAddress.getAllByName(h)
        except java.net.UnknownHostException:
            raise gaierror(errno.ENOEXEC, 'nodename nor servname provided, or not known')

        for a in all_by_name:
            if len([f for f in filter_fns if f(a)]):
                family = {java.net.Inet4Address: AF_INET, java.net.Inet6Address: AF_INET6}[a.getClass()]
                if flags & AI_CANONNAME:
                    canonname = str(a.getCanonicalHostName())
                else:
                    canonname = ""
                sockaddr = str(a.getHostAddress())
                # TODO: Include flowinfo and scopeid in a 4-tuple for IPv6 addresses
                sock_tuple = {AF_INET : _ipv4_address_t, AF_INET6 : _ipv6_address_t}[family](sockaddr, port, a)
                if socktype == 0:
                    socktypes = [SOCK_DGRAM, SOCK_STREAM]
                else:
                    socktypes = [socktype]
                for result_socktype in socktypes:
                    result_proto = {SOCK_DGRAM: IPPROTO_UDP, SOCK_STREAM: IPPROTO_TCP}[result_socktype]
                    if proto in [0, result_proto]:
                        # The returned socket will only support the result_proto
                        # If this does not match the requested proto, don't return it
                        results.append((family, result_socktype, result_proto, canonname, sock_tuple))
    return results 
Example #12
Source File: _socket.py    From CTFCrackTools with GNU General Public License v3.0 4 votes vote down vote up
def getaddrinfo(host, port, family=AF_UNSPEC, socktype=0, proto=0, flags=0):
    if family is None:
        family = AF_UNSPEC
    if socktype is None:
        socktype = 0
    if not family in [AF_INET, AF_INET6, AF_UNSPEC]:
        raise gaierror(errno.EIO, 'ai_family not supported')
    host = _getaddrinfo_get_host(host, family, flags)
    port = _getaddrinfo_get_port(port, flags)
    if socktype not in [0, SOCK_DGRAM, SOCK_STREAM]:
        raise error(errno.ESOCKTNOSUPPORT, "Socket type is not supported")
    filter_fns = []
    filter_fns.append({
        AF_INET:   lambda x: isinstance(x, java.net.Inet4Address),
        AF_INET6:  lambda x: isinstance(x, java.net.Inet6Address),
        AF_UNSPEC: lambda x: isinstance(x, java.net.InetAddress),
    }[family])
    if host in [None, ""]:
        if flags & AI_PASSIVE:
             hosts = {AF_INET: [INADDR_ANY], AF_INET6: [IN6ADDR_ANY_INIT], AF_UNSPEC: [INADDR_ANY, IN6ADDR_ANY_INIT]}[family]
        else:
             hosts = ["localhost"]
    else:
        hosts = [host]
    results = []
    for h in hosts:
        try:
            all_by_name = java.net.InetAddress.getAllByName(h)
        except java.net.UnknownHostException:
            raise gaierror(errno.ENOEXEC, 'nodename nor servname provided, or not known')

        for a in all_by_name:
            if len([f for f in filter_fns if f(a)]):
                family = {java.net.Inet4Address: AF_INET, java.net.Inet6Address: AF_INET6}[a.getClass()]
                if flags & AI_CANONNAME:
                    canonname = str(a.getCanonicalHostName())
                else:
                    canonname = ""
                sockaddr = str(a.getHostAddress())
                # TODO: Include flowinfo and scopeid in a 4-tuple for IPv6 addresses
                sock_tuple = {AF_INET : _ipv4_address_t, AF_INET6 : _ipv6_address_t}[family](sockaddr, port, a)
                if socktype == 0:
                    socktypes = [SOCK_DGRAM, SOCK_STREAM]
                else:
                    socktypes = [socktype]
                for result_socktype in socktypes:
                    result_proto = {SOCK_DGRAM: IPPROTO_UDP, SOCK_STREAM: IPPROTO_TCP}[result_socktype]
                    if proto in [0, result_proto]:
                        # The returned socket will only support the result_proto
                        # If this does not match the requested proto, don't return it
                        results.append((family, result_socktype, result_proto, canonname, sock_tuple))
    return results 
Example #13
Source File: _socket.py    From CTFCrackTools with GNU General Public License v3.0 4 votes vote down vote up
def getaddrinfo(host, port, family=AF_UNSPEC, socktype=0, proto=0, flags=0):
    if family is None:
        family = AF_UNSPEC
    if socktype is None:
        socktype = 0
    if not family in [AF_INET, AF_INET6, AF_UNSPEC]:
        raise gaierror(errno.EIO, 'ai_family not supported')
    host = _getaddrinfo_get_host(host, family, flags)
    port = _getaddrinfo_get_port(port, flags)
    if socktype not in [0, SOCK_DGRAM, SOCK_STREAM]:
        raise error(errno.ESOCKTNOSUPPORT, "Socket type is not supported")
    filter_fns = []
    filter_fns.append({
        AF_INET:   lambda x: isinstance(x, java.net.Inet4Address),
        AF_INET6:  lambda x: isinstance(x, java.net.Inet6Address),
        AF_UNSPEC: lambda x: isinstance(x, java.net.InetAddress),
    }[family])
    if host in [None, ""]:
        if flags & AI_PASSIVE:
             hosts = {AF_INET: [INADDR_ANY], AF_INET6: [IN6ADDR_ANY_INIT], AF_UNSPEC: [INADDR_ANY, IN6ADDR_ANY_INIT]}[family]
        else:
             hosts = ["localhost"]
    else:
        hosts = [host]
    results = []
    for h in hosts:
        try:
            all_by_name = java.net.InetAddress.getAllByName(h)
        except java.net.UnknownHostException:
            raise gaierror(errno.ENOEXEC, 'nodename nor servname provided, or not known')

        for a in all_by_name:
            if len([f for f in filter_fns if f(a)]):
                family = {java.net.Inet4Address: AF_INET, java.net.Inet6Address: AF_INET6}[a.getClass()]
                if flags & AI_CANONNAME:
                    canonname = str(a.getCanonicalHostName())
                else:
                    canonname = ""
                sockaddr = str(a.getHostAddress())
                # TODO: Include flowinfo and scopeid in a 4-tuple for IPv6 addresses
                sock_tuple = {AF_INET : _ipv4_address_t, AF_INET6 : _ipv6_address_t}[family](sockaddr, port, a)
                if socktype == 0:
                    socktypes = [SOCK_DGRAM, SOCK_STREAM]
                else:
                    socktypes = [socktype]
                for result_socktype in socktypes:
                    result_proto = {SOCK_DGRAM: IPPROTO_UDP, SOCK_STREAM: IPPROTO_TCP}[result_socktype]
                    if proto in [0, result_proto]:
                        # The returned socket will only support the result_proto
                        # If this does not match the requested proto, don't return it
                        results.append((family, result_socktype, result_proto, canonname, sock_tuple))
    return results