Commits

Anonymous committed 8f1b911

..

Comments (0)

Files changed (29)

friendpaste/dbsession.py

 from werkzeug.routing import NotFound
 
 from friendpaste.utils import local_manager,ScopedRegistry
-
+from friendpaste.paste.models import Snippet
 
 def make_connection(uri, dbname):
     return CouchDBProxy(uri, dbname)
         self.bind = bind
 
     def view(self, name, wrapper=None, **options):
-        db = self.bind.db
-        return db.view(name, wrapper=None, **options)   
+        try:
+            results = self.bind.db.view(name, wrapper=None, **options)
+        except:
+            raise NotFound
+        if len(results) <= 0:
+            raise NotFound
 
     def load(self, instance, id):
-        db = self.bind.db
-        return instance.load(db, id)
-
+        try:
+            s = instance.load(self.bind.db, id)
+        except:
+            raise NotFound
+        if s._data is None or len(s._data) <= 0:
+            raise NotFound
+        return s
+       
     def store(self, instance):
-        db = self.bind.db
-        instance.store(db)
+        instance.store(self.bind.db)
 
 
 

friendpaste/feeds.py

File contents unchanged.

friendpaste/generic.py

File contents unchanged.

friendpaste/paste/diff.py

File contents unchanged.

friendpaste/paste/views.py

     if rev is None:
         s = couchdb_proxy.load(Snippet, id)
     else:
-        s, revisions = get_snippet(id, rev) 
+        s, revisions = get_snippet(id, rev)
 
+    if s is None:
+        print "blah"
+        raise NotFound()
+    
     if 'application/json' in mimetypes:
         if request.method == 'GET':
+            if s is None:
+                return send_json({'ok': 'false'})
             snippet_hash = {
-            'id': s.id,
+                'id': s.id,
                 'revid': s.revid,
                 'title': s.title,
                 'snippet': s.snippet,
                 'language': str(s.language)
-         }
+            }
             return send_json(snippet_hash)
     
     form = PasteForm(request.form, prefix='paste', **{

friendpaste/utils/pool.py

File contents unchanged.

friendpaste/utils/queue.py

File contents unchanged.

static/css/autumn.css

File contents unchanged.

static/css/borland.css

File contents unchanged.

static/css/colorful.css

File contents unchanged.

static/css/default.css

File contents unchanged.

static/css/emacs.css

File contents unchanged.

static/css/friendly.css

File contents unchanged.

static/css/fruity.css

File contents unchanged.

static/css/manni.css

File contents unchanged.

static/css/murphy.css

File contents unchanged.

static/css/native.css

File contents unchanged.

static/css/pastie.css

File contents unchanged.

static/css/trac.css

File contents unchanged.

static/images/logo_em.gif

Old
Old image
New
New image

static/js/date.js

+
+map = function(/*Array|String*/arr, /*Function|String*/callback, /*Function?*/thisObject){
+    // summary:
+    //		applies callback to each element of arr and returns
+    //		an Array with the results
+    // arr: the array to iterate on.  If a string, operates on individual characters.
+    // callback: a function is invoked with three arguments: item, index, and array and returns a value
+    // thisObject: may be used to scope the call to callback
+    // description:
+    //		This function corresponds to the JavaScript 1.6 Array.map() method.
+    //		In environments that support JavaScript 1.6, this function is a passthrough to the built-in method.
+    //		For more details, see:
+    //			<http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:map>
+    // example:
+    //	|	dojo.map([1, 2, 3, 4], function(item){ return item+1 });
+    //		returns [2, 3, 4, 5]
+    var _p = _getParts(arr, thisObject, callback); arr = _p[0];
+    var outArr = (arguments[3] ? (new arguments[3]()) : []);
+    for(var i=0;i<arr.length;++i){
+        outArr.push(_p[2].call(_p[1], arr[i], i, arr));
+    }
+    return outArr; // Array
+}
+
+
+Date.prototype.setISODate = function(/*String*/formattedString, /*Number?*/defaultTime){
+	//	summary:
+	//		Returns a Date object given a string formatted according to a subset of the ISO-8601 standard.
+	//
+	//	description:
+	//		Accepts a string formatted according to a profile of ISO8601 as defined by
+	//		[RFC3339](http://www.ietf.org/rfc/rfc3339.txt), except that partial input is allowed.
+	//		Can also process dates as specified [by the W3C](http://www.w3.org/TR/NOTE-datetime)
+	//		The following combinations are valid:
+	//
+	//			* dates only
+	//			|	* yyyy
+	//			|	* yyyy-MM
+	//			|	* yyyy-MM-dd
+	// 			* times only, with an optional time zone appended
+	//			|	* THH:mm
+	//			|	* THH:mm:ss
+	//			|	* THH:mm:ss.SSS
+	// 			* and "datetimes" which could be any combination of the above
+	//
+	//		timezones may be specified as Z (for UTC) or +/- followed by a time expression HH:mm
+	//		Assumes the local time zone if not specified.  Does not validate.  Improperly formatted
+	//		input may return null.  Arguments which are out of bounds will be handled
+	// 		by the Date constructor (e.g. January 32nd typically gets resolved to February 1st)
+	//		Only years between 100 and 9999 are supported.
+	//
+  	//	formattedString:
+	//		A string such as 2005-06-30T08:05:00-07:00 or 2005-06-30 or T08:05:00
+	//
+	//	defaultTime:
+	//		Used for defaults for fields omitted in the formattedString.
+	//		Uses 1970-01-01T00:00:00.0Z by default.
+
+	if(!Date.prototype._isoRegExp){
+		Date.prototype._isoRegExp =
+//TODO: could be more restrictive and check for 00-59, etc.
+			/^(?:(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?)?(?:T(\d{2}):(\d{2})(?::(\d{2})(.\d+)?)?((?:[+-](\d{2}):(\d{2}))|Z)?)?$/;
+	}
+
+	var match = Date.prototype._isoRegExp.exec(formattedString);
+	var result = null;
+
+	if(match){
+		match.shift();
+		if(match[1]){match[1]--;} // Javascript Date months are 0-based
+		if(match[6]){match[6] *= 1000;} // Javascript Date expects fractional seconds as milliseconds
+
+		if(defaultTime){
+			// mix in defaultTime.  Relatively expensive, so use || operators for the fast path of defaultTime === 0
+			defaultTime = new Date(defaultTime);
+			map(["FullYear", "Month", "Date", "Hours", "Minutes", "Seconds", "Milliseconds"], function(prop){
+				return defaultTime["get" + prop]();
+			}).forEach(function(value, index){
+				if(match[index] === undefined){
+					match[index] = value;
+				}
+			});
+		}
+		result = new Date(match[0]||1970, match[1]||0, match[2]||1, match[3]||0, match[4]||0, match[5]||0, match[6]||0);
+
+
+		var offset = 0;
+		var zoneSign = match[7] && match[7].charAt(0);
+		if(zoneSign != 'Z'){
+			offset = ((match[8] || 0) * 60) + (Number(match[9]) || 0);
+			if(zoneSign != '-'){ offset *= -1; }
+		}
+		if(zoneSign){
+			offset -= result.getTimezoneOffset();
+		}
+
+        if(offset){
+            result.setTime(result.getTime() + offset * 60000);
+        }
+                    
+	}
+
+	this.setTime(result.getTime()); // Date or null
+}
+
+Date.prototype.toISOString = function(/*Date*/dateObject, /*dojo.date.stamp.__Options?*/options){
+	//	summary:
+	//		Format a Date object as a string according a subset of the ISO-8601 standard
+	//
+	//	description:
+	//		When options.selector is omitted, output follows [RFC3339](http://www.ietf.org/rfc/rfc3339.txt)
+	//		The local time zone is included as an offset from GMT, except when selector=='time' (time without a date)
+	//		Does not check bounds.  Only years between 100 and 9999 are supported.
+	//
+	//	dateObject:
+	//		A Date object
+
+	var _ = function(n){ return (n < 10) ? "0" + n : n; };
+	options = options || {};
+	var formattedDate = [];
+	var getter = options.zulu ? "getUTC" : "get";
+	var date = "";
+	if(options.selector != "time"){
+		var year = dateObject[getter+"FullYear"]();
+		date = ["0000".substr((year+"").length)+year, _(dateObject[getter+"Month"]()+1), _(dateObject[getter+"Date"]())].join('-');
+	}
+	formattedDate.push(date);
+	if(options.selector != "date"){
+		var time = [_(dateObject[getter+"Hours"]()), _(dateObject[getter+"Minutes"]()), _(dateObject[getter+"Seconds"]())].join(':');
+		var millis = dateObject[getter+"Milliseconds"]();
+		if(options.milliseconds){
+			time += "."+ (millis < 100 ? "0" : "") + _(millis);
+		}
+		if(options.zulu){
+			time += "Z";
+		}else if(options.selector != "time"){
+			var timezoneOffset = dateObject.getTimezoneOffset();
+			var absOffset = Math.abs(timezoneOffset);
+			time += (timezoneOffset > 0 ? "-" : "+") + 
+				_(Math.floor(absOffset/60)) + ":" + _(absOffset%60);
+		}
+		formattedDate.push(time);
+	}
+	return formattedDate.join('T'); // String
+}
+
+/* Time Since creates a string which friendly tells you the time since the original date
+* Based on the original time_since() function by Natalie Downe - http://blog.natbat.co.uk/archive/2003/Jun/14/time_since
+*
+* Copyright (c) 2004 Mark Wubben - http://neo.dzygn.com/
+*
+* Usage: date.toTimeSinceString(number nLimit, string sBetween, string sLastBetween)
+* nLimit: limit the shown time units (year, month etc). default = 2
+* sBetween: string between two time units. default = ", "
+* sLastBetween: string between the second-last and last time unit. default = " and "
+==================================================================================================*/
+Date.prototype.toTimeSinceString = function(nLimit, sBetween, sLastBetween){
+	if(!nLimit){ nLimit = 2; }
+	if(!sBetween){ sBetween = ", "; }
+	if(!sLastBetween){ sLastBetween = " and "; }
+	if(!Date.prototype.toTimeSinceString._collStructs){
+		Date.prototype.toTimeSinceString._collStructs = new Array(
+			{seconds: 60 * 60 * 24 * 365, name: "year"},
+			{seconds: 60 * 60 * 24 * 30, name: "month"},
+			{seconds: 60 * 60 * 24 * 7, name: "week"},
+			{seconds: 60 * 60 * 24, name: "day"},
+			{seconds: 60 * 60, name: "hour"},
+			{seconds: 60, name: "minute"}
+		);
+	}
+
+	var collStructs = Date.prototype.toTimeSinceString._collStructs;
+	var nSecondsRemain = ((new Date).valueOf() - this.valueOf()) / 1000;
+	var sReturn = "";
+	var nCount = 0;
+	var nFloored;
+
+
+
+    var now = new Date()
+	for(var i = 0; i < collStructs.length && nCount < nLimit; i++){
+		nFloored = Math.floor(nSecondsRemain / collStructs[i].seconds);
+		if(nFloored > 0){
+			if(sReturn.length > 0){
+				if(nCount == nLimit - 1 || i == collStructs.length - 1){
+					sReturn += sLastBetween;
+				} else if(nCount < nLimit && i < collStructs.length){
+					sReturn += sBetween;
+				}
+			}
+			sReturn += nFloored + " " + collStructs[i].name;
+			if(nFloored > 1){
+				sReturn += "s";
+			}
+			nSecondsRemain -= nFloored * collStructs[i].seconds;
+			nCount++;
+		}
+	}
+    if (sReturn ==  "") 
+        return "0 minutes";
+	return sReturn;
+}
+
+

static/js/friendpaste.js

File contents unchanged.

templates/about.html

File contents unchanged.

templates/developer.html

File contents unchanged.

templates/paste/diff.html

File contents unchanged.

templates/paste/revisions.html

File contents unchanged.

templates/services.html

File contents unchanged.

templates/services/feed.html

File contents unchanged.

templates/services/json.html

File contents unchanged.