• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python config.get函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中trytond.config.config.get函数的典型用法代码示例。如果您正苦于以下问题:Python get函数的具体用法?Python get怎么用?Python get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: ldap_search_user

    def ldap_search_user(login, server, attrs=None):
        '''
        Return the result of a ldap search for the login using the ldap
        server.
        The attributes values defined in attrs will be return.
        '''
        _, dn, _, scope, filter_, extensions = parse_ldap_url(
            config.get(section, 'uri'))
        scope = {
            'base': ldap3.BASE,
            'onelevel': ldap3.LEVEL,
            'subtree': ldap3.SUBTREE,
            }[scope]
        uid = config.get(section, 'uid', default='uid')
        if filter_:
            filter_ = '(&(%s=%s)%s)' % (uid, login, filter_)
        else:
            filter_ = '(%s=%s)' % (uid, login)

        bindpass = None
        bindname, = extensions.get('bindname', [None])
        if not bindname:
            bindname, = extensions.get('!bindname', [None])
        if bindname:
            # XXX find better way to get the password
            bindpass = config.get(section, 'bind_pass')

        with ldap3.Connection(server, bindname, bindpass) as con:
            con.search(dn, filter_, search_scope=scope, attributes=attrs)
            result = con.entries
            if result and len(result) > 1:
                logger.info('ldap_search_user found more than 1 user')
            return [(e.entry_dn, e.entry_attributes_as_dict)
                for e in result]
开发者ID:coopengo,项目名称:ldap_authentication,代码行数:34,代码来源:res.py


示例2: send_magic_login_link

    def send_magic_login_link(cls, email):
        """
        Send a magic login email to the user
        """
        EmailQueue = Pool().get("email.queue")

        try:
            nereid_user, = cls.search([("email", "=", email.lower()), ("company", "=", current_website.company.id)])
        except ValueError:
            # This email was not found so, let user know about this
            message = "No user with email %s was found!" % email
            current_app.logger.debug(message)
        else:
            message = "Please check your mail and follow the link"
            email_message = render_email(
                config.get("email", "from"),
                email,
                _("Magic Signin Link"),
                text_template="emails/magic-login-text.jinja",
                html_template="emails/magic-login-html.jinja",
                nereid_user=nereid_user,
            )
            EmailQueue.queue_mail(config.get("email", "from"), email, email_message.as_string())

        return cls.build_response(message, redirect(url_for("nereid.website.home")), 200)
开发者ID:fulfilio,项目名称:nereid,代码行数:25,代码来源:user.py


示例3: ldap_search_user

    def ldap_search_user(login, con, attrs=None):
        '''
        Return the result of a ldap search for the login using the ldap
        connection con based on connection.
        The attributes values defined in attrs will be return.
        '''
        _, dn, _, scope, filter_, _ = parse_ldap_url(
            config.get(section, 'uri'))
        scope = {
            'base': ldap.SCOPE_BASE,
            'onelevel': ldap.SCOPE_ONELEVEL,
            'subtree': ldap.SCOPE_SUBTREE,
            }.get(scope)
        uid = config.get(section, 'uid', default='uid')
        if filter_:
            filter_ = '(&(%s=%s)%s)' % (uid, unicode2str(login), filter_)
        else:
            filter_ = '(%s=%s)' % (uid, unicode2str(login))

        result = con.search_s(dn, scope, filter_, attrs)
        if config.get(section, 'active_directory'):
            result = [x for x in result if x[0]]
        if result and len(result) > 1:
            logger.info('ldap_search_user found more than 1 user')
        return result
开发者ID:kret0s,项目名称:tryton3_8,代码行数:25,代码来源:res.py


示例4: create

    def create(cls, vlist):
        parties = super(Party, cls).create(vlist)

        #pool = Pool()
        #Badge = pool.get('access.control.badge')
        #Badge.isonas_badge_sync([], parties)

        isonas = Isonasacs(
            config.get('Isonas', 'host'), config.get('Isonas', 'port'))
        isonas.logon(
            config.get('Isonas', 'clientid'), config.get('Isonas', 'password'))
        groupname = config.get('Isonas', 'groupname')

        # need to check if parties have badges
        # partiestocreatebadges

        for party in parties:
            if party.badges:
                name = party.name.encode('ascii', 'replace')[:20]
                try:
                    isonas.add('IDFILE', name, '', '', party.code.encode('ascii'))
                    isonas.add('GROUPS', party.code.encode('ascii'), groupname.encode('ascii'))
                except IsonasacsError:
                    print 'Party Create IsonasacsError exception'
                    pass

        return parties
开发者ID:LavaLab,项目名称:trytonacs-party-access-control-isonas,代码行数:27,代码来源:party.py


