This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tornado | |
from pymongo import DESCENDING, ASCENDING | |
from bson.code import Code | |
import motor | |
from datetime import datetime | |
import sys | |
# | |
# A Sortable Discussion Tree stored in MongoDB | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
JSONValidate.py - JSON data structures are often received from a uncontrolled sources such as | |
Web Clients, as a string representation. Standard python tools such as json.py | |
may be used to parse and validate the string representation into Python data | |
structures, comprised of dicts, lists, and assorted basic types. | |
JSONValidate.py provides application level schema validation. | |
- Schema validation. | |
- Data type validation. | |
- Required/optional data members in dicts. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import pymongo | |
from pymongo import Connection | |
def safe_modify(col, query, update): | |
for attempt in range(5): | |
try: | |
result = col.find_and_modify(query={'name': 'Andrew'}, | |
update={"$inc": {"count": 1}}, | |
upsert=True, # If document for 'name':'Andrew' not in there, make one. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Definitions: | |
PollyDiscussionSubjectTree - Subject tree created by facilitators. Made of PollyDiscussionFolders. | |
PollyDiscussionSubjectFolder - Place(e.g. "Copyright Discussions") for PollyDiscussionSubject to be created. | |
PollyDiscussionSubject - A subject created in a PollyDiscussionFolder. | |
A subject is some kind of proposition someone would like agreement on. | |
PollyDiscussionTree - Tree of PollyDiscussionLists related to a PollyDiscussionSubject. | |
PollyDiscussionList - Lists of PollyDiscussions at many levels in a PollyDiscussionTree | |
PollyDiscussionList are sortable by relevance, date/time. | |
PollyDiscussion - An instance of a discussion point by a specific contributor. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Singleton(object): | |
def __init__(self, thing): | |
global Singleton | |
Singleton = self | |
self.thing = thing | |
def __call__(self, thing): | |
return self | |
singleton = Singleton("Original Instance") # This could happen anywhere |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Borg(object): | |
_state = {} | |
def __new__(cls, *p, **k): | |
self = object.__new__(cls, *p, **k) | |
self.__dict__ = cls._state | |
return self | |
class MyBaseClass(object): | |
def __init__(self, base_thing): | |
self.base_thing = base_thing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
class Command(object): # Decorator for command functions in Rooms class. | |
Functions = {} # Builds dict of command functions {name:function} | |
HelpText = {} # Builds dict of help text {name:helptext} | |
def __init__(self, helpText): | |
self.HelpText = helpText | |
def __call__(self, f): | |
Command.Functions[f.__name__] = f | |
Command.HelpText [f.__name__] = self.HelpText |