-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored master branch #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -224,7 +224,7 @@ def add_param(pname, desc): | |
| if pname is None: | ||
| return | ||
| if "(required)" not in desc: | ||
| pname = pname + "=None" | ||
| pname = f"{pname}=None" | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| parameters.append(pname) | ||
| else: | ||
| # required params should be put straight into sorted_parameters | ||
|
|
@@ -291,7 +291,7 @@ def breadcrumbs(path, root_discovery): | |
| display = p | ||
| if i == 0: | ||
| display = root_discovery.get("title", display) | ||
| crumbs.append('<a href="{}.html">{}</a>'.format(prefix + p, display)) | ||
| crumbs.append(f'<a href="{prefix + p}.html">{display}</a>') | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| accumulated.append(p) | ||
|
|
||
| return " . ".join(crumbs) | ||
|
|
@@ -314,10 +314,11 @@ def document_collection(resource, path, root_discovery, discovery, css=CSS): | |
| html = [ | ||
| "<html><body>", | ||
| css, | ||
| "<h1>%s</h1>" % breadcrumbs(path[:-1], root_discovery), | ||
| f"<h1>{breadcrumbs(path[:-1], root_discovery)}</h1>", | ||
| "<h2>Instance Methods</h2>", | ||
| ] | ||
|
|
||
|
Comment on lines
-317
to
320
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| # Which methods are for collections. | ||
| for name in dir(resource): | ||
| if not name.startswith("_") and callable(getattr(resource, name)): | ||
|
|
@@ -362,13 +363,11 @@ def document_collection_recursive(resource, path, root_discovery, discovery): | |
|
|
||
| html = document_collection(resource, path, root_discovery, discovery) | ||
|
|
||
| f = open(os.path.join(FLAGS.dest, path + "html"), "w") | ||
| if sys.version_info.major < 3: | ||
| html = html.encode("utf-8") | ||
|
|
||
| f.write(html) | ||
| f.close() | ||
| with open(os.path.join(FLAGS.dest, f"{path}html"), "w") as f: | ||
| if sys.version_info.major < 3: | ||
| html = html.encode("utf-8") | ||
|
|
||
| f.write(html) | ||
|
Comment on lines
-365
to
+370
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| for name in dir(resource): | ||
| if ( | ||
| not name.startswith("_") | ||
|
|
@@ -398,18 +397,18 @@ def document_api(name, version, uri): | |
| service = build(name, version) | ||
| content = get_static_doc(name, version) | ||
| except UnknownApiNameOrVersion as e: | ||
| print("Warning: {} {} found but could not be built.".format(name, version)) | ||
| print(f"Warning: {name} {version} found but could not be built.") | ||
| return | ||
| except HttpError as e: | ||
| print("Warning: {} {} returned {}.".format(name, version, e)) | ||
| print(f"Warning: {name} {version} returned {e}.") | ||
|
Comment on lines
-401
to
+403
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return | ||
|
|
||
| discovery = json.loads(content) | ||
|
|
||
| version = safe_version(version) | ||
|
|
||
| document_collection_recursive( | ||
| service, "{}_{}.".format(name, version), discovery, discovery | ||
| service, f"{name}_{version}.", discovery, discovery | ||
| ) | ||
|
|
||
|
|
||
|
|
@@ -429,7 +428,7 @@ def document_api_from_discovery_document(uri): | |
| version = safe_version(discovery["version"]) | ||
|
|
||
| document_collection_recursive( | ||
| service, "{}_{}.".format(name, version), discovery, discovery | ||
| service, f"{name}_{version}.", discovery, discovery | ||
|
Comment on lines
-432
to
+431
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| ) | ||
|
|
||
|
|
||
|
|
@@ -458,12 +457,12 @@ def document_api_from_discovery_document(uri): | |
|
|
||
| markdown = [] | ||
| for api, versions in api_directory.items(): | ||
| markdown.append("## %s" % api) | ||
| for version in versions: | ||
| markdown.append( | ||
| "* [%s](http://googleapis.github.io/google-api-python-client/docs/dyn/%s_%s.html)" | ||
| % (version, api, safe_version(version)) | ||
| ) | ||
| markdown.append(f"## {api}") | ||
| markdown.extend( | ||
| f"* [{version}](http://googleapis.github.io/google-api-python-client/docs/dyn/{api}_{safe_version(version)}.html)" | ||
| for version in versions | ||
| ) | ||
|
|
||
|
Comment on lines
-461
to
+465
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
| markdown.append("\n") | ||
|
|
||
| with open("docs/dyn/index.md", "w") as f: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,18 +18,19 @@ | |
| """Copy files from source to dest expanding symlinks along the way. | ||
| """ | ||
|
|
||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
|
|
||
| from shutil import copytree | ||
|
|
||
| import argparse | ||
| import sys | ||
|
|
||
|
|
||
| # Ignore these files and directories when copying over files into the snapshot. | ||
| IGNORE = set(['.hg', 'httplib2', 'oauth2', 'simplejson', 'static']) | ||
| IGNORE = {'.hg', 'httplib2', 'oauth2', 'simplejson', 'static'} | ||
|
|
||
| # In addition to the above files also ignore these files and directories when | ||
| # copying over samples into the snapshot. | ||
| IGNORE_IN_SAMPLES = set(['googleapiclient', 'oauth2client', 'uritemplate']) | ||
| IGNORE_IN_SAMPLES = {'googleapiclient', 'oauth2client', 'uritemplate'} | ||
|
|
||
| parser = argparse.ArgumentParser(description=__doc__) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -82,14 +82,15 @@ def with_scopes(credentials, scopes): | |
| """ | ||
| if HAS_GOOGLE_AUTH and isinstance(credentials, google.auth.credentials.Credentials): | ||
| return google.auth.credentials.with_scopes_if_required(credentials, scopes) | ||
| else: | ||
| try: | ||
| if credentials.create_scoped_required(): | ||
| return credentials.create_scoped(scopes) | ||
| else: | ||
| return credentials | ||
| except AttributeError: | ||
| return credentials | ||
| try: | ||
| return ( | ||
| credentials.create_scoped(scopes) | ||
| if credentials.create_scoped_required() | ||
| else credentials | ||
| ) | ||
|
|
||
| except AttributeError: | ||
| return credentials | ||
|
Comment on lines
-85
to
+93
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| def authorized_http(credentials): | ||
|
|
@@ -106,17 +107,18 @@ def authorized_http(credentials): | |
| """ | ||
| from googleapiclient.http import build_http | ||
|
|
||
| if HAS_GOOGLE_AUTH and isinstance(credentials, google.auth.credentials.Credentials): | ||
| if google_auth_httplib2 is None: | ||
| raise ValueError( | ||
| "Credentials from google.auth specified, but " | ||
| "google-api-python-client is unable to use these credentials " | ||
| "unless google-auth-httplib2 is installed. Please install " | ||
| "google-auth-httplib2." | ||
| ) | ||
| return google_auth_httplib2.AuthorizedHttp(credentials, http=build_http()) | ||
| else: | ||
| if not HAS_GOOGLE_AUTH or not isinstance( | ||
| credentials, google.auth.credentials.Credentials | ||
| ): | ||
| return credentials.authorize(build_http()) | ||
| if google_auth_httplib2 is None: | ||
| raise ValueError( | ||
| "Credentials from google.auth specified, but " | ||
| "google-api-python-client is unable to use these credentials " | ||
| "unless google-auth-httplib2 is installed. Please install " | ||
| "google-auth-httplib2." | ||
| ) | ||
| return google_auth_httplib2.AuthorizedHttp(credentials, http=build_http()) | ||
|
Comment on lines
-109
to
+121
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| def refresh_credentials(credentials): | ||
|
|
@@ -125,11 +127,12 @@ def refresh_credentials(credentials): | |
| # Http instance which would cause a weird recursive loop of refreshing | ||
| # and likely tear a hole in spacetime. | ||
| refresh_http = httplib2.Http() | ||
| if HAS_GOOGLE_AUTH and isinstance(credentials, google.auth.credentials.Credentials): | ||
| request = google_auth_httplib2.Request(refresh_http) | ||
| return credentials.refresh(request) | ||
| else: | ||
| if not HAS_GOOGLE_AUTH or not isinstance( | ||
| credentials, google.auth.credentials.Credentials | ||
| ): | ||
| return credentials.refresh(refresh_http) | ||
| request = google_auth_httplib2.Request(refresh_http) | ||
| return credentials.refresh(request) | ||
|
Comment on lines
-128
to
+135
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| def apply_credentials(credentials, headers): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -115,9 +115,7 @@ def positional_decorator(wrapped): | |
| @functools.wraps(wrapped) | ||
| def positional_wrapper(*args, **kwargs): | ||
| if len(args) > max_positional_args: | ||
| plural_s = "" | ||
| if max_positional_args != 1: | ||
| plural_s = "s" | ||
| plural_s = "s" if max_positional_args != 1 else "" | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| message = ( | ||
| "{function}() takes at most {args_max} positional " | ||
| "argument{plural} ({args_given} given)".format( | ||
|
|
@@ -158,10 +156,8 @@ def parse_unique_urlencoded(content): | |
| params = {} | ||
| for key, value in six.iteritems(urlencoded_params): | ||
| if len(value) != 1: | ||
| msg = "URL-encoded content contains a repeated value:" "%s -> %s" % ( | ||
| key, | ||
| ", ".join(value), | ||
| ) | ||
| msg = f'URL-encoded content contains a repeated value:{key} -> {", ".join(value)}' | ||
|
|
||
|
Comment on lines
-161
to
+160
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| raise ValueError(msg) | ||
| params[key] = value[0] | ||
| return params | ||
|
|
@@ -205,7 +201,4 @@ def _add_query_parameter(url, name, value): | |
| Returns: | ||
| Updated query parameter. Does not update the url if value is None. | ||
| """ | ||
| if value is None: | ||
| return url | ||
| else: | ||
| return update_query_params(url, {name: value}) | ||
| return url if value is None else update_query_params(url, {name: value}) | ||
|
Comment on lines
-208
to
+204
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -103,10 +103,7 @@ | |
|
|
||
|
|
||
| def _upper_header_keys(headers): | ||
| new_headers = {} | ||
| for k, v in six.iteritems(headers): | ||
| new_headers[k.upper()] = v | ||
| return new_headers | ||
| return {k.upper(): v for k, v in six.iteritems(headers)} | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| class Notification(object): | ||
|
|
@@ -270,14 +267,14 @@ def notification_from_headers(channel, headers): | |
| channel_id = headers[X_GOOG_CHANNEL_ID] | ||
| if channel.id != channel_id: | ||
| raise errors.InvalidNotificationError( | ||
| "Channel id mismatch: %s != %s" % (channel.id, channel_id) | ||
| f"Channel id mismatch: {channel.id} != {channel_id}" | ||
| ) | ||
| else: | ||
| message_number = int(headers[X_GOOG_MESSAGE_NUMBER]) | ||
| state = headers[X_GOOG_RESOURCE_STATE] | ||
| resource_uri = headers[X_GOOG_RESOURCE_URI] | ||
| resource_id = headers[X_GOOG_RESOURCE_ID] | ||
| return Notification(message_number, state, resource_uri, resource_id) | ||
|
|
||
| message_number = int(headers[X_GOOG_MESSAGE_NUMBER]) | ||
| state = headers[X_GOOG_RESOURCE_STATE] | ||
| resource_uri = headers[X_GOOG_RESOURCE_URI] | ||
| resource_id = headers[X_GOOG_RESOURCE_ID] | ||
| return Notification(message_number, state, resource_uri, resource_id) | ||
|
Comment on lines
-273
to
+277
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| @util.positional(2) | ||
|
|
@@ -304,9 +301,7 @@ def new_webhook_channel(url, token=None, expiration=None, params=None): | |
| expiration_ms = ( | ||
| delta.microseconds / 1000 + (delta.seconds + delta.days * 24 * 3600) * 1000 | ||
| ) | ||
| if expiration_ms < 0: | ||
| expiration_ms = 0 | ||
|
|
||
| expiration_ms = max(expiration_ms, 0) | ||
|
Comment on lines
-307
to
+304
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return Channel( | ||
| "web_hook", | ||
| str(uuid.uuid4()), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines
36-36refactored with the following changes:replace-interpolation-with-fstring)