Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code get_dimensions>
  MAKE_FUNCTION 0
  STORE_NAME get_dimensions
  RETURN_CONST None
END
CODE get_dimensions(self)
  DOC 'pass'
  RESUME 0
  LOAD_GLOBAL NULL + FrozenOrderedDict
  LOAD_CONST <code get_dimensions.<locals>.<genexpr>>
  MAKE_FUNCTION 0
  LOAD_FAST self
  LOAD_ATTR ds
  LOAD_ATTR dimensions
  LOAD_ATTR NULL|self + items
  CALL 0
  GET_ITER
  CALL 0
  CALL 1
  RETURN_VALUE
END
CODE get_dimensions.<locals>.<genexpr>(.0)
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_FAST .0
L2:
  FOR_ITER L3
  UNPACK_SEQUENCE 2
  STORE_FAST k
  STORE_FAST v
  LOAD_FAST k
  LOAD_GLOBAL NULL + len
  LOAD_FAST v
  CALL 1
  BUILD_TUPLE 2
  YIELD_VALUE 1
  RESUME 1
  POP_TOP
  JUMP_BACKWARD L2
L3:
  END_FOR
  RETURN_CONST None
L4:
  CALL_INTRINSIC_1 INTRINSIC_STOPITERATION_ERROR
  RERAISE 1
  EXC try=L1..L4 -> handler=L4 depth=0 lasti=True
END

def get_dimensions(self):
    """pass"""
    return FrozenOrderedDict(((k, len(v)) for k, v in self.ds.dimensions.items()))


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code _find_base_tds_url>
  MAKE_FUNCTION 0
  STORE_NAME _find_base_tds_url
  RETURN_CONST None
END
CODE _find_base_tds_url(catalog_url)
  DOC 'pass'
  RESUME 0
  LOAD_GLOBAL NULL + urlparse
  LOAD_FAST catalog_url
  CALL 1
  STORE_FAST url_components
  LOAD_FAST url_components
  LOAD_ATTR path
  POP_JUMP_IF_FALSE L1
  LOAD_FAST catalog_url
  LOAD_ATTR NULL|self + split
  LOAD_FAST url_components
  LOAD_ATTR path
  CALL 1
  LOAD_CONST 0
  BINARY_SUBSCR
  RETURN_VALUE
L1:
  LOAD_FAST catalog_url
  RETURN_VALUE
END

def _find_base_tds_url(catalog_url):
    """pass"""
    url_components = urlparse(catalog_url)
    if url_components.path:
        return catalog_url.split(url_components.path)[0]
    else:
        return catalog_url

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


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST (None,)
  LOAD_CONST <code filter_time_nearest>
  MAKE_FUNCTION defaults
  STORE_NAME filter_time_nearest
  RETURN_CONST None
END
CODE filter_time_nearest(self, time, regex)
  DOC 'pass'
  MAKE_CELL time
  RESUME 0
  LOAD_GLOBAL NULL + min
  LOAD_FAST self
  LOAD_ATTR NULL|self + _get_datasets_with_times
  LOAD_FAST regex
  CALL 1
  LOAD_CLOSURE time
  BUILD_TUPLE 1
  LOAD_CONST <code filter_time_nearest.<locals>.<lambda>>
  MAKE_FUNCTION closure
  KW_NAMES ('key',)
  CALL 2
  LOAD_CONST -1
  BINARY_SUBSCR
  RETURN_VALUE
END
CODE filter_time_nearest.<locals>.<lambda>(i)
  COPY_FREE_VARS 1
  RESUME 0
  LOAD_GLOBAL NULL + abs
  LOAD_FAST i
  LOAD_CONST 0
  BINARY_SUBSCR
  LOAD_DEREF time
  BINARY_OP -
  LOAD_ATTR NULL|self + total_seconds
  CALL 0
  CALL 1
  RETURN_VALUE
END

def filter_time_nearest(self, time, regex=None):
    """pass"""
    return min(self._get_datasets_with_times(regex), key=lambda i: abs((i[0] - time).total_seconds()))[-1]


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST (None,)
  LOAD_CONST <code filter_time_range>
  MAKE_FUNCTION defaults
  STORE_NAME filter_time_range
  RETURN_CONST None
END
CODE filter_time_range(self, start, end, regex)
  DOC 'pass'
  RESUME 0
  LOAD_FAST self
  LOAD_ATTR NULL|self + _get_datasets_with_times
  LOAD_FAST regex
  CALL 1
  GET_ITER
  LOAD_FAST_AND_CLEAR item
  SWAP 2
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L8
  STORE_FAST item
  LOAD_FAST start
  LOAD_FAST item
  LOAD_CONST 0
  BINARY_SUBSCR
  SWAP 2
  COPY 2
  COMPARE_OP <=
  POP_JUMP_IF_FALSE L5
  LOAD_FAST end
  COMPARE_OP <=
  POP_JUMP_IF_TRUE L4
L3:
  JUMP_BACKWARD L2
L4:
  JUMP_FORWARD L6
L5:
  POP_TOP
  JUMP_FORWARD L7
L6:
  LOAD_FAST item
  LOAD_CONST -1
  BINARY_SUBSCR
  LIST_APPEND 2
L7:
  JUMP_BACKWARD L2
L8:
  END_FOR
L9:
  SWAP 2
  STORE_FAST item
  RETURN_VALUE
L10:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST item
  RERAISE 0
  EXC try=L1..L3 -> handler=L10 depth=2 lasti=False
  EXC try=L4..L9 -> handler=L10 depth=2 lasti=False
END

def filter_time_range(self, start, end, regex=None):
    """pass"""
    return [item[-1] for item in self._get_datasets_with_times(regex) if start <= item[0] <= end]


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code check_token>
  MAKE_FUNCTION 0
  STORE_NAME check_token
  RETURN_CONST None
END
CODE check_token(func)
  DOC 'pass'
  MAKE_CELL func
  RESUME 0
  LOAD_GLOBAL NULL + wraps
  LOAD_DEREF func
  CALL 1
  LOAD_CLOSURE func
  BUILD_TUPLE 1
  LOAD_CONST <code check_token.<locals>.wrapper>
  MAKE_FUNCTION closure
  CALL 0
  STORE_FAST wrapper
  LOAD_FAST wrapper
  RETURN_VALUE
END
CODE check_token.<locals>.wrapper(*args, **kwargs)
  COPY_FREE_VARS 1
  RESUME 0
  PUSH_NULL
  LOAD_DEREF func
  LOAD_FAST args
  BUILD_MAP 0
  LOAD_FAST kwargs
  DICT_MERGE 1
  CALL_FUNCTION_EX 1
  STORE_FAST response
  LOAD_FAST response
  LOAD_ATTR status_code
  LOAD_CONST 401
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L1
  LOAD_GLOBAL NULL + InvalidToken
  LOAD_CONST 'Access token invalid or no longer valid'
  CALL 1
  RAISE_VARARGS 1
L1:
  LOAD_FAST response
  RETURN_VALUE
END

def check_token(func):
    """pass"""

    @wraps(func)
    def wrapper(*args, **kwargs):
        response = func(*args, **kwargs)
        if response.status_code == 401:
            raise InvalidToken('Access token invalid or no longer valid')
        else:
            return response
    return wrapper


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST (None,)
  LOAD_CONST <code upload>
  MAKE_FUNCTION defaults
  STORE_NAME upload
  RETURN_CONST None
END
CODE upload(self, remote_path, file_content, ondup, **kwargs)
  DOC 'pass'
  RESUME 0
  LOAD_FAST remote_path
  LOAD_FAST ondup
  LOAD_CONST ('path', 'ondup')
  BUILD_CONST_KEY_MAP 2
  STORE_FAST params
  LOAD_CONST 'file'
  LOAD_CONST 'file'
  LOAD_FAST file_content
  LOAD_CONST ''
  BUILD_TUPLE 3
  BUILD_MAP 1
  STORE_FAST files
  LOAD_CONST 'https://c.pcs.baidu.com/rest/2.0/pcs/file'
  STORE_FAST url
  PUSH_NULL
  LOAD_FAST self
  LOAD_ATTR _request
  LOAD_CONST ('file', 'upload')
  LOAD_FAST url
  LOAD_FAST params
  LOAD_FAST files
  LOAD_CONST ('url', 'extra_params', 'files')
  BUILD_CONST_KEY_MAP 3
  LOAD_FAST kwargs
  DICT_MERGE 1
  CALL_FUNCTION_EX 1
  RETURN_VALUE
END

def upload(self, remote_path, file_content, ondup=None, **kwargs):
    """pass"""
    params = {'path': remote_path, 'ondup': ondup}
    files = {'file': ('file', file_content, '')}
    url = 'https://c.pcs.baidu.com/rest/2.0/pcs/file'
    return self._request('file', 'upload', url=url, extra_params=params, files=files, **kwargs)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code upload_tmpfile>
  MAKE_FUNCTION 0
  STORE_NAME upload_tmpfile
  RETURN_CONST None
END
CODE upload_tmpfile(self, file_content, **kwargs)
  DOC 'pass'
  RESUME 0
  LOAD_CONST 'type'
  LOAD_CONST 'tmpfile'
  BUILD_MAP 1
  STORE_FAST params
  LOAD_CONST 'file'
  LOAD_CONST 'file'
  LOAD_FAST file_content
  LOAD_CONST ''
  BUILD_TUPLE 3
  BUILD_MAP 1
  STORE_FAST files
  LOAD_CONST 'https://c.pcs.baidu.com/rest/2.0/pcs/file'
  STORE_FAST url
  PUSH_NULL
  LOAD_FAST self
  LOAD_ATTR _request
  LOAD_CONST ('file', 'upload')
  LOAD_FAST url
  LOAD_FAST params
  LOAD_FAST files
  LOAD_CONST ('url', 'extra_params', 'files')
  BUILD_CONST_KEY_MAP 3
  LOAD_FAST kwargs
  DICT_MERGE 1
  CALL_FUNCTION_EX 1
  RETURN_VALUE
END

def upload_tmpfile(self, file_content, **kwargs):
    """pass"""
    params = {'type': 'tmpfile'}
    files = {'file': ('file', file_content, '')}
    url = 'https://c.pcs.baidu.com/rest/2.0/pcs/file'
    return self._request('file', 'upload', url=url, extra_params=params, files=files, **kwargs)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST (None,)
  LOAD_CONST <code upload_superfile>
  MAKE_FUNCTION defaults
  STORE_NAME upload_superfile
  RETURN_CONST None
END
CODE upload_superfile(self, remote_path, block_list, ondup, **kwargs)
  DOC 'pass'
  RESUME 0
  LOAD_FAST remote_path
  LOAD_FAST ondup
  LOAD_CONST ('path', 'ondup')
  BUILD_CONST_KEY_MAP 2
  STORE_FAST params
  LOAD_CONST 'param'
  LOAD_GLOBAL json
  LOAD_ATTR NULL|self + dumps
  LOAD_CONST 'block_list'
  LOAD_FAST block_list
  BUILD_MAP 1
  CALL 1
  BUILD_MAP 1
  STORE_FAST data
  PUSH_NULL
  LOAD_FAST self
  LOAD_ATTR _request
  LOAD_CONST ('file', 'createsuperfile')
  LOAD_FAST params
  LOAD_FAST data
  LOAD_CONST ('extra_params', 'data')
  BUILD_CONST_KEY_MAP 2
  LOAD_FAST kwargs
  DICT_MERGE 1
  CALL_FUNCTION_EX 1
  RETURN_VALUE
END

def upload_superfile(self, remote_path, block_list, ondup=None, **kwargs):
    """pass"""
    params = {'path': remote_path, 'ondup': ondup}
    data = {'param': json.dumps({'block_list': block_list})}
    return self._request('file', 'createsuperfile', extra_params=params, data=data, **kwargs)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code mkdir>
  MAKE_FUNCTION 0
  STORE_NAME mkdir
  RETURN_CONST None
END
CODE mkdir(self, remote_path, **kwargs)
  DOC 'pass'
  RESUME 0
  LOAD_CONST 'path'
  LOAD_FAST remote_path
  BUILD_MAP 1
  STORE_FAST data
  PUSH_NULL
  LOAD_FAST self
  LOAD_ATTR _request
  LOAD_CONST ('file', 'mkdir')
  LOAD_CONST 'data'
  LOAD_FAST data
  BUILD_MAP 1
  LOAD_FAST kwargs
  DICT_MERGE 1
  CALL_FUNCTION_EX 1
  RETURN_VALUE
END

def mkdir(self, remote_path, **kwargs):
    """pass"""
    data = {'path': remote_path}
    return self._request('file', 'mkdir', data=data, **kwargs)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code meta>
  MAKE_FUNCTION 0
  STORE_NAME meta
  RETURN_CONST None
END
CODE meta(self, remote_path, **kwargs)
  DOC 'pass'
  RESUME 0
  LOAD_CONST 'path'
  LOAD_FAST remote_path
  BUILD_MAP 1
  STORE_FAST params
  PUSH_NULL
  LOAD_FAST self
  LOAD_ATTR _request
  LOAD_CONST ('file', 'meta')
  LOAD_CONST 'extra_params'
  LOAD_FAST params
  BUILD_MAP 1
  LOAD_FAST kwargs
  DICT_MERGE 1
  CALL_FUNCTION_EX 1
  RETURN_VALUE
END

def meta(self, remote_path, **kwargs):
    """pass"""
    params = {'path': remote_path}
    return self._request('file', 'meta', extra_params=params, **kwargs)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code login>
  MAKE_FUNCTION 0
  STORE_NAME login
  RETURN_CONST None
END
CODE login(self)
  DOC 'pass'
  RESUME 0
  LOAD_GLOBAL os
  LOAD_ATTR path
  LOAD_ATTR NULL|self + exists
  LOAD_FAST self
  LOAD_ATTR _cookieFileName
  CALL 1
  POP_JUMP_IF_FALSE L5
  LOAD_GLOBAL NULL + open
  LOAD_FAST self
  LOAD_ATTR _cookieFileName
  LOAD_CONST 'r'
  CALL 2
  BEFORE_WITH
L1:
  STORE_FAST cookieFile
  LOAD_FAST cookieFile
  LOAD_ATTR NULL|self + read
  CALL 0
  LOAD_ATTR NULL|self + strip
  CALL 0
  LOAD_FAST self
  STORE_ATTR _vid
L2:
  LOAD_CONST None
  LOAD_CONST None
  LOAD_CONST None
  CALL 2
  POP_TOP
L3:
  NOP
L4:
  LOAD_FAST self
  LOAD_ATTR NULL|self + _get_installations
  CALL 0
  POP_TOP
L5:
  LOAD_FAST self
  LOAD_ATTR _vid
  POP_JUMP_IF_NOT_NONE L9
  LOAD_FAST self
  LOAD_ATTR NULL|self + _create_cookie
  CALL 0
  POP_TOP
  LOAD_GLOBAL NULL + open
  LOAD_FAST self
  LOAD_ATTR _cookieFileName
  LOAD_CONST 'w'
  CALL 2
  BEFORE_WITH
L6:
  STORE_FAST cookieFile
  LOAD_FAST cookieFile
  LOAD_ATTR NULL|self + write
  LOAD_FAST self
  LOAD_ATTR _vid
  CALL 1
  POP_TOP
L7:
  LOAD_CONST None
  LOAD_CONST None
  LOAD_CONST None
  CALL 2
  POP_TOP
L8:
  LOAD_FAST self
  LOAD_ATTR NULL|self + _get_installations
  CALL 0
  POP_TOP
L9:
  LOAD_FAST self
  LOAD_ATTR installations
  LOAD_CONST 0
  BINARY_SUBSCR
  LOAD_CONST 'giid'
  BINARY_SUBSCR
  LOAD_FAST self
  STORE_ATTR _giid
  RETURN_CONST None
L10:
  PUSH_EXC_INFO
  WITH_EXCEPT_START
  POP_JUMP_IF_TRUE L11
  RERAISE 2
L11:
  POP_TOP
L12:
  POP_EXCEPT
  POP_TOP
  POP_TOP
  JUMP_BACKWARD L3
L13:
  COPY 3
  POP_EXCEPT
  RERAISE 1
L14:
  PUSH_EXC_INFO
  LOAD_GLOBAL ResponseError
  CHECK_EXC_MATCH
  POP_JUMP_IF_FALSE L16
  POP_TOP
  LOAD_CONST None
  LOAD_FAST self
  STORE_ATTR _vid
  LOAD_GLOBAL os
  LOAD_ATTR NULL|self + remove
  LOAD_FAST self
  LOAD_ATTR _cookieFileName
  CALL 1
  POP_TOP
L15:
  POP_EXCEPT
  JUMP_BACKWARD L5
L16:
  RERAISE 0
L17:
  COPY 3
  POP_EXCEPT
  RERAISE 1
