def list_directory()

in WebApp.py [0:0]


    def list_directory(self, path):
        """Helper to produce a directory listing (absent index.html).
        Return value is either a file object, or None (indicating an
        error).  In either case, the headers are sent, making the
        interface the same as for send_head().
        """
        try:
            list = os.listdir(path)
        except os.error:
            self.send_error(404, "No permission to list directory")
            return None
        list.sort(key=lambda a: a.lower())

        
        f = StringIO()
        displaypath = cgi.escape(urllib.unquote(self.path))
        f.write('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">')
        f.write("<html>\n<title>KMS Workshop - Sample WebApp S3 Uploader</title>\n")   
        f.write("<style> .center { display: block; margin-left: auto; margin-right: auto;}</style>") 
        f.write("<body>\n<img src=\"https://github.com/DanGOTO100/Draft-AWS-KMS-Workshop/blob/master/res/IconWebApp.png?raw=true\" alt=\"KMSicon\" class=\"center\">\n<h2><center>KMS Workshop - Sample WebApp S3 Uploader</center></h2>\n")
        f.write("<hr>\n")
        f.write("<h2>File Upload here:</h2>\n")
        f.write("<form ENCTYPE=\"multipart/form-data\" method=\"post\">")
        f.write("<input name=\"file\" type=\"file\"/>")
        f.write("<input type=\"submit\" value=\"upload\"/></form>\n")
        f.write("<hr><h2>FILES in S3 - Bucket: kms-workshop</h2>\n<ul>\n")
        for key in my_bucket.objects.all():
            f.write('<li><a href="%s">%s</a>\n'
                    % ('S3/'+key.key, 'S3//'+key.key))
        f.write("</ul><hr><h2>FILES in Local Server</h2>\n<ul>\n") 
        for name in list:
            fullname = os.path.join(path, name)
            displayname = linkname = name
            # Append / for directories or @ for symbolic links
            if os.path.isdir(fullname):
                displayname = name + "/"
                linkname = name + "/"
            if os.path.islink(fullname):
                displayname = name + "@"
                # Note: a link to a directory displays with @ and links with /
            f.write('<li><a href="%s">%s</a>\n'
                    % (urllib.quote(linkname), cgi.escape(displayname)))
        f.write("</ul>\n<hr>\n</body>\n</html>\n")
        length = f.tell()
        f.seek(0)
        self.send_response(200)
        self.send_header("Content-type", "text/html")
        self.send_header("Content-Length", str(length))
        self.end_headers()
        return f