Commits

Nikhil Marathe committed 01f6375

Fixed to work with node v0.1.30

Comments (0)

Files changed (3)

deps/nerve/lib/nerve.js

 					headers[name] = response_data.headers[name];
 				}
 			}
-			this.sendHeader(response_data.status_code || 200, headers);
+			this.writeHeader(response_data.status_code || 200, headers);
 			this.write(response_data.content || response_data, 'binary');
 			this.close();
 		}
 	function serve_static_file(pathname, res) {
 		path.exists(pathname, function (exists) {
 			if (exists) {
-				fs.readFile(pathname, 'binary').addCallback(function (content) {
-					res.respond({content: content, headers: {'Content-Type': mime.mime_type(pathname)}});
-				}).addErrback(function (e) {
-					res.respond({content: '<html><head><title>Exception</title></head><body><h1>Exception</h1><pre>' + sys.inspect(e) + '</pre></body></html>', status_code: 501});
-				});
+				fs.readFile(pathname, 'binary', function (err, content) {
+                    if( err )
+                        res.respond({content: '<html><head><title>Exception</title></head><body><h1>Exception</h1><pre>' + sys.inspect(e) + '</pre></body></html>', status_code: 501});
+                    else
+                        res.respond({content: content, headers: {'Content-Type': mime.mime_type(pathname)}});
+                });
 			} else {
 				res.respond({content: '<html><head><title>Not Found</title></head><body><h1>Not Found</h1></body></html>', status_code: 404});
 			}

deps/redis-node-client/redisclient.js

     });
 
     this.conn.addListener("end", function () {
-      if (self.conn && self.conn.readyState === "open") {
+      if (self.conn && self.conn.readyState) {
         self.conn.close();
         self.conn = null;
       }
     var next_reply_at = result[1];
     this.buffer = this.buffer.substring(next_reply_at);
     var callback = this.callbacks.shift();
-    if (callback.promise) {
-      var result_value = result[0];
+    var result_value = result[0];
+    if( callback.func ) {
       if (is_error) 
-        callback.promise.emitError(result_value);
+        callback.func(true, result_value);
       else {
         result_value = post_process_results(callback.command, result_value);
-        callback.promise.emitSuccess(result_value);
+        callback.func(false, result_value);
       }
     }
   }
         description += "'" + arguments[a] + "',";
       description = description.substr(0, description.length - 1) + " )";
     }
-    var args = arguments;    
+    var actual_callback = null;
+    var args = arguments;
+    if( typeof( arguments[arguments.length-1] ) === "function" ) {
+      actual_callback = arguments[arguments.length-1];
+      [].pop.call(args);
+    }
+    else {
+        sys.debug( name );
+        sys.debug( typeof( arguments[arguments.length-1] ));
+    }
     var self = this;
-    var promise = new process.Promise();
     this.connect(function () {
       var command;
       if (inline_commands[name]) 
         write_debug("call:   " + description);
         write_debug("command:" + command);
       }
-      self.callbacks.push({ promise:promise, command:name.toLowerCase() });
+      self.callbacks.push({ command:name.toLowerCase(), func: actual_callback });
       self.conn.write(command);
     });
-    return promise;
   };
 }
 
 //   'lexicographically': true|false
 //   'store_key': 'a_key_name'
 
-Client.prototype.sort = function (key, options) {
-  var promise = new process.Promise();
+Client.prototype.sort = function (key, options, func) {
   var self = this;
   this.connect(function () {
     var opts = [];
     } 
     var command = 'sort ' + key + ' ' + opts.join(' ') + crlf;
     write_debug("call:    client.sort(...)\ncommand: " + command);
-    self.callbacks.push({ promise:promise, command:'sort' });
+    self.callbacks.push({ command:'sort', func: func });
     self.conn.write(command);
   });
-  return promise;
 }
 
 Client.prototype.quit = function () {
 Client.prototype.make_master = function () {
   var self = this;
   this.connect(function () {
-    self.callbacks.push({ promise:null, command:'slaveof' });
+    self.callbacks.push({ command:'slaveof' });
     self.conn.write('slaveof no one');
   });
 };
  * Returns nothing
  */
 var withRedis = function( cb ) {
-    var errback = arguments[1];
+  var errback = arguments[1];
 
-    var r = new redis.Client();
+  var r = new redis.Client();
 
-    r.connect( _.bind( cb, { redis : r } ) );
+  r.connect( _.bind( cb, { redis : r } ) );
 
-    r.addListener( "close", function(error) {
-        if( error ) {
-            process.stdio.writeError( "Error connecting to Redis database\n" );
-            if( typeof(errback) === "function" )
-                errback();
-        }
-    });
+  r.addListener( "close", function(error) {
+    if( error ) {
+      process.stdio.writeError( "Error connecting to Redis database\n" );
+      if( typeof(errback) === "function" )
+        errback();
+    }
+  });
 }
 
 var languages = 
   ["yaml", "YAML"]];
 
 var genLanguageList = function() {
-    return languages.map( function(lang) {
-        return '<option value="' + lang[0] + '">' + lang[1] + '</option>';
-    } );
+  return languages.map( function(lang) {
+    return '<option value="' + lang[0] + '">' + lang[1] + '</option>';
+  } );
 }
 
 var formHtml = '<form action="/add" method="post">'
-            +  '<label for="code">Paste code</label><br>'
-            +  '<textarea name="code" rows="25" cols="80"></textarea><br>'
-            +  '<label for="language">Language</label>'
-            +  '<select name="language">'
-            +  genLanguageList()
-            +  '</select>'
-            +  '<input type="submit" value="Paste!" /></form>';
+      +  '<label for="code">Paste code</label><br>'
+      +  '<textarea name="code" rows="25" cols="80"></textarea><br>'
+      +  '<label for="language">Language</label>'
+      +  '<select name="language">'
+      +  genLanguageList()
+      +  '</select>'
+      +  '<input type="submit" value="Paste!" /></form>';
 
 var getPostParams = function(req, callback){ 
   var body = ''; 
   req.addListener('data', function(chunk){
-       body += chunk;
-     }) 
-     .addListener('end', function() { 
-       var obj = qs.parse(  body.replace( /\+/g, ' ' ) ) ;
-       callback( obj );
-     });
+     body += chunk;
+   }) 
+   .addListener('end', function() { 
+     var obj = qs.parse(  body.replace( /\+/g, ' ' ) ) ;
+     callback( obj );
+   });
 } 
 
 var addSnippet = function( req, res ) {
-    getPostParams( req, function( obj ) {
-        withRedis( function() {
-            var redis = this.redis; // required in inner callback
+  getPostParams( req, function( obj ) {
+    withRedis( function() {
+      var redis = this.redis; // required in inner callback
 
-            this.redis.incr( 'nextid' )
-            .addCallback( function( id ) {
-                redis.set( 'snippet:'+id, JSON.stringify( obj ) )
-                .addCallback( function() {
-                    var msg = 'The snippet has been saved at <a href="/'+id+'">'+req.headers.host+'/'+id+'</a>';
-                    res.respond( msg );
-                } );
-            } );
-        }, function() {
-            res.respond( "Error saving data. Please try again later" );
-        });
+      this.redis.incr( 'nextid' , function( err, id ) {
+        redis.set( 'snippet:'+id, JSON.stringify( obj ), function() {
+          var msg = 'The snippet has been saved at <a href="/'+id+'">'+req.headers.host+'/'+id+'</a>';
+          res.respond( msg );
+        } );
+      } );
+    }, function() {
+      res.respond( "Error saving data. Please try again later" );
     });
+  });
 };
 
 var showSnippet = function( req, res, id ) {
-    withRedis( function() {
-        this.redis.get( 'snippet:'+id )
-        .addCallback( function( data ) {
-            if( !data ) {
-                res.sendHeader( 404 );
-                res.write( "No such snippet" );
-                res.close();
-                return;
-            }
+  withRedis( function() {
+    this.redis.get( 'snippet:'+id, function( err, data ) {
+      if( !data ) {
+        res.sendHeader( 404 );
+        res.write( "No such snippet" );
+        res.close();
+        return;
+      }
 
-            res.sendHeader( 200, { "Content-Type" : "text/html" } );
+      res.sendHeader( 200, { "Content-Type" : "text/html" } );
 
-            var obj = JSON.parse( data );
-            var shortcode = languages.filter( function(el) { 
-                return el[0] == obj.language;
-            } ) [0][0];
+      var obj = JSON.parse( data );
+      var shortcode = languages.filter( function(el) { 
+        return el[0] == obj.language;
+      } ) [0][0];
 
-            var pyg = process.createChildProcess( "pygmentize",
-                                                [ "-l", shortcode,
-                                                  "-f", "html",
-                                                  "-O", "full,style=pastie",
-                                                  "-P", "title=Snippet #" + id ] );
-            pyg.addListener( "output", function( coloured ) {
-                if( coloured )
-                    res.write( coloured );
-                else
-                    res.close();
-            } );
+      var pyg = process.createChildProcess( "pygmentize",
+                        [ "-l", shortcode,
+                          "-f", "html",
+                          "-O", "full,style=pastie",
+                          "-P", "title=Snippet #" + id ] );
+      pyg.addListener( "output", function( coloured ) {
+        if( coloured )
+          res.write( coloured );
+        else
+          res.close();
+      } );
 
-            pyg.write( obj.code );
-            pyg.close();
-        });
+      pyg.write( obj.code );
+      pyg.close();
     });
+  });
 }
 
 nerve.create( [
-    [ /^\/([0-9]+)/, showSnippet ],
-    [ nerve.post("/add"), addSnippet ],
-    [ "/", function( req, res ) { res.respond( formHtml ); } ]
+  [ /^\/([0-9]+)/, showSnippet ],
+  [ nerve.post("/add"), addSnippet ],
+  [ "/", function( req, res ) { res.respond( formHtml ); } ]
 ]).listen( 8000 );