nodes: 0, module; 1, function_definition; 2, function_name:ls; 3, parameters; 4, block; 5, default_parameter; 6, default_parameter; 7, default_parameter; 8, expression_statement; 9, function_definition; 10, if_statement; 11, identifier:root; 12, string:"."; 13, identifier:abspaths; 14, False; 15, identifier:recursive; 16, False; 17, comment:"""
      Return a list of files in directory.
  
      Directory listings are sorted alphabetically. If the named
      directory is a file, return it's path.
  
      Examples:
  
          >>> fs.ls("foo")
          ["a", "b", "c"]
  
          >>> fs.ls("foo/a")
          ["foo/a"]
  
          >>> fs.ls("foo", abspaths=True)
          ["/home/test/foo/a", "/home/test/foo/b", "/home/test/foo/c"]
  
          >>> fs.ls("foo", recursive=True)
          ["a", "b", "b/d", "b/d/e", "c"]
  
      Arguments:
  
          root (str): Path to directory. Can be relative or absolute.
          abspaths (bool, optional): Return absolute paths if true.
          recursive (bool, optional): Recursively list subdirectories if
            true.
  
      Returns:
  
          list of str: A list of paths.
  
      Raises:
  
          OSError: If root directory does not exist.
      """; 18, function_name:_expand_subdirs; 19, parameters; 20, block; 21, call; 22, comment:# If argument is a file, return path.; 23, block; 24, elif_clause; 25, elif_clause; 26, else_clause; 27, identifier:file; 28, if_statement; 29, identifier:isfile; 30, argument_list; 31, return_statement; 32, identifier:abspaths; 33, comment:# Get relative names.; 34, block; 35, identifier:recursive; 36, comment:# Recursively expand subdirectories.; 37, block; 38, comment:# List directory contents.; 39, block; 40, call; 41, block; 42, else_clause; 43, identifier:root; 44, conditional_expression:[abspath(root)] if abspaths else [basename(root)]; 45, expression_statement; 46, comment:# Prepend the absolute path to each relative name.; 47, expression_statement; 48, return_statement; 49, expression_statement; 50, return_statement; 51, return_statement; 52, identifier:isdir; 53, argument_list; 54, return_statement; 55, block; 56, list; 57, identifier:abspaths; 58, list; 59, assignment; 60, assignment; 61, list_comprehension; 62, assignment; 63, call; 64, call; 65, call; 66, binary_operator:[file] + [path(file, x) for x in
                               ls(path(root, file), recursive=True)]; 67, return_statement; 68, call; 69, call; 70, identifier:relpaths; 71, call; 72, identifier:base; 73, call; 74, call; 75, for_in_clause; 76, identifier:paths; 77, call; 78, attribute; 79, argument_list; 80, identifier:list; 81, argument_list; 82, identifier:path; 83, argument_list; 84, list; 85, list_comprehension; 86, list; 87, identifier:abspath; 88, argument_list; 89, identifier:basename; 90, argument_list; 91, identifier:ls; 92, argument_list; 93, identifier:abspath; 94, argument_list; 95, identifier:path; 96, argument_list; 97, identifier:relpath; 98, identifier:relpaths; 99, identifier:ls; 100, argument_list; 101, identifier:labtypes; 102, identifier:flatten; 103, list_comprehension; 104, call; 105, identifier:root; 106, identifier:file; 107, identifier:file; 108, call; 109, for_in_clause; 110, identifier:file; 111, identifier:root; 112, identifier:root; 113, identifier:root; 114, keyword_argument; 115, keyword_argument; 116, identifier:root; 117, identifier:base; 118, identifier:relpath; 119, identifier:root; 120, keyword_argument; 121, keyword_argument; 122, call; 123, for_in_clause; 124, identifier:sorted; 125, argument_list; 126, identifier:path; 127, argument_list; 128, identifier:x; 129, call; 130, identifier:recursive; 131, identifier:recursive; 132, identifier:abspaths; 133, False; 134, identifier:abspaths; 135, identifier:abspaths; 136, identifier:recursive; 137, False; 138, identifier:_expand_subdirs; 139, argument_list; 140, identifier:file; 141, identifier:paths; 142, call; 143, identifier:file; 144, identifier:x; 145, identifier:ls; 146, argument_list; 147, identifier:file; 148, attribute; 149, argument_list; 150, call; 151, keyword_argument; 152, identifier:os; 153, identifier:listdir; 154, identifier:root; 155, identifier:path; 156, argument_list; 157, identifier:recursive; 158, True; 159, identifier:root; 160, identifier:file
code: def ls(root=".", abspaths=False, recursive=False):
      """
      Return a list of files in directory.
  
      Directory listings are sorted alphabetically. If the named
      directory is a file, return it's path.
  
      Examples:
  
          >>> fs.ls("foo")
          ["a", "b", "c"]
  
          >>> fs.ls("foo/a")
          ["foo/a"]
  
          >>> fs.ls("foo", abspaths=True)
          ["/home/test/foo/a", "/home/test/foo/b", "/home/test/foo/c"]
  
          >>> fs.ls("foo", recursive=True)
          ["a", "b", "b/d", "b/d/e", "c"]
  
      Arguments:
  
          root (str): Path to directory. Can be relative or absolute.
          abspaths (bool, optional): Return absolute paths if true.
          recursive (bool, optional): Recursively list subdirectories if
            true.
  
      Returns:
  
          list of str: A list of paths.
  
      Raises:
  
          OSError: If root directory does not exist.
      """
      def _expand_subdirs(file):
          if isdir(path(root, file)):
              return [file] + [path(file, x) for x in
                               ls(path(root, file), recursive=True)]
          else:
              return [file]
  
      if isfile(root):
          # If argument is a file, return path.
          return [abspath(root)] if abspaths else [basename(root)]
      elif abspaths:
          # Get relative names.
          relpaths = ls(root, recursive=recursive, abspaths=False)
          # Prepend the absolute path to each relative name.
          base = abspath(root)
          return [path(base, relpath) for relpath in relpaths]
      elif recursive:
          # Recursively expand subdirectories.
          paths = ls(root, abspaths=abspaths, recursive=False)
          return labtypes.flatten([_expand_subdirs(file) for file in paths])
      else:
          # List directory contents.
          return list(sorted(os.listdir(root)))