# Manifest of files to include in the simple HTTP server.
# Run this script to generate the httpdocs.cpp source file.

# For Python 2.7. Not yet compatible with Python 3.

manifest = [
    ('/', 'index.html', 'text/html'),

    # Images
    ('/media/favicon.png', None, 'image/png'),
    ('/favicon.ico', 'media/favicon.ico', 'image/x-icon'),

    # Javascript and CSS
    ('/js/home.js', None, 'application/javascript'),
    ('/css/narrow.css', None, 'text/css'),

    # Redistributed libraries
    ('/dist/css/bootstrap.min.css', None, 'text/css'),
    ('/dist/js/bootstrap.min.js', None, 'application/javascript'),
    ('/dist/js/jquery-1.10.2.min.js', None, 'application/javascript'),

    # 404 error document must be last.
    (None, '404.html', 'text/html'),
]

import json, sys, os, zlib

sys.stdout.write("""/*
 * HTTP Document data.
 * Automatically generated by manifest.py
 */

#include "netserver.h"

NetServer::HTTPDocument NetServer::httpDocumentList[] = {
""")

def quote(str):
    # Encode a byte buffer as a C++ string, and octal-escape any funny characters

    if str is None:
        return 'NULL'
    output = ['"']

    allowedChars = [chr(c) for c in range(ord(' '), ord('~') + 1) if chr(c) not in '"\\?']
    for c in str:
        if c in allowedChars:
            output.append(c)
        else:
            byte = ord(c)
            output.append('\\%d%d%d' % (byte >> 6, (byte >> 3) & 7, byte & 7))

    output.append('"')
    return ''.join(output)

for path, filename, contentType in manifest:
    if filename is None:
        filename = '.' + path

    if contentType.startswith('text/'):
        mode = 'r'
    else:
        mode = 'rb'

    data = zlib.compress(open(filename, mode).read())
    sys.stdout.write("{ %s, %s, %s, %d },\n" %
        (quote(path), quote(data), quote(contentType), len(data)))

sys.stdout.write("};\n")
@@ -116,61 +116,8 @@
 e.%0A%0A
-# For Python 2.7. Not yet compatible with Python 3.%0A%0A
 mani
@@ -928,19 +928,19 @@
 f quote(
-str
+buf
 ):%0A    #
@@ -1024,19 +1024,19 @@
 %0A    if 
-str
+buf
  is None
@@ -1094,23 +1094,18 @@
 owed
-Char
+Byte
 s = %5Bc
-hr(c)
  for
@@ -1177,20 +1177,68 @@
 for c in
+ buf:%0A        byte = c%0A        if isinstance(c,
  str
+)
 :%0A      
@@ -1239,20 +1239,47 @@
         
-if c
+  byte = ord(c)%0A        if byte
  in allo
@@ -1285,12 +1285,12 @@
 owed
-Char
+Byte
 s:%0A 
@@ -1315,16 +1315,24 @@
 append(c
+hr(byte)
 )%0A      
@@ -1343,34 +1343,8 @@
 se:%0A
-            byte = ord(c)%0A
     
@@ -1623,102 +1623,137 @@
     
-mode = 'r'%0A    else:%0A        mode = 'rb'%0A%0A    data = zlib.compress(open(filename, mode).read()
+raw = open(filename, 'r').read().encode('UTF-8')%0A    else:%0A        raw = open(filename, 'rb').read()%0A    data = zlib.compress(raw
 )%0A  
@@ -1889,8 +1889,9 @@
 (%22%7D;%5Cn%22)
+%0A

Make http manifest.py work with python3+ as well as 2.7