當前位置: 首頁>>代碼示例>>Python>>正文


Python database.Database類代碼示例

本文整理匯總了Python中common.database.Database的典型用法代碼示例。如果您正苦於以下問題:Python Database類的具體用法?Python Database怎麽用?Python Database使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Database類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: save_to_mongo

 def save_to_mongo(request_json):
     try:
         Database.insert(GraphConstants.COLLECTION, request_json)
     except:
         GraphErrors.GraphAlreadyExistsError(
             "The graph you tried to create with name {} already exists. Please pick a different 'unique_name'.".format(
                 request_json['unique_name']))
開發者ID:rc65,項目名稱:stacs-hack-2016,代碼行數:7,代碼來源:graph.py

示例2: updatedb

 def updatedb(self):
     try:
         db = Database()
         smsen = []
         smsen.append(self.smsdict)
         smsgwglobals.wislogger.debug("WATCHDOG: " +
                                      "UPDATING " + str(self.smsdict["smsid"]) + " " + str(self.smsdict["status"]))
         db.update_sms(smsen)
     except error.DatabaseError as e:
         smsgwglobals.wislogger.debug(e.message)
開發者ID:achmadns,項目名稱:smsgateway,代碼行數:10,代碼來源:smstransfer.py

示例3: delete_months

def delete_months(group, months_to_keep):
    # Find data in the database
    # Those timestamps older than `months`, delete them.
    if months_to_keep < 1:
        return
    else:
        Database.remove(DataConstants.COLLECTION,
                        {"group": group,
                         "date":
                             {"$lte": datetime.datetime.utcnow() - datetime.timedelta(days=months_to_keep * 31)}
                         })
開發者ID:rc65,項目名稱:stacs-hack-2016,代碼行數:11,代碼來源:aggregation_logic.py

示例4: run

    def run(self):
        # load the configuration
        # Create default root user
        db = Database()

        abspath = path.abspath(path.join(path.dirname(__file__), path.pardir))
        configfile = abspath + '/conf/smsgw.conf'
        cfg = SmsConfig(configfile)
        wisglobals.wisid = cfg.getvalue('wisid', 'nowisid', 'wis')
        wisglobals.wisipaddress = cfg.getvalue('ipaddress', '127.0.0.1', 'wis')
        wisglobals.wisport = cfg.getvalue('port', '7777', 'wis')
        wisglobals.cleanupseconds = cfg.getvalue('cleanupseconds', '86400', 'wis')

        wisglobals.ldapserver = cfg.getvalue('ldapserver', None, 'wis')
        wisglobals.ldapbasedn = cfg.getvalue('ldapbasedn', None, 'wis')
        wisglobals.ldapenabled = cfg.getvalue('ldapenabled', None, 'wis')
        ldapusers = cfg.getvalue('ldapusers', '[]', 'wis')
        wisglobals.ldapusers = json.loads(ldapusers)
        wisglobals.ldapusers = [item.lower() for item in wisglobals.ldapusers]
        smsgwglobals.wislogger.debug("WIS:" + str(wisglobals.ldapusers))

        password = cfg.getvalue('password', '20778ba41791cdc8ac54b4f1dab8cf7602a81f256cbeb9e782263e8bb00e01794d47651351e5873f9ac82868ede75aa6719160e624f02bba4df1f94324025058', 'wis')
        salt = cfg.getvalue('salt', 'changeme', 'wis')

        # write the default user on startup
        db.write_users('root', password, salt)

        # check if ssl is enabled
        wisglobals.sslenabled = cfg.getvalue('sslenabled', None, 'wis')
        wisglobals.sslcertificate = cfg.getvalue('sslcertificate', None, 'wis')
        wisglobals.sslprivatekey = cfg.getvalue('sslprivatekey', None, 'wis')
        wisglobals.sslcertificatechain = cfg.getvalue('sslcertificatechain', None, 'wis')

        smsgwglobals.wislogger.debug("WIS: SSL " + str(wisglobals.sslenabled))

        if wisglobals.sslenabled is not None and 'true' in wisglobals.sslenabled.lower():
            smsgwglobals.wislogger.debug("WIS: STARTING SSL")
            cherrypy.config.update({'server.ssl_module':
                                    'builtin'})
            cherrypy.config.update({'server.ssl_certificate':
                                    wisglobals.sslcertificate})
            cherrypy.config.update({'server.ssl_private_key':
                                    wisglobals.sslprivatekey})
            if wisglobals.sslcertificatechain is not None:
                cherrypy.config.update({'server.ssl_certificate_chain':
                                        wisglobals.sslcertificatechain})

        cherrypy.config.update({'server.socket_host':
                                wisglobals.wisipaddress})
        cherrypy.config.update({'server.socket_port':
                                int(wisglobals.wisport)})
        cherrypy.quickstart(Root(), '/smsgateway',
                            'wis-web.conf')
開發者ID:stevenx,項目名稱:smsgateway,代碼行數:53,代碼來源:wis.py

示例5: writetodb

 def writetodb(self):
     try:
         db = Database()
         db.insert_sms(self.smsdict["modemid"],
                       self.smsdict["targetnr"],
                       self.smsdict["content"],
                       self.smsdict["priority"],
                       self.smsdict["appid"],
                       self.smsdict["sourceip"],
                       self.smsdict["xforwardedfor"],
                       self.smsdict["smsintime"],
                       self.smsdict["status"],
                       self.smsdict["statustime"])
     except error.DatabaseError as e:
         smsgwglobals.wislogger.debug(e.message)