示例5: get_s3_connection

 def get_s3_connection(self):
     """
     Returns an active S3 connection object
     """
     return connection.S3Connection(
         config.get('nereid_s3', 'access_key'),
         config.get('nereid_s3', 'secret_key')
     )
开发者ID:bhavana94,项目名称:trytond-nereid-s3,代码行数:8,代码来源:static_file.py


示例6: SSLSocket

def SSLSocket(socket):
    # Let the import error raise only when used
    import ssl
    return ssl.wrap_socket(socket,
        server_side=True,
        certfile=config.get('ssl', 'certificate'),
        keyfile=config.get('ssl', 'privatekey'),
        ssl_version=ssl.PROTOCOL_SSLv23)
开发者ID:kret0s,项目名称:gnuhealth-live,代码行数:8,代码来源:sslsocket.py


示例7: get_bucket

 def get_bucket(cls):
     '''
     Return an S3 bucket for the current instance
     '''
     s3_conn = S3Connection(
         config.get('attachment_s3', 'access_key'),
         config.get('attachment_s3', 'secret_key')
     )
     return s3_conn.get_bucket(config.get('attachment_s3', 'bucket_name'))
开发者ID:tarunbhardwaj,项目名称:trytond-attachment-s3,代码行数:9,代码来源:field.py


示例8: get_webdav_url

def get_webdav_url():
    if config.get('ssl', 'privatekey'):
        protocol = 'https'
    else:
        protocol = 'http'
    hostname = (config.get('webdav', 'hostname')
        or unicode(socket.getfqdn(), 'utf8'))
    hostname = '.'.join(encodings.idna.ToASCII(part) for part in
        hostname.split('.'))
    return urlparse.urlunsplit((protocol, hostname,
        urllib.quote(
            Transaction().cursor.database_name.encode('utf-8') + '/'),
            None, None))
开发者ID:kret0s,项目名称:gnuhealth-live,代码行数:13,代码来源:webdav.py


示例9: write

    def write(cls, *args):
        super(Badge, cls).write(*args)
        badges = sum(args[0:None:2], [])
        cls.isonas_badge_sync(badges, [])

        isonas = Isonasacs(
            config.get('Isonas', 'host'), config.get('Isonas', 'port'))
        isonas.logon(
            config.get('Isonas', 'clientid'), config.get('Isonas', 'password'))
        for badge in badges:
            if badge.disabled:
                isonas.update('BADGES', badge.code.encode('ascii'), 0, 0, '', '')
            else:
                isonas.update('BADGES', badge.code.encode('ascii'), 0, 0, 0, '')
开发者ID:LavaLab,项目名称:trytonacs-party-access-control-isonas,代码行数:14,代码来源:party.py


示例10: get_file_path

    def get_file_path(self, name):
        """
        Returns path for given static file

        :param static_file: Browse record of the static file
        """
        if self.folder.type != "s3":
            return super(NereidStaticFile, self).get_file_path(name)

        cloudfront = config.get("nereid_s3", "cloudfront")
        if cloudfront:
            return "/".join([cloudfront, self.s3_key])

        return "https://s3.amazonaws.com/%s/%s" % (config.get("nereid_s3", "bucket"), self.s3_key)
开发者ID:tarunbhardwaj,项目名称:trytond-nereid-s3,代码行数:14,代码来源:static_file.py


示例11: get_url

    def get_url(self, name):
        """
        Return the URL for the given static file

        :param name: Field name
        """
        if self.folder.type != "s3":
            return super(NereidStaticFile, self).get_url(name)

        cloudfront = config.get("nereid_s3", "cloudfront")
        if cloudfront:
            return "/".join([cloudfront, self.s3_key])

        return "https://s3.amazonaws.com/%s/%s" % (config.get("nereid_s3", "bucket"), self.s3_key)
开发者ID:tarunbhardwaj,项目名称:trytond-nereid-s3,代码行数:14,代码来源:static_file.py


示例12: get_login

 def get_login(cls, login, password):
     pool = Pool()
     LoginAttempt = pool.get('res.user.login.attempt')
     try:
         con = ldap_connection()
         if con:
             uid = config.get(section, 'uid', default='uid')
             users = cls.ldap_search_user(login, con, attrs=[uid])
             if users and len(users) == 1:
                 [(dn, attrs)] = users
                 if (password
                         and con.simple_bind_s(dn, unicode2str(password))):
                     # Use ldap uid so we always get the right case
                     login = attrs.get(uid, [login])[0]
                     user_id, _ = cls._get_login(login)
                     if user_id:
                         LoginAttempt.remove(login)
                         return user_id
                     elif config.getboolean(section, 'create_user'):
                         user, = cls.create([{
                                     'name': login,
                                     'login': login,
                                     }])
                         return user.id
     except ldap.LDAPError:
         logger.error('LDAPError when login', exc_info=True)
     return super(User, cls).get_login(login, password)