L18:
  PUSH_EXC_INFO
  WITH_EXCEPT_START
  POP_JUMP_IF_TRUE L19
  RERAISE 2
L19:
  POP_TOP
L20:
  POP_EXCEPT
  POP_TOP
  POP_TOP
  JUMP_BACKWARD L8
L21:
  COPY 3
  POP_EXCEPT
  RERAISE 1
  EXC try=L1..L2 -> handler=L10 depth=1 lasti=True
  EXC try=L4..L5 -> handler=L14 depth=0 lasti=False
  EXC try=L6..L7 -> handler=L18 depth=1 lasti=True
  EXC try=L10..L12 -> handler=L13 depth=3 lasti=True
  EXC try=L14..L15 -> handler=L17 depth=1 lasti=True
  EXC try=L16..L17 -> handler=L17 depth=1 lasti=True
  EXC try=L18..L20 -> handler=L21 depth=3 lasti=True
END

def login(self):
    """pass"""
    if os.path.exists(self._cookieFileName):
        with open(self._cookieFileName, 'r') as cookieFile:
            self._vid = cookieFile.read().strip()
        try:
            self._get_installations()
        except ResponseError:
            self._vid = None
            os.remove(self._cookieFileName)
    if self._vid is None:
        self._create_cookie()
        with open(self._cookieFileName, 'w') as cookieFile:
            cookieFile.write(self._vid)
        self._get_installations()
    self._giid = self.installations[0]['giid']


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code _get_installations>
  MAKE_FUNCTION 0
  STORE_NAME _get_installations
  RETURN_CONST None
END
CODE _get_installations(self)
  DOC 'pass'
  RESUME 0
  LOAD_CONST None
  STORE_FAST response
  LOAD_GLOBAL urls
  LOAD_ATTR BASE_URLS
  GET_ITER
L1:
  FOR_ITER L7
  STORE_FAST base_url
  LOAD_FAST base_url
  LOAD_GLOBAL urls
  STORE_ATTR BASE_URL
  NOP
L2:
  LOAD_GLOBAL requests
  LOAD_ATTR NULL|self + get
  LOAD_GLOBAL urls
  LOAD_ATTR NULL|self + get_installations
  LOAD_FAST self
  LOAD_ATTR _username
  CALL 1
  LOAD_CONST 'vid={}'
  LOAD_ATTR NULL|self + format
  LOAD_FAST self
  LOAD_ATTR _vid
  CALL 1
  LOAD_CONST 'application/json,text/javascript, */*; q=0.01'
  LOAD_CONST ('Cookie', 'Accept')
  BUILD_CONST_KEY_MAP 2
  KW_NAMES ('headers',)
  CALL 2
  STORE_FAST response
  LOAD_CONST 2
  LOAD_FAST response
  LOAD_ATTR status_code
  LOAD_CONST 100
  BINARY_OP //
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L4
L3:
  POP_TOP
  JUMP_FORWARD L8
L4:
  LOAD_CONST 503
  LOAD_FAST response
  LOAD_ATTR status_code
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L6
L5:
  JUMP_BACKWARD L1
L6:
  LOAD_GLOBAL NULL + ResponseError
  LOAD_FAST response
  LOAD_ATTR status_code
  LOAD_FAST response
  LOAD_ATTR text
  CALL 2
  RAISE_VARARGS 1
L7:
  END_FOR
L8:
  LOAD_GLOBAL NULL + _validate_response
  LOAD_FAST response
  CALL 1
  POP_TOP
  LOAD_GLOBAL json
  LOAD_ATTR NULL|self + loads
  LOAD_FAST response
  LOAD_ATTR text
  CALL 1
  LOAD_FAST self
  STORE_ATTR installations
  RETURN_CONST None
L9:
  PUSH_EXC_INFO
  LOAD_GLOBAL requests
  LOAD_ATTR exceptions
  LOAD_ATTR RequestException
  CHECK_EXC_MATCH
  POP_JUMP_IF_FALSE L12
  STORE_FAST ex
L10:
  LOAD_GLOBAL NULL + RequestError
  LOAD_FAST ex
  CALL 1
  RAISE_VARARGS 1
L11:
  LOAD_CONST None
  STORE_FAST ex
  DELETE_FAST ex
  RERAISE 1
L12:
  RERAISE 0
L13:
  COPY 3
  POP_EXCEPT
  RERAISE 1
  EXC try=L2..L3 -> handler=L9 depth=1 lasti=False
  EXC try=L4..L5 -> handler=L9 depth=1 lasti=False
  EXC try=L6..L7 -> handler=L9 depth=1 lasti=False
  EXC try=L9..L10 -> handler=L13 depth=2 lasti=True
  EXC try=L10..L11 -> handler=L11 depth=2 lasti=True
  EXC try=L11..L13 -> handler=L13 depth=2 lasti=True
END

def _get_installations(self):
    """pass"""
    response = None
    for base_url in urls.BASE_URLS:
        urls.BASE_URL = base_url
        try:
            response = requests.get(urls.get_installations(self._username), headers={'Cookie': 'vid={}'.format(self._vid), 'Accept': 'application/json,text/javascript, */*; q=0.01'})
            if 2 == response.status_code // 100:
                break
            elif 503 == response.status_code:
                continue
            else:
                raise ResponseError(response.status_code, response.text)
        except requests.exceptions.RequestException as ex:
            raise RequestError(ex)
    _validate_response(response)
    self.installations = json.loads(response.text)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code get_overview>
  MAKE_FUNCTION 0
  STORE_NAME get_overview
  RETURN_CONST None
END
CODE get_overview(self)
  DOC 'pass'
  RESUME 0
  LOAD_CONST None
  STORE_FAST response
  NOP
L1:
  LOAD_GLOBAL requests
  LOAD_ATTR NULL|self + get
  LOAD_GLOBAL urls
  LOAD_ATTR NULL|self + overview
  LOAD_FAST self
  LOAD_ATTR _giid
  CALL 1
  LOAD_CONST 'application/json, text/javascript, */*; q=0.01'
  LOAD_CONST 'gzip, deflate'
  LOAD_CONST 'application/json'
  LOAD_CONST 'vid={}'
  LOAD_ATTR NULL|self + format
  LOAD_FAST self
  LOAD_ATTR _vid
  CALL 1
  LOAD_CONST ('Accept', 'Accept-Encoding', 'Content-Type', 'Cookie')
  BUILD_CONST_KEY_MAP 4
  KW_NAMES ('headers',)
  CALL 2
  STORE_FAST response
L2:
  LOAD_GLOBAL NULL + _validate_response
  LOAD_FAST response
  CALL 1
  POP_TOP
  LOAD_GLOBAL json
  LOAD_ATTR NULL|self + loads
  LOAD_FAST response
  LOAD_ATTR text
  CALL 1
  RETURN_VALUE
L3:
  PUSH_EXC_INFO
  LOAD_GLOBAL requests
  LOAD_ATTR exceptions
  LOAD_ATTR RequestException
  CHECK_EXC_MATCH
  POP_JUMP_IF_FALSE L6
  STORE_FAST ex
L4:
  LOAD_GLOBAL NULL + RequestError
  LOAD_FAST ex
  CALL 1
  RAISE_VARARGS 1
L5:
  LOAD_CONST None
  STORE_FAST ex
  DELETE_FAST ex
  RERAISE 1
L6:
  RERAISE 0
L7:
  COPY 3
  POP_EXCEPT
  RERAISE 1
  EXC try=L1..L2 -> handler=L3 depth=0 lasti=False
  EXC try=L3..L4 -> handler=L7 depth=1 lasti=True
  EXC try=L4..L5 -> handler=L5 depth=1 lasti=True
  EXC try=L5..L7 -> handler=L7 depth=1 lasti=True
END

def get_overview(self):
    """pass"""
    response = None
    try:
        response = requests.get(urls.overview(self._giid), headers={'Accept': 'application/json, text/javascript, */*; q=0.01', 'Accept-Encoding': 'gzip, deflate', 'Content-Type': 'application/json', 'Cookie': 'vid={}'.format(self._vid)})
    except requests.exceptions.RequestException as ex:
        raise RequestError(ex)
    _validate_response(response)
    return json.loads(response.text)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code set_smartplug_state>
  MAKE_FUNCTION 0
  STORE_NAME set_smartplug_state
  RETURN_CONST None
END
CODE set_smartplug_state(self, device_label, state)
  DOC 'pass'
  RESUME 0
  LOAD_CONST None
  STORE_FAST response
  NOP
L1:
  LOAD_GLOBAL requests
  LOAD_ATTR NULL|self + post
  LOAD_GLOBAL urls
  LOAD_ATTR NULL|self + smartplug
  LOAD_FAST self
  LOAD_ATTR _giid
  CALL 1
  LOAD_CONST 'application/json'
  LOAD_CONST 'vid={}'
  LOAD_ATTR NULL|self + format
  LOAD_FAST self
  LOAD_ATTR _vid
  CALL 1
  LOAD_CONST ('Content-Type', 'Cookie')
  BUILD_CONST_KEY_MAP 2
  LOAD_GLOBAL json
  LOAD_ATTR NULL|self + dumps
  LOAD_FAST device_label
  LOAD_FAST state
  LOAD_CONST ('deviceLabel', 'state')
  BUILD_CONST_KEY_MAP 2
  BUILD_LIST 1
  CALL 1
  KW_NAMES ('headers', 'data')
  CALL 3
  STORE_FAST response
L2:
  LOAD_GLOBAL NULL + _validate_response
  LOAD_FAST response
  CALL 1
  POP_TOP
  RETURN_CONST None
L3:
  PUSH_EXC_INFO
  LOAD_GLOBAL requests
  LOAD_ATTR exceptions
  LOAD_ATTR RequestException
  CHECK_EXC_MATCH
  POP_JUMP_IF_FALSE L6
  STORE_FAST ex
L4:
  LOAD_GLOBAL NULL + RequestError
  LOAD_FAST ex
  CALL 1
  RAISE_VARARGS 1
L5:
  LOAD_CONST None
  STORE_FAST ex
  DELETE_FAST ex
  RERAISE 1
L6:
  RERAISE 0
L7:
  COPY 3
  POP_EXCEPT
  RERAISE 1
  EXC try=L1..L2 -> handler=L3 depth=0 lasti=False
  EXC try=L3..L4 -> handler=L7 depth=1 lasti=True
  EXC try=L4..L5 -> handler=L5 depth=1 lasti=True
  EXC try=L5..L7 -> handler=L7 depth=1 lasti=True
END

def set_smartplug_state(self, device_label, state):
    """pass"""
    response = None
    try:
        response = requests.post(urls.smartplug(self._giid), headers={'Content-Type': 'application/json', 'Cookie': 'vid={}'.format(self._vid)}, data=json.dumps([{'deviceLabel': device_label, 'state': state}]))
    except requests.exceptions.RequestException as ex:
        raise RequestError(ex)
    _validate_response(response)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST ((), 15, 0)
  LOAD_CONST <code get_history>
  MAKE_FUNCTION defaults
  STORE_NAME get_history
  RETURN_CONST None
END
CODE get_history(self, filters, pagesize, offset)
  DOC 'pass'
  RESUME 0
  LOAD_CONST None
  STORE_FAST response
  NOP
L1:
  LOAD_GLOBAL requests
  LOAD_ATTR NULL|self + get
  LOAD_GLOBAL urls
  LOAD_ATTR NULL|self + history
  LOAD_FAST self
  LOAD_ATTR _giid
  CALL 1
  LOAD_CONST 'application/json, text/javascript, */*; q=0.01'
  LOAD_CONST 'vid={}'
  LOAD_ATTR NULL|self + format
  LOAD_FAST self
  LOAD_ATTR _vid
  CALL 1
  LOAD_CONST ('Accept', 'Cookie')
  BUILD_CONST_KEY_MAP 2
  LOAD_GLOBAL NULL + int
  LOAD_FAST offset
  CALL 1
  LOAD_GLOBAL NULL + int
  LOAD_FAST pagesize
  CALL 1
  LOAD_FAST filters
  LOAD_CONST ('offset', 'pagesize', 'notificationCategories')
  BUILD_CONST_KEY_MAP 3
  KW_NAMES ('headers', 'params')
  CALL 3
  STORE_FAST response
L2:
  LOAD_GLOBAL NULL + _validate_response
  LOAD_FAST response
  CALL 1
  POP_TOP
  LOAD_GLOBAL json
  LOAD_ATTR NULL|self + loads
  LOAD_FAST response
  LOAD_ATTR text
  CALL 1
  RETURN_VALUE
L3:
  PUSH_EXC_INFO
  LOAD_GLOBAL requests
  LOAD_ATTR exceptions
  LOAD_ATTR RequestException
  CHECK_EXC_MATCH
  POP_JUMP_IF_FALSE L6
  STORE_FAST ex
L4:
  LOAD_GLOBAL NULL + RequestError
  LOAD_FAST ex
  CALL 1
  RAISE_VARARGS 1
L5:
  LOAD_CONST None
  STORE_FAST ex
  DELETE_FAST ex
  RERAISE 1
L6:
  RERAISE 0
L7:
  COPY 3
  POP_EXCEPT
  RERAISE 1
  EXC try=L1..L2 -> handler=L3 depth=0 lasti=False
  EXC try=L3..L4 -> handler=L7 depth=1 lasti=True
  EXC try=L4..L5 -> handler=L5 depth=1 lasti=True
  EXC try=L5..L7 -> handler=L7 depth=1 lasti=True
END

def get_history(self, filters=(), pagesize=15, offset=0):
    """pass"""
    response = None
    try:
        response = requests.get(urls.history(self._giid), headers={'Accept': 'application/json, text/javascript, */*; q=0.01', 'Cookie': 'vid={}'.format(self._vid)}, params={'offset': int(offset), 'pagesize': int(pagesize), 'notificationCategories': filters})
    except requests.exceptions.RequestException as ex:
        raise RequestError(ex)
    _validate_response(response)
    return json.loads(response.text)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code get_climate>
  MAKE_FUNCTION 0
  STORE_NAME get_climate
  RETURN_CONST None
END
CODE get_climate(self, device_label)
  DOC 'pass'
  RESUME 0
  LOAD_CONST None
  STORE_FAST response
  NOP
L1:
  LOAD_GLOBAL requests
  LOAD_ATTR NULL|self + get
  LOAD_GLOBAL urls
  LOAD_ATTR NULL|self + climate
  LOAD_FAST self
  LOAD_ATTR _giid
  CALL 1
  LOAD_CONST 'application/json, text/javascript, */*; q=0.01'
  LOAD_CONST 'vid={}'
  LOAD_ATTR NULL|self + format
  LOAD_FAST self
  LOAD_ATTR _vid
  CALL 1
  LOAD_CONST ('Accept', 'Cookie')
  BUILD_CONST_KEY_MAP 2
  LOAD_CONST 'deviceLabel'
  LOAD_FAST device_label
  BUILD_MAP 1
  KW_NAMES ('headers', 'params')
  CALL 3
  STORE_FAST response
L2:
  LOAD_GLOBAL NULL + _validate_response
  LOAD_FAST response
  CALL 1
  POP_TOP
  LOAD_GLOBAL json
  LOAD_ATTR NULL|self + loads
  LOAD_FAST response
  LOAD_ATTR text
  CALL 1
  RETURN_VALUE
L3:
  PUSH_EXC_INFO
  LOAD_GLOBAL requests
  LOAD_ATTR exceptions
  LOAD_ATTR RequestException
  CHECK_EXC_MATCH
  POP_JUMP_IF_FALSE L6
  STORE_FAST ex
L4:
  LOAD_GLOBAL NULL + RequestError
  LOAD_FAST ex
  CALL 1
  RAISE_VARARGS 1
L5:
  LOAD_CONST None
  STORE_FAST ex
  DELETE_FAST ex
  RERAISE 1
L6:
  RERAISE 0
L7:
  COPY 3
  POP_EXCEPT
  RERAISE 1
  EXC try=L1..L2 -> handler=L3 depth=0 lasti=False
  EXC try=L3..L4 -> handler=L7 depth=1 lasti=True
  EXC try=L4..L5 -> handler=L5 depth=1 lasti=True
  EXC try=L5..L7 -> handler=L7 depth=1 lasti=True
END

def get_climate(self, device_label):
    """pass"""
    response = None
    try:
        response = requests.get(urls.climate(self._giid), headers={'Accept': 'application/json, text/javascript, */*; q=0.01', 'Cookie': 'vid={}'.format(self._vid)}, params={'deviceLabel': device_label})
    except requests.exceptions.RequestException as ex:
        raise RequestError(ex)
    _validate_response(response)
    return json.loads(response.text)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code type_id>
  MAKE_FUNCTION 0
  STORE_NAME type_id
  RETURN_CONST None
