Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
Fadecandy
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
scanlime
Fadecandy
Commits
54629872
Commit
54629872
authored
11 years ago
by
Serene H
Browse files
Options
Downloads
Patches
Plain Diff
Make http manifest.py work with python3+ as well as 2.7
parent
f8410635
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
server/http/manifest.py
+13
-14
13 additions, 14 deletions
server/http/manifest.py
with
13 additions
and
14 deletions
server/http/manifest.py
+
13
−
14
View file @
54629872
# 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
'
),
...
...
@@ -35,19 +33,21 @@ sys.stdout.write("""/*
NetServer::HTTPDocument NetServer::httpDocumentList[] = {
"""
)
def
quote
(
str
):
def
quote
(
buf
):
# Encode a byte buffer as a C++ string, and octal-escape any funny characters
if
str
is
None
:
if
buf
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
)
allowedBytes
=
[
c
for
c
in
range
(
ord
(
'
'
),
ord
(
'
~
'
)
+
1
)
if
chr
(
c
)
not
in
'"
\\
?
'
]
for
c
in
buf
:
byte
=
c
if
isinstance
(
c
,
str
):
byte
=
ord
(
c
)
if
byte
in
allowedBytes
:
output
.
append
(
chr
(
byte
))
else
:
byte
=
ord
(
c
)
output
.
append
(
'
\\
%d%d%d
'
%
(
byte
>>
6
,
(
byte
>>
3
)
&
7
,
byte
&
7
))
output
.
append
(
'"'
)
...
...
@@ -58,12 +58,11 @@ for path, filename, contentType in manifest:
filename
=
'
.
'
+
path
if
contentType
.
startswith
(
'
text/
'
):
mode
=
'
r
'
raw
=
open
(
filename
,
'
r
'
).
read
().
encode
(
'
UTF-8
'
)
else
:
mode
=
'
rb
'
data
=
zlib
.
compress
(
open
(
filename
,
mode
).
read
())
raw
=
open
(
filename
,
'
rb
'
).
read
()
data
=
zlib
.
compress
(
raw
)
sys
.
stdout
.
write
(
"
{ %s, %s, %s, %d },
\n
"
%
(
quote
(
path
),
quote
(
data
),
quote
(
contentType
),
len
(
data
)))
sys
.
stdout
.
write
(
"
};
\n
"
)
\ No newline at end of file
sys
.
stdout
.
write
(
"
};
\n
"
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment