Skip to content

Commit

Permalink
Merge pull request grpc#5650 from leifurhauks/py3_iteritems
Browse files Browse the repository at this point in the history
replace uses of iteritems with six.iteritems
  • Loading branch information
nicolasnoble committed Mar 21, 2016
2 parents 19e1ea4 + fbe766a commit 62dcaa2
Show file tree
Hide file tree
Showing 16 changed files with 128 additions and 108 deletions.
4 changes: 2 additions & 2 deletions src/python/grpcio/grpc/framework/alpha/_face_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def break_down_invocation(service_name, method_descriptions):
face_cardinalities = {}
request_serializers = {}
response_deserializers = {}
for name, method_description in method_descriptions.iteritems():
for name, method_description in six.iteritems(method_descriptions):
qualified_name = _qualified_name(service_name, name)
method_cardinality = method_description.cardinality()
cardinalities[name] = method_description.cardinality()
Expand Down Expand Up @@ -139,7 +139,7 @@ def break_down_service(service_name, method_descriptions):
implementations = {}
request_deserializers = {}
response_serializers = {}
for name, method_description in method_descriptions.iteritems():
for name, method_description in six.iteritems(method_descriptions):
qualified_name = _qualified_name(service_name, name)
method_cardinality = method_description.cardinality()
if method_cardinality is interfaces.Cardinality.UNARY_UNARY:
Expand Down
6 changes: 4 additions & 2 deletions src/python/grpcio/grpc/framework/alpha/_reexport.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2015, Google Inc.
# Copyright 2015-2016, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -27,6 +27,8 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import six

from grpc.framework.common import cardinality
from grpc.framework.face import exceptions as face_exceptions
from grpc.framework.face import interfaces as face_interfaces
Expand Down Expand Up @@ -181,7 +183,7 @@ def common_cardinality(early_adopter_cardinality):

def common_cardinalities(early_adopter_cardinalities):
common_cardinalities = {}
for name, early_adopter_cardinality in early_adopter_cardinalities.iteritems():
for name, early_adopter_cardinality in six.iteritems(early_adopter_cardinalities):
common_cardinalities[name] = _EARLY_ADOPTER_CARDINALITY_TO_COMMON_CARDINALITY[
early_adopter_cardinality]
return common_cardinalities
Expand Down
6 changes: 4 additions & 2 deletions src/python/grpcio/grpc/framework/crust/implementations.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2015, Google Inc.
# Copyright 2015-2016, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -29,6 +29,8 @@

"""Entry points into the Crust layer of RPC Framework."""

import six

from grpc.framework.common import cardinality
from grpc.framework.common import style
from grpc.framework.crust import _calls
Expand Down Expand Up @@ -271,7 +273,7 @@ def __getattr__(self, attr):

