Permalink
Browse files

Remove dep on commonjs-utils, and add needed modules

  • Loading branch information...
1 parent 016bec5 commit 55daf3f85f014d58c944cf6068edf2e6e80488c9 @kriszyp kriszyp committed Nov 14, 2011
Showing with 618 additions and 27 deletions.
  1. +1 −1 jsgi/auth.js
  2. +2 −2 jsgi/cache.js
  3. +0 −1 jsgi/error.js
  4. +1 −1 jsgi/rest-store.js
  5. +2 −2 jsgi/session.js
  6. +1 −1 media/atom.js
  7. +1 −1 media/hatom.js
  8. +2 −2 media/html.js
  9. +1 −1 media/javascript.js
  10. +1 −1 media/json.js
  11. +1 −1 media/message/json.js
  12. +1 −1 media/plain.js
  13. +1 −1 media/url-encoded.js
  14. +0 −1 package.json
  15. +2 −2 security.js
  16. +3 −3 start-node.js
  17. +2 −2 tests/rest.js
  18. +2 −2 tests/stack.js
  19. +101 −0 util/base64.js
  20. +134 −0 util/json.js
  21. +28 −0 util/parse-header.js
  22. +1 −1 util/repl.js
  23. +330 −0 util/sha1.js
View
@@ -7,7 +7,7 @@ var AccessError = require("perstore/errors").AccessError,
promiseModule = require("promised-io/promise"),
when = promiseModule.when,
print = require("promised-io/process").print,
- base64 = require("commonjs-utils/base64");
+ base64 = require("../util/base64");
exports.Authentication = function(security, nextApp){
// initialize the user model
View
@@ -2,7 +2,7 @@ var CacheStore = require("perstore/store/cache").Cache,
shash = require("narwhal/sha").hash;
exports.FetchCache= function(cache, nextApp) {
- var config = require("commonjs-utils/settings").cache || {};
+ var config = require("perstore/util/settings").cache || {};
config.alwaysVaryOn = config.alwaysVaryOn || [];
return function(request) {
@@ -67,7 +67,7 @@ exports.FetchCache= function(cache, nextApp) {
exports.UpdateCache = function(cache, nextApp){
- var config = require("commonjs-utils/settings").cache || {};
+ var config = require("perstore/util/settings").cache || {};
config.alwaysVaryOn = config.alwaysVaryOn || [];
return function(request) {
View
@@ -7,7 +7,6 @@ var METHOD_HAS_BODY = require("./methods").METHOD_HAS_BODY,
AccessError = require("perstore/errors").AccessError,
MethodNotAllowedError = require("perstore/errors").MethodNotAllowedError,
print = require("promised-io/process").print,
- ErrorConstructor = require("commonjs-utils/extend-error").ErrorConstructor,
when = require("promised-io/promise").when;
exports.ErrorHandler = function(nextApp){
View
@@ -8,7 +8,7 @@ var METHOD_HAS_BODY = require("./methods").METHOD_HAS_BODY,
when = promiseModule.when,
resolve = require("perstore/path").resolve,
Response = require("./response").Response,
- settings = require("commonjs-utils/settings");
+ settings = require("perstore/util/settings");
function dir(){var sys=require('sys');for(var i=0,l=arguments.length;i<l;i++)sys.debug(sys.inspect(arguments[i]));}
exports.RestStore = function(options){
View
@@ -7,9 +7,9 @@
*/
var promiseModule = require("promised-io/promise"),
when = promiseModule.when,
- settings = require("commonjs-utils/settings"),
+ settings = require("perstore/util/settings"),
sessionModel,
- sha1 = require("commonjs-utils/sha1").hex_sha1;
+ sha1 = require("../util/sha1").hex_sha1;
exports.Session = function(options, nextApp){
// assign defaults
View
@@ -21,7 +21,7 @@ Media({
}
write('<link rel="alternate" type="text/html" href="' + (qs.length > 1 && qs || '') + '"/>\n');
if(typeof object.forEach === "function") {
- var range = require("commonjs-utils/jsgi/parse-header")["content-range"](response.headers["content-range"], 25);
+ var range = require("../util/parse-header")["content-range"](response.headers["content-range"], 25);
// TODO escape entities, especially in qs
if (range.prev) {
var prevRange = [range.prev.start, range.prev.end].join("-");
View
@@ -28,7 +28,7 @@ Media({
}
if (typeof object.forEach === "function") {
var headers = object.getMetadata && object.getMetadata() || {},
- range = require("commonjs-utils/jsgi/parse-header")["content-range"](headers["content-range"], 25);
+ range = require("../util/parse-header")["content-range"](headers["content-range"], 25);
if (range && range.prev) {
var prevRange = [range.prev.start, range.prev.end].join("-");
write('<div id="prevLink"><a rel="prev" href="' + qs + '&http-range=items%3d' + prevRange + '">Previous</a></div>')
View
@@ -7,9 +7,9 @@ var Media = require("../media").Media,
transform = require("../html-transform"),
Response=require("../jsgi/response").Response,
resolver = require("templify/lib/templify").Resolver,
- toJSON = require("commonjs-utils/json-ext").stringify,
+ toJSON = require("perstore/util/json-ext").stringify,
when = require("promised-io/promise").when,
- copy = require("commonjs-utils/copy").copy;
+ copy = require("perstore/util/copy").copy;
var templateEngine = require('templify/lib/templify').TemplateEngine({resolver: resolver, store: filesystem});
var defaultHandler = {
View
@@ -1,7 +1,7 @@
/**
* Registers JavaScript media type handling
*/
-var JSONExt = require("commonjs-utils/json-ext"),
+var JSONExt = require("perstore/util/json-ext"),
StreamingSerializer = require("./json").StreamingSerializer,
when = require("promised-io/promise").when,
Media = require("../media").Media,
View
@@ -1,7 +1,7 @@
/**
* Registers JSON media type handling
*/
-var JSONExt = require("commonjs-utils/json-ext"),
+var JSONExt = require("perstore/util/json-ext"),
Media = require("../media").Media,
when = require("promised-io/promise").when,
forEachableToString = require("../media").forEachableToString;
View
@@ -2,7 +2,7 @@
* Registers message/json media handler. This is used for sending and receiving multiple
* requests/responses/messages, and is very useful for bulk updates and Comet
*/
-var JSONExt = require("commonjs-utils/json-ext"),
+var JSONExt = require("perstore/util/json-ext"),
Media = require("../../media").Media,
all = require("promised-io/promise").all,
when = require("promised-io/promise").when,
View
@@ -6,7 +6,7 @@ var Media = require("../media").Media,
when = require("promised-io/promise").when,
getColumnsToExport = require("../media").getColumnsToExport,
print = require("promised-io/process").print,
- JSONExt = require("commonjs-utils/json-ext");
+ JSONExt = require("perstore/util/json-ext");
Media({
mediaType: "text/plain",
View
@@ -1,7 +1,7 @@
/**
* Registers URLEncoded media type handling
*/
-var JSONExt = require("commonjs-utils/json-ext"),
+var JSONExt = require("perstore/util/json-ext"),
stringToValue = require("./auto-type").stringToValue,
print = require("promised-io/process").print,
when = require("promised-io/promise").when,
View
@@ -15,7 +15,6 @@
"mappings":{
"perstore": "http://github.com/kriszyp/perstore/zipball/v0.2.4",
"templify": "http://github.com/dmachi/templify/zipball/master",
- "commonjs-utils": "http://github.com/kriszyp/commonjs-utils/zipball/v0.2.2",
"promised-io": "jar:http://github.com/kriszyp/promised-io/zipball/v0.2.3!/",
"patr": "jar:http://github.com/kriszyp/patr/zipball/v0.2.6!/",
"tunguska": "http://github.com/kriszyp/tunguska/zipball/v0.2.4",
View
@@ -7,8 +7,8 @@ var AccessError = require("perstore/errors").AccessError,
when = require("promised-io/promise").when,
getCurrentSession = require("./jsgi/session").getCurrentSession,
Restrictive = require("perstore/facet").Restrictive,
- sha1 = require("commonjs-utils/sha1").b64_sha1,
- settings = require("commonjs-utils/settings");
+ sha1 = require("./util/sha1").b64_sha1,
+ settings = require("perstore/util/settings");
try{
var uuid = require("uuid");
View
@@ -1,5 +1,5 @@
// helpful for debugging
-var settings = require("commonjs-utils/settings"),
+var settings = require("perstore/util/settings"),
ws = require("node-websocket-server"),
messageJson = require("./media/message/json");
@@ -22,7 +22,7 @@ exports.start = function(jsgiApp, socketApp){
console.log("Listening on port " + port);
// having a REPL is really helpful
-// if(nodes.isMaster){
+ if (require.main === module) {
require("./util/repl").start();
- //}
+ }
};
View
@@ -1,9 +1,9 @@
-require("commonjs-utils/settings").admins = ["user"];// must do this first
+require("perstore/util/settings").admins = ["user"];// must do this first
var MockRequest = require("jack/mock").MockRequest,
mock = new MockRequest(require("pintura").app),
assert = require("assert"),
TestStore = require("perstore/stores").DefaultStore();
- parse = require("commonjs-utils/json-ext").parse;
+ parse = require("perstore/util/json-ext").parse;
TestStore.setPath("TestStore");
require("pintura").config.getDataModel = function(){
return {
View
@@ -1,10 +1,10 @@
-require("commonjs-utils/settings").admins = ["user"];// must do this first
+require("perstore/util/settings").admins = ["user"];// must do this first
var MockRequest = require("jack/mock").MockRequest,
mock = new MockRequest(require("pintura").app),
assert = require("assert"),
TestStore = require("perstore/stores").DefaultStore();
var config = require("pintura").config;
- var parse = require("commonjs-utils/json-ext").parse;
+ var parse = require("perstore/util/json-ext").parse;
TestStore.setPath("TestStore");
View
@@ -0,0 +1,101 @@
+/* Copyright (C) 1999 Masanao Izumo <iz@onicos.co.jp>
+ * Version: 1.0
+ * LastModified: Dec 25 1999
+ * This library is free. You can redistribute it and/or modify it.
+ */
+
+
+var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+var base64DecodeChars = new Array(
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
+ 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
+ -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
+ -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
+ 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1);
+
+exports.encode = function(str) {
+ var out, i, len;
+ var c1, c2, c3;
+
+ len = str.length;
+ i = 0;
+ out = "";
+ while(i < len) {
+ c1 = str.charCodeAt(i++) & 0xff;
+ if(i == len)
+ {
+ out += base64EncodeChars.charAt(c1 >> 2);
+ out += base64EncodeChars.charAt((c1 & 0x3) << 4);
+ out += "==";
+ break;
+ }
+ c2 = str.charCodeAt(i++);
+ if(i == len)
+ {
+ out += base64EncodeChars.charAt(c1 >> 2);
+ out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
+ out += base64EncodeChars.charAt((c2 & 0xF) << 2);
+ out += "=";
+ break;
+ }
+ c3 = str.charCodeAt(i++);
+ out += base64EncodeChars.charAt(c1 >> 2);
+ out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
+ out += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6));
+ out += base64EncodeChars.charAt(c3 & 0x3F);
+ }
+ return out;
+}
+
+exports.decode = function(str) {
+ var c1, c2, c3, c4;
+ var i, len, out;
+
+ len = str.length;
+ i = 0;
+ out = "";
+ while(i < len) {
+ /* c1 */
+ do {
+ c1 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
+ } while(i < len && c1 == -1);
+ if(c1 == -1)
+ break;
+
+ /* c2 */
+ do {
+ c2 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
+ } while(i < len && c2 == -1);
+ if(c2 == -1)
+ break;
+
+ out += String.fromCharCode((c1 << 2) | ((c2 & 0x30) >> 4));
+
+ /* c3 */
+ do {
+ c3 = str.charCodeAt(i++) & 0xff;
+ if(c3 == 61)
+ return out;
+ c3 = base64DecodeChars[c3];
+ } while(i < len && c3 == -1);
+ if(c3 == -1)
+ break;
+
+ out += String.fromCharCode(((c2 & 0XF) << 4) | ((c3 & 0x3C) >> 2));
+
+ /* c4 */
+ do {
+ c4 = str.charCodeAt(i++) & 0xff;
+ if(c4 == 61)
+ return out;
+ c4 = base64DecodeChars[c4];
+ } while(i < len && c4 == -1);
+ if(c4 == -1)
+ break;
+ out += String.fromCharCode(((c3 & 0x03) << 6) | c4);
+ }
+ return out;
+}
Oops, something went wrong.

0 comments on commit 55daf3f

Please sign in to comment.