Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#7784 closed enhancement (implemented)

add Controller.get_socks_port

Reported by: robinson Owned by: atagar
Priority: Medium Milestone:
Component: Core Tor/Stem Version:
Severity: Keywords: controller
Cc: Actual Points:
Parent ID: Points:
Reviewer: Sponsor:

Description

Add a Controller method to retrieve the SOCKS port. Please pull this branch.

https://gitorious.org/stem-robinson/stem-robinson/commits/exp-socksport

Child Tickets

Change History (2)

comment:1 Changed 5 years ago by atagar

  • Resolution set to implemented
  • Status changed from new to closed

Hi Sean, sorry about the delay! Been busy with the holidays and work.

Pushed your changes with some changes...

https://gitweb.torproject.org/stem.git/commitdiff/79fc8cd7514cda072abf855b6a1908f0dd10bb17

It's a pity that the mocking key/value entries need to be alphabetical. That seems like something that'll bite us, but I'm not spotting a nicer way of handling it offhand. Oh well.

comment:2 Changed 5 years ago by robinson

Just to document "Also, remove the the space in the join so that there is only one parameter passed to the string substitution." better:

I was getting an unhelpful error with the following code:

import stem.socket

from stem import InvalidArguments
from stem.control import Controller

from test import mocking

socket = stem.socket.ControlSocket()
controller = Controller(socket)

mocking.mock_method(Controller, "get_info", mocking.raise_exception(InvalidArguments))

mocking.mock_method(Controller, "get_conf", mocking.return_for_args({
  ("SocksPort", "useless_second", "useless_third"): "9050",
  ("SocksListenAddress", "multiple=True"): ["127.0.0.1"]
}, is_method = True))

controller.get_socks_listeners()

Old error:

Traceback (most recent call last):
  File "./return_for_args-test.py", line 19, in <module>
    controller.get_socks_listeners()
  File "stem/control.py", line 1348, in get_socks_listeners
    socks_port = self.get_conf('SocksPort')
  File "test/mocking.py", line 360, in <lambda>
    mock_wrapper = lambda *args, **kwargs: mock_call(*args, **kwargs)
  File "test/mocking.py", line 261, in _return_value
    raise ValueError("Unrecognized argument sent for return_for_args(). Got '%s' but we
only recognize '%s'." % (arg_label, ", ".join(args_to_return_value.keys())))
TypeError: sequence item 0: expected string, tuple found

I mistakenly believed this was due to spaces in the keys in args_to_return_value, but really is was the tuple-as-key did not work in the string substitution. But, I over-corrected. Damian's revision of my fix works and gives readable output.

Note: See TracTickets for help on using tickets.