How to use the uncompyle6.semantics.consts.TABLE_DIRECT.update function in uncompyle6

To help you get started, we’ve selected a few uncompyle6 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rocky / python-uncompyle6 / uncompyle6 / semantics / customize38.py View on Github external
def customize_for_version38(self, version):

    # FIXME: pytest doesn't add proper keys in testing. Reinstate after we have fixed pytest.
    # for lhs in 'for forelsestmt forelselaststmt '
    #             'forelselaststmtl tryfinally38'.split():
    #     del TABLE_DIRECT[lhs]

    TABLE_DIRECT.update({
        'async_for_stmt38':  (
            '%|async for %c in %c:\n%+%c%-%-\n\n',
            (7, 'store'), (0, 'expr'), (8, 'for_block') ),

        'async_forelse_stmt38':  (
            '%|async for %c in %c:\n%+%c%-%|else:\n%+%c%-\n\n',
            (7, 'store'), (0, 'expr'), (8, 'for_block'), (-1, 'else_suite') ),

        'async_with_stmt38': (
            '%|async with %c:\n%+%|%c%-',
            (0, 'expr'), 7),

        'async_with_as_stmt38':  (
            '%|async with %c as %c:\n%+%|%c%-',
            (0, 'expr'), (6, 'store'),
            (7, 'suite_stmts') ),
github rocky / python-decompile3 / uncompyle6 / semantics / customize36.py View on Github external
def customize_for_version36(self, version):
    # Value 100 is important; it is exactly
    # module/function precidence.
    PRECEDENCE['call_kw']     = 100
    PRECEDENCE['call_kw36']   = 100
    PRECEDENCE['call_ex']     = 100
    PRECEDENCE['call_ex_kw']  = 100
    PRECEDENCE['call_ex_kw2'] = 100
    PRECEDENCE['call_ex_kw3'] = 100
    PRECEDENCE['call_ex_kw4'] = 100
    PRECEDENCE['unmap_dict']  = 0

    TABLE_DIRECT.update({
        'tryfinally36':     ( '%|try:\n%+%c%-%|finally:\n%+%c%-\n\n',
                              (1, 'returns'), 3 ),
        'fstring_expr':     ( "{%c%{conversion}}",
                              (0, 'expr') ),
        # FIXME: the below assumes the format strings
        # don't have ''' in them. Fix this properly
        'fstring_single':   ( "f'''{%c%{conversion}}'''", 0),
        'formatted_value_attr': ( "f'''{%c%{conversion}}%{string}'''",
                                  (0, 'expr')),
        'fstring_multi':    ( "f'''%c'''", 0),
        'func_args36':      ( "%c(**", 0),
        'try_except36':     ( '%|try:\n%+%c%-%c\n\n', 1, -2 ),
        'except_return':    ( '%|except:\n%+%c%-', 3 ),
        'unpack_list':      ( '*%c', (0, 'list') ),
        'tryfinally_return_stmt':
              ( '%|try:\n%+%c%-%|finally:\n%+%|return%-\n\n', 1 ),
github rocky / python-uncompyle6 / uncompyle6 / semantics / customize36.py View on Github external
def customize_for_version36(self, version):
    PRECEDENCE['call_kw']     = 0
    PRECEDENCE['call_kw36']   = 1
    PRECEDENCE['call_ex']     = 1
    PRECEDENCE['call_ex_kw']  = 1
    PRECEDENCE['call_ex_kw2'] = 1
    PRECEDENCE['call_ex_kw3'] = 1
    PRECEDENCE['call_ex_kw4'] = 1
    PRECEDENCE['unmap_dict']  = 0
    PRECEDENCE['formatted_value1'] = 100

    TABLE_DIRECT.update({
        'tryfinally36':     ( '%|try:\n%+%c%-%|finally:\n%+%c%-\n\n',
                              (1, 'returns'), 3 ),
        'func_args36':      ( "%c(**", 0),
        'try_except36':     ( '%|try:\n%+%c%-%c\n\n', 1, -2 ),
        'except_return':    ( '%|except:\n%+%c%-', 3 ),
        'unpack_list':      ( '*%c', (0, 'list') ),
        'tryfinally_return_stmt':
              ( '%|try:\n%+%c%-%|finally:\n%+%|return%-\n\n', 1 ),

        'async_for_stmt36':  (
            '%|async for %c in %c:\n%+%c%-%-\n\n',
            (9, 'store'), (1, 'expr'), (18, 'for_block') ),

        'call_ex' : (
            '%c(%p)',
            (0, 'expr'), (1, 100)),
github rocky / python-decompile3 / uncompyle6 / semantics / customize3.py View on Github external
def customize_for_version3(self, version):
    TABLE_DIRECT.update({
        'comp_for'       : ( ' for %c in %c',
                            (2, 'store') , (0, 'expr') ),
        'conditionalnot' : ( '%c if not %c else %c',
                            (2, 'expr') , (0, 'expr'), (4, 'expr') ),
        'except_cond2'   : ( '%|except %c as %c:\n', 1, 5 ),
        'function_def_annotate': ( '\n\n%|def %c%c\n', -1, 0),
        'importmultiple' : ( '%|import %c%c\n', 2, 3 ),
        'import_cont'    : ( ', %c', 2 ),
        'store_locals'   : ( '%|# inspect.currentframe().f_locals = __locals__\n', ),
        'withstmt'       : ( '%|with %c:\n%+%c%-', 0, 3),
        'withasstmt'     : ( '%|with %c as (%c):\n%+%c%-', 0, 2, 3),
        })

    assert version >= 3.0

    def n_classdef3(node):
github rocky / python-uncompyle6 / uncompyle6 / semantics / customize3.py View on Github external
def customize_for_version3(self, version):
    TABLE_DIRECT.update(
        {
            "comp_for": (" for %c in %c", (2, "store"), (0, "expr")),
            "conditionalnot": (
                "%c if not %c else %c",
                (2, "expr"),
                (0, "expr"),
                (4, "expr"),
            ),
            "except_cond2": ("%|except %c as %c:\n", (1, "expr"), (5, "store")),
            "function_def_annotate": ("\n\n%|def %c%c\n", -1, 0),
            # When a generator is a single parameter of a function,
            # it doesn't need the surrounding parenethesis.
            "call_generator": ("%c%P", 0, (1, -1, ", ", 100)),
            "importmultiple": ("%|import %c%c\n", 2, 3),
            "import_cont": (", %c", 2),
            "kwarg": ("%[0]{attr}=%c", 1),
github rocky / python-uncompyle6 / uncompyle6 / semantics / pysource.py View on Github external
########################
            # PyPy changes
            #######################
            TABLE_DIRECT.update({
                'assert_pypy':	( '%|assert %c\n' , 1 ),
                'assert2_pypy':	( '%|assert %c, %c\n' , 1, 4 ),
                'try_except_pypy':	   ( '%|try:\n%+%c%-%c\n\n', 1, 2 ),
                'tryfinallystmt_pypy': ( '%|try:\n%+%c%-%|finally:\n%+%c%-\n\n', 1, 3 ),
                'assign3_pypy':        ( '%|%c, %c, %c = %c, %c, %c\n', 5, 4, 3, 0, 1, 2 ),
                'assign2_pypy':        ( '%|%c, %c = %c, %c\n', 3, 2, 0, 1),
                })
        else:
            ########################
            # Without PyPy
            #######################
            TABLE_DIRECT.update({
                'assert':		( '%|assert %c\n' , 0 ),
                'assert2':		( '%|assert %c, %c\n' , 0, 3 ),
                'try_except':	( '%|try:\n%+%c%-%c\n\n', 1, 3 ),
                'assign2':      ( '%|%c, %c = %c, %c\n', 3, 4, 0, 1 ),
                'assign3':      ( '%|%c, %c, %c = %c, %c, %c\n', 5, 6, 7, 0, 1, 2 ),
                })
        if version < 3.0:
            TABLE_R.update({
                'STORE_SLICE+0':	( '%c[:]', 0 ),
                'STORE_SLICE+1':	( '%c[%p:]', 0, (1, 100) ),
                'STORE_SLICE+2':	( '%c[:%p]', 0, (1, 100) ),
                'STORE_SLICE+3':	( '%c[%p:%p]', 0, (1, 100), (2, 100) ),
                'DELETE_SLICE+0':	( '%|del %c[:]\n', 0 ),
                'DELETE_SLICE+1':	( '%|del %c[%c:]\n', 0, 1 ),
                'DELETE_SLICE+2':	( '%|del %c[:%c]\n', 0, 1 ),
                'DELETE_SLICE+3':	( '%|del %c[%c:%c]\n', 0, 1, 2 ),
github rocky / python-uncompyle6 / uncompyle6 / semantics / pysource.py View on Github external
NAME_MODULE = AST('stmt',
                              [ AST('assign',
                                    [ AST('expr',
                                          [Token('LOAD_GLOBAL', pattr='__name__',
                                                 offset=0, has_arg=True)]),
                                      AST('store',
                                          [ Token('STORE_NAME', pattr='__module__',
                                                  offset=3, has_arg=True)])
                                    ])])
            pass
            if version <= 2.3:
                TABLE_DIRECT.update({
                    'tryfinallystmt': ( '%|try:\n%+%c%-%|finally:\n%+%c%-\n\n', 1, 4 )
                })
                if version <= 2.1:
                    TABLE_DIRECT.update({
                        'importmultiple': ( '%c', 2 ),
                        'imports_cont': ( '%c', 2 ),
                        # FIXME: not quite right. We have indiividual imports
                        # when there is in fact one: "import a, b, ..."
                        'imports_cont': ( '%C%,', (1, 100, '\n') ),
                    })
                    pass
                pass
            pass
        elif version >= 2.5:
            ########################
            # Import style for 2.5+
            ########################
            TABLE_DIRECT.update({
                'importmultiple': ( '%|import %c%c\n', 2, 3 ),
                'import_cont'   : ( ', %c', 2 ),
github rocky / python-uncompyle6 / uncompyle6 / semantics / customize3.py View on Github external
self.currentclass = cclass
        if len(self.param_stack) > 1:
            self.write("\n\n")
        else:
            self.write("\n\n\n")

        self.prune()

    self.n_classdef3 = n_classdef3

    if version == 3.0:
        # In Python 3.0 there is code to move from _[dd] into
        # the iteration variable. These rules we can ignore
        # since we pick up the iteration variable some other way and
        # we definitely don't include in the source  _[dd].
        TABLE_DIRECT.update({
            "ifstmt30":	( "%|if %c:\n%+%c%-",
                          (0, "testfalse_then"),
                          (1, "_ifstmts_jump30") ),
            "ifnotstmt30": ( "%|if not %c:\n%+%c%-",
                             (0, "testtrue_then"),
                             (1, "_ifstmts_jump30") ),
            "try_except30": ( "%|try:\n%+%c%-%c\n\n",
                              (1, "suite_stmts_opt"),
                              (4, "except_handler") ),

            })

        def n_comp_iter(node):
            if node[0] == "expr":
                n = node[0][0]
                if n == "LOAD_FAST" and n.pattr[0:2] == "_[":