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

Python util.unicode_type函数代码示例

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

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



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

示例1: __init__

    def __init__(self, color=True, fmt=DEFAULT_FORMAT,
                 datefmt=DEFAULT_DATE_FORMAT, colors=DEFAULT_COLORS):
        r"""
        :arg bool color: Enables color support.
        :arg string fmt: Log message format.
          It will be applied to the attributes dict of log records. The
          text between ``%(color)s`` and ``%(normal)s`` will be colored
          depending on the level if color support is on.
        :arg dict colors: color mappings from logging level to terminal color
          code
        :arg string datefmt: Datetime format.
          Used for formatting ``(asctime)`` placeholder in ``prefix_fmt``.
        """
        logging.Formatter.__init__(self, datefmt=datefmt)
        self._fmt = fmt

        self._colors = {}
        if color and _stderr_supports_color():
            # The curses module has some str/bytes confusion in
            # python3.  Until version 3.2.3, most methods return
            # bytes, but only accept strings.  In addition, we want to
            # output these strings with the logging module, which
            # works with unicode strings.  The explicit calls to
            # unicode() below are harmless in python2 but will do the
            # right conversion in python 3.
            fg_color = (curses.tigetstr("setaf") or
                        curses.tigetstr("setf") or "")
            if (3, 0) < sys.version_info < (3, 2, 3):
                fg_color = unicode_type(fg_color, "ascii")

            for levelno, code in colors.items():
                self._colors[levelno] = unicode_type(curses.tparm(fg_color, code), "ascii")
            self._normal = unicode_type(curses.tigetstr("sgr0"), "ascii")
        else:
            self._normal = ''
开发者ID:soulrebel,项目名称:tornado,代码行数:35,代码来源:log.py


示例2: converter_default

def converter_default(data):
    length = data.find('/')
    if length == 1 or len(data) == 0:
        raise NoMatchError()
    elif length < 0:
        length = len(data)
    return length, util.unicode_type(data[:length])
开发者ID:FlorianLudwig,项目名称:rueckenwind,代码行数:7,代码来源:routing.py


示例3: url_unescape

    def url_unescape(value, encoding='utf-8', plus=True):
        """Decodes the given value from a URL.

        The argument may be either a byte or unicode string.

        If encoding is None, the result will be a byte string.  
        
        Otherwise,
        the result is a unicode string in the specified encoding.

        If ``plus`` is true (the default), plus signs will be interpreted
        as spaces (literal plus signs must be represented as "%2B").  This
        is appropriate for query strings and form-encoded values but not
        for the path component of a URL.  
            
            Note that this default is the
        reverse of Python's urllib module.

        .. versionadded:: 3.1
           The ``plus`` argument
        """
        unquote = (urllib_parse.unquote_plus if plus else urllib_parse.unquote)
        if encoding is None:
            return unquote(utf8(value))
        else:
            return unicode_type(unquote(utf8(value)), encoding)
开发者ID:183181731,项目名称:ApiTest,代码行数:26,代码来源:escape2.py


示例4: __init__

    def __init__(
        self,
        fmt: str = DEFAULT_FORMAT,
        datefmt: str = DEFAULT_DATE_FORMAT,
        style: str = "%",
        color: bool = True,
        colors: Dict[int, int] = DEFAULT_COLORS,
    ) -> None:
        r"""
        :arg bool color: Enables color support.
        :arg str fmt: Log message format.
          It will be applied to the attributes dict of log records. The
          text between ``%(color)s`` and ``%(end_color)s`` will be colored
          depending on the level if color support is on.
        :arg dict colors: color mappings from logging level to terminal color
          code
        :arg str datefmt: Datetime format.
          Used for formatting ``(asctime)`` placeholder in ``prefix_fmt``.

        .. versionchanged:: 3.2

           Added ``fmt`` and ``datefmt`` arguments.
        """
        logging.Formatter.__init__(self, datefmt=datefmt)
        self._fmt = fmt

        self._colors = {}  # type: Dict[int, str]
        if color and _stderr_supports_color():
            if curses is not None:
                fg_color = curses.tigetstr("setaf") or curses.tigetstr("setf") or b""

                for levelno, code in colors.items():
                    # Convert the terminal control characters from
                    # bytes to unicode strings for easier use with the
                    # logging module.
                    self._colors[levelno] = unicode_type(
                        curses.tparm(fg_color, code), "ascii"
                    )
                self._normal = unicode_type(curses.tigetstr("sgr0"), "ascii")
            else:
                # If curses is not present (currently we'll only get here for
                # colorama on windows), assume hard-coded ANSI color codes.
                for levelno, code in colors.items():
                    self._colors[levelno] = "\033[2;3%dm" % code
                self._normal = "\033[0m"
        else:
            self._normal = ""
