Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code with_reactor>
  MAKE_FUNCTION 0
  STORE_NAME with_reactor
  RETURN_CONST None
END
CODE with_reactor(*dec_args, **dec_kwargs)
  DOC 'pass'
  MAKE_CELL dec_args
  MAKE_CELL dec_kwargs
  MAKE_CELL callee
  RESUME 0
  LOAD_GLOBAL NULL + len
  LOAD_DEREF dec_args
  CALL 1
  LOAD_CONST 1
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L1
  LOAD_GLOBAL NULL + callable
  LOAD_DEREF dec_args
  LOAD_CONST 0
  BINARY_SUBSCR
  CALL 1
  POP_JUMP_IF_FALSE L1
  LOAD_DEREF dec_kwargs
  POP_JUMP_IF_TRUE L1
  LOAD_DEREF dec_args
  LOAD_CONST 0
  BINARY_SUBSCR
  STORE_DEREF callee
  LOAD_CONST ()
  STORE_DEREF dec_args
  BUILD_MAP 0
  STORE_DEREF dec_kwargs
  LOAD_GLOBAL functools
  LOAD_ATTR NULL|self + wraps
  LOAD_DEREF callee
  CALL 1
  LOAD_CLOSURE callee
  BUILD_TUPLE 1
  LOAD_CONST <code with_reactor.<locals>.wrapper>
  MAKE_FUNCTION closure
  CALL 0
  STORE_FAST wrapper
  LOAD_FAST wrapper
  RETURN_VALUE
L1:
  LOAD_CLOSURE dec_args
  LOAD_CLOSURE dec_kwargs
  BUILD_TUPLE 2
  LOAD_CONST <code with_reactor.<locals>.decorator>
  MAKE_FUNCTION closure
  STORE_FAST decorator
  LOAD_FAST decorator
  RETURN_VALUE
END
CODE with_reactor.<locals>.wrapper(*call_args, **call_kwargs)
  COPY_FREE_VARS 1
  RESUME 0
  LOAD_GLOBAL NULL + _twisted_test_sync
  LOAD_DEREF callee
  LOAD_FAST call_args
  LOAD_FAST call_kwargs
  CALL 3
  RETURN_VALUE
END
CODE with_reactor.<locals>.decorator(callee)
  COPY_FREE_VARS 2
  MAKE_CELL callee
  RESUME 0
  LOAD_GLOBAL functools
  LOAD_ATTR NULL|self + wraps
  LOAD_DEREF callee
  CALL 1
  LOAD_CLOSURE callee
  LOAD_CLOSURE dec_args
  LOAD_CLOSURE dec_kwargs
  BUILD_TUPLE 3
  LOAD_CONST <code with_reactor.<locals>.decorator.<locals>.wrapper>
  MAKE_FUNCTION closure
  CALL 0
  STORE_FAST wrapper
  LOAD_FAST wrapper
  RETURN_VALUE
END
CODE with_reactor.<locals>.decorator.<locals>.wrapper(*call_args, **call_kwargs)
  COPY_FREE_VARS 3
  RESUME 0
  LOAD_GLOBAL NULL + _twisted_test_sync
  LOAD_DEREF callee
  LOAD_FAST call_args
  LOAD_FAST call_kwargs
  BUILD_LIST 3
  LOAD_DEREF dec_args
  LIST_EXTEND 1
  CALL_INTRINSIC_1 INTRINSIC_LIST_TO_TUPLE
  BUILD_MAP 0
  LOAD_DEREF dec_kwargs
  DICT_MERGE 1
  CALL_FUNCTION_EX 1
  RETURN_VALUE
END

def with_reactor(*dec_args, **dec_kwargs):
    """pass"""
    if len(dec_args) == 1 and callable(dec_args[0]) and (not dec_kwargs):
        callee = dec_args[0]
        dec_args = ()
        dec_kwargs = {}

        @functools.wraps(callee)
        def wrapper(*call_args, **call_kwargs):
            return _twisted_test_sync(callee, call_args, call_kwargs)
        return wrapper
    else:

        def decorator(callee):

            @functools.wraps(callee)
            def wrapper(*call_args, **call_kwargs):
                return _twisted_test_sync(callee, call_args, call_kwargs, *dec_args, **dec_kwargs)
            return wrapper
        return decorator


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code _ensure_reactor_running>
  MAKE_FUNCTION 0
  STORE_NAME _ensure_reactor_running
  RETURN_CONST None
END
CODE _ensure_reactor_running()
  DOC 'pass'
  MAKE_CELL orig_set_wakeup_fd
  MAKE_CELL orig_signal
  MAKE_CELL signal_registrations
  RESUME 0
  LOAD_GLOBAL reactor
  LOAD_ATTR running
  POP_JUMP_IF_TRUE L5
  BUILD_LIST 0
  STORE_DEREF signal_registrations
  LOAD_CLOSURE orig_signal
  LOAD_CLOSURE signal_registrations
  BUILD_TUPLE 2
  LOAD_CONST <code _ensure_reactor_running.<locals>.signal_capture>
  MAKE_FUNCTION closure
  STORE_FAST signal_capture
  LOAD_CLOSURE orig_set_wakeup_fd
  LOAD_CLOSURE signal_registrations
  BUILD_TUPLE 2
  LOAD_CONST <code _ensure_reactor_running.<locals>.set_wakeup_fd_capture>
  MAKE_FUNCTION closure
  STORE_FAST set_wakeup_fd_capture
  LOAD_GLOBAL signal
  LOAD_ATTR signal
  STORE_DEREF orig_signal
  LOAD_FAST signal_capture
  LOAD_GLOBAL signal
  STORE_ATTR signal
  LOAD_GLOBAL signal
  LOAD_ATTR set_wakeup_fd
  STORE_DEREF orig_set_wakeup_fd
  LOAD_FAST set_wakeup_fd_capture
  LOAD_GLOBAL signal
  STORE_ATTR set_wakeup_fd
  LOAD_GLOBAL threading
  LOAD_ATTR NULL|self + Thread
  LOAD_GLOBAL reactor
  LOAD_ATTR run
  LOAD_CONST 'reactor'
  KW_NAMES ('target', 'name')
  CALL 2
  STORE_FAST reactor_thread
  LOAD_CONST True
  LOAD_FAST reactor_thread
  STORE_ATTR daemon
  LOAD_FAST reactor_thread
  LOAD_ATTR NULL|self + start
  CALL 0
  POP_TOP
  LOAD_GLOBAL reactor
  LOAD_ATTR running
  POP_JUMP_IF_TRUE L2
L1:
  LOAD_GLOBAL time
  LOAD_ATTR NULL|self + sleep
  LOAD_CONST 0.01
  CALL 1
  POP_TOP
  LOAD_GLOBAL reactor
  LOAD_ATTR running
  POP_JUMP_IF_TRUE L2
  JUMP_BACKWARD L1
L2:
  LOAD_GLOBAL time
  LOAD_ATTR NULL|self + sleep
  LOAD_CONST 0.01
  CALL 1
  POP_TOP
  LOAD_DEREF orig_signal
  LOAD_GLOBAL signal
  STORE_ATTR signal
  LOAD_DEREF orig_set_wakeup_fd
  LOAD_GLOBAL signal
  STORE_ATTR set_wakeup_fd
  LOAD_DEREF signal_registrations
  GET_ITER
L3:
  FOR_ITER L4
  UNPACK_SEQUENCE 3
  STORE_FAST func
  STORE_FAST args
  STORE_FAST kwargs
  PUSH_NULL
  LOAD_FAST func
  LOAD_FAST args
  BUILD_MAP 0
  LOAD_FAST kwargs
  DICT_MERGE 1
  CALL_FUNCTION_EX 1
  POP_TOP
  JUMP_BACKWARD L3
L4:
  END_FOR
  RETURN_CONST None
L5:
  RETURN_CONST None
END
CODE _ensure_reactor_running.<locals>.signal_capture(*args, **kwargs)
  COPY_FREE_VARS 2
  RESUME 0
  LOAD_DEREF signal_registrations
  LOAD_ATTR NULL|self + append
  LOAD_DEREF orig_signal
  LOAD_FAST args
  LOAD_FAST kwargs
  BUILD_TUPLE 3
  CALL 1
  POP_TOP
  RETURN_CONST None
END
CODE _ensure_reactor_running.<locals>.set_wakeup_fd_capture(*args, **kwargs)
  COPY_FREE_VARS 2
  RESUME 0
  LOAD_DEREF signal_registrations
  LOAD_ATTR NULL|self + append
  LOAD_DEREF orig_set_wakeup_fd
  LOAD_FAST args
  LOAD_FAST kwargs
  BUILD_TUPLE 3
  CALL 1
  POP_TOP
  RETURN_CONST None
END

def _ensure_reactor_running():
    """pass"""
    if not reactor.running:
        signal_registrations = []

        def signal_capture(*args, **kwargs):
            signal_registrations.append((orig_signal, args, kwargs))

        def set_wakeup_fd_capture(*args, **kwargs):
            signal_registrations.append((orig_set_wakeup_fd, args, kwargs))
        orig_signal = signal.signal
        signal.signal = signal_capture
        orig_set_wakeup_fd = signal.set_wakeup_fd
        signal.set_wakeup_fd = set_wakeup_fd_capture
        reactor_thread = threading.Thread(target=reactor.run, name='reactor')
        reactor_thread.daemon = True
        reactor_thread.start()
        while not reactor.running:
            time.sleep(0.01)
        time.sleep(0.01)
        signal.signal = orig_signal
        signal.set_wakeup_fd = orig_set_wakeup_fd
        for func, args, kwargs in signal_registrations:
            func(*args, **kwargs)

code-search-net/code_search_net (python, train split)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code _timeoutDeferred>
  MAKE_FUNCTION 0
  STORE_NAME _timeoutDeferred
  RETURN_CONST None
END
CODE _timeoutDeferred(deferred, timeout)
  DOC 'pass'
  MAKE_CELL delayedCall
  RESUME 0
  LOAD_GLOBAL reactor
  LOAD_ATTR NULL|self + callLater
  LOAD_FAST timeout
  LOAD_FAST deferred
  LOAD_ATTR cancel
  CALL 2
  STORE_DEREF delayedCall
  LOAD_CLOSURE delayedCall
  BUILD_TUPLE 1
  LOAD_CONST <code _timeoutDeferred.<locals>.gotResult>
  MAKE_FUNCTION closure
  STORE_FAST gotResult
  LOAD_FAST deferred
  LOAD_ATTR NULL|self + addBoth
  LOAD_FAST gotResult
  CALL 1
  POP_TOP
  RETURN_CONST None
END
CODE _timeoutDeferred.<locals>.gotResult(result)
  COPY_FREE_VARS 1
  RESUME 0
  LOAD_DEREF delayedCall
  LOAD_ATTR NULL|self + active
  CALL 0
  POP_JUMP_IF_FALSE L1
  LOAD_DEREF delayedCall
  LOAD_ATTR NULL|self + cancel
  CALL 0
  POP_TOP
L1:
  LOAD_FAST result
  RETURN_VALUE
END

def _timeoutDeferred(deferred, timeout):
    """pass"""
    delayedCall = reactor.callLater(timeout, deferred.cancel)

    def gotResult(result):
        if delayedCall.active():
            delayedCall.cancel()
        return result
    deferred.addBoth(gotResult)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code _get_json>
  MAKE_FUNCTION 0
  STORE_NAME _get_json
  RETURN_CONST None
END
CODE _get_json(value)
  DOC 'pass'
  RESUME 0
  LOAD_GLOBAL NULL + hasattr
  LOAD_FAST value
  LOAD_CONST 'replace'
  CALL 2
  POP_JUMP_IF_FALSE L1
  LOAD_FAST value
  LOAD_ATTR NULL|self + replace
  LOAD_CONST '\n'
  LOAD_CONST ' '
  CALL 2
  STORE_FAST value
L1:
  NOP
L2:
  LOAD_GLOBAL json
  LOAD_ATTR NULL|self + loads
  LOAD_FAST value
  CALL 1
L3:
  RETURN_VALUE
L4:
  PUSH_EXC_INFO
  LOAD_GLOBAL json
  LOAD_ATTR JSONDecodeError
  CHECK_EXC_MATCH
  POP_JUMP_IF_FALSE L7
  POP_TOP
  LOAD_GLOBAL NULL + hasattr
  LOAD_FAST value
  LOAD_CONST 'replace'
  CALL 2
  POP_JUMP_IF_FALSE L5
  LOAD_FAST value
  LOAD_ATTR NULL|self + replace
  LOAD_CONST '"'
  LOAD_CONST '\\"'
  CALL 2
  STORE_FAST value
L5:
  LOAD_GLOBAL json
  LOAD_ATTR NULL|self + loads
  LOAD_CONST '"{}"'
  LOAD_ATTR NULL|self + format
  LOAD_FAST value
  CALL 1
  CALL 1
  SWAP 2
L6:
  POP_EXCEPT
  RETURN_VALUE
L7:
  RERAISE 0
L8:
  COPY 3
  POP_EXCEPT
  RERAISE 1
  EXC try=L2..L3 -> handler=L4 depth=0 lasti=False
  EXC try=L4..L6 -> handler=L8 depth=1 lasti=True
  EXC try=L7..L8 -> handler=L8 depth=1 lasti=True
END

def _get_json(value):
    """pass"""
    if hasattr(value, 'replace'):
        value = value.replace('\n', ' ')
    try:
        return json.loads(value)
    except json.JSONDecodeError:
        if hasattr(value, 'replace'):
            value = value.replace('"', '\\"')
        return json.loads('"{}"'.format(value))


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code save_list>
  MAKE_FUNCTION 0
  STORE_NAME save_list
  RETURN_CONST None
END
CODE save_list(key, *values)
  DOC 'pass'
  RESUME 0
  LOAD_GLOBAL json
  LOAD_ATTR NULL|self + dumps
  LOAD_FAST key
  LOAD_FAST values
  GET_ITER
  LOAD_FAST_AND_CLEAR value
  SWAP 2
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L3
  STORE_FAST value
  LOAD_GLOBAL NULL + _get_json
  LOAD_FAST value
  CALL 1
  LIST_APPEND 2
  JUMP_BACKWARD L2
L3:
  END_FOR
L4:
  SWAP 2
  STORE_FAST value
  BUILD_MAP 1
  CALL 1
  RETURN_VALUE
L5:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST value
  RERAISE 0
  EXC try=L1..L4 -> handler=L5 depth=5 lasti=False
END

