Skip to content
This repository was archived by the owner on Jul 11, 2022. It is now read-only.

Commit 2612c73

Browse files
author
Alexander
committed
Replaced Py3-style dict.items() with six.iteritems(dict)
six.iteritems(dict) behave like dict.iteritems() in Python 2 and like iter(dict.items()) in Python 3. This should keep performance on the same level for both Py2/3 environments.
1 parent cfe390c commit 2612c73

File tree

9 files changed

+19
-10
lines changed

9 files changed

+19
-10
lines changed

crossdock/server/endtoend.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from builtins import object
33
import tornado.web
44
import json
5+
import six
56

67
from jaeger_client.local_agent_net import LocalAgentSender
78
from jaeger_client.config import (
@@ -101,7 +102,7 @@ def generate_traces(self, request, response_writer):
101102
tracer = self.tracers[sampler_type]
102103
for _ in range(req.get('count', 0)):
103104
span = tracer.start_span(req['operation'])
104-
for k, v in req.get('tags', {}).items():
105+
for k, v in six.iteritems(req.get('tags', {})):
105106
span.set_tag(k, v)
106107
span.finish()
107108
response_writer.finish()

crossdock/server/serializer.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from builtins import str
22
import json
33
import logging
4+
import six
45

56
from crossdock.thrift_gen.tracetest.ttypes import JoinTraceRequest, StartTraceRequest, \
67
Downstream, Transport, TraceResponse, ObservedSpan
@@ -94,7 +95,7 @@ def traced_service_object_to_json(obj):
9495

9596

9697
def set_traced_service_object_values(obj, values, downstream_func):
97-
for k in values.keys():
98+
for k in six.iterkeys(values):
9899
if hasattr(obj, k):
99100
if k == 'downstream':
100101
if values[k] is not None:

crossdock/setup_crossdock.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
]
2121
},
2222
install_requires=[
23-
# all dependencies are included in tchannel already
23+
# most of dependencies are included in tchannel already
24+
'six'
2425
],
2526
)

jaeger_client/codecs.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from builtins import object
2626

2727
import urllib.request, urllib.parse, urllib.error
28+
import six
2829

2930
from opentracing import (
3031
InvalidCarrierException,
@@ -68,7 +69,7 @@ def inject(self, span_context, carrier):
6869
parent_id=span_context.parent_id, flags=span_context.flags)
6970
baggage = span_context.baggage
7071
if baggage:
71-
for key, value in baggage.items():
72+
for key, value in six.iteritems(baggage):
7273
if self.url_encoding:
7374
encoded_value = urllib.parse.quote(value)
7475
else:
@@ -81,7 +82,7 @@ def extract(self, carrier):
8182
trace_id, span_id, parent_id, flags = None, None, None, None
8283
baggage = None
8384
debug_id = None
84-
for key, value in carrier.items():
85+
for key, value in six.iteritems(carrier):
8586
uc_key = key.lower()
8687
if uc_key == self.trace_id_header:
8788
if self.url_encoding:

jaeger_client/sampler.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import logging
2626
import random
2727
import json
28+
import six
2829

2930
from threading import Lock
3031
from tornado.ioloop import PeriodicCallback
@@ -309,7 +310,7 @@ def update(self, strategies):
309310
ProbabilisticSampler(self.default_sampling_probability)
310311

311312
def close(self):
312-
for _, sampler in self.samplers.items():
313+
for _, sampler in six.iteritems(self.samplers):
313314
sampler.close()
314315

315316
def __str__(self):

jaeger_client/span.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import json
2525
import threading
2626
import time
27+
import six
2728

2829
import opentracing
2930
from opentracing.ext import tags as ext_tags
@@ -55,7 +56,7 @@ def __init__(self, context, tracer, operation_name,
5556
self.tags = []
5657
self.logs = []
5758
if tags:
58-
for k, v in tags.items():
59+
for k, v in six.iteritems(tags):
5960
self.set_tag(k, v)
6061

6162
def set_operation_name(self, operation_name):

jaeger_client/tracer.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import time
2727
import logging
2828
import random
29+
import six
2930
import opentracing
3031
from opentracing import Format, UnsupportedFormatException
3132
from opentracing.ext import tags as ext_tags
@@ -132,7 +133,7 @@ def start_span(self,
132133
if sampled:
133134
flags = SAMPLED_FLAG
134135
tags = tags or {}
135-
for k, v in sampler_tags.items():
136+
for k, v in six.iteritems(sampler_tags):
136137
tags[k] = v
137138
else: # have debug id
138139
flags = SAMPLED_FLAG | DEBUG_FLAG
@@ -159,7 +160,7 @@ def start_span(self,
159160

160161
if (rpc_server or not parent_id) and (flags & SAMPLED_FLAG):
161162
# this is a first-in-process span, and is sampled
162-
for k, v in self.tags.items():
163+
for k, v in six.iteritems(self.tags):
163164
span.set_tag(k, v)
164165

165166
self._emit_span_metrics(span=span, join=rpc_server)

setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
install_requires=[
3939
'future',
4040
'futures',
41+
'six',
4142
'threadloop>=1,<2',
4243
'thrift>=0.10.0',
4344
'tornado>=4.3,<5',

tests/test_tracer.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import mock
2222
import random
2323

24+
import six
2425
import pytest
2526
import tornado.httputil
2627

@@ -224,7 +225,7 @@ def test_tracer_tags_on_root_span(span_type, expected_tags):
224225
'child', child_of=span.context,
225226
tags={ext_tags.SPAN_KIND: ext_tags.SPAN_KIND_RPC_SERVER}
226227
)
227-
for key, value in expected_tags.items():
228+
for key, value in six.iteritems(expected_tags):
228229
found_tag = None
229230
for tag in span.tags:
230231
if tag.key == key:

0 commit comments

Comments
 (0)