开发者ID:bdarnell,项目名称:tornado,代码行数:47,代码来源:log.py


示例5: get_path

 def get_path(self, values=None):
     if values is None:
         values = {}
     re = []
     for converter, args, data in self.route:
         if converter:
             re.append(util.unicode_type(values[data]))
         else:
             re.append(data)
     return ''.join(re)
开发者ID:FlorianLudwig,项目名称:rueckenwind,代码行数:10,代码来源:routing.py


示例6: url_unescape

    def url_unescape(value, encoding='utf-8'):
        """Decodes the given value from a URL.

        The argument may be either a byte or unicode string.

        If encoding is None, the result will be a byte string.  Otherwise,
        the result is a unicode string in the specified encoding.
        """
        if encoding is None:
            return urllib_parse.unquote_plus(utf8(value))
        else:
            return unicode_type(urllib_parse.unquote_plus(utf8(value)), encoding)
开发者ID:1stvamp,项目名称:tornado,代码行数:12,代码来源:escape.py


示例7: __init__

 def __init__(self, color=True, *args, **kwargs):
     logging.Formatter.__init__(self, *args, **kwargs)
     self._color = color and _stderr_supports_color()
     if self._color:
         # The curses module has some str/bytes confusion in
         # python3.  Until version 3.2.3, most methods return
         # bytes, but only accept strings.  In addition, we want to
         # output these strings with the logging module, which
         # works with unicode strings.  The explicit calls to
         # unicode() below are harmless in python2 but will do the
         # right conversion in python 3.
         fg_color = (curses.tigetstr("setaf") or
                     curses.tigetstr("setf") or "")
         if (3, 0) < sys.version_info < (3, 2, 3):
             fg_color = unicode_type(fg_color, "ascii")
         self._colors = {
             logging.DEBUG: unicode_type(curses.tparm(fg_color, 4),  # Blue
                                         "ascii"),
             logging.INFO: unicode_type(curses.tparm(fg_color, 2),  # Green
                                        "ascii"),
             logging.WARNING: unicode_type(curses.tparm(fg_color, 3),  # Yellow
                                           "ascii"),
             logging.ERROR: unicode_type(curses.tparm(fg_color, 1),  # Red
                                         "ascii"),
         }
         self._normal = unicode_type(curses.tigetstr("sgr0"), "ascii")
开发者ID:1stvamp,项目名称:tornado,代码行数:26,代码来源:log.py


示例8: add

    def add(self):
        """Adds the new experiment"""

        # Check to ensure the experiment doesn't already exists
        if self.exists():
            raise ExperimentException(self.name, "already exists")

        # Add the experiment
        json = dict(creation_date=util.unicode_type(datetime.datetime.now()))
        pipe = self.redis.pipeline(transaction=True)
        pipe.sadd(ACTIVE_EXPERIMENTS_REDIS_KEY, self.name)
        pipe.hset(self._redis_key(), "metadata", escape.json_encode(json))
        pipe.execute()
开发者ID:xoxoj,项目名称:oz,代码行数:13,代码来源:__init__.py


示例9: add_experiment

def add_experiment(redis, name):
    """Adds a new experiment"""

    if not ALLOWED_NAMES.match(name):
        raise ExperimentException(name, "Illegal name")
    if redis.exists(EXPERIMENT_REDIS_KEY_TEMPLATE % name):
        raise ExperimentException(name, "Already exists")

    json = dict(creation_date=util.unicode_type(datetime.datetime.now()))
    pipe = redis.pipeline(transaction=True)
    pipe.sadd(ACTIVE_EXPERIMENTS_REDIS_KEY, name)
    pipe.hset(EXPERIMENT_REDIS_KEY_TEMPLATE % name, "metadata", escape.json_encode(json))
    pipe.execute()
    return Experiment(redis, name)
