本文整理汇总了Python中data.storage.Storage.find方法的典型用法代码示例。如果您正苦于以下问题:Python Storage.find方法的具体用法?Python Storage.find怎么用?Python Storage.find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类data.storage.Storage
的用法示例。
在下文中一共展示了Storage.find方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Room
# 需要导入模块: from data.storage import Storage [as 别名]
# 或者: from data.storage.Storage import find [as 别名]
class Room(object):
# very limited content negotiation support - our format choices
# for output. This also shows _a way_ of representing enums in python
json, xml, html, text = range(1,5)
#
# setup the configuration for our service
#
def __init__(self,base,conf_fn):
self.host = socket.gethostname()
self.base = base
self.conf = {}
# should emit a failure (file not found) message
if os.path.exists(conf_fn):
with open(conf_fn) as cf:
for line in cf:
name, var = line.partition("=")[::2]
self.conf[name.strip()] = var.strip()
else:
raise Exception("configuration file not found.")
# create storage
self.__store = Storage()
#
# example: find data
#
def find(self,name):
print '---> classroom.find:',name
return self.__store.find(name)
#
# example: add data
#
def add(self,name,value):
try:
self.__store.insert(name,value)
self.__store.names();
return 'success'
except:
return 'failed'
def checkLogin(self,data):
try:
print("Inclassromm :::::::::::::");
self.__store.names();
return(self.__store.checkLogin(data))
except:
return 'failed'
#Sud start
def userAdd(self,userJson):
try:
print("Inclassromm :::::::::::::");
self.__store.names();
return(self.__store.createUser(userJson))
except:
return 'failed'
def updateUser(self,userJson,email):
try:
print("Inclassromm of update user:::::::::::::");
self.__store.names();
return(self.__store.updateUser(userJson,email))
except:
return 'failed'
def updateEnrolled(self,enrolledCourseData):
try:
return(self.__store.updateEnrolled(enrolledCourseData))
except:
return 'failed'
def ownedCourselist(self,email):
try:
return(self.__store.ownedCourselist(email))
except:
return 'failed'
def deleteCourse(self,courseJson,cid):
try:
return(self.__store.deleteCourse(courseJson,cid))
except:
return 'failed'
def deleteOwnedCourse(self,courseJson,cid):
try:
return(self.__store.deleteOwnedCourse(courseJson,cid))
#.........这里部分代码省略.........
示例2: Room
# 需要导入模块: from data.storage import Storage [as 别名]
# 或者: from data.storage.Storage import find [as 别名]
class Room(object):
# very limited content negotiation support - our format choices
# for output. This also shows _a way_ of representing enums in python
json, xml, html, text = range(1,5)
#
# setup the configuration for our service
#
def __init__(self,base,conf_fn):
self.host = socket.gethostname()
self.base = base
self.conf = {}
# should emit a failure (file not found) message
if os.path.exists(conf_fn):
with open(conf_fn) as cf:
for line in cf:
name, var = line.partition("=")[::2]
self.conf[name.strip()] = var.strip()
else:
raise Exception("configuration file not found.")
# create storage
self.__store = Storage()
#
# example: find data
#
def find(self,name):
print '---> classroom.find:',name
return self.__store.find(name)
#
# example: add data
#
def add(self,name,value):
try:
self.__store.insert(name,value)
self.__store.names();
return 'success'
except:
return 'failed'
# TODO success|failure
#
# dump the configuration in the requested format. Note placing format logic
# in the functional code is not really a good idea. However, it is here to
# provide an example.
#
#
def dump_conf(self,format):
if format == Room.json:
return self.__conf_as_json()
elif format == Room.html:
return self.__conf_as_html()
elif format == Room.xml:
return self.__conf_as_xml()
elif format == Room.text:
return self.__conf_as_text()
else:
return self.__conf_as_text()
#
# output as xml is supported through other packages. If
# you want to add xml support look at gnosis or lxml.
#
def __conf_as_json(self):
return "xml is hard"
#
#
#
def __conf_as_json(self):
try:
all = {}
all["base.dir"] = self.base
all["conf"] = self.conf
return json.dumps(all)
except:
return "error: unable to return configuration"
#
#
#
def __conf_as_text(self):
try:
sb = StringIO.StringIO()
sb.write("Room Configuration\n")
sb.write("base directory = ")
sb.write(self.base)
sb.write("\n\n")
sb.write("configuration:\n")
for key in sorted(self.conf.iterkeys()):
print >>sb, "%s=%s" % (key, self.conf[key])
str = sb.getvalue()
return str
#.........这里部分代码省略.........
示例3: Room
# 需要导入模块: from data.storage import Storage [as 别名]
# 或者: from data.storage.Storage import find [as 别名]
class Room(object):
# very limited content negotiation support - our format choices
# for output. This also shows _a way_ of representing enums in python
json, xml, html, text = range(1, 5)
#
# setup the configuration for our service
#
def __init__(self, base, conf_fn):
self.host = socket.gethostname()
self.base = base
self.conf = {}
# should emit a failure (file not found) message
if os.path.exists(conf_fn):
with open(conf_fn) as cf:
for line in cf:
name, var = line.partition("=")[::2]
self.conf[name.strip()] = var.strip()
else:
raise Exception("configuration file not found.")
# create storage
self.__store = Storage()
#
# example: get course
#
def getCourse(self, id):
print '---> classroom.getCourse:',id
return self.__store.getCourse(id)
#
# example: add data
#
def add(self,name,value):
try:
self.__store.insert(name,value)
self.__store.names();
return 'success'
except:
e = sys.exc_info()[0]
traceback.print_exc(file=sys.stdout)
return "Error: %s" % e
# TODO success|failure
# update Annoucement
def updateDiscussion(self, id, body):
self.__store.updateDiscussion(id, body)
# update Annoucement
def updateAnnoucement(self, id, body):
self.__store.updateAnnoucement(id, body)
#
# Discussion list delete
#
def deleteDiscussion(self, id):
print '---> classroom discussion delete.find:'
try:
return self.__store.deleteDiscussion(id)
except:
e = sys.exc_info()[0]
traceback.print_exc(file=sys.stdout)
return "Error: %s" % e
#
# Announcement list delete
#
def deleteAnnouncement(self, id):
print '---> classroom announcement delete.find:'
try:
return self.__store.deleteAnnouncement(id)
except:
e = sys.exc_info()[0]
traceback.print_exc(file=sys.stdout)
return "Error: %s" % e
# update course
def updateCourse(self, id, body):
self.__store.updateCourse(id, body)
#
# course list delete
#
def deleteCourse(self, id):
print '---> classroom course delete.find:'
try:
return self.__store.deleteCourse(id)
except:
e = sys.exc_info()[0]
traceback.print_exc(file=sys.stdout)
return "Error: %s" % e
#.........这里部分代码省略.........