END
CODE type_id(self)
  DOC 'pass'
  RESUME 0
  NOP
L1:
  LOAD_GLOBAL ContentType
  LOAD_ATTR objects
  LOAD_ATTR NULL|self + get_for_model
  LOAD_FAST self
  LOAD_ATTR model
  LOAD_CONST False
  KW_NAMES ('for_concrete_model',)
  CALL 2
  LOAD_ATTR id
L2:
  RETURN_VALUE
L3:
  PUSH_EXC_INFO
  LOAD_GLOBAL DatabaseError
  CHECK_EXC_MATCH
  POP_JUMP_IF_FALSE L6
  STORE_FAST e
L4:
  LOAD_GLOBAL NULL + DatabaseError
  LOAD_CONST 'Unable to fetch ContentType object, is a plugin being registered before the initial syncdb? (original error: {0})'
  LOAD_ATTR NULL|self + format
  LOAD_GLOBAL NULL + str
  LOAD_FAST e
  CALL 1
  CALL 1
  CALL 1
  RAISE_VARARGS 1
L5:
  LOAD_CONST None
  STORE_FAST e
  DELETE_FAST e
  RERAISE 1
L6:
  RERAISE 0
L7:
  COPY 3
  POP_EXCEPT
  RERAISE 1
  EXC try=L1..L2 -> handler=L3 depth=0 lasti=False
  EXC try=L3..L4 -> handler=L7 depth=1 lasti=True
  EXC try=L4..L5 -> handler=L5 depth=1 lasti=True
  EXC try=L5..L7 -> handler=L7 depth=1 lasti=True
END

def type_id(self):
    """pass"""
    try:
        return ContentType.objects.get_for_model(self.model, for_concrete_model=False).id
    except DatabaseError as e:
        raise DatabaseError('Unable to fetch ContentType object, is a plugin being registered before the initial syncdb? (original error: {0})'.format(str(e)))


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code get_output_cache_key>
  MAKE_FUNCTION 0
  STORE_NAME get_output_cache_key
  RETURN_CONST None
END
CODE get_output_cache_key(self, placeholder_name, instance)
  DOC 'pass'
  RESUME 0
  LOAD_FAST self
  LOAD_ATTR NULL|self + get_output_cache_base_key
  LOAD_FAST placeholder_name
  LOAD_FAST instance
  CALL 2
  STORE_FAST cachekey
  LOAD_FAST self
  LOAD_ATTR cache_output_per_site
  POP_JUMP_IF_FALSE L1
  LOAD_CONST '{0}-s{1}'
  LOAD_ATTR NULL|self + format
  LOAD_FAST cachekey
  LOAD_GLOBAL settings
  LOAD_ATTR SITE_ID
  CALL 2
  STORE_FAST cachekey
L1:
  LOAD_FAST self
  LOAD_ATTR cache_output_per_language
  POP_JUMP_IF_FALSE L3
  LOAD_GLOBAL NULL + get_language
  CALL 0
  STORE_FAST user_language
  LOAD_FAST user_language
  LOAD_FAST self
  LOAD_ATTR cache_supported_language_codes
  CONTAINS_OP 1
  POP_JUMP_IF_FALSE L2
  LOAD_CONST 'unsupported'
  STORE_FAST user_language
L2:
  LOAD_CONST '{0}.{1}'
  LOAD_ATTR NULL|self + format
  LOAD_FAST cachekey
  LOAD_FAST user_language
  CALL 2
  STORE_FAST cachekey
L3:
  LOAD_FAST cachekey
  RETURN_VALUE
END

def get_output_cache_key(self, placeholder_name, instance):
    """pass"""
    cachekey = self.get_output_cache_base_key(placeholder_name, instance)
    if self.cache_output_per_site:
        cachekey = '{0}-s{1}'.format(cachekey, settings.SITE_ID)
    if self.cache_output_per_language:
        user_language = get_language()
        if user_language not in self.cache_supported_language_codes:
            user_language = 'unsupported'
        cachekey = '{0}.{1}'.format(cachekey, user_language)
    return cachekey


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code get_output_cache_keys>
  MAKE_FUNCTION 0
  STORE_NAME get_output_cache_keys
  RETURN_CONST None
END
CODE get_output_cache_keys(self, placeholder_name, instance)
  DOC 'pass'
  MAKE_CELL placeholder
  MAKE_CELL user_language
  RESUME 0
  LOAD_FAST self
  LOAD_ATTR NULL|self + get_output_cache_base_key
  LOAD_FAST placeholder_name
  LOAD_FAST instance
  CALL 2
  STORE_FAST base_key
  LOAD_FAST base_key
  BUILD_LIST 1
  STORE_FAST cachekeys
  LOAD_FAST self
  LOAD_ATTR cache_output_per_site
  POP_JUMP_IF_FALSE L6
  LOAD_GLOBAL NULL + list
  LOAD_GLOBAL Site
  LOAD_ATTR objects
  LOAD_ATTR NULL|self + values_list
  LOAD_CONST 'pk'
  LOAD_CONST True
  KW_NAMES ('flat',)
  CALL 2
  CALL 1
  STORE_FAST site_ids
  LOAD_GLOBAL settings
  LOAD_ATTR SITE_ID
  LOAD_FAST site_ids
  CONTAINS_OP 1
  POP_JUMP_IF_FALSE L1
  LOAD_FAST site_ids
  LOAD_ATTR NULL|self + append
  LOAD_GLOBAL settings
  LOAD_ATTR SITE_ID
  CALL 1
  POP_TOP
L1:
  LOAD_GLOBAL NULL + get_rendering_cache_key
  LOAD_FAST placeholder_name
  LOAD_FAST instance
  CALL 2
  STORE_FAST base_key
  LOAD_FAST site_ids
  GET_ITER
  LOAD_FAST_AND_CLEAR site_id
  SWAP 2
L2:
  BUILD_LIST 0
  SWAP 2
L3:
  FOR_ITER L4
  STORE_FAST site_id
  LOAD_CONST '{0}-s{1}'
  LOAD_ATTR NULL|self + format
  LOAD_FAST base_key
  LOAD_FAST site_id
  CALL 2
  LIST_APPEND 2
  JUMP_BACKWARD L3
L4:
  END_FOR
L5:
  STORE_FAST cachekeys
  STORE_FAST site_id
L6:
  LOAD_FAST self
  LOAD_ATTR cache_output_per_language
  POP_JUMP_IF_TRUE L7
  LOAD_FAST self
  LOAD_ATTR render_ignore_item_language
  POP_JUMP_IF_FALSE L10
L7:
  BUILD_LIST 0
  STORE_FAST total_list
  LOAD_GLOBAL NULL + list
  LOAD_FAST self
  LOAD_ATTR cache_supported_language_codes
  CALL 1
  LOAD_CONST 'unsupported'
  LOAD_CONST 'None'
  BUILD_LIST 2
  BINARY_OP +
  STORE_FAST cache_languages
  LOAD_FAST instance
  LOAD_ATTR placeholder
  STORE_DEREF placeholder
  LOAD_FAST total_list
  LOAD_ATTR NULL|self + extend
  LOAD_CLOSURE placeholder
  BUILD_TUPLE 1
  LOAD_CONST <code get_output_cache_keys.<locals>.<genexpr>>
  MAKE_FUNCTION closure
  LOAD_FAST cache_languages
  GET_ITER
  CALL 0
  CALL 1
  POP_TOP
  LOAD_FAST cache_languages
  GET_ITER
L8:
  FOR_ITER L9
  STORE_DEREF user_language
  LOAD_FAST total_list
  LOAD_ATTR NULL|self + extend
  LOAD_CLOSURE user_language
  BUILD_TUPLE 1
  LOAD_CONST <code get_output_cache_keys.<locals>.<genexpr>>
  MAKE_FUNCTION closure
  LOAD_FAST cachekeys
  GET_ITER
  CALL 0
  CALL 1
  POP_TOP
  JUMP_BACKWARD L8
L9:
  END_FOR
  LOAD_FAST total_list
  STORE_FAST cachekeys
L10:
  LOAD_FAST cachekeys
  RETURN_VALUE
L11:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST site_id
  RERAISE 0
  EXC try=L2..L5 -> handler=L11 depth=2 lasti=False
END
CODE get_output_cache_keys.<locals>.<genexpr>(.0)
  COPY_FREE_VARS 1
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_FAST .0
L2:
  FOR_ITER L3
  STORE_FAST lc
  LOAD_GLOBAL NULL + get_placeholder_cache_key
  LOAD_DEREF placeholder
  LOAD_FAST lc
  CALL 2
  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
CODE get_output_cache_keys.<locals>.<genexpr>(.0)
  DOC '{0}.{1}'
  COPY_FREE_VARS 1
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_FAST .0
L2:
  FOR_ITER L3
  STORE_FAST base
  LOAD_CONST '{0}.{1}'
  LOAD_ATTR NULL|self + format
  LOAD_FAST base
  LOAD_DEREF user_language
  CALL 2
  YIELD_VALUE 1
  RESUME 1
  POP_TOP
  JUMP_BACKWARD L2
L3:
  END_FOR
  RETURN_CONST None
L4:
  CALL_INTRINSIC_1 INTRINSIC_STOPITERATION_ERROR
  RERAISE 1
  EXC try=L1..L4 -> handler=L4 depth=0 lasti=True
END

def get_output_cache_keys(self, placeholder_name, instance):
    """pass"""
    base_key = self.get_output_cache_base_key(placeholder_name, instance)
    cachekeys = [base_key]
    if self.cache_output_per_site:
        site_ids = list(Site.objects.values_list('pk', flat=True))
        if settings.SITE_ID not in site_ids:
            site_ids.append(settings.SITE_ID)
        base_key = get_rendering_cache_key(placeholder_name, instance)
        cachekeys = ['{0}-s{1}'.format(base_key, site_id) for site_id in site_ids]
    if self.cache_output_per_language or self.render_ignore_item_language:
        total_list = []
        cache_languages = list(self.cache_supported_language_codes) + ['unsupported', 'None']
        placeholder = instance.placeholder
        total_list.extend((get_placeholder_cache_key(placeholder, lc) for lc in cache_languages))
        for user_language in cache_languages:
            total_list.extend(('{0}.{1}'.format(base, user_language) for base in cachekeys))
        cachekeys = total_list
    return cachekeys


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code get_cached_output>
  MAKE_FUNCTION 0
  STORE_NAME get_cached_output
  RETURN_CONST None
END
CODE get_cached_output(self, placeholder_name, instance)
  DOC 'pass'
  RESUME 0
  LOAD_FAST self
  LOAD_ATTR NULL|self + get_output_cache_key
  LOAD_FAST placeholder_name
  LOAD_FAST instance
  CALL 2
  STORE_FAST cachekey
  LOAD_GLOBAL cache
  LOAD_ATTR NULL|self + get
  LOAD_FAST cachekey
  CALL 1
  RETURN_VALUE
END

def get_cached_output(self, placeholder_name, instance):
    """pass"""
    cachekey = self.get_output_cache_key(placeholder_name, instance)
    return cache.get(cachekey)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code set_cached_output>
  MAKE_FUNCTION 0
  STORE_NAME set_cached_output
  RETURN_CONST None
END
CODE set_cached_output(self, placeholder_name, instance, output)
  DOC 'pass'
  RESUME 0
  LOAD_FAST self
  LOAD_ATTR NULL|self + get_output_cache_key
  LOAD_FAST placeholder_name
  LOAD_FAST instance
  CALL 2
  STORE_FAST cachekey
  LOAD_FAST self
  LOAD_ATTR cache_timeout
  LOAD_GLOBAL DEFAULT_TIMEOUT
  IS_OP 1
  POP_JUMP_IF_FALSE L1
  LOAD_GLOBAL cache
  LOAD_ATTR NULL|self + set
  LOAD_FAST cachekey
  LOAD_FAST output
  LOAD_FAST self
  LOAD_ATTR cache_timeout
  CALL 3
  POP_TOP
  RETURN_CONST None
L1:
  LOAD_GLOBAL cache
  LOAD_ATTR NULL|self + set
  LOAD_FAST cachekey
  LOAD_FAST output
  CALL 2
  POP_TOP
  RETURN_CONST None
END

def set_cached_output(self, placeholder_name, instance, output):
    """pass"""
    cachekey = self.get_output_cache_key(placeholder_name, instance)
    if self.cache_timeout is not DEFAULT_TIMEOUT:
        cache.set(cachekey, output, self.cache_timeout)
    else:
        cache.set(cachekey, output)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code render>
  MAKE_FUNCTION 0
  STORE_NAME render
  RETURN_CONST None
END
CODE render(self, request, instance, **kwargs)
  DOC 'pass'
  RESUME 0
  PUSH_NULL
  LOAD_FAST self
  LOAD_ATTR get_render_template
  LOAD_FAST request
  LOAD_FAST instance
  BUILD_TUPLE 2
  BUILD_MAP 0
  LOAD_FAST kwargs
  DICT_MERGE 1
  CALL_FUNCTION_EX 1
  STORE_FAST render_template
  LOAD_FAST render_template
  POP_JUMP_IF_TRUE L1
  LOAD_GLOBAL NULL + str
  LOAD_GLOBAL NULL + _
  LOAD_CONST "{No rendering defined for class '%s'}"
  LOAD_FAST self
  LOAD_ATTR __class__
  LOAD_ATTR __name__
  BINARY_OP %
  CALL 1
  CALL 1
  RETURN_VALUE
L1:
  PUSH_NULL
  LOAD_FAST self
  LOAD_ATTR get_context
  LOAD_FAST request
  LOAD_FAST instance
  BUILD_TUPLE 2
  BUILD_MAP 0
  LOAD_FAST kwargs
  DICT_MERGE 1
  CALL_FUNCTION_EX 1
  STORE_FAST context
  LOAD_FAST self
  LOAD_ATTR NULL|self + render_to_string
  LOAD_FAST request
  LOAD_FAST render_template
  LOAD_FAST context
  CALL 3
  RETURN_VALUE
END

def render(self, request, instance, **kwargs):
    """pass"""
    render_template = self.get_render_template(request, instance, **kwargs)
    if not render_template:
        return str(_(u"{No rendering defined for class '%s'}" % self.__class__.__name__))
    context = self.get_context(request, instance, **kwargs)
    return self.render_to_string(request, render_template, context)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code inline_requests>
  MAKE_FUNCTION 0
  STORE_NAME inline_requests
  RETURN_CONST None
END
CODE inline_requests(method_or_func)
  DOC 'pass'
  MAKE_CELL method_or_func
  RESUME 0
  LOAD_GLOBAL NULL + get_args
  LOAD_DEREF method_or_func
  CALL 1
  STORE_FAST args
  LOAD_FAST args
  POP_JUMP_IF_TRUE L1
  LOAD_GLOBAL NULL + TypeError
  LOAD_CONST 'Function must accept at least one argument.'
  CALL 1
  RAISE_VARARGS 1
L1:
  LOAD_FAST args
  LOAD_CONST 0
  BINARY_SUBSCR
  LOAD_CONST 'self'
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L2
  LOAD_CLOSURE method_or_func
  BUILD_TUPLE 1
  LOAD_CONST <code inline_requests.<locals>.wrapper>
  MAKE_FUNCTION closure
  STORE_FAST wrapper
  JUMP_FORWARD L3
L2:
  LOAD_GLOBAL warnings
  LOAD_ATTR NULL|self + warn
  LOAD_CONST 'Decorating a non-method function will be deprecated'
  LOAD_GLOBAL ScrapyDeprecationWarning
  LOAD_CONST 1
  KW_NAMES ('stacklevel',)
  CALL 3
  POP_TOP
  LOAD_CLOSURE method_or_func
  BUILD_TUPLE 1
  LOAD_CONST <code inline_requests.<locals>.wrapper>
  MAKE_FUNCTION closure
  STORE_FAST wrapper
L3:
  PUSH_NULL
  LOAD_GLOBAL NULL + wraps
  LOAD_DEREF method_or_func
  CALL 1
  LOAD_FAST wrapper
  CALL 1
  RETURN_VALUE
END
CODE inline_requests.<locals>.wrapper(self, response, **kwargs)
  COPY_FREE_VARS 1
  RESUME 0
  LOAD_GLOBAL NULL + create_bound_method
  LOAD_DEREF method_or_func
  LOAD_FAST self
  CALL 2
  STORE_FAST callback
  LOAD_GLOBAL NULL + RequestGenerator
  LOAD_FAST callback
  BUILD_TUPLE 1
  BUILD_MAP 0
  LOAD_FAST kwargs
  DICT_MERGE 1
  CALL_FUNCTION_EX 1
  STORE_FAST genwrapper
  PUSH_NULL
  LOAD_FAST genwrapper
  LOAD_FAST response
  CALL 1
  RETURN_VALUE