开发者ID:kret0s,项目名称:tryton3_8,代码行数:27,代码来源:res.py


示例13: convert

    def convert(cls, report, data):
        "converts the report data to another mimetype if necessary"
        input_format = report.template_extension
        output_format = report.extension or report.template_extension

        if output_format in MIMETYPES:
            return output_format, data

        fd, path = tempfile.mkstemp(suffix=(os.extsep + input_format),
            prefix='trytond_')
        oext = FORMAT2EXT.get(output_format, output_format)
        with os.fdopen(fd, 'wb+') as fp:
            fp.write(data)
        cmd = ['unoconv', '--no-launch', '--connection=%s' % config.get(
                'report', 'unoconv'), '-f', oext, '--stdout', path]
        logger = logging.getLogger(__name__)
        try:
            # JCA : Pipe stderr
            proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
                stderr=subprocess.PIPE, close_fds=True)
            stdoutdata, stderrdata = proc.communicate()
            # JCA : Use error code rather than wait twice
            if proc.returncode != 0:
                logger.info('unoconv.stdout : ' + stdoutdata)
                logger.error('unoconv.stderr : ' + stderrdata)
                raise Exception(stderrdata)
            else:
                logger.debug('unoconv.stdout : ' + stdoutdata)
                logger.debug('unoconv.stderr : ' + stderrdata)
            return oext, stdoutdata
        finally:
            os.remove(path)
开发者ID:coopengo,项目名称:trytond,代码行数:32,代码来源:report.py


示例14: __register__

    def __register__(cls, module_name):
        TableHandler = backend.get('TableHandler')
        cursor = Transaction().connection.cursor()
        pool = Pool()
        Line = pool.get('account.invoice.payment_term.line')
        sql_table = cls.__table__()
        line = Line.__table__()

        # Migration from 4.0: rename long table
        old_model_name = 'account.invoice.payment_term.line.relativedelta'
        old_table = config.get(
            'table', old_model_name, default=old_model_name.replace('.', '_'))
        if TableHandler.table_exist(old_table):
            TableHandler.table_rename(old_table, cls._table)

        super(PaymentTermLineRelativeDelta, cls).__register__(module_name)

        line_table = Line.__table_handler__(module_name)

        # Migration from 3.4
        fields = ['day', 'month', 'weekday', 'months', 'weeks', 'days']
        if any(line_table.column_exist(f) for f in fields):
            columns = ([line.id.as_('line')]
                + [Column(line, f) for f in fields])
            cursor.execute(*sql_table.insert(
                    columns=[sql_table.line]
                    + [Column(sql_table, f) for f in fields],
                    values=line.select(*columns)))
            for field in fields:
                line_table.drop_column(field)
开发者ID:coopengo,项目名称:account_invoice,代码行数:30,代码来源:payment_term.py


示例15: dump

    def dump(database_name):
        from trytond.tools import exec_command_pipe

        cmd = ['pg_dump', '--format=c', '--no-owner']
        env = {}
        uri = parse_uri(config.get('database', 'uri'))
        if uri.username:
            cmd.append('--username=' + uri.username)
        if uri.hostname:
            cmd.append('--host=' + uri.hostname)
        if uri.port:
            cmd.append('--port=' + str(uri.port))
        if uri.password:
            # if db_password is set in configuration we should pass
            # an environment variable PGPASSWORD to our subprocess
            # see libpg documentation
            env['PGPASSWORD'] = uri.password
        cmd.append(database_name)

        pipe = exec_command_pipe(*tuple(cmd), env=env)
        pipe.stdin.close()
        data = pipe.stdout.read()
        res = pipe.wait()
        if res:
            raise Exception('Couldn\'t dump database!')
        return data
开发者ID:kret0s,项目名称:tryton3_8,代码行数:26,代码来源:database.py


示例16: send_tryton_url

    def send_tryton_url(self, path):
        self.send_response(300)
        hostname = (config.get('jsonrpc', 'hostname')
            or unicode(socket.getfqdn(), 'utf8'))
        hostname = '.'.join(encodings.idna.ToASCII(part) for part in
            hostname.split('.'))
        values = {
            'hostname': hostname,
            'path': path,
            }
        content = BytesIO()

        def write(str_):
            content.write(str_.encode('utf-8'))
        write('<html')
        write('<head>')
        write('<meta http-equiv="Refresh" '
            'content="0;url=tryton://%(hostname)s%(path)s"/>' % values)
        write('<title>Moved</title>')
        write('</head>')
        write('<body>')
        write('<h1>Moved</h1>')
        write('<p>This page has moved to '
            '<a href="tryton://%(hostname)s%(path)s">'
            'tryton://%(hostname)s%(path)s</a>.</p>' % values)
        write('</body>')
        write('</html>')
        length = content.tell()
        content.seek(0)
        self.send_header('Location', 'tryton://%(hostname)s%(path)s' % values)
        self.send_header('Content-type', 'text/html')
        self.send_header('Content-Length', str(length))
        self.end_headers()
        self.copyfile(content, self.wfile)
        content.close()