def _adapt_method_implementations(method_implementations, pool):
adapted_implementations = {}
for name, method_implementation in method_implementations.iteritems():
for name, method_implementation in six.iteritems(method_implementations):
if method_implementation.style is style.Service.INLINE:
if method_implementation.cardinality is cardinality.Cardinality.UNARY_UNARY:
adapted_implementations[name] = _service.adapt_inline_unary_unary(
Expand Down
6 changes: 4 additions & 2 deletions src/python/grpcio/grpc/framework/face/implementations.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2015, Google Inc.
# Copyright 2015-2016, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -29,6 +29,8 @@

"""Entry points into the Face layer of RPC Framework."""

import six

from grpc.framework.common import cardinality
from grpc.framework.common import style
from grpc.framework.base import exceptions as _base_exceptions
Expand Down Expand Up @@ -228,7 +230,7 @@ def __getattr__(self, attr):

def _adapt_method_implementations(method_implementations, pool):
adapted_implementations = {}
for name, method_implementation in method_implementations.iteritems():
for name, method_implementation in six.iteritems(method_implementations):
if method_implementation.style is style.Service.INLINE:
if method_implementation.cardinality is cardinality.Cardinality.UNARY_UNARY:
adapted_implementations[name] = _service.adapt_inline_value_in_value_out(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2015, Google Inc.
# Copyright 2015-2016, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -35,6 +35,8 @@
import time
import unittest

import six

from grpc._adapter import _intermediary_low
from grpc._links import invocation
from grpc._links import service
Expand Down Expand Up @@ -68,7 +70,7 @@ def _serialization_behaviors_from_serializations(serializations):
request_deserializers = {}
response_serializers = {}
response_deserializers = {}
for (group, method), serialization in serializations.iteritems():
for (group, method), serialization in six.iteritems(serializations):
request_serializers[group, method] = serialization.serialize_request
request_deserializers[group, method] = serialization.deserialize_request
response_serializers[group, method] = serialization.serialize_response
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2015, Google Inc.
# Copyright 2015-2016, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -32,6 +32,8 @@
import collections
import unittest

import six

from grpc._adapter import _intermediary_low
from grpc._links import invocation
from grpc._links import service
Expand Down Expand Up @@ -59,7 +61,7 @@ def _serialization_behaviors_from_test_methods(test_methods):
request_deserializers = {}
response_serializers = {}
response_deserializers = {}
for (group, method), test_method in test_methods.iteritems():
for (group, method), test_method in six.iteritems(test_methods):
request_serializers[group, method] = test_method.serialize_request
request_deserializers[group, method] = test_method.deserialize_request
response_serializers[group, method] = test_method.serialize_response
Expand Down Expand Up @@ -108,7 +110,7 @@ def instantiate(
# _digest.TestServiceDigest.
cardinalities = {
method: method_object.cardinality()
for (group, method), method_object in methods.iteritems()}
for (group, method), method_object in six.iteritems(methods)}
dynamic_stub = crust_implementations.dynamic_stub(
invocation_end_link, group, cardinalities, pool)

Expand Down
8 changes: 5 additions & 3 deletions src/python/grpcio/tests/unit/beta/_face_interface_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2015, Google Inc.
# Copyright 2015-2016, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -32,6 +32,8 @@
import collections
import unittest

import six

from grpc.beta import implementations
from grpc.beta import interfaces
from tests.unit import resources
Expand All @@ -57,7 +59,7 @@ def _serialization_behaviors_from_test_methods(test_methods):
request_deserializers = {}
response_serializers = {}
response_deserializers = {}
for (group, method), test_method in test_methods.iteritems():
for (group, method), test_method in six.iteritems(test_methods):
request_serializers[group, method] = test_method.serialize_request
request_deserializers[group, method] = test_method.deserialize_request
response_serializers[group, method] = test_method.serialize_response
Expand All @@ -79,7 +81,7 @@ def instantiate(
# _digest.TestServiceDigest.
cardinalities = {
method: method_object.cardinality()
for (group, method), method_object in methods.iteritems()}
for (group, method), method_object in six.iteritems(methods)}

server_options = implementations.server_options(
request_deserializers=serialization_behaviors.request_deserializers,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2015, Google Inc.
# Copyright 2015-2016, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -32,6 +32,8 @@
import collections
import unittest

import six

from grpc.framework.core import implementations as core_implementations
from grpc.framework.crust import implementations as crust_implementations
from grpc.framework.foundation import logging_pool
Expand Down Expand Up @@ -66,7 +68,7 @@ def instantiate(
# _digest.TestServiceDigest.
cardinalities = {
method: method_object.cardinality()
for (group, method), method_object in methods.iteritems()}
for (group, method), method_object in six.iteritems(methods)}
dynamic_stub = crust_implementations.dynamic_stub(
invocation_end_link, group, cardinalities, pool)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def tearDown(self):

def testSuccessfulUnaryRequestUnaryResponse(self):
for name, test_messages_sequence in (
self.digest.unary_unary_messages_sequences.iteritems()):
six.iteritems(self.digest.unary_unary_messages_sequences)):
for test_messages in test_messages_sequence:
request = test_messages.request()

Expand All @@ -85,7 +85,7 @@ def testSuccessfulUnaryRequestUnaryResponse(self):

def testSuccessfulUnaryRequestStreamResponse(self):
for name, test_messages_sequence in (
self.digest.unary_stream_messages_sequences.iteritems()):
six.iteritems(self.digest.unary_stream_messages_sequences)):
for test_messages in test_messages_sequence:
request = test_messages.request()

Expand All @@ -97,7 +97,7 @@ def testSuccessfulUnaryRequestStreamResponse(self):

def testSuccessfulStreamRequestUnaryResponse(self):
for name, test_messages_sequence in (
self.digest.stream_unary_messages_sequences.iteritems()):
six.iteritems(self.digest.stream_unary_messages_sequences)):
for test_messages in test_messages_sequence:
requests = test_messages.requests()

Expand All @@ -108,7 +108,7 @@ def testSuccessfulStreamRequestUnaryResponse(self):

