def encrypt_variable(variable, build_repo, *, tld='<STR_LIT>', public_key=None,<EOL>travis_token=None, **login_kwargs):
if not isinstance(variable, bytes):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if not b"<STR_LIT:=>" in variable:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if not public_key:<EOL><INDENT>_headers = {<EOL>'<STR_LIT:Content-Type>': '<STR_LIT:application/json>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>}<EOL>headersv2 = {**_headers, **Travis_APIv2}<EOL>headersv3 = {**_headers, **Travis_APIv3}<EOL>if travis_token:<EOL><INDENT>headersv3['<STR_LIT>'] = '<STR_LIT>'.format(travis_token)<EOL>res = requests.get('<STR_LIT>'.format(build_repo=urllib.parse.quote(build_repo,<EOL>safe='<STR_LIT>')), headers=headersv3)<EOL>if res.json().get('<STR_LIT:file>') == '<STR_LIT>':<EOL><INDENT>raise RuntimeError("<STR_LIT>" % build_repo)<EOL><DEDENT>public_key = res.json()['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>res = requests.get('<STR_LIT>'.format(build_repo=build_repo,<EOL>tld=tld),<EOL>headers=headersv2)<EOL>public_key = res.json()['<STR_LIT:key>']<EOL><DEDENT>if res.status_code == requests.codes.not_found:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL>res.raise_for_status()<EOL><DEDENT><DEDENT>public_key = public_key.replace("<STR_LIT>", "<STR_LIT>").encode('<STR_LIT:utf-8>')<EOL>key = serialization.load_pem_public_key(public_key, backend=default_backend())<EOL>pad = padding.PKCS1v15()<EOL>return base64.b64encode(key.encrypt(variable, pad))<EOL>
Encrypt an environment variable for ``build_repo`` for Travis

``variable`` should be a bytes object, of the form ``b'ENV=value'``.

``build_repo`` is the repo that ``doctr deploy`` will be run from. It
should be like 'drdoctr/doctr'.

``tld`` should be ``'.org'`` for travis-ci.org and ``'.com'`` for
travis-ci.com.

``public_key`` should be a pem format public key, obtained from Travis if
not provided.

If the repo is private, travis_token should be as returned by
``get_temporary_token(**login_kwargs)``. A token being present
automatically implies ``tld='.com'``.