Skip to content

Commit

Permalink
remove the large photo
Browse files Browse the repository at this point in the history
  • Loading branch information
SunRunAway committed Jun 26, 2013
1 parent 01e77b6 commit 0043169
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ before_script:
- export QINIU_DOMAIN="pysdk.qiniudn.com"
script:
- python setup.py nosetests
- python demo.py
- export PYTHONPATH="$PYTHONPATH:." && python docs/demo.py
3 changes: 3 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
all:
gist README.gist.md > README.md

82 changes: 41 additions & 41 deletions docs/README.gist.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,39 +75,39 @@ Qiniu Resource (Cloud) Storage SDK for Python
```{python}
@gist(gist/conf.py#config)
@gist(../demo.py#import_rs)
@gist(demo.py#import_rs)
@gist(../demo.py#stat)
@gist(demo.py#stat)
```

<a name=rs-copy></a>
### 3.2 复制单个文件
```{python}
@gist(gist/conf.py#config)
@gist(../demo.py#import_rs)
@gist(demo.py#import_rs)
@gist(../demo.py#copy)
@gist(demo.py#copy)
```

<a name=rs-move></a>
### 3.3 移动单个文件
```{python}
@gist(gist/conf.py#config)
@gist(../demo.py#import_rs)
@gist(demo.py#import_rs)
@gist(../demo.py#move)
@gist(demo.py#move)
```

<a name=rs-delete></a>
### 3.4 删除单个文件
```{python}
@gist(gist/conf.py#config)
@gist(../demo.py#import_rs)
@gist(demo.py#import_rs)
@gist(../demo.py#move)
@gist(demo.py#move)
```

<a name=batch></a>
Expand All @@ -118,47 +118,47 @@ Qiniu Resource (Cloud) Storage SDK for Python
```{python}
@gist(gist/conf.py#config)
@gist(../demo.py#import_rs)
@gist(demo.py#import_rs)
@gist(../demo.py#batch_path)
@gist(demo.py#batch_path)
@gist(../demo.py#batch_stat)
@gist(demo.py#batch_stat)
```

<a name=batch-copy></a>
#### 3.5.2 批量复制文件
```{python}
@gist(gist/conf.py#config)
@gist(../demo.py#import_rs)
@gist(demo.py#import_rs)
@gist(../demo.py#batch_path)
@gist(demo.py#batch_path)
@gist(../demo.py#batch_copy)
@gist(demo.py#batch_copy)
```

<a name=batch-move></a>
#### 3.5.3 批量移动文件
```{python}
@gist(gist/conf.py#config)
@gist(../demo.py#import_rs)
@gist(demo.py#import_rs)
@gist(../demo.py#batch_path)
@gist(demo.py#batch_path)
@gist(../demo.py#batch_move)
@gist(demo.py#batch_move)
```

<a name=batch-delete></a>
#### 3.5.4 批量删除文件
```{python}
@gist(gist/conf.py#config)
@gist(../demo.py#import_rs)
@gist(demo.py#import_rs)
@gist(../demo.py#batch_path)
@gist(demo.py#batch_path)
@gist(../demo.py#batch_delete)
@gist(demo.py#batch_delete)
```

