def refresh(self, access_token=None, **kwargs):
if not self.token_lock.locked():<EOL><INDENT>with self.token_lock:<EOL><INDENT>if access_token == self.access_token or access_token is None:<EOL><INDENT>if self.developer_token is not None:<EOL><INDENT>r = self._httpclient.request(<EOL>method='<STR_LIT:POST>',<EOL>url=self.developer_token_url,<EOL>path='<STR_LIT>',<EOL>headers={<EOL>'<STR_LIT>': '<STR_LIT>'.format(<EOL>self.developer_token<EOL>)<EOL>},<EOL>timeout=<NUM_LIT:30>,<EOL>raise_for_status=True<EOL>)<EOL><DEDENT>elif all(<EOL>[<EOL>self.client_id,<EOL>self.client_secret,<EOL>self.refresh_token<EOL>]<EOL>):<EOL><INDENT>data = {<EOL>'<STR_LIT>': self.client_id,<EOL>'<STR_LIT>': self.client_secret,<EOL>'<STR_LIT>': self.refresh_token,<EOL>'<STR_LIT>': '<STR_LIT>'<EOL>}<EOL>r = self._httpclient.request(<EOL>method='<STR_LIT:POST>',<EOL>url=self.token_url,<EOL>json=data,<EOL>path='<STR_LIT>',<EOL>**kwargs<EOL>)<EOL><DEDENT>else:<EOL><INDENT>raise PartialCredentialsError(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>if r:<EOL><INDENT>if not r.ok:<EOL><INDENT>raise PanCloudError(<EOL>'<STR_LIT>' % (<EOL>r.status_code, r.reason, r.text)<EOL>)<EOL><DEDENT>try:<EOL><INDENT>r_json = r.json()<EOL><DEDENT>except ValueError as e:<EOL><INDENT>raise PanCloudError("<STR_LIT>" % e)<EOL><DEDENT>else:<EOL><INDENT>if r.json().get(<EOL>'<STR_LIT>'<EOL>) or r.json().get(<EOL>'<STR_LIT:error>'<EOL>):<EOL><INDENT>raise PanCloudError(r.text)<EOL><DEDENT>self.access_token = r_json.get(<EOL>'<STR_LIT>', None<EOL>)<EOL>self.jwt_exp = self._decode_exp(<EOL>self.access_token_)<EOL>if r_json.get('<STR_LIT>', None):<EOL><INDENT>self.refresh_token =r_json.get('<STR_LIT>')<EOL><DEDENT>self.write_credentials()<EOL><DEDENT>return self.access_token_<EOL><DEDENT><DEDENT><DEDENT><DEDENT>
Refresh access and refresh tokens.

        Args:
            access_token (str): Access token to refresh. Defaults to ``None``.

        Returns:
            str: Refreshed access token.