END
CODE inline_requests.<locals>.wrapper(response, **kwargs)
  COPY_FREE_VARS 1
  RESUME 0
  LOAD_GLOBAL NULL + RequestGenerator
  LOAD_DEREF method_or_func
  BUILD_TUPLE 1
  BUILD_MAP 0
  LOAD_FAST kwargs
  DICT_MERGE 1
  CALL_FUNCTION_EX 1
  STORE_FAST genwrapper
  PUSH_NULL
  LOAD_FAST genwrapper
  LOAD_FAST response
  CALL 1
  RETURN_VALUE
END

def inline_requests(method_or_func):
    """pass"""
    args = get_args(method_or_func)
    if not args:
        raise TypeError('Function must accept at least one argument.')
    if args[0] == 'self':

        def wrapper(self, response, **kwargs):
            callback = create_bound_method(method_or_func, self)
            genwrapper = RequestGenerator(callback, **kwargs)
            return genwrapper(response)
    else:
        warnings.warn('Decorating a non-method function will be deprecated', ScrapyDeprecationWarning, stacklevel=1)

        def wrapper(response, **kwargs):
            genwrapper = RequestGenerator(method_or_func, **kwargs)
            return genwrapper(response)
    return wraps(method_or_func)(wrapper)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code get_args>
  MAKE_FUNCTION 0
  STORE_NAME get_args
  RETURN_CONST None
END
CODE get_args(method_or_func)
  DOC 'pass'
  RESUME 0
  NOP
L1:
  LOAD_GLOBAL NULL + list
  LOAD_GLOBAL inspect
  LOAD_ATTR NULL|self + signature
  LOAD_FAST method_or_func
  CALL 1
  LOAD_ATTR parameters
  LOAD_ATTR NULL|self + keys
  CALL 0
  CALL 1
  STORE_FAST args
L2:
  LOAD_FAST args
  RETURN_VALUE
L3:
  PUSH_EXC_INFO
  LOAD_GLOBAL AttributeError
  CHECK_EXC_MATCH
  POP_JUMP_IF_FALSE L5
  POP_TOP
  LOAD_GLOBAL inspect
  LOAD_ATTR NULL|self + getargspec
  LOAD_FAST method_or_func
  CALL 1
  LOAD_ATTR args
  STORE_FAST args
L4:
  POP_EXCEPT
  LOAD_FAST args
  RETURN_VALUE
L5:
  RERAISE 0
L6:
  COPY 3
  POP_EXCEPT
  RERAISE 1
  EXC try=L1..L2 -> handler=L3 depth=0 lasti=False
  EXC try=L3..L4 -> handler=L6 depth=1 lasti=True
  EXC try=L5..L6 -> handler=L6 depth=1 lasti=True
END

def get_args(method_or_func):
    """pass"""
    try:
        args = list(inspect.signature(method_or_func).parameters.keys())
    except AttributeError:
        args = inspect.getargspec(method_or_func).args
    return args


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST (None,)
  LOAD_CONST <code _unwindGenerator>
  MAKE_FUNCTION defaults
  STORE_NAME _unwindGenerator
  RETURN_CONST None
END
CODE _unwindGenerator(self, generator, _prev)
  DOC 'pass'
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  NOP
L2:
  LOAD_FAST _prev
  POP_JUMP_IF_FALSE L3
  LOAD_FAST _prev
  LOAD_CONST None
  STORE_FAST _prev
  STORE_FAST ret
  JUMP_FORWARD L5
L3:
  NOP
L4:
  LOAD_GLOBAL NULL + next
  LOAD_FAST generator
  CALL 1
  STORE_FAST ret
L5:
  LOAD_GLOBAL NULL + isinstance
  LOAD_FAST ret
  LOAD_GLOBAL Request
  CALL 2
  POP_JUMP_IF_FALSE L8
  LOAD_FAST ret
  LOAD_ATTR callback
  POP_JUMP_IF_FALSE L6
  LOAD_GLOBAL warnings
  LOAD_ATTR NULL|self + warn
  LOAD_CONST 'Got a request with callback set, bypassing the generator wrapper. Generator may not be able to resume. %s'
  LOAD_FAST ret
  BINARY_OP %
  CALL 1
  POP_TOP
  JUMP_FORWARD L8
L6:
  LOAD_FAST ret
  LOAD_ATTR errback
  POP_JUMP_IF_FALSE L7
  LOAD_GLOBAL warnings
  LOAD_ATTR NULL|self + warn
  LOAD_CONST 'Got a request with errback set, bypassing the generator wrapper. Generator may not be able to resume. %s'
  LOAD_FAST ret
  BINARY_OP %
  CALL 1
  POP_TOP
  JUMP_FORWARD L8
L7:
  LOAD_FAST self
  LOAD_ATTR NULL|self + _wrapRequest
  LOAD_FAST ret
  LOAD_FAST generator
  CALL 2
  YIELD_VALUE 1
  RESUME 1
  POP_TOP
  RETURN_CONST None
L8:
  LOAD_FAST ret
  YIELD_VALUE 1
  RESUME 1
  POP_TOP
  JUMP_BACKWARD L2
L9:
  PUSH_EXC_INFO
  LOAD_GLOBAL StopIteration
  CHECK_EXC_MATCH
  POP_JUMP_IF_FALSE L11
  POP_TOP
L10:
  POP_EXCEPT
  RETURN_CONST None
L11:
  RERAISE 0
L12:
  COPY 3
  POP_EXCEPT
  RERAISE 1
L13:
  CALL_INTRINSIC_1 INTRINSIC_STOPITERATION_ERROR
  RERAISE 1
  EXC try=L1..L3 -> handler=L13 depth=0 lasti=True
  EXC try=L4..L5 -> handler=L9 depth=0 lasti=False
  EXC try=L5..L9 -> handler=L13 depth=0 lasti=True
  EXC try=L9..L10 -> handler=L12 depth=1 lasti=True
  EXC try=L10..L11 -> handler=L13 depth=0 lasti=True
  EXC try=L11..L12 -> handler=L12 depth=1 lasti=True
  EXC try=L12..L13 -> handler=L13 depth=0 lasti=True
END

def _unwindGenerator(self, generator, _prev=None):
    """pass"""
    while True:
        if _prev:
            ret, _prev = (_prev, None)
        else:
            try:
                ret = next(generator)
            except StopIteration:
                break
        if isinstance(ret, Request):
            if ret.callback:
                warnings.warn('Got a request with callback set, bypassing the generator wrapper. Generator may not be able to resume. %s' % ret)
            elif ret.errback:
                warnings.warn('Got a request with errback set, bypassing the generator wrapper. Generator may not be able to resume. %s' % ret)
            else:
                yield self._wrapRequest(ret, generator)
                return
        yield ret


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code jwt_required>
  MAKE_FUNCTION 0
  STORE_NAME jwt_required
  RETURN_CONST None
END
CODE jwt_required(fn)
  DOC 'pass'
  MAKE_CELL fn
  RESUME 0
  LOAD_GLOBAL NULL + wraps
  LOAD_DEREF fn
  CALL 1
  LOAD_CLOSURE fn
  BUILD_TUPLE 1
  LOAD_CONST <code jwt_required.<locals>.wrapper>
  MAKE_FUNCTION closure
  CALL 0
  STORE_FAST wrapper
  LOAD_FAST wrapper
  RETURN_VALUE
END
CODE jwt_required.<locals>.wrapper(*args, **kwargs)
  COPY_FREE_VARS 1
  RESUME 0
  LOAD_GLOBAL NULL + _decode_jwt_from_headers
  CALL 0
  STORE_FAST jwt_data
  LOAD_FAST jwt_data
  LOAD_GLOBAL ctx_stack
  LOAD_ATTR top
  STORE_ATTR jwt
  PUSH_NULL
  LOAD_DEREF fn
  LOAD_FAST args
  BUILD_MAP 0
  LOAD_FAST kwargs
  DICT_MERGE 1
  CALL_FUNCTION_EX 1
  RETURN_VALUE
END

def jwt_required(fn):
    """pass"""

    @wraps(fn)
    def wrapper(*args, **kwargs):
        jwt_data = _decode_jwt_from_headers()
        ctx_stack.top.jwt = jwt_data
        return fn(*args, **kwargs)
    return wrapper


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code jwt_optional>
  MAKE_FUNCTION 0
  STORE_NAME jwt_optional
  RETURN_CONST None
END
CODE jwt_optional(fn)
  DOC 'pass'
  MAKE_CELL fn
  RESUME 0
  LOAD_GLOBAL NULL + wraps
  LOAD_DEREF fn
  CALL 1
  LOAD_CLOSURE fn
  BUILD_TUPLE 1
  LOAD_CONST <code jwt_optional.<locals>.wrapper>
  MAKE_FUNCTION closure
  CALL 0
  STORE_FAST wrapper
  LOAD_FAST wrapper
  RETURN_VALUE
END
CODE jwt_optional.<locals>.wrapper(*args, **kwargs)
  COPY_FREE_VARS 1
  RESUME 0
  NOP
L1:
  LOAD_GLOBAL NULL + _decode_jwt_from_headers
  CALL 0
  STORE_FAST jwt_data
  LOAD_FAST jwt_data
  LOAD_GLOBAL ctx_stack
  LOAD_ATTR top
  STORE_ATTR jwt
L2:
  PUSH_NULL
  LOAD_DEREF fn
  LOAD_FAST args
  BUILD_MAP 0
  LOAD_FAST kwargs
  DICT_MERGE 1
  CALL_FUNCTION_EX 1
  RETURN_VALUE
L3:
  PUSH_EXC_INFO
  LOAD_GLOBAL NoAuthorizationError
  LOAD_GLOBAL InvalidHeaderError
  BUILD_TUPLE 2
  CHECK_EXC_MATCH
  POP_JUMP_IF_FALSE L5
  POP_TOP
L4:
  POP_EXCEPT
  JUMP_BACKWARD L2
L5:
  RERAISE 0
L6:
  COPY 3
  POP_EXCEPT
  RERAISE 1
  EXC try=L1..L2 -> handler=L3 depth=0 lasti=False
  EXC try=L3..L4 -> handler=L6 depth=1 lasti=True
  EXC try=L5..L6 -> handler=L6 depth=1 lasti=True
END

def jwt_optional(fn):
    """pass"""

    @wraps(fn)
    def wrapper(*args, **kwargs):
        try:
            jwt_data = _decode_jwt_from_headers()
            ctx_stack.top.jwt = jwt_data
        except (NoAuthorizationError, InvalidHeaderError):
            pass
        return fn(*args, **kwargs)
    return wrapper


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code decode_jwt>
  MAKE_FUNCTION 0
  STORE_NAME decode_jwt
  RETURN_CONST None
END
CODE decode_jwt(encoded_token)
  DOC 'pass'
  RESUME 0
  LOAD_GLOBAL config
  LOAD_ATTR decode_key
  STORE_FAST secret
  LOAD_GLOBAL config
  LOAD_ATTR algorithm
  STORE_FAST algorithm
  LOAD_GLOBAL config
  LOAD_ATTR audience
  STORE_FAST audience
  LOAD_GLOBAL jwt
  LOAD_ATTR NULL|self + decode
  LOAD_FAST encoded_token
  LOAD_FAST secret
  LOAD_FAST algorithm
  BUILD_LIST 1
  LOAD_FAST audience
  KW_NAMES ('algorithms', 'audience')
  CALL 4
  RETURN_VALUE
END

def decode_jwt(encoded_token):
    """pass"""
    secret = config.decode_key
    algorithm = config.algorithm
    audience = config.audience
    return jwt.decode(encoded_token, secret, algorithms=[algorithm], audience=audience)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code init_app>
  MAKE_FUNCTION 0
  STORE_NAME init_app
  RETURN_CONST None
END
CODE init_app(self, app)
  DOC 'pass'
  RESUME 0
  LOAD_GLOBAL NULL + hasattr
  LOAD_FAST app
  LOAD_CONST 'extensions'
  CALL 2
  POP_JUMP_IF_TRUE L1
  BUILD_MAP 0
  LOAD_FAST app
  STORE_ATTR extensions
L1:
  LOAD_FAST self
  LOAD_FAST app
  LOAD_ATTR extensions
  LOAD_CONST 'flask-jwt-simple'
  STORE_SUBSCR
  LOAD_FAST self
  LOAD_ATTR NULL|self + _set_default_configuration_options
  LOAD_FAST app
  CALL 1
  POP_TOP
  LOAD_FAST self
  LOAD_ATTR NULL|self + _set_error_handler_callbacks
  LOAD_FAST app
  CALL 1
  POP_TOP
  LOAD_CONST True
  LOAD_FAST app
  LOAD_ATTR config
  LOAD_CONST 'PROPAGATE_EXCEPTIONS'
  STORE_SUBSCR
  RETURN_CONST None
END

def init_app(self, app):
    """pass"""
    if not hasattr(app, 'extensions'):
        app.extensions = {}
    app.extensions['flask-jwt-simple'] = self
    self._set_default_configuration_options(app)
    self._set_error_handler_callbacks(app)
    app.config['PROPAGATE_EXCEPTIONS'] = True


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code _set_error_handler_callbacks>
  MAKE_FUNCTION 0
  STORE_NAME _set_error_handler_callbacks
  RETURN_CONST None
END
CODE _set_error_handler_callbacks(self, app)
  DOC 'pass'
  MAKE_CELL self
  RESUME 0
  LOAD_FAST app
  LOAD_ATTR NULL|self + errorhandler
  LOAD_GLOBAL NoAuthorizationError
  CALL 1
  LOAD_CLOSURE self
  BUILD_TUPLE 1
  LOAD_CONST <code _set_error_handler_callbacks.<locals>.handle_no_auth_error>
  MAKE_FUNCTION closure
  CALL 0
  STORE_FAST handle_no_auth_error
  LOAD_FAST app
  LOAD_ATTR NULL|self + errorhandler
  LOAD_GLOBAL InvalidHeaderError
  CALL 1
  LOAD_CLOSURE self
  BUILD_TUPLE 1
  LOAD_CONST <code _set_error_handler_callbacks.<locals>.handle_invalid_header_error>
  MAKE_FUNCTION closure
  CALL 0
  STORE_FAST handle_invalid_header_error
  LOAD_FAST app
  LOAD_ATTR NULL|self + errorhandler
  LOAD_GLOBAL jwt
  LOAD_ATTR ExpiredSignatureError
  CALL 1
  LOAD_CLOSURE self
  BUILD_TUPLE 1
  LOAD_CONST <code _set_error_handler_callbacks.<locals>.handle_expired_error>
  MAKE_FUNCTION closure
  CALL 0
  STORE_FAST handle_expired_error
  LOAD_FAST app
  LOAD_ATTR NULL|self + errorhandler
  LOAD_GLOBAL jwt
  LOAD_ATTR InvalidTokenError
  CALL 1
  LOAD_CLOSURE self
  BUILD_TUPLE 1
  LOAD_CONST <code _set_error_handler_callbacks.<locals>.handle_invalid_token_error>
  MAKE_FUNCTION closure
  CALL 0
  STORE_FAST handle_invalid_token_error
  RETURN_CONST None
END
CODE _set_error_handler_callbacks.<locals>.handle_no_auth_error(e)
  COPY_FREE_VARS 1
  RESUME 0
  LOAD_DEREF self
  LOAD_ATTR NULL|self + _unauthorized_callback
  LOAD_GLOBAL NULL + str
  LOAD_FAST e
  CALL 1
  CALL 1
  RETURN_VALUE
END
CODE _set_error_handler_callbacks.<locals>.handle_invalid_header_error(e)
  COPY_FREE_VARS 1
  RESUME 0
  LOAD_DEREF self
  LOAD_ATTR NULL|self + _invalid_token_callback
  LOAD_GLOBAL NULL + str
  LOAD_FAST e
  CALL 1
  CALL 1
  RETURN_VALUE
END
CODE _set_error_handler_callbacks.<locals>.handle_expired_error(e)
  COPY_FREE_VARS 1
  RESUME 0
  LOAD_DEREF self
  LOAD_ATTR NULL|self + _expired_token_callback
  CALL 0
  RETURN_VALUE
END
CODE _set_error_handler_callbacks.<locals>.handle_invalid_token_error(e)
  COPY_FREE_VARS 1
  RESUME 0
  LOAD_DEREF self
  LOAD_ATTR NULL|self + _invalid_token_callback
  LOAD_GLOBAL NULL + str
  LOAD_FAST e
  CALL 1
  CALL 1
  RETURN_VALUE
END