<a name=get-and-put-api></a>
Expand All @@ -172,9 +172,9 @@ uptoken是一个字符串,作为http协议Header的一部分(Authorization
```{python}
@gist(gist/conf.py#config)
@gist(../demo.py#import_rs)
@gist(demo.py#import_rs)
@gist(../demo.py#uptoken)
@gist(demo.py#uptoken)
```

<a name=upload></a>
Expand All @@ -190,19 +190,19 @@ uptoken是一个字符串,作为http协议Header的一部分(Authorization
```{python}
@gist(gist/conf.py#config)
@gist(../demo.py#import_io)
@gist(demo.py#import_io)
@gist(../demo.py#put)
@gist(demo.py#put)
```

上传本地文件

```{python}
@gist(gist/conf.py#config)
@gist(../demo.py#import_io)
@gist(demo.py#import_io)
@gist(../demo.py#put_file)
@gist(demo.py#put_file)
```

<a name=resumable-io-upload></a>
Expand All @@ -211,18 +211,18 @@ uptoken是一个字符串,作为http协议Header的一部分(Authorization
```{python}
@gist(gist/conf.py#config)
@gist(../demo.py#import_resumable_io)
@gist(demo.py#import_resumable_io)
@gist(../demo.py#resumable_put)
@gist(demo.py#resumable_put)
```

上传本地文件
```{python}
@gist(gist/conf.py#config)
@gist(../demo.py#import_resumable_io)
@gist(demo.py#import_resumable_io)
@gist(../demo.py#resumable_put_file)
@gist(demo.py#resumable_put_file)
```

<a name=io-download></a>
Expand Down Expand Up @@ -253,9 +253,9 @@ uptoken是一个字符串,作为http协议Header的一部分(Authorization
```{python}
@gist(gist/conf.py#config)
@gist(../demo.py#import_rs)
@gist(demo.py#import_rs)
@gist(../demo.py#dntoken)
@gist(demo.py#dntoken)
```

<a name=fop-api></a>
Expand All @@ -269,21 +269,21 @@ uptoken是一个字符串,作为http协议Header的一部分(Authorization
```{python}
@gist(gist/conf.py#config)
@gist(../demo.py#import_fop)
@gist(../demo.py#import_rs)
@gist(demo.py#import_fop)
@gist(demo.py#import_rs)
@gist(../demo.py#image_info)
@gist(demo.py#image_info)
```

<a name=fop-exif></a>
### 5.1.2 查看图片EXIF信息
```{python}
@gist(gist/conf.py#config)
@gist(../demo.py#import_fop)
@gist(../demo.py#import_rs)
@gist(demo.py#import_fop)
@gist(demo.py#import_rs)
@gist(../demo.py#exif)
@gist(demo.py#exif)
```


Expand All @@ -292,10 +292,10 @@ uptoken是一个字符串,作为http协议Header的一部分(Authorization
```{python}
@gist(gist/conf.py#config)
@gist(../demo.py#import_fop)
@gist(../demo.py#import_rs)
@gist(demo.py#import_fop)
@gist(demo.py#import_rs)
@gist(../demo.py#image_view)
@gist(demo.py#image_view)
```

<a name=contribution></a>
Expand Down
6 changes: 3 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ import qiniu.fop
import qiniu.rs
# 生成base_url
url = qiniu.rs.make_base_url(domain, key2)
url = qiniu.rs.make_base_url(domain, pic_key)
# 生成fop_url
image_info = qiniu.fop.ImageInfo()
Expand All @@ -420,7 +420,7 @@ import qiniu.fop
import qiniu.rs
# 生成base_url
url = qiniu.rs.make_base_url(domain, key2)
url = qiniu.rs.make_base_url(domain, pic_key)
# 生成fop_url
image_exif = qiniu.fop.Exif()
Expand Down Expand Up @@ -449,7 +449,7 @@ iv = qiniu.fop.ImageView()
iv.width = 100
# 生成base_url
url = qiniu.rs.make_base_url(domain, key2)
url = qiniu.rs.make_base_url(domain, pic_key)
# 生成fop_url
url = iv.make_request(url)
# 对其签名,生成private_url。如果是公有bucket此步可以省略
Expand Down
27 changes: 10 additions & 17 deletions demo.py → docs/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@
key2 = None
key3 = None
domain = None
pic_key = None

# ----------------------------------------------------------

def setup(access_key, secret_key, bucketname, bucket_domain):
global bucket_name, uptoken, key, key2, domain, key3
def setup(access_key, secret_key, bucketname, bucket_domain, pickey):
global bucket_name, uptoken, key, key2, domain, key3, pic_key
qiniu.conf.ACCESS_KEY = access_key
qiniu.conf.SECRET_KEY = secret_key
bucket_name = bucketname
domain = bucket_domain
pic_key = pickey
# @gist uptoken
policy = qiniu.rs.PutPolicy(bucket_name)
uptoken = policy.token()
Expand All @@ -49,7 +51,8 @@ def _setup():
secret_key = getenv("QINIU_SECRET_KEY")
bucket_name = getenv("QINIU_BUCKET_NAME")
domain = getenv("QINIU_DOMAIN")
setup(access_key, secret_key, bucket_name, domain)
pickey = getenv("QINIU_PIC_KEY")
setup(access_key, secret_key, bucket_name, domain, pickey)

def getenv(name):
env = os.getenv(name)
Expand Down Expand Up @@ -227,21 +230,11 @@ def delete():
return

def image_info():
''' 上传图片, 并且查看他的信息 '''
# 初始化
qiniu.rs.Client().delete(bucket_name, key2)
''' 查看图片的信息 '''

extra = qiniu.io.PutExtra(bucket_name)
extra.mime_type = "image/png"
localfile = 'qiniu/test/photo_test.jpeg'
ret, err = qiniu.io.put_file(uptoken, key2, localfile, extra)
if err is not None:
error(err)
return

# @gist image_info
# 生成base_url
url = qiniu.rs.make_base_url(domain, key2)
url = qiniu.rs.make_base_url(domain, pic_key)

# 生成fop_url
image_info = qiniu.fop.ImageInfo()
Expand All @@ -258,7 +251,7 @@ def image_exif():
''' 查看图片的exif信息 '''
# @gist exif
# 生成base_url
url = qiniu.rs.make_base_url(domain, key2)
url = qiniu.rs.make_base_url(domain, pic_key)

# 生成fop_url
image_exif = qiniu.fop.Exif()
Expand All @@ -278,7 +271,7 @@ def image_view():
iv.width = 100

# 生成base_url
url = qiniu.rs.make_base_url(domain, key2)
url = qiniu.rs.make_base_url(domain, pic_key)
# 生成fop_url
url = iv.make_request(url)
# 对其签名,生成private_url。如果是公有bucket此步可以省略
Expand Down
1 change: 1 addition & 0 deletions qiniu/rs/test/rs_token_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def test_get_policy(self):

f = urllib.urlopen(private_url)
body = f.read()
f.close()
self.assertEqual(len(body)>100, True)


Expand Down
14 changes: 12 additions & 2 deletions qiniu/test/resumable_io_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import os
import unittest
import zlib
import urllib
import tempfile
import shutil

from qiniu import conf
from qiniu.auth import up
Expand Down Expand Up @@ -38,14 +41,21 @@ def test_block(self):
rs.Client().delete(bucket, key)

def test_put(self):
src = urllib.urlopen("http://cheneya.qiniudn.com/hello_jpg")
dst = tempfile.NamedTemporaryFile()
shutil.copyfileobj(src, dst)
src.close()

policy = rs.PutPolicy(bucket)
extra = resumable_io.PutExtra(bucket)
extra.bucket = bucket
key = "sdk_py_resumable_block_5"
localfile = os.path.abspath(os.path.dirname(__file__)) + "/photo_test.jpeg"
localfile = dst.name
ret, err = resumable_io.put_file(policy.token(), key, localfile, extra)
dst.close()

assert err is None, err
self.assertEqual(ret["hash"], "FggslKhqmufiC1VkQvuF2gtvve9P", "hash not match")
self.assertEqual(ret["hash"], "FnyTMUqPNRTdk1Wou7oLqDHkBm_p", "hash not match")
rs.Client().delete(bucket, key)


Expand Down
3 changes: 0 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
license='MIT',
url=URL,
packages=['qiniu', 'qiniu.test', 'qiniu.auth', 'qiniu.rs', 'qiniu.rs.test'],
package_data={
"qiniu.test": ['photo_test.jpeg'],
},
platforms='any',
classifiers=[
'Intended Audience :: Developers',
Expand Down

0 comments on commit 0043169

Please sign in to comment.