• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python _compat.u函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pygal._compat.u函数的典型用法代码示例。如果您正苦于以下问题:Python u函数的具体用法?Python u怎么用?Python u使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_no_data

def test_no_data():
    line = Line()
    q = line.render_pyquery()
    assert q(".text-overlay text").text() == "No data"
    line.no_data_text = u("þæ®þ怀&ij¿’€")
    q = line.render_pyquery()
    assert q(".text-overlay text").text() == u("þæ®þ怀&ij¿’€")
开发者ID:AllanDaemon,项目名称:pygal,代码行数:7,代码来源:test_config.py


示例2: test_value_formatter

def test_value_formatter():
    line = Line(value_formatter=lambda x: str(x) + u('‰'))
    line.add('_', [10 ** 4, 10 ** 5, 23 * 10 ** 4])
    q = line.render_pyquery()
    assert len(q(".y.axis .guides")) == 11
    assert q(".axis.y text").map(texts) == list(map(
        lambda x: str(x) + u('‰'), map(float, range(20000, 240000, 20000))))
开发者ID:AllanDaemon,项目名称:pygal,代码行数:7,代码来源:test_config.py


示例3: test_render_data_uri

def test_render_data_uri(Chart):
    """Test the render data uri"""
    chart = Chart(fill=True)
    chart.add(u('ééé'), [1, 2, 3])
    chart.add(u('èèè'), [10, 21, 5])
    assert chart.render_data_uri().startswith(
        'data:image/svg+xml;charset=utf-8;base64,')
开发者ID:ConnorMooreLUC,项目名称:pygal,代码行数:7,代码来源:test_config.py


示例4: add_styles

    def add_styles(self):
        """Add the css to the svg"""
        colors = self.graph.style.get_colors(self.id, self.graph._order)
        strokes = self.get_strokes()
        all_css = []
        auto_css = ["file://base.css"]

        if self.graph.style._google_fonts:
            auto_css.append(
                "//fonts.googleapis.com/css?family=%s" % quote_plus("|".join(self.graph.style._google_fonts))
            )

        for css in auto_css + list(self.graph.css):
            css_text = None
            if css.startswith("inline:"):
                css_text = css[len("inline:") :]
            elif css.startswith("file://"):
                css = css[len("file://") :]

                if not os.path.exists(css):
                    css = os.path.join(os.path.dirname(__file__), "css", css)

                with io.open(css, encoding="utf-8") as f:
                    css_text = template(f.read(), style=self.graph.style, colors=colors, strokes=strokes, id=self.id)

            if css_text is not None:
                if not self.graph.pretty_print:
                    css_text = minify_css(css_text)
                all_css.append(css_text)
            else:
                if css.startswith("//") and self.graph.force_uri_protocol:
                    css = "%s:%s" % (self.graph.force_uri_protocol, css)
                self.processing_instructions.append(etree.PI(u("xml-stylesheet"), u('href="%s"' % css)))
        self.node(self.defs, "style", type="text/css").text = "\n".join(all_css)
开发者ID:Kozea,项目名称:pygal,代码行数:34,代码来源:svg.py


示例5: __init__

    def __init__(self, graph):
        """Create the svg helper with the chart instance"""
        self.graph = graph
        if not graph.no_prefix:
            self.id = "#chart-%s " % graph.uuid
        else:
            self.id = ""
        self.processing_instructions = [etree.ProcessingInstruction(u("xml"), u("version='1.0' encoding='utf-8'"))]
        if etree.lxml:
            attrs = {"nsmap": {None: self.ns, "xlink": self.xlink_ns}}
        else:
            attrs = {"xmlns": self.ns}
            if hasattr(etree, "register_namespace"):
                etree.register_namespace("xlink", self.xlink_ns)
            else:
                etree._namespace_map[self.xlink_ns] = "xlink"

        self.root = etree.Element("svg", **attrs)
        self.root.attrib["id"] = self.id.lstrip("#").rstrip()
        self.root.attrib["class"] = "pygal-chart"
        self.root.append(
            etree.Comment(
                u(
                    "Generated with pygal %s (%s) ©Kozea 2011-2015 on %s"
                    % (__version__, "lxml" if etree.lxml else "etree", date.today().isoformat())
                )
            )
        )
        self.root.append(etree.Comment(u("http://pygal.org")))
        self.root.append(etree.Comment(u("http://github.com/Kozea/pygal")))
        self.defs = self.node(tag="defs")
        self.title = self.node(tag="title")
        self.title.text = graph.title or "Pygal"
开发者ID:regzhuce,项目名称:pygal,代码行数:33,代码来源:svg.py


