Skip to content

Commit

Permalink
Replaces single quotations and doc strings to double quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
wb36499 committed Apr 16, 2024
1 parent d22514a commit 3bc37ce
Show file tree
Hide file tree
Showing 28 changed files with 1,133 additions and 1,133 deletions.
10 changes: 5 additions & 5 deletions src/fishbowl/fishbowl.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def _generate_operations(self) -> str:

operation_summaries = sorted(operation_summaries, key=lambda op: op["name"])

op_names = [op['name'] for op in operation_summaries]
op_names = [op["name"] for op in operation_summaries]

imports = self._generate_import_strings(op_names)

Expand Down Expand Up @@ -221,7 +221,7 @@ def _generate_import_strings(self,
List of import strings e.g. `from gafferpy.gaffer_binaryoperators import BinaryOperator`
"""
get_field_types = self._get_function_dict()['get_field_types']
get_field_types = self._get_function_dict()["get_field_types"]

class_names = [func.split(".")[-1] for func in funcs]

Expand All @@ -232,20 +232,20 @@ def _generate_import_strings(self,
for func in funcs:
for java_type in get_field_types(func).values():
python_type = parse_java_type_to_string(java_type)
if 'gafferpy' not in python_type:
if "gafferpy" not in python_type:
continue

gafferpy_import = re.findall("gafferpy[\\w+ \\.]*", python_type)[0]
gafferpy_import = gafferpy_import.replace("generated_api.", "gaffer_")
import_parts = gafferpy_import.split('.')
import_parts = gafferpy_import.split(".")
module = ".".join(import_parts[:-1])
_class = import_parts[-1]
# only import classes not already defined in the file in question
if _class not in class_names:
import_map[module].add(_class)

return [
f"from {import_path} import {', '.join(sorted(classes))}" for import_path,
f"from {import_path} import {", ".join(sorted(classes))}" for import_path,
classes in import_map.items()
]

Expand Down
12 changes: 6 additions & 6 deletions src/gafferpy/client/base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@
#

class BaseClient:
'''
"""
This class handles the connection to a Gaffer server and handles operations.
This class is initialised with a host to connect to.
'''
"""

def __init__(self, base_url, verbose=False, headers={}, **kwargs):
'''
"""
This initialiser sets up a connection to the specified Gaffer server.
The host (and port) of the Gaffer server, should be in the form,
'hostname:1234/service-name/version'
'''
"hostname:1234/service-name/version"
"""
self.base_url = base_url
self.verbose = verbose
self.headers = headers
self.headers.setdefault('Content-Type', 'application/json;charset=utf-8')
self.headers.setdefault("Content-Type", "application/json;charset=utf-8")

def perform_request(self, method, target, headers=None, body=None, json_result=True):
raise NotImplementedError()
Expand Down
6 changes: 3 additions & 3 deletions src/gafferpy/client/pki_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@

class PkiClient(UrllibClient):
def __init__(self, base_url, verbose=False, headers={}, **kwargs):
'''
"""
This initialiser sets up a connection to the specified Gaffer server.
The host (and port) of the Gaffer server, should be in the form,
'hostname:1234/service-name/version'
'''
"hostname:1234/service-name/version"
"""
super().__init__(base_url, verbose, headers, **kwargs)

# Fail if none pki, protocol None
Expand Down
18 changes: 9 additions & 9 deletions src/gafferpy/client/requests_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
_REQUESTS_AVAILABLE = True

class SSLAdapter(HTTPAdapter):
'''
"""
A subclass of the HTTPS Transport Adapter that is used to
setup an arbitrary SSL version for the requests session.
'''
"""

def __init__(self, ssl_version=None, **kwargs):
self.ssl_version = ssl_version
Expand All @@ -48,10 +48,10 @@ def init_poolmanager(self, connections, maxsize, block=False):


class RequestsClient(BaseClient):
'''
"""
This class handles the connection to a Gaffer server and handles operations.
This class is initialised with a host to connect to.
'''
"""

def __init__(self, base_url, verbose=False, headers={}, **kwargs):
if not _REQUESTS_AVAILABLE:
Expand All @@ -70,7 +70,7 @@ def __init__(self, base_url, verbose=False, headers={}, **kwargs):
self._session.verify = kwargs.get("verify", True)
self._session.proxies = kwargs.get("proxies", {})
protocol = kwargs.get("protocol", None)
self._session.mount('https://', SSLAdapter(ssl_version=protocol))
self._session.mount("https://", SSLAdapter(ssl_version=protocol))

def perform_request(self, method, target, headers=None, body=None, json_result=True):
url = self.base_url + target
Expand All @@ -85,7 +85,7 @@ def perform_request(self, method, target, headers=None, body=None, json_result=T
response.raise_for_status()
except requests.exceptions.HTTPError as error:
raise ConnectionError(
'HTTP error ' + str(error.response.status_code) + ': ' + error.response.text)
"HTTP error " + str(error.response.status_code) + ": " + error.response.text)

if not json_result and method == "GET":
return response.text
Expand All @@ -96,10 +96,10 @@ def perform_request(self, method, target, headers=None, body=None, json_result=T
response_json = response.text

if self.verbose:
print('\nQuery response:\n' +
json.dumps(response_json, indent=4) + '\n')
print("\nQuery response:\n" +
json.dumps(response_json, indent=4) + "\n")

if response_json is not None and response_json != '':
if response_json is not None and response_json != "":
result = response_json
else:
result = None
Expand Down
24 changes: 12 additions & 12 deletions src/gafferpy/client/urllib_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@


class UrllibClient(BaseClient):
'''
"""
This class handles the connection to a Gaffer server and handles operations.
This class is initialised with a host to connect to.
'''
"""

def __init__(self, base_url, verbose=False, headers={}, **kwargs):
'''
"""
This initialiser sets up a connection to the specified Gaffer server.
The host (and port) of the Gaffer server, should be in the form,
'hostname:1234/service-name/version'
'''
"hostname:1234/service-name/version"
"""
super().__init__(base_url, verbose, headers, **kwargs)

# Create the opener
Expand All @@ -52,22 +52,22 @@ def perform_request(self, method, target, headers=None, body=None, json_result=T
try:
response = self._opener.open(request)
except urllib.error.HTTPError as error:
error_body = error.read().decode('utf-8')
new_error_string = ('HTTP error ' +
str(error.code) + ' ' +
error.reason + ': ' +
error_body = error.read().decode("utf-8")
new_error_string = ("HTTP error " +
str(error.code) + " " +
error.reason + ": " +
error_body)
raise ConnectionError(new_error_string)

response_text = response.read().decode('utf-8')
response_text = response.read().decode("utf-8")

if not json_result and method == "GET":
return response_text

if self.verbose:
print('Query response: ' + response_text)
print("Query response: " + response_text)

if response_text is not None and response_text != '':
if response_text is not None and response_text != "":
result = json.loads(response_text)
else:
result = None
Expand Down
4 changes: 2 additions & 2 deletions src/gafferpy/fromJson.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

if __name__ == "__main__":
if len(sys.argv) < 2:
raise TypeError('JSON str argument is required')
raise TypeError("JSON str argument is required")

json_str = sys.argv[1]
if len(sys.argv) > 2:
Expand All @@ -31,6 +31,6 @@
pythonObj = g.JsonConverter.from_json(json_str,
class_name=class_name)
if not isinstance(pythonObj, g.ToCodeString):
raise TypeError('Unable to convert JSON to a Python: ' + json_str)
raise TypeError("Unable to convert JSON to a Python: " + json_str)

print(pythonObj.to_code_string())
20 changes: 10 additions & 10 deletions src/gafferpy/gaffer_binaryoperators.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ def __init__(self, selection=None, binary_operator=None):
def to_json(self):
function_json = {}
if self.selection is not None:
function_json['selection'] = self.selection
function_json["selection"] = self.selection
if self.binary_operator is not None:
function_json['binaryOperator'] = self.binary_operator.to_json()
function_json["binaryOperator"] = self.binary_operator.to_json()

return function_json

Expand All @@ -46,25 +46,25 @@ def to_json(self):


def binary_operator_context_converter(obj):
if 'class' in obj:
if "class" in obj:
binary_operator = dict(obj)
else:
binary_operator = obj['binary_operator']
binary_operator = obj["binary_operator"]
if isinstance(binary_operator, dict):
binary_operator = dict(binary_operator)

if not isinstance(binary_operator, BinaryOperator):
binary_operator = JsonConverter.from_json(binary_operator)
if not isinstance(binary_operator, BinaryOperator):
class_name = binary_operator.get('class')
binary_operator.pop('class', None)
class_name = binary_operator.get("class")
binary_operator.pop("class", None)
binary_operator = BinaryOperator(
class_name=class_name,
fields=binary_operator
)

return BinaryOperatorContext(
selection=obj.get('selection'),
selection=obj.get("selection"),
binary_operator=binary_operator
)

Expand All @@ -78,8 +78,8 @@ def binary_operator_converter(obj):
if not isinstance(binary_operator, BinaryOperator):
binary_operator = JsonConverter.from_json(binary_operator)
if not isinstance(binary_operator, BinaryOperator):
class_name = binary_operator.get('class')
binary_operator.pop('class', None)
class_name = binary_operator.get("class")
binary_operator.pop("class", None)
binary_operator = BinaryOperator(
class_name=class_name,
fields=binary_operator
Expand All @@ -91,7 +91,7 @@ def binary_operator_converter(obj):
def load_binaryoperator_json_map():
for name, class_obj in inspect.getmembers(
sys.modules[__name__], inspect.isclass):
if hasattr(class_obj, 'CLASS'):
if hasattr(class_obj, "CLASS"):
JsonConverter.GENERIC_JSON_CONVERTERS[class_obj.CLASS] = \
lambda obj, class_obj=class_obj: class_obj(**obj)
JsonConverter.CLASS_MAP[class_obj.CLASS] = class_obj
Expand Down
6 changes: 3 additions & 3 deletions src/gafferpy/gaffer_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@


class GetGraph:
def __init__(self, _url=''):
def __init__(self, _url=""):
self._url = _url

def get_url(self):
Expand All @@ -38,7 +38,7 @@ def get_url(self):


class GetClassFilterFunctions(GetFilterFunctions):
def __init__(self, class_name=''):
def __init__(self, class_name=""):
super().__init__(class_name)


Expand All @@ -53,7 +53,7 @@ def get_operation(self):
def load_config_json_map():
for name, class_obj in inspect.getmembers(
sys.modules[__name__], inspect.isclass):
if hasattr(class_obj, 'CLASS'):
if hasattr(class_obj, "CLASS"):
JsonConverter.GENERIC_JSON_CONVERTERS[class_obj.CLASS] = \
lambda obj, class_obj=class_obj: class_obj(**obj)
JsonConverter.CLASS_MAP[class_obj.CLASS] = class_obj
Expand Down
2 changes: 1 addition & 1 deletion src/gafferpy/gaffer_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def execute_operation_chain(self, operation_chain, headers=None):
"""
This method queries Gaffer with the provided operation chain.
"""
target = '/graph/operations/execute'
target = "/graph/operations/execute"

op_chain_json_obj = ToJson.recursive_to_json(operation_chain)

Expand Down
8 changes: 4 additions & 4 deletions src/gafferpy/gaffer_connector_pki.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
warnings.warn("""
This connector is deprecated, instead use gaffer_connector.GafferConnector(
host,
client_class='pki',
client_class="pki",
pki = pki,
protocol = protocol
)
Expand Down Expand Up @@ -68,7 +68,7 @@ def __init__(self, cert_filename, password=None):

# Read the contents of the certificate file to check that it is
# readable
with open(cert_filename, 'r') as cert_file:
with open(cert_filename, "r") as cert_file:
self._cert_file_contents = cert_file.read()
cert_file.close()

Expand All @@ -77,7 +77,7 @@ def __init__(self, cert_filename, password=None):

# Obtain the password if required and remember it
if password is None:
password = getpass.getpass('Password for PEM certificate file: ')
password = getpass.getpass("Password for PEM certificate file: ")
self._password = password

def get_ssl_context(self, protocol=None):
Expand Down Expand Up @@ -105,4 +105,4 @@ def get_ssl_context(self, protocol=None):
return ssl_context

def __str__(self):
return 'Certificates from ' + self._cert_filename
return "Certificates from " + self._cert_filename
Loading

0 comments on commit 3bc37ce

Please sign in to comment.