當前位置: 首頁>>代碼示例>>Python>>正文


Python stem.OperationFailed方法代碼示例

本文整理匯總了Python中stem.OperationFailed方法的典型用法代碼示例。如果您正苦於以下問題:Python stem.OperationFailed方法的具體用法?Python stem.OperationFailed怎麽用?Python stem.OperationFailed使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在stem的用法示例。


在下文中一共展示了stem.OperationFailed方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: save_conf

# 需要導入模塊: import stem [as 別名]
# 或者: from stem import OperationFailed [as 別名]
def save_conf(self):
    """
    Saves the current configuration options into the active torrc file.

    :raises:
      * :class:`stem.ControllerError` if the call fails
      * :class:`stem.OperationFailed` if the client is unable to save
        the configuration file
    """

    response = self.msg('SAVECONF')
    stem.response.convert('SINGLELINE', response)

    if response.is_ok():
      return True
    elif response.code == '551':
      raise stem.OperationFailed(response.code, response.message)
    else:
      raise stem.ProtocolError('SAVECONF returned unexpected response code') 
開發者ID:Tycx2ry,項目名稱:llk,代碼行數:21,代碼來源:control.py

示例2: map_address

# 需要導入模塊: import stem [as 別名]
# 或者: from stem import OperationFailed [as 別名]
def map_address(self, mapping):
    """
    Map addresses to replacement addresses. Tor replaces subseqent connections
    to the original addresses with the replacement addresses.

    If the original address is a null address, i.e., one of '0.0.0.0', '::0', or
    '.' Tor picks an original address itself and returns it in the reply. If the
    original address is already mapped to a different address the mapping is
    removed.

    :param dict mapping: mapping of original addresses to replacement addresses

    :raises:
      * :class:`stem.InvalidRequest` if the addresses are malformed
      * :class:`stem.OperationFailed` if Tor couldn't fulfill the request

    :returns: **dict** with 'original -> replacement' address mappings
    """

    mapaddress_arg = ' '.join(['%s=%s' % (k, v) for (k, v) in list(mapping.items())])
    response = self.msg('MAPADDRESS %s' % mapaddress_arg)
    stem.response.convert('MAPADDRESS', response)

    return response.entries 
開發者ID:Tycx2ry,項目名稱:llk,代碼行數:26,代碼來源:control.py

示例3: _attach_stream

# 需要導入模塊: import stem [as 別名]
# 或者: from stem import OperationFailed [as 別名]
def _attach_stream(self, event):
        """ Attach stream to circuit. """
        try:
            self._controller.attach_stream(event.id, self._cid)
        except (OperationFailed, InvalidRequest), error:
            error = str(error)
            # If circuit is already closed, close stream too.
            if error in (('Unknown circuit "%s"' % self._cid),
                         "Can't attach stream to non-open origin circuit"):
                self._controller.close_stream(event.id)
            # Ignore the rare cases (~5*10^-7) where a stream has already been
            # closed almost directly after its NEW-event has been received.
            elif error == 'Unknown stream "%s"' % event.id:
                sys.stderr.write('Stream %s has already been ' +
                                 'closed.\n' % event.id)
            else:
                raise 
開發者ID:naviga-tor,項目名稱:navigator,代碼行數:19,代碼來源:NavigaTor.py

示例4: attach_stream

# 需要導入模塊: import stem [as 別名]
# 或者: from stem import OperationFailed [as 別名]
def attach_stream(self, stream_id, circuit_id, exiting_hop = None):
    """
    Attaches a stream to a circuit.

    Note: Tor attaches streams to circuits automatically unless the
    __LeaveStreamsUnattached configuration variable is set to '1'

    :param str stream_id: id of the stream that must be attached
    :param str circuit_id: id of the circuit to which it must be attached
    :param int exiting_hop: hop in the circuit where traffic should exit

    :raises:
      * :class:`stem.InvalidRequest` if the stream or circuit id were unrecognized
      * :class:`stem.UnsatisfiableRequest` if the stream isn't in a state where it can be attached
      * :class:`stem.OperationFailed` if the stream couldn't be attached for any other reason
    """

    query = 'ATTACHSTREAM %s %s' % (stream_id, circuit_id)

    if exiting_hop:
      query += ' HOP=%s' % exiting_hop

    response = self.msg(query)
    stem.response.convert('SINGLELINE', response)

    if not response.is_ok():
      if response.code == '552':
        raise stem.InvalidRequest(response.code, response.message)
      elif response.code == '551':
        raise stem.OperationFailed(response.code, response.message)
      elif response.code == '555':
        raise stem.UnsatisfiableRequest(response.code, response.message)
      else:
        raise stem.ProtocolError('ATTACHSTREAM returned unexpected response code: %s' % response.code) 