开发者ID:dailymuse,项目名称:oz,代码行数:14,代码来源:__init__.py


示例10: url_unescape

    def url_unescape(value, encoding='utf-8', plus=True):
        """解码来自于URL 的给定值.

        该参数可以是一个字节或unicode 字符串.

        如果encoding 是None , 该结果将会是一个字节串. 否则, 该结果会是
        指定编码的unicode 字符串.

        如果 ``plus`` 是true (默认值), 加号将被解释为空格(文字加号必须被
        表示为"%2B"). 这是适用于查询字符串和form-encoded 的值, 但不是URL
        的路径组件. 注意该默认设置和Python 的urllib 模块是相反的.

        .. versionadded:: 3.1
           该 ``plus`` 参数
        """
        unquote = (urllib_parse.unquote_plus if plus else urllib_parse.unquote)
        if encoding is None:
            return unquote(utf8(value))
        else:
            return unicode_type(unquote(utf8(value)), encoding)
开发者ID:Andor-Z,项目名称:tornado-zh,代码行数:20,代码来源:escape.py


示例11: __init__

    def __init__(self, color=True, prefix_fmt=None, datefmt=None):
        r"""
        :arg bool color: Enables color support
        :arg string prefix_fmt: Log message prefix format.
          Prefix is a part of the log message, directly preceding the actual
          message text.
        :arg string datefmt: Datetime format.
          Used for formatting ``(asctime)`` placeholder in ``prefix_fmt``.

        .. versionchanged:: 3.2

           Added ``prefix_fmt`` and ``datefmt`` arguments.
        """
        self.__prefix_fmt = prefix_fmt if prefix_fmt is not None else self.DEFAULT_PREFIX_FORMAT
        datefmt = datefmt if datefmt is not None else self.DEFAULT_DATE_FORMAT
        logging.Formatter.__init__(self, datefmt=datefmt)
        self._color = color and _stderr_supports_color()
        if self._color:
            # The curses module has some str/bytes confusion in
            # python3.  Until version 3.2.3, most methods return
            # bytes, but only accept strings.  In addition, we want to
            # output these strings with the logging module, which
            # works with unicode strings.  The explicit calls to
            # unicode() below are harmless in python2 but will do the
            # right conversion in python 3.
            fg_color = (curses.tigetstr("setaf") or
                        curses.tigetstr("setf") or "")
            if (3, 0) < sys.version_info < (3, 2, 3):
                fg_color = unicode_type(fg_color, "ascii")
            self._colors = {
                logging.DEBUG: unicode_type(curses.tparm(fg_color, 4),  # Blue
                                            "ascii"),
                logging.INFO: unicode_type(curses.tparm(fg_color, 2),  # Green
                                           "ascii"),
                logging.WARNING: unicode_type(curses.tparm(fg_color, 3),  # Yellow
                                              "ascii"),
                logging.ERROR: unicode_type(curses.tparm(fg_color, 1),  # Red
                                            "ascii"),
            }
            self._normal = unicode_type(curses.tigetstr("sgr0"), "ascii")
开发者ID:Fressia,项目名称:tornado,代码行数:40,代码来源:log.py


示例12: converter_path

def converter_path(data):
    """consume rest of the path"""
    return len(data), util.unicode_type(data)
开发者ID:FlorianLudwig,项目名称:rueckenwind,代码行数:3,代码来源:routing.py


示例13: url_unescape

def url_unescape(value, encoding="utf-8", plus=True):
    unquote = urllib_parse.unquote_plus if plus else urllib_parse.unquote
    if encoding is None:
        return unquote(utf8(value))
    else:
        return unicode_type(unquote(utf8(value)), encoding)
开发者ID:confucianzuoyuan,项目名称:tinytornado,代码行数:6,代码来源:escape.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python util.GzipDecompressor类代码示例发布时间:2022-05-27
下一篇:
Python util.u函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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