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


Python Coerce.str方法代码示例

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


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

示例1: method_pack

# 需要导入模块: from topaz.coerce import Coerce [as 别名]
# 或者: from topaz.coerce.Coerce import str [as 别名]
 def method_pack(self, space, w_template):
     template = Coerce.str(space, w_template)
     result = RPacker(template, space.listview(self)).operate(space)
     w_result = space.newstr_fromchars(result)
     if space.is_true(space.send(w_template, "tainted?")):
         space.send(w_result, "taint")
     return w_result
开发者ID:krekoten,项目名称:topaz,代码行数:9,代码来源:arrayobject.py

示例2: method_initialize

# 需要导入模块: from topaz.coerce import Coerce [as 别名]
# 或者: from topaz.coerce.Coerce import str [as 别名]
 def method_initialize(self, space, w_source, flags=0):
     if isinstance(w_source, W_RegexpObject):
         self.set_source(space, w_source.source, w_source.flags)
     else:
         try:
             self.set_source(space, Coerce.str(space, w_source), flags)
         except regexp.RegexpError as e:
             raise space.error(space.w_RegexpError, str(e))
     return self
开发者ID:Freidrichs,项目名称:topaz,代码行数:11,代码来源:regexpobject.py

示例3: method_match

# 需要导入模块: from topaz.coerce import Coerce [as 别名]
# 或者: from topaz.coerce.Coerce import str [as 别名]
 def method_match(self, space, w_s, w_offset=None):
     if w_s is space.w_nil:
         return space.w_nil
     s = Coerce.str(space, w_s)
     if w_offset is not None:
         offset = Coerce.int(space, w_offset)
     else:
         offset = 0
     ctx = self.make_ctx(s, offset)
     matched = rsre_core.search_context(ctx)
     return self.get_match_result(space, ctx, s, matched)
开发者ID:Fleurer,项目名称:topaz,代码行数:13,代码来源:regexpobject.py

示例4: method_match_operator

# 需要导入模块: from topaz.coerce import Coerce [as 别名]
# 或者: from topaz.coerce.Coerce import str [as 别名]
 def method_match_operator(self, space, w_s):
     if w_s is space.w_nil:
         return space.w_nil
     s = Coerce.str(space, w_s)
     ctx = self.make_ctx(s)
     matched = rsre_core.search_context(ctx)
     self.get_match_result(space, ctx, s, matched)
     if matched:
         return space.newint(ctx.match_start)
     else:
         return space.w_nil
开发者ID:Fleurer,项目名称:topaz,代码行数:13,代码来源:regexpobject.py

示例5: method_subscript_assign

# 需要导入模块: from topaz.coerce import Coerce [as 别名]
# 或者: from topaz.coerce.Coerce import str [as 别名]
 def method_subscript_assign(self, space, key, w_value):
     if "\0" in key:
         raise space.error(space.w_ArgumentError, "bad environment variable name")
     if w_value is space.w_nil:
         try:
             del os.environ[key]
         except (KeyError, OSError):
             pass
         return space.w_nil
     if "=" in key or key == "":
         raise error_for_errno(space, errno.EINVAL)
     value = Coerce.str(space, w_value)
     if "\0" in value:
         raise space.error(space.w_ArgumentError, "bad environment variable value")
     os.environ[key] = value
     return w_value
开发者ID:Fleurer,项目名称:topaz,代码行数:18,代码来源:envobject.py

示例6: method_subscript

# 需要导入模块: from topaz.coerce import Coerce [as 别名]
# 或者: from topaz.coerce.Coerce import str [as 别名]
    def method_subscript(self, space, w_idx, w_count, w_other=None):
        if w_other is None:
            w_other = w_count
            w_count = None

        other = Coerce.str(space, w_other)
        start_idx = -1
        end_idx = -1
        if space.is_kind_of(w_idx, space.w_string):
            other_str = space.str_w(w_idx)
            start_idx = space.str_w(self).find(other_str)
            end_idx = start_idx + len(other_str)
        elif space.is_kind_of(w_idx, space.w_regexp):
            ctx = w_idx.make_ctx(space.str_w(self))
            if self.search_context(space, ctx):
                if w_count is None:
                    start_idx = ctx.match_start
                    end_idx = ctx.match_end
                elif space.is_kind_of(w_count, space.w_string):
                    raise space.error(
                        space.w_NotImplementedError,
                        "string subscript replace with regexp and named group"
                    )
                else:
                    groupnum = Coerce.int(space, w_count)
                    try:
                        start_idx, end_idx = ctx.span(groupnum)
                    except IndexError:
                        pass
        else:
            start_idx, end_idx, as_range, nil = space.subscript_access(self.length(), w_idx, w_count=w_count)
            if not w_count:
                end_idx = start_idx + 1

        if start_idx < 0 or end_idx < 0:
            raise space.error(space.w_IndexError, "cannot find substring in string to replace")

        self.strategy.to_mutable(space, self)
        self.strategy.delslice(space, self.str_storage, start_idx, end_idx)
        self.strategy.insert(self.str_storage, start_idx, other)
        return self
开发者ID:topazproject,项目名称:topaz,代码行数:43,代码来源:stringobject.py

示例7: method_pack

# 需要导入模块: from topaz.coerce import Coerce [as 别名]
# 或者: from topaz.coerce.Coerce import str [as 别名]
 def method_pack(self, space, w_template):
     template = Coerce.str(space, w_template)
     result = RPacker(template, space.listview(self)).operate(space)
     w_result = space.newstr_fromchars(result)
     space.infect(w_result, w_template)
     return w_result
开发者ID:Fleurer,项目名称:topaz,代码行数:8,代码来源:arrayobject.py


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