开发者ID:kret0s,项目名称:tryton3_8,代码行数:35,代码来源:jsonrpc.py


示例17: _login_ldap

 def _login_ldap(cls, login, parameters):
     if 'password' not in parameters:
         msg = cls.fields_get(['password'])['password']['string']
         raise LoginException('password', msg, type='password')
     password = parameters['password']
     try:
         server = ldap_server()
         if server:
             uid = config.get(section, 'uid', default='uid')
             users = cls.ldap_search_user(login, server, attrs=[uid])
             if users and len(users) == 1:
                 [(dn, attrs)] = users
                 con = ldap3.Connection(server, dn, password)
                 if (password and con.bind()):
                     # Use ldap uid so we always get the right case
                     login = attrs.get(uid, [login])[0]
                     user_id = cls._get_login(login)[0]
                     if user_id:
                         return user_id
                     elif config.getboolean(section, 'create_user'):
                         user, = cls.create([{
                                     'name': login,
                                     'login': login,
                                     }])
                         return user.id
     except LDAPException:
         logger.error('LDAPError when login', exc_info=True)
开发者ID:coopengo,项目名称:ldap_authentication,代码行数:27,代码来源:res.py


示例18: cursor

 def cursor(self, autocommit=False, readonly=False):
     conv = MySQLdb.converters.conversions.copy()
     conv[float] = lambda value, _: repr(value)
     conv[MySQLdb.constants.FIELD_TYPE.TIME] = MySQLdb.times.Time_or_None
     args = {
         'db': self.database_name,
         'sql_mode': 'traditional,postgresql',
         'use_unicode': True,
         'charset': 'utf8',
         'conv': conv,
     }
     uri = parse_uri(config.get('database', 'uri'))
     assert uri.scheme == 'mysql'
     if uri.hostname:
         args['host'] = uri.hostname
     if uri.port:
         args['port'] = uri.port
     if uri.username:
         args['user'] = uri.username
     if uri.password:
         args['passwd'] = urllib.unquote_plus(uri.password)
     conn = MySQLdb.connect(**args)
     cursor = Cursor(conn, self.database_name)
     cursor.execute('SET time_zone = `UTC`')
     return cursor
开发者ID:kret0s,项目名称:tryton3_8,代码行数:25,代码来源:database.py


示例19: connect

 def connect(self):
     if self.name == ':memory:':
         path = ':memory:'
     else:
         db_filename = self.name + '.sqlite'
         path = os.path.join(config.get('database', 'path'), db_filename)
         if not os.path.isfile(path):
             raise IOError('Database "%s" doesn\'t exist!' % db_filename)
     if self._conn is not None:
         return self
     self._conn = sqlite.connect(path,
         detect_types=sqlite.PARSE_DECLTYPES | sqlite.PARSE_COLNAMES,
         factory=SQLiteConnection)
     self._conn.create_function('extract', 2, SQLiteExtract.extract)
     self._conn.create_function('date_trunc', 2, date_trunc)
     self._conn.create_function('split_part', 3, split_part)
     self._conn.create_function('position', 2, SQLitePosition.position)
     self._conn.create_function('overlay', 3, SQLiteOverlay.overlay)
     self._conn.create_function('overlay', 4, SQLiteOverlay.overlay)
     if sqlite.sqlite_version_info < (3, 3, 14):
         self._conn.create_function('replace', 3, replace)
     self._conn.create_function('now', 0, now)
     self._conn.create_function('sign', 1, sign)
     self._conn.create_function('greatest', -1, greatest)
     self._conn.create_function('least', -1, least)
     self._conn.execute('PRAGMA foreign_keys = ON')
     return self
开发者ID:coopengo,项目名称:trytond,代码行数:27,代码来源:database.py


示例20: setUp

 def setUp(self):
     super(LDAPAuthenticationTestCase, self).setUp()
     methods = config.get('session', 'authentications')
     config.set('session', 'authentications', 'ldap')
     self.addCleanup(config.set, 'session', 'authentications', methods)
     config.add_section(section)
     config.set(section, 'uri', 'ldap://localhost/dc=tryton,dc=org')
     self.addCleanup(config.remove_section, section)
开发者ID:coopengo,项目名称:ldap_authentication,代码行数:8,代码来源:test_ldap_authentication.py



注:本文中的trytond.config.config.get函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python config.set函数代码示例发布时间:2022-05-27
下一篇:
Python cache.Cache类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap