Exemplo n.º 1
0
 def insertIntoDB(self):
     cur.execute(
         """INSERT INTO MESSAGE(ID, Title, Post, parentID, USER_ID) 
         VALUES(%d, '%s', '%s', %d, %d)"""
         % (self.id, mdb.escape_string(self.title), mdb.escape_string(self.post), self.parentPostID, self.author)
     )
     con.commit()
Exemplo n.º 2
0
 def insertIntoDB(self):
     cur.execute(
         """INSERT INTO MESSAGE(ID, Title, Post, parentID, USER_ID) 
         VALUES(%d, '%s', '%s', %d, %d)""" %
         (self.id, mdb.escape_string(self.title),
          mdb.escape_string(self.post), self.parentPostID, self.author))
     con.commit()
Exemplo n.º 3
0
 def tearDown(self):
     cur.execute("DELETE FROM MESSAGE")
     cur.execute("DELETE FROM USER")
     meeplib._reset()
     con.commit() 
     assert len(meeplib._messages) == 0
     assert len(meeplib._users) == 0
     assert len(meeplib._user_ids) == 0
Exemplo n.º 4
0
 def tearDown(self):
     cur.execute("DELETE FROM MESSAGE")
     cur.execute("DELETE FROM USER")
     meeplib._reset()
     con.commit()
     assert len(meeplib._messages) == 0
     assert len(meeplib._users) == 0
     assert len(meeplib._user_ids) == 0
Exemplo n.º 5
0
 def insertIntoDB(self):
     try:
         cur.execute(
             "INSERT INTO USER(Username, Password, ID) VALUES('%s', '%s', %d)"
             % (mdb.escape_string(self.username), mdb.escape_string(self.password), self.id)
         )
         con.commit()
     except mdb.Error, e:
         print "Error %d: %s" % (e.args[0], e.args[1])
Exemplo n.º 6
0
 def insertIntoDB(self):
     try:
         cur.execute(
             "INSERT INTO USER(Username, Password, ID) VALUES('%s', '%s', %d)"
             % (mdb.escape_string(
                 self.username), mdb.escape_string(self.password), self.id))
         con.commit()
     except mdb.Error, e:
         print "Error %d: %s" % (e.args[0], e.args[1])
Exemplo n.º 7
0
def destroyCookieHeader(id):
    cur.execute("""DELETE FROM SESSION WHERE ID='%s'""" % (id))
    con.commit()

    c = SimpleCookie()
    c['username'] = ''

    s = c.output()
    (key, value) = s.split(': ')
    return (key, value)
Exemplo n.º 8
0
def destroyCookieHeader(id):
    cur.execute("""DELETE FROM SESSION WHERE ID='%s'""" % (id))
    con.commit()
    
    c = SimpleCookie()
    c['username'] = ''
    
    s = c.output()
    (key, value) = s.split(': ')
    return (key, value)
Exemplo n.º 9
0
    def setUp(self):
        #the backup data causes some of the tests to fail - not sure why
        #remove the backup data before every test
        cur.execute("DELETE FROM MESSAGE")
        cur.execute("DELETE FROM SESSION")
        cur.execute("DELETE FROM USER")
        meeplib._reset()
        con.commit()

        u = meeplib.User('foo', 'bar')
        u.insertIntoDB()
        m = meeplib.Message('the title', 'the content', u.id, -1)
        m.insertIntoDB()
Exemplo n.º 10
0
 def setUp(self):
     #the backup data causes some of the tests to fail - not sure why
     #remove the backup data before every test
     cur.execute("DELETE FROM MESSAGE")
     cur.execute("DELETE FROM SESSION")
     cur.execute("DELETE FROM USER")
     meeplib._reset()
     con.commit()  
         
     u = meeplib.User('foo', 'bar')
     u.insertIntoDB()
     m = meeplib.Message('the title', 'the content', u.id, -1)
     m.insertIntoDB()
Exemplo n.º 11
0
 def setUp(self):
     #the backup data causes some of the tests to fail - not sure why
     #remove the backup data before every test
     cur.execute("DELETE FROM MESSAGE")
     cur.execute("DELETE FROM SESSION")
     cur.execute("DELETE FROM USER")
     con.commit()
     meep_example_app.meeplib._users = {}
     meep_example_app.meeplib._messages = {}
     meep_example_app.meeplib._user_ids= {}  
     
     meep_example_app.initialize()
     app = meep_example_app.MeepExampleApp()
     self.app = app
     cur.execute("INSERT INTO SESSION(ID, USER_ID) VALUES('studentx',%d)" % (meep_example_app.meeplib.get_user('studentx').id))
     con.commit()
Exemplo n.º 12
0
    def setUp(self):
        #the backup data causes some of the tests to fail - not sure why
        #remove the backup data before every test
        cur.execute("DELETE FROM MESSAGE")
        cur.execute("DELETE FROM SESSION")
        cur.execute("DELETE FROM USER")
        con.commit()
        meep_example_app.meeplib._users = {}
        meep_example_app.meeplib._messages = {}
        meep_example_app.meeplib._user_ids = {}

        meep_example_app.initialize()
        app = meep_example_app.MeepExampleApp()
        self.app = app
        cur.execute("INSERT INTO SESSION(ID, USER_ID) VALUES('studentx',%d)" %
                    (meep_example_app.meeplib.get_user('studentx').id))
        con.commit()
Exemplo n.º 13
0
def make_set_cookie_header(name, value, path='/'):
    """
    Makes a 'Set-Cookie' header.
    
    """
    
    sessionID = str(uuid.uuid4())
    c = SimpleCookie()
    c[name] = sessionID
    c[name]['path'] = path
    
    #insert entry into database
    cur.execute("""INSERT INTO SESSION(ID, USER_ID) VALUES('%s',   
        %d)""" % (sessionID, value.id))
    con.commit()
    
    # can also set expires and other stuff.  See
    # Examples under http://docs.python.org/library/cookie.html.

    s = c.output()
    (key, value) = s.split(': ')
    return (key, value)
Exemplo n.º 14
0
def make_set_cookie_header(name, value, path='/'):
    """
    Makes a 'Set-Cookie' header.
    
    """

    sessionID = str(uuid.uuid4())
    c = SimpleCookie()
    c[name] = sessionID
    c[name]['path'] = path

    #insert entry into database
    cur.execute("""INSERT INTO SESSION(ID, USER_ID) VALUES('%s',   
        %d)""" % (sessionID, value.id))
    con.commit()

    # can also set expires and other stuff.  See
    # Examples under http://docs.python.org/library/cookie.html.

    s = c.output()
    (key, value) = s.split(': ')
    return (key, value)
Exemplo n.º 15
0
def delete_message(msg):
    assert isinstance(msg, Message)
    for c in msg.children.values():
        delete_message(c)
        try:
            cur.execute("DELETE FROM MESSAGE WHERE ID=%d" % (c.id))
        except mdb.Error, e:
            print "Error %d: %s" % (e.args[0], e.args[1])
    try:
        if msg.parentPostID == -1:
            del _messages[msg.id]
        else:
            del _messages[msg.parentPostID].children[msg.id]
            del _messages[msg.id]
        cur.execute("DELETE FROM MESSAGE WHERE ID=%d" % (msg.id))
        con.commit()
    except mdb.Error, e:
        print "Error %d: %s" % (e.args[0], e.args[1])


###


class User(object):
    def __init__(self, username, password):
        self.username = username
        self.password = password
        self._save_user()

    def __cmp__(self, other):
        if (other.username != self.username
Exemplo n.º 16
0
def delete_message(msg):
    assert isinstance(msg, Message)
    for c in msg.children.values():
        delete_message(c)
        try:
            cur.execute("DELETE FROM MESSAGE WHERE ID=%d" % (c.id))
        except mdb.Error, e:
            print "Error %d: %s" % (e.args[0], e.args[1])
    try:
        if msg.parentPostID == -1:
            del _messages[msg.id]
        else:
            del _messages[msg.parentPostID].children[msg.id]
            del _messages[msg.id]
        cur.execute("DELETE FROM MESSAGE WHERE ID=%d" % (msg.id))
        con.commit()
    except mdb.Error, e:
        print "Error %d: %s" % (e.args[0], e.args[1])


###


class User(object):
    def __init__(self, username, password):
        self.username = username
        self.password = password
        self._save_user()

    def __cmp__(self, other):
        if other.username != self.username or other.password != self.password:
Exemplo n.º 17
0
def resetDB():
    cur.execute("DELETE FROM SESSION")
    cur.execute("DELETE FROM MESSAGE")
    cur.execute("DELETE FROM USER")
    con.commit()   
Exemplo n.º 18
0
def resetDB():
    cur.execute("DELETE FROM SESSION")
    cur.execute("DELETE FROM MESSAGE")
    cur.execute("DELETE FROM USER")
    con.commit()