示例6: render_sparktext

    def render_sparktext(self, relative_to=None):
        """Make a mini text sparkline from chart"""
        bars = u('▁▂▃▄▅▆▇█')
        if len(self.raw_series) == 0:
            return u('')
        values = list(self.raw_series[0][1])
        if len(values) == 0:
            return u('')

        chart = u('')
        values = list(map(lambda x: max(x, 0), values))

        vmax = max(values)
        if relative_to is None:
            relative_to = min(values)

        if (vmax - relative_to) == 0:
            chart = bars[0] * len(values)
            return chart

        divisions = len(bars) - 1
        for value in values:
            chart += bars[int(divisions *
                              (value - relative_to) / (vmax - relative_to))]
        return chart
开发者ID:andreiSaw,项目名称:analyticsserver-1359,代码行数:25,代码来源:public.py


示例7: add_styles

 def add_styles(self):
     """Add the css to the svg"""
     colors = self.graph.config.style.get_colors(self.id)
     all_css = []
     for css in ['base.css'] + list(self.graph.css):
         if '://' in css:
             self.processing_instructions.append(
                 etree.PI(
                     u('xml-stylesheet'), u('href="%s"' % css)))
         else:
             if css.startswith('inline:'):
                 css_text = css[len('inline:'):]
             else:
                 if not os.path.exists(css):
                     css = os.path.join(
                         os.path.dirname(__file__), 'css', css)
                 with io.open(css, encoding='utf-8') as f:
                     css_text = template(
                         f.read(),
                         style=self.graph.config.style,
                         colors=colors,
                         font_sizes=self.graph.config.font_sizes(),
                         id=self.id)
             if not self.graph.pretty_print:
                 css_text = minify_css(css_text)
             all_css.append(css_text)
     self.node(
         self.defs, 'style', type='text/css').text = '\n'.join(all_css)
开发者ID:AlanRun,项目名称:UiAutoTest,代码行数:28,代码来源:svg.py


示例8: __init__

 def __init__(self, graph):
     self.graph = graph
     if not graph.no_prefix:
         self.id = '#chart-%s ' % graph.uuid
     else:
         self.id = ''
     self.processing_instructions = [
         etree.PI(u('xml'), u("version='1.0' encoding='utf-8'"))]
     self.root = etree.Element(
         "{%s}svg" % self.ns,
         nsmap={
             None: self.ns,
             'xlink': 'http://www.w3.org/1999/xlink',
         })
     self.root.attrib['id'] = self.id.lstrip('#').rstrip()
     self.root.attrib['class'] = 'pygal-chart'
     self.root.append(
         etree.Comment(u(
             'Generated with pygal %s ©Kozea 2011-2014 on %s' % (
                 __version__, date.today().isoformat()))))
     self.root.append(etree.Comment(u('http://pygal.org')))
     self.root.append(etree.Comment(u('http://github.com/Kozea/pygal')))
     self.defs = self.node(tag='defs')
     self.title = self.node(tag='title')
     self.title.text = graph.title or 'Pygal'
开发者ID:HanderLo,项目名称:pygal,代码行数:25,代码来源:svg.py


示例9: add_styles

    def add_styles(self):
        """Add the css to the svg"""
        colors = self.graph.style.get_colors(self.id, self.graph._order)
        strokes = self.get_strokes()
        all_css = []
        for css in ["base.css"] + list(self.graph.css):
            if "://" in css:
                self.processing_instructions.append(etree.PI(u("xml-stylesheet"), u('href="%s"' % css)))
            else:
                if css.startswith("inline:"):
                    css_text = css[len("inline:") :]
                else:
                    if not os.path.exists(css):
                        css = os.path.join(os.path.dirname(__file__), "css", css)

                    class FontSizes(object):
                        """Container for font sizes"""

                    fs = FontSizes()
                    for name in dir(self.graph.state):
                        if name.endswith("_font_size"):
                            setattr(fs, name.replace("_font_size", ""), ("%dpx" % getattr(self.graph, name)))

                    with io.open(css, encoding="utf-8") as f:
                        css_text = template(
                            f.read(), style=self.graph.style, colors=colors, strokes=strokes, font_sizes=fs, id=self.id
                        )
                if not self.graph.pretty_print:
                    css_text = minify_css(css_text)
                all_css.append(css_text)
        self.node(self.defs, "style", type="text/css").text = "\n".join(all_css)
开发者ID:langelee,项目名称:pygal,代码行数:31,代码来源:svg.py


示例10: test_truncate

def test_truncate():
    assert truncate('1234567890', 50) == '1234567890'
    assert truncate('1234567890', 5) == u('1234…')
    assert truncate('1234567890', 1) == u('…')
    assert truncate('1234567890', 9) == u('12345678…')
    assert truncate('1234567890', 10) == '1234567890'
    assert truncate('1234567890', 0) == '1234567890'
    assert truncate('1234567890', -1) == '1234567890'
