本文整理汇总了Python中site_helper.storage函数的典型用法代码示例。如果您正苦于以下问题:Python storage函数的具体用法?Python storage怎么用?Python storage使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了storage函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_toModel_widthIndentList_7
def test_toModel_widthIndentList_7(self):
source = '''
1
id: 1
model: SiteConfig
name: na
2
value: vb
aa
3
id: 2
model: SiteConfig
name: nc
'''
target = [
['1', sh.storage({
'SiteConfigid': 1L,
'value': 'v1',
'name': 'na',
'title': 't1',
})
],
['2', sh.storage({'value': 'vb'})],
['aa', [
'3', sh.storage({
'SiteConfigid': 2L,
'value': 'v2',
'name': 'nc',
'title': 't2',
})
]
]
]
开发者ID:ajiexw,项目名称:zarkpy,代码行数:34,代码来源:TestIndentTable.py
示例2: test_indentsToDict_addIndex
def test_indentsToDict_addIndex(self):
source = '''
aaa
bb: BB
cc: CC
ddd
ee
ff
gg
hh:
ll
'''
target = sh.storage({
'__index' : 0,
'aaa': sh.storage({
'__index' : 1,
'cc': 'CC',
'bb': 'BB'}),
'ddd': sh.storage({
'__index' : 2,
'ee': sh.storage({
'__index' : 3,
'ff': ''}),
'gg': '',
'hh': ''}), # toDict时,key后面的冒号可有可无
'll' : '',
})
indents = t_ctrl.indent(source)
results = t_ctrl.indentsToDict(indents, add_index=True)
self.assertEqual(results, target)
开发者ID:ajiexw,项目名称:zarkpy,代码行数:32,代码来源:TestIndentTable.py
示例3: test_toModel_widthIndentList_4
def test_toModel_widthIndentList_4(self):
source = '''
1
name: na
2
value: vb
aa
bb
cc: dd
ee
ff
3
name: nc
'''
target = [
['1', sh.storage({'name': 'na'})],
['2', sh.storage({'value': 'vb'})],
['aa', [
['bb', sh.storage({'cc': 'dd'})],
'ee',
['ff',
['3', sh.storage({'name': 'nc'})]]
]
]
]
indents = t_ctrl.indent(source)
list_results = t_ctrl.indentsToList(indents)
self.assertEqual(t_ctrl.toModel(list_results), target )
self.assertEqual(t_ctrl.getIndentsLevel(indents), 4)
开发者ID:ajiexw,项目名称:zarkpy,代码行数:33,代码来源:TestIndentTable.py
示例4: test_indentsToDict
def test_indentsToDict(self):
source = '''
aaa
bb: BB
cc: CC
ddd
ee:
ff
gg
hh:
ll
'''
target = sh.storage({
'aaa': sh.storage({
'cc': 'CC',
'bb': 'BB'}),
'ddd': sh.storage({
'ee': sh.storage({'ff': ''}), # toDict时,冒号可写可不写
'gg': '',
'hh': ''}),
'll' : '',
})
indents = t_ctrl.indent(source)
results = t_ctrl.indentsToDict(indents)
self.assertEqual(results, target)
self.assertEqual(type(results.aaa), sh.storage_class)
# 测试contentToDict集合了indent和indentsToDict
self.assertEqual(t_ctrl.contentToDict(source), target)
开发者ID:ajiexw,项目名称:zarkpy,代码行数:33,代码来源:TestIndentTable.py
示例5: test_update
def test_update(self):
'''更新头像内容'''
user_model = self.model
data = test_helper.storage({'username':'sdjl', 'email':'[email protected]', 'password':'sdjllyh', 'birthday':'1985-10-17'})
data.imagefile = site_helper.storage({'filename':'sdjl.jpg', 'value':'shuai!shuai!shuai!shuai!shuai!shuai!shuai!shuai!shuai!shuai!shuai!'})
new_id = user_model.insert(data)
data.imagefile = site_helper.storage({'filename':'sdjl.jpg', 'value':'chou!chou!chou!chou!chou!chou!chou!chou!chou!chou!'})
user_model.update(new_id, data)
self.assertEqual(open('%s%d.jpg' % (site_helper.config.USER_COVER_PATH, new_id)).read().strip(), 'chou!chou!chou!chou!chou!chou!chou!chou!chou!chou!')
开发者ID:ajiexw,项目名称:old-zarkpy,代码行数:9,代码来源:TestUser.py
示例6: test_update_saveimage
def test_update_saveimage(self):
'''更新的时候要替换原来的图片文件'''
makeup_model = self.model
db_helper = getDBHelper()
data = test_helper.storage({'name':'面膜', 'cover_url':'/img/makeupreserve/cover/1.jpg' })
data.imagefile = site_helper.storage({'filename':'c://sdjl.jpg', 'value':'liuyonghui'})
new_makeup_id = makeup_model.insert(data)
data.imagefile = site_helper.storage({'filename':'c://wx.jpg', 'value':'wangxuan'})
makeup_model.update(new_makeup_id, data)
self.assertEqual(open('%s%d.jpg' % (site_helper.config.MAKEUP_COVER_PATH, new_makeup_id)).read().strip(), 'wangxuan')
开发者ID:ajiexw,项目名称:old-zarkpy,代码行数:10,代码来源:TestMakeup.py
示例7: test_toModel_widthIndentDict_4
def test_toModel_widthIndentDict_4(self):
source = '1'
target = sh.storage({
'1': sh.storage({
'name': 'n1',
'SiteConfigid': 1L,
'value': 'v1',
'title': 't1',
}),
})
开发者ID:ajiexw,项目名称:zarkpy,代码行数:10,代码来源:TestIndentTable.py
示例8: assignUserInfo
def assignUserInfo(self, data, access_token):
new_data = sh.copy(data) if data else sh.storage()
exists = sh.model(self.MODEL_NAME).getByAccessToken(access_token)
if not exists: return new_data
res = sh.requestHtmlContent(self.USER_INFO_URL, (
'access_token', access_token,
'oauth_consumer_key', self.getAppID(),
'uid', exists.uid,
))
if not res: return new_data
res = sh.loadsJson(res)
if res.get('error_code', None): return new_data
if not new_data.has_key('name'):
new_data['name'] = res.screen_name
if res.gender == 'm':
new_data['sex'] = '他'
elif res.gender == 'f':
new_data['sex'] = '她'
else:
new_data['sex'] = '保密'
image_file = sh.requestImageFile(res.avatar_large)
if image_file:
new_data['image_file'] = image_file
return new_data
开发者ID:ajiexw,项目名称:zarkpy,代码行数:32,代码来源:Sina.py
示例9: POST
def POST(self, inputs=None):
if not inputs:
inputs = sh.inputs()
assert inputs.has_key("action")
if inputs.action == "postImage":
assert inputs.get("Userid", 0)
assert sh.model("User").get(inputs.Userid)
assert inputs.get("data_name", None)
assert inputs.get("data_id", None)
img_model = sh.model("UserImage")
image_data = sh.getSwfUploadImageFile()
new_id = img_model.insert(
sh.storage(
dict(
image_file=image_data,
Userid=inputs.Userid,
file_name=image_data.filename,
data_name=inputs.data_name,
data_id=inputs.data_id,
)
)
)
return "success;%d;%s;%s" % (new_id, img_model.getUrlByPrivate(inputs.Userid, new_id), image_data.filename)
开发者ID:kevinhao,项目名称:zarkpy,代码行数:27,代码来源:UserImage.py
示例10: getEmptyData
def getEmptyData(self):
data = sh.storage([(k, '') for k in self.model.column_names])
for name, ct in self.getColumnTypes().items():
if isinstance(ct, dict) and ct.has_key('default'):
data[name] = ct.default
data['__is_empty'] = True
return data
开发者ID:ajiexw,项目名称:zarkpy,代码行数:7,代码来源:EmptyModel.py
示例11: assignUserInfo
def assignUserInfo(self, data, access_token):
new_data = sh.copy(data) if data else sh.storage()
exists = sh.model(self.MODEL_NAME).getByAccessToken(access_token)
if not exists: return new_data
res = sh.requestHtmlContent(self.USER_INFO_URL, (
'access_token', access_token,
'oauth_consumer_key', self.getAppID(),
'openid', exists.uid,
'format', 'json',
))
if not res: return new_data
res = sh.loadsJson(res)
if res.ret != 0: return new_data
if not new_data.has_key('name'):
new_data['name'] = res.nickname
if res.gender == '男':
new_data['sex'] = '他'
elif res.gender == '女':
new_data['sex'] = '她'
image_file = sh.requestImageFile(res.figureurl_2)
if image_file:
new_data['image_file'] = image_file
return new_data
开发者ID:ajiexw,项目名称:zarkpy,代码行数:29,代码来源:QQ.py
示例12: test_insert_convert
def test_insert_convert(self):
image_modle = sh.model('Image')
image_model.use_convert = True # 改变图片
image_model.convert_type = 'png'
image_model.max_width = 50
image_model.max_height = 60
data = sh.storage({'data_name': 'User', 'data_id': 1, image_model.image_key: test_image_data})
id = image_model.insert(data)
item = image_model.get(id)
image_path = sh.urlToPath(item.url)
# 转换为png格式
self.assertTrue(image_path.endswith('/%d.png' % (id)))
self.assertEqual(imghdr.what(None, open(image_path).read()), 'png')
# 压缩为50x50. 因为会保持原有比例,所以压缩后高度依然是50, 不是60
self.assertEqual(Image.open(image_path).size, (50, 50))
# 当max_height与max_width有其中之一为None时就不压缩
image_model.max_height = None
id2 = image_model.insert(data)
item2 = image_model.get(id2)
# 虽然不压缩尺寸,但是要转换格式
image_path = sh.urlToPath(item2.url)
self.assertTrue(image_path.endswith('/%d.png' % (id2)))
# 依然是原来的尺寸
self.assertEqual(Image.open(image_path).size, Image.open(test_image_data.filename).size)
开发者ID:ajiexw,项目名称:zarkpy,代码行数:25,代码来源:TestImage.py
示例13: GET
def GET(self):
inputs = sh.inputs()
assert inputs.has_key("code")
assert inputs.has_key("state")
site_name = inputs.state.partition("_")[0]
authorization_code = inputs.code.strip()
oauth_ctrl = sh.ctrl("oauth.%s" % site_name)
oauth_model = sh.model("oauth.%sOAuth2" % site_name)
user_ctrl = sh.ctrl("User")
user_model = sh.model("User")
token_url = oauth_ctrl.createAccessTokenUrl(authorization_code)
content = sh.requestHtmlContent(token_url, None, oauth_ctrl.ACCESS_TOKEN_METHOD)
assert content, u"第三方返回的数据有误"
access_token, access_expires = oauth_ctrl.pickAccessTokenAndExpires(content)
requested_uid = oauth_ctrl.requestUidWithAccessToken(access_token)
assert requested_uid, u"第三方返回的数据有误"
if self.TEST_API_LOGIN:
login_url = "%s/api/oauth/login?access_token=%s&access_expires=%s&uid=%s&state=%s" % (
sh.config.HOST_NAME,
access_token,
access_expires,
requested_uid,
inputs.state,
)
return '<a href="%s" >%s</a>' % (login_url, login_url)
# 因为access_token是动态变化的,所以要用requested_uid来判断是否登录过
# 这也避免了access_token变化时插入重复的uid
exists = oauth_model.getByUid(requested_uid)
# 如果当前uid还没有插入数据库,则先插入再考虑绑定Userid
if not exists:
new_oauth_id = oauth_model.insert(
dict(uid=requested_uid, access_token=access_token, access_expires=access_expires)
)
exists = oauth_model.get(new_oauth_id)
# 如果已绑定Userid则登录
if exists.Userid:
return self.login(exists.Userid)
# 如果希望自动注册,则注册并绑定后登录
if self.NO_REGISTER_ACTION == "auto_register":
data = oauth_ctrl.assignUserInfo(sh.storage(), access_token)
self.assignRandomPassword(data)
self.assignRegisterIP(data)
conflict = user_ctrl.checkNewUser(data)
if conflict:
return self.redirectToRegister(access_token, inputs.state, error=conflict)
new_user_id = user_model.insert(data)
oauth_model.update(exists.id, dict(Userid=new_user_id))
return self.login(new_user_id)
# 否则希望用户自己注册
elif self.NO_REGISTER_ACTION == "to_register":
return self.redirectToRegister(access_token, inputs.state)
开发者ID:kevinhao,项目名称:zarkpy,代码行数:59,代码来源:Login.py
示例14: test_getUrl_getFilePath
def test_getUrl_getFilePath(self):
image_modle = sh.model('Image')
image_model.use_convert = False
data = sh.storage({'data_name': 'User', 'data_id': 1, image_model.image_key: test_image_data})
id = image_model.insert(data)
item = image_model.get(id)
self.assertEqual(item.url, image_model.getUrl(id))
self.assertEqual(sh.urlToPath(item.url), image_model.getFilePath(id))
开发者ID:ajiexw,项目名称:zarkpy,代码行数:8,代码来源:TestImage.py
示例15: requestImageFile
def requestImageFile(self, url):
response, content = self.getHtmlContent(url)
if response.status == 200:
ret_image_file = site_helper.storage()
ret_image_file.filename = url + '.jpeg'
ret_image_file.value = content
return ret_image_file
else:
return None
开发者ID:ajiexw,项目名称:old-zarkpy,代码行数:9,代码来源:OAuth2.py
示例16: test_delete
def test_delete(self):
my_id = self.register()
# 插入图片并得到UserImageid
data = sh.storage(dict(action = 'postImage', Userid = my_id, data_name='None', data_id=2))
data.Filedata = open(test_image_path).read()
data.Filename = 'good_image.jpg'
new_img_id = int(self.post(api_url, data).split(';')[1])
self.assertEqual(self.proxyDo(ui_model.get, new_img_id).deleted, 'no')
# 使用delete删除图片
self.get(api_url, dict(action='delete', UserImageid=new_img_id))
self.assertIsNone(self.proxyDo(ui_model.get, new_img_id))
开发者ID:ajiexw,项目名称:zarkpy,代码行数:11,代码来源:TestUserImage.py
示例17: test_insert_saveimage
def test_insert_saveimage(self):
'''插入makeup时, 如果有imagefile,就把文件保存在config.MAKEUP_COVER_PATH中, 并且以Makeupid命名, 修改cover_url指向图片文件'''
makeup_model = self.model
db_helper = getDBHelper()
data = test_helper.storage({'name':'面膜', 'cover_url':'/img/makeupreserve/cover/1.jpg' })
data.imagefile = site_helper.storage({'filename':'c://sdjl.jpg', 'value':'liuyonghui'})
new_makeup_id = makeup_model.insert(data)
self.assertTrue(os.path.exists('%s%d.jpg' % (site_helper.config.MAKEUP_COVER_PATH, new_makeup_id)))
self.assertEqual(db_helper.fetchFirst('select cover_url from Makeup where Makeupid=%s', new_makeup_id), site_helper.config.MAKEUP_COVER_URL+str(new_makeup_id)+'.jpg')
self.assertEqual(open('%s%d.jpg' % (site_helper.config.MAKEUP_COVER_PATH, new_makeup_id)).read().strip(), 'liuyonghui')
开发者ID:ajiexw,项目名称:old-zarkpy,代码行数:11,代码来源:TestMakeup.py
示例18: test_insert
def test_insert(self):
'''保存图片, 验证加密方式, 生日格式'''
user_model = self.model
data = test_helper.storage({'username':'sdjl', 'email':'[email protected]', 'password':'sdjllyh', 'birthday':'1985-10-17'})
data.imagefile = site_helper.storage({'filename':'sdjl.jpg', 'value':'shuai!shuai!shuai!shuai!shuai!shuai!shuai!shuai!shuai!shuai!shuai!'})
new_id = user_model.insert(data)
new_user = getDBHelper().fetchOne('select * from '+user_model.table_name+' where '+user_model.primary_key+'=%s',new_id)
self.assertEqual(new_user.password, 'dab61a7c59b7d5f2e9fd22c85f6aa03c') # 不允许改变加密方式
self.assertEqual(new_user.cover_url, '%s%d.jpg' % (site_helper.config.USER_COVER_URL, new_id)) # 保存图片
self.assertEqual(open('%s%d.jpg' % (site_helper.config.USER_COVER_PATH, new_id)).read().strip(), 'shuai!shuai!shuai!shuai!shuai!shuai!shuai!shuai!shuai!shuai!shuai!')
self.assertEqual(new_user.birthday, date(1985,10,17) )
开发者ID:ajiexw,项目名称:old-zarkpy,代码行数:11,代码来源:TestUser.py
示例19: test_noneToEmpty
def test_noneToEmpty(self):
item = user_model.noneToEmpty(None)
# 所有出现在column_names中的字段都为''
self.assertTrue(all([item.get(k) == '' for k in user_model.column_names]))
# 可以通过__is_empty来判断是否为空数据
self.assertTrue(item.get('__is_empty') is True)
# noneToEmpty也可以传入data列表, 只有is None时才返回Empty
items = user_model.noneToEmpty([{}, None, sh.storage()])
self.assertTrue(items[0].get('__is_empty', False) is False)
self.assertTrue(items[1].get('__is_empty', False) is True)
self.assertTrue(items[2].get('__is_empty', False) is False)
开发者ID:ajiexw,项目名称:note,代码行数:11,代码来源:TestEmptyModel.py
示例20: test_all
def test_all(self):
# 测试where
id1 = db.insert('insert into Image (data_name, data_id) values (%s, %s)', ('test_image', 123))
env = sh.storage()
env.where = ['data_name=%s and data_id=%s', ('test_image', 123)]
self.assertEqual(image_model.all(env)[0].id, id1)
# 测试where + select
env.select = 'data_name'
items = image_model.all(env)
self.assertEqual(items[0].data_name, 'test_image')
self.assertTrue(not items[0].has_key('data_id'))
# 测试orderby
id2 = db.insert('insert into Image (data_name, data_id) values (%s, %s)', ('image2', 456))
assert id2 > id1
env = sh.storage(dict(orderby='Imageid desc'))
items = image_model.all(env)
self.assertTrue(items[0].id > items[1].id)
# 测试limit
env = sh.storage(dict(limit=[0, 1]))
items = image_model.all(env)
self.assertTrue(len(items) == 1)
# 测试distinct
id3 = db.insert('insert into Image (data_name, data_id) values (%s, %s)', ('image2', 789))
env = sh.storage(dict(distinct=True, where=['data_name=%s', ['image2']]))
items = image_model.all(env)
self.assertTrue(len(items) == 2)
# 测试from + select
uid = user_model.insert(dict(email='[email protected]', name='sdjl', password='123456', register_ip='127.0.0.1', Imageid=id3))
env = sh.storage()
env['from'] = 'User u join Image i on u.Imageid=i.Imageid'
env.select = 'u.email email, i.data_id data_id'
env.where = ['email=%s', ['[email protected]']]
items = image_model.all(env)
self.assertTrue(len(items) == 1)
self.assertEqual(items[0].email, '[email protected]')
self.assertEqual(items[0].data_id, 789)
开发者ID:ajiexw,项目名称:note,代码行数:41,代码来源:TestModel.py
注:本文中的site_helper.storage函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论