Skip to content

Commit 28260f9

Browse files
committed
Make python header spacing & quote usage consistent
1 parent 71eec07 commit 28260f9

27 files changed

+50
-36
lines changed

src/targets/python/helpers.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ function concatValues (concatType, values, pretty, indentation, indentLevel) {
2525

2626
if (pretty) {
2727
return openingBrace + '\n' + currentIndent + values.join(join) + '\n' + closingBraceIndent + closingBrace
28+
} else if (concatType === 'object' && values.length > 0) {
29+
return openingBrace + ' ' + values.join(join) + ' ' + closingBrace
2830
} else {
2931
return openingBrace + values.join(join) + closingBrace
3032
}

src/targets/python/python3.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ module.exports = function (source, options) {
4040
const headerCount = Object.keys(headers).length
4141
if (headerCount === 1) {
4242
for (const header in headers) {
43-
code.push('headers = { \'%s\': "%s" }', header, headers[header])
43+
code.push('headers = { "%s": "%s" }', header, headers[header])
4444
.blank()
4545
}
4646
} else if (headerCount > 1) {
@@ -50,9 +50,9 @@ module.exports = function (source, options) {
5050

5151
for (const header in headers) {
5252
if (count++ !== headerCount) {
53-
code.push(' \'%s\': "%s",', header, headers[header])
53+
code.push(' "%s": "%s",', header, headers[header])
5454
} else {
55-
code.push(' \'%s\': "%s"', header, headers[header])
55+
code.push(' "%s": "%s"', header, headers[header])
5656
}
5757
}
5858

src/targets/python/requests.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module.exports = function (source, options) {
3434
// Construct query string
3535
let qs
3636
if (Object.keys(source.queryObj).length) {
37-
qs = 'querystring = ' + JSON.stringify(source.queryObj)
37+
qs = 'querystring = ' + helpers.literalRepresentation(source.queryObj, opts)
3838

3939
code.push(qs)
4040
.blank()
@@ -67,7 +67,7 @@ module.exports = function (source, options) {
6767

6868
if (headerCount === 1) {
6969
for (const header in headers) {
70-
code.push('headers = {"%s": "%s"}', header, headers[header])
70+
code.push('headers = { "%s": "%s" }', header, headers[header])
7171
.blank()
7272
}
7373
} else if (headerCount > 1) {

test/fixtures/output/python/python3/application-form-encoded.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
payload = "foo=bar&hello=world"
66

7-
headers = { 'content-type': "application/x-www-form-urlencoded" }
7+
headers = { "content-type": "application/x-www-form-urlencoded" }
88

99
conn.request("POST", "/har", payload, headers)
1010

test/fixtures/output/python/python3/application-json.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
payload = "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}],\"boolean\":false}"
66

7-
headers = { 'content-type': "application/json" }
7+
headers = { "content-type": "application/json" }
88

99
conn.request("POST", "/har", payload, headers)
1010

test/fixtures/output/python/python3/cookies.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
conn = http.client.HTTPConnection("mockbin.com")
44

5-
headers = { 'cookie': "foo=bar; bar=baz" }
5+
headers = { "cookie": "foo=bar; bar=baz" }
66

77
conn.request("POST", "/har", headers=headers)
88

test/fixtures/output/python/python3/full.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
payload = "foo=bar"
66

77
headers = {
8-
'cookie': "foo=bar; bar=baz",
9-
'accept': "application/json",
10-
'content-type': "application/x-www-form-urlencoded"
8+
"cookie": "foo=bar; bar=baz",
9+
"accept": "application/json",
10+
"content-type": "application/x-www-form-urlencoded"
1111
}
1212

1313
conn.request("POST", "/har?foo=bar&foo=baz&baz=abc&key=value", payload, headers)

test/fixtures/output/python/python3/headers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
conn = http.client.HTTPConnection("mockbin.com")
44

55
headers = {
6-
'accept': "application/json",
7-
'x-foo': "Bar"
6+
"accept": "application/json",
7+
"x-foo": "Bar"
88
}
99

1010
conn.request("GET", "/har", headers=headers)

test/fixtures/output/python/python3/jsonObj-multiline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
payload = "{\n \"foo\": \"bar\"\n}"
66

7-
headers = { 'content-type': "application/json" }
7+
headers = { "content-type": "application/json" }
88

99
conn.request("POST", "/har", payload, headers)
1010

test/fixtures/output/python/python3/jsonObj-null-value.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
payload = "{\"foo\":null}"
66

7-
headers = { 'content-type': "application/json" }
7+
headers = { "content-type": "application/json" }
88

99
conn.request("POST", "/har", payload, headers)
1010

0 commit comments

Comments
 (0)