Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(655)

Unified Diff: telemetry/telemetry/internal/forwarders/__init__.py

Issue 1671903002: [Telemetry] Implement network_controller_backend new API (Closed) Base URL: git@github.com:catapult-project/catapult@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | telemetry/telemetry/internal/platform/network_controller_backend.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: telemetry/telemetry/internal/forwarders/__init__.py
diff --git a/telemetry/telemetry/internal/forwarders/__init__.py b/telemetry/telemetry/internal/forwarders/__init__.py
index e05fb3b558b10e38be479bc4d25c90933a8df000..98007b4456466dc2ddc2326df457a23166f1eb3d 100644
--- a/telemetry/telemetry/internal/forwarders/__init__.py
+++ b/telemetry/telemetry/internal/forwarders/__init__.py
@@ -6,7 +6,29 @@ import collections
PortPair = collections.namedtuple('PortPair', ['local_port', 'remote_port'])
-PortPairs = collections.namedtuple('PortPairs', ['http', 'https', 'dns'])
+PortSet = collections.namedtuple('PortSet', ['http', 'https', 'dns'])
+
+class PortPairs(collections.namedtuple('PortPairs', ['http', 'https', 'dns'])):
+ __slots__ = ()
+
+ @classmethod
+ def Zip(cls, local_ports, remote_ports):
+ """Zip a pair of PortSet's into a single PortPairs object."""
+ with_dns = local_ports.dns is not None and remote_ports.dns is not None
+ return cls(
+ PortPair(local_ports.http, remote_ports.http),
+ PortPair(local_ports.https, remote_ports.https),
+ PortPair(local_ports.dns, remote_ports.dns) if with_dns else None)
+
+ @property
+ def local_ports(self):
+ """Return a tuple of local ports only."""
+ return PortSet(*[p.local_port if p is not None else None for p in self])
+
+ @property
+ def remote_ports(self):
+ """Return a tuple of remote ports only."""
+ return PortSet(*[p.remote_port if p is not None else None for p in self])
class ForwarderFactory(object):
« no previous file with comments | « no previous file | telemetry/telemetry/internal/platform/network_controller_backend.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698