本文整理汇总了Python中ptah.resolve函数的典型用法代码示例。如果您正苦于以下问题:Python resolve函数的具体用法?Python resolve怎么用?Python resolve使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了resolve函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_container_delete
def test_container_delete(self):
container = Container(__name__ = 'container', __path__ = '/container/')
content = Content(title='Content')
ptah.cms.Session.add(container)
ptah.cms.Session.add(content)
ptah.cms.Session.flush()
container['content'] = content
content_uri = content.__uri__
container_uri = container.__uri__
transaction.commit()
container = ptah.resolve(container_uri)
del container['content']
self.assertEqual(container.keys(), [])
self.assertEqual(container.values(), [])
transaction.commit()
self.assertTrue(ptah.resolve(content_uri) is None)
container = ptah.resolve(container_uri)
self.assertEqual(container.keys(), [])
self.assertRaises(KeyError, container.__delitem__, 'content')
self.assertRaises(KeyError, container.__delitem__, Content())
示例2: generateThumbnail
def generateThumbnail(theme, width=210):
blob = ptah.resolve(theme.preview)
if not blob:
return
data = StringIO(blob.read())
image = PIL.Image.open(data)
if image.mode == '1':
image = image.convert('L')
elif image.mode == 'P':
image = image.convert('RGBA')
# get width, height
orig_size = image.size
scale = float(width)/orig_size[0]
height = int(round(orig_size[1] * scale))
#convert image
pilfilter = PIL.Image.NEAREST
pilfilter = PIL.Image.ANTIALIAS
image.thumbnail((width, height), pilfilter)
newfile = StringIO()
image.save(newfile, 'jpeg', quality=88)
blob = ptah.resolve(theme.thumbnail)
if blob is None:
blob = ptah.cms.blob_storage.create(theme)
theme.thumbnail = blob.__uri__
blob.write(newfile.getvalue())
blob.updateMetadata(mimetype = 'image/jpeg')
示例3: test_container_getitem
def test_container_getitem(self):
container = Container(__name__="container", __path__="/container/")
content1 = Content(title="Content1")
content2 = Content(title="Content2")
container["content1"] = content1
container["content2"] = content2
self.assertEqual(container["content1"].__uri__, content1.__uri__)
self.assertEqual(container["content2"].__uri__, content2.__uri__)
self.assertEqual(container.get("content1").__uri__, content1.__uri__)
self.assertEqual(container.get("content2").__uri__, content2.__uri__)
ptah.cms.Session.add(container)
ptah.cms.Session.add(content1)
ptah.cms.Session.add(content2)
ptah.cms.Session.flush()
c_u = container.__uri__
c1_u = content1.__uri__
c2_u = content2.__uri__
transaction.commit()
container = ptah.resolve(c_u)
self.assertEqual(container["content1"].__uri__, c1_u)
self.assertEqual(container["content2"].__uri__, c2_u)
transaction.commit()
container = ptah.resolve(c_u)
self.assertEqual(container.get("content1").__uri__, c1_u)
self.assertEqual(container.get("content2").__uri__, c2_u)
示例4: test_container_simple_move
def test_container_simple_move(self):
container = Container(__name__ = 'container', __path__ = '/container/')
content = Content(title='Content')
ptah.cms.Session.add(container)
ptah.cms.Session.add(content)
ptah.cms.Session.flush()
container['content'] = content
content_uri = content.__uri__
container_uri = container.__uri__
transaction.commit()
container = ptah.resolve(container_uri)
content = ptah.resolve(content_uri)
container['moved'] = content
self.assertEqual(content.__name__, 'moved')
self.assertEqual(content.__path__, '/container/moved/')
self.assertEqual(content.__parent__, container)
self.assertEqual(content.__parent_uri__, container.__uri__)
transaction.commit()
container = ptah.resolve(container_uri)
self.assertEqual(container.keys(), ['moved'])
self.assertEqual(container['moved'].__uri__, content_uri)
示例5: __call__
def __call__(self):
self.tinfo = ptah.resolve(self.params['turi'])
with ptah.sa_session() as sa:
self.session = sa
self.context = ptah.resolve(self.params['uri'])
return super(EditRecord, self).__call__()
示例6: test_container_simple_move
def test_container_simple_move(self):
container = Container(__name__="container", __path__="/container/")
content = Content(title="Content")
ptah.cms.Session.add(container)
ptah.cms.Session.add(content)
ptah.cms.Session.flush()
container["content"] = content
content_uri = content.__uri__
container_uri = container.__uri__
transaction.commit()
container = ptah.resolve(container_uri)
content = ptah.resolve(content_uri)
container["moved"] = content
self.assertEqual(content.__name__, "moved")
self.assertEqual(content.__path__, "/container/moved/")
self.assertEqual(content.__parent__, container)
self.assertEqual(content.__parent_uri__, container.__uri__)
transaction.commit()
container = ptah.resolve(container_uri)
self.assertEqual(container.keys(), ["moved"])
self.assertEqual(container["moved"].__uri__, content_uri)
示例7: test_container_insert_subtree
def test_container_insert_subtree(self):
container = Container(__name__="container", __path__="/container/")
folder = Container(title="Folder")
content = Content(title="Content")
ptah.cms.Session.add(container)
ptah.cms.Session.add(folder)
ptah.cms.Session.add(content)
folder["content"] = content
container["folder"] = folder
content_uri = content.__uri__
folder_uri = folder.__uri__
container_uri = container.__uri__
transaction.commit()
container = ptah.resolve(container_uri)
content = ptah.resolve(content_uri)
folder = ptah.resolve(folder_uri)
self.assertEqual(container.keys(), ["folder"])
self.assertEqual(folder.keys(), ["content"])
self.assertEqual(folder.__path__, "/container/folder/")
self.assertEqual(content.__path__, "/container/folder/content/")
transaction.commit()
示例8: test_container_insert_subtree
def test_container_insert_subtree(self):
container = Container(__name__ = 'container', __path__ = '/container/')
folder = Container(title='Folder')
content = Content(title='Content')
ptah.cms.Session.add(container)
ptah.cms.Session.add(folder)
ptah.cms.Session.add(content)
folder['content'] = content
container['folder'] = folder
content_uri = content.__uri__
folder_uri = folder.__uri__
container_uri = container.__uri__
transaction.commit()
container = ptah.resolve(container_uri)
content = ptah.resolve(content_uri)
folder = ptah.resolve(folder_uri)
self.assertEqual(container.keys(), ['folder'])
self.assertEqual(folder.keys(), ['content'])
self.assertEqual(folder.__path__, '/container/folder/')
self.assertEqual(content.__path__, '/container/folder/content/')
transaction.commit()
示例9: test_container_getitem
def test_container_getitem(self):
container = Container(__name__ = 'container', __path__ = '/container/')
content1 = Content(title='Content1')
content2 = Content(title='Content2')
container['content1'] = content1
container['content2'] = content2
self.assertEqual(container['content1'].__uri__, content1.__uri__)
self.assertEqual(container['content2'].__uri__, content2.__uri__)
self.assertEqual(container.get('content1').__uri__, content1.__uri__)
self.assertEqual(container.get('content2').__uri__, content2.__uri__)
ptah.cms.Session.add(container)
ptah.cms.Session.add(content1)
ptah.cms.Session.add(content2)
ptah.cms.Session.flush()
c_u = container.__uri__
c1_u = content1.__uri__
c2_u = content2.__uri__
transaction.commit()
container = ptah.resolve(c_u)
self.assertEqual(container['content1'].__uri__, c1_u)
self.assertEqual(container['content2'].__uri__, c2_u)
transaction.commit()
container = ptah.resolve(c_u)
self.assertEqual(container.get('content1').__uri__, c1_u)
self.assertEqual(container.get('content2').__uri__, c2_u)
示例10: test_superuser_resolver
def test_superuser_resolver(self):
import ptah
from ptah.authentication import SUPERUSER
self._init_ptah()
user = ptah.resolve(ptah.SUPERUSER_URI)
self.assertIs(user, SUPERUSER)
self.assertIsNone(ptah.resolve("ptah+auth:unknown"))
示例11: test_superuser_resolver
def test_superuser_resolver(self):
import ptah
from ptah.authentication import SUPERUSER
self.init_ptah()
user = ptah.resolve(ptah.SUPERUSER_URI)
self.assertIs(user, SUPERUSER)
self.assertIsNone(ptah.resolve('ptah-auth:unknown'))
self.assertEqual(repr(user), '<ptah Superuser>')
示例12: test_blob_write
def test_blob_write(self):
import ptah, ptah.cms
blob_uri = ptah.cms.blobStorage.add(StringIO("blob data")).__uri__
blob = ptah.resolve(blob_uri)
blob.write("new data")
transaction.commit()
blob = ptah.resolve(blob_uri)
self.assertEqual(blob.read(), "new data")
示例13: test_blob_write
def test_blob_write(self):
import ptah
blob_uri = ptah.cms.blob_storage.add(
BytesIO(bytes_('blob data','utf-8'))).__uri__
blob = ptah.resolve(blob_uri)
blob.write(bytes_('new data','utf-8'))
transaction.commit()
blob = ptah.resolve(blob_uri)
self.assertEqual(blob.read(), bytes_('new data','utf-8'))
示例14: test_container_basics
def test_container_basics(self):
container = Container(__name__="container", __path__="/container/")
content = Content(title="Content")
ptah.cms.Session.add(container)
ptah.cms.Session.add(content)
ptah.cms.Session.flush()
self.assertEqual(content.__path__, "")
self.assertRaises(ValueError, container.__setitem__, "content", object())
self.assertRaises(ValueError, container.__setitem__, "content", container)
container["content"] = content
self.assertEqual(content.__name__, "content")
self.assertEqual(content.__path__, "/container/content/")
self.assertEqual(content.__parent__, container)
self.assertEqual(content.__parent_uri__, container.__uri__)
content_uri = content.__uri__
container_uri = container.__uri__
transaction.commit()
container = ptah.resolve(container_uri)
self.assertTrue("content" in container)
self.assertEqual(container.keys(), ["content"])
self.assertEqual(container["content"].__uri__, content_uri)
self.assertEqual(container.get("content").__uri__, content_uri)
self.assertEqual(container.get("unknown"), None)
self.assertRaises(KeyError, container.__getitem__, "unknown")
content = container["content"]
self.assertRaises(KeyError, container.__setitem__, "content", content)
示例15: create
def create(self, tname, name=None, **params):
tinfo = ptah.resolve(tname)
if tinfo is None:
raise NotFound('Type information is not found')
tinfo.check_context(self)
item = tinfo.create()
if not name:
name = item.__uri__
if '/' in name:
raise Error("Names cannot contain '/'")
if name.startswith(' '):
raise Error("Names cannot starts with ' '")
if name in self:
raise Error("Name already in use.")
self[name] = item
item.update(**params)
return item