def _set_error_handler_callbacks(self, app):
    """pass"""

    @app.errorhandler(NoAuthorizationError)
    def handle_no_auth_error(e):
        return self._unauthorized_callback(str(e))

    @app.errorhandler(InvalidHeaderError)
    def handle_invalid_header_error(e):
        return self._invalid_token_callback(str(e))

    @app.errorhandler(jwt.ExpiredSignatureError)
    def handle_expired_error(e):
        return self._expired_token_callback()

    @app.errorhandler(jwt.InvalidTokenError)
    def handle_invalid_token_error(e):
        return self._invalid_token_callback(str(e))


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code _set_default_configuration_options>
  MAKE_FUNCTION 0
  STORE_NAME _set_default_configuration_options
  RETURN_CONST None
END
CODE _set_default_configuration_options(app)
  DOC 'pass'
  RESUME 0
  LOAD_FAST app
  LOAD_ATTR config
  LOAD_ATTR NULL|self + setdefault
  LOAD_CONST 'JWT_HEADER_NAME'
  LOAD_CONST 'Authorization'
  CALL 2
  POP_TOP
  LOAD_FAST app
  LOAD_ATTR config
  LOAD_ATTR NULL|self + setdefault
  LOAD_CONST 'JWT_HEADER_TYPE'
  LOAD_CONST 'Bearer'
  CALL 2
  POP_TOP
  LOAD_FAST app
  LOAD_ATTR config
  LOAD_ATTR NULL|self + setdefault
  LOAD_CONST 'JWT_EXPIRES'
  LOAD_GLOBAL datetime
  LOAD_ATTR NULL|self + timedelta
  LOAD_CONST 1
  KW_NAMES ('hours',)
  CALL 1
  CALL 2
  POP_TOP
  LOAD_FAST app
  LOAD_ATTR config
  LOAD_ATTR NULL|self + setdefault
  LOAD_CONST 'JWT_ALGORITHM'
  LOAD_CONST 'HS256'
  CALL 2
  POP_TOP
  LOAD_FAST app
  LOAD_ATTR config
  LOAD_ATTR NULL|self + setdefault
  LOAD_CONST 'JWT_IDENTITY_CLAIM'
  LOAD_CONST 'sub'
  CALL 2
  POP_TOP
  LOAD_FAST app
  LOAD_ATTR config
  LOAD_ATTR NULL|self + setdefault
  LOAD_CONST 'JWT_DECODE_AUDIENCE'
  LOAD_CONST None
  CALL 2
  POP_TOP
  LOAD_FAST app
  LOAD_ATTR config
  LOAD_ATTR NULL|self + setdefault
  LOAD_CONST 'JWT_SECRET_KEY'
  LOAD_CONST None
  CALL 2
  POP_TOP
  LOAD_FAST app
  LOAD_ATTR config
  LOAD_ATTR NULL|self + setdefault
  LOAD_CONST 'JWT_PRIVATE_KEY'
  LOAD_CONST None
  CALL 2
  POP_TOP
  LOAD_FAST app
  LOAD_ATTR config
  LOAD_ATTR NULL|self + setdefault
  LOAD_CONST 'JWT_PUBLIC_KEY'
  LOAD_CONST None
  CALL 2
  POP_TOP
  RETURN_CONST None
END

def _set_default_configuration_options(app):
    """pass"""
    app.config.setdefault('JWT_HEADER_NAME', 'Authorization')
    app.config.setdefault('JWT_HEADER_TYPE', 'Bearer')
    app.config.setdefault('JWT_EXPIRES', datetime.timedelta(hours=1))
    app.config.setdefault('JWT_ALGORITHM', 'HS256')
    app.config.setdefault('JWT_IDENTITY_CLAIM', 'sub')
    app.config.setdefault('JWT_DECODE_AUDIENCE', None)
    app.config.setdefault('JWT_SECRET_KEY', None)
    app.config.setdefault('JWT_PRIVATE_KEY', None)
    app.config.setdefault('JWT_PUBLIC_KEY', None)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code category>
  MAKE_FUNCTION 0
  STORE_NAME category
  RETURN_CONST None
END
CODE category(**kwargs)
  DOC 'pass'
  RESUME 0
  LOAD_CONST 'series'
  LOAD_FAST kwargs
  CONTAINS_OP 0
  POP_JUMP_IF_FALSE L1
  LOAD_FAST kwargs
  LOAD_ATTR NULL|self + pop
  LOAD_CONST 'series'
  CALL 1
  POP_TOP
  LOAD_CONST 'series'
  STORE_FAST path
  JUMP_FORWARD L2
L1:
  LOAD_CONST None
  STORE_FAST path
L2:
  PUSH_NULL
  LOAD_GLOBAL NULL + Fred
  CALL 0
  LOAD_ATTR category
  LOAD_FAST path
  BUILD_TUPLE 1
  BUILD_MAP 0
  LOAD_FAST kwargs
  DICT_MERGE 1
  CALL_FUNCTION_EX 1
  RETURN_VALUE
END

def category(**kwargs):
    """pass"""
    if 'series' in kwargs:
        kwargs.pop('series')
        path = 'series'
    else:
        path = None
    return Fred().category(path, **kwargs)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST (None,)
  LOAD_CONST <code releases>
  MAKE_FUNCTION defaults
  STORE_NAME releases
  RETURN_CONST None
END
CODE releases(release_id, **kwargs)
  DOC 'pass'
  RESUME 0
  LOAD_CONST 'id'
  LOAD_FAST kwargs
  CONTAINS_OP 1
  POP_JUMP_IF_FALSE L1
  LOAD_FAST release_id
  POP_JUMP_IF_NONE L1
  LOAD_FAST release_id
  LOAD_FAST kwargs
  LOAD_CONST 'release_id'
  STORE_SUBSCR
  PUSH_NULL
  LOAD_GLOBAL NULL + Fred
  CALL 0
  LOAD_ATTR release
  LOAD_CONST ()
  BUILD_MAP 0
  LOAD_FAST kwargs
  DICT_MERGE 1
  CALL_FUNCTION_EX 1
  RETURN_VALUE
L1:
  PUSH_NULL
  LOAD_GLOBAL NULL + Fred
  CALL 0
  LOAD_ATTR releases
  LOAD_CONST ()
  BUILD_MAP 0
  LOAD_FAST kwargs
  DICT_MERGE 1
  CALL_FUNCTION_EX 1
  RETURN_VALUE
END

def releases(release_id=None, **kwargs):
    """pass"""
    if not 'id' in kwargs and release_id is not None:
        kwargs['release_id'] = release_id
        return Fred().release(**kwargs)
    return Fred().releases(**kwargs)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST (None,)
  LOAD_CONST <code series>
  MAKE_FUNCTION defaults
  STORE_NAME series
  RETURN_CONST None
END
CODE series(identifier, **kwargs)
  DOC 'pass'
  RESUME 0
  LOAD_FAST identifier
  POP_JUMP_IF_FALSE L1
  LOAD_FAST identifier
  LOAD_FAST kwargs
  LOAD_CONST 'series_id'
  STORE_SUBSCR
L1:
  LOAD_CONST 'release'
  LOAD_FAST kwargs
  CONTAINS_OP 0
  POP_JUMP_IF_FALSE L2
  LOAD_FAST kwargs
  LOAD_ATTR NULL|self + pop
  LOAD_CONST 'release'
  CALL 1
  POP_TOP
  LOAD_CONST 'release'
  STORE_FAST path
  JUMP_FORWARD L4
L2:
  LOAD_CONST 'releases'
  LOAD_FAST kwargs
  CONTAINS_OP 0
  POP_JUMP_IF_FALSE L3
  LOAD_FAST kwargs
  LOAD_ATTR NULL|self + pop
  LOAD_CONST 'releases'
  CALL 1
  POP_TOP
  LOAD_CONST 'release'
  STORE_FAST path
  JUMP_FORWARD L4
L3:
  LOAD_CONST None
  STORE_FAST path
L4:
  PUSH_NULL
  LOAD_GLOBAL NULL + Fred
  CALL 0
  LOAD_ATTR series
  LOAD_FAST path
  BUILD_TUPLE 1
  BUILD_MAP 0
  LOAD_FAST kwargs
  DICT_MERGE 1
  CALL_FUNCTION_EX 1
  RETURN_VALUE
END

def series(identifier=None, **kwargs):
    """pass"""
    if identifier:
        kwargs['series_id'] = identifier
    if 'release' in kwargs:
        kwargs.pop('release')
        path = 'release'
    elif 'releases' in kwargs:
        kwargs.pop('releases')
        path = 'release'
    else:
        path = None
    return Fred().series(path, **kwargs)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST (None,)
  LOAD_CONST <code source>
  MAKE_FUNCTION defaults
  STORE_NAME source
  RETURN_CONST None
END
CODE source(source_id, **kwargs)
  DOC 'pass'
  RESUME 0
  LOAD_FAST source_id
  POP_JUMP_IF_NONE L1
  LOAD_FAST source_id
  LOAD_FAST kwargs
  LOAD_CONST 'source_id'
  STORE_SUBSCR
  JUMP_FORWARD L2
L1:
  LOAD_CONST 'id'
  LOAD_FAST kwargs
  CONTAINS_OP 0
  POP_JUMP_IF_FALSE L2
  LOAD_FAST kwargs
  LOAD_ATTR NULL|self + pop
  LOAD_CONST 'id'
  CALL 1
  STORE_FAST source_id
  LOAD_FAST source_id
  LOAD_FAST kwargs
  LOAD_CONST 'source_id'
  STORE_SUBSCR
L2:
  LOAD_CONST 'releases'
  LOAD_FAST kwargs
  CONTAINS_OP 0
  POP_JUMP_IF_FALSE L3
  LOAD_FAST kwargs
  LOAD_ATTR NULL|self + pop
  LOAD_CONST 'releases'
  CALL 1
  POP_TOP
  LOAD_CONST 'releases'
  STORE_FAST path
  JUMP_FORWARD L4
L3:
  LOAD_CONST None
  STORE_FAST path
L4:
  PUSH_NULL
  LOAD_GLOBAL NULL + Fred
  CALL 0
  LOAD_ATTR source
  LOAD_FAST path
  BUILD_TUPLE 1
  BUILD_MAP 0
  LOAD_FAST kwargs
  DICT_MERGE 1
  CALL_FUNCTION_EX 1
  RETURN_VALUE
END

def source(source_id=None, **kwargs):
    """pass"""
    if source_id is not None:
        kwargs['source_id'] = source_id
    elif 'id' in kwargs:
        source_id = kwargs.pop('id')
        kwargs['source_id'] = source_id
    if 'releases' in kwargs:
        kwargs.pop('releases')
        path = 'releases'
    else:
        path = None
    return Fred().source(path, **kwargs)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST (None,)
  LOAD_CONST <code sources>
  MAKE_FUNCTION defaults
  STORE_NAME sources
  RETURN_CONST None
END
CODE sources(source_id, **kwargs)
  DOC 'pass'
  RESUME 0
  LOAD_FAST source_id
  POP_JUMP_IF_TRUE L1
  LOAD_CONST 'id'
  LOAD_FAST kwargs
  CONTAINS_OP 0
  POP_JUMP_IF_FALSE L2
L1:
  LOAD_GLOBAL NULL + source
  LOAD_FAST source_id
  BUILD_TUPLE 1
  BUILD_MAP 0
  LOAD_FAST kwargs
  DICT_MERGE 1
  CALL_FUNCTION_EX 1
  RETURN_VALUE
L2:
  PUSH_NULL
  LOAD_GLOBAL NULL + Fred
  CALL 0
  LOAD_ATTR sources
  LOAD_CONST ()
  BUILD_MAP 0
  LOAD_FAST kwargs
  DICT_MERGE 1
  CALL_FUNCTION_EX 1
  RETURN_VALUE
END

def sources(source_id=None, **kwargs):
    """pass"""
    if source_id or 'id' in kwargs:
        return source(source_id, **kwargs)
    return Fred().sources(**kwargs)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code _create_path>
  MAKE_FUNCTION 0
  STORE_NAME _create_path
  RETURN_CONST None
END
CODE _create_path(self, *args)
  DOC 'pass'
  RESUME 0
  LOAD_GLOBAL NULL + filter
  LOAD_CONST None
  LOAD_FAST args
  CALL 2
  STORE_FAST args
  LOAD_FAST self
  LOAD_ATTR endpoint
  LOAD_CONST '/'
  LOAD_ATTR NULL|self + join
  LOAD_FAST args
  CALL 1
  BINARY_OP +
  STORE_FAST path
  LOAD_FAST path
  RETURN_VALUE
END

def _create_path(self, *args):
    """pass"""
    args = filter(None, args)
    path = self.endpoint + '/'.join(args)
    return path


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code item_extra_kwargs>
  MAKE_FUNCTION 0
  STORE_NAME item_extra_kwargs
  RETURN_CONST None
END
CODE item_extra_kwargs(self, item)
  DOC 'pass'
  RESUME 0
  LOAD_GLOBAL use_feed_image
  POP_JUMP_IF_FALSE L2
  LOAD_FAST item
  LOAD_ATTR feed_image
  STORE_FAST feed_image
  LOAD_FAST feed_image
  POP_JUMP_IF_FALSE L1
  LOAD_GLOBAL NULL + urljoin
  LOAD_FAST self
  LOAD_ATTR NULL|self + get_site_url
  CALL 0
  LOAD_FAST feed_image
  LOAD_ATTR file
  LOAD_ATTR url
  CALL 2
  STORE_FAST image_complete_url
  JUMP_FORWARD L2
L1:
  LOAD_CONST ''
  STORE_FAST image_complete_url
L2:
  LOAD_GLOBAL NULL + getattr
  LOAD_FAST item
  LOAD_FAST self
  LOAD_ATTR item_content_field
  CALL 2
  STORE_FAST content_field
  NOP
L3:
  LOAD_GLOBAL NULL + expand_db_html
  LOAD_FAST content_field
  CALL 1
  STORE_FAST content
L4:
  LOAD_GLOBAL NULL + BeautifulSoup
  LOAD_FAST content
  LOAD_CONST 'html.parser'
  CALL 2
  STORE_FAST soup
  LOAD_FAST soup
  LOAD_ATTR NULL|self + find_all
  LOAD_CONST 'div'
  LOAD_CONST 'class'
  LOAD_CONST 'responsive-object'
  BUILD_MAP 1
  CALL 2
  GET_ITER
L5:
  FOR_ITER L6
  STORE_FAST div
  LOAD_FAST div
  LOAD_CONST 'style'
  DELETE_SUBSCR
  JUMP_BACKWARD L5
L6:
  END_FOR
  LOAD_FAST soup
  LOAD_ATTR NULL|self + findAll
  LOAD_CONST 'img'
  CALL 1
  GET_ITER
L7:
  FOR_ITER L9
  STORE_FAST img_tag
  LOAD_FAST img_tag
  LOAD_ATTR NULL|self + has_attr
  LOAD_CONST 'src'
  CALL 1
  POP_JUMP_IF_TRUE L8
  JUMP_BACKWARD L7
L8:
  LOAD_GLOBAL NULL + urljoin
  LOAD_FAST self
  LOAD_ATTR NULL|self + get_site_url
  CALL 0
  LOAD_FAST img_tag
  LOAD_CONST 'src'
  BINARY_SUBSCR
  CALL 2
  LOAD_FAST img_tag
  LOAD_CONST 'src'
  STORE_SUBSCR
  JUMP_BACKWARD L7
L9:
  END_FOR
  LOAD_CONST 'content'
  LOAD_FAST soup
  LOAD_ATTR NULL|self + prettify
  LOAD_CONST 'html'
  KW_NAMES ('formatter',)
  CALL 1
  BUILD_MAP 1
  STORE_FAST fields_to_add
  LOAD_GLOBAL use_feed_image
  POP_JUMP_IF_FALSE L10
  LOAD_FAST_CHECK image_complete_url
  LOAD_FAST fields_to_add
  LOAD_CONST 'image'
  STORE_SUBSCR
  LOAD_FAST fields_to_add
  RETURN_VALUE
L10:
  LOAD_CONST ''
  LOAD_FAST fields_to_add
  LOAD_CONST 'image'
  STORE_SUBSCR
  LOAD_FAST fields_to_add
  RETURN_VALUE
L11:
  PUSH_EXC_INFO
  POP_TOP
  LOAD_FAST content_field
  LOAD_ATTR NULL|self + __html__
  CALL 0
  STORE_FAST content
L12:
  POP_EXCEPT
  JUMP_BACKWARD L4
L13:
  COPY 3
  POP_EXCEPT
  RERAISE 1
  EXC try=L3..L4 -> handler=L11 depth=0 lasti=False
  EXC try=L11..L12 -> handler=L13 depth=1 lasti=True
END

