def download(url, file=None):
import urllib.request<EOL>import shutil<EOL>if isinstance(file, str):<EOL><INDENT>file = open(file, '<STR_LIT:wb>')<EOL><DEDENT>try:<EOL><INDENT>with urllib.request.urlopen(url) as response:<EOL><INDENT>if file:<EOL><INDENT>shutil.copyfileobj(response, file)<EOL><DEDENT>else:<EOL><INDENT>return response.read()<EOL><DEDENT><DEDENT><DEDENT>finally:<EOL><INDENT>if file:<EOL><INDENT>file.close()<EOL><DEDENT><DEDENT>
Pass file as a filename, open file object, or None to return the request bytes

Args:
    url (str): URL of file to download
    file (Union[str, io, None]): One of the following:
         - Filename of output file
         - File opened in binary write mode
         - None: Return raw bytes instead

Returns:
    Union[bytes, None]: Bytes of file if file is None