Skip to content

Commit edd9178

Browse files
authored
Merge pull request #2703 from dhermes/connection-non-public
Making base connection module non-public and making connection attribute non-public
2 parents b39c0ba + 0bc8caf commit edd9178

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

packages/google-cloud-translate/google/cloud/translate/client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def __init__(self, api_key, http=None, target_language=ENGLISH_ISO_639):
4747
self.api_key = api_key
4848
if http is None:
4949
http = httplib2.Http()
50-
self.connection = Connection(http=http)
50+
self._connection = Connection(http=http)
5151
self.target_language = target_language
5252

5353
def get_languages(self, target_language=None):
@@ -75,7 +75,7 @@ def get_languages(self, target_language=None):
7575
target_language = self.target_language
7676
if target_language is not None:
7777
query_params['target'] = target_language
78-
response = self.connection.api_request(
78+
response = self._connection.api_request(
7979
method='GET', path='/languages', query_params=query_params)
8080
return response.get('data', {}).get('languages', ())
8181

@@ -117,7 +117,7 @@ def detect_language(self, values):
117117
query_params = [('key', self.api_key)]
118118
query_params.extend(('q', _to_bytes(value, 'utf-8'))
119119
for value in values)
120-
response = self.connection.api_request(
120+
response = self._connection.api_request(
121121
method='GET', path='/detect', query_params=query_params)
122122
detections = response.get('data', {}).get('detections', ())
123123

@@ -208,7 +208,7 @@ def translate(self, values, target_language=None, format_=None,
208208
if source_language is not None:
209209
query_params.append(('source', source_language))
210210

211-
response = self.connection.api_request(
211+
response = self._connection.api_request(
212212
method='GET', path='', query_params=query_params)
213213

214214
translations = response.get('data', {}).get('translations', ())

packages/google-cloud-translate/google/cloud/translate/connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

1515
"""Create / interact with Google Cloud Translate connections."""
1616

17-
from google.cloud import connection as base_connection
17+
from google.cloud import _http
1818

1919

20-
class Connection(base_connection.JSONConnection):
20+
class Connection(_http.JSONConnection):
2121
"""A connection to Google Cloud Translate via the JSON REST API."""
2222

2323
API_BASE_URL = 'https://www.googleapis.com'

packages/google-cloud-translate/unit_tests/test_client.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ def test_ctor(self):
3333

3434
http = object()
3535
client = self._make_one(self.KEY, http=http)
36-
self.assertIsInstance(client.connection, Connection)
37-
self.assertIsNone(client.connection.credentials)
38-
self.assertIs(client.connection.http, http)
36+
self.assertIsInstance(client._connection, Connection)
37+
self.assertIsNone(client._connection.credentials)
38+
self.assertIs(client._connection.http, http)
3939
self.assertEqual(client.target_language, ENGLISH_ISO_639)
4040

4141
def test_ctor_non_default(self):
@@ -44,9 +44,9 @@ def test_ctor_non_default(self):
4444
http = object()
4545
target = 'es'
4646
client = self._make_one(self.KEY, http=http, target_language=target)
47-
self.assertIsInstance(client.connection, Connection)
48-
self.assertIsNone(client.connection.credentials)
49-
self.assertIs(client.connection.http, http)
47+
self.assertIsInstance(client._connection, Connection)
48+
self.assertIsNone(client._connection.credentials)
49+
self.assertIs(client._connection.http, http)
5050
self.assertEqual(client.target_language, target)
5151

5252
def test_get_languages(self):
@@ -63,7 +63,7 @@ def test_get_languages(self):
6363
'languages': supported,
6464
},
6565
}
66-
conn = client.connection = _Connection(data)
66+
conn = client._connection = _Connection(data)
6767

6868
result = client.get_languages()
6969
self.assertEqual(result, supported)
@@ -88,7 +88,7 @@ def test_get_languages_no_target(self):
8888
'languages': supported,
8989
},
9090
}
91-
conn = client.connection = _Connection(data)
91+
conn = client._connection = _Connection(data)
9292

9393
result = client.get_languages()
9494
self.assertEqual(result, supported)
@@ -113,7 +113,7 @@ def test_get_languages_explicit_target(self):
113113
'languages': supported,
114114
},
115115
}
116-
conn = client.connection = _Connection(data)
116+
conn = client._connection = _Connection(data)
117117

118118
result = client.get_languages(target_language)
119119
self.assertEqual(result, supported)
@@ -129,7 +129,7 @@ def test_get_languages_explicit_target(self):
129129
def test_detect_language_bad_result(self):
130130
client = self._make_one(self.KEY)
131131
value = 'takoy'
132-
conn = client.connection = _Connection({})
132+
conn = client._connection = _Connection({})
133133

134134
with self.assertRaises(ValueError):
135135
client.detect_language(value)
@@ -159,7 +159,7 @@ def test_detect_language_single_value(self):
159159
'detections': [[detection]],
160160
},
161161
}
162-
conn = client.connection = _Connection(data)
162+
conn = client._connection = _Connection(data)
163163

164164
result = client.detect_language(value)
165165
self.assertEqual(result, detection)
@@ -199,7 +199,7 @@ def test_detect_language_multiple_values(self):
199199
],
200200
},
201201
}
202-
conn = client.connection = _Connection(data)
202+
conn = client._connection = _Connection(data)
203203

204204
result = client.detect_language([value1, value2])
205205
self.assertEqual(result, [detection1, detection2])
@@ -236,15 +236,15 @@ def test_detect_language_multiple_results(self):
236236
'detections': [[detection1, detection2]],
237237
},
238238
}
239-
client.connection = _Connection(data)
239+
client._connection = _Connection(data)
240240

241241
with self.assertRaises(ValueError):
242242
client.detect_language(value)
243243

244244
def test_translate_bad_result(self):
245245
client = self._make_one(self.KEY)
246246
value = 'hvala ti'
247-
conn = client.connection = _Connection({})
247+
conn = client._connection = _Connection({})
248248

249249
with self.assertRaises(ValueError):
250250
client.translate(value)
@@ -274,7 +274,7 @@ def test_translate_defaults(self):
274274
'translations': [translation],
275275
},
276276
}
277-
conn = client.connection = _Connection(data)
277+
conn = client._connection = _Connection(data)
278278

279279
result = client.translate(value)
280280
self.assertEqual(result, translation)
@@ -310,7 +310,7 @@ def test_translate_multiple(self):
310310
'translations': [translation1, translation2],
311311
},
312312
}
313-
conn = client.connection = _Connection(data)
313+
conn = client._connection = _Connection(data)
314314

315315
result = client.translate([value1, value2])
316316
self.assertEqual(result, [translation1, translation2])
@@ -342,7 +342,7 @@ def test_translate_explicit(self):
342342
'translations': [translation],
343343
},
344344
}
345-
conn = client.connection = _Connection(data)
345+
conn = client._connection = _Connection(data)
346346

347347
cid = '123'
348348
format_ = 'text'

0 commit comments

Comments
 (0)