1 # Copyright 2012-2020, Damian Johnson and The Tor Project
2 # See LICENSE for licensing information
8 class MapAddressResponse(stem
.response
.ControlMessage
):
10 MAPADDRESS reply. Responses can contain a mixture of successes and failures,
15 512-syntax error: invalid address '@@@'
16 250 1.2.3.4=tor.freehaven.net
18 This only raises an exception if **every** mapping fails. Otherwise
19 **mapped** enumerates our successes and **failures** lists any
22 :var dict mapped: mapping between the original and replacement addresses
23 :var list failures: failure listed within this reply
26 * :class:`stem.OperationFailed` if Tor was unable to satisfy the request
27 * :class:`stem.InvalidRequest` if the addresses provided were invalid
30 def _parse_message(self
) -> None:
32 for code
, _
, message
in self
.content():
34 raise stem
.InvalidRequest(code
, message
)
36 raise stem
.OperationFailed(code
, message
)
38 raise stem
.ProtocolError('MAPADDRESS returned unexpected response code: %s', code
)
43 for code
, _
, message
in self
.content():
46 key
, value
= message
.split('=', 1)
47 self
.mapped
[key
] = value
49 raise stem
.ProtocolError(None, "MAPADDRESS returned '%s', which isn't a mapping" % message
)
51 self
.failures
.append(message
)