def testSuccessfulStreamRequestStreamResponse(self):
for name, test_messages_sequence in (
self.digest.stream_stream_messages_sequences.iteritems()):
six.iteritems(self.digest.stream_stream_messages_sequences)):
for test_messages in test_messages_sequence:
requests = test_messages.requests()

Expand All @@ -120,7 +120,7 @@ def testSuccessfulStreamRequestStreamResponse(self):

def testSequentialInvocations(self):
for name, test_messages_sequence in (
self.digest.unary_unary_messages_sequences.iteritems()):
six.iteritems(self.digest.unary_unary_messages_sequences)):
for test_messages in test_messages_sequence:
first_request = test_messages.request()
second_request = test_messages.request()
Expand All @@ -137,7 +137,7 @@ def testSequentialInvocations(self):

def testExpiredUnaryRequestUnaryResponse(self):
for name, test_messages_sequence in (
self.digest.unary_unary_messages_sequences.iteritems()):
six.iteritems(self.digest.unary_unary_messages_sequences)):
for test_messages in test_messages_sequence:
request = test_messages.request()

Expand All @@ -148,7 +148,7 @@ def testExpiredUnaryRequestUnaryResponse(self):

def testExpiredUnaryRequestStreamResponse(self):
for name, test_messages_sequence in (
self.digest.unary_stream_messages_sequences.iteritems()):
six.iteritems(self.digest.unary_stream_messages_sequences)):
for test_messages in test_messages_sequence:
request = test_messages.request()

Expand All @@ -160,7 +160,7 @@ def testExpiredUnaryRequestStreamResponse(self):

def testExpiredStreamRequestUnaryResponse(self):
for name, test_messages_sequence in (
self.digest.stream_unary_messages_sequences.iteritems()):
six.iteritems(self.digest.stream_unary_messages_sequences)):
for test_messages in test_messages_sequence:
requests = test_messages.requests()

Expand All @@ -171,7 +171,7 @@ def testExpiredStreamRequestUnaryResponse(self):

def testExpiredStreamRequestStreamResponse(self):
for name, test_messages_sequence in (
self.digest.stream_stream_messages_sequences.iteritems()):
six.iteritems(self.digest.stream_stream_messages_sequences)):
for test_messages in test_messages_sequence:
requests = test_messages.requests()

Expand All @@ -183,7 +183,7 @@ def testExpiredStreamRequestStreamResponse(self):

def testFailedUnaryRequestUnaryResponse(self):
for name, test_messages_sequence in (
self.digest.unary_unary_messages_sequences.iteritems()):
six.iteritems(self.digest.unary_unary_messages_sequences)):
for test_messages in test_messages_sequence:
request = test_messages.request()

Expand All @@ -193,7 +193,7 @@ def testFailedUnaryRequestUnaryResponse(self):

def testFailedUnaryRequestStreamResponse(self):
for name, test_messages_sequence in (
self.digest.unary_stream_messages_sequences.iteritems()):
six.iteritems(self.digest.unary_stream_messages_sequences)):
for test_messages in test_messages_sequence:
request = test_messages.request()

Expand All @@ -204,7 +204,7 @@ def testFailedUnaryRequestStreamResponse(self):

def testFailedStreamRequestUnaryResponse(self):
for name, test_messages_sequence in (
self.digest.stream_unary_messages_sequences.iteritems()):
six.iteritems(self.digest.stream_unary_messages_sequences)):
for test_messages in test_messages_sequence:
requests = test_messages.requests()

Expand All @@ -214,7 +214,7 @@ def testFailedStreamRequestUnaryResponse(self):

def testFailedStreamRequestStreamResponse(self):
for name, test_messages_sequence in (
self.digest.stream_stream_messages_sequences.iteritems()):
six.iteritems(self.digest.stream_stream_messages_sequences)):
for test_messages in test_messages_sequence:
requests = test_messages.requests()

Expand Down
6 changes: 4 additions & 2 deletions src/python/grpcio/tests/unit/framework/face/testing/digest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2015, Google Inc.
# Copyright 2015-2016, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -32,6 +32,8 @@
import collections
import threading

import six

# testing_control, interfaces, and testing_service are referenced from
# specification in this module.
from grpc.framework.common import cardinality
Expand Down Expand Up @@ -368,7 +370,7 @@ def _assemble(
events = {}
adaptations = {}
messages = {}
for name, scenario in scenarios.iteritems():
for name, scenario in six.iteritems(scenarios):
if name in names:
raise ValueError('Repeated name "%s"!' % name)

Expand Down
Loading

0 comments on commit 62dcaa2

Please sign in to comment.