Skip to content

Commit 61a39e1

Browse files
committed
use autopep8 format
1 parent 1d41b57 commit 61a39e1

25 files changed

+1523
-1427
lines changed

docs/gist/demo.py

Lines changed: 299 additions & 276 deletions
Large diffs are not rendered by default.

docs/gist/fetch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#coding=utf-8
1+
# coding=utf-8
22
import sys
33
sys.path.insert(0, "../../")
44

docs/gist/pfop.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#coding=utf-8
1+
# coding=utf-8
22
import sys
33
sys.path.insert(0, "../../")
44

@@ -34,4 +34,4 @@
3434
print err
3535
else:
3636
print "success"
37-
print ret
37+
print ret

docs/gist/prefetch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#coding=utf-8
1+
# coding=utf-8
22
import sys
33
sys.path.insert(0, "../../")
44

qiniu/auth/digest.py

Lines changed: 49 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,52 +7,56 @@
77
from .. import rpc
88
from .. import conf
99

10+
1011
class Mac(object):
11-
access = None
12-
secret = None
13-
def __init__(self, access=None, secret=None):
14-
if access is None and secret is None:
15-
access, secret = conf.ACCESS_KEY, conf.SECRET_KEY
16-
self.access, self.secret = access, secret
17-
18-
def __sign(self, data):
19-
hashed = hmac.new(self.secret, data, sha1)
20-
return urlsafe_b64encode(hashed.digest())
21-
22-
def sign(self, data):
23-
return '%s:%s' % (self.access, self.__sign(data))
24-
25-
def sign_with_data(self, b):
26-
data = urlsafe_b64encode(b)
27-
return '%s:%s:%s' % (self.access, self.__sign(data), data)
28-
29-
def sign_request(self, path, body, content_type):
30-
parsedurl = urlparse(path)
31-
p_query = parsedurl.query
32-
p_path = parsedurl.path
33-
data = p_path
34-
if p_query != "":
35-
data = ''.join([data, '?', p_query])
36-
data = ''.join([data, "\n"])
37-
38-
if body:
39-
incBody = [
40-
"application/x-www-form-urlencoded",
41-
]
42-
if content_type in incBody:
43-
data += body
44-
45-
return '%s:%s' % (self.access, self.__sign(data))
12+
access = None
13+
secret = None
14+
15+
def __init__(self, access=None, secret=None):
16+
if access is None and secret is None:
17+
access, secret = conf.ACCESS_KEY, conf.SECRET_KEY
18+
self.access, self.secret = access, secret
19+
20+
def __sign(self, data):
21+
hashed = hmac.new(self.secret, data, sha1)
22+
return urlsafe_b64encode(hashed.digest())
23+
24+
def sign(self, data):
25+
return '%s:%s' % (self.access, self.__sign(data))
26+
27+
def sign_with_data(self, b):
28+
data = urlsafe_b64encode(b)
29+
return '%s:%s:%s' % (self.access, self.__sign(data), data)
30+
31+
def sign_request(self, path, body, content_type):
32+
parsedurl = urlparse(path)
33+
p_query = parsedurl.query
34+
p_path = parsedurl.path
35+
data = p_path
36+
if p_query != "":
37+
data = ''.join([data, '?', p_query])
38+
data = ''.join([data, "\n"])
39+
40+
if body:
41+
incBody = [
42+
"application/x-www-form-urlencoded",
43+
]
44+
if content_type in incBody:
45+
data += body
46+
47+
return '%s:%s' % (self.access, self.__sign(data))
4648

4749

4850
class Client(rpc.Client):
49-
def __init__(self, host, mac=None):
50-
if mac is None:
51-
mac = Mac()
52-
super(Client, self).__init__(host)
53-
self.mac = mac
54-
55-
def round_tripper(self, method, path, body):
56-
token = self.mac.sign_request(path, body, self._header.get("Content-Type"))
57-
self.set_header("Authorization", "QBox %s" % token)
58-
return super(Client, self).round_tripper(method, path, body)
51+
52+
def __init__(self, host, mac=None):
53+
if mac is None:
54+
mac = Mac()
55+
super(Client, self).__init__(host)
56+
self.mac = mac
57+
58+
def round_tripper(self, method, path, body):
59+
token = self.mac.sign_request(
60+
path, body, self._header.get("Content-Type"))
61+
self.set_header("Authorization", "QBox %s" % token)
62+
return super(Client, self).round_tripper(method, path, body)

qiniu/auth/up.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44

55

66
class Client(rpc.Client):
7-
up_token = None
7+
up_token = None
88

9-
def __init__(self, up_token, host=None):
10-
if host is None:
11-
host = conf.UP_HOST
12-
if host.startswith("http://"):
13-
host = host[7:]
14-
self.up_token = up_token
15-
super(Client, self).__init__(host)
9+
def __init__(self, up_token, host=None):
10+
if host is None:
11+
host = conf.UP_HOST
12+
if host.startswith("http://"):
13+
host = host[7:]
14+
self.up_token = up_token
15+
super(Client, self).__init__(host)
1616

17-
def round_tripper(self, method, path, body):
18-
self.set_header("Authorization", "UpToken %s" % self.up_token)
19-
return super(Client, self).round_tripper(method, path, body)
17+
def round_tripper(self, method, path, body):
18+
self.set_header("Authorization", "UpToken %s" % self.up_token)
19+
return super(Client, self).round_tripper(method, path, body)

qiniu/fop.py

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,40 @@
11
# -*- coding:utf-8 -*-
22
import json
33

4+
45
class Exif(object):
5-
def make_request(self, url):
6-
return '%s?exif' % url
6+
7+
def make_request(self, url):
8+
return '%s?exif' % url
79

810

911
class ImageView(object):
10-
mode = 1 # 1或2
11-
width = None # width 默认为0,表示不限定宽度
12-
height = None
13-
quality = None # 图片质量, 1-100
14-
format = None # 输出格式, jpg, gif, png, tif 等图片格式
12+
mode = 1 # 1或2
13+
width = None # width 默认为0,表示不限定宽度
14+
height = None
15+
quality = None # 图片质量, 1-100
16+
format = None # 输出格式, jpg, gif, png, tif 等图片格式
1517

16-
def make_request(self, url):
17-
target = []
18-
target.append('%s' % self.mode)
19-
20-
if self.width is not None:
21-
target.append("w/%s" % self.width)
18+
def make_request(self, url):
19+
target = []
20+
target.append('%s' % self.mode)
2221

23-
if self.height is not None:
24-
target.append("h/%s" % self.height)
22+
if self.width is not None:
23+
target.append("w/%s" % self.width)
2524

26-
if self.quality is not None:
27-
target.append("q/%s" % self.quality)
25+
if self.height is not None:
26+
target.append("h/%s" % self.height)
2827

29-
if self.format is not None:
30-
target.append("format/%s" % self.format)
28+
if self.quality is not None:
29+
target.append("q/%s" % self.quality)
3130

32-
return "%s?imageView/%s" % (url, '/'.join(target))
31+
if self.format is not None:
32+
target.append("format/%s" % self.format)
33+
34+
return "%s?imageView/%s" % (url, '/'.join(target))
3335

3436

3537
class ImageInfo(object):
36-
def make_request(self, url):
37-
return '%s?imageInfo' % url
38+
39+
def make_request(self, url):
40+
return '%s?imageInfo' % url

0 commit comments

Comments
 (0)