Skip to content

Commit

Permalink
Merge pull request #2703 from dhermes/connection-non-public
Browse files Browse the repository at this point in the history
Making base connection module non-public and making connection attribute non-public
  • Loading branch information
dhermes authored Nov 11, 2016
2 parents 0291dd4 + 523d751 commit 1157488
Show file tree
Hide file tree
Showing 99 changed files with 453 additions and 473 deletions.
4 changes: 2 additions & 2 deletions bigquery/google/cloud/bigquery/_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

"""Create / interact with Google BigQuery connections."""

from google.cloud import connection as base_connection
from google.cloud import _http


class Connection(base_connection.JSONConnection):
class Connection(_http.JSONConnection):
"""A connection to Google BigQuery via the JSON REST API."""

API_BASE_URL = 'https://www.googleapis.com'
Expand Down
14 changes: 7 additions & 7 deletions bigquery/google/cloud/bigquery/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ def create(self, client=None):
"""
client = self._require_client(client)
path = '/projects/%s/datasets' % (self.project,)
api_response = client.connection.api_request(
api_response = client._connection.api_request(
method='POST', path=path, data=self._build_resource())
self._set_properties(api_response)

Expand All @@ -443,8 +443,8 @@ def exists(self, client=None):
client = self._require_client(client)

try:
client.connection.api_request(method='GET', path=self.path,
query_params={'fields': 'id'})
client._connection.api_request(method='GET', path=self.path,
query_params={'fields': 'id'})
except NotFound:
return False
else:
Expand All @@ -463,7 +463,7 @@ def reload(self, client=None):
"""
client = self._require_client(client)