def item_extra_kwargs(self, item):
    """pass"""
    if use_feed_image:
        feed_image = item.feed_image
        if feed_image:
            image_complete_url = urljoin(self.get_site_url(), feed_image.file.url)
        else:
            image_complete_url = ''
    content_field = getattr(item, self.item_content_field)
    try:
        content = expand_db_html(content_field)
    except:
        content = content_field.__html__()
    soup = BeautifulSoup(content, 'html.parser')
    for div in soup.find_all('div', {'class': 'responsive-object'}):
        del div['style']
    for img_tag in soup.findAll('img'):
        if img_tag.has_attr('src'):
            img_tag['src'] = urljoin(self.get_site_url(), img_tag['src'])
    fields_to_add = {'content': soup.prettify(formatter='html')}
    if use_feed_image:
        fields_to_add['image'] = image_complete_url
    else:
        fields_to_add['image'] = ''
    return fields_to_add


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code treenav_undefined_url>
  MAKE_FUNCTION 0
  STORE_NAME treenav_undefined_url
  RETURN_CONST None
END
CODE treenav_undefined_url(request, item_slug)
  DOC 'pass'
  RESUME 0
  LOAD_GLOBAL NULL + get_object_or_404
  LOAD_GLOBAL treenav
  LOAD_ATTR MenuItem
  LOAD_FAST item_slug
  KW_NAMES ('slug',)
  CALL 2
  STORE_FAST item
  LOAD_GLOBAL Http404
  RAISE_VARARGS 1
END

def treenav_undefined_url(request, item_slug):
    """pass"""
    item = get_object_or_404(treenav.MenuItem, slug=item_slug)
    raise Http404


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code treenav_save_other_object_handler>
  MAKE_FUNCTION 0
  STORE_NAME treenav_save_other_object_handler
  RETURN_CONST None
END
CODE treenav_save_other_object_handler(sender, instance, created, **kwargs)
  DOC 'pass'
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST ('ContentType',)
  IMPORT_NAME django.contrib.contenttypes.models
  IMPORT_FROM ContentType
  STORE_FAST ContentType
  POP_TOP
  LOAD_CONST 1
  LOAD_CONST ('MenuItem',)
  IMPORT_NAME models
  IMPORT_FROM MenuItem
  STORE_FAST MenuItem
  POP_TOP
  LOAD_CONST 'django-treenav-menumodels'
  STORE_FAST cache_key
  LOAD_FAST sender
  LOAD_FAST MenuItem
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L1
  LOAD_GLOBAL cache
  LOAD_ATTR NULL|self + delete
  LOAD_FAST cache_key
  CALL 1
  POP_TOP
L1:
  LOAD_GLOBAL cache
  LOAD_ATTR NULL|self + get
  LOAD_FAST cache_key
  CALL 1
  STORE_FAST menu_models
  LOAD_FAST menu_models
  POP_JUMP_IF_TRUE L4
  BUILD_LIST 0
  STORE_FAST menu_models
  LOAD_FAST MenuItem
  LOAD_ATTR objects
  LOAD_ATTR NULL|self + exclude
  LOAD_CONST True
  KW_NAMES ('content_type__isnull',)
  CALL 1
  GET_ITER
L2:
  FOR_ITER L3
  STORE_FAST menu_item
  LOAD_FAST menu_models
  LOAD_ATTR NULL|self + append
  LOAD_FAST menu_item
  LOAD_ATTR content_type
  LOAD_ATTR NULL|self + model_class
  CALL 0
  CALL 1
  POP_TOP
  JUMP_BACKWARD L2
L3:
  END_FOR
  LOAD_GLOBAL cache
  LOAD_ATTR NULL|self + set
  LOAD_FAST cache_key
  LOAD_FAST menu_models
  CALL 2
  POP_TOP
L4:
  LOAD_FAST sender
  LOAD_FAST menu_models
  CONTAINS_OP 0
  POP_JUMP_IF_FALSE L8
  LOAD_FAST ContentType
  LOAD_ATTR objects
  LOAD_ATTR NULL|self + get_for_model
  LOAD_FAST sender
  CALL 1
  STORE_FAST ct
  LOAD_FAST MenuItem
  LOAD_ATTR objects
  LOAD_ATTR NULL|self + filter
  LOAD_FAST ct
  LOAD_FAST instance
  LOAD_ATTR pk
  KW_NAMES ('content_type', 'object_id')
  CALL 2
  STORE_FAST items
  LOAD_FAST items
  GET_ITER
L5:
  FOR_ITER L7
  STORE_FAST item
  LOAD_FAST item
  LOAD_ATTR href
  LOAD_FAST instance
  LOAD_ATTR NULL|self + get_absolute_url
  CALL 0
  COMPARE_OP !=
  POP_JUMP_IF_TRUE L6
  JUMP_BACKWARD L5
L6:
  LOAD_FAST instance
  LOAD_ATTR NULL|self + get_absolute_url
  CALL 0
  LOAD_FAST item
  STORE_ATTR href
  LOAD_FAST item
  LOAD_ATTR NULL|self + save
  CALL 0
  POP_TOP
  JUMP_BACKWARD L5
L7:
  END_FOR
  RETURN_CONST None
L8:
  RETURN_CONST None
END

def treenav_save_other_object_handler(sender, instance, created, **kwargs):
    """pass"""
    from django.contrib.contenttypes.models import ContentType
    from .models import MenuItem
    cache_key = 'django-treenav-menumodels'
    if sender == MenuItem:
        cache.delete(cache_key)
    menu_models = cache.get(cache_key)
    if not menu_models:
        menu_models = []
        for menu_item in MenuItem.objects.exclude(content_type__isnull=True):
            menu_models.append(menu_item.content_type.model_class())
        cache.set(cache_key, menu_models)
    if sender in menu_models:
        ct = ContentType.objects.get_for_model(sender)
        items = MenuItem.objects.filter(content_type=ct, object_id=instance.pk)
        for item in items:
            if item.href != instance.get_absolute_url():
                item.href = instance.get_absolute_url()
                item.save()


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code refresh_hrefs>
  MAKE_FUNCTION 0
  STORE_NAME refresh_hrefs
  RETURN_CONST None
END
CODE refresh_hrefs(self, request)
  DOC 'pass'
  RESUME 0
  LOAD_GLOBAL treenav
  LOAD_ATTR MenuItem
  LOAD_ATTR objects
  LOAD_ATTR NULL|self + all
  CALL 0
  GET_ITER
L1:
  FOR_ITER L2
  STORE_FAST item
  LOAD_FAST item
  LOAD_ATTR NULL|self + save
  CALL 0
  POP_TOP
  JUMP_BACKWARD L1
L2:
  END_FOR
  LOAD_FAST self
  LOAD_ATTR NULL|self + message_user
  LOAD_FAST request
  LOAD_GLOBAL NULL + _
  LOAD_CONST 'Menu item HREFs refreshed successfully.'
  CALL 1
  CALL 2
  POP_TOP
  LOAD_FAST self
  LOAD_ATTR model
  LOAD_ATTR _meta
  LOAD_ATTR app_label
  LOAD_FAST self
  LOAD_ATTR model
  LOAD_ATTR _meta
  LOAD_ATTR model_name
  BUILD_TUPLE 2
  STORE_FAST info
  LOAD_GLOBAL NULL + reverse
  LOAD_CONST 'admin:%s_%s_changelist'
  LOAD_FAST info
  BINARY_OP %
  LOAD_FAST self
  LOAD_ATTR admin_site
  LOAD_ATTR name
  KW_NAMES ('current_app',)
  CALL 2
  STORE_FAST changelist_url
  LOAD_GLOBAL NULL + redirect
  LOAD_FAST changelist_url
  CALL 1
  RETURN_VALUE
END

def refresh_hrefs(self, request):
    """pass"""
    for item in treenav.MenuItem.objects.all():
        item.save()
    self.message_user(request, _('Menu item HREFs refreshed successfully.'))
    info = (self.model._meta.app_label, self.model._meta.model_name)
    changelist_url = reverse('admin:%s_%s_changelist' % info, current_app=self.admin_site.name)
    return redirect(changelist_url)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code clean_cache>
  MAKE_FUNCTION 0
  STORE_NAME clean_cache
  RETURN_CONST None
END
CODE clean_cache(self, request)
  DOC 'pass'
  RESUME 0
  LOAD_GLOBAL treenav
  LOAD_ATTR NULL|self + delete_cache
  CALL 0
  POP_TOP
  LOAD_FAST self
  LOAD_ATTR NULL|self + message_user
  LOAD_FAST request
  LOAD_GLOBAL NULL + _
  LOAD_CONST 'Cache menuitem cache cleaned successfully.'
  CALL 1
  CALL 2
  POP_TOP
  LOAD_FAST self
  LOAD_ATTR model
  LOAD_ATTR _meta
  LOAD_ATTR app_label
  LOAD_FAST self
  LOAD_ATTR model
  LOAD_ATTR _meta
  LOAD_ATTR model_name
  BUILD_TUPLE 2
  STORE_FAST info
  LOAD_GLOBAL NULL + reverse
  LOAD_CONST 'admin:%s_%s_changelist'
  LOAD_FAST info
  BINARY_OP %
  LOAD_FAST self
  LOAD_ATTR admin_site
  LOAD_ATTR name
  KW_NAMES ('current_app',)
  CALL 2
  STORE_FAST changelist_url
  LOAD_GLOBAL NULL + redirect
  LOAD_FAST changelist_url
  CALL 1
  RETURN_VALUE
END

def clean_cache(self, request):
    """pass"""
    treenav.delete_cache()
    self.message_user(request, _('Cache menuitem cache cleaned successfully.'))
    info = (self.model._meta.app_label, self.model._meta.model_name)
    changelist_url = reverse('admin:%s_%s_changelist' % info, current_app=self.admin_site.name)
    return redirect(changelist_url)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code rebuild_tree>
  MAKE_FUNCTION 0
  STORE_NAME rebuild_tree
  RETURN_CONST None
END
CODE rebuild_tree(self, request)
  DOC 'pass'
  RESUME 0
  LOAD_FAST self
  LOAD_ATTR model
  LOAD_ATTR objects
  LOAD_ATTR NULL|self + rebuild
  CALL 0
  POP_TOP
  LOAD_FAST self
  LOAD_ATTR NULL|self + message_user
  LOAD_FAST request
  LOAD_GLOBAL NULL + _
  LOAD_CONST 'Menu Tree Rebuilt.'
  CALL 1
  CALL 2
  POP_TOP
  LOAD_FAST self
  LOAD_ATTR NULL|self + clean_cache
  LOAD_FAST request
  CALL 1
  RETURN_VALUE
END

def rebuild_tree(self, request):
    """pass"""
    self.model.objects.rebuild()
    self.message_user(request, _('Menu Tree Rebuilt.'))
    return self.clean_cache(request)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code save_related>
  MAKE_FUNCTION 0
  STORE_NAME save_related
  RETURN_CONST None
END
CODE save_related(self, request, form, formsets, change)
  DOC 'pass'
  RESUME 0
  LOAD_GLOBAL super
  LOAD_GLOBAL MenuItemAdmin
  LOAD_FAST self
  LOAD_SUPER_ATTR NULL|self + save_related
  LOAD_FAST request
  LOAD_FAST form
  LOAD_FAST formsets
  LOAD_FAST change
  CALL 4
  POP_TOP
  LOAD_FAST self
  LOAD_ATTR model
  LOAD_ATTR objects
  LOAD_ATTR NULL|self + rebuild
  CALL 0
  POP_TOP
  RETURN_CONST None
END

def save_related(self, request, form, formsets, change):
    """pass"""
    super(MenuItemAdmin, self).save_related(request, form, formsets, change)
    self.model.objects.rebuild()


Input:
CODE <module>()
  DOC 'X'
  RESUME 0
  LOAD_CONST 'X'
  LOAD_NAME Union
  LOAD_NAME pd
  LOAD_ATTR DataFrame
  LOAD_NAME np
  LOAD_ATTR ndarray
  BUILD_TUPLE 2
  BINARY_SUBSCR
  LOAD_CONST 'labels'
  LOAD_NAME np
  LOAD_ATTR ndarray
  LOAD_CONST 'centroids'
  LOAD_NAME np
  LOAD_ATTR ndarray
  LOAD_CONST 'return'
  LOAD_NAME float
  BUILD_TUPLE 8
  LOAD_CONST <code _calculate_dispersion>
  MAKE_FUNCTION annotations
  STORE_NAME _calculate_dispersion
  RETURN_CONST None
END
CODE _calculate_dispersion(X, labels, centroids)
  DOC 'pass'
  RESUME 0
  LOAD_GLOBAL np
  LOAD_ATTR NULL|self + sum
  LOAD_GLOBAL np
  LOAD_ATTR NULL|self + sum
  LOAD_GLOBAL NULL + zip
  LOAD_FAST X
  LOAD_FAST labels
  CALL 2
  GET_ITER
  LOAD_FAST_AND_CLEAR inst
  LOAD_FAST_AND_CLEAR label
  SWAP 3
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L3
  UNPACK_SEQUENCE 2
  STORE_FAST inst
  STORE_FAST label
  LOAD_GLOBAL np
  LOAD_ATTR NULL|self + abs
  LOAD_FAST inst
  LOAD_FAST centroids
  LOAD_FAST label
  BINARY_SUBSCR
  BINARY_OP -
  CALL 1
  LOAD_CONST 2
  BINARY_OP **
  LIST_APPEND 2
  JUMP_BACKWARD L2
L3:
  END_FOR
L4:
  SWAP 3
  STORE_FAST label
  STORE_FAST inst
  CALL 1
  CALL 1
  STORE_FAST disp
  LOAD_FAST disp
  RETURN_VALUE
L5:
  SWAP 2
  POP_TOP
  SWAP 3
  STORE_FAST label
  STORE_FAST inst
  RERAISE 0
  EXC try=L1..L4 -> handler=L5 depth=7 lasti=False
END

def _calculate_dispersion(X: Union[pd.DataFrame, np.ndarray], labels: np.ndarray, centroids: np.ndarray) -> float:
    """pass"""
    disp = np.sum(np.sum([np.abs(inst - centroids[label]) ** 2 for inst, label in zip(X, labels)]))
    return disp


Input:
CODE <module>()
  DOC 'X'
  RESUME 0
  LOAD_CONST 'X'
  LOAD_NAME Union
  LOAD_NAME pd
  LOAD_ATTR DataFrame
  LOAD_NAME np
  LOAD_ATTR ndarray
  BUILD_TUPLE 2
  BINARY_SUBSCR
  LOAD_CONST 'n_refs'
  LOAD_NAME int
  LOAD_CONST 'n_clusters'
  LOAD_NAME int
  LOAD_CONST 'return'
  LOAD_NAME Tuple
  LOAD_NAME float
  LOAD_NAME int
  BUILD_TUPLE 2
  BINARY_SUBSCR
  BUILD_TUPLE 8
  LOAD_CONST <code _calculate_gap>
  MAKE_FUNCTION annotations
  STORE_NAME _calculate_gap
  RETURN_CONST None
END
CODE _calculate_gap(self, X, n_refs, n_clusters)
  DOC 'pass'
  RESUME 0
  LOAD_GLOBAL np
  LOAD_ATTR NULL|self + zeros
  LOAD_FAST n_refs
  CALL 1
  STORE_FAST ref_dispersions
  LOAD_GLOBAL NULL + range
  LOAD_FAST n_refs
  CALL 1
  GET_ITER
L1:
  FOR_ITER L2
  STORE_FAST i
  LOAD_GLOBAL np
  LOAD_ATTR random
  LOAD_ATTR NULL|self + random_sample
  LOAD_FAST X
  LOAD_ATTR shape
  KW_NAMES ('size',)
  CALL 1
  STORE_FAST random_data
  LOAD_GLOBAL NULL + kmeans2
  LOAD_FAST random_data
  LOAD_FAST n_clusters
  LOAD_CONST 10
  LOAD_CONST 'points'
  KW_NAMES ('data', 'k', 'iter', 'minit')
  CALL 4
  UNPACK_SEQUENCE 2
  STORE_FAST centroids
  STORE_FAST labels
  LOAD_FAST self
  LOAD_ATTR NULL|self + _calculate_dispersion
  LOAD_FAST random_data
  LOAD_FAST labels
  LOAD_FAST centroids
  KW_NAMES ('X', 'labels', 'centroids')
  CALL 3
  STORE_FAST dispersion
  LOAD_FAST dispersion
  LOAD_FAST ref_dispersions
  LOAD_FAST i
  STORE_SUBSCR
  JUMP_BACKWARD L1
L2:
  END_FOR
  LOAD_GLOBAL NULL + kmeans2
  LOAD_FAST X
  LOAD_FAST n_clusters
  LOAD_CONST 10
  LOAD_CONST 'points'
  KW_NAMES ('data', 'k', 'iter', 'minit')
  CALL 4
  UNPACK_SEQUENCE 2
  STORE_FAST centroids
  STORE_FAST labels
  LOAD_FAST self
  LOAD_ATTR NULL|self + _calculate_dispersion
  LOAD_FAST X
  LOAD_FAST labels
  LOAD_FAST centroids
  KW_NAMES ('X', 'labels', 'centroids')
  CALL 3
  STORE_FAST dispersion
  LOAD_GLOBAL np
  LOAD_ATTR NULL|self + mean
  LOAD_GLOBAL np
  LOAD_ATTR NULL|self + log
  LOAD_FAST ref_dispersions
  CALL 1
  CALL 1
  LOAD_GLOBAL np
  LOAD_ATTR NULL|self + log
  LOAD_FAST dispersion
  CALL 1
  BINARY_OP -
  STORE_FAST gap_value
  LOAD_FAST gap_value
  LOAD_GLOBAL NULL + int
  LOAD_FAST n_clusters
  CALL 1
  BUILD_TUPLE 2
  RETURN_VALUE
END

def _calculate_gap(self, X: Union[pd.DataFrame, np.ndarray], n_refs: int, n_clusters: int) -> Tuple[float, int]:
    """pass"""
    ref_dispersions = np.zeros(n_refs)
    for i in range(n_refs):
        random_data = np.random.random_sample(size=X.shape)
        centroids, labels = kmeans2(data=random_data, k=n_clusters, iter=10, minit='points')
        dispersion = self._calculate_dispersion(X=random_data, labels=labels, centroids=centroids)
        ref_dispersions[i] = dispersion
    centroids, labels = kmeans2(data=X, k=n_clusters, iter=10, minit='points')
    dispersion = self._calculate_dispersion(X=X, labels=labels, centroids=centroids)
    gap_value = np.mean(np.log(ref_dispersions)) - np.log(dispersion)
    return (gap_value, int(n_clusters))


Input:
CODE <module>()
  DOC 'X'
  RESUME 0
  LOAD_CONST 'X'
  LOAD_NAME Union
  LOAD_NAME pd
  LOAD_ATTR DataFrame
  LOAD_NAME np
  LOAD_ATTR ndarray
  BUILD_TUPLE 2
  BINARY_SUBSCR
  LOAD_CONST 'n_refs'
  LOAD_NAME int
  LOAD_CONST 'cluster_array'
  LOAD_NAME np
  LOAD_ATTR ndarray
  BUILD_TUPLE 6
  LOAD_CONST <code _process_with_rust>
  MAKE_FUNCTION annotations
  STORE_NAME _process_with_rust
  RETURN_CONST None
END
CODE _process_with_rust(self, X, n_refs, cluster_array)
  DOC 'pass'
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST ('gapstat',)
  IMPORT_NAME gap_statistic.rust
  IMPORT_FROM gapstat
  STORE_FAST gapstat
  POP_TOP
  LOAD_FAST gapstat
  LOAD_ATTR NULL|self + optimal_k
  LOAD_FAST X
  LOAD_GLOBAL NULL + list
  LOAD_FAST cluster_array
  CALL 1
  CALL 2
  GET_ITER
L2:
  FOR_ITER L3
  UNPACK_SEQUENCE 2
  STORE_FAST label
  STORE_FAST gap_value
  LOAD_FAST gap_value
  LOAD_FAST label
  BUILD_TUPLE 2
  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 _process_with_rust(self, X: Union[pd.DataFrame, np.ndarray], n_refs: int, cluster_array: np.ndarray):
    """pass"""
    from gap_statistic.rust import gapstat
    for label, gap_value in gapstat.optimal_k(X, list(cluster_array)):
        yield (gap_value, label)


Input:
CODE <module>()
  DOC 'X'
  RESUME 0
  LOAD_CONST 'X'
  LOAD_NAME Union
  LOAD_NAME pd
  LOAD_ATTR DataFrame
  LOAD_NAME np
  LOAD_ATTR ndarray
  BUILD_TUPLE 2
  BINARY_SUBSCR
  LOAD_CONST 'n_refs'
  LOAD_NAME int
  LOAD_CONST 'cluster_array'
  LOAD_NAME np
  LOAD_ATTR ndarray
  BUILD_TUPLE 6
  LOAD_CONST <code _process_with_joblib>
  MAKE_FUNCTION annotations
  STORE_NAME _process_with_joblib
  RETURN_CONST None
END
CODE _process_with_joblib(self, X, n_refs, cluster_array)
  DOC 'pass'
  MAKE_CELL self
  MAKE_CELL X
  MAKE_CELL n_refs
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_GLOBAL Parallel
  POP_JUMP_IF_NOT_NONE L2
  LOAD_GLOBAL NULL + EnvironmentError
  LOAD_CONST 'joblib is not installed; cannot use joblib as the parallel backend!'
  CALL 1
  RAISE_VARARGS 1
L2:
  LOAD_GLOBAL NULL + Parallel
  LOAD_DEREF self
  LOAD_ATTR n_jobs
  KW_NAMES ('n_jobs',)
  CALL 1
  BEFORE_WITH
L3:
  STORE_FAST parallel
  PUSH_NULL
  LOAD_FAST parallel
  LOAD_CLOSURE X
  LOAD_CLOSURE n_refs
  LOAD_CLOSURE self
  BUILD_TUPLE 3
  LOAD_CONST <code _process_with_joblib.<locals>.<genexpr>>
  MAKE_FUNCTION closure
  LOAD_FAST cluster_array
  GET_ITER
  CALL 0
  CALL 1
  GET_ITER
L4:
  FOR_ITER L5
  UNPACK_SEQUENCE 2
  STORE_FAST gap_value
  STORE_FAST n_clusters
  LOAD_FAST gap_value
  LOAD_FAST n_clusters
  BUILD_TUPLE 2
  YIELD_VALUE 2
  RESUME 1
  POP_TOP
  JUMP_BACKWARD L4
L5:
  END_FOR
L6:
  NOP
L7:
  LOAD_CONST None
  LOAD_CONST None
  LOAD_CONST None
  CALL 2
  POP_TOP
  RETURN_CONST None
L8:
  PUSH_EXC_INFO
  WITH_EXCEPT_START
  POP_JUMP_IF_TRUE L9
  RERAISE 2
L9:
  POP_TOP
L10:
  POP_EXCEPT
  POP_TOP
  POP_TOP
  RETURN_CONST None
L11:
  COPY 3
  POP_EXCEPT
  RERAISE 1
L12:
  CALL_INTRINSIC_1 INTRINSIC_STOPITERATION_ERROR
  RERAISE 1
  EXC try=L1..L3 -> handler=L12 depth=0 lasti=True
  EXC try=L3..L6 -> handler=L8 depth=1 lasti=True
  EXC try=L7..L8 -> handler=L12 depth=0 lasti=True
  EXC try=L8..L10 -> handler=L11 depth=3 lasti=True
  EXC try=L10..L12 -> handler=L12 depth=0 lasti=True
END
CODE _process_with_joblib.<locals>.<genexpr>(.0)
  COPY_FREE_VARS 3
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_FAST .0
L2:
  FOR_ITER L3
  STORE_FAST n_clusters
  PUSH_NULL
  LOAD_GLOBAL NULL + delayed
  LOAD_DEREF self
  LOAD_ATTR _calculate_gap
  CALL 1
  LOAD_DEREF X
  LOAD_DEREF n_refs
  LOAD_FAST n_clusters
  CALL 3
  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 _process_with_joblib(self, X: Union[pd.DataFrame, np.ndarray], n_refs: int, cluster_array: np.ndarray):
    """pass"""
    if Parallel is None:
        raise EnvironmentError('joblib is not installed; cannot use joblib as the parallel backend!')
    with Parallel(n_jobs=self.n_jobs) as parallel:
        for gap_value, n_clusters in parallel((delayed(self._calculate_gap)(X, n_refs, n_clusters) for n_clusters in cluster_array)):
            yield (gap_value, n_clusters)


Input:
CODE <module>()
  DOC 'X'
  RESUME 0
  LOAD_CONST 'X'
  LOAD_NAME Union
  LOAD_NAME pd
  LOAD_ATTR DataFrame
  LOAD_NAME np
  LOAD_ATTR ndarray
  BUILD_TUPLE 2
  BINARY_SUBSCR
  LOAD_CONST 'n_refs'
  LOAD_NAME int
  LOAD_CONST 'cluster_array'
  LOAD_NAME np
  LOAD_ATTR ndarray
  BUILD_TUPLE 6
  LOAD_CONST <code _process_with_multiprocessing>
  MAKE_FUNCTION annotations
  STORE_NAME _process_with_multiprocessing
  RETURN_CONST None
END
CODE _process_with_multiprocessing(self, X, n_refs, cluster_array)
  DOC 'pass'
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_GLOBAL NULL + ProcessPoolExecutor
  LOAD_FAST self
  LOAD_ATTR n_jobs
  KW_NAMES ('max_workers',)
  CALL 1
  BEFORE_WITH
L2:
  STORE_FAST executor
  LOAD_FAST cluster_array
  GET_ITER
  LOAD_FAST_AND_CLEAR n_clusters
  SWAP 2
L3:
  BUILD_LIST 0
  SWAP 2
L4:
  FOR_ITER L5
  STORE_FAST n_clusters
  LOAD_FAST executor
  LOAD_ATTR NULL|self + submit
  LOAD_FAST self
  LOAD_ATTR _calculate_gap
  LOAD_FAST X
  LOAD_FAST n_refs
  LOAD_FAST n_clusters
  CALL 4
  LIST_APPEND 2
  JUMP_BACKWARD L4
L5:
  END_FOR
L6:
  STORE_FAST jobs
  STORE_FAST n_clusters
  LOAD_GLOBAL NULL + as_completed
  LOAD_FAST jobs
  CALL 1
  GET_ITER
L7:
  FOR_ITER L8
  STORE_FAST future
  LOAD_FAST future
  LOAD_ATTR NULL|self + result
  CALL 0
  UNPACK_SEQUENCE 2
  STORE_FAST gap_value
  STORE_FAST k
  LOAD_FAST gap_value
  LOAD_FAST k
  BUILD_TUPLE 2
  YIELD_VALUE 2
  RESUME 1
  POP_TOP
  JUMP_BACKWARD L7
L8:
  END_FOR
L9:
  NOP
L10:
  LOAD_CONST None
  LOAD_CONST None
  LOAD_CONST None
  CALL 2
  POP_TOP
  RETURN_CONST None
L11:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST n_clusters
  RERAISE 0
L12:
  PUSH_EXC_INFO
  WITH_EXCEPT_START
  POP_JUMP_IF_TRUE L13
  RERAISE 2
L13:
  POP_TOP
L14:
  POP_EXCEPT
  POP_TOP
  POP_TOP
  RETURN_CONST None
L15:
  COPY 3
  POP_EXCEPT
  RERAISE 1
L16:
  CALL_INTRINSIC_1 INTRINSIC_STOPITERATION_ERROR
  RERAISE 1
  EXC try=L1..L2 -> handler=L16 depth=0 lasti=True
  EXC try=L2..L3 -> handler=L12 depth=1 lasti=True
  EXC try=L3..L6 -> handler=L11 depth=3 lasti=False
  EXC try=L6..L9 -> handler=L12 depth=1 lasti=True
  EXC try=L10..L11 -> handler=L16 depth=0 lasti=True
  EXC try=L11..L12 -> handler=L12 depth=1 lasti=True
  EXC try=L12..L14 -> handler=L15 depth=3 lasti=True
  EXC try=L14..L16 -> handler=L16 depth=0 lasti=True
END

def _process_with_multiprocessing(self, X: Union[pd.DataFrame, np.ndarray], n_refs: int, cluster_array: np.ndarray):
    """pass"""
    with ProcessPoolExecutor(max_workers=self.n_jobs) as executor:
        jobs = [executor.submit(self._calculate_gap, X, n_refs, n_clusters) for n_clusters in cluster_array]
        for future in as_completed(jobs):
            gap_value, k = future.result()
            yield (gap_value, k)


Input:
CODE <module>()
  DOC 'X'
  RESUME 0
  LOAD_CONST 'X'
  LOAD_NAME Union
  LOAD_NAME pd
  LOAD_ATTR DataFrame
  LOAD_NAME np
  LOAD_ATTR ndarray
  BUILD_TUPLE 2
  BINARY_SUBSCR
  LOAD_CONST 'n_refs'
  LOAD_NAME int
  LOAD_CONST 'cluster_array'
  LOAD_NAME np
  LOAD_ATTR ndarray
  BUILD_TUPLE 6
  LOAD_CONST <code _process_non_parallel>
  MAKE_FUNCTION annotations
  STORE_NAME _process_non_parallel
  RETURN_CONST None
END
CODE _process_non_parallel(self, X, n_refs, cluster_array)
  DOC 'pass'
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_FAST cluster_array
  GET_ITER
  LOAD_FAST_AND_CLEAR n_clusters
  SWAP 2
L2:
  BUILD_LIST 0
  SWAP 2
L3:
  FOR_ITER L4
  STORE_FAST n_clusters
  LOAD_FAST self
  LOAD_ATTR NULL|self + _calculate_gap
  LOAD_FAST X
  LOAD_FAST n_refs
  LOAD_FAST n_clusters
  CALL 3
  LIST_APPEND 2
  JUMP_BACKWARD L3
L4:
  END_FOR
L5:
  SWAP 2
  STORE_FAST n_clusters
  GET_ITER
L6:
  FOR_ITER L7
  UNPACK_SEQUENCE 2
  STORE_FAST gap_value
  STORE_FAST n_clusters
  LOAD_FAST gap_value
  LOAD_FAST n_clusters
  BUILD_TUPLE 2
  YIELD_VALUE 1
  RESUME 1
  POP_TOP
  JUMP_BACKWARD L6
L7:
  END_FOR
  RETURN_CONST None
L8:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST n_clusters
  RERAISE 0
L9:
  CALL_INTRINSIC_1 INTRINSIC_STOPITERATION_ERROR
  RERAISE 1
  EXC try=L1..L2 -> handler=L9 depth=0 lasti=True
  EXC try=L2..L5 -> handler=L8 depth=2 lasti=False
  EXC try=L5..L9 -> handler=L9 depth=0 lasti=True
END

def _process_non_parallel(self, X: Union[pd.DataFrame, np.ndarray], n_refs: int, cluster_array: np.ndarray):
    """pass"""
    for gap_value, n_clusters in [self._calculate_gap(X, n_refs, n_clusters) for n_clusters in cluster_array]:
        yield (gap_value, n_clusters)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code get_last>
  MAKE_FUNCTION 0
  STORE_NAME get_last
  RETURN_CONST None
END
CODE get_last(self)
  DOC 'pass'
  RESUME 0
  LOAD_FAST self
  LOAD_ATTR NULL|self + table
  CALL 0
  LOAD_ATTR NULL|self + where
  LOAD_CONST 'batch'
  LOAD_FAST self
  LOAD_ATTR NULL|self + get_last_batch_number
  CALL 0
  CALL 2
  STORE_FAST query
  LOAD_FAST query
  LOAD_ATTR NULL|self + order_by
  LOAD_CONST 'migration'
  LOAD_CONST 'desc'
  CALL 2
  LOAD_ATTR NULL|self + get
  CALL 0
  RETURN_VALUE
END

def get_last(self):
    """pass"""
    query = self.table().where('batch', self.get_last_batch_number())
    return query.order_by('migration', 'desc').get()


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code compile_insert>
  MAKE_FUNCTION 0
  STORE_NAME compile_insert
  RETURN_CONST None
END
CODE compile_insert(self, query, values)
  DOC 'pass'
  RESUME 0
  LOAD_FAST self
  LOAD_ATTR NULL|self + wrap_table
  LOAD_FAST query
  LOAD_ATTR from__
  CALL 1
  STORE_FAST table
  LOAD_GLOBAL NULL + isinstance
  LOAD_FAST values
  LOAD_GLOBAL list
  CALL 2
  POP_JUMP_IF_TRUE L1
  LOAD_FAST values
  BUILD_LIST 1
  STORE_FAST values
L1:
  LOAD_FAST self
  LOAD_ATTR NULL|self + columnize
  LOAD_FAST values
  LOAD_CONST 0
  BINARY_SUBSCR
  LOAD_ATTR NULL|self + keys
  CALL 0
  CALL 1
  STORE_FAST columns
  LOAD_FAST self
  LOAD_ATTR NULL|self + parameterize
  LOAD_FAST values
  LOAD_CONST 0
  BINARY_SUBSCR
  LOAD_ATTR NULL|self + values
  CALL 0
  CALL 1
  STORE_FAST parameters
  LOAD_CONST '(%s)'
  LOAD_FAST parameters
  BINARY_OP %
  BUILD_LIST 1
  LOAD_GLOBAL NULL + len
  LOAD_FAST values
  CALL 1
  BINARY_OP *
  STORE_FAST value
  LOAD_CONST ', '
  LOAD_ATTR NULL|self + join
  LOAD_FAST value
  CALL 1
  STORE_FAST parameters
  LOAD_CONST 'INSERT INTO '
  LOAD_FAST table
  FORMAT_VALUE str
  LOAD_CONST ' ('
  LOAD_FAST columns
  FORMAT_VALUE str
  LOAD_CONST ') VALUES '
  LOAD_FAST parameters
  FORMAT_VALUE str
  BUILD_STRING 6
  RETURN_VALUE
