当前位置: 首页>>代码示例>>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;未经允许,请勿转载。