Skip to content

Commit

Permalink
Removed the external process requirement after disabling Python GIL.
Browse files Browse the repository at this point in the history
  • Loading branch information
msporny committed Dec 15, 2010
1 parent 26bd1be commit db7bf90
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 40 deletions.
23 changes: 5 additions & 18 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ <h1>Live Loop</h1>
<div class="container vspacing">
<div class="row">
<div class="twelvecol">
<h1>For Dave Lehn.
<span class="subhead">With love and hugs.</span></h1>
<h1>The RDFa markup playground.
<span class="subhead">Linked Data, love and hugs.</span></h1>
</div>
</div>
<div class="row">
<div class="twelvecol last">
<p class="largeprint">
RDFa Live Loop lets you dynamically edit RDFa source code and instantly see
what your markup produces.</p>
RDFa Live Loop lets you play with HTML+RDFa markup and instantly see
the data that your markup produces.</p>
</div>
</div>
<pre id="code-prologue">&lt;html&gt;</pre>
Expand All @@ -64,6 +64,7 @@ <h1>For Dave Lehn.
<a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/"><img alt="Creative Commons License" src="http://i.creativecommons.org/l/by-sa/3.0/88x31.png" /></a>
</div>
<div class="ninecol last">
<span>* Support for RDFa 1.1 coming soon...</span>
<p>&copy; 2010 <a href="http://digitalbazaar.com/">Digital Bazaar</a>, Inc.
Website CSS created by <a href="http://cssgrid.net/">@andytlr</a>
and is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/au/">
Expand All @@ -76,20 +77,6 @@ <h1>For Dave Lehn.
</div>
</div>

<script type="text/javascript">

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-1539674-7']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
})();

</script>

</body>
</html>

4 changes: 2 additions & 2 deletions live-loop.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

liveloop.generateCodePrologue = function()
{
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML+RDFa 1.0//EN\" \"http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:dc=\"http://purl.org/dc/terms/\">\n <head>\n <title>Test Snippet</title>\n </head>\n <body>";
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML+RDFa 1.0//EN\" \"http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:dc=\"http://purl.org/dc/terms/\">\n <head>\n <title>Test Snippet</title>\n </head>\n <body>\n";
}

liveloop.setupCodePrologue = function()
Expand All @@ -21,7 +21,7 @@

liveloop.generateCodeEpilogue = function()
{
return " </body>\n</html>";
return "\n </body>\n</html>";
}

liveloop.setupCodeEpilogue = function()
Expand Down
30 changes: 10 additions & 20 deletions live-loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# @param object_type the type for the object in the triple.
# @param datatype the datatype for the object in the triple.
# @param language the language for the object in the triple.
def writeTriple2( \
def writeTriple( \
request, subject, predicate, obj, object_type, datatype, language):
request.write("&lt;%s&gt; &lt;%s&gt; " % (subject, predicate))
if(object_type == rdfa.RDF_TYPE_IRI):
Expand All @@ -46,11 +46,11 @@ def writeTriple2( \
# @param object_type the type for the object in the triple.
# @param datatype the datatype for the object in the triple.
# @param language the language for the object in the triple.
def defaultTriple2( \
def defaultTriple( \
request, subject, predicate, obj, object_type, datatype, language):

request.write("<div class=\"rdfa-default-triple\">")
writeTriple2( \
writeTriple( \
request, subject, predicate, obj, object_type, datatype, language)
request.write("</div>")

Expand All @@ -65,7 +65,7 @@ def defaultTriple2( \
# @param object_type the type for the object in the triple.
# @param datatype the datatype for the object in the triple.
# @param language the language for the object in the triple.
def processorTriple2( \
def processorTriple( \
request, subject, predicate, obj, object_type, datatype, language):

request.write("<div class=\"rdfa-processor-triple\">")
Expand All @@ -83,7 +83,7 @@ def processorTriple2( \
# @param bufferSize the size of the buffer to return. Returning anything less
# than bufferSize will halt execution after the returned
# buffer has been processed.
def handleBuffer2(data, bufferSize):
def handleBuffer(data, bufferSize):
return data.read()

##
Expand All @@ -106,14 +106,11 @@ def handler(req):
if(service.find("/live-loop/triples") != -1):
req.content_type = 'text/html'
if(req.method == "POST"):
document = req.read()
liveLoopDir = os.path.dirname(req.canonical_filename)
p = subprocess.Popen(["python", "live-loop.py"],
bufsize=4096, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, close_fds=True, cwd=liveLoopDir)
p.stdin.write(document)
(so, se) = p.communicate()
req.write(so)
parser = rdfa.RdfaParser("http://example.com/sample.html", False)
parser.setDefaultGraphTripleHandler(defaultTriple, req)
parser.setProcessorGraphTripleHandler(processorTriple, req)
parser.setBufferHandler(handleBuffer, req)
parser.parse()
else:
req.content_type = 'text/plain'
req.write("""
Expand All @@ -139,10 +136,3 @@ def handler(req):

return status

if __name__ == "__main__":
parser = rdfa.RdfaParser("http://example.com/sample.html")
parser.setDefaultGraphTripleHandler(defaultTriple2, sys.stdout)
parser.setProcessorGraphTripleHandler(processorTriple2, sys.stdout)
parser.setBufferHandler(handleBuffer2, sys.stdin)
parser.parse()

0 comments on commit db7bf90

Please sign in to comment.