def save_list(key, *values):
    """pass"""
    return json.dumps({key: [_get_json(value) for value in values]})


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code save_file>
  MAKE_FUNCTION 0
  STORE_NAME save_file
  RETURN_CONST None
END
CODE save_file(key, file_path, *refs)
  DOC 'pass'
  RESUME 0
  LOAD_GLOBAL os
  LOAD_ATTR path
  LOAD_ATTR NULL|self + isfile
  LOAD_FAST file_path
  CALL 1
  POP_JUMP_IF_TRUE L1
  LOAD_GLOBAL NULL + error
  LOAD_CONST "Output '{}' set to a missing file: '{}'."
  LOAD_ATTR NULL|self + format
  LOAD_FAST key
  LOAD_FAST file_path
  CALL 2
  CALL 1
  RETURN_VALUE
L1:
  LOAD_FAST key
  LOAD_CONST 'file'
  LOAD_FAST file_path
  BUILD_MAP 1
  BUILD_MAP 1
  STORE_FAST result
  LOAD_FAST refs
  POP_JUMP_IF_FALSE L11
  LOAD_FAST refs
  GET_ITER
  LOAD_FAST_AND_CLEAR ref
  SWAP 2
L2:
  BUILD_LIST 0
  SWAP 2
L3:
  FOR_ITER L8
  STORE_FAST ref
  LOAD_GLOBAL os
  LOAD_ATTR path
  LOAD_ATTR NULL|self + isfile
  LOAD_FAST ref
  CALL 1
  POP_JUMP_IF_FALSE L5
L4:
  JUMP_BACKWARD L3
L5:
  LOAD_GLOBAL os
  LOAD_ATTR path
  LOAD_ATTR NULL|self + isdir
  LOAD_FAST ref
  CALL 1
  POP_JUMP_IF_FALSE L7
L6:
  JUMP_BACKWARD L3
L7:
  LOAD_FAST ref
  LIST_APPEND 2
  JUMP_BACKWARD L3
L8:
  END_FOR
L9:
  STORE_FAST missing_refs
  STORE_FAST ref
  LOAD_GLOBAL NULL + len
  LOAD_FAST missing_refs
  CALL 1
  LOAD_CONST 0
  COMPARE_OP >
  POP_JUMP_IF_FALSE L10
  LOAD_GLOBAL NULL + error
  LOAD_CONST "Output '{}' set to missing references: '{}'."
  LOAD_ATTR NULL|self + format
  LOAD_FAST key
  LOAD_CONST ', '
  LOAD_ATTR NULL|self + join
  LOAD_FAST missing_refs
  CALL 1
  CALL 2
  CALL 1
  RETURN_VALUE
L10:
  LOAD_FAST refs
  LOAD_FAST result
  LOAD_FAST key
  BINARY_SUBSCR
  LOAD_CONST 'refs'
  STORE_SUBSCR
L11:
  LOAD_GLOBAL json
  LOAD_ATTR NULL|self + dumps
  LOAD_FAST result
  CALL 1
  RETURN_VALUE
L12:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST ref
  RERAISE 0
  EXC try=L2..L4 -> handler=L12 depth=2 lasti=False
  EXC try=L5..L6 -> handler=L12 depth=2 lasti=False
  EXC try=L7..L9 -> handler=L12 depth=2 lasti=False
END

def save_file(key, file_path, *refs):
    """pass"""
    if not os.path.isfile(file_path):
        return error("Output '{}' set to a missing file: '{}'.".format(key, file_path))
    result = {key: {'file': file_path}}
    if refs:
        missing_refs = [ref for ref in refs if not (os.path.isfile(ref) or os.path.isdir(ref))]
        if len(missing_refs) > 0:
            return error("Output '{}' set to missing references: '{}'.".format(key, ', '.join(missing_refs)))
        result[key]['refs'] = refs
    return json.dumps(result)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code save_file_list>
  MAKE_FUNCTION 0
  STORE_NAME save_file_list
  RETURN_CONST None
END
CODE save_file_list(key, *files_refs)
  DOC 'pass'
  RESUME 0
  BUILD_LIST 0
  STORE_FAST file_list
  LOAD_FAST files_refs
  GET_ITER
L1:
  EXTENDED_ARG 1
  FOR_ITER L21
  STORE_FAST file_refs
  LOAD_CONST ':'
  LOAD_FAST file_refs
  CONTAINS_OP 0
  POP_JUMP_IF_FALSE L4
  NOP
L2:
  LOAD_FAST file_refs
  LOAD_ATTR NULL|self + split
  LOAD_CONST ':'
  CALL 1
  UNPACK_SEQUENCE 2
  STORE_FAST file_name
  STORE_FAST refs
L3:
  JUMP_FORWARD L5
L4:
  LOAD_FAST file_refs
  LOAD_CONST None
  STORE_FAST refs
  STORE_FAST file_name
L5:
  LOAD_GLOBAL os
  LOAD_ATTR path
  LOAD_ATTR NULL|self + isfile
  LOAD_FAST file_name
  CALL 1
  POP_JUMP_IF_TRUE L6
  LOAD_GLOBAL NULL + error
  LOAD_CONST "Output '{}' set to a missing file: '{}'."
  LOAD_ATTR NULL|self + format
  LOAD_FAST key
  LOAD_FAST file_name
  CALL 2
  CALL 1
  SWAP 2
  POP_TOP
  RETURN_VALUE
L6:
  LOAD_CONST 'file'
  LOAD_FAST file_name
  BUILD_MAP 1
  STORE_FAST file_obj
  LOAD_FAST refs
  POP_JUMP_IF_FALSE L20
  LOAD_FAST refs
  LOAD_ATTR NULL|self + split
  LOAD_CONST ','
  CALL 1
  GET_ITER
  LOAD_FAST_AND_CLEAR ref_path
  SWAP 2
L7:
  BUILD_LIST 0
  SWAP 2
L8:
  FOR_ITER L9
  STORE_FAST ref_path
  LOAD_FAST ref_path
  LOAD_ATTR NULL|self + strip
  CALL 0
  LIST_APPEND 2
  JUMP_BACKWARD L8
L9:
  END_FOR
L10:
  STORE_FAST refs
  STORE_FAST ref_path
  LOAD_FAST refs
  GET_ITER
  LOAD_FAST_AND_CLEAR ref
  SWAP 2
L11:
  BUILD_LIST 0
  SWAP 2
L12:
  FOR_ITER L17
  STORE_FAST ref
  LOAD_GLOBAL os
  LOAD_ATTR path
  LOAD_ATTR NULL|self + isfile
  LOAD_FAST ref
  CALL 1
  POP_JUMP_IF_FALSE L14
L13:
  JUMP_BACKWARD L12
L14:
  LOAD_GLOBAL os
  LOAD_ATTR path
  LOAD_ATTR NULL|self + isdir
  LOAD_FAST ref
  CALL 1
  POP_JUMP_IF_FALSE L16
L15:
  JUMP_BACKWARD L12
L16:
  LOAD_FAST ref
  LIST_APPEND 2
  JUMP_BACKWARD L12
L17:
  END_FOR
L18:
  STORE_FAST missing_refs
  STORE_FAST ref
  LOAD_GLOBAL NULL + len
  LOAD_FAST missing_refs
  CALL 1
  LOAD_CONST 0
  COMPARE_OP >
  POP_JUMP_IF_FALSE L19
  LOAD_GLOBAL NULL + error
  LOAD_CONST "Output '{}' set to missing references: '{}'."
  LOAD_ATTR NULL|self + format
  LOAD_FAST key
  LOAD_CONST ', '
  LOAD_ATTR NULL|self + join
  LOAD_FAST missing_refs
  CALL 1
  CALL 2
  CALL 1
  SWAP 2
  POP_TOP
  RETURN_VALUE
L19:
  LOAD_FAST refs
  LOAD_FAST file_obj
  LOAD_CONST 'refs'
  STORE_SUBSCR
L20:
  LOAD_FAST file_list
  LOAD_ATTR NULL|self + append
  LOAD_FAST file_obj
  CALL 1
  POP_TOP
  EXTENDED_ARG 1
  JUMP_BACKWARD L1
L21:
  END_FOR
  LOAD_GLOBAL json
  LOAD_ATTR NULL|self + dumps
  LOAD_FAST key
  LOAD_FAST file_list
  BUILD_MAP 1
  CALL 1
  RETURN_VALUE
L22:
  PUSH_EXC_INFO
  LOAD_GLOBAL ValueError
  CHECK_EXC_MATCH
  POP_JUMP_IF_FALSE L27
  STORE_FAST e
L23:
  LOAD_GLOBAL NULL + error
  LOAD_CONST "Only one colon ':' allowed in file-refs specification."
  CALL 1
L24:
  SWAP 2
L25:
  POP_EXCEPT
  LOAD_CONST None
  STORE_FAST e
  DELETE_FAST e
  SWAP 2
  POP_TOP
  RETURN_VALUE
L26:
  LOAD_CONST None
  STORE_FAST e
  DELETE_FAST e
  RERAISE 1
L27:
  RERAISE 0
L28:
  COPY 3
  POP_EXCEPT
  RERAISE 1
L29:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST ref_path
  RERAISE 0
L30:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST ref
  RERAISE 0
  EXC try=L2..L3 -> handler=L22 depth=1 lasti=False
  EXC try=L7..L10 -> handler=L29 depth=3 lasti=False
  EXC try=L11..L13 -> handler=L30 depth=3 lasti=False
  EXC try=L14..L15 -> handler=L30 depth=3 lasti=False
  EXC try=L16..L18 -> handler=L30 depth=3 lasti=False
  EXC try=L22..L23 -> handler=L28 depth=2 lasti=True
  EXC try=L23..L24 -> handler=L26 depth=2 lasti=True
  EXC try=L24..L25 -> handler=L28 depth=2 lasti=True
  EXC try=L26..L28 -> handler=L28 depth=2 lasti=True
END

def save_file_list(key, *files_refs):
    """pass"""
    file_list = []
    for file_refs in files_refs:
        if ':' in file_refs:
            try:
                file_name, refs = file_refs.split(':')
            except ValueError as e:
                return error("Only one colon ':' allowed in file-refs specification.")
        else:
            file_name, refs = (file_refs, None)
        if not os.path.isfile(file_name):
            return error("Output '{}' set to a missing file: '{}'.".format(key, file_name))
        file_obj = {'file': file_name}
        if refs:
            refs = [ref_path.strip() for ref_path in refs.split(',')]
            missing_refs = [ref for ref in refs if not (os.path.isfile(ref) or os.path.isdir(ref))]
            if len(missing_refs) > 0:
                return error("Output '{}' set to missing references: '{}'.".format(key, ', '.join(missing_refs)))
            file_obj['refs'] = refs
        file_list.append(file_obj)
    return json.dumps({key: file_list})


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code save_dir>
  MAKE_FUNCTION 0
  STORE_NAME save_dir
  RETURN_CONST None
END
CODE save_dir(key, dir_path, *refs)
  DOC 'pass'
  RESUME 0
  LOAD_GLOBAL os
  LOAD_ATTR path
  LOAD_ATTR NULL|self + isdir
  LOAD_FAST dir_path
  CALL 1
  POP_JUMP_IF_TRUE L1
  LOAD_GLOBAL NULL + error
  LOAD_CONST "Output '{}' set to a missing directory: '{}'."
  LOAD_ATTR NULL|self + format
  LOAD_FAST key
  LOAD_FAST dir_path
  CALL 2
  CALL 1
  RETURN_VALUE
L1:
  LOAD_FAST key
  LOAD_CONST 'dir'
  LOAD_FAST dir_path
  BUILD_MAP 1
  BUILD_MAP 1
  STORE_FAST result
  LOAD_FAST refs
  POP_JUMP_IF_FALSE L11
  LOAD_FAST refs
  GET_ITER
  LOAD_FAST_AND_CLEAR ref
  SWAP 2
L2:
  BUILD_LIST 0
  SWAP 2
L3:
  FOR_ITER L8
  STORE_FAST ref
  LOAD_GLOBAL os
  LOAD_ATTR path
  LOAD_ATTR NULL|self + isfile
  LOAD_FAST ref
  CALL 1
  POP_JUMP_IF_FALSE L5
L4:
  JUMP_BACKWARD L3
L5:
  LOAD_GLOBAL os
  LOAD_ATTR path
  LOAD_ATTR NULL|self + isdir
  LOAD_FAST ref
  CALL 1
  POP_JUMP_IF_FALSE L7
L6:
  JUMP_BACKWARD L3
L7:
  LOAD_FAST ref
  LIST_APPEND 2
  JUMP_BACKWARD L3
L8:
  END_FOR
L9:
  STORE_FAST missing_refs
  STORE_FAST ref
  LOAD_GLOBAL NULL + len
  LOAD_FAST missing_refs
  CALL 1
  LOAD_CONST 0
  COMPARE_OP >
  POP_JUMP_IF_FALSE L10
  LOAD_GLOBAL NULL + error
  LOAD_CONST "Output '{}' set to missing references: '{}'."
  LOAD_ATTR NULL|self + format
  LOAD_FAST key
  LOAD_CONST ', '
  LOAD_ATTR NULL|self + join
  LOAD_FAST missing_refs
  CALL 1
  CALL 2
  CALL 1
  RETURN_VALUE
L10:
  LOAD_FAST refs
  LOAD_FAST result
  LOAD_FAST key
  BINARY_SUBSCR
  LOAD_CONST 'refs'
  STORE_SUBSCR
L11:
  LOAD_GLOBAL json
  LOAD_ATTR NULL|self + dumps
  LOAD_FAST result
  CALL 1
  RETURN_VALUE
L12:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST ref
  RERAISE 0
  EXC try=L2..L4 -> handler=L12 depth=2 lasti=False
  EXC try=L5..L6 -> handler=L12 depth=2 lasti=False
  EXC try=L7..L9 -> handler=L12 depth=2 lasti=False
END

def save_dir(key, dir_path, *refs):
    """pass"""
    if not os.path.isdir(dir_path):
        return error("Output '{}' set to a missing directory: '{}'.".format(key, dir_path))
    result = {key: {'dir': dir_path}}
    if refs:
        missing_refs = [ref for ref in refs if not (os.path.isfile(ref) or os.path.isdir(ref))]
        if len(missing_refs) > 0:
            return error("Output '{}' set to missing references: '{}'.".format(key, ', '.join(missing_refs)))
        result[key]['refs'] = refs
    return json.dumps(result)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code save_dir_list>
  MAKE_FUNCTION 0
  STORE_NAME save_dir_list
  RETURN_CONST None
END
CODE save_dir_list(key, *dirs_refs)
  DOC 'pass'
  RESUME 0
  BUILD_LIST 0
  STORE_FAST dir_list
  LOAD_FAST dirs_refs
  GET_ITER
L1:
  EXTENDED_ARG 1
  FOR_ITER L21
  STORE_FAST dir_refs
  LOAD_CONST ':'
  LOAD_FAST dir_refs
  CONTAINS_OP 0
  POP_JUMP_IF_FALSE L4
  NOP
L2:
  LOAD_FAST dir_refs
  LOAD_ATTR NULL|self + split
  LOAD_CONST ':'
  CALL 1
  UNPACK_SEQUENCE 2
  STORE_FAST dir_path
  STORE_FAST refs
L3:
  JUMP_FORWARD L5
L4:
  LOAD_FAST dir_refs
  LOAD_CONST None
  STORE_FAST refs
  STORE_FAST dir_path
L5:
  LOAD_GLOBAL os
  LOAD_ATTR path
  LOAD_ATTR NULL|self + isdir
  LOAD_FAST dir_path
  CALL 1
  POP_JUMP_IF_TRUE L6
  LOAD_GLOBAL NULL + error
  LOAD_CONST "Output '{}' set to a missing directory: '{}'."
  LOAD_ATTR NULL|self + format
  LOAD_FAST key
  LOAD_FAST dir_path
  CALL 2
  CALL 1
  SWAP 2
  POP_TOP
  RETURN_VALUE
L6:
  LOAD_CONST 'dir'
  LOAD_FAST dir_path
  BUILD_MAP 1
  STORE_FAST dir_obj
  LOAD_FAST refs
  POP_JUMP_IF_FALSE L20
  LOAD_FAST refs
  LOAD_ATTR NULL|self + split
  LOAD_CONST ','
  CALL 1
  GET_ITER
  LOAD_FAST_AND_CLEAR ref_path
  SWAP 2
L7:
  BUILD_LIST 0
  SWAP 2
L8:
  FOR_ITER L9
  STORE_FAST ref_path
  LOAD_FAST ref_path
  LOAD_ATTR NULL|self + strip
  CALL 0
  LIST_APPEND 2
  JUMP_BACKWARD L8
L9:
  END_FOR
L10:
  STORE_FAST refs
  STORE_FAST ref_path
  LOAD_FAST refs
  GET_ITER
  LOAD_FAST_AND_CLEAR ref
  SWAP 2
L11:
  BUILD_LIST 0
  SWAP 2
L12:
  FOR_ITER L17
  STORE_FAST ref
  LOAD_GLOBAL os
  LOAD_ATTR path
  LOAD_ATTR NULL|self + isfile
  LOAD_FAST ref
  CALL 1
  POP_JUMP_IF_FALSE L14
L13:
  JUMP_BACKWARD L12
L14:
  LOAD_GLOBAL os
  LOAD_ATTR path
  LOAD_ATTR NULL|self + isdir
  LOAD_FAST ref
  CALL 1
  POP_JUMP_IF_FALSE L16
L15:
  JUMP_BACKWARD L12
L16:
  LOAD_FAST ref
  LIST_APPEND 2
  JUMP_BACKWARD L12
L17:
  END_FOR
L18:
  STORE_FAST missing_refs
  STORE_FAST ref
  LOAD_GLOBAL NULL + len
  LOAD_FAST missing_refs
  CALL 1
  LOAD_CONST 0
  COMPARE_OP >
  POP_JUMP_IF_FALSE L19
  LOAD_GLOBAL NULL + error
  LOAD_CONST "Output '{}' set to missing references: '{}'."
  LOAD_ATTR NULL|self + format
  LOAD_FAST key
  LOAD_CONST ', '
  LOAD_ATTR NULL|self + join
  LOAD_FAST missing_refs
  CALL 1
  CALL 2
  CALL 1
  SWAP 2
  POP_TOP
  RETURN_VALUE
L19:
  LOAD_FAST refs
  LOAD_FAST dir_obj
  LOAD_CONST 'refs'
  STORE_SUBSCR
L20:
  LOAD_FAST dir_list
  LOAD_ATTR NULL|self + append
  LOAD_FAST dir_obj
  CALL 1
  POP_TOP
  EXTENDED_ARG 1
  JUMP_BACKWARD L1
L21:
  END_FOR
  LOAD_GLOBAL json
  LOAD_ATTR NULL|self + dumps
  LOAD_FAST key
  LOAD_FAST dir_list
  BUILD_MAP 1
  CALL 1
  RETURN_VALUE
L22:
  PUSH_EXC_INFO
  LOAD_GLOBAL ValueError
  CHECK_EXC_MATCH
  POP_JUMP_IF_FALSE L27
  STORE_FAST e
L23:
  LOAD_GLOBAL NULL + error
  LOAD_CONST "Only one colon ':' allowed in dir-refs specification."
  CALL 1
L24:
  SWAP 2
L25:
  POP_EXCEPT
  LOAD_CONST None
  STORE_FAST e
  DELETE_FAST e
  SWAP 2
  POP_TOP
  RETURN_VALUE
L26:
  LOAD_CONST None
  STORE_FAST e
  DELETE_FAST e
  RERAISE 1
L27:
  RERAISE 0
L28:
  COPY 3
  POP_EXCEPT
  RERAISE 1
L29:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST ref_path
  RERAISE 0
L30:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST ref
  RERAISE 0
  EXC try=L2..L3 -> handler=L22 depth=1 lasti=False
  EXC try=L7..L10 -> handler=L29 depth=3 lasti=False
  EXC try=L11..L13 -> handler=L30 depth=3 lasti=False
  EXC try=L14..L15 -> handler=L30 depth=3 lasti=False
  EXC try=L16..L18 -> handler=L30 depth=3 lasti=False
  EXC try=L22..L23 -> handler=L28 depth=2 lasti=True
  EXC try=L23..L24 -> handler=L26 depth=2 lasti=True
  EXC try=L24..L25 -> handler=L28 depth=2 lasti=True
  EXC try=L26..L28 -> handler=L28 depth=2 lasti=True
END

def save_dir_list(key, *dirs_refs):
    """pass"""
    dir_list = []
    for dir_refs in dirs_refs:
        if ':' in dir_refs:
            try:
                dir_path, refs = dir_refs.split(':')
            except ValueError as e:
                return error("Only one colon ':' allowed in dir-refs specification.")
        else:
            dir_path, refs = (dir_refs, None)
        if not os.path.isdir(dir_path):
            return error("Output '{}' set to a missing directory: '{}'.".format(key, dir_path))
        dir_obj = {'dir': dir_path}
        if refs:
            refs = [ref_path.strip() for ref_path in refs.split(',')]
            missing_refs = [ref for ref in refs if not (os.path.isfile(ref) or os.path.isdir(ref))]
            if len(missing_refs) > 0:
                return error("Output '{}' set to missing references: '{}'.".format(key, ', '.join(missing_refs)))
            dir_obj['refs'] = refs
        dir_list.append(dir_obj)
    return json.dumps({key: dir_list})


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code n_day>
  MAKE_FUNCTION 0
  STORE_NAME n_day
  RETURN_CONST None
END
CODE n_day(date_string)
  DOC 'pass'
  RESUME 0
  LOAD_GLOBAL datetime
  LOAD_ATTR date
  LOAD_ATTR NULL|self + today
  CALL 0
  STORE_FAST today
  LOAD_GLOBAL re
  LOAD_ATTR NULL|self + match
  LOAD_CONST '(\\d{1,3}|a) days? ago'
  LOAD_FAST date_string
  CALL 2
  STORE_FAST match
  LOAD_FAST match
  LOAD_ATTR NULL|self + groups
  CALL 0
  STORE_FAST groups
  LOAD_FAST groups
  POP_JUMP_IF_FALSE L2
  LOAD_FAST groups
  LOAD_CONST 0
  BINARY_SUBSCR
  STORE_FAST decrement
  LOAD_FAST decrement
  LOAD_CONST 'a'
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L1
  LOAD_CONST 1
  STORE_FAST decrement
L1:
  LOAD_FAST today
  LOAD_GLOBAL datetime
  LOAD_ATTR NULL|self + timedelta
  LOAD_GLOBAL NULL + int
  LOAD_FAST decrement
  CALL 1
  KW_NAMES ('days',)
  CALL 1
  BINARY_OP -
  RETURN_VALUE
L2:
  RETURN_CONST None
END

def n_day(date_string):
    """pass"""
    today = datetime.date.today()
    match = re.match('(\\d{1,3}|a) days? ago', date_string)
    groups = match.groups()
    if groups:
        decrement = groups[0]
        if decrement == 'a':
            decrement = 1
        return today - datetime.timedelta(days=int(decrement))
    return None


Input:
CODE <module>()
  DOC 'location'
  RESUME 0
  LOAD_CONST 'location'
  LOAD_NAME FileLocation
  LOAD_CONST 'return'
  LOAD_NAME Optional
  LOAD_NAME FunctionDesc
  BINARY_SUBSCR
  BUILD_TUPLE 4
  LOAD_CONST <code encloses>
  MAKE_FUNCTION annotations
  STORE_NAME encloses
  RETURN_CONST None
END
CODE encloses(self, location)
  DOC 'pass'
  RESUME 0
  LOAD_FAST self
  LOAD_ATTR NULL|self + in_file
  LOAD_FAST location
  LOAD_ATTR filename
  CALL 1
  GET_ITER
L1:
  FOR_ITER L3
  STORE_FAST func
  LOAD_FAST location
  LOAD_FAST func
  LOAD_ATTR location
  CONTAINS_OP 0
  POP_JUMP_IF_TRUE L2
  JUMP_BACKWARD L1
L2:
  LOAD_FAST func
  SWAP 2
  POP_TOP
  RETURN_VALUE
L3:
  END_FOR
  RETURN_CONST None
END

def encloses(self, location: FileLocation) -> Optional[FunctionDesc]:
    """pass"""
    for func in self.in_file(location.filename):
        if location in func.location:
            return func
    return None


Input:
CODE <module>()
  DOC 'filename'
  RESUME 0
  LOAD_CONST 'filename'
  LOAD_NAME str
  LOAD_CONST 'return'
  LOAD_NAME Iterator
  LOAD_NAME FunctionDesc
  BINARY_SUBSCR
  BUILD_TUPLE 4
  LOAD_CONST <code in_file>
  MAKE_FUNCTION annotations
  STORE_NAME in_file
  RETURN_CONST None
END
CODE in_file(self, filename)
  DOC 'pass'
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_FAST self
  LOAD_ATTR __filename_to_functions
  LOAD_ATTR NULL|self + get
  LOAD_FAST filename
  BUILD_LIST 0
  CALL 2
  GET_YIELD_FROM_ITER
  LOAD_CONST None
L2:
  SEND L5
L3:
  YIELD_VALUE 2
L4:
  RESUME 2
  JUMP_BACKWARD_NO_INTERRUPT L2
L5:
  END_SEND
  POP_TOP
  RETURN_CONST None
L6:
  CLEANUP_THROW
L7:
  JUMP_BACKWARD L5
L8:
  CALL_INTRINSIC_1 INTRINSIC_STOPITERATION_ERROR
  RERAISE 1
  EXC try=L1..L3 -> handler=L8 depth=0 lasti=True
  EXC try=L3..L4 -> handler=L6 depth=2 lasti=False
  EXC try=L4..L7 -> handler=L8 depth=0 lasti=True
END

def in_file(self, filename: str) -> Iterator[FunctionDesc]:
    """pass"""
    yield from self.__filename_to_functions.get(filename, [])


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code parse_config>
  MAKE_FUNCTION 0
  STORE_NAME parse_config
  RETURN_CONST None
END
CODE parse_config(args)
  DOC 'pass'
  RESUME 0
  LOAD_GLOBAL path
  LOAD_ATTR NULL|self + expanduser
  LOAD_FAST args
  LOAD_ATTR config_file
  CALL 1
  STORE_FAST config_path
  LOAD_GLOBAL path
  LOAD_ATTR NULL|self + exists
  LOAD_FAST config_path
  CALL 1
  POP_JUMP_IF_TRUE L2
  LOAD_FAST args
  LOAD_ATTR config_file
  LOAD_GLOBAL DEFAULT_JOURNAL_RC
  COMPARE_OP !=
  POP_JUMP_IF_FALSE L1
  LOAD_GLOBAL NULL + print
  LOAD_CONST "journal: error: config file '"
  LOAD_FAST args
  LOAD_ATTR config_file
  BINARY_OP +
  LOAD_CONST "' not found"
  BINARY_OP +
  CALL 1
  POP_TOP
  LOAD_GLOBAL sys
  LOAD_ATTR NULL|self + exit
  CALL 0
  POP_TOP
  JUMP_FORWARD L2
L1:
  LOAD_GLOBAL DEFAULT_JOURNAL
  RETURN_VALUE
L2:
  LOAD_GLOBAL ConfigParser
  LOAD_ATTR NULL|self + SafeConfigParser
  LOAD_CONST 'default'
  LOAD_CONST '__journal'
  BUILD_MAP 1
  LOAD_CONST 'location'
  LOAD_GLOBAL DEFAULT_JOURNAL
  BUILD_MAP 1
  LOAD_CONST ('journal', '__journal')
  BUILD_CONST_KEY_MAP 2
  CALL 1
  STORE_FAST config
  LOAD_FAST config
  LOAD_ATTR NULL|self + read
  LOAD_FAST config_path
  CALL 1
  POP_TOP
  LOAD_FAST config
  LOAD_ATTR NULL|self + get
  LOAD_FAST config
  LOAD_ATTR NULL|self + get
  LOAD_CONST 'journal'
  LOAD_CONST 'default'
  CALL 2
  LOAD_CONST 'location'
  CALL 2
  STORE_FAST journal_location
  LOAD_FAST args
  LOAD_ATTR journal
  POP_JUMP_IF_FALSE L3
  LOAD_FAST config
  LOAD_ATTR NULL|self + get
  LOAD_FAST args
  LOAD_ATTR journal
  LOAD_CONST 'location'
  CALL 2
  STORE_FAST journal_location
L3:
  LOAD_FAST journal_location
  RETURN_VALUE
END

def parse_config(args):
    """pass"""
    config_path = path.expanduser(args.config_file)
    if not path.exists(config_path):
        if args.config_file != DEFAULT_JOURNAL_RC:
            print("journal: error: config file '" + args.config_file + "' not found")
            sys.exit()
        else:
            return DEFAULT_JOURNAL
    config = ConfigParser.SafeConfigParser({'journal': {'default': '__journal'}, '__journal': {'location': DEFAULT_JOURNAL}})
    config.read(config_path)
    journal_location = config.get(config.get('journal', 'default'), 'location')
    if args.journal:
        journal_location = config.get(args.journal, 'location')
    return journal_location


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code record_entries>
  MAKE_FUNCTION 0
  STORE_NAME record_entries
  RETURN_CONST None
END
CODE record_entries(journal_location, entries)
  DOC 'pass'
  RESUME 0
  LOAD_GLOBAL NULL + check_journal_dest
  LOAD_FAST journal_location
  CALL 1
  POP_TOP
  LOAD_GLOBAL datetime
  LOAD_ATTR datetime
  LOAD_ATTR NULL|self + today
  CALL 0
  STORE_FAST current_date
  LOAD_FAST current_date
  LOAD_ATTR NULL|self + strftime
  LOAD_CONST '%a %H:%M:%S %Y-%m-%d'
  CALL 1
  LOAD_CONST '\n'
  BINARY_OP +
  STORE_FAST date_header
  LOAD_GLOBAL NULL + open
  LOAD_GLOBAL NULL + build_journal_path
  LOAD_FAST journal_location
  LOAD_FAST current_date
  CALL 2
  LOAD_CONST 'a'
  CALL 2
  BEFORE_WITH
L1:
  STORE_FAST date_file
  LOAD_FAST date_header
  STORE_FAST entry_output
  LOAD_FAST entry_output
  LOAD_CONST '-'
  LOAD_CONST ' '
  LOAD_ATTR NULL|self + join
  LOAD_FAST entries
  CALL 1
  BINARY_OP +
  LOAD_CONST '\n'
  BINARY_OP +
  BINARY_OP +=
  STORE_FAST entry_output
  LOAD_FAST entry_output
  LOAD_CONST '\n'
  BINARY_OP +=
  STORE_FAST entry_output
  LOAD_FAST date_file
  LOAD_ATTR NULL|self + write
  LOAD_FAST entry_output
  CALL 1
  POP_TOP
L2:
  LOAD_CONST None
  LOAD_CONST None
  LOAD_CONST None
  CALL 2
  POP_TOP
  RETURN_CONST None
L3:
  PUSH_EXC_INFO
  WITH_EXCEPT_START
  POP_JUMP_IF_TRUE L4
  RERAISE 2
L4:
  POP_TOP
L5:
  POP_EXCEPT
  POP_TOP
  POP_TOP
  RETURN_CONST None
L6:
  COPY 3
  POP_EXCEPT
  RERAISE 1
  EXC try=L1..L2 -> handler=L3 depth=1 lasti=True
  EXC try=L3..L5 -> handler=L6 depth=3 lasti=True
END

def record_entries(journal_location, entries):
    """pass"""
    check_journal_dest(journal_location)
    current_date = datetime.datetime.today()
    date_header = current_date.strftime('%a %H:%M:%S %Y-%m-%d') + '\n'
    with open(build_journal_path(journal_location, current_date), 'a') as date_file:
        entry_output = date_header
        entry_output += '-' + ' '.join(entries) + '\n'
        entry_output += '\n'
        date_file.write(entry_output)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code get_entry>
  MAKE_FUNCTION 0
  STORE_NAME get_entry
  RETURN_CONST None
END
CODE get_entry(journal_location, date)
  DOC 'pass'
  RESUME 0
  LOAD_GLOBAL NULL + isinstance
  LOAD_FAST date
  LOAD_GLOBAL datetime
  LOAD_ATTR date
  CALL 2
  POP_JUMP_IF_TRUE L1
  RETURN_CONST None
L1:
  NOP
L2:
  LOAD_GLOBAL NULL + open
  LOAD_GLOBAL NULL + build_journal_path
  LOAD_FAST journal_location
  LOAD_FAST date
  CALL 2
  LOAD_CONST 'r'
  CALL 2
  BEFORE_WITH
L3:
  STORE_FAST entry_file
  LOAD_FAST entry_file
  LOAD_ATTR NULL|self + read
  CALL 0
L4:
  SWAP 2
  LOAD_CONST None
  LOAD_CONST None
  LOAD_CONST None
  CALL 2
  POP_TOP
L5:
  RETURN_VALUE
L6:
  PUSH_EXC_INFO
  WITH_EXCEPT_START
  POP_JUMP_IF_TRUE L7
  RERAISE 2
L7:
  POP_TOP
L8:
  POP_EXCEPT
  POP_TOP
  POP_TOP
L9:
  RETURN_CONST None
L10:
  COPY 3
  POP_EXCEPT
  RERAISE 1
L11:
  PUSH_EXC_INFO
  LOAD_GLOBAL IOError
  CHECK_EXC_MATCH
  POP_JUMP_IF_FALSE L13
  POP_TOP
L12:
  POP_EXCEPT
  RETURN_CONST None
L13:
  RERAISE 0
L14:
  COPY 3
  POP_EXCEPT
  RERAISE 1
  EXC try=L2..L3 -> handler=L11 depth=0 lasti=False
  EXC try=L3..L4 -> handler=L6 depth=1 lasti=True
  EXC try=L4..L5 -> handler=L11 depth=0 lasti=False
  EXC try=L6..L8 -> handler=L10 depth=3 lasti=True
  EXC try=L8..L9 -> handler=L11 depth=0 lasti=False
  EXC try=L10..L11 -> handler=L11 depth=0 lasti=False
  EXC try=L11..L12 -> handler=L14 depth=1 lasti=True
  EXC try=L13..L14 -> handler=L14 depth=1 lasti=True
END

def get_entry(journal_location, date):
    """pass"""
    if not isinstance(date, datetime.date):
        return None
    try:
        with open(build_journal_path(journal_location, date), 'r') as entry_file:
            return entry_file.read()
    except IOError:
        return None


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code TemplateValidator>
  MAKE_FUNCTION 0
  STORE_NAME TemplateValidator
  RETURN_CONST None
END
CODE TemplateValidator(value)
  DOC 'pass'
  RESUME 0
  NOP
L1:
  LOAD_GLOBAL NULL + Template
  LOAD_FAST value
  CALL 1
  POP_TOP
L2:
  RETURN_CONST None
L3:
  PUSH_EXC_INFO
  LOAD_GLOBAL Exception
  CHECK_EXC_MATCH
  POP_JUMP_IF_FALSE L6
  STORE_FAST e
L4:
  LOAD_GLOBAL NULL + ValidationError
  LOAD_GLOBAL NULL + _
  LOAD_CONST 'Cannot compile template (%(exception)s)'
  CALL 1
  LOAD_CONST 'exception'
  LOAD_FAST e
  BUILD_MAP 1
  KW_NAMES ('params',)
  CALL 2
  RAISE_VARARGS 1
L5:
  LOAD_CONST None
  STORE_FAST e
  DELETE_FAST e
  RERAISE 1
L6:
  RERAISE 0
L7:
  COPY 3
  POP_EXCEPT
  RERAISE 1
  EXC try=L1..L2 -> handler=L3 depth=0 lasti=False
  EXC try=L3..L4 -> handler=L7 depth=1 lasti=True
  EXC try=L4..L5 -> handler=L5 depth=1 lasti=True
  EXC try=L5..L7 -> handler=L7 depth=1 lasti=True
END

def TemplateValidator(value):
    """pass"""
    try:
        Template(value)
    except Exception as e:
        raise ValidationError(_('Cannot compile template (%(exception)s)'), params={'exception': e})


Input:
CODE <module>()
  RESUME 0
  LOAD_NAME LBRY_API_RAW_JSON_URL
  BUILD_TUPLE 1
  LOAD_CONST <code get_lbry_api_function_docs>
  MAKE_FUNCTION defaults
  STORE_NAME get_lbry_api_function_docs
  RETURN_CONST None
END
CODE get_lbry_api_function_docs(url)
  DOC 'pass'
  RESUME 0
  NOP
L1:
  LOAD_GLOBAL NULL + urlopen
  LOAD_FAST url
  CALL 1
  STORE_FAST docs_page
  LOAD_FAST docs_page
  LOAD_ATTR NULL|self + read
  CALL 0
  LOAD_ATTR NULL|self + decode
  LOAD_CONST 'utf-8'
  CALL 1
  STORE_FAST contents
  LOAD_GLOBAL NULL + loads
  LOAD_FAST contents
  CALL 1
L2:
  RETURN_VALUE
L3:
  PUSH_EXC_INFO
  LOAD_GLOBAL URLError
  CHECK_EXC_MATCH
  POP_JUMP_IF_FALSE L7
  STORE_FAST UE
L4:
  LOAD_GLOBAL NULL + print
  LOAD_FAST UE
  CALL 1
  POP_TOP
L5:
  POP_EXCEPT
  LOAD_CONST None
  STORE_FAST UE
  DELETE_FAST UE
  BUILD_LIST 0
  RETURN_VALUE
L6:
  LOAD_CONST None
  STORE_FAST UE
  DELETE_FAST UE
  RERAISE 1
L7:
  LOAD_GLOBAL Exception
  CHECK_EXC_MATCH
  POP_JUMP_IF_FALSE L11
  STORE_FAST E
L8:
  LOAD_GLOBAL NULL + print
  LOAD_FAST E
  CALL 1
  POP_TOP
L9:
  POP_EXCEPT
  LOAD_CONST None
  STORE_FAST E
  DELETE_FAST E
  BUILD_LIST 0
  RETURN_VALUE
L10:
  LOAD_CONST None
  STORE_FAST E
  DELETE_FAST E
  RERAISE 1
L11:
  RERAISE 0
L12:
  COPY 3
  POP_EXCEPT
  RERAISE 1
  EXC try=L1..L2 -> handler=L3 depth=0 lasti=False
  EXC try=L3..L4 -> handler=L12 depth=1 lasti=True
  EXC try=L4..L5 -> handler=L6 depth=1 lasti=True
  EXC try=L6..L8 -> handler=L12 depth=1 lasti=True
  EXC try=L8..L9 -> handler=L10 depth=1 lasti=True
  EXC try=L10..L12 -> handler=L12 depth=1 lasti=True
END

def get_lbry_api_function_docs(url=LBRY_API_RAW_JSON_URL):
    """pass"""
    try:
        docs_page = urlopen(url)
        contents = docs_page.read().decode('utf-8')
        return loads(contents)
    except URLError as UE:
        print(UE)
    except Exception as E:
        print(E)
    return []


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code generate_method_definition>
  MAKE_FUNCTION 0
  STORE_NAME generate_method_definition
  RETURN_CONST None
END
CODE generate_method_definition(func)
  DOC 'pass'
  RESUME 0
  LOAD_CONST 4
  STORE_FAST indent
  LOAD_CONST ' '
  LOAD_FAST indent
  BINARY_OP *
  LOAD_CONST 'def '
  BINARY_OP +
  LOAD_FAST func
  LOAD_CONST 'name'
  BINARY_SUBSCR
  BINARY_OP +
  STORE_FAST method_definition
  LOAD_FAST func
  LOAD_CONST 'arguments'
  BINARY_SUBSCR
  GET_ITER
  LOAD_FAST_AND_CLEAR param
  SWAP 2
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L5
  STORE_FAST param
  LOAD_FAST param
  LOAD_CONST 'is_required'
  BINARY_SUBSCR
  POP_JUMP_IF_TRUE L4
L3:
  JUMP_BACKWARD L2
L4:
  LOAD_FAST param
  LIST_APPEND 2
  JUMP_BACKWARD L2
L5:
  END_FOR
L6:
  STORE_FAST params_required
  STORE_FAST param
  LOAD_FAST func
  LOAD_CONST 'arguments'
  BINARY_SUBSCR
  GET_ITER
  LOAD_FAST_AND_CLEAR param
  SWAP 2
L7:
  BUILD_LIST 0
  SWAP 2
L8:
  FOR_ITER L11
  STORE_FAST param
  LOAD_FAST param
  LOAD_CONST 'is_required'
  BINARY_SUBSCR
  POP_JUMP_IF_FALSE L10
L9:
  JUMP_BACKWARD L8
L10:
  LOAD_FAST param
  LIST_APPEND 2
  JUMP_BACKWARD L8
L11:
  END_FOR
L12:
  STORE_FAST params_optional
  STORE_FAST param
  LOAD_FAST method_definition
  LOAD_CONST '(self, '
  BINARY_OP +=
  STORE_FAST method_definition
  LOAD_FAST params_required
  GET_ITER
L13:
  FOR_ITER L14
  STORE_FAST param
  LOAD_FAST method_definition
  LOAD_FAST param
  LOAD_CONST 'name'
  BINARY_SUBSCR
  BINARY_OP +=
  STORE_FAST method_definition
  LOAD_FAST method_definition
  LOAD_CONST ', '
  BINARY_OP +=
  STORE_FAST method_definition
  JUMP_BACKWARD L13
L14:
  END_FOR
  LOAD_FAST params_optional
  GET_ITER
L15:
  FOR_ITER L16
  STORE_FAST param
  LOAD_FAST method_definition
  LOAD_FAST param
  LOAD_CONST 'name'
  BINARY_SUBSCR
  BINARY_OP +=
  STORE_FAST method_definition
  LOAD_FAST method_definition
  LOAD_CONST '=None, '
  BINARY_OP +=
  STORE_FAST method_definition
  JUMP_BACKWARD L15
L16:
  END_FOR
  LOAD_FAST method_definition
  LOAD_ATTR NULL|self + rstrip
  LOAD_CONST ', '
  CALL 1
  LOAD_CONST '):\n'
  BINARY_OP +
  STORE_FAST method_definition
  LOAD_FAST indent
  LOAD_CONST 4
  BINARY_OP +=
  STORE_FAST indent
  LOAD_FAST method_definition
  LOAD_CONST ' '
  LOAD_FAST indent
  BINARY_OP *
  BINARY_OP +=
  STORE_FAST method_definition
  LOAD_FAST method_definition
  LOAD_CONST '"""'
  LOAD_FAST func
  LOAD_CONST 'description'
  BINARY_SUBSCR
  BINARY_OP +
  BINARY_OP +=
  STORE_FAST method_definition
  LOAD_FAST method_definition
  LOAD_CONST '\n\n'
  LOAD_CONST ' '
  LOAD_FAST indent
  BINARY_OP *
  BINARY_OP +
  BINARY_OP +=
  STORE_FAST method_definition
  LOAD_FAST params_required
  LOAD_FAST params_optional
  BINARY_OP +
  GET_ITER
L17:
  FOR_ITER L20
  STORE_FAST param
  LOAD_FAST method_definition
  LOAD_CONST ':param '
  LOAD_GLOBAL DTYPE_MAPPING
  LOAD_FAST param
  LOAD_CONST 'type'
  BINARY_SUBSCR
  LOAD_ATTR NULL|self + lower
  CALL 0
  BINARY_SUBSCR
  BINARY_OP +
  BINARY_OP +=
  STORE_FAST method_definition
  LOAD_FAST method_definition
  LOAD_CONST ' '
  LOAD_FAST param
  LOAD_CONST 'name'
  BINARY_SUBSCR
  BINARY_OP +
  LOAD_CONST ': '
  BINARY_OP +
  BINARY_OP +=
  STORE_FAST method_definition
  LOAD_FAST method_definition
  LOAD_FAST param
  LOAD_CONST 'description'
  BINARY_SUBSCR
  BINARY_OP +=
  STORE_FAST method_definition
  LOAD_FAST method_definition
  LOAD_FAST param
  LOAD_CONST 'is_required'
  BINARY_SUBSCR
  POP_JUMP_IF_FALSE L18
  LOAD_CONST '\n'
  JUMP_FORWARD L19
L18:
  LOAD_CONST ' (Optional)\n'
L19:
  BINARY_OP +=
  STORE_FAST method_definition
  LOAD_FAST method_definition
  LOAD_CONST ' '
  LOAD_FAST indent
  BINARY_OP *
  BINARY_OP +=
  STORE_FAST method_definition
  JUMP_BACKWARD L17
L20:
  END_FOR
  LOAD_FAST func
  LOAD_CONST 'returns'
  BINARY_SUBSCR
  LOAD_ATTR NULL|self + find
  LOAD_CONST '('
  CALL 1
  STORE_FAST open_index
  LOAD_FAST func
  LOAD_CONST 'returns'
  BINARY_SUBSCR
  LOAD_ATTR NULL|self + find
  LOAD_CONST ')'
  LOAD_FAST open_index
  LOAD_CONST -1
  COMPARE_OP >
  POP_JUMP_IF_FALSE L21
  LOAD_FAST open_index
  JUMP_FORWARD L22
L21:
  LOAD_CONST 0
L22:
  CALL 2
  STORE_FAST close_index
  LOAD_FAST func
  LOAD_CONST 'returns'
  BINARY_SUBSCR
  LOAD_ATTR NULL|self + replace
  LOAD_CONST '\t'
  LOAD_CONST '    '
  CALL 2
  LOAD_FAST func
  LOAD_CONST 'returns'
  STORE_SUBSCR
  LOAD_FAST func
  LOAD_CONST 'returns'
  BINARY_SUBSCR
  LOAD_ATTR NULL|self + replace
  LOAD_CONST '\n'
  LOAD_CONST ''
  CALL 2
  STORE_FAST return_string
  LOAD_FAST open_index
  LOAD_FAST close_index
  COMPARE_OP <
  POP_JUMP_IF_FALSE L23
  LOAD_FAST func
  LOAD_CONST 'returns'
  BINARY_SUBSCR
  LOAD_FAST open_index
  LOAD_CONST 1
  BINARY_OP +
  LOAD_FAST close_index
  BINARY_SLICE
  LOAD_GLOBAL DTYPE_MAPPING
  CONTAINS_OP 0
  POP_JUMP_IF_FALSE L23
  LOAD_FAST method_definition
  LOAD_CONST ':rtype: '
  LOAD_GLOBAL DTYPE_MAPPING
  LOAD_FAST func
  LOAD_CONST 'returns'
  BINARY_SUBSCR
  LOAD_FAST open_index
  LOAD_CONST 1
  BINARY_OP +
  LOAD_FAST close_index
  BINARY_SLICE
  BINARY_SUBSCR
  BINARY_OP +
  BINARY_OP +=
  STORE_FAST method_definition
  LOAD_FAST func
  LOAD_CONST 'returns'
  BINARY_SUBSCR
  LOAD_ATTR NULL|self + replace
  LOAD_FAST func
  LOAD_CONST 'returns'
  BINARY_SUBSCR
  LOAD_FAST open_index
  LOAD_FAST close_index
  LOAD_CONST 1
  BINARY_OP +
  BINARY_SLICE
  LOAD_CONST ''
  CALL 2
  LOAD_FAST func
  LOAD_CONST 'returns'
  STORE_SUBSCR
  LOAD_FAST method_definition
  LOAD_CONST '\n'
  LOAD_CONST ' '
  LOAD_FAST indent
  BINARY_OP *
  BINARY_OP +
  BINARY_OP +=
  STORE_FAST method_definition
L23:
  LOAD_FAST method_definition
  LOAD_CONST ':return: '
  LOAD_FAST return_string
  BINARY_OP +
  BINARY_OP +=
  STORE_FAST method_definition
  LOAD_GLOBAL NULL + range
  LOAD_CONST 0
  LOAD_GLOBAL NULL + len
  LOAD_FAST return_string
  CALL 1
  LOAD_CONST 1
  BINARY_OP +
  LOAD_CONST 80
  LOAD_FAST indent
  LOAD_CONST 2
  BINARY_OP +
  BINARY_OP -
  CALL 3
  GET_ITER
L24:
  FOR_ITER L25
  STORE_FAST i
  LOAD_FAST method_definition
  LOAD_FAST return_string
  LOAD_FAST i
  LOAD_FAST i
  LOAD_CONST 80
  LOAD_FAST indent
  LOAD_CONST 2
  BINARY_OP +
  BINARY_OP -
  BINARY_OP +
  BINARY_SLICE
  LOAD_CONST '\n'
  BINARY_OP +
  LOAD_CONST ' '
  LOAD_FAST indent
  BINARY_OP *
  BINARY_OP +
  BINARY_OP +=
  STORE_FAST method_definition
  JUMP_BACKWARD L24
L25:
  END_FOR
  LOAD_FAST method_definition
  LOAD_CONST '"""\n'
  LOAD_CONST ' '
  LOAD_FAST indent
  BINARY_OP *
  BINARY_OP +
  BINARY_OP +=
  STORE_FAST method_definition
  LOAD_CONST '__params_map = {'
  STORE_FAST params_map
  LOAD_GLOBAL NULL + len
  LOAD_FAST params_map
  CALL 1
  LOAD_GLOBAL NULL + len
  LOAD_FAST params_required
  CALL 1
  LOAD_GLOBAL NULL + len
  LOAD_FAST params_optional
  CALL 1
  BINARY_OP +
  STORE_FAST num_params
  STORE_FAST params_indent
  LOAD_FAST method_definition
  LOAD_FAST params_map
  BINARY_OP +=
  STORE_FAST method_definition
  LOAD_GLOBAL NULL + enumerate
  LOAD_FAST params_required
  LOAD_FAST params_optional
  BINARY_OP +
  CALL 1
  GET_ITER
L26:
  FOR_ITER L30
  UNPACK_SEQUENCE 2
  STORE_FAST i
  STORE_FAST param
  LOAD_FAST method_definition
  LOAD_CONST "'"
  LOAD_FAST param
  LOAD_CONST 'name'
  BINARY_SUBSCR
  BINARY_OP +
  LOAD_CONST "': "
  BINARY_OP +
  LOAD_FAST param
  LOAD_CONST 'name'
  BINARY_SUBSCR
  BINARY_OP +
  BINARY_OP +=
  STORE_FAST method_definition
  LOAD_FAST param
  LOAD_CONST 'is_required'
  BINARY_SUBSCR
  POP_JUMP_IF_TRUE L27
  LOAD_FAST method_definition
  LOAD_CONST ' if '
  BINARY_OP +
  LOAD_FAST param
  LOAD_CONST 'name'
  BINARY_SUBSCR
  BINARY_OP +
  LOAD_CONST 'is not None else None'
  BINARY_OP +
  POP_TOP
L27:
  LOAD_FAST method_definition
  LOAD_FAST i
  LOAD_CONST 1
  BINARY_OP +
  LOAD_FAST num_params
  COMPARE_OP <
  POP_JUMP_IF_FALSE L28
  LOAD_CONST ',\n'
  LOAD_CONST ' '
  LOAD_FAST indent
  BINARY_OP *
  BINARY_OP +
  LOAD_CONST ' '
  LOAD_FAST params_indent
  BINARY_OP *
  BINARY_OP +
  JUMP_FORWARD L29
L28:
  LOAD_CONST ''
L29:
  BINARY_OP +=
  STORE_FAST method_definition
  JUMP_BACKWARD L26
L30:
  END_FOR
  LOAD_FAST method_definition
  LOAD_CONST '}\n\n'
  LOAD_CONST ' '
  LOAD_FAST indent
  BINARY_OP *
  BINARY_OP +
  BINARY_OP +=
  STORE_FAST method_definition
  LOAD_FAST method_definition
  LOAD_CONST "return self.make_request(SERVER_ADDRESS, '"
  LOAD_FAST func
  LOAD_CONST 'name'
  BINARY_SUBSCR
  BINARY_OP +
  LOAD_CONST "', "
  BINARY_OP +
  LOAD_FAST params_map
  LOAD_ATTR NULL|self + rstrip
  LOAD_CONST ' = {'
  CALL 1
  BINARY_OP +
  LOAD_CONST ', timeout=self.timeout)\n\n'
  BINARY_OP +
  BINARY_OP +=
  STORE_FAST method_definition
  LOAD_FAST method_definition
  RETURN_VALUE
L31:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST param
  RERAISE 0
L32:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST param
  RERAISE 0
  EXC try=L1..L3 -> handler=L31 depth=2 lasti=False
  EXC try=L4..L6 -> handler=L31 depth=2 lasti=False
  EXC try=L7..L9 -> handler=L32 depth=2 lasti=False
  EXC try=L10..L12 -> handler=L32 depth=2 lasti=False
END

def generate_method_definition(func):
    """pass"""
    indent = 4
    method_definition = ' ' * indent + 'def ' + func['name']
    params_required = [param for param in func['arguments'] if param['is_required']]
    params_optional = [param for param in func['arguments'] if not param['is_required']]
    method_definition += '(self, '
    for param in params_required:
        method_definition += param['name']
        method_definition += ', '
    for param in params_optional:
        method_definition += param['name']
        method_definition += '=None, '
    method_definition = method_definition.rstrip(', ') + '):\n'
    indent += 4
    method_definition += ' ' * indent
    method_definition += '"""' + func['description']
    method_definition += '\n\n' + ' ' * indent
    for param in params_required + params_optional:
        method_definition += ':param ' + DTYPE_MAPPING[param['type'].lower()]
        method_definition += ' ' + param['name'] + ': '
        method_definition += param['description']
        method_definition += '\n' if param['is_required'] else ' (Optional)\n'
        method_definition += ' ' * indent
    open_index = func['returns'].find('(')
    close_index = func['returns'].find(')', open_index if open_index > -1 else 0)
    func['returns'] = func['returns'].replace('\t', ' ' * 4)
    return_string = func['returns'].replace('\n', '')
    if open_index < close_index and func['returns'][open_index + 1:close_index] in DTYPE_MAPPING:
        method_definition += ':rtype: ' + DTYPE_MAPPING[func['returns'][open_index + 1:close_index]]
        func['returns'] = func['returns'].replace(func['returns'][open_index:close_index + 1], '')
        method_definition += '\n' + ' ' * indent
    method_definition += ':return: ' + return_string
    for i in range(0, len(return_string) + 1, 80 - (indent + 2)):
        method_definition += return_string[i:i + (80 - (indent + 2))] + '\n' + ' ' * indent
    method_definition += '"""' + '\n' + ' ' * indent
    params_map = '__params_map = {'
    params_indent, num_params = (len(params_map), len(params_required) + len(params_optional))
    method_definition += params_map
    for i, param in enumerate(params_required + params_optional):
        method_definition += "'" + param['name'] + "': " + param['name']
        if not param['is_required']:
            method_definition + ' if ' + param['name'] + 'is not None else None'
        method_definition += ',\n' + ' ' * indent + ' ' * params_indent if i + 1 < num_params else ''
    method_definition += '}\n\n' + ' ' * indent
    method_definition += "return self.make_request(SERVER_ADDRESS, '" + func['name'] + "', " + params_map.rstrip(' = {') + ', timeout=self.timeout)\n\n'
    return method_definition


Input:
CODE <module>()
  RESUME 0
  LOAD_NAME LBRY_API_RAW_JSON_URL
  LOAD_NAME __LBRYD_BASE_FPATH__
  LOAD_NAME LBRYD_FPATH
  BUILD_TUPLE 3
  LOAD_CONST <code generate_lbryd_wrapper>
  MAKE_FUNCTION defaults
  STORE_NAME generate_lbryd_wrapper
  RETURN_CONST None
END
CODE generate_lbryd_wrapper(url, read_file, write_file)
  DOC 'pass'
  RESUME 0
  LOAD_GLOBAL NULL + get_lbry_api_function_docs
  LOAD_FAST url
  CALL 1
  STORE_FAST functions
  LOAD_GLOBAL NULL + open
  LOAD_FAST write_file
  LOAD_CONST 'w'
  CALL 2
  BEFORE_WITH
L1:
  STORE_FAST lbry_file
  LOAD_FAST lbry_file
  LOAD_ATTR NULL|self + write
  LOAD_CONST '# This file was generated at build time using the generator function\n'
  CALL 1
  POP_TOP
  LOAD_FAST lbry_file
  LOAD_ATTR NULL|self + write
  LOAD_CONST '# You may edit but do so with caution\n'
  CALL 1
  POP_TOP
  LOAD_GLOBAL NULL + open
  LOAD_FAST read_file
  LOAD_CONST 'r'
  CALL 2
  BEFORE_WITH
L2:
  STORE_FAST template
  LOAD_FAST template
  LOAD_ATTR NULL|self + read
  CALL 0
  STORE_FAST header
L3:
  LOAD_CONST None
  LOAD_CONST None
  LOAD_CONST None
  CALL 2
  POP_TOP
L4:
  LOAD_FAST lbry_file
  LOAD_ATTR NULL|self + write
  LOAD_FAST_CHECK header
  CALL 1
  POP_TOP
  LOAD_FAST functions
  GET_ITER
L5:
  FOR_ITER L6
  STORE_FAST func
  LOAD_GLOBAL NULL + generate_method_definition
  LOAD_FAST func
  CALL 1
  STORE_FAST method_definition
  LOAD_FAST lbry_file
  LOAD_ATTR NULL|self + write
  LOAD_FAST method_definition
  CALL 1
  POP_TOP
  JUMP_BACKWARD L5
L6:
  END_FOR
L7:
  NOP
  LOAD_CONST None
  LOAD_CONST None
  LOAD_CONST None
  CALL 2
  POP_TOP
L8:
  NOP
L9:
  LOAD_CONST 0
  LOAD_CONST ('FormatFile',)
  IMPORT_NAME yapf.yapflib.yapf_api
  IMPORT_FROM FormatFile
  STORE_FAST FormatFile
  POP_TOP
  PUSH_NULL
  LOAD_FAST FormatFile
  LOAD_FAST write_file
  LOAD_CONST True
  KW_NAMES ('in_place',)
  CALL 2
  POP_TOP
L10:
  RETURN_CONST None
L11:
  PUSH_EXC_INFO
  WITH_EXCEPT_START
  POP_JUMP_IF_TRUE L12
  RERAISE 2
L12:
  POP_TOP
L13:
  POP_EXCEPT
  POP_TOP
  POP_TOP
  JUMP_BACKWARD L4
L14:
  COPY 3
  POP_EXCEPT
  RERAISE 1
L15:
  PUSH_EXC_INFO
  WITH_EXCEPT_START
  POP_JUMP_IF_TRUE L16
  RERAISE 2
L16:
  POP_TOP
L17:
  POP_EXCEPT
  POP_TOP
  POP_TOP
  JUMP_BACKWARD L8
L18:
  COPY 3
  POP_EXCEPT
  RERAISE 1
L19:
  PUSH_EXC_INFO
  LOAD_GLOBAL ImportError
  CHECK_EXC_MATCH
  POP_JUMP_IF_FALSE L23
  STORE_FAST IE
L20:
  LOAD_GLOBAL NULL + print
  LOAD_CONST '[Warning]: yapf is not installed, so the generated code will not follow an easy-to-read standard'
  CALL 1
  POP_TOP
  LOAD_GLOBAL NULL + print
  LOAD_FAST IE
  CALL 1
  POP_TOP
L21:
  POP_EXCEPT
  LOAD_CONST None
  STORE_FAST IE
  DELETE_FAST IE
  RETURN_CONST None
L22:
  LOAD_CONST None
  STORE_FAST IE
  DELETE_FAST IE
  RERAISE 1
L23:
  RERAISE 0
L24:
  COPY 3
  POP_EXCEPT
  RERAISE 1
  EXC try=L1..L2 -> handler=L15 depth=1 lasti=True
  EXC try=L2..L3 -> handler=L11 depth=2 lasti=True
  EXC try=L3..L7 -> handler=L15 depth=1 lasti=True
  EXC try=L9..L10 -> handler=L19 depth=0 lasti=False
  EXC try=L11..L13 -> handler=L14 depth=4 lasti=True
  EXC try=L13..L15 -> handler=L15 depth=1 lasti=True
  EXC try=L15..L17 -> handler=L18 depth=3 lasti=True
  EXC try=L19..L20 -> handler=L24 depth=1 lasti=True
  EXC try=L20..L21 -> handler=L22 depth=1 lasti=True
  EXC try=L22..L24 -> handler=L24 depth=1 lasti=True
END

def generate_lbryd_wrapper(url=LBRY_API_RAW_JSON_URL, read_file=__LBRYD_BASE_FPATH__, write_file=LBRYD_FPATH):
    """pass"""
    functions = get_lbry_api_function_docs(url)
    with open(write_file, 'w') as lbry_file:
        lbry_file.write('# This file was generated at build time using the generator function\n')
        lbry_file.write('# You may edit but do so with caution\n')
        with open(read_file, 'r') as template:
            header = template.read()
        lbry_file.write(header)
        for func in functions:
            method_definition = generate_method_definition(func)
            lbry_file.write(method_definition)
    try:
        from yapf.yapflib.yapf_api import FormatFile
        FormatFile(write_file, in_place=True)
    except ImportError as IE:
        print('[Warning]: yapf is not installed, so the generated code will not follow an easy-to-read standard')
        print(IE)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code get>
  MAKE_FUNCTION 0
  STORE_NAME get
  RETURN_CONST None
END
CODE get(self, style)
  DOC 'pass'
  RESUME 0
  LOAD_GLOBAL NULL + len
  LOAD_FAST self
  LOAD_ATTR stack
  CALL 1
  LOAD_CONST 1
  BINARY_OP -
  STORE_FAST level
  LOAD_FAST level
  LOAD_CONST 0
  COMPARE_OP >=
  POP_JUMP_IF_FALSE L3
L1:
  LOAD_FAST style
  LOAD_FAST self
  LOAD_ATTR stack
  LOAD_FAST level
  BINARY_SUBSCR
  CONTAINS_OP 0
  POP_JUMP_IF_FALSE L2
  LOAD_FAST self
  LOAD_ATTR stack
  LOAD_FAST level
  BINARY_SUBSCR
  LOAD_FAST style
  BINARY_SUBSCR
  RETURN_VALUE
L2:
  LOAD_FAST level
  LOAD_CONST 1
  BINARY_OP -
  STORE_FAST level
  LOAD_FAST level
  LOAD_CONST 0
  COMPARE_OP >=
  POP_JUMP_IF_FALSE L3
  JUMP_BACKWARD L1
L3:
  RETURN_CONST None
END

def get(self, style):
    """pass"""
    level = len(self.stack) - 1
    while level >= 0:
        if style in self.stack[level]:
            return self.stack[level][style]
        else:
            level = level - 1
    return None


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code enforce_type>
  MAKE_FUNCTION 0
  STORE_NAME enforce_type
  RETURN_CONST None
END
CODE enforce_type(self, attr, val)
  DOC 'pass'
  RESUME 0
  LOAD_FAST attr
  LOAD_FAST self
  LOAD_ATTR types
  CONTAINS_OP 1
  POP_JUMP_IF_FALSE L1
  LOAD_GLOBAL NULL + utfstr
  LOAD_FAST val
  CALL 1
  RETURN_VALUE
L1:
  LOAD_FAST self
  LOAD_ATTR types
  LOAD_FAST attr
  BINARY_SUBSCR
  LOAD_CONST 'int'
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L2
  LOAD_GLOBAL NULL + int
  LOAD_GLOBAL NULL + float
  LOAD_FAST val
  CALL 1
  CALL 1
  RETURN_VALUE
L2:
  LOAD_FAST self
  LOAD_ATTR types
  LOAD_FAST attr
  BINARY_SUBSCR
  LOAD_CONST 'float'
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L3
  LOAD_GLOBAL NULL + float
  LOAD_FAST val
  CALL 1
  RETURN_VALUE
L3:
  LOAD_GLOBAL NULL + utfstr
  LOAD_FAST val
  CALL 1
  RETURN_VALUE
END

def enforce_type(self, attr, val):
    """pass"""
    if not attr in self.types:
        return utfstr(val)
    elif self.types[attr] == 'int':
        return int(float(val))
    elif self.types[attr] == 'float':
        return float(val)
    else:
        return utfstr(val)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code to_escpos>
  MAKE_FUNCTION 0
  STORE_NAME to_escpos
  RETURN_CONST None
END
CODE to_escpos(self)
  DOC 'pass'
  MAKE_CELL self
  RESUME 0
  LOAD_CONST ''
  STORE_FAST cmd
  LOAD_DEREF self
  LOAD_ATTR cmds
  LOAD_ATTR NULL|self + keys
  CALL 0
  STORE_FAST ordered_cmds
  LOAD_FAST ordered_cmds
  LOAD_ATTR NULL|self + sort
  LOAD_CLOSURE self
  BUILD_TUPLE 1
  LOAD_CONST <code to_escpos.<locals>.<lambda>>
  MAKE_FUNCTION closure
  CALL 1
  POP_TOP
  LOAD_FAST ordered_cmds
  GET_ITER
L1:
  FOR_ITER L2
  STORE_FAST style
  LOAD_FAST cmd
  LOAD_DEREF self
  LOAD_ATTR cmds
  LOAD_FAST style
  BINARY_SUBSCR
  LOAD_DEREF self
  LOAD_ATTR NULL|self + get
  LOAD_FAST style
  CALL 1
  BINARY_SUBSCR
  BINARY_OP +=
  STORE_FAST cmd
  JUMP_BACKWARD L1
L2:
  END_FOR
  LOAD_FAST cmd
  RETURN_VALUE
END
CODE to_escpos.<locals>.<lambda>(x, y)
  COPY_FREE_VARS 1
  RESUME 0
  LOAD_GLOBAL NULL + cmp
  LOAD_DEREF self
  LOAD_ATTR cmds
  LOAD_FAST x
  BINARY_SUBSCR
  LOAD_CONST '_order'
  BINARY_SUBSCR
  LOAD_DEREF self
  LOAD_ATTR cmds
  LOAD_FAST y
  BINARY_SUBSCR
  LOAD_CONST '_order'
  BINARY_SUBSCR
  CALL 2
  RETURN_VALUE
END

def to_escpos(self):
    """pass"""
    cmd = ''
    ordered_cmds = self.cmds.keys()
    ordered_cmds.sort(lambda x, y: cmp(self.cmds[x]['_order'], self.cmds[y]['_order']))
    for style in ordered_cmds:
        cmd += self.cmds[style][self.get(style)]
    return cmd


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST (None,)
  LOAD_CONST <code start_inline>
  MAKE_FUNCTION defaults
  STORE_NAME start_inline
  RETURN_CONST None
END
CODE start_inline(self, stylestack)
  DOC 'pass'
  RESUME 0
  LOAD_FAST self
  LOAD_ATTR stack
  LOAD_ATTR NULL|self + append
  LOAD_CONST 'inline'
  CALL 1
  POP_TOP
  LOAD_FAST self
  LOAD_ATTR dirty
  POP_JUMP_IF_FALSE L1
  LOAD_FAST self
  LOAD_ATTR escpos
  LOAD_ATTR NULL|self + _raw
  LOAD_CONST ' '
  CALL 1
  POP_TOP
L1:
  LOAD_FAST stylestack
  POP_JUMP_IF_FALSE L2
  LOAD_FAST self
  LOAD_ATTR NULL|self + style
  LOAD_FAST stylestack
  CALL 1
  POP_TOP
  RETURN_CONST None
L2:
  RETURN_CONST None
END

def start_inline(self, stylestack=None):
    """pass"""
    self.stack.append('inline')
    if self.dirty:
        self.escpos._raw(' ')
    if stylestack:
        self.style(stylestack)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST (None,)
  LOAD_CONST <code start_block>
  MAKE_FUNCTION defaults
  STORE_NAME start_block
  RETURN_CONST None
END
CODE start_block(self, stylestack)
  DOC 'pass'
  RESUME 0
  LOAD_FAST self
  LOAD_ATTR dirty
  POP_JUMP_IF_FALSE L1
  LOAD_FAST self
  LOAD_ATTR escpos
  LOAD_ATTR NULL|self + _raw
  LOAD_CONST '\n'
  CALL 1
  POP_TOP
  LOAD_CONST False
  LOAD_FAST self
  STORE_ATTR dirty
L1:
  LOAD_FAST self
  LOAD_ATTR stack
  LOAD_ATTR NULL|self + append
  LOAD_CONST 'block'
  CALL 1
  POP_TOP
  LOAD_FAST stylestack
  POP_JUMP_IF_FALSE L2
  LOAD_FAST self
  LOAD_ATTR NULL|self + style
  LOAD_FAST stylestack
  CALL 1
  POP_TOP
  RETURN_CONST None
L2:
  RETURN_CONST None
END

def start_block(self, stylestack=None):
    """pass"""
    if self.dirty:
        self.escpos._raw('\n')
        self.dirty = False
    self.stack.append('block')
    if stylestack:
        self.style(stylestack)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code end_entity>
  MAKE_FUNCTION 0
  STORE_NAME end_entity
  RETURN_CONST None
END
CODE end_entity(self)
  DOC 'pass'
  RESUME 0
  LOAD_FAST self
  LOAD_ATTR stack
  LOAD_CONST -1
  BINARY_SUBSCR
  LOAD_CONST 'block'
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L1
  LOAD_FAST self
  LOAD_ATTR dirty
  POP_JUMP_IF_FALSE L1
  LOAD_FAST self
  LOAD_ATTR escpos
  LOAD_ATTR NULL|self + _raw
  LOAD_CONST '\n'
  CALL 1
  POP_TOP
  LOAD_CONST False
  LOAD_FAST self
  STORE_ATTR dirty
L1:
  LOAD_GLOBAL NULL + len
  LOAD_FAST self
  LOAD_ATTR stack
  CALL 1
  LOAD_CONST 1
  COMPARE_OP >
  POP_JUMP_IF_FALSE L2
  LOAD_FAST self
  LOAD_ATTR stack
  LOAD_CONST None
  LOAD_CONST -1
  BINARY_SLICE
  LOAD_FAST self
  STORE_ATTR stack
  RETURN_CONST None
L2:
  RETURN_CONST None
END

def end_entity(self):
    """pass"""
    if self.stack[-1] == 'block' and self.dirty:
        self.escpos._raw('\n')
        self.dirty = False
    if len(self.stack) > 1:
        self.stack = self.stack[:-1]


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code _pinyin_generator>
  MAKE_FUNCTION 0
  STORE_NAME _pinyin_generator
  RETURN_CONST None
END
CODE _pinyin_generator(chars, format)
  DOC 'pass'
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_FAST chars
  GET_ITER
L2:
  FOR_ITER L8
  STORE_FAST char
  LOAD_CONST '%X'
  LOAD_GLOBAL NULL + ord
  LOAD_FAST char
  CALL 1
  BINARY_OP %
  STORE_FAST key
  LOAD_GLOBAL pinyin_dict
  LOAD_ATTR NULL|self + get
  LOAD_FAST key
  LOAD_FAST char
  CALL 2
  STORE_FAST pinyin
  LOAD_GLOBAL pinyin_tone
  LOAD_ATTR NULL|self + get
  LOAD_FAST key
  LOAD_CONST 0
  CALL 2
  STORE_FAST tone
  LOAD_FAST tone
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L3
  LOAD_FAST format
  LOAD_CONST 'strip'
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L4
L3:
  JUMP_FORWARD L7
L4:
  LOAD_FAST format
  LOAD_CONST 'numerical'
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L5
  LOAD_FAST pinyin
  LOAD_GLOBAL NULL + str
  LOAD_FAST tone
  CALL 1
  BINARY_OP +=
  STORE_FAST pinyin
  JUMP_FORWARD L7
L5:
  LOAD_FAST format
  LOAD_CONST 'diacritical'
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L6
  LOAD_GLOBAL itertools
  LOAD_ATTR NULL|self + chain
  LOAD_CONST <code _pinyin_generator.<locals>.<genexpr>>
  MAKE_FUNCTION 0
  LOAD_FAST pinyin
  GET_ITER
  CALL 0
  LOAD_CONST <code _pinyin_generator.<locals>.<genexpr>>
  MAKE_FUNCTION 0
  LOAD_FAST pinyin
  GET_ITER
  CALL 0
  CALL 2
  STORE_FAST vowels
  LOAD_FAST pinyin
  LOAD_ATTR NULL|self + index
  LOAD_GLOBAL NULL + next
  LOAD_FAST vowels
  CALL 1
  CALL 1
  LOAD_CONST 1
  BINARY_OP +
  STORE_FAST vowel
  LOAD_FAST pinyin
  LOAD_CONST None
  LOAD_FAST vowel
  BINARY_SLICE
  LOAD_GLOBAL tonemarks
  LOAD_FAST tone
  BINARY_SUBSCR
  BINARY_OP +
  LOAD_FAST pinyin
  LOAD_FAST vowel
  LOAD_CONST None
  BINARY_SLICE
  BINARY_OP +
  STORE_FAST pinyin
  JUMP_FORWARD L7
L6:
  LOAD_CONST 'Format must be one of: numerical/diacritical/strip'
  STORE_FAST error
  LOAD_GLOBAL NULL + ValueError
  LOAD_FAST error
  CALL 1
  RAISE_VARARGS 1
L7:
  LOAD_GLOBAL unicodedata
  LOAD_ATTR NULL|self + normalize
  LOAD_CONST 'NFC'
  LOAD_FAST pinyin
  CALL 2
  YIELD_VALUE 1
  RESUME 1
  POP_TOP
  JUMP_BACKWARD L2
L8:
  END_FOR
  RETURN_CONST None
L9:
  CALL_INTRINSIC_1 INTRINSIC_STOPITERATION_ERROR
  RERAISE 1
  EXC try=L1..L9 -> handler=L9 depth=0 lasti=True
END
CODE _pinyin_generator.<locals>.<genexpr>(.0)
  DOC 'aeo'
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_FAST .0
L2:
  FOR_ITER L5
  STORE_FAST c
  LOAD_FAST c
  LOAD_CONST 'aeo'
  CONTAINS_OP 0
  POP_JUMP_IF_TRUE L4
L3:
  JUMP_BACKWARD L2
L4:
  LOAD_FAST c
  YIELD_VALUE 1
  RESUME 1
  POP_TOP
  JUMP_BACKWARD L2
L5:
  END_FOR
  RETURN_CONST None
L6:
  CALL_INTRINSIC_1 INTRINSIC_STOPITERATION_ERROR
  RERAISE 1
  EXC try=L1..L3 -> handler=L6 depth=0 lasti=True
  EXC try=L4..L6 -> handler=L6 depth=0 lasti=True
END
CODE _pinyin_generator.<locals>.<genexpr>(.0)
  DOC 'iuv'
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_FAST .0
L2:
  FOR_ITER L5
  STORE_FAST c
  LOAD_FAST c
  LOAD_CONST 'iuv'
  CONTAINS_OP 0
  POP_JUMP_IF_TRUE L4
L3:
  JUMP_BACKWARD L2
L4:
  LOAD_FAST c
  YIELD_VALUE 1
  RESUME 1
  POP_TOP
  JUMP_BACKWARD L2
L5:
  END_FOR
  RETURN_CONST None
L6:
  CALL_INTRINSIC_1 INTRINSIC_STOPITERATION_ERROR
  RERAISE 1
  EXC try=L1..L3 -> handler=L6 depth=0 lasti=True
  EXC try=L4..L6 -> handler=L6 depth=0 lasti=True
END

def _pinyin_generator(chars, format):
    """pass"""
    for char in chars:
        key = '%X' % ord(char)
        pinyin = pinyin_dict.get(key, char)
        tone = pinyin_tone.get(key, 0)
        if tone == 0 or format == 'strip':
            pass
        elif format == 'numerical':
            pinyin += str(tone)
        elif format == 'diacritical':
            vowels = itertools.chain((c for c in pinyin if c in 'aeo'), (c for c in pinyin if c in 'iuv'))
            vowel = pinyin.index(next(vowels)) + 1
            pinyin = pinyin[:vowel] + tonemarks[tone] + pinyin[vowel:]
        else:
            error = 'Format must be one of: numerical/diacritical/strip'
            raise ValueError(error)
        yield unicodedata.normalize('NFC', pinyin)


Input:
CODE <module>()
  DOC ''
  RESUME 0
  LOAD_CONST ('', 'diacritical')
  LOAD_CONST <code get>
  MAKE_FUNCTION defaults
  STORE_NAME get
  RETURN_CONST None
END
CODE get(s, delimiter, format)
  DOC 'pass'
  RESUME 0
  LOAD_FAST delimiter
  LOAD_ATTR NULL|self + join
  LOAD_GLOBAL NULL + _pinyin_generator
  LOAD_GLOBAL NULL + u
  LOAD_FAST s
  CALL 1
  LOAD_FAST format
  KW_NAMES ('format',)
  CALL 2
  CALL 1
  RETURN_VALUE
END

def get(s, delimiter='', format='diacritical'):
    """pass"""
    return delimiter.join(_pinyin_generator(u(s), format=format))


Input:
CODE <module>()
  DOC ' '
  RESUME 0
  LOAD_CONST (' ',)
  LOAD_CONST <code get_initial>
  MAKE_FUNCTION defaults
  STORE_NAME get_initial
  RETURN_CONST None
END
CODE get_initial(s, delimiter)
  DOC 'pass'
  RESUME 0
  LOAD_CONST <code get_initial.<locals>.<genexpr>>
  MAKE_FUNCTION 0
  LOAD_GLOBAL NULL + _pinyin_generator
  LOAD_GLOBAL NULL + u
  LOAD_FAST s
  CALL 1
  LOAD_CONST 'strip'
  KW_NAMES ('format',)
  CALL 2
  GET_ITER
  CALL 0
  STORE_FAST initials
  LOAD_FAST delimiter
  LOAD_ATTR NULL|self + join
  LOAD_FAST initials
  CALL 1
  RETURN_VALUE
END
CODE get_initial.<locals>.<genexpr>(.0)
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_FAST .0
L2:
  FOR_ITER L3
  STORE_FAST p
  LOAD_FAST p
  LOAD_CONST 0
  BINARY_SUBSCR
  YIELD_VALUE 1
  RESUME 1
  POP_TOP
  JUMP_BACKWARD L2
L3:
  END_FOR
  RETURN_CONST None
L4:
  CALL_INTRINSIC_1 INTRINSIC_STOPITERATION_ERROR
  RERAISE 1
  EXC try=L1..L4 -> handler=L4 depth=0 lasti=True
END

def get_initial(s, delimiter=' '):
    """pass"""
    initials = (p[0] for p in _pinyin_generator(u(s), format='strip'))
    return delimiter.join(initials)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code _add_to_tree>
  MAKE_FUNCTION 0
  STORE_NAME _add_to_tree
  RETURN_CONST None
END
CODE _add_to_tree(tree, word, meaning)
  DOC 'pass'
  RESUME 0
  LOAD_GLOBAL NULL + len
  LOAD_FAST word
  CALL 1
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L1
  LOAD_FAST meaning
  LOAD_FAST tree
  LOAD_CONST ''
  STORE_SUBSCR
  RETURN_CONST None
L1:
  LOAD_GLOBAL NULL + _add_to_tree
  LOAD_FAST tree
  LOAD_FAST word
  LOAD_CONST 0
  BINARY_SUBSCR
  BINARY_SUBSCR
  LOAD_FAST word
  LOAD_CONST 1
  LOAD_CONST None
  BINARY_SLICE
  LOAD_FAST meaning
  CALL 3
  POP_TOP
  RETURN_CONST None
END

def _add_to_tree(tree, word, meaning):
    """pass"""
    if len(word) == 0:
        tree[''] = meaning
    else:
        _add_to_tree(tree[word[0]], word[1:], meaning)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code init>
  MAKE_FUNCTION 0
  STORE_NAME init
  RETURN_CONST None
END
CODE init()
  DOC 'pass'
  MAKE_CELL exp
  RESUME 0
  BUILD_MAP 0
  BUILD_MAP 0
  LOAD_CONST ('traditional', 'simplified')
  BUILD_CONST_KEY_MAP 2
  STORE_GLOBAL dictionaries
  LOAD_GLOBAL NULL + Tree
  CALL 0
  LOAD_GLOBAL NULL + Tree
  CALL 0
  LOAD_CONST ('traditional', 'simplified')
  BUILD_CONST_KEY_MAP 2
  STORE_GLOBAL trees
  LOAD_GLOBAL gzip
  LOAD_ATTR NULL|self + open
  LOAD_GLOBAL os
  LOAD_ATTR path
  LOAD_ATTR NULL|self + join
  LOAD_GLOBAL os
  LOAD_ATTR path
  LOAD_ATTR NULL|self + dirname
  LOAD_GLOBAL __file__
  CALL 1
  LOAD_CONST 'cedict.txt.gz'
  CALL 2
  LOAD_CONST 'rt'
  LOAD_CONST 'utf-8'
  KW_NAMES ('mode', 'encoding')
  CALL 3
  STORE_FAST lines
  LOAD_GLOBAL re
  LOAD_ATTR NULL|self + compile
  LOAD_CONST '^([^ ]+) ([^ ]+) \\[(.*)\\] /(.+)/'
  CALL 1
  STORE_DEREF exp
  LOAD_CLOSURE exp
  BUILD_TUPLE 1
  LOAD_CONST <code init.<locals>.<genexpr>>
  MAKE_FUNCTION closure
  LOAD_FAST lines
  GET_ITER
  CALL 0
  STORE_FAST parsed_lines
  LOAD_FAST parsed_lines
  GET_ITER
L1:
  FOR_ITER L2
  UNPACK_SEQUENCE 4
  STORE_FAST traditional
  STORE_FAST simplified
  STORE_FAST pinyin
  STORE_FAST meaning
  LOAD_FAST meaning
  LOAD_ATTR NULL|self + split
  LOAD_CONST '/'
  CALL 1
  STORE_FAST meaning
  LOAD_FAST meaning
  LOAD_GLOBAL dictionaries
  LOAD_CONST 'traditional'
  BINARY_SUBSCR
  LOAD_FAST traditional
  STORE_SUBSCR
  LOAD_FAST meaning
  LOAD_GLOBAL dictionaries
  LOAD_CONST 'simplified'
  BINARY_SUBSCR
  LOAD_FAST simplified
  STORE_SUBSCR
  LOAD_GLOBAL NULL + _add_to_tree
  LOAD_GLOBAL trees
  LOAD_CONST 'traditional'
  BINARY_SUBSCR
  LOAD_FAST traditional
  LOAD_FAST meaning
  CALL 3
  POP_TOP
  LOAD_GLOBAL NULL + _add_to_tree
  LOAD_GLOBAL trees
  LOAD_CONST 'simplified'
  BINARY_SUBSCR
  LOAD_FAST simplified
  LOAD_FAST meaning
  CALL 3
  POP_TOP
  JUMP_BACKWARD L1
L2:
  END_FOR
  RETURN_CONST None
END
CODE init.<locals>.<genexpr>(.0)
  COPY_FREE_VARS 1
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_FAST .0
L2:
  FOR_ITER L5
  STORE_FAST line
  LOAD_FAST line
  LOAD_CONST 0
  BINARY_SUBSCR
  LOAD_CONST '#'
  COMPARE_OP !=
  POP_JUMP_IF_TRUE L4
L3:
  JUMP_BACKWARD L2
L4:
  LOAD_DEREF exp
  LOAD_ATTR NULL|self + match
  LOAD_FAST line
  CALL 1
  LOAD_ATTR NULL|self + groups
  CALL 0
  YIELD_VALUE 1
  RESUME 1
  POP_TOP
  JUMP_BACKWARD L2
L5:
  END_FOR
  RETURN_CONST None
L6:
  CALL_INTRINSIC_1 INTRINSIC_STOPITERATION_ERROR
  RERAISE 1
  EXC try=L1..L3 -> handler=L6 depth=0 lasti=True
  EXC try=L4..L6 -> handler=L6 depth=0 lasti=True
END

def init():
    """pass"""
    global dictionaries, trees
    dictionaries = {'traditional': {}, 'simplified': {}}
    trees = {'traditional': Tree(), 'simplified': Tree()}
    lines = gzip.open(os.path.join(os.path.dirname(__file__), 'cedict.txt.gz'), mode='rt', encoding='utf-8')
    exp = re.compile('^([^ ]+) ([^ ]+) \\[(.*)\\] /(.+)/')
    parsed_lines = (exp.match(line).groups() for line in lines if line[0] != '#')
    for traditional, simplified, pinyin, meaning in parsed_lines:
        meaning = meaning.split('/')
        dictionaries['traditional'][traditional] = meaning
        dictionaries['simplified'][simplified] = meaning
        _add_to_tree(trees['traditional'], traditional, meaning)
        _add_to_tree(trees['simplified'], simplified, meaning)


Input:
CODE <module>()
  DOC 'simplified'
  RESUME 0
  LOAD_CONST 'simplified'
  BUILD_LIST 1
  BUILD_TUPLE 1
  LOAD_CONST <code translate_word>
  MAKE_FUNCTION defaults
  STORE_NAME translate_word
  RETURN_CONST None
END
CODE translate_word(word, dictionary)
  DOC 'pass'
  RESUME 0
  LOAD_GLOBAL dictionaries
  POP_JUMP_IF_TRUE L1
  LOAD_GLOBAL NULL + init
  CALL 0
  POP_TOP
L1:
  LOAD_FAST dictionary
  GET_ITER
L2:
  FOR_ITER L4
  STORE_FAST d
  LOAD_FAST word
  LOAD_GLOBAL dictionaries
  LOAD_FAST d
  BINARY_SUBSCR
  CONTAINS_OP 0
  POP_JUMP_IF_TRUE L3
  JUMP_BACKWARD L2
L3:
  LOAD_GLOBAL dictionaries
  LOAD_FAST d
  BINARY_SUBSCR
  LOAD_FAST word
  BINARY_SUBSCR
  SWAP 2
  POP_TOP
  RETURN_VALUE
L4:
  END_FOR
  RETURN_CONST None
END

def translate_word(word, dictionary=['simplified']):
    """pass"""
    if not dictionaries:
        init()
    for d in dictionary:
        if word in dictionaries[d]:
            return dictionaries[d][word]
    return None


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code get_status_key>
  MAKE_FUNCTION 0
  STORE_NAME get_status_key
  RETURN_CONST None
END
CODE get_status_key(self, instance)
  DOC 'pass'
  RESUME 0
  LOAD_FAST instance
  LOAD_ATTR pk
  POP_JUMP_IF_NOT_NONE L1
  LOAD_CONST 'inst_%s'
  LOAD_GLOBAL NULL + id
  LOAD_FAST instance
  CALL 1
  BINARY_OP %
  JUMP_FORWARD L2
L1:
  LOAD_FAST instance
  LOAD_ATTR pk
L2:
  STORE_FAST key_id
  LOAD_FAST instance
  LOAD_ATTR _meta
  LOAD_ATTR app_label
  FORMAT_VALUE str
  LOAD_CONST '.'
  LOAD_GLOBAL NULL + get_model_name
  LOAD_FAST instance
  CALL 1
  FORMAT_VALUE str
  LOAD_CONST '-'
  LOAD_FAST key_id
  FORMAT_VALUE str
  LOAD_CONST '-'
  LOAD_FAST self
  LOAD_ATTR field
  LOAD_ATTR name
  FORMAT_VALUE str
  BUILD_STRING 7
  RETURN_VALUE
END

def get_status_key(self, instance):
    """pass"""
    key_id = 'inst_%s' % id(instance) if instance.pk is None else instance.pk
    return '%s.%s-%s-%s' % (instance._meta.app_label, get_model_name(instance), key_id, self.field.name)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code get_status>
  MAKE_FUNCTION 0
  STORE_NAME get_status
  RETURN_CONST None
END
CODE get_status(self, instance)
  DOC 'pass'
  RESUME 0
  LOAD_FAST self
  LOAD_ATTR NULL|self + _get_status
  LOAD_FAST instance
  CALL 1
  UNPACK_SEQUENCE 2
  STORE_FAST status_key
  STORE_FAST status
  LOAD_FAST status
  LOAD_CONST 'state'
  BINARY_SUBSCR
  LOAD_CONST ('complete', 'error')
  CONTAINS_OP 0
  POP_JUMP_IF_FALSE L1
  LOAD_GLOBAL cache
  LOAD_ATTR NULL|self + delete
  LOAD_FAST status_key
  CALL 1
  POP_TOP
L1:
  LOAD_FAST status
  RETURN_VALUE
END

def get_status(self, instance):
    """pass"""
    status_key, status = self._get_status(instance)
    if status['state'] in ['complete', 'error']:
        cache.delete(status_key)
    return status


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code set_status>
  MAKE_FUNCTION 0
  STORE_NAME set_status
  RETURN_CONST None
END
CODE set_status(self, instance, status)
  DOC 'pass'
  RESUME 0
  LOAD_FAST self
  LOAD_ATTR NULL|self + get_status_key
  LOAD_FAST instance
  CALL 1
  STORE_FAST status_key
  LOAD_GLOBAL cache
  LOAD_ATTR NULL|self + set
  LOAD_FAST status_key
  LOAD_FAST status
  LOAD_CONST 300
  KW_NAMES ('timeout',)
  CALL 3
  POP_TOP
  RETURN_CONST None
END

def set_status(self, instance, status):
    """pass"""
    status_key = self.get_status_key(instance)
    cache.set(status_key, status, timeout=300)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST (None,)
  LOAD_CONST <code get_mode>
  MAKE_FUNCTION defaults
  STORE_NAME get_mode
  RETURN_CONST None
END
CODE get_mode(self, old_mode)
  DOC 'pass'
  RESUME 0
  LOAD_FAST self
  LOAD_ATTR mode
  POP_JUMP_IF_NONE L1
  LOAD_FAST self
  LOAD_ATTR mode
  RETURN_VALUE
L1:
  LOAD_FAST self
  LOAD_ATTR can_write
  POP_JUMP_IF_TRUE L2
  LOAD_ASSERTION_ERROR
  LOAD_CONST 'This format does not have a supported output mode.'
  CALL 0
  RAISE_VARARGS 1
L2:
  LOAD_FAST old_mode
  POP_JUMP_IF_NOT_NONE L3
  LOAD_FAST self
  LOAD_ATTR output_modes
  LOAD_CONST 0
  BINARY_SUBSCR
  RETURN_VALUE
L3:
  LOAD_FAST old_mode
  LOAD_FAST self
  LOAD_ATTR output_modes
  CONTAINS_OP 0
  POP_JUMP_IF_FALSE L4
  LOAD_FAST old_mode
  RETURN_VALUE
L4:
  NOP
L5:
  LOAD_GLOBAL PILLOW_MODES
  LOAD_ATTR NULL|self + index
  LOAD_FAST old_mode
  CALL 1
  STORE_FAST idx
L6:
  LOAD_GLOBAL PILLOW_MODES
  LOAD_FAST idx
  LOAD_CONST 1
  BINARY_OP +
  LOAD_CONST None
  BINARY_SLICE
  GET_ITER
L7:
  FOR_ITER L9
  STORE_FAST mode
  LOAD_FAST mode
  LOAD_FAST self
  LOAD_ATTR output_modes
  CONTAINS_OP 0
  POP_JUMP_IF_TRUE L8
  JUMP_BACKWARD L7
L8:
  LOAD_FAST mode
  SWAP 2
  POP_TOP
  RETURN_VALUE
L9:
  END_FOR
  LOAD_GLOBAL PILLOW_MODES
  LOAD_CONST None
  LOAD_FAST idx
  BINARY_SLICE
  STORE_FAST opposite
  LOAD_FAST opposite
  LOAD_ATTR NULL|self + reverse
  CALL 0
  POP_TOP
  LOAD_FAST opposite
  GET_ITER
L10:
  FOR_ITER L12
  STORE_FAST mode
  LOAD_FAST mode
  LOAD_FAST self
  LOAD_ATTR output_modes
  CONTAINS_OP 0
  POP_JUMP_IF_TRUE L11
  JUMP_BACKWARD L10
L11:
  LOAD_FAST mode
  SWAP 2
  POP_TOP
  RETURN_VALUE
L12:
  END_FOR
  RETURN_CONST None
L13:
  PUSH_EXC_INFO
  LOAD_GLOBAL ValueError
  CHECK_EXC_MATCH
  POP_JUMP_IF_FALSE L15
  POP_TOP
  LOAD_FAST self
  LOAD_ATTR output_modes
  LOAD_CONST 0
  BINARY_SUBSCR
  SWAP 2
L14:
  POP_EXCEPT
  RETURN_VALUE
L15:
  RERAISE 0
L16:
  COPY 3
  POP_EXCEPT
  RERAISE 1
  EXC try=L5..L6 -> handler=L13 depth=0 lasti=False
  EXC try=L13..L14 -> handler=L16 depth=1 lasti=True
  EXC try=L15..L16 -> handler=L16 depth=1 lasti=True
END

def get_mode(self, old_mode=None):
    """pass"""
    if self.mode is not None:
        return self.mode
    assert self.can_write, 'This format does not have a supported output mode.'
    if old_mode is None:
        return self.output_modes[0]
    if old_mode in self.output_modes:
        return old_mode
    try:
        idx = PILLOW_MODES.index(old_mode)
    except ValueError:
        return self.output_modes[0]
    for mode in PILLOW_MODES[idx + 1:]:
        if mode in self.output_modes:
            return mode
    opposite = PILLOW_MODES[:idx]
    opposite.reverse()
    for mode in opposite:
        if mode in self.output_modes:
            return mode


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST (0,)
  LOAD_CONST <code token_at_cursor>
  MAKE_FUNCTION defaults
  STORE_NAME token_at_cursor
  RETURN_CONST None
END
CODE token_at_cursor(code, pos)
  DOC 'pass'
  RESUME 0
  LOAD_GLOBAL NULL + len
  LOAD_FAST code
  CALL 1
  STORE_FAST l
  LOAD_FAST pos
  COPY 1
  STORE_FAST end
  STORE_FAST start
  LOAD_FAST end
  LOAD_FAST l
  COMPARE_OP <
  POP_JUMP_IF_FALSE L2
  LOAD_FAST code
  LOAD_FAST end
  BINARY_SUBSCR
  LOAD_ATTR NULL|self + isalpha
  CALL 0
  POP_JUMP_IF_FALSE L2
L1:
  LOAD_FAST end
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST end
  LOAD_FAST end
  LOAD_FAST l
  COMPARE_OP <
  POP_JUMP_IF_FALSE L2
  LOAD_FAST code
  LOAD_FAST end
  BINARY_SUBSCR
  LOAD_ATTR NULL|self + isalpha
  CALL 0
  POP_JUMP_IF_FALSE L2
  JUMP_BACKWARD L1
L2:
  LOAD_FAST start
  LOAD_CONST 0
  COMPARE_OP >
  POP_JUMP_IF_FALSE L4
  LOAD_FAST code
  LOAD_FAST start
  LOAD_CONST 1
  BINARY_OP -
  BINARY_SUBSCR
  LOAD_ATTR NULL|self + isalpha
  CALL 0
  POP_JUMP_IF_FALSE L4
L3:
  LOAD_FAST start
  LOAD_CONST 1
  BINARY_OP -=
  STORE_FAST start
  LOAD_FAST start
  LOAD_CONST 0
  COMPARE_OP >
  POP_JUMP_IF_FALSE L4
  LOAD_FAST code
  LOAD_FAST start
  LOAD_CONST 1
  BINARY_OP -
  BINARY_SUBSCR
  LOAD_ATTR NULL|self + isalpha
  CALL 0
  POP_JUMP_IF_FALSE L4
  JUMP_BACKWARD L3
L4:
  LOAD_FAST start
  LOAD_CONST 0
  COMPARE_OP >
  POP_JUMP_IF_FALSE L5
  LOAD_FAST code
  LOAD_FAST start
  LOAD_CONST 1
  BINARY_OP -
  BINARY_SUBSCR
  LOAD_CONST '%'
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L5
  LOAD_FAST start
  LOAD_CONST 1
  BINARY_OP -=
  STORE_FAST start
L5:
  LOAD_FAST code
  LOAD_FAST start
  LOAD_FAST end
  BINARY_SLICE
  LOAD_FAST start
  BUILD_TUPLE 2
  RETURN_VALUE
END

def token_at_cursor(code, pos=0):
    """pass"""
    l = len(code)
    end = start = pos
    while end < l and code[end].isalpha():
        end += 1
    while start > 0 and code[start - 1].isalpha():
        start -= 1
    if start > 0 and code[start - 1] == '%':
        start -= 1
    return (code[start:end], start)


Input:
CODE <module>()
  DOC 'ok'
  RESUME 0
  LOAD_CONST ('ok', False)
  LOAD_CONST <code _send>
  MAKE_FUNCTION defaults
  STORE_NAME _send
  RETURN_CONST None
END
CODE _send(self, data, msg_type, silent)
  DOC 'pass'
  RESUME 0
  LOAD_FAST data
  POP_JUMP_IF_NONE L4
  NOP
L1:
  LOAD_FAST self
  LOAD_ATTR _klog
  LOAD_ATTR NULL|self + debug
  LOAD_CONST 'msg to frontend (%d): %.160s...'
  LOAD_FAST silent
  LOAD_FAST data
  CALL 3
  POP_TOP
L2:
  LOAD_FAST silent
  POP_JUMP_IF_TRUE L4
  LOAD_FAST msg_type
  LOAD_CONST 'raw'
  COMPARE_OP !=
  POP_JUMP_IF_FALSE L3
  LOAD_GLOBAL NULL + data_msg
  LOAD_FAST data
  LOAD_FAST msg_type
  KW_NAMES ('mtype',)
  CALL 2
  STORE_FAST data
L3:
  LOAD_FAST self
  LOAD_ATTR NULL|self + send_response
  LOAD_FAST self
  LOAD_ATTR iopub_socket
  LOAD_CONST 'display_data'
  LOAD_FAST data
  CALL 3
  POP_TOP
L4:
  LOAD_FAST msg_type
  LOAD_CONST 'error'
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L5
  LOAD_CONST 'error'
  JUMP_FORWARD L6
L5:
  LOAD_CONST 'ok'
L6:
  LOAD_FAST self
  LOAD_ATTR execution_count
  BUILD_LIST 0
  BUILD_MAP 0
  LOAD_CONST ('status', 'execution_count', 'payload', 'user_expressions')
  BUILD_CONST_KEY_MAP 4
  RETURN_VALUE
L7:
  PUSH_EXC_INFO
  LOAD_GLOBAL Exception
  CHECK_EXC_MATCH
  POP_JUMP_IF_FALSE L11
  STORE_FAST e
L8:
  LOAD_FAST self
  LOAD_ATTR _klog
  LOAD_ATTR NULL|self + warn
  LOAD_CONST "can't log response: %s"
  LOAD_FAST e
  CALL 2
  POP_TOP
L9:
  POP_EXCEPT
  LOAD_CONST None
  STORE_FAST e
  DELETE_FAST e
  JUMP_BACKWARD L2
L10:
  LOAD_CONST None
  STORE_FAST e
  DELETE_FAST e
  RERAISE 1
L11:
  RERAISE 0
L12:
  COPY 3
  POP_EXCEPT
  RERAISE 1
  EXC try=L1..L2 -> handler=L7 depth=0 lasti=False
  EXC try=L7..L8 -> handler=L12 depth=1 lasti=True
  EXC try=L8..L9 -> handler=L10 depth=1 lasti=True
  EXC try=L10..L12 -> handler=L12 depth=1 lasti=True
END

def _send(self, data, msg_type='ok', silent=False):
    """pass"""
    if data is not None:
        try:
            self._klog.debug(u'msg to frontend (%d): %.160s...', silent, data)
        except Exception as e:
            self._klog.warn(u"can't log response: %s", e)
        if not silent:
            if msg_type != 'raw':
                data = data_msg(data, mtype=msg_type)
            self.send_response(self.iopub_socket, 'display_data', data)
    return {'status': 'error' if msg_type == 'error' else 'ok', 'execution_count': self.execution_count, 'payload': [], 'user_expressions': {}}