本文整理汇总了Python中site_helper.storage函数的典型用法代码示例。如果您正苦于以下问题:Python storage函数的具体用法?Python storage怎么用?Python storage使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了storage函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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',
})
]
]
]
示例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)
示例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)
示例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)
示例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!')
示例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')
示例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',
}),
})
示例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
示例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)
示例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
示例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
示例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)
示例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)
示例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))
示例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