開發者ID:Tycx2ry,項目名稱:llk,代碼行數:36,代碼來源:control.py

示例5: get_microdescriptors

# 需要導入模塊: import stem [as 別名]
# 或者: from stem import OperationFailed [as 別名]
def get_microdescriptors(self, default = UNDEFINED):
    """
    get_microdescriptors(default = UNDEFINED)

    Provides an iterator for all of the microdescriptors that tor currently
    knows about.

    **Tor does not expose this information via the control protocol**
    (:trac:`8323`). Until it does this reads the microdescriptors from disk,
    and hence won't work remotely or if we lack read permissions.

    :param list default: items to provide if the query fails

    :returns: iterates over
      :class:`~stem.descriptor.microdescriptor.Microdescriptor` for relays in
      the tor network

    :raises: :class:`stem.ControllerError` if unable to query tor and no
      default was provided
    """

    try:
      data_directory = self.get_conf('DataDirectory')
    except stem.ControllerError as exc:
      raise stem.OperationFailed(message = 'Unable to determine the data directory (%s)' % exc)

    cached_descriptor_path = os.path.join(data_directory, 'cached-microdescs')

    if not os.path.exists(data_directory):
      raise stem.OperationFailed(message = "Data directory reported by tor doesn't exist (%s)" % data_directory)
    elif not os.path.exists(cached_descriptor_path):
      raise stem.OperationFailed(message = "Data directory doens't contain cached microescriptors (%s)" % cached_descriptor_path)

    with stem.descriptor.reader.DescriptorReader([cached_descriptor_path]) as reader:
      for desc in reader:
        # It shouldn't be possible for these to be something other than
        # microdescriptors but as the saying goes: trust but verify.

        if not isinstance(desc, stem.descriptor.microdescriptor.Microdescriptor):
          raise stem.OperationFailed(message = 'BUG: Descriptor reader provided non-microdescriptor content (%s)' % type(desc))

        yield desc 
開發者ID:Tycx2ry,項目名稱:llk,代碼行數:44,代碼來源:control.py

示例6: connect_tor_http

# 需要導入模塊: import stem [as 別名]
# 或者: from stem import OperationFailed [as 別名]
def connect_tor_http(controller,
                     circuit_path,
                     job,
                     conn_timeout,
                     curlopts=None,
                     curlinfos=None):
    """
    This helper function will perform an HTTP request over Tor. It will not
    perform any special action in the event that this is the experimental flow,
    but can be customised on a per-call basis through the curlopts argument.
    """

    if curlopts is None:
        curlopts = {}

    curlopts[pycurl.PROXY] = "localhost"
    curlopts[pycurl.PROXYPORT] = 9050
    curlopts[pycurl.PROXYTYPE] = pycurl.PROXYTYPE_SOCKS5_HOSTNAME

    attach_error = []

    try:
        if circuit_path is not None:
            circuit_path = circuit_path.split(",")
        circuit_id = controller.new_circuit(circuit_path, await_build=True)
    except stem.CircuitExtensionFailed:
        return {"spdr_state": CONN_DISCARD}

    def attach_stream(stream):
        try:
            if stream.status == 'NEW':
                if (stream.target_address == job['dip'] and
                        stream.target_port == job['dp']):
                    controller.attach_stream(stream.id, circuit_id)
        except stem.OperationFailed:
            attach_error.append(None)

    controller.add_event_listener(attach_stream, stem.control.EventType.STREAM) # pylint: disable=no-member
    result = connect_http(None, job, conn_timeout, curlopts, curlinfos)
    controller.remove_event_listener(attach_stream)

    if len(attach_error) > 0:
        return {"spdr_state": CONN_DISCARD}

    return result 
開發者ID:mami-project,項目名稱:pathspider,代碼行數:47,代碼來源:tor_http.py


注:本文中的stem.OperationFailed方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。