开发者ID:Bouska,项目名称:pygal,代码行数:8,代码来源:test_util.py


示例11: test_same_max_and_relative_values_sparktext

def test_same_max_and_relative_values_sparktext():
    chart = Line()
    chart.add('_', [0, 0, 0, 0, 0])
    assert chart.render_sparktext() == u('▁▁▁▁▁')

    chart2 = Line()
    chart2.add('_', [1, 1, 1, 1, 1])
    assert chart2.render_sparktext(relative_to=1) == u('▁▁▁▁▁')
开发者ID:AlanRun,项目名称:UiAutoTest,代码行数:8,代码来源:test_sparktext.py


示例12: test_no_data_sparktext

def test_no_data_sparktext():
    """Test no data sparktext"""
    chart2 = Line()
    chart2.add('_', [])
    assert chart2.render_sparktext() == u('')

    chart3 = Line()
    assert chart3.render_sparktext() == u('')
开发者ID:aroraumang,项目名称:pygal,代码行数:8,代码来源:test_sparktext.py


示例13: test_truncate

def test_truncate():
    """Test truncate function"""
    assert truncate('1234567890', 50) == '1234567890'
    assert truncate('1234567890', 5) == u('1234…')
    assert truncate('1234567890', 1) == u('…')
    assert truncate('1234567890', 9) == u('12345678…')
    assert truncate('1234567890', 10) == '1234567890'
    assert truncate('1234567890', 0) == '1234567890'
    assert truncate('1234567890', -1) == '1234567890'
开发者ID:madaiz11,项目名称:pygal,代码行数:9,代码来源:test_util.py


示例14: test_negative_and_float_and_no_data_sparktext

def test_negative_and_float_and_no_data_sparktext():
    chart = Line()
    chart.add('_', [0.1, 0.2, 0.9, -0.5])
    assert chart.render_sparktext() == u('▁▂█▁')

    chart2 = Line()
    chart2.add('_', [])
    assert chart2.render_sparktext() == u('')

    chart3 = Line()
    assert chart3.render_sparktext() == u('')
开发者ID:Bouska,项目名称:pygal,代码行数:11,代码来源:test_sparktext.py


示例15: add_styles

    def add_styles(self):
        """Add the css to the svg"""
        colors = self.graph.style.get_colors(self.id, self.graph._order)
        strokes = self.get_strokes()
        all_css = []
        auto_css = [base_css]

        if self.graph.style._google_fonts:
            auto_css.append(
                '//fonts.googleapis.com/css?family=%s' % quote_plus(
                    '|'.join(self.graph.style._google_fonts))
            )

        for css in auto_css + list(self.graph.css):
            css_text = None
            if type(css) == str and css.startswith('inline:'):
                css_text = css[len('inline:'):]
            elif type(css) == str and css.startswith('file://'):
                if not os.path.exists(css):
                    css = os.path.join(
                        os.path.dirname(__file__), 'css', css[len('file://'):])

                with io.open(css, encoding='utf-8') as f:
                    css_text = template(
                        f.read(),
                        style=self.graph.style,
                        colors=colors,
                        strokes=strokes,
                        id=self.id)
            elif not type(css) == str:
                css_text = template(
                    css.data,
                    style=self.graph.style,
                    colors=colors,
                    strokes=strokes,
                    id=self.id)

            if css_text is not None:
                if not self.graph.pretty_print:
                    css_text = minify_css(css_text)
                all_css.append(css_text)
            else:
                if type(css) == str and css.startswith('//') and self.graph.force_uri_protocol:
                    css = '%s:%s' % (self.graph.force_uri_protocol, css)
                self.processing_instructions.append(
                    etree.PI(
                        u('xml-stylesheet'), u('href="%s"' % css)))
        self.node(
            self.defs, 'style', type='text/css').text = '\n'.join(all_css)
开发者ID:never-eat-yellow-snow,项目名称:pygal,代码行数:49,代码来源:svg.py


示例16: test_swap_curly

