本文整理汇总了Python中flask_flatpages.FlatPages.get方法的典型用法代码示例。如果您正苦于以下问题:Python FlatPages.get方法的具体用法?Python FlatPages.get怎么用?Python FlatPages.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask_flatpages.FlatPages
的用法示例。
在下文中一共展示了FlatPages.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_basic
# 需要导入模块: from flask_flatpages import FlatPages [as 别名]
# 或者: from flask_flatpages.FlatPages import get [as 别名]
def test_basic(self):
pages = FlatPages(Flask(__name__))
hello = pages.get('headerid')
self.assertEqual(
hello.html,
u'<h1>Page Header</h1>\n<h2>Paragraph Header</h2>\n<p>Text</p>'
)
pages.app.config['FLATPAGES_MARKDOWN_EXTENSIONS'] = []
pages.reload()
pages._file_cache = {}
hello = pages.get('headerid')
self.assertEqual(
hello.html,
u'<h1>Page Header</h1>\n<h2>Paragraph Header</h2>\n<p>Text</p>'
)
pages.app.config['FLATPAGES_MARKDOWN_EXTENSIONS'] = [
'codehilite', 'headerid'
]
pages.reload()
pages._file_cache = {}
hello = pages.get('headerid')
self.assertEqual(
hello.html,
'<h1 id="page-header">Page Header</h1>\n'
'<h2 id="paragraph-header">Paragraph Header</h2>\n'
'<p>Text</p>'
)
示例2: test_other_html_renderer
# 需要导入模块: from flask_flatpages import FlatPages [as 别名]
# 或者: from flask_flatpages.FlatPages import get [as 别名]
def test_other_html_renderer(self):
def body_renderer(body):
return body.upper()
def page_renderer(body, pages, page):
return page.body.upper()
def pages_renderer(body, pages):
return pages.get('hello').body.upper()
renderers = filter(None, (
operator.methodcaller('upper'),
'string.upper' if not compat.IS_PY3 else None,
body_renderer,
page_renderer,
pages_renderer
))
for renderer in (renderers):
pages = FlatPages(Flask(__name__))
pages.app.config['FLATPAGES_HTML_RENDERER'] = renderer
hello = pages.get('hello')
self.assertEqual(hello.body, u'Hello, *世界*!\n')
# Upper-case, markdown not interpreted
self.assertEqual(hello.html, u'HELLO, *世界*!\n')
示例3: TestFlatPagesPandoc
# 需要导入模块: from flask_flatpages import FlatPages [as 别名]
# 或者: from flask_flatpages.FlatPages import get [as 别名]
class TestFlatPagesPandoc(unittest.TestCase):
def setUp(self):
self.tmp = mkdtemp()
self.content = os.path.join(self.tmp, "content")
os.makedirs(self.content)
self.app = Flask(__name__)
self.app.config.update(
FLATPAGES_ROOT=self.content,
FLATPAGES_ENCODING="utf-8",
FLATPAGES_AUTO_RELOAD=True,
)
self.pages = FlatPages(self.app)
FlatPagesPandoc("markdown", self.app, pre_render=False)
def tearDown(self):
rmtree(self.tmp)
def get(self, body, ext=".md", enc="utf-8"):
self.app.config.update(FLATPAGES_EXTENSION=ext)
with open(os.path.join(self.content, "test" + ext), "w", enc) as f:
f.write(u"title:test\n\n" + body)
return self.pages.get("test").html
def test_h1(self):
self.assertEqual(self.get("# test"), '<h1 id="test">test</h1>\n')
def test_unicode(self):
self.assertEqual(self.get(u"萬大事都有得解決"), u"<p>萬大事都有得解決</p>\n")
def test_unicode2(self):
self.app.config.update(FLATPAGES_ENCODING="iso-8859-15")
self.assertEqual(self.get(u"äöü", enc="iso-8859-15"), u"<p>äöü</p>\n")
示例4: test_html_conversion
# 需要导入模块: from flask_flatpages import FlatPages [as 别名]
# 或者: from flask_flatpages.FlatPages import get [as 别名]
def test_html_conversion(self):
pages = FlatPages(Flask(__name__))
foo = pages.get("foo")
print "we get here"
print foo["description_html"]
self.assertTrue(True)
self.assertEquals(foo["description"].strip(), '# hello')
self.assertEquals(foo["description_html"], '<h1>hello</h1>')
示例5: test_other_html_renderer
# 需要导入模块: from flask_flatpages import FlatPages [as 别名]
# 或者: from flask_flatpages.FlatPages import get [as 别名]
def test_other_html_renderer(self):
for renderer in (unicode.upper, 'string.upper'):
pages = FlatPages(Flask(__name__))
pages.app.config['FLATPAGES_HTML_RENDERER'] = renderer
hello = pages.get('hello')
self.assertEquals(hello.body, u'Hello, *世界*!\n')
# Upper-case, markdown not interpreted
self.assertEquals(hello.html, u'HELLO, *世界*!\n')
示例6: TestPages
# 需要导入模块: from flask_flatpages import FlatPages [as 别名]
# 或者: from flask_flatpages.FlatPages import get [as 别名]
class TestPages(TestCase):
def setUp(self):
app.config["FLATPAGES_ROOT"] = "test/test_pages"
self.pages = FlatPages(app)
def test_get_fenced_blocks(self):
page = self.pages.get("test-install-python")
code = fenced_code(page.html)
assert_not_in("Verified on MacOSX", code)
assert_in("brew install python3", code)
示例7: test_instance_relative
# 需要导入模块: from flask_flatpages import FlatPages [as 别名]
# 或者: from flask_flatpages.FlatPages import get [as 别名]
def test_instance_relative(self):
with temp_directory() as temp:
source = os.path.join(os.path.dirname(__file__), 'pages')
dest = os.path.join(temp, 'instance', 'pages')
shutil.copytree(source, dest)
app = Flask(__name__, instance_path=os.path.join(temp, 'instance'))
app.config['FLATPAGES_INSTANCE_RELATIVE'] = True
pages = FlatPages(app)
bar = pages.get('foo/bar')
self.assertTrue(bar is not None)
示例8: test_yaml_meta
# 需要导入模块: from flask_flatpages import FlatPages [as 别名]
# 或者: from flask_flatpages.FlatPages import get [as 别名]
def test_yaml_meta(self):
pages = FlatPages(Flask(__name__))
foo = pages.get('foo')
self.assertEquals(foo.meta, {
'title': 'Foo > bar',
'created': datetime.date(2010, 12, 11),
'versions': [3.14, 42]
})
self.assertEquals(foo['title'], 'Foo > bar')
self.assertEquals(foo['created'], datetime.date(2010, 12, 11))
self.assertEquals(foo['versions'], [3.14, 42])
self.assertRaises(KeyError, lambda: foo['nonexistent'])
示例9: test_extra
# 需要导入模块: from flask_flatpages import FlatPages [as 别名]
# 或者: from flask_flatpages.FlatPages import get [as 别名]
def test_extra(self):
app = Flask(__name__)
app.config['FLATPAGES_MARKDOWN_EXTENSIONS'] = ['extra']
pages = FlatPages(app)
extra_sep = '\n' if sys.version_info[:2] > (2, 6) else '\n\n'
extra = pages.get('extra')
self.assertEqual(
extra.html,
'<p>This is <em>true</em> markdown text.</p>\n'
'<div>{0}'
'<p>This is <em>true</em> markdown text.</p>\n'
'</div>'.format(extra_sep)
)
示例10: test_codehilite_linenums_disabled
# 需要导入模块: from flask_flatpages import FlatPages [as 别名]
# 或者: from flask_flatpages.FlatPages import get [as 别名]
def test_codehilite_linenums_disabled(self):
app = Flask(__name__)
app.config['FLATPAGES_MARKDOWN_EXTENSIONS'] = [
'codehilite(linenums=False)'
]
pages = FlatPages(app)
codehilite = pages.get('codehilite')
self.assertEqual(
codehilite.html,
'<div class="codehilite"><pre><span class="k">print</span>'
'<span class="p">(</span><span class="s">'Hello, world!''
'</span><span class="p">)</span>\n</pre></div>'
)
示例11: test_headerid_with_toc
# 需要导入模块: from flask_flatpages import FlatPages [as 别名]
# 或者: from flask_flatpages.FlatPages import get [as 别名]
def test_headerid_with_toc(self):
app = Flask(__name__)
pages = FlatPages(app)
pages.app.config['FLATPAGES_MARKDOWN_EXTENSIONS'] = [
'codehilite', 'toc' #headerid is deprecated in Markdown 3.0
]
pages.reload()
pages._file_cache = {}
hello = pages.get('headerid')
self.assertEqual(
hello.html,
'<h1 id="page-header">Page Header</h1>\n'
'<h2 id="paragraph-header">Paragraph Header</h2>\n'
'<p>Text</p>'
)
self.check_default_codehilite_page(pages) #test codehilite also loaded
示例12: TestFlatPagesKnitr
# 需要导入模块: from flask_flatpages import FlatPages [as 别名]
# 或者: from flask_flatpages.FlatPages import get [as 别名]
class TestFlatPagesKnitr(unittest.TestCase):
def setUp(self):
self.tmp = mkdtemp()
self.content = os.path.join(self.tmp, "content")
os.makedirs(self.content)
self.app = Flask(__name__, static_folder=os.path.join(self.tmp, "static"))
self.app.config.update(
FLATPAGES_ROOT=self.content,
FLATPAGES_AUTO_RELOAD=True,
FLATPAGES_ENCODING="utf-8",
FLATPAGES_MARKDOWN_EXTENSIONS=["fenced_code"],
)
self.pages = FlatPages(self.app)
FlatPagesKnitr(self.app)
def tearDown(self):
rmtree(self.tmp)
def get(self, body, ext=".Rmd", enc="utf-8"):
self.app.config.update(FLATPAGES_EXTENSION=ext)
with open(os.path.join(self.content, "test" + ext), "w", enc) as f:
f.write("title:test\n\n" + body)
return self.pages.get("test").html
def test_rmd(self):
self.assertEqual(self.get("#test"), "<h1>test</h1>")
def test_r(self):
self.assertTrue("3.14" in self.get("```{r}\npi\n```"))
def test_plot(self):
self.get("```{r, test}\nplot(1:4, 1:4)\n```")
self.assertTrue(os.path.exists(os.path.join(
self.tmp, "static", "knitr", "test", "figure", "test-1.png")))
def test_unicode(self):
self.assertTrue(u"萬大事都有得解決" in self.get(u"```{r}\npaste('萬大事都有得解決')\n```"))
def test_unicode2(self):
self.app.config.update(FLATPAGES_ENCODING="iso-8859-15")
self.assertEqual(self.get(u"äöü", enc="iso-8859-15"), u"<p>äöü</p>")
示例13: test_markdown
# 需要导入模块: from flask_flatpages import FlatPages [as 别名]
# 或者: from flask_flatpages.FlatPages import get [as 别名]
def test_markdown(self):
pages = FlatPages(Flask(__name__))
foo = pages.get('foo')
self.assertEqual(foo.body, 'Foo *bar*\n')
self.assertEqual(foo.html, '<p>Foo <em>bar</em></p>')
示例14: test_get
# 需要导入模块: from flask_flatpages import FlatPages [as 别名]
# 或者: from flask_flatpages.FlatPages import get [as 别名]
def test_get(self):
pages = FlatPages(Flask(__name__))
self.assertEqual(pages.get('foo/bar').path, 'foo/bar')
self.assertEqual(pages.get('nonexistent'), None)
self.assertEqual(pages.get('nonexistent', 42), 42)
示例15: test_consistency
# 需要导入模块: from flask_flatpages import FlatPages [as 别名]
# 或者: from flask_flatpages.FlatPages import get [as 别名]
def test_consistency(self):
pages = FlatPages(Flask(__name__))
for page in pages:
assert pages.get(page.path) is page