def test_destroy(): r = requests.get('http://i1.wp.com/leancloud.cn/images/static/default-avatar.png') b = buffer(r.content) f = File('Lenna2.jpg', b) f.save() assert f.id f.destroy()
def upload(file_path): print 'uploading file %s' % file_path img_name = path.split(file_path)[1] img_file = open(file_path) up_file = File(img_name, img_file) img_url = up_file.save().url return img_url
def test_destroy(): r = requests.get('http://www.lenna.org/full/len_std.jpg') b = buffer(r.content) f = File('Lenna2.jpg', b) f.save() assert f.id f.destroy()
def test_destroy(): # type: () -> None r = requests.get('http://i1.wp.com/leancloud.cn/images/static/default-avatar.png') b = io.BytesIO(r.content) f = File('Lenna2.jpg', b) f.save() assert f.id f.destroy()
def upload(file_path): if os.path.exists(file_path): img_name = os.path.split(file_path)[1] img_file = open(file_path) up_file = File(img_name, img_file) img_url = up_file.save().url print(" url: %s" % img_url) return img_url
def test_save_with_specified_key_but_without_master_key(): # type: () -> None f = File("Blah.txt", open("tests/sample_text.txt", "rb")) f.key = "abc" try: f.save() except LeanCloudError as e: if e.code == 1 and e.error.startswith("Unsupported file key"): pass
def test_thumbnail(): r = requests.get('http://www.lenna.org/full/len_std.jpg') f = File('Lenna2.jpg', r.content) f.save() assert f.id url = f.get_thumbnail_url(100, 100) assert url.endswith('?imageView/2/w/100/h/100/q/100/format/png')
def test_thumbnail(): r = requests.get('http://i1.wp.com/leancloud.cn/images/static/default-avatar.png') b = buffer_type(r.content) f = File('Lenna2.jpg', b) f.save() assert f.id url = f.get_thumbnail_url(100, 100) assert url.endswith('?imageView/2/w/100/h/100/q/100/format/png')
def upload(file_path): print file_path img_name = path.split(file_path)[1] with open(file_path, 'rb') as f: img_file = read_full_file(f) # Qiang up_file = File(img_name, buffer(img_file)) up_file.save() img_url = up_file.url return img_url
def test_thumbnail(): r = requests.get('http://www.lenna.org/full/len_std.jpg') b = buffer(r.content) f = File('lenna.jpg', b) f.save() assert f.id url = f.get_thumbnail_url(100, 100) assert url.endswith('?imageView/2/w/100/h/100/q/100/format/png')
def upload(file_path): cmp_file_path = dirpath + file_path if os.path.exists(cmp_file_path): img_name = os.path.split(cmp_file_path)[1] img_file = open(cmp_file_path) up_file = File(img_name, img_file) img_url = up_file.save().url # print(" url: %s" % img_url) return img_url
def test_thumbnail(): r = requests.get('http://i1.wp.com/leancloud.cn/images/static/default-avatar.png') b = buffer(r.content) f = File('Lenna2.jpg', b) f.save() assert f.id url = f.get_thumbnail_url(100, 100) assert url.endswith('?imageView/2/w/100/h/100/q/100/format/png')
def test_thumbnail(): # type: () -> None r = requests.get("http://i1.wp.com/leancloud.cn/images/static/default-avatar.png") b = io.BytesIO(r.content) f = File("Lenna2.jpg", b) f.save() assert f.id url = f.get_thumbnail_url(100, 100) assert url.endswith("?imageView/2/w/100/h/100/q/100/format/png")
def test_save_external(): # type: () -> None file_name = "lenna.jpg" file_url = "http://i1.wp.com/leancloud.cn/images/static/default-avatar.png" f = File.create_with_url(file_name, file_url) f.save() assert f.id file_on_cloud = File.create_without_data(f.id) file_on_cloud.fetch() assert file_on_cloud.name == file_name assert file_on_cloud.url == file_url
def get_img(url): try: fn = url.split('/')[-1] c = urllib2.urlopen(url).read() f = StringIO(c) lc_file = File(fn, f) lc_file.save() r = lc_file.url except Exception, e: print '---------', e r = None
def test_save(): # type: () -> None user = leancloud.User() user.login('user1_name', 'password') f = File('Blah.txt', open('tests/sample_text.txt', 'rb')) f.save() assert f.owner_id == user.id assert f.id assert f.name == 'Blah.txt' assert f.mime_type == 'text/plain' assert not f.url.endswith('.')
def upload_file(self, file_abspath): filename = os.path.basename(file_abspath) # filename have suffix with open(file_abspath, 'r') as f: upload_file = File(filename, f) upload_file.save() print 'uploaded', file_abspath img_file = self._class() img_file.set('File', upload_file) img_file.set('filename', filename) tag_list = LeanCloudApi.get_tag_list(filename) img_file.set('tag_list', tag_list) img_file.save() self.add_img_info(img_file.id) # save img_info after save
def test_save_with_specified_key(): # type: () -> None f = File("Blah.txt", open("tests/sample_text.txt", "rb")) user_specified_key = "abc" f.key = user_specified_key f.save() assert f.id assert f.name == "Blah.txt" assert f.mime_type == "text/plain" path = urlparse(f.url).path if path.startswith("/avos-cloud-"): # old school aws s3 file url assert path.split("/")[2] == user_specified_key else: assert path == "/" + user_specified_key
def test_file_callback(): # type: () -> None d = {} def noop(token, *args, **kwargs): d['token'] = token f = File('xxx', io.BytesIO(b'xxx')) f._save_to_s3 = noop f._save_to_qiniu = noop f._save_to_qcloud = noop f.save() f._save_callback(d['token'], False)
def test_file_callback(): # type: () -> None d = {} def noop(token, *args, **kwargs): d["token"] = token f = File("xxx", io.BytesIO(b"xxx")) f._save_to_s3 = noop f._save_to_qiniu = noop f._save_to_qcloud = noop f.save() f._save_callback(d["token"], False)
def test_basic(): s = BytesIO(b'blah blah blah') if PY2: import cStringIO s1 = cStringIO.StringIO() s1.write('blah blah blah') else: s1 = s f1 = File('Blah', s, 'text/plain') f2 = File('Blah', s1) f3 = File('Blah', open('tests/test_file.txt', 'rb')) for f in (f1, f2, f3): assert f.name == 'Blah' assert f._metadata['size'] == 14 assert f.size == 14 assert f._type == 'text/plain'
def test_create_with_url(): # type: () -> None f = File.create_with_url( "xxx", u"http://i1.wp.com/leancloud.cn/images/static/default-avatar.png", meta_data={}, ) assert f.url == "http://i1.wp.com/leancloud.cn/images/static/default-avatar.png"
def test_thumbnail_size_erorr(): # type: () -> None r = requests.get("http://i1.wp.com/leancloud.cn/images/static/default-avatar.png") b = io.BytesIO(r.content) f = File("Lenna2.jpg", b) f.save() assert f.id f.get_thumbnail_url(-1, -1) f.get_thumbnail_url(1, 1, quality=110)
def test_thumbnail_size_erorr(): r = requests.get('http://i1.wp.com/leancloud.cn/images/static/default-avatar.png') b = buffer_type(r.content) f = File('Lenna2.jpg', b) f.save() assert f.id f.get_thumbnail_url(-1, -1) f.get_thumbnail_url(1, 1, quality=110)
def on_message(self, message): logging.info(message) msg = json.loads(message['data']) musics = msg.get('musics') # download for music in musics: song_name = music.get('song_name') song_id = music.get('song_id') singer_name = music.get('singer_name') singer_id = music.get('singer_id') audition_list = music.get('audition_list') album_id = music.get('album_id') album_name = music.get('album_name') audition = audition_list[-1] url = audition.get('url') duration = audition.get('duration') suffix = audition.get('suffix') bit_rate = audition.get('bitRate') type_description = audition.get('typeDescription') size = audition.get('size') pic_url = music.get('mv_list')[0].get('pic_url') if music.get( 'mv_list') else '' if not Query(Music).equal_to('song_id', song_id).find(): filename = u'{}-{}.mp3'.format(song_name, singer_name) f = File(filename, StringIO.StringIO(urllib2.urlopen(url).read())) f.save() picture = None if pic_url: picture_name = u'{}-{}.jpg'.format(song_name, singer_name) picture = File( picture_name, StringIO.StringIO(urllib2.urlopen(pic_url).read())) picture.save() m = Music() m.file = f m.duration = duration m.suffix = suffix m.bit_rate = bit_rate m.type_description = type_description m.size = size m.song_name = song_name m.song_id = song_id m.singer_name = singer_name m.singer_id = singer_id m.album_id = album_id m.album_name = album_name if picture: m.picture = picture m.save()
def post(self, username): profile_fields = ['realName', 'gender', 'school', 'grade', 'major', 'about'] userProfile = Query(UserProfile).equal_to("user", username).first() try: for key in profile_fields: userProfile.set(key, self.get_argument(key, "")) if 'file' in self.request.files: file_dict_list = self.request.files['file'] for file_dict in file_dict_list: data = file_dict["body"] avatar = File("avatar", buffer(data)) avatar.save() userProfile.set("avatar", avatar.get_thumbnail_url(width='200', height='200')) userProfile.save() self.redirect('/user/'+username) print self.request except LeanCloudError, e: pass
def test_thumbnail_size_erorr(): r = requests.get('http://www.lenna.org/full/len_std.jpg') f = File('Lenna2.jpg', r.content) f.save() assert f.id f.get_thumbnail_url(-1, -1) f.get_thumbnail_url(1, 1, quality=110)
def test_file_field(): # type: () -> None user = User() user.login('user1_name', 'password') user.set('xxxxx', File('xxx.txt', io.BytesIO(b'qqqqq'))) user.save() q = Query(User) saved_user = q.get(user.id) assert isinstance(saved_user.get('xxxxx'), File) assert saved_user.get('xxxxx').name == 'xxx.txt'
def test_file_field(): # type: () -> None user = User() user.login("user1_name", "password") user.set("xxxxx", File("xxx.txt", io.BytesIO(b"qqqqq"))) user.save() q = Query(User) saved_user = q.get(user.id) assert isinstance(saved_user.get("xxxxx"), File) assert saved_user.get("xxxxx").name == "xxx.txt"
def test_file_field(): user = User() user.login('user1_name', 'password') user.set('xxxxx', File('xxx.txt', buffer('qqqqq'))) user.save() q = Query(User) saved_user = q.get(user.id) assert isinstance(saved_user.get('xxxxx'), File) assert saved_user.get('xxxxx').name == 'xxx.txt'
def test_thumbnail_size_erorr(): r = requests.get('http://i1.wp.com/leancloud.cn/images/static/default-avatar.png') b = buffer(r.content) f = File('Lenna2.jpg', b) f.save() assert f.id f.get_thumbnail_url(-1, -1) f.get_thumbnail_url(1, 1, quality=110)
def test_basic(): # type: () -> None s = BytesIO(b'blah blah blah') if PY2: import cStringIO # type: ignore s1 = cStringIO.StringIO() s1.write('blah blah blah') else: s1 = s f = File('Blah', s, mime_type='text/plain') assert f.name == 'Blah' assert f._metadata['size'] == 14 assert f.size == 14
def test_save(): # type: () -> None user = leancloud.User() name = 'user1_name' passwd = 'password' try: user.login(name, passwd) except LeanCloudError as e: if e.code == 211: user.set_username(name) user.set_password(passwd) user.sign_up() user.login(name, passwd) f = File('Blah.txt', open('tests/sample_text.txt', 'rb')) f.save() assert f.owner_id == user.id assert f.id assert f.name == 'Blah.txt' assert f.mime_type == 'text/plain' assert not f.url.endswith('.')
def test_save(): # type: () -> None user = leancloud.User() name = "user1_name" passwd = "password" try: user.login(name, passwd) except LeanCloudError as e: if e.code == 211: user.set_username(name) user.set_password(passwd) user.sign_up() user.login(name, passwd) f = File("Blah.txt", open("tests/sample_text.txt", "rb")) f.save() assert f.owner_id == user.id assert f.id assert f.name == "Blah.txt" assert f.mime_type == "text/plain" assert not f.url.endswith(".")
def test_destroy(): r = requests.get('http://i1.wp.com/leancloud.cn/images/static/default-avatar.png') b = buffer_type(r.content) f = File('Lenna2.jpg', b) f.save() assert f.id f.destroy()
def test_destroy(): # type: () -> None r = requests.get("http://i1.wp.com/leancloud.cn/images/static/default-avatar.png") b = io.BytesIO(r.content) f = File("Lenna2.jpg", b) f.save() assert f.id f.destroy()
def upload(): if not session.get('session_token'): return redirect(url_for('accounts_bp.login')) app_id = session.get('app_id', None) developer = Developer() developer.session_token = session.get('session_token') username = developer.username() app_list = developer.get_app_list() if request.method == "POST": cert = request.files.get('cert') key = request.files.get('key') app_id = request.form.get('appId') passphrase = request.form.get('passphrase') if app_id not in map(lambda x: x['app_id'], app_list): flash("This appId owned by others", "alert") return redirect(url_for("settings.upload")) cert_pem = File(app_id + '_cert.pem', StringIO(cert.read())) key_pem = File(app_id + '_key.pem', StringIO(key.read())) cert_pem.metadata.update(owner=username) key_pem.metadata.update(owner=username) cert_url = cert_pem.save().url key_url = key_pem.save().url app_query = Query(Application) app_query.equal_to('objectId', app_id) app = app_query.first() if app: app.set('cert_url', cert_url) app.set('key_url', key_url) app.set('passphrase', passphrase) app.save() flash("Certificate has added done!") return redirect(url_for("settings.upload")) return render_template('settings/upload.html', username=username, app_id=app_id, app_list=app_list)
def test_fetch(): r = requests.get('http://i1.wp.com/leancloud.cn/images/static/default-avatar.png') b = buffer_type(r.content) f = File('Lenna2.jpg', b) f.metadata['foo'] = 'bar' f.save() fetched = File.create_without_data(f.id) fetched.fetch() assert fetched.id == f.id assert fetched.metadata == f.metadata assert fetched.name == f.name assert fetched.url == f.url assert fetched.size == f.size assert fetched.url == f.url f.destroy()
def upload_image(fname): HEIGHT, WIDTH = 384, 240 #c = request.files['file'].read() with open(fname, 'rb') as f: c = f.read() file_orig = StringIO(c) im = Image.open(file_orig) h, w = im.size if h > HEIGHT or w > WIDTH: im.thumbnail((HEIGHT, WIDTH), Image.ANTIALIAS) file = StringIO() h, w = im.size if h==w: im = im.rotate(90 * 3) try: im.save(file, 'JPEG') except: #for .gif file = file_orig else: file = file_orig lc_file = File('pi', file_orig) lc_file.save() return lc_file.url
def test_fetch(): # type: () -> None r = requests.get("http://i1.wp.com/leancloud.cn/images/static/default-avatar.png") b = io.BytesIO(r.content) f = File("Lenna2.jpg", b) f.metadata["foo"] = "bar" f.save() fetched = File.create_without_data(f.id) fetched.fetch() normalized_f_url = f.url.split("/")[-1] normalized_fetched_url = f.url.split("/")[-1] assert fetched.id == f.id assert fetched.metadata == f.metadata assert fetched.name == f.name assert fetched.size == f.size assert fetched.url == f.url or normalized_fetched_url == normalized_f_url f.destroy()
def test_fetch(): r = requests.get('http://i1.wp.com/leancloud.cn/images/static/default-avatar.png') b = buffer(r.content) f = File('Lenna2.jpg', b) f.metadata['foo'] = 'bar' f.save() fetched = File.create_without_data(f.id) fetched.fetch() assert fetched.id == f.id assert fetched.metadata == f.metadata assert fetched.name == f.name assert fetched.url == f.url assert fetched.size == f.size assert fetched.url == f.url f.destroy()
def upload_file_by_url(self, filename, url, tag_list=None): """tag_list is tag of string list""" data = LeanCloudApi.fetch_data(url) if not data: return data = data.content f = File(filename, StringIO(data)) img_file = self._class() img_file.set('File', f) img_file.set('filename', filename) if tag_list: img_file.set('tag_list', tag_list) try: img_file.save() print filename, '----uploaded----' self.add_img_info(img_file.id) # save img_info after save except: 'save failed' return
def test_fetch(): # type: () -> None r = requests.get('http://i1.wp.com/leancloud.cn/images/static/default-avatar.png') b = io.BytesIO(r.content) f = File('Lenna2.jpg', b) f.metadata['foo'] = 'bar' f.save() fetched = File.create_without_data(f.id) fetched.fetch() normalized_f_url = f.url.split('/')[-1] normalized_fetched_url = f.url.split('/')[-1] assert fetched.id == f.id assert fetched.metadata == f.metadata assert fetched.name == f.name assert fetched.size == f.size assert fetched.url == f.url or normalized_fetched_url == normalized_f_url f.destroy()
def test_create_without_data(): f = File.create_without_data(123) assert f.id == 123
def test_acl(): # type: () -> None acl_ = ACL() f = File('Blah', io.BytesIO(b'xxx')) assert_raises(TypeError, f.set_acl, 'a') f.set_acl(acl_) assert f.get_acl() == acl_
def test_thumbnail_url_erorr(): f = File.create_with_url('xx', False) f.get_thumbnail_url(100, 100)
def test_save_external(): f = File.create_with_url('lenna.jpg', 'http://i1.wp.com/leancloud.cn/images/static/default-avatar.png') f.save() assert f.id
def test_thumbnail_url_erorr(): # type: () -> None f = File.create_with_url('xx', '') f.get_thumbnail_url(100, 100)
def test_save(): f = File('blah', buffer('xxx')) f.save() assert f.id
def test_save(): f = File('Blah', 'xxx') f.save() assert f.id
def test_create_with_url(): f = File.create_with_url('xxx', 'http://www.lenna.org/full/len_std.jpg', meta_data={}) assert f.url == 'http://www.lenna.org/full/len_std.jpg'
def test_acl(): acl = ACL() f = File('Blah', buffer('xxx')) assert_raises(TypeError, f.set_acl, 'a') f.set_acl(acl) assert f.get_acl() == acl
def test_save(): f = File('Blah', buffer('xxx')) f.save() assert f.id
def test_create_without_data(): # type: () -> None f = File.create_without_data('a123') assert f.id == 'a123'
def test_create_with_url(): f = File.create_with_url('xxx', 'http://i1.wp.com/leancloud.cn/images/static/default-avatar.png', meta_data={}) assert f.url == 'http://i1.wp.com/leancloud.cn/images/static/default-avatar.png'
def test_save_external(): f = File.create_with_url('lenna.jpg', 'http://www.lenna.org/full/len_std.jpg') f.save() assert f.id