當前位置: 首頁>>代碼示例>>Python>>正文


Python tokenize.Name方法代碼示例

本文整理匯總了Python中tokenize.Name方法的典型用法代碼示例。如果您正苦於以下問題:Python tokenize.Name方法的具體用法?Python tokenize.Name怎麽用?Python tokenize.Name使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tokenize的用法示例。


在下文中一共展示了tokenize.Name方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: normalize_names

# 需要導入模塊: import tokenize [as 別名]
# 或者: from tokenize import Name [as 別名]
def normalize_names(self):
        """
        It is internally used to normalize the name of the widgets.
        It means a widget named foo:vbox-dialog in glade
        is refered self.vbox_dialog in the code.

        It also sets a data "prefixes" with the list of
        prefixes a widget has for each widget.
        """
        for widget in self.get_widgets():
            widget_name = gtk.Widget.get_name(widget)
            prefixes_name_l = widget_name.split(":")
            prefixes = prefixes_name_l[ : -1]
            widget_api_name = prefixes_name_l[-1]
            widget_api_name = "_".join( re.findall(tokenize.Name, widget_api_name) )
            gtk.Widget.set_name(widget, widget_api_name)
            if hasattr(self, widget_api_name):
                raise AttributeError("instance %s already has an attribute %s" % (self,widget_api_name))
            else:
                setattr(self, widget_api_name, widget)
                if prefixes:
                    gtk.Widget.set_data(widget, "prefixes", prefixes) 
開發者ID:mjun,項目名稱:gnome-connection-manager,代碼行數:24,代碼來源:SimpleGladeApp.py

示例2: _validate_string

# 需要導入模塊: import tokenize [as 別名]
# 或者: from tokenize import Name [as 別名]
def _validate_string(self, text):
    """Validates a string is composed of valid characters.

    Args:
      text: any str to validate.

    Raises:
      ValueError: when text contains illegal characters.
    """
    if not re.match(tokenize.Name, text):
      raise ValueError('%s should only contain ascii letters or digits.' %
                       text) 
開發者ID:elsigh,項目名稱:browserscope,代碼行數:14,代碼來源:file_format_parser.py

示例3: isidentifier

# 需要導入模塊: import tokenize [as 別名]
# 或者: from tokenize import Name [as 別名]
def isidentifier(string):
        """Check if string can be a variable name."""
        return re.match(tokenize.Name + r'\Z', string) is not None 
開發者ID:spyder-ide,項目名稱:spyder-kernels,代碼行數:5,代碼來源:py3compat.py

示例4: valid_identifier

# 需要導入模塊: import tokenize [as 別名]
# 或者: from tokenize import Name [as 別名]
def valid_identifier(name):
    return re.match(tokenize.Name + '$', name) and not keyword.iskeyword(name) 
開發者ID:mwisslead,項目名稱:vfp2py,代碼行數:4,代碼來源:vfp2py_convert_visitor.py

示例5: register_last_expr

# 需要導入模塊: import tokenize [as 別名]
# 或者: from tokenize import Name [as 別名]
def register_last_expr(tree, register):
    """
    Registers the last expression as register in the context of an AST.
    tree may either be a list of nodes, or an ast node with a body.
    Returns the newly modified structure AND mutates the original.
    """
    if isinstance(tree, list):
        if not tree:
            # Empty body.
            return tree
        # Allows us to use cases like directly passing orelse bodies.
        last_node = tree[-1]
    else:
        last_node = tree.body[-1]
    if type(last_node) in NO_REGISTER_STATEMENTS:
        return tree

    def mk_register_node(final_node):
        return ast.Expr(
            value=ast.Call(
                func=ast.Name(
                    id=register,
                    ctx=ast.Load(),
                ),
                args=[
                    final_node.value,
                ],
                keywords=[],
                starargs=None,
                kwargs=None,
            )
        )

    if hasattr(last_node, 'body'):
        # Deep inspect the body of the nodes.
        register_last_expr(last_node, register)

        # Try to register in all the body types.
        try:
            register_last_expr(last_node.orelse, register)
        except AttributeError:
            pass
        try:
            for handler in last_node.handlers:
                register_last_expr(handler, register)
        except AttributeError:
            pass
        try:
            register_last_expr(last_node.finalbody, register)
        except AttributeError:
            pass
    else:
        # Nodes with no body require no recursive inspection.
        tree.body[-1] = mk_register_node(last_node)

    return ast.fix_missing_locations(tree) 
開發者ID:quantopian,項目名稱:qdb,代碼行數:58,代碼來源:utils.py


注:本文中的tokenize.Name方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。