nodes: 0, module; 1, function_definition; 2, function_name:get_url_filemeta; 3, parameters; 4, block; 5, identifier:url; 6, expression_statement; 7, expression_statement; 8, if_statement; 9, if_statement; 10, expression_statement; 11, try_statement; 12, return_statement; 13, comment:""" Request HTML for the page at the URL indicated and return the url, filename, and remote size
  
      TODO: just add remote_size and basename and filename attributes to the urlparse object
            instead of returning a dict
  
      >>> sorted(get_url_filemeta('mozilla.com').items())
      [('filename', ''),
       ('hostname', 'mozilla.com'),
       ('path', ''),
       ('remote_size', -1),
       ('url', 'http://mozilla.com'),
       ('username', None)]
      >>> sorted(get_url_filemeta('https://duckduckgo.com/about?q=nlp').items())
      [('filename', 'about'),
       ('hostname', 'duckduckgo.com'),
       ('path', '/about'),
       ('remote_size', -1),
       ('url', 'https://duckduckgo.com/about?q=nlp'),
       ('username', None)]
      >>> 1000 <= int(get_url_filemeta('en.wikipedia.org')['remote_size']) <= 200000
      True
      """; 14, assignment; 15, comparison_operator:parsed_url is None; 16, block; 17, call; 18, block; 19, assignment; 20, block; 21, except_clause; 22, except_clause; 23, None; 24, identifier:parsed_url; 25, call; 26, identifier:parsed_url; 27, None; 28, return_statement; 29, attribute; 30, argument_list; 31, return_statement; 32, identifier:url; 33, call; 34, expression_statement; 35, expression_statement; 36, return_statement; 37, identifier:ConnectionError; 38, block; 39, tuple; 40, block; 41, identifier:try_parse_url; 42, argument_list; 43, None; 44, attribute; 45, identifier:startswith; 46, string; 47, call; 48, attribute; 49, argument_list; 50, assignment; 51, assignment; 52, call; 53, return_statement; 54, identifier:InvalidURL; 55, identifier:InvalidSchema; 56, identifier:InvalidHeader; 57, identifier:MissingSchema; 58, return_statement; 59, identifier:url; 60, identifier:parsed_url; 61, identifier:scheme; 62, string_content:ftp; 63, identifier:get_ftp_filemeta; 64, argument_list; 65, identifier:parsed_url; 66, identifier:geturl; 67, identifier:r; 68, call; 69, identifier:remote_size; 70, call; 71, identifier:dict; 72, argument_list; 73, None; 74, None; 75, identifier:parsed_url; 76, attribute; 77, argument_list; 78, attribute; 79, argument_list; 80, keyword_argument; 81, keyword_argument; 82, keyword_argument; 83, keyword_argument; 84, keyword_argument; 85, keyword_argument; 86, identifier:requests; 87, identifier:get; 88, identifier:url; 89, keyword_argument; 90, keyword_argument; 91, keyword_argument; 92, attribute; 93, identifier:get; 94, string; 95, unary_operator; 96, identifier:url; 97, identifier:url; 98, identifier:hostname; 99, attribute; 100, identifier:path; 101, attribute; 102, identifier:username; 103, attribute; 104, identifier:remote_size; 105, identifier:remote_size; 106, identifier:filename; 107, call; 108, identifier:stream; 109, True; 110, identifier:allow_redirects; 111, True; 112, identifier:timeout; 113, integer:5; 114, identifier:r; 115, identifier:headers; 116, string_content:Content-Length; 117, integer:1; 118, identifier:parsed_url; 119, identifier:hostname; 120, identifier:parsed_url; 121, identifier:path; 122, identifier:parsed_url; 123, identifier:username; 124, attribute; 125, argument_list; 126, attribute; 127, identifier:basename; 128, attribute; 129, identifier:os; 130, identifier:path; 131, identifier:parsed_url; 132, identifier:path
code: def get_url_filemeta(url):
      """ Request HTML for the page at the URL indicated and return the url, filename, and remote size
  
      TODO: just add remote_size and basename and filename attributes to the urlparse object
            instead of returning a dict
  
      >>> sorted(get_url_filemeta('mozilla.com').items())
      [('filename', ''),
       ('hostname', 'mozilla.com'),
       ('path', ''),
       ('remote_size', -1),
       ('url', 'http://mozilla.com'),
       ('username', None)]
      >>> sorted(get_url_filemeta('https://duckduckgo.com/about?q=nlp').items())
      [('filename', 'about'),
       ('hostname', 'duckduckgo.com'),
       ('path', '/about'),
       ('remote_size', -1),
       ('url', 'https://duckduckgo.com/about?q=nlp'),
       ('username', None)]
      >>> 1000 <= int(get_url_filemeta('en.wikipedia.org')['remote_size']) <= 200000
      True
      """
      parsed_url = try_parse_url(url)
  
      if parsed_url is None:
          return None
      if parsed_url.scheme.startswith('ftp'):
          return get_ftp_filemeta(parsed_url)
  
      url = parsed_url.geturl()
      try:
          r = requests.get(url, stream=True, allow_redirects=True, timeout=5)
          remote_size = r.headers.get('Content-Length', -1)
          return dict(url=url, hostname=parsed_url.hostname, path=parsed_url.path,
                      username=parsed_url.username, remote_size=remote_size,
                      filename=os.path.basename(parsed_url.path))
      except ConnectionError:
          return None
      except (InvalidURL, InvalidSchema, InvalidHeader, MissingSchema):
          return None
      return None