Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(52)  |  Call(42)  |  Derive(0)  |  Import(10)
Return a NAME leaf

        def Name(name, prefix=None):
    """Return a NAME leaf"""
    return Leaf(token.NAME, name, prefix=prefix)
        


src/p/y/py3kwarn-HEAD/py3kwarn2to3/fixes/fix_urllib.py   py3kwarn(Download)
# Local imports
from py3kwarn2to3.fixes.fix_imports import alternates, FixImports
from py3kwarn2to3.fixer_util import (Name, Comma, FromImport, Newline,
                                find_indentation, Node, syms)
 
        # create a Node list of the replacement modules
        for name in MAPPING[import_mod.value][:-1]:
            names.extend([Name(name[0], prefix=pref), Comma()])
        names.append(Name(MAPPING[import_mod.value][-1][0], prefix=pref))
        import_mod.replace(names)
                    break
            if new_name:
                mod_member.replace(Name(new_name, prefix=pref))
            else:
                self.cannot_convert(node, "This is an invalid module element")
            def handle_name(name, prefix):
                if name.type == syms.import_as_name:
                    kids = [Name(name.children[0].value, prefix=prefix),
                            name.children[1].clone(),
                            name.children[2].clone()]

src/p/y/py3kwarn-0.4.4/py3kwarn2to3/fixes/fix_urllib.py   py3kwarn(Download)
# Local imports
from py3kwarn2to3.fixes.fix_imports import alternates, FixImports
from py3kwarn2to3.fixer_util import (Name, Comma, FromImport, Newline,
                                find_indentation, Node, syms)
 
        # create a Node list of the replacement modules
        for name in MAPPING[import_mod.value][:-1]:
            names.extend([Name(name[0], prefix=pref), Comma()])
        names.append(Name(MAPPING[import_mod.value][-1][0], prefix=pref))
        import_mod.replace(names)
                    break
            if new_name:
                mod_member.replace(Name(new_name, prefix=pref))
            else:
                self.cannot_convert(node, "This is an invalid module element")
            def handle_name(name, prefix):
                if name.type == syms.import_as_name:
                    kids = [Name(name.children[0].value, prefix=prefix),
                            name.children[1].clone(),
                            name.children[2].clone()]

src/p/y/py3kwarn-HEAD/py3kwarn2to3/fixes/fix_exitfunc.py   py3kwarn(Download)
 
from py3kwarn2to3 import pytree, fixer_base
from py3kwarn2to3.fixer_util import Name, Attr, Call, Comma, Newline, syms
 
 
        func.prefix = u""
        register = pytree.Node(syms.power,
                               Attr(Name(u"atexit"), Name(u"register"))
                               )
        call = Call(register, [func], node.prefix)
        if names.type == syms.dotted_as_names:
            names.append_child(Comma())
            names.append_child(Name(u"atexit", u" "))
        else:
            containing_stmt = self.sys_import.parent
            position = containing_stmt.children.index(self.sys_import)
            stmt_container = containing_stmt.parent
            new_import = pytree.Node(syms.import_name,
                              [Name(u"import"), Name(u"atexit", u" ")]

src/p/y/py3kwarn-0.4.4/py3kwarn2to3/fixes/fix_exitfunc.py   py3kwarn(Download)
 
from py3kwarn2to3 import pytree, fixer_base
from py3kwarn2to3.fixer_util import Name, Attr, Call, Comma, Newline, syms
 
 
        func.prefix = u""
        register = pytree.Node(syms.power,
                               Attr(Name(u"atexit"), Name(u"register"))
                               )
        call = Call(register, [func], node.prefix)
        if names.type == syms.dotted_as_names:
            names.append_child(Comma())
            names.append_child(Name(u"atexit", u" "))
        else:
            containing_stmt = self.sys_import.parent
            position = containing_stmt.children.index(self.sys_import)
            stmt_container = containing_stmt.parent
            new_import = pytree.Node(syms.import_name,
                              [Name(u"import"), Name(u"atexit", u" ")]

src/p/y/py3kwarn-HEAD/py3kwarn2to3/fixes/fix_callable.py   py3kwarn(Download)
# Local imports
from py3kwarn2to3 import fixer_base
from py3kwarn2to3.fixer_util import Call, Name, String, Attr, touch_import
 
class FixCallable(fixer_base.BaseFix):
 
        args = [func.clone(), String(u', ')]
        args.extend(Attr(Name(u'collections'), Name(u'Callable')))
        return Call(Name(u'isinstance'), args, prefix=node.prefix)
 

src/p/y/py3kwarn-0.4.4/py3kwarn2to3/fixes/fix_callable.py   py3kwarn(Download)
# Local imports
from py3kwarn2to3 import fixer_base
from py3kwarn2to3.fixer_util import Call, Name, String, Attr, touch_import
 
class FixCallable(fixer_base.BaseFix):
 
        args = [func.clone(), String(u', ')]
        args.extend(Attr(Name(u'collections'), Name(u'Callable')))
        return Call(Name(u'isinstance'), args, prefix=node.prefix)
 

src/p/y/py3kwarn-HEAD/py3kwarn2to3/fixes/fix_operator.py   py3kwarn(Download)
 
from py3kwarn2to3 import fixer_base
from py3kwarn2to3.fixer_util import Call, Name, String, touch_import
 
 
    def _isCallable(self, node, results):
        obj = results["obj"]
        args = [obj.clone(), String(u", "), String(u"'__call__'")]
        return Call(Name(u"hasattr"), args, prefix=node.prefix)
 
    def _handle_type2abc(self, node, results, module, abc):
        touch_import(None, module, node)
        obj = results["obj"]
        args = [obj.clone(), String(u", " + u".".join([module, abc]))]
        return Call(Name(u"isinstance"), args, prefix=node.prefix)

src/p/y/py3kwarn-0.4.4/py3kwarn2to3/fixes/fix_operator.py   py3kwarn(Download)
 
from py3kwarn2to3 import fixer_base
from py3kwarn2to3.fixer_util import Call, Name, String, touch_import
 
 
    def _isCallable(self, node, results):
        obj = results["obj"]
        args = [obj.clone(), String(u", "), String(u"'__call__'")]
        return Call(Name(u"hasattr"), args, prefix=node.prefix)
 
    def _handle_type2abc(self, node, results, module, abc):
        touch_import(None, module, node)
        obj = results["obj"]
        args = [obj.clone(), String(u", " + u".".join([module, abc]))]
        return Call(Name(u"isinstance"), args, prefix=node.prefix)

src/p/y/py3kwarn-HEAD/py3kwarn2to3/tests/test_util.py   py3kwarn(Download)
from py3kwarn2to3.pytree import Node, Leaf
from py3kwarn2to3 import fixer_util
from py3kwarn2to3.fixer_util import Attr, Name, Call, Comma
from py3kwarn2to3.pgen2 import token
 
    def test(self):
        call = parse("foo()", strip_levels=2)
 
        self.assertStr(Attr(Name("a"), Name("b")), "a.b")
        self.assertStr(Attr(call, Name("b")), "foo().b")
 
    def test_returns(self):
        attr = Attr(Name("a"), Name("b"))

src/p/y/py3kwarn-HEAD/py3kwarn2to3/tests/data/fixers/myfixes/fix_parrot.py   py3kwarn(Download)
from py3kwarn2to3.fixer_base import BaseFix
from py3kwarn2to3.fixer_util import Name
 
class FixParrot(BaseFix):
    """
    def transform(self, node, results):
        name = results["name"]
        name.replace(Name("cheese", name.prefix))