api_response = client.connection.api_request(
api_response = client._connection.api_request(
method='GET', path=self.path)
self._set_properties(api_response)

Expand Down Expand Up @@ -502,7 +502,7 @@ def patch(self, client=None, **kw):
if 'location' in kw:
partial['location'] = kw['location']

api_response = client.connection.api_request(
api_response = client._connection.api_request(
method='PATCH', path=self.path, data=partial)
self._set_properties(api_response)

Expand All @@ -518,7 +518,7 @@ def update(self, client=None):
``client`` stored on the current dataset.
"""
client = self._require_client(client)
api_response = client.connection.api_request(
api_response = client._connection.api_request(
method='PUT', path=self.path, data=self._build_resource())
self._set_properties(api_response)

Expand All @@ -534,7 +534,7 @@ def delete(self, client=None):
``client`` stored on the current dataset.
"""
client = self._require_client(client)
client.connection.api_request(method='DELETE', path=self.path)
client._connection.api_request(method='DELETE', path=self.path)

def list_tables(self, max_results=None, page_token=None):
"""List tables for the project associated with this client.
Expand Down
10 changes: 5 additions & 5 deletions bigquery/google/cloud/bigquery/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def begin(self, client=None):

client = self._require_client(client)
path = '/projects/%s/jobs' % (self.project,)
api_response = client.connection.api_request(
api_response = client._connection.api_request(
method='POST', path=path, data=self._build_resource())
self._set_properties(api_response)

Expand All @@ -337,8 +337,8 @@ def exists(self, client=None):
client = self._require_client(client)

try:
client.connection.api_request(method='GET', path=self.path,
query_params={'fields': 'id'})
client._connection.api_request(method='GET', path=self.path,
query_params={'fields': 'id'})
except NotFound:
return False
else:
Expand All @@ -357,7 +357,7 @@ def reload(self, client=None):
"""
client = self._require_client(client)

api_response = client.connection.api_request(
api_response = client._connection.api_request(
method='GET', path=self.path)
self._set_properties(api_response)

Expand All @@ -374,7 +374,7 @@ def cancel(self, client=None):
"""
client = self._require_client(client)

api_response = client.connection.api_request(
api_response = client._connection.api_request(
method='POST', path='%s/cancel' % (self.path,))
self._set_properties(api_response['job'])

Expand Down
8 changes: 4 additions & 4 deletions bigquery/google/cloud/bigquery/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def run(self, client=None):

client = self._require_client(client)
path = '/projects/%s/queries' % (self.project,)
api_response = client.connection.api_request(
api_response = client._connection.api_request(
method='POST', path=path, data=self._build_resource())
self._set_properties(api_response)

Expand Down Expand Up @@ -392,9 +392,9 @@ def fetch_data(self, max_results=None, page_token=None, start_index=None,
params['timeoutMs'] = timeout_ms

path = '/projects/%s/queries/%s' % (self.project, self.name)
response = client.connection.api_request(method='GET',
path=path,
query_params=params)
response = client._connection.api_request(method='GET',
path=path,
query_params=params)
self._set_properties(response)

total_rows = response.get('totalRows')
Expand Down
18 changes: 9 additions & 9 deletions bigquery/google/cloud/bigquery/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ def create(self, client=None):
client = self._require_client(client)
path = '/projects/%s/datasets/%s/tables' % (
self._dataset.project, self._dataset.name)
api_response = client.connection.api_request(
api_response = client._connection.api_request(
method='POST', path=path, data=self._build_resource())
self._set_properties(api_response)

Expand All @@ -513,8 +513,8 @@ def exists(self, client=None):
client = self._require_client(client)

try:
client.connection.api_request(method='GET', path=self.path,
query_params={'fields': 'id'})
client._connection.api_request(method='GET', path=self.path,
query_params={'fields': 'id'})
except NotFound:
return False
else:
Expand All @@ -533,7 +533,7 @@ def reload(self, client=None):
"""
client = self._require_client(client)

api_response = client.connection.api_request(
api_response = client._connection.api_request(
method='GET', path=self.path)
self._set_properties(api_response)

Expand Down Expand Up @@ -608,7 +608,7 @@ def patch(self,
partial['schema'] = {
'fields': _build_schema_resource(schema)}

api_response = client.connection.api_request(
api_response = client._connection.api_request(
method='PATCH', path=self.path, data=partial)
self._set_properties(api_response)

Expand All @@ -624,7 +624,7 @@ def update(self, client=None):
``client`` stored on the current dataset.
"""
client = self._require_client(client)
api_response = client.connection.api_request(
api_response = client._connection.api_request(
method='PUT', path=self.path, data=self._build_resource())
self._set_properties(api_response)

Expand All @@ -640,7 +640,7 @@ def delete(self, client=None):
``client`` stored on the current dataset.
"""
client = self._require_client(client)
client.connection.api_request(method='DELETE', path=self.path)
client._connection.api_request(method='DELETE', path=self.path)

def fetch_data(self, max_results=None, page_token=None, client=None):
"""API call: fetch the table data via a GET request
Expand Down Expand Up @@ -764,7 +764,7 @@ def insert_data(self,
if template_suffix is not None:
data['templateSuffix'] = template_suffix

response = client.connection.api_request(
response = client._connection.api_request(
method='POST',
path='%s/insertAll' % self.path,
data=data)
Expand Down Expand Up @@ -885,7 +885,7 @@ def upload_from_file(self,
a file opened in text mode.
"""
client = self._require_client(client)
connection = client.connection
connection = client._connection
content_type = 'application/octet-stream'

# Rewind the file if desired.
Expand Down
20 changes: 10 additions & 10 deletions bigquery/unit_tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ def test_ctor(self):
creds = _Credentials()
http = object()
client = self._make_one(project=PROJECT, credentials=creds, http=http)
self.assertIsInstance(client.connection, Connection)
self.assertIs(client.connection.credentials, creds)
self.assertIs(client.connection.http, http)
self.assertIsInstance(client._connection, Connection)
self.assertIs(client._connection.credentials, creds)
self.assertIs(client._connection.http, http)

def test_list_projects_defaults(self):
import six
Expand All @@ -59,7 +59,7 @@ def test_list_projects_defaults(self):
}
creds = _Credentials()
client = self._make_one(PROJECT_1, creds)
conn = client.connection = _Connection(DATA)
conn = client._connection = _Connection(DATA)

iterator = client.list_projects()
page = six.next(iterator.pages)
Expand Down Expand Up @@ -88,7 +88,7 @@ def test_list_projects_explicit_response_missing_projects_key(self):
DATA = {}
creds = _Credentials()
client = self._make_one(PROJECT, creds)
conn = client.connection = _Connection(DATA)
conn = client._connection = _Connection(DATA)

iterator = client.list_projects(max_results=3, page_token=TOKEN)
page = six.next(iterator.pages)
Expand Down Expand Up @@ -130,7 +130,7 @@ def test_list_datasets_defaults(self):
}
creds = _Credentials()
client = self._make_one(PROJECT, creds)
conn = client.connection = _Connection(DATA)
conn = client._connection = _Connection(DATA)

iterator = client.list_datasets()
page = six.next(iterator.pages)
Expand Down Expand Up @@ -158,7 +158,7 @@ def test_list_datasets_explicit_response_missing_datasets_key(self):
DATA = {}
creds = _Credentials()
client = self._make_one(PROJECT, creds)
conn = client.connection = _Connection(DATA)
conn = client._connection = _Connection(DATA)

iterator = client.list_datasets(
include_all=True, max_results=3, page_token=TOKEN)
Expand Down Expand Up @@ -306,7 +306,7 @@ def test_list_jobs_defaults(self):
}
creds = _Credentials()
client = self._make_one(PROJECT, creds)
conn = client.connection = _Connection(DATA)
conn = client._connection = _Connection(DATA)

iterator = client.list_jobs()
page = six.next(iterator.pages)
Expand Down Expand Up @@ -362,7 +362,7 @@ def test_list_jobs_load_job_wo_sourceUris(self):
}
creds = _Credentials()
client = self._make_one(PROJECT, creds)
conn = client.connection = _Connection(DATA)
conn = client._connection = _Connection(DATA)

iterator = client.list_jobs()
page = six.next(iterator.pages)
Expand Down Expand Up @@ -390,7 +390,7 @@ def test_list_jobs_explicit_missing(self):
TOKEN = 'TOKEN'
creds = _Credentials()
client = self._make_one(PROJECT, creds)
conn = client.connection = _Connection(DATA)
conn = client._connection = _Connection(DATA)

iterator = client.list_jobs(max_results=1000, page_token=TOKEN,
all_users=True, state_filter='done')
Expand Down
2 changes: 1 addition & 1 deletion bigquery/unit_tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ class _Client(object):

def __init__(self, project='project', connection=None):
self.project = project
self.connection = connection
self._connection = connection


class _Connection(object):
Expand Down
2 changes: 1 addition & 1 deletion bigquery/unit_tests/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -1648,7 +1648,7 @@ class _Client(object):

def __init__(self, project='project', connection=None):
self.project = project
self.connection = connection
self._connection = connection

def dataset(self, name):
from google.cloud.bigquery.dataset import Dataset
Expand Down
2 changes: 1 addition & 1 deletion bigquery/unit_tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ class _Client(object):

def __init__(self, project='project', connection=None):
self.project = project
self.connection = connection
self._connection = connection

def dataset(self, name):
from google.cloud.bigquery.dataset import Dataset
Expand Down
2 changes: 1 addition & 1 deletion bigquery/unit_tests/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -1880,7 +1880,7 @@ class _Client(object):

def __init__(self, project='project', connection=None):
self.project = project
self.connection = connection
self._connection = connection

def job_from_resource(self, resource): # pylint: disable=unused-argument
return self._job
Expand Down
2 changes: 1 addition & 1 deletion bigtable/google/cloud/bigtable/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
from google.cloud.bigtable.instance import _EXISTING_INSTANCE_LOCATION_ID
from google.cloud.client import _ClientFactoryMixin
from google.cloud.client import _ClientProjectMixin
from google.cloud.connection import DEFAULT_USER_AGENT
from google.cloud._http import DEFAULT_USER_AGENT
from google.cloud.credentials import get_credentials
from google.cloud.environment_vars import BIGTABLE_EMULATOR

Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions core/google/cloud/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import six

from google.cloud._helpers import _determine_default_project
from google.cloud.connection import Connection
from google.cloud._http import Connection
from google.cloud.credentials import get_credentials


Expand Down Expand Up @@ -120,7 +120,7 @@ class Client(_ClientFactoryMixin):
def __init__(self, credentials=None, http=None):
if credentials is None and http is None:
credentials = get_credentials()
self.connection = self._connection_class(
self._connection = self._connection_class(
credentials=credentials, http=http)


Expand Down
4 changes: 2 additions & 2 deletions core/google/cloud/iterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,12 +382,12 @@ def _get_next_page_response(self):
"""
params = self._get_query_params()
if self._HTTP_METHOD == 'GET':
return self.client.connection.api_request(
return self.client._connection.api_request(
method=self._HTTP_METHOD,
path=self.path,
query_params=params)
elif self._HTTP_METHOD == 'POST':
return self.client.connection.api_request(
return self.client._connection.api_request(
method=self._HTTP_METHOD,
path=self.path,
data=params)
Expand Down
4 changes: 2 additions & 2 deletions core/google/cloud/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class Operation(object):
:type client: :class:`~google.cloud.client.Client`
:param client: The client used to poll for the status of the operation.
If the operation was created via JSON/HTTP, the client
must own a :class:`~google.cloud.connection.Connection`
must own a :class:`~google.cloud._http.Connection`
to send polling requests. If created via protobuf, the
client must have a gRPC stub in the ``_operations_stub``
attribute.
Expand Down Expand Up @@ -218,7 +218,7 @@ def _get_operation_http(self):
:returns: The latest status of the current operation.
"""
path = 'operations/%s' % (self.name,)
api_response = self.client.connection.api_request(
api_response = self.client._connection.api_request(
method='GET', path=path)
return json_format.ParseDict(
api_response, operations_pb2.Operation())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class TestConnection(unittest.TestCase):

@staticmethod
def _get_target_class():
from google.cloud.connection import Connection
from google.cloud._http import Connection

return Connection

def _make_one(self, *args, **kw):
Expand Down Expand Up @@ -111,7 +112,8 @@ class TestJSONConnection(unittest.TestCase):

@staticmethod
def _get_target_class():
from google.cloud.connection import JSONConnection
from google.cloud._http import JSONConnection

return JSONConnection

def _make_one(self, *args, **kw):
Expand Down
Loading

0 comments on commit 1157488

Please sign in to comment.