Skip to content

Commit 5eabd6b

Browse files
committed
Whitespace cleanup
1 parent 18bfb7b commit 5eabd6b

File tree

7 files changed

+78
-83
lines changed

7 files changed

+78
-83
lines changed

janrain/capture/cli.py

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,127 +14,127 @@ class ApiArgumentParser(ArgumentParser):
1414
common command-line options for authenticating with the Janrain API and
1515
allows for an janrain.capture.Api instance to be initialized using those
1616
credentials.
17-
17+
1818
Example:
19-
19+
2020
parser = janrain.capture.cli.ApiArgumentParser()
2121
args = parser.parse_args()
2222
api = parser.init_api()
23-
23+
2424
"""
2525
def __init__(self, *args, **kwargs):
2626
super(ApiArgumentParser, self).__init__(*args, **kwargs)
2727
self._parsed_args = None
28-
28+
2929
# credentials explicitly specified on the command line
30-
self.add_argument('-u', '--apid_uri',
30+
self.add_argument('-u', '--apid_uri',
3131
help="Full URI to the Capture API domain")
3232
self.add_argument('-i', '--client-id',
3333
help="authenticate with a specific client_id")
3434
self.add_argument('-s', '--client-secret',
3535
help="authenticate with a specific client_secret")
36-
36+
3737
# credentials defined in config file at the specified path
3838
self.add_argument('-k', '--config-key',
3939
help="authenticate using the credentials defined at "\
4040
"a specific path in the configuration file " \
4141
"(eg. clients.demo)")
42-
42+
4343
# default client found in the configuration file
4444
self.add_argument('-d', '--default-client', action='store_true',
4545
help="authenticate using the default client defined "\
46-
"in the configuration file")
47-
46+
"in the configuration file")
47+
4848
def parse_args(self, args=None, namespace=None):
4949
# override to store the result which can later be used by init_api()
5050
args = super(ApiArgumentParser, self).parse_args(args, namespace)
5151
self._parsed_args = args
5252
return self._parsed_args
53-
53+
5454
def init_api(self, api_class=None):
5555
"""
5656
Initialize a janrain.capture.Api() instance for the credentials that
57-
were specified on the command line or environment variables. This
58-
method will use the first credentials it finds, looking in the
57+
were specified on the command line or environment variables. This
58+
method will use the first credentials it finds, looking in the
5959
following order:
60-
60+
6161
1. A client_id and client_secret specified on the command line
6262
2. A configuration key specified on the command line
6363
3. The default client as specified with a flag on the command line
64-
4. The CAPTURE_CLIENT_ID and CAPTURE_CLIENT_SECRET environment vars
65-
64+
4. The CAPTURE_CLIENT_ID and CAPTURE_CLIENT_SECRET environment vars
65+
6666
Returns:
6767
A janrain.capture.Api instance
68-
68+
6969
"""
7070
if not self._parsed_args:
7171
raise Exception("You must call the parse_args() method before " \
7272
"the init_api() method.")
73-
73+
7474
args = self._parsed_args
75-
75+
7676
if args.client_id and args.client_secret:
7777
credentials = {
7878
'client_id': args.client_id,
7979
'client_secret': args.client_secret
8080
}
81-
81+
8282
elif args.config_key:
8383
credentials = config.get_settings_at_path(args.config_key)
84-
84+
8585
elif args.default_client:
8686
credentials = config.default_client()
87-
87+
8888
elif 'CAPTURE_CLIENT_ID' in os.environ \
8989
and 'CAPTURE_CLIENT_SECRET' in os.environ:
9090
credentials = {
9191
'client_id': os.environ['CAPTURE_CLIENT_ID'],
9292
'client_secret': os.environ['CAPTURE_CLIENT_SECRET']
9393
}
94-
94+
9595
else:
9696
message = "You did not specify credentials to authenticate " \
9797
"with the Capture API."
9898
raise JanrainCredentialsError(message)
99-
99+
100100
if args.apid_uri:
101101
credentials['apid_uri'] = args.apid_uri
102-
102+
103103
elif 'apid_uri' not in credentials:
104104
if 'CAPTURE_APID_URI' in os.environ:
105105
credentials['apid_uri'] = os.environ['CAPTURE_APID_URI']
106106
else:
107107
message = "You did not specify the URL to the Capture API"
108108
raise JanrainCredentialsError(message)
109-
109+
110110
defaults = {k: credentials[k] for k in ('client_id', 'client_secret')}
111-
111+
112112
if api_class:
113113
return api_class(credentials['apid_uri'], defaults)
114114
else:
115115
return Api(credentials['apid_uri'], defaults)
116-
116+
117117

118118
def main():
119119
"""
120120
Main entry point for CLI. This may be called by running the module directly
121121
or by an executable installed onto the system path.
122122
"""
123123
parser = ApiArgumentParser(formatter_class=lambda prog: HelpFormatter(prog,max_help_position=30))
124-
parser.add_argument('api_call',
124+
parser.add_argument('api_call',
125125
help="API endpoint expressed as a relative path " \
126126
"(eg. /settings/get).")
127-
parser.add_argument('-p', '--parameters', nargs='*',
127+
parser.add_argument('-p', '--parameters', nargs='*',
128128
metavar="parameter=value",
129129
help="parameters passed through to the API call")
130-
parser.add_argument('-v', '--version', action='version',
130+
parser.add_argument('-v', '--version', action='version',
131131
version="capture-api " + get_version())
132132
parser.add_argument('-x', '--disable-signed-requests', action='store_true',
133133
help="sign HTTP requests")
134134
parser.add_argument('-b', '--debug', action='store_true',
135135
help="log debug messages to stdout")
136136
args = parser.parse_args()
137-
137+
138138
try:
139139
api = parser.init_api()
140140
except (JanrainConfigError, JanrainCredentialsError) as error:
@@ -145,22 +145,22 @@ def main():
145145

146146
if args.debug:
147147
logging.basicConfig(level=logging.DEBUG)
148-
148+
149149
# map list of parameters from command line into a dict for use as kwargs
150150
kwargs = {}
151151
if args.parameters:
152-
kwargs = dict((key, value) for key, value in [s.split("=", 1)
152+
kwargs = dict((key, value) for key, value in [s.split("=", 1)
153153
for s in args.parameters])
154-
154+
155155
try:
156156
data = api.call(args.api_call, **kwargs)
157157
except ApiResponseError as error:
158158
sys.exit("API Error {} - {}\n".format(error.code, error.message))
159159
except Exception as error:
160160
sys.exit("Error - {}\n".format(error))
161-
161+
162162
print(json.dumps(data, indent=2, sort_keys=True))
163-
163+
164164
sys.exit()
165165

166166
if __name__ == "__main__":

janrain/capture/config.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
def get_settings_at_path(dot_path):
77
"""
88
Get the settings for the specified YAML path.
9-
9+
1010
Args:
1111
dot_path - A YAML path string in dot-notation (Eg. "clusters.dev")
12-
12+
1313
Returns:
1414
A dictionary containing the settings at the specified path.
15-
15+
1616
Raises:
1717
KeyError if the path does not exist
1818
"""
@@ -23,13 +23,13 @@ def get_settings_at_path(dot_path):
2323
if not current:
2424
raise JanrainConfigError("Could not find key '{}' in '{}'." \
2525
.format(dot_path, get_config_file()))
26-
merge_cluster(current)
26+
merge_cluster(current)
2727
return current
28-
28+
2929
def default_client():
3030
"""
3131
Get the settings for the default client defined in the config file.
32-
32+
3333
Returns:
3434
A dictionary containing the default client settings.
3535
"""
@@ -40,13 +40,13 @@ def default_client():
4040
message = "Could not find key 'default_client' in '{}'." \
4141
.format(get_config_file())
4242
raise JanrainConfigError(message)
43-
43+
4444
return get_client(client_name)
4545

4646
def unittest_client():
4747
"""
4848
Get the settings for the unittest client defined in the config file.
49-
49+
5050
Returns:
5151
A dictionary containing the default client settings.
5252
"""
@@ -57,40 +57,40 @@ def unittest_client():
5757
message = "Could not find key 'unittest_client' in '{}'." \
5858
.format(get_config_file())
5959
raise JanrainConfigError(message)
60-
60+
6161
return get_client(client_name)
6262

6363
def client(client_name):
6464
""" DEPRECATED """
6565
return get_client(client_name)
66-
66+
6767
def get_client(client_name):
6868
"""
6969
Get the settings defined for the specified client.
70-
70+
7171
Args:
7272
client_name - The name of the client defined in the the config file
73-
73+
7474
Returns:
7575
A dictionary containing the client settings.
7676
"""
7777
client = get_settings_at_path("clients." + client_name)
7878
merge_cluster(client)
79-
79+
8080
return client
8181

8282
def cluster(cluster_name):
8383
""" DEPRECATED """
8484
return get_cluster(cluster_name)
85-
85+
8686
def get_cluster(cluster_name):
8787
"""
8888
Get the settings defined for the specified cluster.
89-
89+
9090
Args:
9191
cluster_name - The name of the cluster defined in the config file
9292
(Eg. "prod" or "eu_staging")
93-
93+
9494
Returns:
9595
A dictionary containing the cluster settings.
9696
"""
@@ -99,16 +99,16 @@ def get_cluster(cluster_name):
9999
def get_clusters():
100100
"""
101101
Get the list of all clusters.
102-
102+
103103
Returns:
104104
A dictionary containing the cluster settings.
105105
"""
106106
return get_settings_at_path("clusters")
107107

108108
def get_config_file():
109109
"""
110-
Get the full path to the config file. By default, this is a YAML file named
111-
`.janrain-capture`` located in the user's home directory. Override the
110+
Get the full path to the config file. By default, this is a YAML file named
111+
`.janrain-capture`` located in the user's home directory. Override the
112112
default file by specifying a full path to a YAML file in the JANRAIN_CONFIG
113113
environment variable.
114114
"""
@@ -120,19 +120,19 @@ def get_config_file():
120120
def merge_cluster(settings):
121121
"""
122122
Merge the cluster settings into the dictionary if a 'clusters' key exists.
123-
123+
124124
Args:
125125
settings - The settings to dictionary to merge cluster setings into.
126126
"""
127127
if 'cluster' in settings:
128128
# merge in cluster values
129129
cluster = get_cluster(settings['cluster'])
130130
settings.update(cluster)
131-
131+
132132
def read_config_file():
133133
"""
134-
Parse the YAML configuration file into Python types.
135-
134+
Parse the YAML configuration file into Python types.
135+
136136
Returns:
137137
A Python dictionary representing the YAML.
138138
"""

janrain/capture/exceptions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class JanrainCredentialsError(Exception):
1111
class JanrainConfigError(Exception):
1212
""" Exception for credential configuration file errors """
1313
pass
14-
14+
1515
class InvalidApiCallError(JanrainApiException):
1616
""" Request for a non-existing API call. """
1717
def __init__(self, api_call, status):
@@ -21,7 +21,7 @@ def __init__(self, api_call, status):
2121
class JanrainInvalidUrlError(JanrainApiException):
2222
""" Invalid URL. """
2323
pass
24-
24+
2525
class ApiResponseError(JanrainApiException):
2626
""" An error response from the capture API. """
2727
def __init__(self, code, error, error_description, response):

janrain/capture/test/janrain-config

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
defaults:
22
default_client: test-client
33
unittest_client: test-client
4-
5-
clusters:
6-
dev:
4+
5+
clusters:
6+
dev:
77
client_id: dev client_id
88
client_secret: dev client_secret
99

janrain/capture/test/test_api.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,25 @@ def setUp(self):
1313
'client_secret': client['client_secret']
1414
})
1515
self.client = client
16-
16+
1717
def test_api_encode(self):
1818
# Python natives should be encoded into JSON
1919
self.assertEqual(api_encode(True), "true")
2020
self.assertEqual(api_encode(False), "false")
2121
json.loads(api_encode(['foo', 'bar']))
2222
json.loads(api_encode({'foo': True, 'bar': None}))
23-
23+
2424
def test_api_object(self):
2525
# should prepend https:// if protocol is missing
2626
api = Api("foo.janrain.com")
2727
self.assertEqual(api.api_url, "https://foo.janrain.com")
28-
28+
2929
# responses should have stat
3030
result = self.api.call("entity.count", type_name="user")
3131
self.assertTrue("stat" in result)
32-
32+
3333
# oauth/token returns 400 or 401 which should *not* be a URLError
3434
with self.assertRaises(ApiResponseError):
3535
self.api.call("/oauth/token")
36-
36+
3737

0 commit comments

Comments
 (0)