本文整理汇总了Python中trac.mimeview.api.Mimeview.get_supported_conversions方法的典型用法代码示例。如果您正苦于以下问题:Python Mimeview.get_supported_conversions方法的具体用法?Python Mimeview.get_supported_conversions怎么用?Python Mimeview.get_supported_conversions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trac.mimeview.api.Mimeview
的用法示例。
在下文中一共展示了Mimeview.get_supported_conversions方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_supported_conversions
# 需要导入模块: from trac.mimeview.api import Mimeview [as 别名]
# 或者: from trac.mimeview.api.Mimeview import get_supported_conversions [as 别名]
def test_get_supported_conversions(self):
class Converter0(Component):
implements(IContentConverter)
def get_supported_conversions(self):
yield 'key0', 'Format 0', 'c0', 'text/x-sample', 'text/html', 8
class Converter2(Component):
implements(IContentConverter)
def get_supported_conversions(self):
yield 'key2', 'Format 2', 'c2', 'text/x-sample', 'text/html', 2
class Converter1(Component):
implements(IContentConverter)
def get_supported_conversions(self):
yield 'key1', 'Format 1', 'c1', 'text/x-sample', 'text/html', 4
mimeview = Mimeview(self.env)
conversions = mimeview.get_supported_conversions('text/x-sample')
self.assertEqual(Converter0(self.env), conversions[0][-1])
self.assertEqual(Converter1(self.env), conversions[1][-1])
self.assertEqual(Converter2(self.env), conversions[2][-1])
示例2: test_get_supported_conversions
# 需要导入模块: from trac.mimeview.api import Mimeview [as 别名]
# 或者: from trac.mimeview.api.Mimeview import get_supported_conversions [as 别名]
def test_get_supported_conversions(self):
mimeview = Mimeview(self.env)
conversions = mimeview.get_supported_conversions('text/x-sample')
self.assertEqual(Converter0(self.env), conversions[0][-1])
self.assertEqual(Converter1(self.env), conversions[1][-1])
self.assertEqual(Converter2(self.env), conversions[2][-1])
示例3: TicketConversionTestCase
# 需要导入模块: from trac.mimeview.api import Mimeview [as 别名]
# 或者: from trac.mimeview.api.Mimeview import get_supported_conversions [as 别名]
class TicketConversionTestCase(unittest.TestCase):
def setUp(self):
self.env = EnvironmentStub()
self.env.config.set('trac', 'templates_dir',
os.path.join(os.path.dirname(self.env.path),
'templates'))
self.ticket_module = TicketModule(self.env)
self.mimeview = Mimeview(self.env)
self.req = Mock(base_path='/trac.cgi', path_info='',
href=Href('/trac.cgi'), chrome={'logo': {}},
abs_href=Href('http://example.org/trac.cgi'),
environ={}, perm=PermissionCache(self.env, '-'),
authname='-', args={}, tz=None,
locale='', session=None, form_token=None)
def tearDown(self):
self.env.reset_db()
def _create_a_ticket(self):
# 1. Creating ticket
ticket = Ticket(self.env)
ticket['owner'] = ''
ticket['reporter'] = 'santa'
ticket['summary'] = 'Foo'
ticket['description'] = 'Bar'
ticket['foo'] = 'This is a custom field'
ticket.insert()
return ticket
def _create_a_ticket_with_email(self):
ticket = Ticket(self.env)
ticket['owner'] = '[email protected]'
ticket['reporter'] = '[email protected]'
ticket['cc'] = 'cc1, [email protected]'
ticket['summary'] = 'Foo'
ticket['description'] = 'Bar'
ticket.insert()
return ticket
def test_conversions(self):
conversions = self.mimeview.get_supported_conversions(
'trac.ticket.Ticket')
expected = sorted([('csv', 'Comma-delimited Text', 'csv',
'trac.ticket.Ticket', 'text/csv', 8,
self.ticket_module),
('tab', 'Tab-delimited Text', 'tsv',
'trac.ticket.Ticket', 'text/tab-separated-values', 8,
self.ticket_module),
('rss', 'RSS Feed', 'xml',
'trac.ticket.Ticket', 'application/rss+xml', 8,
self.ticket_module)],
key=lambda i: i[-1], reverse=True)
self.assertEqual(expected, conversions)
def test_csv_conversion(self):
ticket = self._create_a_ticket()
csv = self.mimeview.convert_content(self.req, 'trac.ticket.Ticket',
ticket, 'csv')
self.assertEqual(('\xef\xbb\xbf'
'id,summary,reporter,owner,description,status,'
'keywords,cc\r\n1,Foo,santa,,Bar,,,\r\n',
'text/csv;charset=utf-8', 'csv'), csv)
def test_csv_conversion_with_obfuscation(self):
ticket = self._create_a_ticket_with_email()
csv = self.mimeview.convert_content(self.req, 'trac.ticket.Ticket',
ticket, 'csv')
self.assertEqual(
('\xef\xbb\xbf'
'id,summary,reporter,owner,description,status,keywords,cc\r\n'
'1,Foo,[email protected]…,[email protected]…,Bar,,,cc1 [email protected]…\r\n',
'text/csv;charset=utf-8', 'csv'),
csv)
self.req.perm = MockPerm()
csv = self.mimeview.convert_content(self.req, 'trac.ticket.Ticket',
ticket, 'csv')
self.assertEqual(
('\xef\xbb\xbf'
'id,summary,reporter,owner,description,status,keywords,cc\r\n'
'1,Foo,[email protected],[email protected],Bar,,,'
'cc1 [email protected]\r\n',
'text/csv;charset=utf-8', 'csv'),
csv)
def test_tab_conversion(self):
ticket = self._create_a_ticket()
csv = self.mimeview.convert_content(self.req, 'trac.ticket.Ticket',
ticket, 'tab')
self.assertEqual(('\xef\xbb\xbf'
'id\tsummary\treporter\towner\tdescription\tstatus\t'
'keywords\tcc\r\n1\tFoo\tsanta\t\tBar\t\t\t\r\n',
'text/tab-separated-values;charset=utf-8', 'tsv'),
csv)
def test_tab_conversion_with_obfuscation(self):
ticket = self._create_a_ticket_with_email()
csv = self.mimeview.convert_content(self.req, 'trac.ticket.Ticket',
ticket, 'tab')
self.assertEqual(
#.........这里部分代码省略.........
示例4: process_request
# 需要导入模块: from trac.mimeview.api import Mimeview [as 别名]
# 或者: from trac.mimeview.api.Mimeview import get_supported_conversions [as 别名]
def process_request(self, req):
req.perm.assert_permission('TICKET_VIEW')
action = req.args.get('action', 'view')
db = self.env.get_db_cnx()
id = int(req.args.get('id'))
ticket = Ticket(self.env, id, db=db)
if req.method == 'POST':
if not req.args.has_key('preview'):
self._do_save(req, db, ticket)
else:
# Use user supplied values
ticket.populate(req.args)
self._validate_ticket(req, ticket)
req.hdf['ticket.action'] = action
req.hdf['ticket.ts'] = req.args.get('ts')
req.hdf['ticket.reassign_owner'] = req.args.get('reassign_owner') \
or req.authname
req.hdf['ticket.resolve_resolution'] = req.args.get('resolve_resolution')
comment = req.args.get('comment')
if comment:
req.hdf['ticket.comment'] = comment
# Wiki format a preview of comment
req.hdf['ticket.comment_preview'] = wiki_to_html(
comment, self.env, req, db)
else:
req.hdf['ticket.reassign_owner'] = req.authname
# Store a timestamp in order to detect "mid air collisions"
req.hdf['ticket.ts'] = ticket.time_changed
self._insert_ticket_data(req, db, ticket,
get_reporter_id(req, 'author'))
mime = Mimeview(self.env)
format = req.args.get('format')
if format:
mime.send_converted(req, 'trac.ticket.Ticket', ticket, format,
'ticket_%d' % ticket.id)
# If the ticket is being shown in the context of a query, add
# links to help navigate in the query result set
if 'query_tickets' in req.session:
tickets = req.session['query_tickets'].split()
if str(id) in tickets:
idx = tickets.index(str(ticket.id))
if idx > 0:
add_link(req, 'first', req.href.ticket(tickets[0]),
u'Ticket #%s' % tickets[0])
add_link(req, 'prev', req.href.ticket(tickets[idx - 1]),
u'Ticket #%s' % tickets[idx - 1])
if idx < len(tickets) - 1:
add_link(req, 'next', req.href.ticket(tickets[idx + 1]),
u'Ticket #%s' % tickets[idx + 1])
add_link(req, 'last', req.href.ticket(tickets[-1]),
u'Ticket #%s' % tickets[-1])
add_link(req, 'up', req.session['query_href'])
add_stylesheet(req, 'common/css/ticket.css')
# Add registered converters
for conversion in mime.get_supported_conversions('trac.ticket.Ticket'):
conversion_href = req.href.ticket(ticket.id, format=conversion[0])
add_link(req, 'alternate', conversion_href, conversion[1],
conversion[3])
return 'ticket.cs', None
示例5: TicketConversionTestCase
# 需要导入模块: from trac.mimeview.api import Mimeview [as 别名]
# 或者: from trac.mimeview.api.Mimeview import get_supported_conversions [as 别名]
class TicketConversionTestCase(unittest.TestCase):
def setUp(self):
self.env = EnvironmentStub()
self.env.config.set("trac", "templates_dir", os.path.join(os.path.dirname(self.env.path), "templates"))
self.ticket_module = TicketModule(self.env)
self.mimeview = Mimeview(self.env)
self.req = Mock(
base_path="/trac.cgi",
path_info="",
href=Href("/trac.cgi"),
chrome={"logo": {}},
abs_href=Href("http://example.org/trac.cgi"),
environ={},
perm=PermissionCache(self.env, "-"),
authname="-",
args={},
tz=None,
locale="",
session=None,
form_token=None,
)
def tearDown(self):
self.env.reset_db()
def _create_a_ticket(self):
# 1. Creating ticket
ticket = Ticket(self.env)
ticket["owner"] = ""
ticket["reporter"] = "santa"
ticket["summary"] = "Foo"
ticket["description"] = "Bar"
ticket["foo"] = "This is a custom field"
ticket.insert()
return ticket
def _create_a_ticket_with_email(self):
ticket = Ticket(self.env)
ticket["owner"] = "[email protected]"
ticket["reporter"] = "[email protected]"
ticket["cc"] = "cc1, [email protected]"
ticket["summary"] = "Foo"
ticket["description"] = "Bar"
ticket.insert()
return ticket
def test_conversions(self):
conversions = self.mimeview.get_supported_conversions("trac.ticket.Ticket")
expected = sorted(
[
("csv", "Comma-delimited Text", "csv", "trac.ticket.Ticket", "text/csv", 8, self.ticket_module),
(
"tab",
"Tab-delimited Text",
"tsv",
"trac.ticket.Ticket",
"text/tab-separated-values",
8,
self.ticket_module,
),
("rss", "RSS Feed", "xml", "trac.ticket.Ticket", "application/rss+xml", 8, self.ticket_module),
],
key=lambda i: i[-1],
reverse=True,
)
self.assertEqual(expected, conversions)
def test_csv_conversion(self):
ticket = self._create_a_ticket()
csv = self.mimeview.convert_content(self.req, "trac.ticket.Ticket", ticket, "csv")
self.assertEqual(
(
"\xef\xbb\xbf" "id,summary,reporter,owner,description,status," "keywords,cc\r\n1,Foo,santa,,Bar,,,\r\n",
"text/csv;charset=utf-8",
"csv",
),
csv,
)
def test_csv_conversion_with_obfuscation(self):
ticket = self._create_a_ticket_with_email()
csv = self.mimeview.convert_content(self.req, "trac.ticket.Ticket", ticket, "csv")
self.assertEqual(
(
"\xef\xbb\xbf"
"id,summary,reporter,owner,description,status,keywords,cc\r\n"
"1,Foo,[email protected]…,[email protected]…,Bar,,,cc1 [email protected]…\r\n",
"text/csv;charset=utf-8",
"csv",
),
csv,
)
self.req.perm = MockPerm()
csv = self.mimeview.convert_content(self.req, "trac.ticket.Ticket", ticket, "csv")
self.assertEqual(
(
"\xef\xbb\xbf"
"id,summary,reporter,owner,description,status,keywords,cc\r\n"
"1,Foo,[email protected],[email protected],Bar,,,"
"cc1 [email protected]\r\n",
#.........这里部分代码省略.........
示例6: TicketConversionTestCase
# 需要导入模块: from trac.mimeview.api import Mimeview [as 别名]
# 或者: from trac.mimeview.api.Mimeview import get_supported_conversions [as 别名]
class TicketConversionTestCase(unittest.TestCase):
def setUp(self):
self.env = EnvironmentStub()
self.ticket_module = TicketModule(self.env)
self.mimeview = Mimeview(self.env)
self.req = Mock(hdf=HDFWrapper(['./templates']),
base_path='/trac.cgi', path_info='',
href=Href('/trac.cgi'))
def _create_a_ticket(self):
# 1. Creating ticket
ticket = Ticket(self.env)
ticket['reporter'] = 'santa'
ticket['summary'] = 'Foo'
ticket['description'] = 'Bar'
ticket['foo'] = 'This is a custom field'
return ticket
def test_conversions(self):
conversions = self.mimeview.get_supported_conversions(
'trac.ticket.Ticket')
expected = sorted([('csv', 'Comma-delimited Text', 'csv',
'trac.ticket.Ticket', 'text/csv', 8,
self.ticket_module),
('tab', 'Tab-delimited Text', 'tsv',
'trac.ticket.Ticket', 'text/tab-separated-values', 8,
self.ticket_module),
('rss', 'RSS Feed', 'xml',
'trac.ticket.Ticket', 'application/rss+xml', 8,
self.ticket_module)],
key=lambda i: i[-1], reverse=True)
self.assertEqual(expected, conversions)
def test_csv_conversion(self):
ticket = self._create_a_ticket()
csv = self.mimeview.convert_content(self.req, 'trac.ticket.Ticket',
ticket, 'csv')
self.assertEqual((u'id,summary,reporter,owner,description,keywords,cc'
'\r\nNone,Foo,santa,,Bar,,\r\n',
'text/csv;charset=utf-8', 'csv'), csv)
def test_tab_conversion(self):
ticket = self._create_a_ticket()
csv = self.mimeview.convert_content(self.req, 'trac.ticket.Ticket',
ticket, 'tab')
self.assertEqual((u'id\tsummary\treporter\towner\tdescription\tkeywords'
'\tcc\r\nNone\tFoo\tsanta\t\tBar\t\t\r\n',
'text/tab-separated-values;charset=utf-8', 'tsv'),
csv)
def test_rss_conversion(self):
ticket = self._create_a_ticket()
content, mimetype, ext = self.mimeview.convert_content(
self.req, 'trac.ticket.Ticket', ticket, 'rss')
self.assertEqual(('<?xml version="1.0"?>\n<!-- RSS generated by Trac v '
'on -->\n<rss version="2.0">\n <channel>\n '
'<title>Ticket </title>\n <link></link>\n '
'<description><p>\nBar\n</p>\n'
'</description>\n <language>en-us</language>\n '
'<generator>Trac v</generator>\n </channel>\n</rss>\n',
'application/rss+xml', 'xml'),
(content.replace('\r', ''), mimetype, ext))