開發者ID:stevenx,項目名稱:smsgateway,代碼行數:15,代碼來源:smstransfer.py

示例6: from_name

 def from_name(cls, name, **kwargs):
     data = Database.find_one(GraphConstants.COLLECTION, {'unique_name': name})
     if not data:
         raise GraphErrors.GraphNotFoundError("The graph you requested '{}' was not found.".format(name))
     data.update(kwargs)
     graph = cls.from_json(data)
     return graph.run(data)
開發者ID:rc65,項目名稱:stacs-hack-2016,代碼行數:7,代碼來源:graph.py

示例7: checkpassword

    def checkpassword(username, password):
        try:
            db = Database()
            erg = db.read_users(username)

            if erg is None or len(erg) == 0:
                raise error.UserNotFoundError()

            retpasswordhash = erg[0]["password"]
            retpasswordsalt = erg[0]["salt"]

            givpasswordhash = hashlib.sha512((password +
                                              retpasswordsalt)
                                             .encode('utf-8')).hexdigest()

            if retpasswordhash == givpasswordhash:
                return True
            else:
                return False

        except error.DatabaseError as e:
            smsgwglobals.wislogger.debug(e.message)
開發者ID:stevenx,項目名稱:smsgateway,代碼行數:22,代碼來源:helper.py

示例8: login_valid_user

 def login_valid_user(email, password):
     """
     :param  email: user's email
     :param password: user's password
     :return: True if valid, False otherwise
     """
     userData = Database.find_one("users", {'email': email})
     if userData is None:
         raise UserNotExistsError("this user does not existed!")
         return False
     if not Utils.check_hashed_password(password, userData['password']):
         raise UserIncorrectPasswordError("Incorrect password!")
         return False
     return True
開發者ID:tuannvm,項目名稱:flask,代碼行數:14,代碼來源:user.py

示例9: register_user

 def register_user(email, password):
     """
     This method registers a user using  e-mail and password.
     The password already come with sha-512 hash algorithm.
     :param email: user's email (might be invalid)
     :param password: sha512-hashed password
     :return: True if registered successfully, of False otherwise
     """
     userData = Database.find_one("users", {'email': email})
     if userData is not None:
         raise UserExistsError("user already existed!")
     #if email is invalid, then what?
     if not Utils.email_is_valid(email):
         raise UserEmailInvalid("invalid email!")
     #hash password, create new object, then insert to db
     User(email, Utils.hash_password(password)).save_to_db()
     return True
開發者ID:tuannvm,項目名稱:flask,代碼行數:17,代碼來源:user.py

示例10: is_login_valid

    def is_login_valid(cls, email, password):
        """
        This method verifies that an e-mail/password combo (as sent by the site forms) is valid or not.
        Checks that the e-mail exists, and that the password associated to that e-mail is correct.
        :param email: The user's email
        :param password: A sha512 hashed password
        :return: True if valid, False otherwise
        """
        user_data = Database.find_one(UserConstants.COLLECTION, {"email": email})  # Password in sha512 -> pbkdf2_sha512
        if user_data is None:
            # Tell the user that their e-mail doesn't exist
            raise UserErrors.UserNotExistsError("Your user does not exist.")
        if not Utils.check_hashed_password(password, user_data['password']):
            # Tell the user that their password is wrong
            raise UserErrors.IncorrectPasswordError("Your password was wrong.")

        return cls(**user_data)
開發者ID:rc65,項目名稱:stacs-hack-2016,代碼行數:17,代碼來源:user.py

示例11: register_user

    def register_user(email, password):
        """
        This method registers a user using e-mail and password.
        The password already comes hashed as sha-512.
        :param email: user's e-mail (might be invalid)
        :param password: sha512-hashed password
        :return: True if registered successfully, or False otherwise (exceptions can also be raised)
        """
        user_data = Database.find_one(UserConstants.COLLECTION, {"email": email})

        if user_data is not None:
            raise UserErrors.UserAlreadyRegisteredError("The e-mail you used to register already exists.")
        if not Utils.email_is_valid(email):
            raise UserErrors.InvalidEmailError("The e-mail does not have the right format.")

        user = User(email, Utils.hash_password(password))
        user.save_to_db()

        return user
開發者ID:rc65,項目名稱:stacs-hack-2016,代碼行數:19,代碼來源:user.py

示例12: find_by_id

 def find_by_id(cls, id):
     return cls(**Database.find_one(UserConstants.COLLECTION, {'_id': id}))
開發者ID:rc65,項目名稱:stacs-hack-2016,代碼行數:2,代碼來源:user.py

示例13: save_to_db

 def save_to_db(self):
     Database.insert(UserConstants.COLLECTION, self.json())
開發者ID:rc65,項目名稱:stacs-hack-2016,代碼行數:2,代碼來源:user.py

示例14: initialize_database

def initialize_database():
	Database.initialize()
開發者ID:asimonia,項目名稱:web-blog,代碼行數:2,代碼來源:app.py

示例15: from_mongo

 def from_mongo(cls, id):
     post_data = Database.find_one(collection="posts", query={"_id": id})
     return cls(**post_data)
開發者ID:wmsgood,項目名稱:Mongoblog,代碼行數:3,代碼來源:post.py


注:本文中的common.database.Database類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。