当前位置: 首页>>代码示例>>Python>>正文


Python Mimeview.convert_content方法代码示例

本文整理汇总了Python中trac.mimeview.api.Mimeview.convert_content方法的典型用法代码示例。如果您正苦于以下问题:Python Mimeview.convert_content方法的具体用法?Python Mimeview.convert_content怎么用?Python Mimeview.convert_content使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在trac.mimeview.api.Mimeview的用法示例。


在下文中一共展示了Mimeview.convert_content方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ProductTicketConversionTestCase

# 需要导入模块: from trac.mimeview.api import Mimeview [as 别名]
# 或者: from trac.mimeview.api.Mimeview import convert_content [as 别名]
class ProductTicketConversionTestCase(TicketConversionTestCase, \
        MultiproductTestCase):

    def setUp(self):
        self._mp_setup()
        self.global_env = self.env
        self.env = ProductEnvironment(self.global_env, self.default_product)

        # Product name inserted in RSS feed
        self.env.product._data['name'] = 'My Project'

        self.env.config.set('trac', 'templates_dir',
                            os.path.join(os.path.dirname(self.env.path),
                                         'templates'))
        self.ticket_module = ProductTicketModule(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=[], authname='-', args={}, tz=None,
                        locale='', session=None, form_token=None)

    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,'
                          'product,keywords,cc\r'
                          '\n1,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(('\xef\xbb\xbf'
                          'id\tsummary\treporter\towner\tdescription\tstatus\t'
                          'product\tkeywords\tcc\r\n'
                          '1\tFoo\tsanta\t\tBar\t\t\t\t\r\n',
                          'text/tab-separated-values;charset=utf-8', 'tsv'),
                         csv)

    def tearDown(self):
        self.global_env.reset_db()
开发者ID:Stackato-Apps,项目名称:bloodhound,代码行数:47,代码来源:conversion.py

示例2: _test_convert_content

# 需要导入模块: from trac.mimeview.api import Mimeview [as 别名]
# 或者: from trac.mimeview.api.Mimeview import convert_content [as 别名]
 def _test_convert_content(self, expected, content, iterable):
     mimeview = Mimeview(self.env)
     output = mimeview.convert_content(self._make_req(), self.in_mimetype,
                                       content, 'text', iterable=iterable)
     if iterable:
         self.assertNotIn(type(output[0]), (str, unicode))
         self.assertEqual(expected, ''.join(output[0]))
     else:
         self.assertEqual(type(expected), type(output[0]))
         self.assertEqual(expected, output[0])
     self.assertEqual('text/plain', output[1])
     self.assertEqual('txt', output[2])
开发者ID:exocad,项目名称:exotrac,代码行数:14,代码来源:api.py

示例3: TicketConversionTestCase

# 需要导入模块: from trac.mimeview.api import Mimeview [as 别名]
# 或者: from trac.mimeview.api.Mimeview import convert_content [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(
#.........这里部分代码省略.........
开发者ID:pkdevbox,项目名称:trac,代码行数:103,代码来源:conversion.py

示例4: TicketConversionTestCase

# 需要导入模块: from trac.mimeview.api import Mimeview [as 别名]
# 或者: from trac.mimeview.api.Mimeview import convert_content [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",
#.........这里部分代码省略.........
开发者ID:spsoft-RockWang,项目名称:project-_trac,代码行数:103,代码来源:conversion.py

示例5: TicketConversionTestCase

# 需要导入模块: from trac.mimeview.api import Mimeview [as 别名]
# 或者: from trac.mimeview.api.Mimeview import convert_content [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>&lt;p&gt;\nBar\n&lt;/p&gt;\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))
开发者ID:cyphactor,项目名称:lifecyclemanager,代码行数:66,代码来源:conversion.py


注:本文中的trac.mimeview.api.Mimeview.convert_content方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。