END

def compile_insert(self, query, values):
    """pass"""
    table = self.wrap_table(query.from__)
    if not isinstance(values, list):
        values = [values]
    columns = self.columnize(values[0].keys())
    parameters = self.parameterize(values[0].values())
    value = ['(%s)' % parameters] * len(values)
    parameters = ', '.join(value)
    return 'INSERT INTO %s (%s) VALUES %s' % (table, columns, parameters)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code get_alter_table_sql>
  MAKE_FUNCTION 0
  STORE_NAME get_alter_table_sql
  RETURN_CONST None
END
CODE get_alter_table_sql(self, diff)
  DOC 'pass'
  RESUME 0
  BUILD_LIST 0
  STORE_FAST sql
  LOAD_FAST diff
  LOAD_ATTR changed_columns
  LOAD_ATTR NULL|self + values
  CALL 0
  GET_ITER
L1:
  EXTENDED_ARG 2
  FOR_ITER L13
  STORE_FAST column_diff
  LOAD_FAST self
  LOAD_ATTR NULL|self + is_unchanged_binary_column
  LOAD_FAST column_diff
  CALL 1
  POP_JUMP_IF_FALSE L2
  JUMP_BACKWARD L1
L2:
  LOAD_FAST column_diff
  LOAD_ATTR old_column_name
  STORE_FAST old_column_name
  LOAD_FAST column_diff
  LOAD_ATTR column
  STORE_FAST column
  LOAD_GLOBAL NULL + any
  LOAD_FAST column_diff
  LOAD_ATTR NULL|self + has_changed
  LOAD_CONST 'type'
  CALL 1
  LOAD_FAST column_diff
  LOAD_ATTR NULL|self + has_changed
  LOAD_CONST 'precision'
  CALL 1
  LOAD_FAST column_diff
  LOAD_ATTR NULL|self + has_changed
  LOAD_CONST 'scale'
  CALL 1
  LOAD_FAST column_diff
  LOAD_ATTR NULL|self + has_changed
  LOAD_CONST 'fixed'
  CALL 1
  BUILD_LIST 4
  CALL 1
  POP_JUMP_IF_FALSE L3
  LOAD_CONST 'ALTER '
  LOAD_FAST old_column_name
  BINARY_OP +
  LOAD_CONST ' TYPE '
  BINARY_OP +
  LOAD_FAST self
  LOAD_ATTR NULL|self + get_sql_type_declaration
  LOAD_FAST column
  LOAD_ATTR NULL|self + to_dict
  CALL 0
  CALL 1
  BINARY_OP +
  STORE_FAST query
  LOAD_FAST sql
  LOAD_ATTR NULL|self + append
  LOAD_CONST 'ALTER TABLE '
  LOAD_FAST diff
  LOAD_ATTR name
  BINARY_OP +
  LOAD_CONST ' '
  BINARY_OP +
  LOAD_FAST query
  BINARY_OP +
  CALL 1
  POP_TOP
L3:
  LOAD_FAST column_diff
  LOAD_ATTR NULL|self + has_changed
  LOAD_CONST 'default'
  CALL 1
  POP_JUMP_IF_TRUE L4
  LOAD_FAST column_diff
  LOAD_ATTR NULL|self + has_changed
  LOAD_CONST 'type'
  CALL 1
  POP_JUMP_IF_FALSE L7
L4:
  LOAD_FAST column
  LOAD_ATTR NULL|self + get_default
  CALL 0
  POP_JUMP_IF_NOT_NONE L5
  LOAD_CONST ' DROP DEFAULT'
  STORE_FAST default_clause
  JUMP_FORWARD L6
L5:
  LOAD_CONST ' SET'
  LOAD_FAST self
  LOAD_ATTR NULL|self + get_default_value_declaration_sql
  LOAD_FAST column
  LOAD_ATTR NULL|self + to_dict
  CALL 0
  CALL 1
  BINARY_OP +
  STORE_FAST default_clause
L6:
  LOAD_CONST 'ALTER '
  LOAD_FAST old_column_name
  BINARY_OP +
  LOAD_FAST default_clause
  BINARY_OP +
  STORE_FAST query
  LOAD_FAST sql
  LOAD_ATTR NULL|self + append
  LOAD_CONST 'ALTER TABLE '
  LOAD_FAST diff
  LOAD_ATTR name
  BINARY_OP +
  LOAD_CONST ' '
  BINARY_OP +
  LOAD_FAST query
  BINARY_OP +
  CALL 1
  POP_TOP
L7:
  LOAD_FAST column_diff
  LOAD_ATTR NULL|self + has_changed
  LOAD_CONST 'notnull'
  CALL 1
  POP_JUMP_IF_FALSE L9
  LOAD_CONST 'DROP'
  STORE_FAST op
  LOAD_FAST column
  LOAD_ATTR NULL|self + get_notnull
  CALL 0
  POP_JUMP_IF_FALSE L8
  LOAD_CONST 'SET'
  STORE_FAST op
L8:
  LOAD_CONST 'ALTER '
  LOAD_FAST old_column_name
  BINARY_OP +
  LOAD_CONST ' '
  BINARY_OP +
  LOAD_FAST op
  BINARY_OP +
  LOAD_CONST ' NOT NULL'
  BINARY_OP +
  STORE_FAST query
  LOAD_FAST sql
  LOAD_ATTR NULL|self + append
  LOAD_CONST 'ALTER TABLE '
  LOAD_FAST diff
  LOAD_ATTR name
  BINARY_OP +
  LOAD_CONST ' '
  BINARY_OP +
  LOAD_FAST query
  BINARY_OP +
  CALL 1
  POP_TOP
L9:
  LOAD_FAST column_diff
  LOAD_ATTR NULL|self + has_changed
  LOAD_CONST 'autoincrement'
  CALL 1
  POP_JUMP_IF_FALSE L11
  LOAD_FAST column
  LOAD_ATTR NULL|self + get_autoincrement
  CALL 0
  POP_JUMP_IF_FALSE L10
  LOAD_FAST self
  LOAD_ATTR NULL|self + get_identity_sequence_name
  LOAD_FAST diff
  LOAD_ATTR name
  LOAD_FAST old_column_name
  CALL 2
  STORE_FAST seq_name
  LOAD_FAST sql
  LOAD_ATTR NULL|self + append
  LOAD_CONST 'CREATE SEQUENCE '
  LOAD_FAST seq_name
  BINARY_OP +
  CALL 1
  POP_TOP
  LOAD_FAST sql
  LOAD_ATTR NULL|self + append
  LOAD_CONST "SELECT setval('"
  LOAD_FAST seq_name
  BINARY_OP +
  LOAD_CONST "', (SELECT MAX("
  BINARY_OP +
  LOAD_FAST old_column_name
  BINARY_OP +
  LOAD_CONST ') FROM '
  BINARY_OP +
  LOAD_FAST diff
  LOAD_ATTR name
  BINARY_OP +
  LOAD_CONST '))'
  BINARY_OP +
  CALL 1
  POP_TOP
  LOAD_CONST 'ALTER '
  LOAD_FAST old_column_name
  BINARY_OP +
  LOAD_CONST " SET DEFAULT nextval('"
  BINARY_OP +
  LOAD_FAST seq_name
  BINARY_OP +
  LOAD_CONST "')"
  BINARY_OP +
  STORE_FAST query
  LOAD_FAST sql
  LOAD_ATTR NULL|self + append
  LOAD_CONST 'ALTER TABLE '
  LOAD_FAST diff
  LOAD_ATTR name
  BINARY_OP +
  LOAD_CONST ' '
  BINARY_OP +
  LOAD_FAST query
  BINARY_OP +
  CALL 1
  POP_TOP
  JUMP_FORWARD L11
L10:
  LOAD_CONST 'ALTER '
  LOAD_FAST old_column_name
  BINARY_OP +
  LOAD_CONST ' DROP DEFAULT'
  BINARY_OP +
  STORE_FAST query
  LOAD_FAST sql
  LOAD_ATTR NULL|self + append
  LOAD_CONST 'ALTER TABLE '
  LOAD_FAST diff
  LOAD_ATTR name
  BINARY_OP +
  LOAD_CONST ' '
  BINARY_OP +
  LOAD_FAST query
  BINARY_OP +
  CALL 1
  POP_TOP
L11:
  LOAD_FAST column_diff
  LOAD_ATTR NULL|self + has_changed
  LOAD_CONST 'length'
  CALL 1
  POP_JUMP_IF_TRUE L12
  EXTENDED_ARG 2
  JUMP_BACKWARD L1
L12:
  LOAD_CONST 'ALTER '
  LOAD_FAST old_column_name
  BINARY_OP +
  LOAD_CONST ' TYPE '
  BINARY_OP +
  LOAD_FAST self
  LOAD_ATTR NULL|self + get_sql_type_declaration
  LOAD_FAST column
  LOAD_ATTR NULL|self + to_dict
  CALL 0
  CALL 1
  BINARY_OP +
  STORE_FAST query
  LOAD_FAST sql
  LOAD_ATTR NULL|self + append
  LOAD_CONST 'ALTER TABLE '
  LOAD_FAST diff
  LOAD_ATTR name
  BINARY_OP +
  LOAD_CONST ' '
  BINARY_OP +
  LOAD_FAST query
  BINARY_OP +
  CALL 1
  POP_TOP
  EXTENDED_ARG 2
  JUMP_BACKWARD L1
L13:
  END_FOR
  LOAD_FAST diff
  LOAD_ATTR renamed_columns
  LOAD_ATTR NULL|self + items
  CALL 0
  GET_ITER
L14:
  FOR_ITER L15
  UNPACK_SEQUENCE 2
  STORE_FAST old_column_name
  STORE_FAST column
  LOAD_FAST sql
  LOAD_ATTR NULL|self + append
  LOAD_CONST 'ALTER TABLE '
  LOAD_FAST diff
  LOAD_ATTR name
  BINARY_OP +
  LOAD_CONST ' RENAME COLUMN '
  BINARY_OP +
  LOAD_FAST old_column_name
  BINARY_OP +
  LOAD_CONST ' TO '
  BINARY_OP +
  LOAD_FAST column
  LOAD_ATTR NULL|self + get_name
  CALL 0
  BINARY_OP +
  CALL 1
  POP_TOP
  JUMP_BACKWARD L14
L15:
  END_FOR
  LOAD_FAST sql
  RETURN_VALUE
END

def get_alter_table_sql(self, diff):
    """pass"""
    sql = []
    for column_diff in diff.changed_columns.values():
        if self.is_unchanged_binary_column(column_diff):
            continue
        old_column_name = column_diff.old_column_name
        column = column_diff.column
        if any([column_diff.has_changed('type'), column_diff.has_changed('precision'), column_diff.has_changed('scale'), column_diff.has_changed('fixed')]):
            query = 'ALTER ' + old_column_name + ' TYPE ' + self.get_sql_type_declaration(column.to_dict())
            sql.append('ALTER TABLE ' + diff.name + ' ' + query)
        if column_diff.has_changed('default') or column_diff.has_changed('type'):
            if column.get_default() is None:
                default_clause = ' DROP DEFAULT'
            else:
                default_clause = ' SET' + self.get_default_value_declaration_sql(column.to_dict())
            query = 'ALTER ' + old_column_name + default_clause
            sql.append('ALTER TABLE ' + diff.name + ' ' + query)
        if column_diff.has_changed('notnull'):
            op = 'DROP'
            if column.get_notnull():
                op = 'SET'
            query = 'ALTER ' + old_column_name + ' ' + op + ' NOT NULL'
            sql.append('ALTER TABLE ' + diff.name + ' ' + query)
        if column_diff.has_changed('autoincrement'):
            if column.get_autoincrement():
                seq_name = self.get_identity_sequence_name(diff.name, old_column_name)
                sql.append('CREATE SEQUENCE ' + seq_name)
                sql.append("SELECT setval('" + seq_name + "', (SELECT MAX(" + old_column_name + ') FROM ' + diff.name + '))')
                query = 'ALTER ' + old_column_name + " SET DEFAULT nextval('" + seq_name + "')"
                sql.append('ALTER TABLE ' + diff.name + ' ' + query)
            else:
                query = 'ALTER ' + old_column_name + ' DROP DEFAULT'
                sql.append('ALTER TABLE ' + diff.name + ' ' + query)
        if column_diff.has_changed('length'):
            query = 'ALTER ' + old_column_name + ' TYPE ' + self.get_sql_type_declaration(column.to_dict())
            sql.append('ALTER TABLE ' + diff.name + ' ' + query)
    for old_column_name, column in diff.renamed_columns.items():
        sql.append('ALTER TABLE ' + diff.name + ' RENAME COLUMN ' + old_column_name + ' TO ' + column.get_name())
    return sql


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code _date_based_where>
  MAKE_FUNCTION 0
  STORE_NAME _date_based_where
  RETURN_CONST None
END
CODE _date_based_where(self, type, query, where)
  DOC 'pass'
  RESUME 0
  LOAD_GLOBAL NULL + str
  LOAD_FAST where
  LOAD_CONST 'value'
  BINARY_SUBSCR
  CALL 1
  LOAD_ATTR NULL|self + zfill
  LOAD_CONST 2
  CALL 1
  STORE_FAST value
  LOAD_FAST self
  LOAD_ATTR NULL|self + parameter
  LOAD_FAST value
  CALL 1
  STORE_FAST value
  LOAD_CONST "strftime('"
  LOAD_FAST type
  FORMAT_VALUE str
  LOAD_CONST "', "
  LOAD_FAST self
  LOAD_ATTR NULL|self + wrap
  LOAD_FAST where
  LOAD_CONST 'column'
  BINARY_SUBSCR
  CALL 1
  FORMAT_VALUE str
  LOAD_CONST ') '
  LOAD_FAST where
  LOAD_CONST 'operator'
  BINARY_SUBSCR
  FORMAT_VALUE str
  LOAD_CONST ' '
  LOAD_FAST value
  FORMAT_VALUE str
  BUILD_STRING 8
  RETURN_VALUE
END

def _date_based_where(self, type, query, where):
    """pass"""
    value = str(where['value']).zfill(2)
    value = self.parameter(value)
    return "strftime('%s', %s) %s %s" % (type, self.wrap(where['column']), where['operator'], value)


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code compile_select>
  MAKE_FUNCTION 0
  STORE_NAME compile_select
  RETURN_CONST None
END
CODE compile_select(self, query)
  DOC 'pass'
  RESUME 0
  LOAD_GLOBAL super
  LOAD_GLOBAL MySqlQueryGrammar
  LOAD_FAST self
  LOAD_SUPER_ATTR NULL|self + compile_select
  LOAD_FAST query
  CALL 1
  STORE_FAST sql
  LOAD_FAST query
  LOAD_ATTR unions
  POP_JUMP_IF_FALSE L1
  LOAD_CONST '('
  LOAD_FAST sql
  FORMAT_VALUE str
  LOAD_CONST ') '
  LOAD_FAST self
  LOAD_ATTR NULL|self + _compile_unions
  LOAD_FAST query
  CALL 1
  FORMAT_VALUE str
  BUILD_STRING 4
  STORE_FAST sql
L1:
  LOAD_FAST sql
  RETURN_VALUE
END

def compile_select(self, query):
    """pass"""
    sql = super(MySqlQueryGrammar, self).compile_select(query)
    if query.unions:
        sql = '(%s) %s' % (sql, self._compile_unions(query))
    return sql


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code _compile_lock>
  MAKE_FUNCTION 0
  STORE_NAME _compile_lock
  RETURN_CONST None
END
CODE _compile_lock(self, query, value)
  DOC 'pass'
  RESUME 0
  LOAD_GLOBAL NULL + isinstance
  LOAD_FAST value
  LOAD_GLOBAL basestring
  CALL 2
  POP_JUMP_IF_FALSE L1
  LOAD_FAST value
  RETURN_VALUE
L1:
  LOAD_FAST value
  LOAD_CONST True
  IS_OP 0
  POP_JUMP_IF_FALSE L2
  RETURN_CONST 'FOR UPDATE'
L2:
  LOAD_FAST value
  LOAD_CONST False
  IS_OP 0
  POP_JUMP_IF_FALSE L3
  RETURN_CONST 'LOCK IN SHARE MODE'
L3:
  RETURN_CONST None
END

def _compile_lock(self, query, value):
    """pass"""
    if isinstance(value, basestring):
        return value
    if value is True:
        return 'FOR UPDATE'
    elif value is False:
        return 'LOCK IN SHARE MODE'