def test_swap_curly():
    """Test swap curly function"""
    for str in ('foo', u('foo foo foo bar'), 'foo béè b¡ð/ijə˘©þß®~¯æ',
                u('foo béè b¡ð/ijə˘©þß®~¯æ')):
        assert _swap_curly(str) == str
    assert _swap_curly('foo{bar}baz') == 'foo{{bar}}baz'
    assert _swap_curly('foo{{bar}}baz') == 'foo{bar}baz'
    assert _swap_curly('{foo}{{bar}}{baz}') == '{{foo}}{bar}{{baz}}'
    assert _swap_curly('{foo}{{{bar}}}{baz}') == '{{foo}}{{{bar}}}{{baz}}'
    assert _swap_curly('foo{ bar }baz') == 'foo{{ bar }}baz'
    assert _swap_curly('foo{ bar}baz') == 'foo{{ bar}}baz'
    assert _swap_curly('foo{bar }baz') == 'foo{{bar }}baz'
    assert _swap_curly('foo{{ bar }}baz') == 'foo{bar}baz'
    assert _swap_curly('foo{{bar }}baz') == 'foo{bar}baz'
    assert _swap_curly('foo{{ bar}}baz') == 'foo{bar}baz'
开发者ID:Kozea,项目名称:pygal,代码行数:15,代码来源:test_util.py


示例17: test_another_sparktext

def test_another_sparktext():
    chart = Line()
    chart.add('_', [0, 30, 55, 80, 33, 150])
    assert chart.render_sparktext() == u('▁▂▃▄▂█')
    assert chart.render_sparktext() == chart.render_sparktext()
    chart2 = Bar()
    chart2.add('_', [0, 30, 55, 80, 33, 150])
    assert chart2.render_sparktext() == chart.render_sparktext()
开发者ID:Bouska,项目名称:pygal,代码行数:8,代码来源:test_sparktext.py


示例18: test_another_sparktext

def test_another_sparktext():
    """Test that same data produces same sparktext"""
    chart = Line()
    chart.add('_', [0, 30, 55, 80, 33, 150])
    assert chart.render_sparktext() == u('▁▂▃▄▂█')
    assert chart.render_sparktext() == chart.render_sparktext()
    chart2 = Bar()
    chart2.add('_', [0, 30, 55, 80, 33, 150])
    assert chart2.render_sparktext() == chart.render_sparktext()
开发者ID:aroraumang,项目名称:pygal,代码行数:9,代码来源:test_sparktext.py


示例19: __init__

 def __init__(self, graph):
     self.graph = graph
     self.processing_instructions = [
         etree.PI(u('xml'), u("version='1.0' encoding='utf-8'"))]
     self.root = etree.Element(
         "{%s}svg" % self.ns,
         nsmap={
             None: self.ns,
             'xlink': 'http://www.w3.org/1999/xlink',
         })
     self.root.append(
         etree.Comment(u(
             'Generated with pygal %s ©Kozea 2011-2013 on %s' % (
             __version__, date.today().isoformat()))))
     self.root.append(etree.Comment(u('http://pygal.org')))
     self.root.append(etree.Comment(u('http://github.com/Kozea/pygal')))
     self.defs = self.node(tag='defs')
     self.title = self.node(tag='title')
     self.title.text = graph.title or 'Pygal'
开发者ID:psibi,项目名称:pygal,代码行数:19,代码来源:svg.py


示例20: __init__

    def __init__(self, graph):
        """Create the svg helper with the chart instance"""
        self.graph = graph
        if not graph.no_prefix:
            self.id = '#chart-%s ' % graph.uuid
        else:
            self.id = ''
        self.processing_instructions = [
            etree.ProcessingInstruction(
                u('xml'), u("version='1.0' encoding='utf-8'"))]
        if etree.lxml:
            attrs = {
                'nsmap': {
                    None: self.ns,
                    'xlink': self.xlink_ns
                }
            }
        else:
            attrs = {
                'xmlns': self.ns
            }
            if hasattr(etree, 'register_namespace'):
                etree.register_namespace('xlink', self.xlink_ns)
            else:
                etree._namespace_map[self.xlink_ns] = 'xlink'

        self.root = etree.Element('svg', **attrs)
        self.root.attrib['id'] = self.id.lstrip('#').rstrip()
        self.root.attrib['class'] = 'pygal-chart'
        self.root.append(
            etree.Comment(u(
                'Generated with pygal %s (%s) ©Kozea 2011-2015 on %s' % (
                    __version__,
                    'lxml' if etree.lxml else 'etree',
                    date.today().isoformat()))))
        self.root.append(etree.Comment(u('http://pygal.org')))
        self.root.append(etree.Comment(u('http://github.com/Kozea/pygal')))
        self.defs = self.node(tag='defs')
        self.title = self.node(tag='title')
        self.title.text = graph.title or 'Pygal'

        for def_ in self.graph.defs:
            self.defs.append(etree.fromstring(def_))
开发者ID:JacobBurger,项目名称:flask-sample,代码行数:43,代码来源:svg.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python colors.hsl_to_rgb函数代码示例发布时间:2022-05-25
下一篇:
Python _compat.is_list_like函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap