Input:
CODE <module>()
  DOC 'classes'
  RESUME 0
  LOAD_CONST 'classes'
  LOAD_NAME Sequence
  LOAD_NAME type
  BINARY_SUBSCR
  LOAD_CONST 'return'
  LOAD_NAME Tuple
  LOAD_NAME Mapping
  LOAD_NAME type
  LOAD_NAME Sequence
  LOAD_NAME type
  BINARY_SUBSCR
  BUILD_TUPLE 2
  BINARY_SUBSCR
  LOAD_NAME Mapping
  LOAD_NAME type
  LOAD_NAME Sequence
  LOAD_NAME type
  BINARY_SUBSCR
  BUILD_TUPLE 2
  BINARY_SUBSCR
  BUILD_TUPLE 2
  BINARY_SUBSCR
  BUILD_TUPLE 4
  LOAD_CONST <code _build_mappings>
  MAKE_FUNCTION annotations
  STORE_NAME _build_mappings
  RETURN_CONST None
END
CODE _build_mappings(self, classes)
  DOC 'pass'
  RESUME 0
  BUILD_MAP 0
  STORE_FAST parents_to_children
  BUILD_MAP 0
  STORE_FAST children_to_parents
  LOAD_GLOBAL NULL + set
  CALL 0
  STORE_FAST visited_classes
  LOAD_GLOBAL NULL + list
  LOAD_FAST classes
  CALL 1
  STORE_FAST class_stack
L1:
  LOAD_FAST class_stack
  POP_JUMP_IF_FALSE L7
L2:
  LOAD_FAST class_stack
  LOAD_ATTR NULL|self + pop
  CALL 0
  STORE_FAST class_
  LOAD_FAST class_
  LOAD_FAST visited_classes
  CONTAINS_OP 0
  POP_JUMP_IF_FALSE L3
  JUMP_BACKWARD L1
L3:
  LOAD_FAST visited_classes
  LOAD_ATTR NULL|self + add
  LOAD_FAST class_
  CALL 1
  POP_TOP
  LOAD_FAST class_
  LOAD_ATTR __bases__
  GET_ITER
L4:
  FOR_ITER L6
  STORE_FAST base
  LOAD_FAST base
  LOAD_FAST visited_classes
  CONTAINS_OP 1
  POP_JUMP_IF_FALSE L5
  LOAD_FAST class_stack
  LOAD_ATTR NULL|self + append
  LOAD_FAST base
  CALL 1
  POP_TOP
L5:
  LOAD_FAST parents_to_children
  LOAD_ATTR NULL|self + setdefault
  LOAD_FAST base
  LOAD_GLOBAL NULL + set
  CALL 0
  CALL 2
  LOAD_ATTR NULL|self + add
  LOAD_FAST class_
  CALL 1
  POP_TOP
  LOAD_FAST children_to_parents
  LOAD_ATTR NULL|self + setdefault
  LOAD_FAST class_
  LOAD_GLOBAL NULL + set
  CALL 0
  CALL 2
  LOAD_ATTR NULL|self + add
  LOAD_FAST base
  CALL 1
  POP_TOP
  JUMP_BACKWARD L4
L6:
  END_FOR
  LOAD_FAST class_stack
  POP_JUMP_IF_FALSE L7
  JUMP_BACKWARD L2
L7:
  LOAD_GLOBAL collections
  LOAD_ATTR NULL|self + OrderedDict
  CALL 0
  STORE_FAST sorted_parents_to_children
  LOAD_GLOBAL NULL + sorted
  LOAD_FAST parents_to_children
  LOAD_ATTR NULL|self + items
  CALL 0
  LOAD_CONST <code _build_mappings.<locals>.<lambda>>
  MAKE_FUNCTION 0
  KW_NAMES ('key',)
  CALL 2
  GET_ITER
L8:
  FOR_ITER L9
  UNPACK_SEQUENCE 2
  STORE_FAST parent
  STORE_FAST children
  LOAD_GLOBAL NULL + sorted
  LOAD_FAST children
  LOAD_CONST <code _build_mappings.<locals>.<lambda>>
  MAKE_FUNCTION 0
  KW_NAMES ('key',)
  CALL 2
  LOAD_FAST sorted_parents_to_children
  LOAD_FAST parent
  STORE_SUBSCR
  JUMP_BACKWARD L8
L9:
  END_FOR
  LOAD_GLOBAL collections
  LOAD_ATTR NULL|self + OrderedDict
  CALL 0
  STORE_FAST sorted_children_to_parents
  LOAD_GLOBAL NULL + sorted
  LOAD_FAST children_to_parents
  LOAD_ATTR NULL|self + items
  CALL 0
  LOAD_CONST <code _build_mappings.<locals>.<lambda>>
  MAKE_FUNCTION 0
  KW_NAMES ('key',)
  CALL 2
  GET_ITER
L10:
  FOR_ITER L11
  UNPACK_SEQUENCE 2
  STORE_FAST child
  STORE_FAST parents
  LOAD_GLOBAL NULL + sorted
  LOAD_FAST parents
  LOAD_CONST <code _build_mappings.<locals>.<lambda>>
  MAKE_FUNCTION 0
  KW_NAMES ('key',)
  CALL 2
  LOAD_FAST sorted_children_to_parents
  LOAD_FAST child
  STORE_SUBSCR
  JUMP_BACKWARD L10
L11:
  END_FOR
  LOAD_FAST sorted_parents_to_children
  LOAD_FAST sorted_children_to_parents
  BUILD_TUPLE 2
  RETURN_VALUE
END
CODE _build_mappings.<locals>.<lambda>(x)
  RESUME 0
  LOAD_FAST x
  LOAD_CONST 0
  BINARY_SUBSCR
  LOAD_ATTR __module__
  LOAD_FAST x
  LOAD_CONST 0
  BINARY_SUBSCR
  LOAD_ATTR __name__
  BUILD_TUPLE 2
  RETURN_VALUE
END
CODE _build_mappings.<locals>.<lambda>(x)
  RESUME 0
  LOAD_FAST x
  LOAD_ATTR __module__
  LOAD_FAST x
  LOAD_ATTR __name__
  BUILD_TUPLE 2
  RETURN_VALUE
END
CODE _build_mappings.<locals>.<lambda>(x)
  RESUME 0
  LOAD_FAST x
  LOAD_CONST 0
  BINARY_SUBSCR
  LOAD_ATTR __module__
  LOAD_FAST x
  LOAD_CONST 0
  BINARY_SUBSCR
  LOAD_ATTR __name__
  BUILD_TUPLE 2
  RETURN_VALUE
END
CODE _build_mappings.<locals>.<lambda>(x)
  RESUME 0
  LOAD_FAST x
  LOAD_ATTR __module__
  LOAD_FAST x
  LOAD_ATTR __name__
  BUILD_TUPLE 2
  RETURN_VALUE
END

def _build_mappings(self, classes: Sequence[type]) -> Tuple[Mapping[type, Sequence[type]], Mapping[type, Sequence[type]]]:
    """pass"""
    parents_to_children: MutableMapping[type, Set[type]] = {}
    children_to_parents: MutableMapping[type, Set[type]] = {}
    visited_classes: Set[type] = set()
    class_stack = list(classes)
    while class_stack:
        class_ = class_stack.pop()
        if class_ in visited_classes:
            continue
        visited_classes.add(class_)
        for base in class_.__bases__:
            if base not in visited_classes:
                class_stack.append(base)
            parents_to_children.setdefault(base, set()).add(class_)
            children_to_parents.setdefault(class_, set()).add(base)
    sorted_parents_to_children: MutableMapping[type, List[type]] = collections.OrderedDict()
    for parent, children in sorted(parents_to_children.items(), key=lambda x: (x[0].__module__, x[0].__name__)):
        sorted_parents_to_children[parent] = sorted(children, key=lambda x: (x.__module__, x.__name__))
    sorted_children_to_parents: MutableMapping[type, List[type]] = collections.OrderedDict()
    for child, parents in sorted(children_to_parents.items(), key=lambda x: (x[0].__module__, x[0].__name__)):
        sorted_children_to_parents[child] = sorted(parents, key=lambda x: (x.__module__, x.__name__))
    return (sorted_parents_to_children, sorted_children_to_parents)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST (True,)
  LOAD_CONST 'package_paths'
  LOAD_NAME Sequence
  LOAD_NAME str
  BINARY_SUBSCR
  LOAD_CONST 'recurse_subpackages'
  LOAD_NAME bool
  LOAD_CONST 'return'
  LOAD_NAME Sequence
  LOAD_NAME type
  BINARY_SUBSCR
  BUILD_TUPLE 6
  LOAD_CONST <code _collect_classes>
  MAKE_FUNCTION defaults, annotations
  STORE_NAME _collect_classes
  RETURN_CONST None
END
CODE _collect_classes(self, package_paths, recurse_subpackages)
  DOC 'pass'
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME uqbar.apis
  STORE_FAST uqbar
  BUILD_LIST 0
  STORE_FAST classes
  LOAD_GLOBAL NULL + set
  CALL 0
  STORE_FAST initial_source_paths
  LOAD_FAST package_paths
  GET_ITER
L1:
  FOR_ITER L5
  STORE_FAST path
  NOP
L2:
  LOAD_GLOBAL importlib
  LOAD_ATTR NULL|self + import_module
  LOAD_FAST path
  CALL 1
  STORE_FAST module
  LOAD_GLOBAL NULL + hasattr
  LOAD_FAST module
  LOAD_CONST '__path__'
  CALL 2
  POP_JUMP_IF_FALSE L3
  LOAD_FAST initial_source_paths
  LOAD_ATTR NULL|self + update
  LOAD_GLOBAL NULL + getattr
  LOAD_FAST module
  LOAD_CONST '__path__'
  CALL 2
  CALL 1
  POP_TOP
  JUMP_FORWARD L4
L3:
  LOAD_FAST initial_source_paths
  LOAD_ATTR NULL|self + add
  LOAD_FAST module
  LOAD_ATTR __file__
  CALL 1
  POP_TOP
L4:
  JUMP_BACKWARD L1
L5:
  END_FOR
  LOAD_FAST uqbar
  LOAD_ATTR apis
  LOAD_ATTR NULL|self + collect_source_paths
  LOAD_FAST initial_source_paths
  LOAD_FAST recurse_subpackages
  KW_NAMES ('recurse_subpackages',)
  CALL 2
  GET_ITER
L6:
  FOR_ITER L12
  STORE_FAST source_path
  LOAD_FAST uqbar
  LOAD_ATTR apis
  LOAD_ATTR NULL|self + source_path_to_package_path
  LOAD_FAST source_path
  CALL 1
  STORE_FAST package_path
  LOAD_GLOBAL importlib
  LOAD_ATTR NULL|self + import_module
  LOAD_FAST package_path
  CALL 1
  STORE_FAST module
  LOAD_GLOBAL NULL + dir
  LOAD_FAST module
  CALL 1
  GET_ITER
L7:
  FOR_ITER L11
  STORE_FAST name
  LOAD_FAST name
  LOAD_ATTR NULL|self + startswith
  LOAD_CONST '_'
  CALL 1
  POP_JUMP_IF_FALSE L8
  JUMP_BACKWARD L7
L8:
  LOAD_GLOBAL NULL + getattr
  LOAD_FAST module
  LOAD_FAST name
  CALL 2
  STORE_FAST object_
  LOAD_GLOBAL NULL + isinstance
  LOAD_FAST object_
  LOAD_GLOBAL type
  CALL 2
  POP_JUMP_IF_TRUE L9
  JUMP_BACKWARD L7
L9:
  LOAD_FAST object_
  LOAD_ATTR __module__
  LOAD_FAST module
  LOAD_ATTR __name__
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L10
  JUMP_BACKWARD L7
L10:
  LOAD_FAST classes
  LOAD_ATTR NULL|self + append
  LOAD_FAST object_
  CALL 1
  POP_TOP
  JUMP_BACKWARD L7
L11:
  END_FOR
  JUMP_BACKWARD L6
L12:
  END_FOR
  LOAD_GLOBAL NULL + sorted
  LOAD_FAST classes
  LOAD_CONST <code _collect_classes.<locals>.<lambda>>
  MAKE_FUNCTION 0
  KW_NAMES ('key',)
  CALL 2
  RETURN_VALUE
L13:
  PUSH_EXC_INFO
  LOAD_GLOBAL ModuleNotFoundError
  CHECK_EXC_MATCH
  POP_JUMP_IF_FALSE L15
  POP_TOP
  LOAD_FAST path
  LOAD_ATTR NULL|self + rpartition
  LOAD_CONST '.'
  CALL 1
  UNPACK_SEQUENCE 3
  STORE_FAST path
  STORE_FAST _
  STORE_FAST class_name
  LOAD_GLOBAL importlib
  LOAD_ATTR NULL|self + import_module
  LOAD_FAST path
  CALL 1
  STORE_FAST module
  LOAD_FAST classes
  LOAD_ATTR NULL|self + append
  LOAD_GLOBAL NULL + getattr
  LOAD_FAST module
  LOAD_FAST class_name
  CALL 2
  CALL 1
  POP_TOP
L14:
  POP_EXCEPT
  EXTENDED_ARG 1
  JUMP_BACKWARD L1
L15:
  RERAISE 0
L16:
  COPY 3
  POP_EXCEPT
  RERAISE 1
  EXC try=L2..L4 -> handler=L13 depth=1 lasti=False
  EXC try=L13..L14 -> handler=L16 depth=2 lasti=True
  EXC try=L15..L16 -> handler=L16 depth=2 lasti=True
END
CODE _collect_classes.<locals>.<lambda>(x)
  RESUME 0
  LOAD_FAST x
  LOAD_ATTR __module__
  LOAD_FAST x
  LOAD_ATTR __name__
  BUILD_TUPLE 2
  RETURN_VALUE
END

def _collect_classes(self, package_paths: Sequence[str], recurse_subpackages: bool=True) -> Sequence[type]:
    """pass"""
    import uqbar.apis
    classes = []
    initial_source_paths: Set[str] = set()
    for path in package_paths:
        try:
            module = importlib.import_module(path)
            if hasattr(module, '__path__'):
                initial_source_paths.update(getattr(module, '__path__'))
            else:
                initial_source_paths.add(module.__file__)
        except ModuleNotFoundError:
            path, _, class_name = path.rpartition('.')
            module = importlib.import_module(path)
            classes.append(getattr(module, class_name))
    for source_path in uqbar.apis.collect_source_paths(initial_source_paths, recurse_subpackages=recurse_subpackages):
        package_path = uqbar.apis.source_path_to_package_path(source_path)
        module = importlib.import_module(package_path)
        for name in dir(module):
            if name.startswith('_'):
                continue
            object_ = getattr(module, name)
            if isinstance(object_, type) and object_.__module__ == module.__name__:
                classes.append(object_)
    return sorted(classes, key=lambda x: (x.__module__, x.__name__))

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


Input:
CODE <module>()
  DOC 'paths'
  RESUME 0
  LOAD_CONST 'paths'
  LOAD_NAME Sequence
  LOAD_NAME Union
  LOAD_NAME str
  LOAD_NAME pathlib
  LOAD_ATTR Path
  BUILD_TUPLE 2
  BINARY_SUBSCR
  BINARY_SUBSCR
  LOAD_CONST 'return'
  LOAD_NAME Optional
  LOAD_NAME pathlib
  LOAD_ATTR Path
  BINARY_SUBSCR
  BUILD_TUPLE 4
  LOAD_CONST <code find_common_prefix>
  MAKE_FUNCTION annotations
  STORE_NAME find_common_prefix
  RETURN_CONST None
END
CODE find_common_prefix(paths)
  DOC 'pass'
  RESUME 0
  LOAD_GLOBAL collections
  LOAD_ATTR NULL|self + Counter
  CALL 0
  STORE_FAST counter
  LOAD_FAST paths
  GET_ITER
L1:
  FOR_ITER L2
  STORE_FAST path
  LOAD_GLOBAL pathlib
  LOAD_ATTR NULL|self + Path
  LOAD_FAST path
  CALL 1
  STORE_FAST path
  LOAD_FAST counter
  LOAD_ATTR NULL|self + update
  LOAD_FAST path
  BUILD_LIST 1
  CALL 1
  POP_TOP
  LOAD_FAST counter
  LOAD_ATTR NULL|self + update
  LOAD_FAST path
  LOAD_ATTR parents
  CALL 1
  POP_TOP
  JUMP_BACKWARD L1
L2:
  END_FOR
  LOAD_GLOBAL NULL + sorted
  LOAD_FAST counter
  LOAD_ATTR NULL|self + items
  CALL 0
  GET_ITER
  LOAD_FAST_AND_CLEAR path
  LOAD_FAST_AND_CLEAR count
  SWAP 3
L3:
  BUILD_LIST 0
  SWAP 2
L4:
  FOR_ITER L7
  UNPACK_SEQUENCE 2
  STORE_FAST path
  STORE_FAST count
  LOAD_FAST count
  LOAD_GLOBAL NULL + len
  LOAD_FAST paths
  CALL 1
  COMPARE_OP >=
  POP_JUMP_IF_TRUE L6
L5:
  JUMP_BACKWARD L4
L6:
  LOAD_FAST path
  LIST_APPEND 2
  JUMP_BACKWARD L4
L7:
  END_FOR
L8:
  SWAP 3
  STORE_FAST count
  STORE_FAST path
  LOAD_CONST <code find_common_prefix.<locals>.<lambda>>
  MAKE_FUNCTION 0
  KW_NAMES ('key',)
  CALL 2
  STORE_FAST valid_paths
  LOAD_FAST valid_paths
  POP_JUMP_IF_FALSE L9
  LOAD_FAST valid_paths
  LOAD_CONST -1
  BINARY_SUBSCR
  RETURN_VALUE
L9:
  RETURN_CONST None
L10:
  SWAP 2
  POP_TOP
  SWAP 3
  STORE_FAST count
  STORE_FAST path
  RERAISE 0
  EXC try=L3..L5 -> handler=L10 depth=5 lasti=False
  EXC try=L6..L8 -> handler=L10 depth=5 lasti=False
END
CODE find_common_prefix.<locals>.<lambda>(x)
  RESUME 0
  LOAD_GLOBAL NULL + len
  LOAD_FAST x
  LOAD_ATTR parts
  CALL 1
  RETURN_VALUE
END

def find_common_prefix(paths: Sequence[Union[str, pathlib.Path]]) -> Optional[pathlib.Path]:
    """pass"""
    counter: collections.Counter = collections.Counter()
    for path in paths:
        path = pathlib.Path(path)
        counter.update([path])
        counter.update(path.parents)
    valid_paths = sorted([path for path, count in counter.items() if count >= len(paths)], key=lambda x: len(x.parts))
    if valid_paths:
        return valid_paths[-1]
    return None


Input:
CODE <module>()
  DOC 'name'
  RESUME 0
  LOAD_NAME os
  LOAD_ATTR X_OK
  BUILD_TUPLE 1
  LOAD_CONST 'name'
  LOAD_NAME str
  LOAD_CONST 'return'
  LOAD_NAME List
  LOAD_NAME str
  BINARY_SUBSCR
  BUILD_TUPLE 4
  LOAD_CONST <code find_executable>
  MAKE_FUNCTION defaults, annotations
  STORE_NAME find_executable
  RETURN_CONST None
END
CODE find_executable(name, flags)
  DOC 'pass'
  RESUME 0
  BUILD_LIST 0
  STORE_FAST result
  LOAD_GLOBAL os
  LOAD_ATTR environ
  LOAD_ATTR NULL|self + get
  LOAD_CONST 'PATHEXT'
  LOAD_CONST ''
  CALL 2
  LOAD_ATTR NULL|self + split
  LOAD_GLOBAL os
  LOAD_ATTR pathsep
  CALL 1
  GET_ITER
  LOAD_FAST_AND_CLEAR x
  SWAP 2
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L5
  STORE_FAST x
  LOAD_FAST x
  POP_JUMP_IF_TRUE L4
L3:
  JUMP_BACKWARD L2
L4:
  LOAD_FAST x
  LIST_APPEND 2
  JUMP_BACKWARD L2
L5:
  END_FOR
L6:
  STORE_FAST extensions
  STORE_FAST x
  LOAD_GLOBAL os
  LOAD_ATTR environ
  LOAD_ATTR NULL|self + get
  LOAD_CONST 'PATH'
  LOAD_CONST None
  CALL 2
  STORE_FAST path
  LOAD_FAST path
  POP_JUMP_IF_NOT_NONE L7
  BUILD_LIST 0
  RETURN_VALUE
L7:
  LOAD_GLOBAL os
  LOAD_ATTR environ
  LOAD_ATTR NULL|self + get
  LOAD_CONST 'PATH'
  LOAD_CONST ''
  CALL 2
  LOAD_ATTR NULL|self + split
  LOAD_GLOBAL os
  LOAD_ATTR pathsep
  CALL 1
  GET_ITER
L8:
  FOR_ITER L13
  STORE_FAST path
  LOAD_GLOBAL os
  LOAD_ATTR path
  LOAD_ATTR NULL|self + join
  LOAD_FAST path
  LOAD_FAST name
  CALL 2
  STORE_FAST path
  LOAD_GLOBAL os
  LOAD_ATTR NULL|self + access
  LOAD_FAST path
  LOAD_FAST flags
  CALL 2
  POP_JUMP_IF_FALSE L9
  LOAD_FAST result
  LOAD_ATTR NULL|self + append
  LOAD_FAST path
  CALL 1
  POP_TOP
L9:
  LOAD_FAST extensions
  GET_ITER
L10:
  FOR_ITER L12
  STORE_FAST extension
  LOAD_FAST path
  LOAD_FAST extension
  BINARY_OP +
  STORE_FAST path_extension
  LOAD_GLOBAL os
  LOAD_ATTR NULL|self + access
  LOAD_FAST path_extension
  LOAD_FAST flags
  CALL 2
  POP_JUMP_IF_TRUE L11
  JUMP_BACKWARD L10
L11:
  LOAD_FAST result
  LOAD_ATTR NULL|self + append
  LOAD_FAST path_extension
  CALL 1
  POP_TOP
  JUMP_BACKWARD L10
L12:
  END_FOR
  JUMP_BACKWARD L8
L13:
  END_FOR
  LOAD_FAST result
  RETURN_VALUE
L14:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST x
  RERAISE 0
  EXC try=L1..L3 -> handler=L14 depth=2 lasti=False
  EXC try=L4..L6 -> handler=L14 depth=2 lasti=False
END

def find_executable(name: str, flags=os.X_OK) -> List[str]:
    """pass"""
    result = []
    extensions = [x for x in os.environ.get('PATHEXT', '').split(os.pathsep) if x]
    path = os.environ.get('PATH', None)
    if path is None:
        return []
    for path in os.environ.get('PATH', '').split(os.pathsep):
        path = os.path.join(path, name)
        if os.access(path, flags):
            result.append(path)
        for extension in extensions:
            path_extension = path + extension
            if os.access(path_extension, flags):
                result.append(path_extension)
    return result


Input:
CODE <module>()
  DOC 'source_path'
  RESUME 0
  LOAD_CONST 'source_path'
  LOAD_NAME Union
  LOAD_NAME str
  LOAD_NAME pathlib
  LOAD_ATTR Path
  BUILD_TUPLE 2
  BINARY_SUBSCR
  LOAD_CONST 'target_path'
  LOAD_NAME Union
  LOAD_NAME str
  LOAD_NAME pathlib
  LOAD_ATTR Path
  BUILD_TUPLE 2
  BINARY_SUBSCR
  LOAD_CONST 'return'
  LOAD_NAME pathlib
  LOAD_ATTR Path
  BUILD_TUPLE 6
  LOAD_CONST <code relative_to>
  MAKE_FUNCTION annotations
  STORE_NAME relative_to
  RETURN_CONST None
END
CODE relative_to(source_path, target_path)
  DOC 'pass'
  RESUME 0
  LOAD_GLOBAL pathlib
  LOAD_ATTR NULL|self + Path
  LOAD_FAST source_path
  CALL 1
  LOAD_ATTR NULL|self + absolute
  CALL 0
  STORE_FAST source_path
  LOAD_FAST source_path
  LOAD_ATTR NULL|self + is_file
  CALL 0
  POP_JUMP_IF_FALSE L1
  LOAD_FAST source_path
  LOAD_ATTR parent
  STORE_FAST source_path
L1:
  LOAD_GLOBAL pathlib
  LOAD_ATTR NULL|self + Path
  LOAD_FAST target_path
  CALL 1
  LOAD_ATTR NULL|self + absolute
  CALL 0
  STORE_FAST target_path
  LOAD_GLOBAL NULL + find_common_prefix
  LOAD_FAST source_path
  LOAD_FAST target_path
  BUILD_LIST 2
  CALL 1
  STORE_FAST common_prefix
  LOAD_FAST common_prefix
  POP_JUMP_IF_TRUE L2
  LOAD_GLOBAL NULL + ValueError
  LOAD_CONST 'No common prefix'
  CALL 1
  RAISE_VARARGS 1
L2:
  LOAD_FAST source_path
  LOAD_ATTR NULL|self + relative_to
  LOAD_FAST common_prefix
  CALL 1
  STORE_FAST source_path
  LOAD_FAST target_path
  LOAD_ATTR NULL|self + relative_to
  LOAD_FAST common_prefix
  CALL 1
  STORE_FAST target_path
  LOAD_GLOBAL NULL + pathlib
  LOAD_ATTR Path
  LOAD_CONST '..'
  BUILD_LIST 1
  LOAD_GLOBAL NULL + len
  LOAD_FAST source_path
  LOAD_ATTR parts
  CALL 1
  BINARY_OP *
  CALL_FUNCTION_EX 0
  STORE_FAST result
  LOAD_FAST result
  LOAD_FAST target_path
  BINARY_OP /
  RETURN_VALUE
END

def relative_to(source_path: Union[str, pathlib.Path], target_path: Union[str, pathlib.Path]) -> pathlib.Path:
    """pass"""
    source_path = pathlib.Path(source_path).absolute()
    if source_path.is_file():
        source_path = source_path.parent
    target_path = pathlib.Path(target_path).absolute()
    common_prefix = find_common_prefix([source_path, target_path])
    if not common_prefix:
        raise ValueError('No common prefix')
    source_path = source_path.relative_to(common_prefix)
    target_path = target_path.relative_to(common_prefix)
    result = pathlib.Path(*['..'] * len(source_path.parts))
    return result / target_path


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST (True,)
  LOAD_CONST 'root_path'
  LOAD_NAME Union
  LOAD_NAME str
  LOAD_NAME pathlib
  LOAD_ATTR Path
  BUILD_TUPLE 2
  BINARY_SUBSCR
  LOAD_CONST 'top_down'
  LOAD_NAME bool
  LOAD_CONST 'return'
  LOAD_NAME Generator
  LOAD_NAME Tuple
  LOAD_NAME pathlib
  LOAD_ATTR Path
  LOAD_NAME Sequence
  LOAD_NAME pathlib
  LOAD_ATTR Path
  BINARY_SUBSCR
  LOAD_NAME Sequence
  LOAD_NAME pathlib
  LOAD_ATTR Path
  BINARY_SUBSCR
  BUILD_TUPLE 3
  BINARY_SUBSCR
  LOAD_CONST None
  LOAD_CONST None
  BUILD_TUPLE 3
  BINARY_SUBSCR
  BUILD_TUPLE 6
  LOAD_CONST <code walk>
  MAKE_FUNCTION defaults, annotations
  STORE_NAME walk
  RETURN_CONST None
END
CODE walk(root_path, top_down)
  DOC 'pass'
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_GLOBAL pathlib
  LOAD_ATTR NULL|self + Path
  LOAD_FAST root_path
  CALL 1
  STORE_FAST root_path
  BUILD_LIST 0
  BUILD_LIST 0
  STORE_FAST file_paths
  STORE_FAST directory_paths
  LOAD_GLOBAL NULL + sorted
  LOAD_FAST root_path
  LOAD_ATTR NULL|self + iterdir
  CALL 0
  CALL 1
  GET_ITER
L2:
  FOR_ITER L4
  STORE_FAST path
  LOAD_FAST path
  LOAD_ATTR NULL|self + is_dir
  CALL 0
  POP_JUMP_IF_FALSE L3
  LOAD_FAST directory_paths
  LOAD_ATTR NULL|self + append
  LOAD_FAST path
  CALL 1
  POP_TOP
  JUMP_BACKWARD L2
L3:
  LOAD_FAST file_paths
  LOAD_ATTR NULL|self + append
  LOAD_FAST path
  CALL 1
  POP_TOP
  JUMP_BACKWARD L2
L4:
  END_FOR
  LOAD_FAST top_down
  POP_JUMP_IF_FALSE L5
  LOAD_FAST root_path
  LOAD_FAST directory_paths
  LOAD_FAST file_paths
  BUILD_TUPLE 3
  YIELD_VALUE 1
  RESUME 1
  POP_TOP
L5:
  LOAD_FAST directory_paths
  GET_ITER
L6:
  FOR_ITER L11
  STORE_FAST directory_path
  LOAD_GLOBAL NULL + walk
  LOAD_FAST directory_path
  LOAD_FAST top_down
  KW_NAMES ('top_down',)
  CALL 2
  GET_YIELD_FROM_ITER
  LOAD_CONST None
L7:
  SEND L10
L8:
  YIELD_VALUE 2
L9:
  RESUME 2
  JUMP_BACKWARD_NO_INTERRUPT L7
L10:
  END_SEND
  POP_TOP
  JUMP_BACKWARD L6
L11:
  END_FOR
  LOAD_FAST top_down
  POP_JUMP_IF_TRUE L12
  LOAD_FAST root_path
  LOAD_FAST directory_paths
  LOAD_FAST file_paths
  BUILD_TUPLE 3
  YIELD_VALUE 1
  RESUME 1
  POP_TOP
  RETURN_CONST None
L12:
  RETURN_CONST None
L13:
  CLEANUP_THROW
L14:
  JUMP_BACKWARD L10
L15:
  CALL_INTRINSIC_1 INTRINSIC_STOPITERATION_ERROR
  RERAISE 1
  EXC try=L1..L8 -> handler=L15 depth=0 lasti=True
  EXC try=L8..L9 -> handler=L13 depth=3 lasti=False
  EXC try=L9..L14 -> handler=L15 depth=0 lasti=True
END

def walk(root_path: Union[str, pathlib.Path], top_down: bool=True) -> Generator[Tuple[pathlib.Path, Sequence[pathlib.Path], Sequence[pathlib.Path]], None, None]:
    """pass"""
    root_path = pathlib.Path(root_path)
    directory_paths, file_paths = ([], [])
    for path in sorted(root_path.iterdir()):
        if path.is_dir():
            directory_paths.append(path)
        else:
            file_paths.append(path)
    if top_down:
        yield (root_path, directory_paths, file_paths)
    for directory_path in directory_paths:
        yield from walk(directory_path, top_down=top_down)
    if not top_down:
        yield (root_path, directory_paths, file_paths)


Input:
CODE <module>()
  DOC 'return'
  RESUME 0
  LOAD_CONST 'return'
  LOAD_NAME Generator
  LOAD_NAME Tuple
  LOAD_NAME int
  LOAD_NAME int
  LOAD_NAME str
  LOAD_NAME type
  BUILD_TUPLE 4
  BINARY_SUBSCR
  LOAD_CONST None
  LOAD_CONST None
  BUILD_TUPLE 3
  BINARY_SUBSCR
  BUILD_TUPLE 2
  LOAD_CONST <code run>
  MAKE_FUNCTION annotations
  STORE_NAME run
  RETURN_CONST None
END
CODE run(self)
  DOC 'pass'
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_GLOBAL NULL + is_test_file
  LOAD_FAST self
  LOAD_ATTR filename
  CALL 1
  POP_JUMP_IF_FALSE L9
  LOAD_FAST self
  LOAD_ATTR NULL|self + load
  CALL 0
  POP_TOP
  LOAD_FAST self
  LOAD_ATTR NULL|self + all_funcs
  CALL 0
  GET_ITER
L2:
  FOR_ITER L8
  STORE_FAST func
L3:
  NOP
L4:
  LOAD_FAST func
  LOAD_ATTR NULL|self + check_all
  CALL 0
  GET_ITER
L5:
  FOR_ITER L6
  STORE_FAST error
  LOAD_FAST error
  LOAD_ATTR line_number
  LOAD_FAST error
  LOAD_ATTR offset
  LOAD_FAST error
  LOAD_ATTR text
  LOAD_GLOBAL Checker
  BUILD_TUPLE 4
  YIELD_VALUE 2
  RESUME 1
  POP_TOP
  JUMP_BACKWARD L5
L6:
  END_FOR
L7:
  JUMP_BACKWARD L2
L8:
  END_FOR
  RETURN_CONST None
L9:
  RETURN_CONST None
L10:
  PUSH_EXC_INFO
  LOAD_GLOBAL ValidationError
  CHECK_EXC_MATCH
  POP_JUMP_IF_FALSE L14
  STORE_FAST error
L11:
  LOAD_FAST error
  LOAD_ATTR NULL|self + to_flake8
  LOAD_GLOBAL Checker
  CALL 1
  YIELD_VALUE 3
  RESUME 1
  POP_TOP
L12:
  POP_EXCEPT
  LOAD_CONST None
  STORE_FAST error
  DELETE_FAST error
  JUMP_BACKWARD L2
L13:
  LOAD_CONST None
  STORE_FAST error
  DELETE_FAST error
  RERAISE 1
L14:
  RERAISE 0
L15:
  COPY 3
  POP_EXCEPT
  RERAISE 1
L16:
  CALL_INTRINSIC_1 INTRINSIC_STOPITERATION_ERROR
  RERAISE 1
  EXC try=L1..L3 -> handler=L16 depth=0 lasti=True
  EXC try=L4..L7 -> handler=L10 depth=1 lasti=False
  EXC try=L7..L10 -> handler=L16 depth=0 lasti=True
  EXC try=L10..L11 -> handler=L15 depth=2 lasti=True
  EXC try=L11..L12 -> handler=L13 depth=2 lasti=True
  EXC try=L12..L13 -> handler=L16 depth=0 lasti=True
  EXC try=L13..L15 -> handler=L15 depth=2 lasti=True
  EXC try=L15..L16 -> handler=L16 depth=0 lasti=True
END

def run(self) -> Generator[Tuple[int, int, str, type], None, None]:
    """pass"""
    if is_test_file(self.filename):
        self.load()
        for func in self.all_funcs():
            try:
                for error in func.check_all():
                    yield (error.line_number, error.offset, error.text, Checker)
            except ValidationError as error:
                yield error.to_flake8(Checker)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST (None,)
  LOAD_CONST <code make_driver>
  MAKE_FUNCTION defaults
  STORE_NAME make_driver
  RETURN_CONST None
END
CODE make_driver(loop)
  DOC 'pass'
  MAKE_CELL loop
  MAKE_CELL stop
  RESUME 0
  LOAD_DEREF loop
  COPY 1
  POP_JUMP_IF_TRUE L1
  POP_TOP
  LOAD_GLOBAL asyncio
  LOAD_ATTR NULL|self + get_event_loop
  CALL 0
L1:
  STORE_DEREF loop
  LOAD_CONST (None,)
  LOAD_CLOSURE loop
  BUILD_TUPLE 1
  LOAD_CONST <code make_driver.<locals>.stop>
  MAKE_FUNCTION defaults, closure
  STORE_DEREF stop
  LOAD_CLOSURE stop
  BUILD_TUPLE 1
  LOAD_CONST <code make_driver.<locals>.driver>
  MAKE_FUNCTION closure
  STORE_FAST driver
  LOAD_GLOBAL NULL + Component
  LOAD_FAST driver
  LOAD_GLOBAL Sink
  KW_NAMES ('call', 'input')
  CALL 2
  RETURN_VALUE
END
CODE make_driver.<locals>.stop(i)
  COPY_FREE_VARS 1
  RESUME 0
  LOAD_DEREF loop
  LOAD_ATTR NULL|self + stop
  CALL 0
  POP_TOP
  RETURN_CONST None
END
CODE make_driver.<locals>.driver(sink)
  DOC 'pass'
  COPY_FREE_VARS 1
  RESUME 0
  LOAD_FAST sink
  LOAD_ATTR control
  LOAD_ATTR NULL|self + subscribe
  LOAD_DEREF stop
  LOAD_DEREF stop
  LOAD_DEREF stop
  KW_NAMES ('on_next', 'on_error', 'on_completed')
  CALL 3
  POP_TOP
  RETURN_CONST None
END

def make_driver(loop=None):
    """pass"""
    loop = loop or asyncio.get_event_loop()

    def stop(i=None):
        loop.stop()

    def driver(sink):
        """pass"""
        sink.control.subscribe(on_next=stop, on_error=stop, on_completed=stop)
        return None
    return Component(call=driver, input=Sink)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code _stdin_>
  MAKE_FUNCTION 0
  STORE_NAME _stdin_
  RETURN_CONST None
END
CODE _stdin_(p)
  DOC 'pass'
  RESUME 0
  LOAD_GLOBAL sys
  LOAD_ATTR version
  LOAD_CONST 0
  BINARY_SUBSCR
  STORE_FAST _v
  LOAD_FAST _v
  LOAD_CONST '3'
  IS_OP 0
  POP_JUMP_IF_FALSE L1
  LOAD_GLOBAL NULL + input
  LOAD_FAST p
  CALL 1
  RETURN_VALUE
L1:
  LOAD_GLOBAL NULL + raw_input
  LOAD_FAST p
  CALL 1
  RETURN_VALUE
END

def _stdin_(p):
    """pass"""
    _v = sys.version[0]
    return input(p) if _v is '3' else raw_input(p)


Input:
CODE <module>()
  RESUME 0
  LOAD_NAME SUR_DIR
  LOAD_NAME SUR_FILE
  BUILD_TUPLE 2
  LOAD_CONST <code survey_loader>
  MAKE_FUNCTION defaults
  STORE_NAME survey_loader
  RETURN_CONST None
END
CODE survey_loader(sur_dir, sur_file)
  DOC 'pass'
  RESUME 0
  LOAD_GLOBAL os
  LOAD_ATTR path
  LOAD_ATTR NULL|self + join
  LOAD_FAST sur_dir
  LOAD_FAST sur_file
  CALL 2
  STORE_FAST survey_path
  LOAD_CONST None
  STORE_FAST survey
  LOAD_GLOBAL NULL + open
  LOAD_FAST survey_path
  CALL 1
  BEFORE_WITH
L1:
  STORE_FAST survey_file
  LOAD_GLOBAL NULL + Survey
  LOAD_FAST survey_file
  LOAD_ATTR NULL|self + read
  CALL 0
  CALL 1
  STORE_FAST survey
L2:
  LOAD_CONST None
  LOAD_CONST None
  LOAD_CONST None
  CALL 2
  POP_TOP
  LOAD_FAST survey
  RETURN_VALUE
L3:
  PUSH_EXC_INFO
  WITH_EXCEPT_START
  POP_JUMP_IF_TRUE L4
  RERAISE 2
L4:
  POP_TOP
L5:
  POP_EXCEPT
  POP_TOP
  POP_TOP
  LOAD_FAST survey
  RETURN_VALUE
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 survey_loader(sur_dir=SUR_DIR, sur_file=SUR_FILE):
    """pass"""
    survey_path = os.path.join(sur_dir, sur_file)
    survey = None
    with open(survey_path) as survey_file:
        survey = Survey(survey_file.read())
    return survey


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code format_choices>
  MAKE_FUNCTION 0
  STORE_NAME format_choices
  RETURN_CONST None
END
CODE format_choices(self)
  DOC 'pass'
  RESUME 0
  LOAD_GLOBAL NULL + enumerate
  LOAD_FAST self
  LOAD_ATTR choices
  CALL 1
  STORE_FAST ce
  LOAD_CONST <code format_choices.<locals>.<lambda>>
  MAKE_FUNCTION 0
  STORE_FAST f
  LOAD_FAST ce
  GET_ITER
  LOAD_FAST_AND_CLEAR i
  LOAD_FAST_AND_CLEAR c
  SWAP 3
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L3
  UNPACK_SEQUENCE 2
  STORE_FAST i
  STORE_FAST c
  PUSH_NULL
  LOAD_FAST f
  LOAD_FAST i
  LOAD_FAST c
  CALL 2
  LIST_APPEND 2
  JUMP_BACKWARD L2
L3:
  END_FOR
L4:
  SWAP 3
  STORE_FAST c
  STORE_FAST i
  LOAD_CONST 'Help (?)'
  BUILD_LIST 1
  BINARY_OP +
  STORE_FAST toks
  LOAD_CONST ' '
  LOAD_ATTR NULL|self + join
  LOAD_FAST toks
  CALL 1
  RETURN_VALUE
L5:
  SWAP 2
  POP_TOP
  SWAP 3
  STORE_FAST c
  STORE_FAST i
  RERAISE 0
  EXC try=L1..L4 -> handler=L5 depth=3 lasti=False
END
CODE format_choices.<locals>.<lambda>(i, c)
  RESUME 0
  LOAD_CONST '%s (%d)'
  LOAD_FAST c
  LOAD_FAST i
  LOAD_CONST 1
  BINARY_OP +
  BUILD_TUPLE 2
  BINARY_OP %
  RETURN_VALUE
END

def format_choices(self):
    """pass"""
    ce = enumerate(self.choices)
    f = lambda i, c: '%s (%d)' % (c, i + 1)
    toks = [f(i, c) for i, c in ce] + ['Help (?)']
    return ' '.join(toks)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code is_answer_valid>
  MAKE_FUNCTION 0
  STORE_NAME is_answer_valid
  RETURN_CONST None
END
CODE is_answer_valid(self, ans)
  DOC 'pass'
  RESUME 0
  LOAD_FAST ans
  LOAD_GLOBAL NULL + range
  LOAD_GLOBAL NULL + len
  LOAD_FAST self
  LOAD_ATTR choices
  CALL 1
  CALL 1
  GET_ITER
  LOAD_FAST_AND_CLEAR i
  SWAP 2
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L3
  STORE_FAST i
  LOAD_GLOBAL NULL + str
  LOAD_FAST i
  LOAD_CONST 1
  BINARY_OP +
  CALL 1
  LIST_APPEND 2
  JUMP_BACKWARD L2
L3:
  END_FOR
L4:
  SWAP 2
  STORE_FAST i
  CONTAINS_OP 0
  RETURN_VALUE
L5:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST i
  RERAISE 0
  EXC try=L1..L4 -> handler=L5 depth=3 lasti=False
END

def is_answer_valid(self, ans):
    """pass"""
    return ans in [str(i + 1) for i in range(len(self.choices))]


Input:
CODE <module>()
  DOC 'span'
  RESUME 0
  LOAD_CONST 'span'
  LOAD_NAME typing
  LOAD_ATTR Tuple
  LOAD_NAME int
  LOAD_NAME int
  BUILD_TUPLE 2
  BINARY_SUBSCR
  LOAD_CONST 'line_type'
  LOAD_NAME LineType
  LOAD_CONST 'return'
  LOAD_CONST None
  BUILD_TUPLE 6
  LOAD_CONST <code update>
  MAKE_FUNCTION annotations
  STORE_NAME update
  RETURN_CONST None
END
CODE update(self, span, line_type)
  DOC 'pass'
  RESUME 0
  LOAD_FAST span
  UNPACK_SEQUENCE 2
  STORE_FAST first_block_line
  STORE_FAST last_block_line
  LOAD_GLOBAL NULL + range
  LOAD_FAST first_block_line
  LOAD_FAST last_block_line
  LOAD_CONST 1
  BINARY_OP +
  CALL 2
  GET_ITER
L1:
  FOR_ITER L4
  STORE_FAST i
  NOP
L2:
  LOAD_FAST self
  LOAD_ATTR NULL|self + __setitem__
  LOAD_FAST i
  LOAD_FAST line_type
  CALL 2
  POP_TOP
L3:
  JUMP_BACKWARD L1
L4:
  END_FOR
  RETURN_CONST None
L5:
  PUSH_EXC_INFO
  LOAD_GLOBAL ValueError
  CHECK_EXC_MATCH
  POP_JUMP_IF_FALSE L8
  STORE_FAST error
L6:
  LOAD_GLOBAL NULL + ValidationError
  LOAD_FAST i
  LOAD_FAST self
  LOAD_ATTR fn_offset
  BINARY_OP +
  LOAD_CONST 1
  LOAD_CONST 'AAA99 {}'
  LOAD_ATTR NULL|self + format
  LOAD_FAST error
  CALL 1
  CALL 3
  RAISE_VARARGS 1
L7:
  LOAD_CONST None
  STORE_FAST error
  DELETE_FAST error
  RERAISE 1
L8:
  RERAISE 0
L9:
  COPY 3
  POP_EXCEPT
  RERAISE 1
  EXC try=L2..L3 -> handler=L5 depth=1 lasti=False
  EXC try=L5..L6 -> handler=L9 depth=2 lasti=True
  EXC try=L6..L7 -> handler=L7 depth=2 lasti=True
  EXC try=L7..L9 -> handler=L9 depth=2 lasti=True
END

def update(self, span: typing.Tuple[int, int], line_type: LineType) -> None:
    """pass"""
    first_block_line, last_block_line = span
    for i in range(first_block_line, last_block_line + 1):
        try:
            self.__setitem__(i, line_type)
        except ValueError as error:
            raise ValidationError(i + self.fn_offset, 1, 'AAA99 {}'.format(error))


Input:
CODE <module>()
  DOC 'return'
  RESUME 0
  LOAD_CONST 'return'
  LOAD_NAME typing
  LOAD_ATTR Generator
  LOAD_NAME AAAError
  LOAD_CONST None
  LOAD_CONST None
  BUILD_TUPLE 3
  BINARY_SUBSCR
  BUILD_TUPLE 2
  LOAD_CONST <code check_arrange_act_spacing>
  MAKE_FUNCTION annotations
  STORE_NAME check_arrange_act_spacing
  RETURN_CONST None
END
CODE check_arrange_act_spacing(self)
  DOC 'pass'
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_FAST self
  LOAD_ATTR NULL|self + check_block_spacing
  LOAD_GLOBAL LineType
  LOAD_ATTR arrange
  LOAD_GLOBAL LineType
  LOAD_ATTR act
  LOAD_CONST 'AAA03 expected 1 blank line before Act block, found {}'
  CALL 3
  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 check_arrange_act_spacing(self) -> typing.Generator[AAAError, None, None]:
    """pass"""
    yield from self.check_block_spacing(LineType.arrange, LineType.act, 'AAA03 expected 1 blank line before Act block, found {}')


Input:
CODE <module>()
  DOC 'return'
  RESUME 0
  LOAD_CONST 'return'
  LOAD_NAME typing
  LOAD_ATTR Generator
  LOAD_NAME AAAError
  LOAD_CONST None
  LOAD_CONST None
  BUILD_TUPLE 3
  BINARY_SUBSCR
  BUILD_TUPLE 2
  LOAD_CONST <code check_act_assert_spacing>
  MAKE_FUNCTION annotations
  STORE_NAME check_act_assert_spacing
  RETURN_CONST None
END
CODE check_act_assert_spacing(self)
  DOC 'pass'
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_FAST self
  LOAD_ATTR NULL|self + check_block_spacing
  LOAD_GLOBAL LineType
  LOAD_ATTR act
  LOAD_GLOBAL LineType
  LOAD_ATTR _assert
  LOAD_CONST 'AAA04 expected 1 blank line before Assert block, found {}'
  CALL 3
  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 check_act_assert_spacing(self) -> typing.Generator[AAAError, None, None]:
    """pass"""
    yield from self.check_block_spacing(LineType.act, LineType._assert, 'AAA04 expected 1 blank line before Assert block, found {}')


Input:
CODE <module>()
  DOC 'first_block_type'
  RESUME 0
  LOAD_CONST 'first_block_type'
  LOAD_NAME LineType
  LOAD_CONST 'second_block_type'
  LOAD_NAME LineType
  LOAD_CONST 'error_message'
  LOAD_NAME str
  LOAD_CONST 'return'
  LOAD_NAME typing
  LOAD_ATTR Generator
  LOAD_NAME AAAError
  LOAD_CONST None
  LOAD_CONST None
  BUILD_TUPLE 3
  BINARY_SUBSCR
  BUILD_TUPLE 8
  LOAD_CONST <code check_block_spacing>
  MAKE_FUNCTION annotations
  STORE_NAME check_block_spacing
  RETURN_CONST None
END
CODE check_block_spacing(self, first_block_type, second_block_type, error_message)
  DOC 'pass'
  MAKE_CELL first_block_type
  MAKE_CELL second_block_type
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_GLOBAL NULL + list
  LOAD_GLOBAL NULL + enumerate
  LOAD_FAST self
  CALL 1
  CALL 1
  STORE_FAST numbered_lines
  LOAD_GLOBAL NULL + filter
  LOAD_CLOSURE first_block_type
  BUILD_TUPLE 1
  LOAD_CONST <code check_block_spacing.<locals>.<lambda>>
  MAKE_FUNCTION closure
  LOAD_FAST numbered_lines
  CALL 2
  STORE_FAST first_block_lines
L2:
  NOP
L3:
  LOAD_GLOBAL NULL + list
  LOAD_FAST first_block_lines
  CALL 1
  LOAD_CONST -1
  BINARY_SUBSCR
  LOAD_CONST 0
  BINARY_SUBSCR
  STORE_FAST first_block_lineno
L4:
  LOAD_GLOBAL NULL + filter
  LOAD_CLOSURE second_block_type
  BUILD_TUPLE 1
  LOAD_CONST <code check_block_spacing.<locals>.<lambda>>
  MAKE_FUNCTION closure
  LOAD_FAST numbered_lines
  CALL 2
  STORE_FAST second_block_lines
L5:
  NOP
L6:
  LOAD_GLOBAL NULL + next
  LOAD_FAST second_block_lines
  CALL 1
  LOAD_CONST 0
  BINARY_SUBSCR
  STORE_FAST second_block_lineno
L7:
  LOAD_FAST numbered_lines
  LOAD_FAST first_block_lineno
  LOAD_CONST 1
  BINARY_OP +
  LOAD_FAST second_block_lineno
  BINARY_SLICE
  GET_ITER
  LOAD_FAST_AND_CLEAR bl
  SWAP 2
L8:
  BUILD_LIST 0
  SWAP 2
L9:
  FOR_ITER L12
  STORE_FAST bl
  LOAD_FAST bl
  LOAD_CONST 1
  BINARY_SUBSCR
  LOAD_GLOBAL LineType
  LOAD_ATTR blank_line
  IS_OP 0
  POP_JUMP_IF_TRUE L11
L10:
  JUMP_BACKWARD L9
L11:
  LOAD_FAST bl
  LIST_APPEND 2
  JUMP_BACKWARD L9
L12:
  END_FOR
L13:
  STORE_FAST blank_lines
  STORE_FAST bl
  LOAD_FAST blank_lines
  POP_JUMP_IF_TRUE L14
  LOAD_GLOBAL NULL + AAAError
  LOAD_FAST self
  LOAD_ATTR fn_offset
  LOAD_FAST second_block_lineno
  BINARY_OP +
  LOAD_CONST 1
  BINARY_OP -
  LOAD_CONST 0
  LOAD_FAST error_message
  LOAD_ATTR NULL|self + format
  LOAD_CONST 'none'
  CALL 1
  KW_NAMES ('line_number', 'offset', 'text')
  CALL 3
  YIELD_VALUE 1
  RESUME 1
  POP_TOP
  RETURN_CONST None
L14:
  LOAD_GLOBAL NULL + len
  LOAD_FAST blank_lines
  CALL 1
  LOAD_CONST 1
  COMPARE_OP >
  POP_JUMP_IF_FALSE L15
  LOAD_GLOBAL NULL + AAAError
  LOAD_FAST self
  LOAD_ATTR fn_offset
  LOAD_FAST blank_lines
  LOAD_CONST 1
  BINARY_SUBSCR
  LOAD_CONST 0
  BINARY_SUBSCR
  BINARY_OP +
  LOAD_CONST 0
  LOAD_FAST error_message
  LOAD_ATTR NULL|self + format
  LOAD_GLOBAL NULL + len
  LOAD_FAST blank_lines
  CALL 1
  CALL 1
  KW_NAMES ('line_number', 'offset', 'text')
  CALL 3
  YIELD_VALUE 1
  RESUME 1
  POP_TOP
  RETURN_CONST None
L15:
  RETURN_CONST None
L16:
  PUSH_EXC_INFO
  LOAD_GLOBAL IndexError
  CHECK_EXC_MATCH
  POP_JUMP_IF_FALSE L18
  POP_TOP
L17:
  POP_EXCEPT
  RETURN_CONST None
L18:
  RERAISE 0
L19:
  COPY 3
  POP_EXCEPT
  RERAISE 1
L20:
  PUSH_EXC_INFO
  LOAD_GLOBAL StopIteration
  CHECK_EXC_MATCH
  POP_JUMP_IF_FALSE L22
  POP_TOP
L21:
  POP_EXCEPT
  RETURN_CONST None
L22:
  RERAISE 0
L23:
  COPY 3
  POP_EXCEPT
  RERAISE 1
L24:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST bl
  RERAISE 0
L25:
  CALL_INTRINSIC_1 INTRINSIC_STOPITERATION_ERROR
  RERAISE 1
  EXC try=L1..L2 -> handler=L25 depth=0 lasti=True
  EXC try=L3..L4 -> handler=L16 depth=0 lasti=False
  EXC try=L4..L5 -> handler=L25 depth=0 lasti=True
  EXC try=L6..L7 -> handler=L20 depth=0 lasti=False
  EXC try=L7..L8 -> handler=L25 depth=0 lasti=True
  EXC try=L8..L10 -> handler=L24 depth=2 lasti=False
  EXC try=L11..L13 -> handler=L24 depth=2 lasti=False
  EXC try=L13..L16 -> handler=L25 depth=0 lasti=True
  EXC try=L16..L17 -> handler=L19 depth=1 lasti=True
  EXC try=L17..L18 -> handler=L25 depth=0 lasti=True
  EXC try=L18..L19 -> handler=L19 depth=1 lasti=True
  EXC try=L19..L20 -> handler=L25 depth=0 lasti=True
  EXC try=L20..L21 -> handler=L23 depth=1 lasti=True
  EXC try=L21..L22 -> handler=L25 depth=0 lasti=True
  EXC try=L22..L23 -> handler=L23 depth=1 lasti=True
  EXC try=L23..L25 -> handler=L25 depth=0 lasti=True
END
CODE check_block_spacing.<locals>.<lambda>(l)
  COPY_FREE_VARS 1
  RESUME 0
  LOAD_FAST l
  LOAD_CONST 1
  BINARY_SUBSCR
  LOAD_DEREF first_block_type
  IS_OP 0
  RETURN_VALUE
END
CODE check_block_spacing.<locals>.<lambda>(l)
  COPY_FREE_VARS 1
  RESUME 0
  LOAD_FAST l
  LOAD_CONST 1
  BINARY_SUBSCR
  LOAD_DEREF second_block_type
  IS_OP 0
  RETURN_VALUE
END

def check_block_spacing(self, first_block_type: LineType, second_block_type: LineType, error_message: str) -> typing.Generator[AAAError, None, None]:
    """pass"""
    numbered_lines = list(enumerate(self))
    first_block_lines = filter(lambda l: l[1] is first_block_type, numbered_lines)
    try:
        first_block_lineno = list(first_block_lines)[-1][0]
    except IndexError:
        return
    second_block_lines = filter(lambda l: l[1] is second_block_type, numbered_lines)
    try:
        second_block_lineno = next(second_block_lines)[0]
    except StopIteration:
        return
    blank_lines = [bl for bl in numbered_lines[first_block_lineno + 1:second_block_lineno] if bl[1] is LineType.blank_line]
    if not blank_lines:
        yield AAAError(line_number=self.fn_offset + second_block_lineno - 1, offset=0, text=error_message.format('none'))
        return
    if len(blank_lines) > 1:
        yield AAAError(line_number=self.fn_offset + blank_lines[1][0], offset=0, text=error_message.format(len(blank_lines)))


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code get_access_token>
  MAKE_FUNCTION 0
  STORE_NAME get_access_token
  RETURN_CONST None
END
CODE get_access_token(self, code)
  DOC 'pass'
  RESUME 0
  NOP
L1:
  LOAD_GLOBAL NULL + super
  CALL 0
  LOAD_ATTR NULL|self + fetch_token
  LOAD_GLOBAL MINUT_TOKEN_URL
  LOAD_FAST self
  LOAD_ATTR _client_id
  LOAD_FAST self
  LOAD_ATTR _client_secret
  LOAD_FAST code
  KW_NAMES ('client_id', 'client_secret', 'code')
  CALL 4
  LOAD_FAST self
  STORE_ATTR _token
L2:
  LOAD_FAST self
  LOAD_ATTR _token
  RETURN_VALUE
L3:
  PUSH_EXC_INFO
  LOAD_GLOBAL MissingTokenError
  CHECK_EXC_MATCH
  POP_JUMP_IF_FALSE L7
  STORE_FAST error
L4:
  LOAD_GLOBAL _LOGGER
  LOAD_ATTR NULL|self + debug
  LOAD_CONST 'Token issues: %s'
  LOAD_FAST error
  CALL 2
  POP_TOP
L5:
  POP_EXCEPT
  LOAD_CONST None
  STORE_FAST error
  DELETE_FAST error
  LOAD_FAST self
  LOAD_ATTR _token
  RETURN_VALUE
L6:
  LOAD_CONST None
  STORE_FAST error
  DELETE_FAST error
  RERAISE 1
L7:
  RERAISE 0
L8:
  COPY 3
  POP_EXCEPT
  RERAISE 1
  EXC try=L1..L2 -> handler=L3 depth=0 lasti=False
  EXC try=L3..L4 -> handler=L8 depth=1 lasti=True
  EXC try=L4..L5 -> handler=L6 depth=1 lasti=True
  EXC try=L6..L8 -> handler=L8 depth=1 lasti=True
END

def get_access_token(self, code):
    """pass"""
    try:
        self._token = super().fetch_token(MINUT_TOKEN_URL, client_id=self._client_id, client_secret=self._client_secret, code=code)
    except MissingTokenError as error:
        _LOGGER.debug('Token issues: %s', error)
    return self._token


Input:
CODE <module>()
  DOC 'GET'
  RESUME 0
  LOAD_CONST ('GET',)
  LOAD_CONST <code _request>
  MAKE_FUNCTION defaults
  STORE_NAME _request
  RETURN_CONST None
END
CODE _request(self, url, request_type, **params)
  DOC 'pass'
  RESUME 0
  NOP
L1:
  LOAD_GLOBAL _LOGGER
  LOAD_ATTR NULL|self + debug
  LOAD_CONST 'Request %s %s'
  LOAD_FAST url
  LOAD_FAST params
  CALL 3
  POP_TOP
  PUSH_NULL
  LOAD_FAST self
  LOAD_ATTR request
  LOAD_FAST request_type
  LOAD_FAST url
  BUILD_TUPLE 2
  LOAD_CONST 'timeout'
  LOAD_GLOBAL TIMEOUT
  LOAD_ATTR seconds
  BUILD_MAP 1
  LOAD_FAST params
  DICT_MERGE 1
  CALL_FUNCTION_EX 1
  STORE_FAST response
  LOAD_FAST response
  LOAD_ATTR NULL|self + raise_for_status
  CALL 0
  POP_TOP
  LOAD_GLOBAL _LOGGER
  LOAD_ATTR NULL|self + debug
  LOAD_CONST 'Response %s %s %.200s'
  LOAD_FAST response
  LOAD_ATTR status_code
  LOAD_FAST response
  LOAD_ATTR headers
  LOAD_CONST 'content-type'
  BINARY_SUBSCR
  LOAD_FAST response
  LOAD_ATTR NULL|self + json
  CALL 0
  CALL 4
  POP_TOP
  LOAD_FAST response
  LOAD_ATTR NULL|self + json
  CALL 0
  STORE_FAST response
  LOAD_CONST 'error'
  LOAD_FAST response
  CONTAINS_OP 0
  POP_JUMP_IF_FALSE L2
  LOAD_GLOBAL NULL + OSError
  LOAD_FAST response
  LOAD_CONST 'error'
  BINARY_SUBSCR
  CALL 1
  RAISE_VARARGS 1
L2:
  LOAD_FAST response
L3:
  RETURN_VALUE
L4:
  PUSH_EXC_INFO
  LOAD_GLOBAL OSError
  CHECK_EXC_MATCH
  POP_JUMP_IF_FALSE L8
  STORE_FAST error
L5:
  LOAD_GLOBAL _LOGGER
  LOAD_ATTR NULL|self + warning
  LOAD_CONST 'Failed request: %s'
  LOAD_FAST error
  CALL 2
  POP_TOP
L6:
  POP_EXCEPT
  LOAD_CONST None
  STORE_FAST error
  DELETE_FAST error
  RETURN_CONST None
L7:
  LOAD_CONST None
  STORE_FAST error
  DELETE_FAST error
  RERAISE 1
L8:
  RERAISE 0
L9:
  COPY 3
  POP_EXCEPT
  RERAISE 1
  EXC try=L1..L3 -> handler=L4 depth=0 lasti=False
  EXC try=L4..L5 -> handler=L9 depth=1 lasti=True
  EXC try=L5..L6 -> handler=L7 depth=1 lasti=True
  EXC try=L7..L9 -> handler=L9 depth=1 lasti=True
END

def _request(self, url, request_type='GET', **params):
    """pass"""
    try:
        _LOGGER.debug('Request %s %s', url, params)
        response = self.request(request_type, url, timeout=TIMEOUT.seconds, **params)
        response.raise_for_status()
        _LOGGER.debug('Response %s %s %.200s', response.status_code, response.headers['content-type'], response.json())
        response = response.json()
        if 'error' in response:
            raise OSError(response['error'])
        return response
    except OSError as error:
        _LOGGER.warning('Failed request: %s', error)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code _request_devices>
  MAKE_FUNCTION 0
  STORE_NAME _request_devices
  RETURN_CONST None
END
CODE _request_devices(self, url, _type)
  DOC 'pass'
  RESUME 0
  LOAD_FAST self
  LOAD_ATTR NULL|self + _request
  LOAD_FAST url
  CALL 1
  STORE_FAST res
  LOAD_FAST res
  POP_JUMP_IF_FALSE L1
  LOAD_FAST res
  LOAD_ATTR NULL|self + get
  LOAD_FAST _type
  CALL 1
  RETURN_VALUE
L1:
  BUILD_MAP 0
  RETURN_VALUE
END

def _request_devices(self, url, _type):
    """pass"""
    res = self._request(url)
    return res.get(_type) if res else {}


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code read_sensor>
  MAKE_FUNCTION 0
  STORE_NAME read_sensor
  RETURN_CONST None
END
CODE read_sensor(self, device_id, sensor_uri)
  DOC 'pass'
  RESUME 0
  LOAD_GLOBAL MINUT_DEVICES_URL
  LOAD_CONST '/{device_id}/{sensor_uri}'
  LOAD_ATTR NULL|self + format
  LOAD_FAST device_id
  LOAD_FAST sensor_uri
  KW_NAMES ('device_id', 'sensor_uri')
  CALL 2
  BINARY_OP +
  STORE_FAST url
  LOAD_FAST self
  LOAD_ATTR NULL|self + _request
  LOAD_FAST url
  LOAD_CONST 'GET'
  LOAD_CONST 'limit'
  LOAD_CONST 1
  BUILD_MAP 1
  KW_NAMES ('request_type', 'data')
  CALL 3
  STORE_FAST res
  LOAD_FAST res
  LOAD_ATTR NULL|self + get
  LOAD_CONST 'values'
  CALL 1
  POP_JUMP_IF_TRUE L1
  RETURN_CONST None
L1:
  LOAD_FAST res
  LOAD_ATTR NULL|self + get
  LOAD_CONST 'values'
  CALL 1
  LOAD_CONST -1
  BINARY_SUBSCR
  LOAD_ATTR NULL|self + get
  LOAD_CONST 'value'
  CALL 1
  RETURN_VALUE
END

def read_sensor(self, device_id, sensor_uri):
    """pass"""
    url = MINUT_DEVICES_URL + '/{device_id}/{sensor_uri}'.format(device_id=device_id, sensor_uri=sensor_uri)
    res = self._request(url, request_type='GET', data={'limit': 1})
    if not res.get('values'):
        return None
    return res.get('values')[-1].get('value')


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code _register_webhook>
  MAKE_FUNCTION 0
  STORE_NAME _register_webhook
  RETURN_CONST None
END
CODE _register_webhook(self, webhook_url, events)
  DOC 'pass'
  RESUME 0
  LOAD_FAST self
  LOAD_ATTR NULL|self + _request
  LOAD_GLOBAL MINUT_WEBHOOKS_URL
  LOAD_CONST 'POST'
  LOAD_FAST webhook_url
  LOAD_FAST events
  LOAD_CONST ('url', 'events')
  BUILD_CONST_KEY_MAP 2
  KW_NAMES ('request_type', 'json')
  CALL 3
  STORE_FAST response
  LOAD_FAST response
  RETURN_VALUE
END

def _register_webhook(self, webhook_url, events):
    """pass"""
    response = self._request(MINUT_WEBHOOKS_URL, request_type='POST', json={'url': webhook_url, 'events': events})
    return response


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code remove_webhook>
  MAKE_FUNCTION 0
  STORE_NAME remove_webhook
  RETURN_CONST None
END
CODE remove_webhook(self)
  DOC 'pass'
  RESUME 0
  LOAD_FAST self
  LOAD_ATTR _webhook
  LOAD_ATTR NULL|self + get
  LOAD_CONST 'hook_id'
  CALL 1
  POP_JUMP_IF_FALSE L1
  LOAD_FAST self
  LOAD_ATTR NULL|self + _request
  LOAD_CONST '{}/{}'
  LOAD_ATTR NULL|self + format
  LOAD_GLOBAL MINUT_WEBHOOKS_URL
  LOAD_FAST self
  LOAD_ATTR _webhook
  LOAD_CONST 'hook_id'
  BINARY_SUBSCR
  CALL 2
  LOAD_CONST 'DELETE'
  KW_NAMES ('request_type',)
  CALL 2
  POP_TOP
  RETURN_CONST None
L1:
  RETURN_CONST None
END

def remove_webhook(self):
    """pass"""
    if self._webhook.get('hook_id'):
        self._request('{}/{}'.format(MINUT_WEBHOOKS_URL, self._webhook['hook_id']), request_type='DELETE')


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code _get_ip>
  MAKE_FUNCTION 0
  STORE_NAME _get_ip
  RETURN_CONST None
END
CODE _get_ip()
  DOC 'pass'
  RESUME 0
  LOAD_CONST 'netstat'
  LOAD_CONST '-nr'
  BUILD_LIST 2
  STORE_FAST cmd_netstat
  LOAD_GLOBAL subprocess
  LOAD_ATTR NULL|self + Popen
  LOAD_FAST cmd_netstat
  LOAD_GLOBAL subprocess
  LOAD_ATTR PIPE
  KW_NAMES ('stdout',)
  CALL 2
  STORE_FAST p1
  LOAD_CONST 'grep'
  LOAD_CONST '^0\\.0\\.0\\.0'
  BUILD_LIST 2
  STORE_FAST cmd_grep
  LOAD_GLOBAL subprocess
  LOAD_ATTR NULL|self + Popen
  LOAD_FAST cmd_grep
  LOAD_FAST p1
  LOAD_ATTR stdout
  LOAD_GLOBAL subprocess
  LOAD_ATTR PIPE
  KW_NAMES ('stdin', 'stdout')
  CALL 3
  STORE_FAST p2
  LOAD_CONST 'awk'
  LOAD_CONST '{ print $2 }'
  BUILD_LIST 2
  STORE_FAST cmd_awk
  LOAD_GLOBAL subprocess
  LOAD_ATTR NULL|self + Popen
  LOAD_FAST cmd_awk
  LOAD_FAST p2
  LOAD_ATTR stdout
  LOAD_GLOBAL subprocess
  LOAD_ATTR PIPE
  KW_NAMES ('stdin', 'stdout')
  CALL 3
  STORE_FAST p3
  LOAD_FAST p3
  LOAD_ATTR stdout
  LOAD_ATTR NULL|self + read
  CALL 0
  STORE_FAST galaxy_ip
  LOAD_GLOBAL log
  LOAD_ATTR NULL|self + debug
  LOAD_CONST 'Host IP determined to be %s'
  LOAD_FAST galaxy_ip
  CALL 2
  POP_TOP
  LOAD_FAST galaxy_ip
  RETURN_VALUE
END

def _get_ip():
    """pass"""
    cmd_netstat = ['netstat', '-nr']
    p1 = subprocess.Popen(cmd_netstat, stdout=subprocess.PIPE)
    cmd_grep = ['grep', '^0\\.0\\.0\\.0']
    p2 = subprocess.Popen(cmd_grep, stdin=p1.stdout, stdout=subprocess.PIPE)
    cmd_awk = ['awk', '{ print $2 }']
    p3 = subprocess.Popen(cmd_awk, stdin=p2.stdout, stdout=subprocess.PIPE)
    galaxy_ip = p3.stdout.read()
    log.debug('Host IP determined to be %s', galaxy_ip)
    return galaxy_ip


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST (None, True)
  LOAD_CONST <code get_galaxy_connection>
  MAKE_FUNCTION defaults
  STORE_NAME get_galaxy_connection
  RETURN_CONST None
END
CODE get_galaxy_connection(history_id, obj)
  DOC 'pass'
  RESUME 0
  LOAD_FAST history_id
  COPY 1
  POP_JUMP_IF_TRUE L1
  POP_TOP
  LOAD_GLOBAL os
  LOAD_ATTR environ
  LOAD_CONST 'HISTORY_ID'
  BINARY_SUBSCR
L1:
  STORE_FAST history_id
  LOAD_GLOBAL os
  LOAD_ATTR environ
  LOAD_CONST 'API_KEY'
  BINARY_SUBSCR
  STORE_FAST key
  LOAD_GLOBAL NULL + _get_ip
  CALL 0
  STORE_FAST galaxy_ip
  LOAD_GLOBAL NULL + Template
  LOAD_GLOBAL os
  LOAD_ATTR environ
  LOAD_CONST 'GALAXY_URL'
  BINARY_SUBSCR
  CALL 1
  LOAD_ATTR NULL|self + safe_substitute
  LOAD_CONST 'DOCKER_HOST'
  LOAD_FAST galaxy_ip
  BUILD_MAP 1
  CALL 1
  STORE_FAST url
  LOAD_GLOBAL NULL + _test_url
  LOAD_FAST url
  LOAD_FAST key
  LOAD_FAST history_id
  LOAD_FAST obj
  KW_NAMES ('obj',)
  CALL 4
  STORE_FAST gi
  LOAD_FAST gi
  POP_JUMP_IF_NONE L2
  LOAD_FAST gi
  RETURN_VALUE
L2:
  LOAD_GLOBAL os
  LOAD_ATTR environ
  LOAD_CONST 'GALAXY_URL'
  BINARY_SUBSCR
  LOAD_ATTR NULL|self + rstrip
  LOAD_CONST '/'
  CALL 1
  STORE_FAST app_path
  LOAD_CONST ''
  LOAD_ATTR NULL|self + join
  LOAD_FAST app_path
  LOAD_ATTR NULL|self + split
  LOAD_CONST '/'
  CALL 1
  LOAD_CONST 3
  LOAD_CONST None
  BINARY_SLICE
  CALL 1
  STORE_FAST app_path
  LOAD_CONST 'GALAXY_WEB_PORT'
  LOAD_GLOBAL os
  LOAD_ATTR environ
  CONTAINS_OP 1
  POP_JUMP_IF_FALSE L3
  LOAD_GLOBAL NULL + Exception
  LOAD_CONST 'No port'
  CALL 1
  RAISE_VARARGS 1
L3:
  LOAD_GLOBAL os
  LOAD_ATTR environ
  LOAD_CONST 'GALAXY_WEB_PORT'
  BINARY_SUBSCR
  STORE_FAST galaxy_port
  LOAD_CONST 'http://'
  LOAD_FAST galaxy_ip
  LOAD_ATTR NULL|self + strip
  CALL 0
  FORMAT_VALUE str
  LOAD_CONST ':'
  LOAD_FAST galaxy_port
  FORMAT_VALUE str
  LOAD_CONST '/'
  LOAD_FAST app_path
  LOAD_ATTR NULL|self + strip
  CALL 0
  FORMAT_VALUE str
  BUILD_STRING 6
  STORE_FAST built_galaxy_url
  LOAD_FAST built_galaxy_url
  LOAD_ATTR NULL|self + rstrip
  LOAD_CONST '/'
  CALL 1
  STORE_FAST url
  LOAD_GLOBAL NULL + _test_url
  LOAD_FAST url
  LOAD_FAST key
  LOAD_FAST history_id
  LOAD_FAST obj
  KW_NAMES ('obj',)
  CALL 4
  STORE_FAST gi
  LOAD_FAST gi
  POP_JUMP_IF_NONE L4
  LOAD_FAST gi
  RETURN_VALUE
L4:
  LOAD_CONST 'Could not connect to a galaxy instance. Please contact your SysAdmin for help with this error'
  STORE_FAST msg
  LOAD_GLOBAL NULL + Exception
  LOAD_FAST msg
  CALL 1
  RAISE_VARARGS 1
END

def get_galaxy_connection(history_id=None, obj=True):
    """pass"""
    history_id = history_id or os.environ['HISTORY_ID']
    key = os.environ['API_KEY']
    galaxy_ip = _get_ip()
    url = Template(os.environ['GALAXY_URL']).safe_substitute({'DOCKER_HOST': galaxy_ip})
    gi = _test_url(url, key, history_id, obj=obj)
    if gi is not None:
        return gi
    app_path = os.environ['GALAXY_URL'].rstrip('/')
    app_path = ''.join(app_path.split('/')[3:])
    if 'GALAXY_WEB_PORT' not in os.environ:
        raise Exception('No port')
    else:
        galaxy_port = os.environ['GALAXY_WEB_PORT']
    built_galaxy_url = 'http://%s:%s/%s' % (galaxy_ip.strip(), galaxy_port, app_path.strip())
    url = built_galaxy_url.rstrip('/')
    gi = _test_url(url, key, history_id, obj=obj)
    if gi is not None:
        return gi
    msg = 'Could not connect to a galaxy instance. Please contact your SysAdmin for help with this error'
    raise Exception(msg)


Input:
CODE <module>()
  DOC 'auto'
  RESUME 0
  LOAD_CONST ('auto', None)
  LOAD_CONST <code put>
  MAKE_FUNCTION defaults
  STORE_NAME put
  RETURN_CONST None
END
CODE put(filenames, file_type, history_id)
  DOC 'pass'
  RESUME 0
  LOAD_FAST history_id
  COPY 1
  POP_JUMP_IF_TRUE L1
  POP_TOP
  LOAD_GLOBAL os
  LOAD_ATTR environ
  LOAD_CONST 'HISTORY_ID'
  BINARY_SUBSCR
L1:
  STORE_FAST history_id
  LOAD_GLOBAL NULL + get_galaxy_connection
  LOAD_FAST history_id
  KW_NAMES ('history_id',)
  CALL 1
  STORE_FAST gi
  LOAD_FAST filenames
  GET_ITER
L2:
  FOR_ITER L3
  STORE_FAST filename
  LOAD_GLOBAL log
  LOAD_ATTR NULL|self + debug
  LOAD_CONST 'Uploading gx=%s history=%s localpath=%s ft=%s'
  LOAD_FAST gi
  LOAD_FAST history_id
  LOAD_FAST filename
  LOAD_FAST file_type
  CALL 5
  POP_TOP
  LOAD_FAST gi
  LOAD_ATTR histories
  LOAD_ATTR NULL|self + get
  LOAD_FAST history_id
  CALL 1
  STORE_FAST history
  LOAD_FAST history
  LOAD_ATTR NULL|self + upload_dataset
  LOAD_FAST filename
  LOAD_FAST file_type
  KW_NAMES ('file_type',)
  CALL 2
  POP_TOP
  JUMP_BACKWARD L2
L3:
  END_FOR
  RETURN_CONST None
END

def put(filenames, file_type='auto', history_id=None):
    """pass"""
    history_id = history_id or os.environ['HISTORY_ID']
    gi = get_galaxy_connection(history_id=history_id)
    for filename in filenames:
        log.debug('Uploading gx=%s history=%s localpath=%s ft=%s', gi, history_id, filename, file_type)
        history = gi.histories.get(history_id)
        history.upload_dataset(filename, file_type=file_type)


Input:
CODE <module>()
  DOC 'hid'
  RESUME 0
  LOAD_CONST ('hid', None)
  LOAD_CONST <code get>
  MAKE_FUNCTION defaults
  STORE_NAME get
  RETURN_CONST None
END
CODE get(datasets_identifiers, identifier_type, history_id)
  DOC 'pass'
  RESUME 0
  LOAD_FAST history_id
  COPY 1
  POP_JUMP_IF_TRUE L1
  POP_TOP
  LOAD_GLOBAL os
  LOAD_ATTR environ
  LOAD_CONST 'HISTORY_ID'
  BINARY_SUBSCR
L1:
  STORE_FAST history_id
  LOAD_GLOBAL NULL + get_galaxy_connection
  LOAD_FAST history_id
  LOAD_CONST False
  KW_NAMES ('history_id', 'obj')
  CALL 2
  STORE_FAST gi
  LOAD_FAST datasets_identifiers
  GET_ITER
L2:
  FOR_ITER L9
  STORE_FAST dataset_identifier
  LOAD_CONST '/import/%s'
  LOAD_FAST dataset_identifier
  BINARY_OP %
  STORE_FAST file_path
  LOAD_GLOBAL log
  LOAD_ATTR NULL|self + debug
  LOAD_CONST 'Downloading gx=%s history=%s dataset=%s'
  LOAD_FAST gi
  LOAD_FAST history_id
  LOAD_FAST dataset_identifier
  CALL 4
  POP_TOP
  LOAD_GLOBAL os
  LOAD_ATTR path
  LOAD_ATTR NULL|self + exists
  LOAD_FAST file_path
  CALL 1
  POP_JUMP_IF_TRUE L8
  LOAD_GLOBAL NULL + HistoryClient
  LOAD_FAST gi
  CALL 1
  STORE_FAST hc
  LOAD_GLOBAL NULL + DatasetClient
  LOAD_FAST gi
  CALL 1
  STORE_FAST dc
  LOAD_FAST hc
  LOAD_ATTR NULL|self + show_history
  LOAD_FAST history_id
  LOAD_CONST True
  KW_NAMES ('contents',)
  CALL 2
  STORE_FAST history
  LOAD_FAST history
  GET_ITER
  LOAD_FAST_AND_CLEAR ds
  SWAP 2
L3:
  BUILD_MAP 0
  SWAP 2
L4:
  FOR_ITER L5
  STORE_FAST ds
  LOAD_FAST ds
  LOAD_FAST identifier_type
  BINARY_SUBSCR
  LOAD_FAST ds
  LOAD_CONST 'id'
  BINARY_SUBSCR
  MAP_ADD 2
  JUMP_BACKWARD L4
L5:
  END_FOR
L6:
  STORE_FAST datasets
  STORE_FAST ds
  LOAD_FAST identifier_type
  LOAD_CONST 'hid'
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L7
  LOAD_GLOBAL NULL + int
  LOAD_FAST dataset_identifier
  CALL 1
  STORE_FAST dataset_identifier
L7:
  LOAD_FAST dc
  LOAD_ATTR NULL|self + download_dataset
  LOAD_FAST datasets
  LOAD_FAST dataset_identifier
  BINARY_SUBSCR
  LOAD_FAST file_path
  LOAD_CONST False
  KW_NAMES ('file_path', 'use_default_filename')
  CALL 3
  POP_TOP
  JUMP_BACKWARD L2
L8:
  LOAD_GLOBAL log
  LOAD_ATTR NULL|self + debug
  LOAD_CONST 'Cached, not re-downloading'
  CALL 1
  POP_TOP
  JUMP_BACKWARD L2
L9:
  END_FOR
  LOAD_FAST_CHECK file_path
  RETURN_VALUE
L10:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST ds
  RERAISE 0
  EXC try=L3..L6 -> handler=L10 depth=3 lasti=False
END

def get(datasets_identifiers, identifier_type='hid', history_id=None):
    """pass"""
    history_id = history_id or os.environ['HISTORY_ID']
    gi = get_galaxy_connection(history_id=history_id, obj=False)
    for dataset_identifier in datasets_identifiers:
        file_path = '/import/%s' % dataset_identifier
        log.debug('Downloading gx=%s history=%s dataset=%s', gi, history_id, dataset_identifier)
        if not os.path.exists(file_path):
            hc = HistoryClient(gi)
            dc = DatasetClient(gi)
            history = hc.show_history(history_id, contents=True)
            datasets = {ds[identifier_type]: ds['id'] for ds in history}
            if identifier_type == 'hid':
                dataset_identifier = int(dataset_identifier)
            dc.download_dataset(datasets[dataset_identifier], file_path=file_path, use_default_filename=False)
        else:
            log.debug('Cached, not re-downloading')
    return file_path


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST (None,)
  LOAD_CONST <code get_user_history>
  MAKE_FUNCTION defaults
  STORE_NAME get_user_history
  RETURN_CONST None
END
CODE get_user_history(history_id)
  DOC 'pass'
  RESUME 0
  LOAD_FAST history_id
  COPY 1
  POP_JUMP_IF_TRUE L1
  POP_TOP
  LOAD_GLOBAL os
  LOAD_ATTR environ
  LOAD_CONST 'HISTORY_ID'
  BINARY_SUBSCR
L1:
  STORE_FAST history_id
  LOAD_GLOBAL NULL + get_galaxy_connection
  LOAD_FAST history_id
  LOAD_CONST False
  KW_NAMES ('history_id', 'obj')
  CALL 2
  STORE_FAST gi
  LOAD_GLOBAL NULL + HistoryClient
  LOAD_FAST gi
  CALL 1
  STORE_FAST hc
  LOAD_FAST hc
  LOAD_ATTR NULL|self + show_history
  LOAD_FAST history_id
  LOAD_CONST True
  LOAD_CONST True
  KW_NAMES ('visible', 'contents')
  CALL 3
  STORE_FAST history
  LOAD_FAST history
  RETURN_VALUE
END

def get_user_history(history_id=None):
    """pass"""
    history_id = history_id or os.environ['HISTORY_ID']
    gi = get_galaxy_connection(history_id=history_id, obj=False)
    hc = HistoryClient(gi)
    history = hc.show_history(history_id, visible=True, contents=True)
    return history


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code get_user_sets>
  MAKE_FUNCTION 0
  STORE_NAME get_user_sets
  RETURN_CONST None
END
CODE get_user_sets(client_id, user_id)
  DOC 'pass'
  RESUME 0
  LOAD_GLOBAL NULL + api_call
  LOAD_CONST 'get'
  LOAD_CONST 'users/{}/sets'
  LOAD_ATTR NULL|self + format
  LOAD_FAST user_id
  CALL 1
  LOAD_FAST client_id
  KW_NAMES ('client_id',)
  CALL 3
  STORE_FAST data
  LOAD_FAST data
  GET_ITER
  LOAD_FAST_AND_CLEAR wordset
  SWAP 2
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L3
  STORE_FAST wordset
  LOAD_GLOBAL WordSet
  LOAD_ATTR NULL|self + from_dict
  LOAD_FAST wordset
  CALL 1
  LIST_APPEND 2
  JUMP_BACKWARD L2
L3:
  END_FOR
L4:
  SWAP 2
  STORE_FAST wordset
  RETURN_VALUE
L5:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST wordset
  RERAISE 0
  EXC try=L1..L4 -> handler=L5 depth=2 lasti=False
END

def get_user_sets(client_id, user_id):
    """pass"""
    data = api_call('get', 'users/{}/sets'.format(user_id), client_id=client_id)
    return [WordSet.from_dict(wordset) for wordset in data]


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code print_user_sets>
  MAKE_FUNCTION 0
  STORE_NAME print_user_sets
  RETURN_CONST None
END
CODE print_user_sets(wordsets, print_terms)
  DOC 'pass'
  RESUME 0
  LOAD_FAST wordsets
  POP_JUMP_IF_TRUE L1
  LOAD_GLOBAL NULL + print
  LOAD_CONST 'No sets found'
  CALL 1
  POP_TOP
  RETURN_CONST None
L1:
  LOAD_GLOBAL NULL + print
  LOAD_CONST 'Found sets: {}'
  LOAD_ATTR NULL|self + format
  LOAD_GLOBAL NULL + len
  LOAD_FAST wordsets
  CALL 1
  CALL 1
  CALL 1
  POP_TOP
  LOAD_FAST wordsets
  GET_ITER
L2:
  FOR_ITER L6
  STORE_FAST wordset
  LOAD_GLOBAL NULL + print
  LOAD_CONST '    {}'
  LOAD_ATTR NULL|self + format
  LOAD_FAST wordset
  CALL 1
  CALL 1
  POP_TOP
  LOAD_FAST print_terms
  POP_JUMP_IF_TRUE L3
  JUMP_BACKWARD L2
L3:
  LOAD_FAST wordset
  LOAD_ATTR terms
  GET_ITER
L4:
  FOR_ITER L5
  STORE_FAST term
  LOAD_GLOBAL NULL + print
  LOAD_CONST '        {}'
  LOAD_ATTR NULL|self + format
  LOAD_FAST term
  CALL 1
  CALL 1
  POP_TOP
  JUMP_BACKWARD L4
L5:
  END_FOR
  JUMP_BACKWARD L2
L6:
  END_FOR
  RETURN_CONST None
END

def print_user_sets(wordsets, print_terms):
    """pass"""
    if not wordsets:
        print('No sets found')
    else:
        print('Found sets: {}'.format(len(wordsets)))
        for wordset in wordsets:
            print('    {}'.format(wordset))
            if print_terms:
                for term in wordset.terms:
                    print('        {}'.format(term))


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code get_common_terms>
  MAKE_FUNCTION 0
  STORE_NAME get_common_terms
  RETURN_CONST None
END
CODE get_common_terms(*api_envs)
  DOC 'pass'
  RESUME 0
  BUILD_LIST 0
  STORE_FAST common_terms
  LOAD_GLOBAL NULL + get_user_sets
  LOAD_FAST api_envs
  CALL_FUNCTION_EX 0
  STORE_FAST wordsets
  LOAD_GLOBAL NULL + combinations
  LOAD_FAST wordsets
  LOAD_CONST 2
  CALL 2
  GET_ITER
L1:
  FOR_ITER L3
  UNPACK_SEQUENCE 2
  STORE_FAST wordset1
  STORE_FAST wordset2
  LOAD_FAST wordset1
  LOAD_ATTR NULL|self + has_common
  LOAD_FAST wordset2
  CALL 1
  STORE_FAST common
  LOAD_FAST common
  POP_JUMP_IF_TRUE L2
  JUMP_BACKWARD L1
L2:
  LOAD_FAST common_terms
  LOAD_ATTR NULL|self + append
  LOAD_FAST wordset1
  LOAD_ATTR title
  LOAD_FAST wordset2
  LOAD_ATTR title
  LOAD_FAST common
  BUILD_TUPLE 3
  CALL 1
  POP_TOP
  JUMP_BACKWARD L1
L3:
  END_FOR
  LOAD_FAST common_terms
  RETURN_VALUE
END

def get_common_terms(*api_envs):
    """pass"""
    common_terms = []
    wordsets = get_user_sets(*api_envs)
    for wordset1, wordset2 in combinations(wordsets, 2):
        common = wordset1.has_common(wordset2)
        if common:
            common_terms.append((wordset1.title, wordset2.title, common))
    return common_terms


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code print_common_terms>
  MAKE_FUNCTION 0
  STORE_NAME print_common_terms
  RETURN_CONST None
END
CODE print_common_terms(common_terms)
  DOC 'pass'
  RESUME 0
  LOAD_FAST common_terms
  POP_JUMP_IF_TRUE L1
  LOAD_GLOBAL NULL + print
  LOAD_CONST 'No duplicates'
  CALL 1
  POP_TOP
  RETURN_CONST None
L1:
  LOAD_FAST common_terms
  GET_ITER
L2:
  FOR_ITER L5
  STORE_FAST set_pair
  LOAD_FAST set_pair
  UNPACK_SEQUENCE 3
  STORE_FAST set1
  STORE_FAST set2
  STORE_FAST terms
  LOAD_GLOBAL NULL + print
  LOAD_CONST '{} and {} have in common:'
  LOAD_ATTR NULL|self + format
  LOAD_FAST set1
  LOAD_FAST set2
  CALL 2
  CALL 1
  POP_TOP
  LOAD_FAST terms
  GET_ITER
L3:
  FOR_ITER L4
  STORE_FAST term
  LOAD_GLOBAL NULL + print
  LOAD_CONST '    {}'
  LOAD_ATTR NULL|self + format
  LOAD_FAST term
  CALL 1
  CALL 1
  POP_TOP
  JUMP_BACKWARD L3
L4:
  END_FOR
  JUMP_BACKWARD L2
L5:
  END_FOR
  RETURN_CONST None
END

def print_common_terms(common_terms):
    """pass"""
    if not common_terms:
        print('No duplicates')
    else:
        for set_pair in common_terms:
            set1, set2, terms = set_pair
            print('{} and {} have in common:'.format(set1, set2))
            for term in terms:
                print('    {}'.format(term))


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST (None,)
  LOAD_CONST <code run>
  MAKE_FUNCTION defaults
  STORE_NAME run
  RETURN_CONST None
END
CODE run(entry_point, drivers, loop)
  DOC 'pass'
  RESUME 0
  LOAD_GLOBAL NULL + setup
  LOAD_FAST entry_point
  LOAD_FAST drivers
  CALL 2
  STORE_FAST program
  LOAD_FAST program
  LOAD_ATTR NULL|self + run
  CALL 0
  STORE_FAST dispose
  LOAD_FAST loop
  LOAD_CONST None
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L1
  LOAD_GLOBAL asyncio
  LOAD_ATTR NULL|self + get_event_loop
  CALL 0
  STORE_FAST loop
L1:
  LOAD_FAST loop
  LOAD_ATTR NULL|self + run_forever
  CALL 0
  POP_TOP
  PUSH_NULL
  LOAD_FAST dispose
  CALL 0
  POP_TOP
  RETURN_CONST None
END

def run(entry_point, drivers, loop=None):
    """pass"""
    program = setup(entry_point, drivers)
    dispose = program.run()
    if loop == None:
        loop = asyncio.get_event_loop()
    loop.run_forever()
    dispose()


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code compare_schemas>
  MAKE_FUNCTION 0
  STORE_NAME compare_schemas
  RETURN_CONST None
END
CODE compare_schemas(one, two)
  DOC 'pass'
  RESUME 0
  LOAD_GLOBAL NULL + _normalize_string_type
  LOAD_FAST one
  CALL 1
  STORE_FAST one
  LOAD_GLOBAL NULL + _normalize_string_type
  LOAD_FAST two
  CALL 1
  STORE_FAST two
  LOAD_GLOBAL NULL + _assert_same_types
  LOAD_FAST one
  LOAD_FAST two
  CALL 2
  POP_TOP
  LOAD_GLOBAL NULL + isinstance
  LOAD_FAST one
  LOAD_GLOBAL list
  CALL 2
  POP_JUMP_IF_FALSE L1
  LOAD_GLOBAL NULL + _compare_lists
  LOAD_FAST one
  LOAD_FAST two
  CALL 2
  RETURN_VALUE
L1:
  LOAD_GLOBAL NULL + isinstance
  LOAD_FAST one
  LOAD_GLOBAL dict
  CALL 2
  POP_JUMP_IF_FALSE L2
  LOAD_GLOBAL NULL + _compare_dicts
  LOAD_FAST one
  LOAD_FAST two
  CALL 2
  RETURN_VALUE
L2:
  LOAD_GLOBAL NULL + isinstance
  LOAD_FAST one
  LOAD_GLOBAL SCALAR_TYPES
  CALL 2
  POP_JUMP_IF_FALSE L3
  LOAD_FAST one
  LOAD_FAST two
  COMPARE_OP ==
  RETURN_VALUE
L3:
  LOAD_FAST one
  POP_JUMP_IF_NOT_NONE L4
  LOAD_FAST one
  LOAD_FAST two
  IS_OP 0
  RETURN_VALUE
L4:
  LOAD_GLOBAL NULL + RuntimeError
  LOAD_CONST 'Not allowed type "{type}"'
  LOAD_ATTR NULL|self + format
  LOAD_GLOBAL NULL + type
  LOAD_FAST one
  CALL 1
  LOAD_ATTR __name__
  KW_NAMES ('type',)
  CALL 1
  CALL 1
  RAISE_VARARGS 1
END

def compare_schemas(one, two):
    """pass"""
    one = _normalize_string_type(one)
    two = _normalize_string_type(two)
    _assert_same_types(one, two)
    if isinstance(one, list):
        return _compare_lists(one, two)
    elif isinstance(one, dict):
        return _compare_dicts(one, two)
    elif isinstance(one, SCALAR_TYPES):
        return one == two
    elif one is None:
        return one is two
    else:
        raise RuntimeError('Not allowed type "{type}"'.format(type=type(one).__name__))


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code is_ecma_regex>
  MAKE_FUNCTION 0
  STORE_NAME is_ecma_regex
  RETURN_CONST None
END
CODE is_ecma_regex(regex)
  DOC 'pass'
  RESUME 0
  LOAD_FAST regex
  LOAD_ATTR NULL|self + split
  LOAD_CONST '/'
  CALL 1
  STORE_FAST parts
  LOAD_GLOBAL NULL + len
  LOAD_FAST parts
  CALL 1
  LOAD_CONST 1
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L1
  RETURN_CONST False
L1:
  LOAD_GLOBAL NULL + len
  LOAD_FAST parts
  CALL 1
  LOAD_CONST 3
  COMPARE_OP <
  POP_JUMP_IF_FALSE L2
  LOAD_GLOBAL NULL + ValueError
  LOAD_CONST "Given regex isn't ECMA regex nor Python regex."
  CALL 1
  RAISE_VARARGS 1
L2:
  LOAD_FAST parts
  LOAD_ATTR NULL|self + pop
  CALL 0
  POP_TOP
  LOAD_FAST parts
  LOAD_ATTR NULL|self + append
  LOAD_CONST ''
  CALL 1
  POP_TOP
  LOAD_CONST '/'
  LOAD_ATTR NULL|self + join
  LOAD_FAST parts
  CALL 1
  STORE_FAST raw_regex
  LOAD_FAST raw_regex
  LOAD_ATTR NULL|self + startswith
  LOAD_CONST '/'
  CALL 1
  POP_JUMP_IF_FALSE L3
  LOAD_FAST raw_regex
  LOAD_ATTR NULL|self + endswith
  LOAD_CONST '/'
  CALL 1
  POP_JUMP_IF_FALSE L3
  RETURN_CONST True
L3:
  RETURN_CONST False
END

def is_ecma_regex(regex):
    """pass"""
    parts = regex.split('/')
    if len(parts) == 1:
        return False
    if len(parts) < 3:
        raise ValueError("Given regex isn't ECMA regex nor Python regex.")
    parts.pop()
    parts.append('')
    raw_regex = '/'.join(parts)
    if raw_regex.startswith('/') and raw_regex.endswith('/'):
        return True
    return False


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code convert_ecma_regex_to_python>
  MAKE_FUNCTION 0
  STORE_NAME convert_ecma_regex_to_python
  RETURN_CONST None
END
CODE convert_ecma_regex_to_python(value)
  DOC 'pass'
  RESUME 0
  LOAD_GLOBAL NULL + is_ecma_regex
  LOAD_FAST value
  CALL 1
  POP_JUMP_IF_TRUE L1
  LOAD_GLOBAL NULL + PythonRegex
  LOAD_FAST value
  BUILD_LIST 0
  CALL 2
  RETURN_VALUE
L1:
  LOAD_FAST value
  LOAD_ATTR NULL|self + split
  LOAD_CONST '/'
  CALL 1
  STORE_FAST parts
  LOAD_FAST parts
  LOAD_ATTR NULL|self + pop
  CALL 0
  STORE_FAST flags
  NOP
L2:
  LOAD_FAST flags
  GET_ITER
  LOAD_FAST_AND_CLEAR f
  SWAP 2
L3:
  BUILD_LIST 0
  SWAP 2
L4:
  FOR_ITER L5
  STORE_FAST f
  LOAD_GLOBAL ECMA_TO_PYTHON_FLAGS
  LOAD_FAST f
  BINARY_SUBSCR
  LIST_APPEND 2
  JUMP_BACKWARD L4
L5:
  END_FOR
L6:
  STORE_FAST result_flags
  STORE_FAST f
L7:
  LOAD_GLOBAL NULL + PythonRegex
  LOAD_CONST '/'
  LOAD_ATTR NULL|self + join
  LOAD_FAST parts
  LOAD_CONST 1
  LOAD_CONST None
  BINARY_SLICE
  CALL 1
  LOAD_FAST result_flags
  CALL 2
  RETURN_VALUE
L8:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST f
  RERAISE 0
L9:
  PUSH_EXC_INFO
  LOAD_GLOBAL KeyError
  CHECK_EXC_MATCH
  POP_JUMP_IF_FALSE L10
  POP_TOP
  LOAD_GLOBAL NULL + ValueError
  LOAD_CONST 'Wrong flags "{}".'
  LOAD_ATTR NULL|self + format
  LOAD_FAST flags
  CALL 1
  CALL 1
  RAISE_VARARGS 1
L10:
  RERAISE 0
L11:
  COPY 3
  POP_EXCEPT
  RERAISE 1
  EXC try=L2..L3 -> handler=L9 depth=0 lasti=False
  EXC try=L3..L6 -> handler=L8 depth=2 lasti=False
  EXC try=L6..L7 -> handler=L9 depth=0 lasti=False
  EXC try=L8..L9 -> handler=L9 depth=0 lasti=False
  EXC try=L9..L11 -> handler=L11 depth=1 lasti=True
END

def convert_ecma_regex_to_python(value):
    """pass"""
    if not is_ecma_regex(value):
        return PythonRegex(value, [])
    parts = value.split('/')
    flags = parts.pop()
    try:
        result_flags = [ECMA_TO_PYTHON_FLAGS[f] for f in flags]
    except KeyError:
        raise ValueError('Wrong flags "{}".'.format(flags))
    return PythonRegex('/'.join(parts[1:]), result_flags)


Input:
CODE <module>()
  RESUME 0
  BUILD_LIST 0
  BUILD_TUPLE 1
  LOAD_CONST <code convert_python_regex_to_ecma>
  MAKE_FUNCTION defaults
  STORE_NAME convert_python_regex_to_ecma
  RETURN_CONST None
END
CODE convert_python_regex_to_ecma(value, flags)
  DOC 'pass'
  RESUME 0
  LOAD_GLOBAL NULL + is_ecma_regex
  LOAD_FAST value
  CALL 1
  POP_JUMP_IF_FALSE L1
  LOAD_FAST value
  RETURN_VALUE
L1:
  LOAD_FAST flags
  GET_ITER
  LOAD_FAST_AND_CLEAR f
  SWAP 2
L2:
  BUILD_LIST 0
  SWAP 2
L3:
  FOR_ITER L4
  STORE_FAST f
  LOAD_GLOBAL PYTHON_TO_ECMA_FLAGS
  LOAD_FAST f
  BINARY_SUBSCR
  LIST_APPEND 2
  JUMP_BACKWARD L3
L4:
  END_FOR
L5:
  STORE_FAST result_flags
  STORE_FAST f
  LOAD_CONST ''
  LOAD_ATTR NULL|self + join
  LOAD_FAST result_flags
  CALL 1
  STORE_FAST result_flags
  LOAD_CONST '/{value}/{flags}'
  LOAD_ATTR NULL|self + format
  LOAD_FAST value
  LOAD_FAST result_flags
  KW_NAMES ('value', 'flags')
  CALL 2
  RETURN_VALUE
L6:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST f
  RERAISE 0
  EXC try=L2..L5 -> handler=L6 depth=2 lasti=False
END

def convert_python_regex_to_ecma(value, flags=[]):
    """pass"""
    if is_ecma_regex(value):
        return value
    result_flags = [PYTHON_TO_ECMA_FLAGS[f] for f in flags]
    result_flags = ''.join(result_flags)
    return '/{value}/{flags}'.format(value=value, flags=result_flags)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code populate>
  MAKE_FUNCTION 0
  STORE_NAME populate
  RETURN_CONST None
END
CODE populate(self, **values)
  DOC 'pass'
  RESUME 0
  LOAD_FAST values
  LOAD_ATTR NULL|self + copy
  CALL 0
  STORE_FAST values
  LOAD_GLOBAL NULL + list
  LOAD_FAST self
  LOAD_ATTR NULL|self + iterate_with_name
  CALL 0
  CALL 1
  STORE_FAST fields
  LOAD_FAST fields
  GET_ITER
L1:
  FOR_ITER L3
  UNPACK_SEQUENCE 3
  STORE_FAST _
  STORE_FAST structure_name
  STORE_FAST field
  LOAD_FAST structure_name
  LOAD_FAST values
  CONTAINS_OP 0
  POP_JUMP_IF_TRUE L2
  JUMP_BACKWARD L1
L2:
  LOAD_FAST field
  LOAD_ATTR NULL|self + __set__
  LOAD_FAST self
  LOAD_FAST values
  LOAD_ATTR NULL|self + pop
  LOAD_FAST structure_name
  CALL 1
  CALL 2
  POP_TOP
  JUMP_BACKWARD L1
L3:
  END_FOR
  LOAD_FAST fields
  GET_ITER
L4:
  FOR_ITER L6
  UNPACK_SEQUENCE 3
  STORE_FAST name
  STORE_FAST _
  STORE_FAST field
  LOAD_FAST name
  LOAD_FAST values
  CONTAINS_OP 0
  POP_JUMP_IF_TRUE L5
  JUMP_BACKWARD L4
L5:
  LOAD_FAST field
  LOAD_ATTR NULL|self + __set__
  LOAD_FAST self
  LOAD_FAST values
  LOAD_ATTR NULL|self + pop
  LOAD_FAST name
  CALL 1
  CALL 2
  POP_TOP
  JUMP_BACKWARD L4
L6:
  END_FOR
  RETURN_CONST None
END

def populate(self, **values):
    """pass"""
    values = values.copy()
    fields = list(self.iterate_with_name())
    for _, structure_name, field in fields:
        if structure_name in values:
            field.__set__(self, values.pop(structure_name))
    for name, _, field in fields:
        if name in values:
            field.__set__(self, values.pop(name))


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code get_field>
  MAKE_FUNCTION 0
  STORE_NAME get_field
  RETURN_CONST None
END
CODE get_field(self, field_name)
  DOC 'pass'
  RESUME 0
  LOAD_FAST self
  GET_ITER
L1:
  FOR_ITER L3
  UNPACK_SEQUENCE 2
  STORE_FAST attr_name
  STORE_FAST field
  LOAD_FAST field_name
  LOAD_FAST attr_name
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L2
  JUMP_BACKWARD L1
L2:
  LOAD_FAST field
  SWAP 2
  POP_TOP
  RETURN_VALUE
L3:
  END_FOR
  LOAD_GLOBAL errors
  LOAD_ATTR NULL|self + FieldNotFound
  LOAD_CONST 'Field not found'
  LOAD_FAST field_name
  CALL 2
  RAISE_VARARGS 1
END

def get_field(self, field_name):
    """pass"""
    for attr_name, field in self:
        if field_name == attr_name:
            return field
    raise errors.FieldNotFound('Field not found', field_name)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST (False,)
  LOAD_CONST <code write>
  MAKE_FUNCTION defaults
  STORE_NAME write
  RETURN_CONST None
END
CODE write(self, rows, keyed)
  DOC 'pass'
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_FAST rows
  GET_ITER
L2:
  FOR_ITER L13
  STORE_FAST row
  LOAD_FAST row
  STORE_FAST keyed_row
  LOAD_FAST keyed
  POP_JUMP_IF_TRUE L3
  LOAD_GLOBAL NULL + dict
  LOAD_GLOBAL NULL + zip
  LOAD_FAST self
  LOAD_ATTR __schema
  LOAD_ATTR field_names
  LOAD_FAST row
  CALL 2
  CALL 1
  STORE_FAST keyed_row
L3:
  LOAD_FAST self
  LOAD_ATTR NULL|self + __convert_row
  LOAD_FAST keyed_row
  CALL 1
  STORE_FAST keyed_row
  LOAD_FAST self
  LOAD_ATTR NULL|self + __check_existing
  LOAD_FAST keyed_row
  CALL 1
  POP_JUMP_IF_FALSE L8
  LOAD_FAST self
  LOAD_ATTR NULL|self + __insert
  CALL 0
  GET_ITER
L4:
  FOR_ITER L5
  STORE_FAST wr
  LOAD_FAST wr
  YIELD_VALUE 1
  RESUME 1
  POP_TOP
  JUMP_BACKWARD L4
L5:
  END_FOR
  LOAD_FAST self
  LOAD_ATTR NULL|self + __update
  LOAD_FAST keyed_row
  CALL 1
  STORE_FAST ret
  LOAD_FAST ret
  POP_JUMP_IF_NONE L8
  LOAD_GLOBAL NULL + WrittenRow
  LOAD_FAST keyed_row
  LOAD_CONST True
  LOAD_FAST self
  LOAD_ATTR __autoincrement
  POP_JUMP_IF_FALSE L6
  LOAD_FAST ret
  JUMP_FORWARD L7
L6:
  LOAD_CONST None
L7:
  CALL 3
  YIELD_VALUE 1
  RESUME 1
  POP_TOP
  JUMP_BACKWARD L2
L8:
  LOAD_FAST self
  LOAD_ATTR __buffer
  LOAD_ATTR NULL|self + append
  LOAD_FAST keyed_row
  CALL 1
  POP_TOP
  LOAD_GLOBAL NULL + len
  LOAD_FAST self
  LOAD_ATTR __buffer
  CALL 1
  LOAD_GLOBAL BUFFER_SIZE
  COMPARE_OP >
  POP_JUMP_IF_TRUE L10
L9:
  JUMP_BACKWARD L2
L10:
  LOAD_FAST self
  LOAD_ATTR NULL|self + __insert
  CALL 0
  GET_ITER
L11:
  FOR_ITER L12
  STORE_FAST wr
  LOAD_FAST wr
  YIELD_VALUE 1
  RESUME 1
  POP_TOP
  JUMP_BACKWARD L11
L12:
  END_FOR
  JUMP_BACKWARD L2
L13:
  END_FOR
  LOAD_FAST self
  LOAD_ATTR NULL|self + __insert
  CALL 0
  GET_ITER
L14:
  FOR_ITER L15
  STORE_FAST wr
  LOAD_FAST wr
  YIELD_VALUE 1
  RESUME 1
  POP_TOP
  JUMP_BACKWARD L14
L15:
  END_FOR
  RETURN_CONST None
L16:
  CALL_INTRINSIC_1 INTRINSIC_STOPITERATION_ERROR
  RERAISE 1
  EXC try=L1..L9 -> handler=L16 depth=0 lasti=True
  EXC try=L10..L16 -> handler=L16 depth=0 lasti=True
END

def write(self, rows, keyed=False):
    """pass"""
    for row in rows:
        keyed_row = row
        if not keyed:
            keyed_row = dict(zip(self.__schema.field_names, row))
        keyed_row = self.__convert_row(keyed_row)
        if self.__check_existing(keyed_row):
            for wr in self.__insert():
                yield wr
            ret = self.__update(keyed_row)
            if ret is not None:
                yield WrittenRow(keyed_row, True, ret if self.__autoincrement else None)
                continue
        self.__buffer.append(keyed_row)
        if len(self.__buffer) > BUFFER_SIZE:
            for wr in self.__insert():
                yield wr
    for wr in self.__insert():
        yield wr


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code __prepare_bloom>
  MAKE_FUNCTION 0
  STORE_NAME __prepare_bloom
  RETURN_CONST None
END
CODE __prepare_bloom(self)
  DOC 'pass'
  RESUME 0
  LOAD_GLOBAL pybloom_live
  LOAD_ATTR NULL|self + ScalableBloomFilter
  CALL 0
  LOAD_FAST self
  STORE_ATTR __bloom
  LOAD_FAST self
  LOAD_ATTR __update_keys
  GET_ITER
  LOAD_FAST_AND_CLEAR key
  SWAP 2
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L3
  STORE_FAST key
  LOAD_GLOBAL NULL + getattr
  LOAD_FAST self
  LOAD_ATTR __table
  LOAD_ATTR c
  LOAD_FAST key
  CALL 2
  LIST_APPEND 2
  JUMP_BACKWARD L2
L3:
  END_FOR
L4:
  STORE_FAST columns
  STORE_FAST key
  LOAD_GLOBAL NULL + select
  LOAD_FAST columns
  CALL 1
  LOAD_ATTR NULL|self + execution_options
  LOAD_CONST True
  KW_NAMES ('stream_results',)
  CALL 1
  LOAD_ATTR NULL|self + execute
  CALL 0
  STORE_FAST keys
  LOAD_FAST keys
  GET_ITER
L5:
  FOR_ITER L6
  STORE_FAST key
  LOAD_FAST self
  LOAD_ATTR __bloom
  LOAD_ATTR NULL|self + add
  LOAD_GLOBAL NULL + tuple
  LOAD_FAST key
  CALL 1
  CALL 1
  POP_TOP
  JUMP_BACKWARD L5
L6:
  END_FOR
  RETURN_CONST None
L7:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST key
  RERAISE 0
  EXC try=L1..L4 -> handler=L7 depth=2 lasti=False
END

def __prepare_bloom(self):
    """pass"""
    self.__bloom = pybloom_live.ScalableBloomFilter()
    columns = [getattr(self.__table.c, key) for key in self.__update_keys]
    keys = select(columns).execution_options(stream_results=True).execute()
    for key in keys:
        self.__bloom.add(tuple(key))


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code __insert>
  MAKE_FUNCTION 0
  STORE_NAME __insert
  RETURN_CONST None
END
CODE __insert(self)
  DOC 'pass'
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_GLOBAL NULL + len
  LOAD_FAST self
  LOAD_ATTR __buffer
  CALL 1
  LOAD_CONST 0
  COMPARE_OP >
  EXTENDED_ARG 1
  POP_JUMP_IF_FALSE L8
  LOAD_FAST self
  LOAD_ATTR __table
  LOAD_ATTR NULL|self + insert
  CALL 0
  STORE_FAST statement
  LOAD_FAST self
  LOAD_ATTR __autoincrement
  POP_JUMP_IF_FALSE L4
  LOAD_FAST statement
  LOAD_ATTR NULL|self + returning
  LOAD_GLOBAL NULL + getattr
  LOAD_FAST self
  LOAD_ATTR __table
  LOAD_ATTR c
  LOAD_FAST self
  LOAD_ATTR __autoincrement
  CALL 2
  CALL 1
  STORE_FAST statement
  LOAD_FAST statement
  LOAD_ATTR NULL|self + values
  LOAD_FAST self
  LOAD_ATTR __buffer
  CALL 1
  STORE_FAST statement
  LOAD_FAST statement
  LOAD_ATTR NULL|self + execute
  CALL 0
  STORE_FAST res
  LOAD_FAST res
  GET_ITER
L2:
  FOR_ITER L3
  UNPACK_SEQUENCE 1
  STORE_FAST id
  LOAD_FAST self
  LOAD_ATTR __buffer
  LOAD_ATTR NULL|self + pop
  LOAD_CONST 0
  CALL 1
  STORE_FAST row
  LOAD_GLOBAL NULL + WrittenRow
  LOAD_FAST row
  LOAD_CONST False
  LOAD_FAST id
  CALL 3
  YIELD_VALUE 1
  RESUME 1
  POP_TOP
  JUMP_BACKWARD L2
L3:
  END_FOR
  JUMP_FORWARD L7
L4:
  LOAD_FAST statement
  LOAD_ATTR NULL|self + execute
  LOAD_FAST self
  LOAD_ATTR __buffer
  CALL 1
  POP_TOP
  LOAD_FAST self
  LOAD_ATTR __buffer
  GET_ITER
L5:
  FOR_ITER L6
  STORE_FAST row
  LOAD_GLOBAL NULL + WrittenRow
  LOAD_FAST row
  LOAD_CONST False
  LOAD_CONST None
  CALL 3
  YIELD_VALUE 1
  RESUME 1
  POP_TOP
  JUMP_BACKWARD L5
L6:
  END_FOR
L7:
  BUILD_LIST 0
  LOAD_FAST self
  STORE_ATTR __buffer
  RETURN_CONST None
L8:
  RETURN_CONST None
L9:
  CALL_INTRINSIC_1 INTRINSIC_STOPITERATION_ERROR
  RERAISE 1
  EXC try=L1..L9 -> handler=L9 depth=0 lasti=True
END

def __insert(self):
    """pass"""
    if len(self.__buffer) > 0:
        statement = self.__table.insert()
        if self.__autoincrement:
            statement = statement.returning(getattr(self.__table.c, self.__autoincrement))
            statement = statement.values(self.__buffer)
            res = statement.execute()
            for id, in res:
                row = self.__buffer.pop(0)
                yield WrittenRow(row, False, id)
        else:
            statement.execute(self.__buffer)
            for row in self.__buffer:
                yield WrittenRow(row, False, None)
        self.__buffer = []


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code __update>
  MAKE_FUNCTION 0
  STORE_NAME __update
  RETURN_CONST None
END
CODE __update(self, row)
  DOC 'pass'
  RESUME 0
  LOAD_FAST self
  LOAD_ATTR __table
  LOAD_ATTR NULL|self + update
  CALL 0
  LOAD_ATTR NULL|self + values
  LOAD_FAST row
  CALL 1
  STORE_FAST expr
  LOAD_FAST self
  LOAD_ATTR __update_keys
  GET_ITER
L1:
  FOR_ITER L2
  STORE_FAST key
  LOAD_FAST expr
  LOAD_ATTR NULL|self + where
  LOAD_GLOBAL NULL + getattr
  LOAD_FAST self
  LOAD_ATTR __table
  LOAD_ATTR c
  LOAD_FAST key
  CALL 2
  LOAD_FAST row
  LOAD_FAST key
  BINARY_SUBSCR
  COMPARE_OP ==
  CALL 1
  STORE_FAST expr
  JUMP_BACKWARD L1
L2:
  END_FOR
  LOAD_FAST self
  LOAD_ATTR __autoincrement
  POP_JUMP_IF_FALSE L3
  LOAD_FAST expr
  LOAD_ATTR NULL|self + returning
  LOAD_GLOBAL NULL + getattr
  LOAD_FAST self
  LOAD_ATTR __table
  LOAD_ATTR c
  LOAD_FAST self
  LOAD_ATTR __autoincrement
  CALL 2
  CALL 1
  STORE_FAST expr
L3:
  LOAD_FAST expr
  LOAD_ATTR NULL|self + execute
  CALL 0
  STORE_FAST res
  LOAD_FAST res
  LOAD_ATTR rowcount
  LOAD_CONST 0
  COMPARE_OP >
  POP_JUMP_IF_FALSE L5
  LOAD_FAST self
  LOAD_ATTR __autoincrement
  POP_JUMP_IF_FALSE L4
  LOAD_GLOBAL NULL + next
  LOAD_GLOBAL NULL + iter
  LOAD_FAST res
  CALL 1
  CALL 1
  STORE_FAST first
  LOAD_FAST first
  LOAD_CONST 0
  BINARY_SUBSCR
  STORE_FAST last_row_id
  LOAD_FAST last_row_id
  RETURN_VALUE
L4:
  RETURN_CONST 0
L5:
  RETURN_CONST None
END

def __update(self, row):
    """pass"""
    expr = self.__table.update().values(row)
    for key in self.__update_keys:
        expr = expr.where(getattr(self.__table.c, key) == row[key])
    if self.__autoincrement:
        expr = expr.returning(getattr(self.__table.c, self.__autoincrement))
    res = expr.execute()
    if res.rowcount > 0:
        if self.__autoincrement:
            first = next(iter(res))
            last_row_id = first[0]
            return last_row_id
        return 0
    return None


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code __check_existing>
  MAKE_FUNCTION 0
  STORE_NAME __check_existing
  RETURN_CONST None
END
CODE __check_existing(self, row)
  DOC 'pass'
  MAKE_CELL row
  RESUME 0
  LOAD_FAST self
  LOAD_ATTR __update_keys
  POP_JUMP_IF_NONE L2
  LOAD_GLOBAL NULL + tuple
  LOAD_CLOSURE row
  BUILD_TUPLE 1
  LOAD_CONST <code __check_existing.<locals>.<genexpr>>
  MAKE_FUNCTION closure
  LOAD_FAST self
  LOAD_ATTR __update_keys
  GET_ITER
  CALL 0
  CALL 1
  STORE_FAST key
  LOAD_FAST key
  LOAD_FAST self
  LOAD_ATTR __bloom
  CONTAINS_OP 0
  POP_JUMP_IF_FALSE L1
  RETURN_CONST True
L1:
  LOAD_FAST self
  LOAD_ATTR __bloom
  LOAD_ATTR NULL|self + add
  LOAD_FAST key
  CALL 1
  POP_TOP
  RETURN_CONST False
L2:
  RETURN_CONST False
END
CODE __check_existing.<locals>.<genexpr>(.0)
  COPY_FREE_VARS 1
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_FAST .0
L2:
  FOR_ITER L3
  STORE_FAST key
  LOAD_DEREF row
  LOAD_FAST key
  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 __check_existing(self, row):
    """pass"""
    if self.__update_keys is not None:
        key = tuple((row[key] for key in self.__update_keys))
        if key in self.__bloom:
            return True
        self.__bloom.add(key)
        return False
    return False


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code buckets>
  MAKE_FUNCTION 0
  STORE_NAME buckets
  RETURN_CONST None
END
CODE buckets(self)
  DOC 'pass'
  RESUME 0
  BUILD_LIST 0
  STORE_FAST buckets
  LOAD_FAST self
  LOAD_ATTR __metadata
  LOAD_ATTR sorted_tables
  GET_ITER
L1:
  FOR_ITER L3
  STORE_FAST table
  LOAD_FAST self
  LOAD_ATTR __mapper
  LOAD_ATTR NULL|self + restore_bucket
  LOAD_FAST table
  LOAD_ATTR name
  CALL 1
  STORE_FAST bucket
  LOAD_FAST bucket
  POP_JUMP_IF_NOT_NONE L2
  JUMP_BACKWARD L1
L2:
  LOAD_FAST buckets
  LOAD_ATTR NULL|self + append
  LOAD_FAST bucket
  CALL 1
  POP_TOP
  JUMP_BACKWARD L1
L3:
  END_FOR
  LOAD_FAST buckets
  RETURN_VALUE
END

def buckets(self):
    """pass"""
    buckets = []
    for table in self.__metadata.sorted_tables:
        bucket = self.__mapper.restore_bucket(table.name)
        if bucket is not None:
            buckets.append(bucket)
    return buckets


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST (0,)
  LOAD_CONST <code open_hierarchy>
  MAKE_FUNCTION defaults
  STORE_NAME open_hierarchy
  RETURN_CONST None
END
CODE open_hierarchy(self, path, relative_to_object_id, object_id, create_file_type)
  DOC 'pass'
  RESUME 0
  NOP
L1:
  LOAD_FAST self
  LOAD_ATTR process
  LOAD_ATTR NULL|self + OpenHierarchy
  LOAD_FAST path
  LOAD_FAST relative_to_object_id
  LOAD_CONST ''
  LOAD_FAST create_file_type
  CALL 4
L2:
  RETURN_VALUE
L3:
  PUSH_EXC_INFO
  LOAD_GLOBAL Exception
  CHECK_EXC_MATCH
  POP_JUMP_IF_FALSE L7
  STORE_FAST e
L4:
  LOAD_GLOBAL NULL + print
  LOAD_FAST e
  CALL 1
  POP_TOP
  LOAD_GLOBAL NULL + print
  LOAD_CONST 'Could not Open Hierarchy'
  CALL 1
  POP_TOP
L5:
  POP_EXCEPT
  LOAD_CONST None
  STORE_FAST e
  DELETE_FAST e
  RETURN_CONST None
L6:
  LOAD_CONST None
  STORE_FAST e
  DELETE_FAST e
  RERAISE 1
L7:
  RERAISE 0
L8:
  COPY 3
  POP_EXCEPT
  RERAISE 1
  EXC try=L1..L2 -> handler=L3 depth=0 lasti=False
  EXC try=L3..L4 -> handler=L8 depth=1 lasti=True
  EXC try=L4..L5 -> handler=L6 depth=1 lasti=True
  EXC try=L6..L8 -> handler=L8 depth=1 lasti=True
END

def open_hierarchy(self, path, relative_to_object_id, object_id, create_file_type=0):
    """pass"""
    try:
        return self.process.OpenHierarchy(path, relative_to_object_id, '', create_file_type)
    except Exception as e:
        print(e)
        print('Could not Open Hierarchy')


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST (0,)
  LOAD_CONST <code create_new_page>
  MAKE_FUNCTION defaults
  STORE_NAME create_new_page
  RETURN_CONST None
END
CODE create_new_page(self, section_id, new_page_style)
  DOC 'pass'
  RESUME 0
  NOP
L1:
  LOAD_FAST self
  LOAD_ATTR process
  LOAD_ATTR NULL|self + CreateNewPage
  LOAD_FAST section_id
  LOAD_CONST ''
  LOAD_FAST new_page_style
  CALL 3
  POP_TOP
L2:
  RETURN_CONST None
L3:
  PUSH_EXC_INFO
  LOAD_GLOBAL Exception
  CHECK_EXC_MATCH
  POP_JUMP_IF_FALSE L7
  STORE_FAST e
L4:
  LOAD_GLOBAL NULL + print
  LOAD_FAST e
  CALL 1
  POP_TOP
  LOAD_GLOBAL NULL + print
  LOAD_CONST 'Unable to create the page'
  CALL 1
  POP_TOP
L5:
  POP_EXCEPT
  LOAD_CONST None
  STORE_FAST e
  DELETE_FAST e
  RETURN_CONST None
L6:
  LOAD_CONST None
  STORE_FAST e
  DELETE_FAST e
  RERAISE 1
L7:
  RERAISE 0
L8:
  COPY 3
  POP_EXCEPT
  RERAISE 1
  EXC try=L1..L2 -> handler=L3 depth=0 lasti=False
  EXC try=L3..L4 -> handler=L8 depth=1 lasti=True
  EXC try=L4..L5 -> handler=L6 depth=1 lasti=True
  EXC try=L6..L8 -> handler=L8 depth=1 lasti=True
END

def create_new_page(self, section_id, new_page_style=0):
    """pass"""
    try:
        self.process.CreateNewPage(section_id, '', new_page_style)
    except Exception as e:
        print(e)
        print('Unable to create the page')


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST (0,)
  LOAD_CONST <code get_page_content>
  MAKE_FUNCTION defaults
  STORE_NAME get_page_content
  RETURN_CONST None
END
CODE get_page_content(self, page_id, page_info)
  DOC 'pass'
  RESUME 0
  NOP
L1:
  LOAD_FAST self
  LOAD_ATTR process
  LOAD_ATTR NULL|self + GetPageContent
  LOAD_FAST page_id
  LOAD_CONST ''
  LOAD_FAST page_info
  CALL 3
L2:
  RETURN_VALUE
L3:
  PUSH_EXC_INFO
  LOAD_GLOBAL Exception
  CHECK_EXC_MATCH
  POP_JUMP_IF_FALSE L7
  STORE_FAST e
L4:
  LOAD_GLOBAL NULL + print
  LOAD_FAST e
  CALL 1
  POP_TOP
  LOAD_GLOBAL NULL + print
  LOAD_CONST 'Could not get Page Content'
  CALL 1
  POP_TOP
L5:
  POP_EXCEPT
  LOAD_CONST None
  STORE_FAST e
  DELETE_FAST e
  RETURN_CONST None
L6:
  LOAD_CONST None
  STORE_FAST e
  DELETE_FAST e
  RERAISE 1
L7:
  RERAISE 0
L8:
  COPY 3
  POP_EXCEPT
  RERAISE 1
  EXC try=L1..L2 -> handler=L3 depth=0 lasti=False
  EXC try=L3..L4 -> handler=L8 depth=1 lasti=True
  EXC try=L4..L5 -> handler=L6 depth=1 lasti=True
  EXC try=L6..L8 -> handler=L8 depth=1 lasti=True
END

def get_page_content(self, page_id, page_info=0):
    """pass"""
    try:
        return self.process.GetPageContent(page_id, '', page_info)
    except Exception as e:
        print(e)
        print('Could not get Page Content')


Input:
CODE <module>()
  DOC ''
  RESUME 0
  LOAD_CONST ('',)
  LOAD_CONST <code publish>
  MAKE_FUNCTION defaults
  STORE_NAME publish
  RETURN_CONST None
END
CODE publish(self, hierarchy_id, target_file_path, publish_format, clsid_of_exporter)
  DOC 'pass'
  RESUME 0
  NOP
L1:
  LOAD_FAST self
  LOAD_ATTR process
  LOAD_ATTR NULL|self + Publish
  LOAD_FAST hierarchy_id
  LOAD_FAST target_file_path
  LOAD_FAST publish_format
  LOAD_FAST clsid_of_exporter
  CALL 4
  POP_TOP
L2:
  RETURN_CONST None
L3:
  PUSH_EXC_INFO
  LOAD_GLOBAL Exception
  CHECK_EXC_MATCH
  POP_JUMP_IF_FALSE L7
  STORE_FAST e
L4:
  LOAD_GLOBAL NULL + print
  LOAD_FAST e
  CALL 1
  POP_TOP
  LOAD_GLOBAL NULL + print
  LOAD_CONST 'Could not Publish'
  CALL 1
  POP_TOP
L5:
  POP_EXCEPT
  LOAD_CONST None
  STORE_FAST e
  DELETE_FAST e
  RETURN_CONST None
L6:
  LOAD_CONST None
  STORE_FAST e
  DELETE_FAST e
  RERAISE 1
L7:
  RERAISE 0
L8:
  COPY 3
  POP_EXCEPT
  RERAISE 1
  EXC try=L1..L2 -> handler=L3 depth=0 lasti=False
  EXC try=L3..L4 -> handler=L8 depth=1 lasti=True
  EXC try=L4..L5 -> handler=L6 depth=1 lasti=True
  EXC try=L6..L8 -> handler=L8 depth=1 lasti=True
END

def publish(self, hierarchy_id, target_file_path, publish_format, clsid_of_exporter=''):
    """pass"""
    try:
        self.process.Publish(hierarchy_id, target_file_path, publish_format, clsid_of_exporter)
    except Exception as e:
        print(e)
        print('Could not Publish')


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST (0,)
  LOAD_CONST <code get_special_location>
  MAKE_FUNCTION defaults
  STORE_NAME get_special_location
  RETURN_CONST None
END
CODE get_special_location(self, special_location)
  DOC 'pass'
  RESUME 0
  NOP
L1:
  LOAD_FAST self
  LOAD_ATTR process
  LOAD_ATTR NULL|self + GetSpecialLocation
  LOAD_FAST special_location
  CALL 1
L2:
  RETURN_VALUE
L3:
  PUSH_EXC_INFO
  LOAD_GLOBAL Exception
  CHECK_EXC_MATCH
  POP_JUMP_IF_FALSE L7
  STORE_FAST e
L4:
  LOAD_GLOBAL NULL + print
  LOAD_FAST e
  CALL 1
  POP_TOP
  LOAD_GLOBAL NULL + print
  LOAD_CONST 'Could not retreive special location'
  CALL 1
  POP_TOP
L5:
  POP_EXCEPT
  LOAD_CONST None
  STORE_FAST e
  DELETE_FAST e
  RETURN_CONST None
L6:
  LOAD_CONST None
  STORE_FAST e
  DELETE_FAST e
  RERAISE 1
L7:
  RERAISE 0
L8:
  COPY 3
  POP_EXCEPT
  RERAISE 1
  EXC try=L1..L2 -> handler=L3 depth=0 lasti=False
  EXC try=L3..L4 -> handler=L8 depth=1 lasti=True
  EXC try=L4..L5 -> handler=L6 depth=1 lasti=True
  EXC try=L6..L8 -> handler=L8 depth=1 lasti=True
END

def get_special_location(self, special_location=0):
    """pass"""
    try:
        return self.process.GetSpecialLocation(special_location)
    except Exception as e:
        print(e)
        print('Could not retreive special location')


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code memory>
  MAKE_FUNCTION 0
  STORE_NAME memory
  RETURN_CONST None
END
CODE memory()
  DOC 'pass'
  RESUME 0
  LOAD_GLOBAL NULL + dict
  CALL 0
  STORE_FAST mem_info
  LOAD_GLOBAL psutil
  LOAD_ATTR NULL|self + virtual_memory
  CALL 0
  LOAD_ATTR NULL|self + _asdict
  CALL 0
  LOAD_ATTR NULL|self + items
  CALL 0
  GET_ITER
L1:
  FOR_ITER L2
  UNPACK_SEQUENCE 2
  STORE_FAST k
  STORE_FAST v
  LOAD_GLOBAL NULL + int
  LOAD_FAST v
  CALL 1
  LOAD_FAST mem_info
  LOAD_FAST k
  STORE_SUBSCR
  JUMP_BACKWARD L1
L2:
  END_FOR
  LOAD_FAST mem_info
  RETURN_VALUE
END

def memory():
    """pass"""
    mem_info = dict()
    for k, v in psutil.virtual_memory()._asdict().items():
        mem_info[k] = int(v)
    return mem_info


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code get_chunk_size>
  MAKE_FUNCTION 0
  STORE_NAME get_chunk_size
  RETURN_CONST None
END
CODE get_chunk_size(N, n)
  DOC 'pass'
  RESUME 0
  LOAD_GLOBAL NULL + memory
  CALL 0
  LOAD_CONST 'free'
  BINARY_SUBSCR
  STORE_FAST mem_free
  LOAD_FAST mem_free
  LOAD_CONST 60000000
  COMPARE_OP >
  POP_JUMP_IF_FALSE L1
  LOAD_GLOBAL NULL + int
  LOAD_FAST mem_free
  LOAD_CONST 10000000
  BINARY_OP -
  LOAD_CONST 1000
  BINARY_OP *
  LOAD_CONST 4
  LOAD_FAST n
  BINARY_OP *
  LOAD_FAST N
  BINARY_OP *
  BINARY_OP /
  CALL 1
  STORE_FAST chunk_size
  LOAD_FAST chunk_size
  RETURN_VALUE
L1:
  LOAD_FAST mem_free
  LOAD_CONST 40000000
  COMPARE_OP >
  POP_JUMP_IF_FALSE L2
  LOAD_GLOBAL NULL + int
  LOAD_FAST mem_free
  LOAD_CONST 7000000
  BINARY_OP -
  LOAD_CONST 1000
  BINARY_OP *
  LOAD_CONST 4
  LOAD_FAST n
  BINARY_OP *
  LOAD_FAST N
  BINARY_OP *
  BINARY_OP /
  CALL 1
  STORE_FAST chunk_size
  LOAD_FAST chunk_size
  RETURN_VALUE
L2:
  LOAD_FAST mem_free
  LOAD_CONST 14000000
  COMPARE_OP >
  POP_JUMP_IF_FALSE L3
  LOAD_GLOBAL NULL + int
  LOAD_FAST mem_free
  LOAD_CONST 2000000
  BINARY_OP -
  LOAD_CONST 1000
  BINARY_OP *
  LOAD_CONST 4
  LOAD_FAST n
  BINARY_OP *
  LOAD_FAST N
  BINARY_OP *
  BINARY_OP /
  CALL 1
  STORE_FAST chunk_size
  LOAD_FAST chunk_size
  RETURN_VALUE
L3:
  LOAD_FAST mem_free
  LOAD_CONST 8000000
  COMPARE_OP >
  POP_JUMP_IF_FALSE L4
  LOAD_GLOBAL NULL + int
  LOAD_FAST mem_free
  LOAD_CONST 1400000
  BINARY_OP -
  LOAD_CONST 1000
  BINARY_OP *
  LOAD_CONST 4
  LOAD_FAST n
  BINARY_OP *
  LOAD_FAST N
  BINARY_OP *
  BINARY_OP /
  CALL 1
  STORE_FAST chunk_size
  LOAD_FAST chunk_size
  RETURN_VALUE
L4:
  LOAD_FAST mem_free
  LOAD_CONST 2000000
  COMPARE_OP >
  POP_JUMP_IF_FALSE L5
  LOAD_GLOBAL NULL + int
  LOAD_FAST mem_free
  LOAD_CONST 900000
  BINARY_OP -
  LOAD_CONST 1000
  BINARY_OP *
  LOAD_CONST 4
  LOAD_FAST n
  BINARY_OP *
  LOAD_FAST N
  BINARY_OP *
  BINARY_OP /
  CALL 1
  STORE_FAST chunk_size
  LOAD_FAST chunk_size
  RETURN_VALUE
L5:
  LOAD_FAST mem_free
  LOAD_CONST 1000000
  COMPARE_OP >
  POP_JUMP_IF_FALSE L6
  LOAD_GLOBAL NULL + int
  LOAD_FAST mem_free
  LOAD_CONST 400000
  BINARY_OP -
  LOAD_CONST 1000
  BINARY_OP *
  LOAD_CONST 4
  LOAD_FAST n
  BINARY_OP *
  LOAD_FAST N
  BINARY_OP *
  BINARY_OP /
  CALL 1
  STORE_FAST chunk_size
  LOAD_FAST chunk_size
  RETURN_VALUE
L6:
  LOAD_GLOBAL NULL + print
  LOAD_CONST '\nERROR: Cluster_Ensembles: get_chunk_size: this machine does not have enough free memory resources to perform ensemble clustering.\n'
  CALL 1
  POP_TOP
  LOAD_GLOBAL sys
  LOAD_ATTR NULL|self + exit
  LOAD_CONST 1
  CALL 1
  POP_TOP
  RETURN_CONST None
END

def get_chunk_size(N, n):
    """pass"""
    mem_free = memory()['free']
    if mem_free > 60000000:
        chunk_size = int((mem_free - 10000000) * 1000 / (4 * n * N))
        return chunk_size
    elif mem_free > 40000000:
        chunk_size = int((mem_free - 7000000) * 1000 / (4 * n * N))
        return chunk_size
    elif mem_free > 14000000:
        chunk_size = int((mem_free - 2000000) * 1000 / (4 * n * N))
        return chunk_size
    elif mem_free > 8000000:
        chunk_size = int((mem_free - 1400000) * 1000 / (4 * n * N))
        return chunk_size
    elif mem_free > 2000000:
        chunk_size = int((mem_free - 900000) * 1000 / (4 * n * N))
        return chunk_size
    elif mem_free > 1000000:
        chunk_size = int((mem_free - 400000) * 1000 / (4 * n * N))
        return chunk_size
    else:
        print('\nERROR: Cluster_Ensembles: get_chunk_size: this machine does not have enough free memory resources to perform ensemble clustering.\n')
        sys.exit(1)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code get_compression_filter>
  MAKE_FUNCTION 0
  STORE_NAME get_compression_filter
  RETURN_CONST None
END
CODE get_compression_filter(byte_counts)
  DOC 'pass'
  RESUME 0
  LOAD_GLOBAL NULL + isinstance
  LOAD_FAST byte_counts
  LOAD_GLOBAL numbers
  LOAD_ATTR Integral
  CALL 2
  POP_JUMP_IF_FALSE L1
  LOAD_FAST byte_counts
  LOAD_CONST 0
  COMPARE_OP >
  POP_JUMP_IF_TRUE L2
L1:
  LOAD_ASSERTION_ERROR
  RAISE_VARARGS 1
L2:
  LOAD_CONST 2
  LOAD_FAST byte_counts
  BINARY_OP *
  LOAD_CONST 1000
  LOAD_GLOBAL NULL + memory
  CALL 0
  LOAD_CONST 'free'
  BINARY_SUBSCR
  BINARY_OP *
  COMPARE_OP >
  POP_JUMP_IF_FALSE L5
  NOP
L3:
  LOAD_GLOBAL tables
  LOAD_ATTR NULL|self + filters
  LOAD_CONST 5
  LOAD_CONST 'blosc'
  LOAD_CONST True
  LOAD_CONST 6
  KW_NAMES ('complevel', 'complib', 'shuffle', 'least_significant_digit')
  CALL 4
  STORE_FAST FILTERS
L4:
  LOAD_FAST FILTERS
  RETURN_VALUE
L5:
  LOAD_CONST None
  STORE_FAST FILTERS
  LOAD_FAST FILTERS
  RETURN_VALUE
L6:
  PUSH_EXC_INFO
  LOAD_GLOBAL tables
  LOAD_ATTR FiltersWarning
  CHECK_EXC_MATCH
  POP_JUMP_IF_FALSE L8
  POP_TOP
  LOAD_GLOBAL tables
  LOAD_ATTR NULL|self + filters
  LOAD_CONST 5
  LOAD_CONST 'lzo'
  LOAD_CONST True
  LOAD_CONST 6
  KW_NAMES ('complevel', 'complib', 'shuffle', 'least_significant_digit')
  CALL 4
  STORE_FAST FILTERS
L7:
  POP_EXCEPT
  LOAD_FAST FILTERS
  RETURN_VALUE
L8:
  RERAISE 0
L9:
  COPY 3
  POP_EXCEPT
  RERAISE 1
  EXC try=L3..L4 -> handler=L6 depth=0 lasti=False
  EXC try=L6..L7 -> handler=L9 depth=1 lasti=True
  EXC try=L8..L9 -> handler=L9 depth=1 lasti=True
END

def get_compression_filter(byte_counts):
    """pass"""
    assert isinstance(byte_counts, numbers.Integral) and byte_counts > 0
    if 2 * byte_counts > 1000 * memory()['free']:
        try:
            FILTERS = tables.filters(complevel=5, complib='blosc', shuffle=True, least_significant_digit=6)
        except tables.FiltersWarning:
            FILTERS = tables.filters(complevel=5, complib='lzo', shuffle=True, least_significant_digit=6)
    else:
        FILTERS = None
    return FILTERS