当前位置: 首页>>代码示例>>Python>>正文


Python bbs.get_ini函数代码示例

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


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

示例1: get_sesame_menu_items

def get_sesame_menu_items(session):
    # there doesn't exist any documentation on how this works,
    # only the given examples in the generated default.ini file
    menu_items = []
    if ini.CFG.has_section('sesame'):
        for name in filter(lambda _name: '_' not in _name,
                           ini.CFG.options('sesame')):

            sesame_kwargs = {'name': name}

            door_cmd = ini.CFG.get('sesame', name).split(None, 1)[0]
            if door_cmd.lower() == 'no' or not os.path.exists(door_cmd):
                # skip entry if path does not resolve, or set to 'no'
                continue

            inp_key = get_ini(section='sesame', key='{0}_key'.format(name))
            if not inp_key:
                raise ValueError('sesame configuration for "{0}" requires '
                                 'complimenting value "{0}_key" for menu '
                                 'input key.'.format(name))

            if get_ini(section='sesame', key='{0}_sysop_only'.format(name),
                       getter='getboolean') and not session.user.is_sysop:
                continue

            text = get_ini(
                section='sesame', key='{0}_text'.format(name)
            ) or name

            menu_items.append(
                MenuItem(inp_key=inp_key, text=text, script='sesame',
                         args=(), kwargs=sesame_kwargs))

    return menu_items
开发者ID:NuSkooler,项目名称:x84,代码行数:34,代码来源:main.py

示例2: get_network_tag_description

def get_network_tag_description(term, colors):
    """ Return description text of message networks, if any. """
    server_tags = get_ini("msg", "server_tags", split=True)
    network_tags = get_ini("msg", "network_tags", split=True)

    if not (network_tags or server_tags):
        return u""
    return u"".join(
        (
            u"\r\n\r\n",
            colors["text"](u"This board participates in intra-bbs " "messaging, "),
            u"".join(
                (
                    colors["text"](u"hosting network messages by tag "),
                    u", ".join(quote(tag, colors) for tag in server_tags),
                )
            )
            if server_tags
            else u"",
            (colors["text"](u" and ") if (server_tags and network_tags) else u""),
            u"".join(
                (
                    colors["text"](u"participating in network messages by tag "),
                    u", ".join(quote(tag, colors) for tag in network_tags),
                )
            )
            if network_tags
            else u"",
            u".",
        )
    )
开发者ID:gofore,项目名称:x84,代码行数:31,代码来源:msgarea.py

示例3: translate_ttype

def translate_ttype(ttype):
    """
    Return preferred terminal type given the session-negotiation ttype.

    This provides a kind of coercion; we know some terminals, such as
    SyncTerm report a terminal type of 'ansi' -- however, the author
    publishes a termcap database for 'ansi-bbs' which he instructs
    should be used!  So an ``[system]`` configuration item
    of ``termcap-ansi`` may be set to ``'ansi-bbs'`` to coerce
    such terminals for Syncterm-centric telnet servers -- though I
    would not recommend it.

    Furthermore, if the ttype is (literally) 'unknown', then a
    system-wide default terminal type may be returned, also by
    ``[system]`` configuration option ``termcap-unknown``.
    """
    from x84.bbs import get_ini
    log = logging.getLogger(__name__)

    termcap_unknown = get_ini('system', 'termcap-unknown') or 'ansi'
    termcap_ansi = get_ini('system', 'termcap-ansi') or 'ansi'

    if termcap_unknown != 'no' and ttype == 'unknown':
        log.debug("terminal-type {0!r} => {1!r}"
                  .format(ttype, termcap_unknown))
        return termcap_unknown

    elif (termcap_ansi != 'no' and ttype.lower().startswith('ansi')
          and ttype != termcap_ansi):
        log.debug("terminal-type {0!r} => {1!r}"
                  .format(ttype, termcap_ansi))
        return termcap_ansi

    return ttype
开发者ID:adammendoza,项目名称:x84,代码行数:34,代码来源:terminal.py

示例4: allow_tag

def allow_tag(session, idx):
    """
    Whether user is allowed to tag a message.

    :rtype: bool

    A user can tag a message if the given session's user is:

    * the message author or recipient.
    * a member of sysop or moderator group.
    * a member of any existing tag-matching user group.
    """
    moderated = get_ini('msg', 'moderated_tags', getter='getboolean')
    tag_moderators = set(get_ini('msg', 'tag_moderators', split=True))
    if not moderated and 'sysop' in session.user.groups:
        return True

    elif moderated and (tag_moderators | session.user.groups):
        # tags are moderated, but user is one of the moderator groups
        return True

    msg = get_msg(idx)
    if session.user.handle in (msg.recipient, msg.author):
        return True

    for tag in msg.tags:
        if tag in session.user.groups:
            return True
    return False
开发者ID:rostob,项目名称:x84,代码行数:29,代码来源:msgarea.py

示例5: view_leaf_msgnet

def view_leaf_msgnet(server_tag=None, board_id=None):
    if server_tag is None:
        server_tags = get_ini(section="msg", key="server_tags", split=True)
        if not server_tags:
            raise ValueError("no `server_tags' defined in ini file, " "section [msg].")
        # RECURSION
        for _st in server_tags:
            view_leaf_msgnet(server_tag=_st, board_id=None)
        return

    if board_id is None:
        board_ids = DBProxy("{0}keys".format(server_tag)).keys()
        for _bid in board_ids:
            # RECURSION
            view_leaf_msgnet(server_tag=server_tag, board_id=_bid)
        return

    with DBProxy("{0}keys".format(server_tag)) as key_db:
        echo(u"\r\n[msgnet_{0}]".format(server_tag))
        echo(u"\r\nurl_base = https://{addr}:{port}/".format(addr=get_ini("web", "addr"), port=get_ini("web", "port")))
        echo(u"\r\nboard_id = {0}".format(board_id))
        echo(u"\r\ntoken = {0}".format(key_db[board_id]))
        echo(u"\r\npoll_interval = 300")
        echo(u"\r\n")
        echo(u"\r\n[msg]")
        echo(u"\r\nnetwork_tags = {0}".format(server_tag))
    echo(u"\r\n")
    echo(u"-" * 40)
开发者ID:gofore,项目名称:x84,代码行数:28,代码来源:sysop.py

示例6: server

def server(urls, funcs):
    """ Main server thread for running the web server """
    from x84.bbs import get_ini
    from web.wsgiserver import CherryPyWSGIServer
    from web.wsgiserver.ssl_pyopenssl import pyOpenSSLAdapter

    log = logging.getLogger(__name__)

    addr = get_ini(section='web',
                   key='addr'
                   ) or '0.0.0.0'

    port = get_ini(section='web',
                   key='port',
                   getter='getint'
                   ) or 8443

    app = web.application(urls, funcs)

    web.config.debug = False

    log.info('https listening on {addr}:{port}/tcp'
             .format(addr=addr, port=port))

    # Runs CherryPy WSGI server hosting WSGI app.wsgifunc().
    web.httpserver.runsimple(app.wsgifunc(), (addr, port))  # blocking
开发者ID:gofore,项目名称:x84,代码行数:26,代码来源:webserve.py

示例7: prompt_tags

def prompt_tags(session, term, msg, colors, public=True):
    xpos = max(0, (term.width // 2) - (80 // 2))

    # conditionally enforce tag moderation
    moderated = get_ini("msg", "moderated_tags", getter="getboolean")
    tag_moderators = set(get_ini("msg", "tag_moderators", split=True))

    # enforce 'public' tag
    if public and "public" not in msg.tags:
        msg.tags.add("public")
    elif not public and "public" in msg.tags:
        msg.tags.remove("public")

    # describe all available tags, as we oft want to do.
    do_describe_available_tags(term, colors)

    # and remind ourselves of the available network tags,
    description = get_network_tag_description(term, colors)
    if description:
        show_description(term=term, color=None, description=description)

    echo(
        u"".join(
            (term.move_x(xpos), term.clear_eos, u"Enter tags, separated by commas.\r\n", term.move_x(xpos), u":: ")
        )
    )

    all_tags = list_tags()

    while True:
        inp = LineEditor(
            subject_max_length, u", ".join(sorted(msg.tags)), colors={"highlight": colors["backlight"]}
        ).read()
        if inp is None:
            echo(u"".join((term.move_x(xpos), colors["highlight"]("Message canceled."), term.clear_eol)))
            term.inkey(1)
            return False

        msg.tags = set(filter(None, set(map(unicode.strip, inp.split(",")))))
        if moderated and not (tag_moderators | session.user.groups):
            cannot_tag = [_tag for _tag in msg.tags if _tag not in all_tags]
            if cannot_tag:
                echo(
                    u"".join(
                        (
                            u"\r\n",
                            term.move_x(xpos),
                            u", ".join((quote(tag, colors) for tag in cannot_tag)),
                            u": not allowed; this system is moderated.",
                        )
                    )
                )
                term.inkey(2)
                echo(term.move_up)
                map(msg.tags.remove, cannot_tag)
                continue

        return True
开发者ID:gofore,项目名称:x84,代码行数:58,代码来源:msgarea.py

示例8: check_new_user

def check_new_user(username):
    """ Boolean return when username matches `newcmds' ini cfg. """
    from x84.bbs import get_ini
    matching = get_ini(section='matrix',
                       key='newcmds',
                       split=True)
    allowed = get_ini(section='nua',
                      key='allow_apply',
                      getter='getboolean')
    return allowed and username in matching
开发者ID:hick,项目名称:x84,代码行数:10,代码来源:userbase.py

示例9: main

def main():
    """
    x84 main entry point. The system begins and ends here.

    Command line arguments to engine.py:
      --config= location of alternate configuration file
      --logger= location of alternate logging.ini file
    """
    import x84.bbs.ini

    # load existing .ini files or create default ones.
    x84.bbs.ini.init(*parse_args())
    from x84.bbs import get_ini
    from x84.bbs.ini import CFG

    if sys.maxunicode == 65535:
        import warnings
        warnings.warn('Python not built with wide unicode support!')

    # retrieve list of managed servers
    servers = get_servers(CFG)

    # begin unmanaged servers
    if get_ini(section='web', key='modules'):
        # start https server for one or more web modules.
        #
        # may raise an ImportError for systems where pyOpenSSL and etc. could
        # not be installed (due to any issues with missing python-dev, libffi,
        # cc, etc.).  Allow it to raise naturally, the curious user should
        # either discover and resolve the root issue, or disable web modules if
        # it cannot be resolved.
        from x84 import webserve
        webserve.main()

    if get_ini(section='msg', key='network_tags'):
        # start background timer to poll for new messages
        # of message networks we may be a member of.
        from x84 import msgpoll
        msgpoll.main()

    try:
        # begin main event loop
        _loop(servers)
    except KeyboardInterrupt:
        # exit on ^C, killing any client sessions.
        from x84.terminal import kill_session
        for server in servers:
            for idx, thread in enumerate(server.threads[:]):
                if not thread.stopped:
                    thread.stopped = True
                server.threads.remove(thread)
            for key, client in server.clients.items()[:]:
                kill_session(client, 'server shutdown')
                del server.clients[key]
开发者ID:hick,项目名称:x84,代码行数:54,代码来源:engine.py

示例10: check_anonymous_user

def check_anonymous_user(username):
    """ Boolean return when user is anonymous and is allowed. """
    from x84.bbs import get_ini
    matching = get_ini(section='matrix',
                       key='anoncmds',
                       split=True)
    allowed = get_ini(section='matrix',
                      key='enable_anonymous',
                      getter='getboolean',
                      split=False)
    return allowed and username in matching
开发者ID:hick,项目名称:x84,代码行数:11,代码来源:userbase.py

示例11: get_networks

def get_networks():
    " Get configured message networks. "
    from x84.bbs import get_ini

    log = logging.getLogger(__name__)

    # pull list of network-associated tags
    network_list = get_ini(section='msg',
                           key='network_tags',
                           split=True,
                           splitsep=',')

    # expected configuration options,
    net_options = ('url_base token board_id'.split())

    networks = list()
    for net_name in network_list:
        net = {'name': net_name}

        section = 'msgnet_{0}'.format(net_name)
        configured = True
        for option in net_options:
            if not get_ini(section=section, key=option):
                log.error('[{net_name}] Missing configuration, '
                          'section=[{section}], option={option}.'
                          .format(net_name=net_name,
                                  section=section,
                                  option=option))
                configured = False
            net[option] = get_ini(section=section, key=option)
        if not configured:
            continue

        # make last_file an absolute path, relative to `datapath`
        net['last_file'] = os.path.join(
            os.path.expanduser(get_ini(section='system', key='datapath')),
            '{net[name]}_last'.format(net=net))

        net['verify'] = True
        ca_path = get_ini(section=section, key='ca_path')
        if ca_path:
            ca_path = os.path.expanduser(ca_path)
            if not os.path.isfile(ca_path):
                log.warn("File not found for Config section [{section}], "
                         "option {key}, value={ca_path}.  default ca_verify "
                         "will be used. ".format(section=section,
                                                 key='ca_path',
                                                 value=ca_path))
            else:
                net['verify'] = ca_path

        networks.append(net)
    return networks
开发者ID:hick,项目名称:x84,代码行数:53,代码来源:msgpoll.py

示例12: __init__

 def __init__(self, client, sid, master_pipes):
     """ Class constructor. """
     from x84.bbs import get_ini
     self.client = client
     self.sid = sid
     (self.master_write, self.master_read) = master_pipes
     self.timeout = get_ini('system', 'timeout') or 0
开发者ID:adammendoza,项目名称:x84,代码行数:7,代码来源:terminal.py

示例13: main

def main(background_daemon=True):
    """
    Entry point to configure and begin network message polling.

    Called by x84/engine.py, function main() as unmanaged thread.

    :param background_daemon: When True (default), this function returns and
      web modules are served in an unmanaged, background (daemon) thread.
      Otherwise, function call to ``main()`` is blocking.
    :type background_daemon: bool
    :rtype: None
    """
    from threading import Thread
    from x84.bbs import get_ini

    log = logging.getLogger(__name__)

    poll_interval = get_ini(section='msg',
                            key='poll_interval',
                            getter='getint'
                            ) or 1984

    if background_daemon:
        t = Thread(target=poller, args=(poll_interval,))
        t.daemon = True
        log.info('msgpoll at {0}s intervals.'.format(poll_interval))
        t.start()
    else:
        poller(poll_interval)
开发者ID:hick,项目名称:x84,代码行数:29,代码来源:msgpoll.py

示例14: init_term

def init_term(writer, env):
    """
    Determine the final TERM and encoding and return a Terminal.

    curses is initialized using the value of 'TERM' of dictionary env,
    as well as a starting window size of 'LINES' and 'COLUMNS'. If the
    terminal-type is of 'ansi' or 'ansi-bbs', then the cp437 encoding
    is assumed; otherwise 'utf8'.

    A blessed-abstracted curses terminal is returned.
    """
    from x84.bbs.ipc import IPCStream
    from x84.bbs import get_ini
    log = logging.getLogger(__name__)
    env['TERM'] = translate_ttype(env.get('TERM', 'unknown'))
    env['encoding'] = determine_encoding(env)
    term = Terminal(kind=env['TERM'],
                    stream=IPCStream(writer=writer),
                    rows=int(env.get('LINES', '24')),
                    columns=int(env.get('COLUMNS', '80')))

    if term.kind is None:
        # the given environment's TERM failed curses initialization
        # because, more than likely, the TERM type was not found.
        termcap_unknown = get_ini('system', 'termcap-unknown') or 'ansi'
        log.debug('terminal-type {0} failed, using {1} instead.'
                  .format(env['TERM'], termcap_unknown))
        term = Terminal(kind=termcap_unknown,
                        stream=IPCStream(writer=writer),
                        rows=int(env.get('LINES', '24')),
                        columns=int(env.get('COLUMNS', '80')))

    log.info("terminal type is {0!r}".format(term.kind))
    return term
开发者ID:adammendoza,项目名称:x84,代码行数:34,代码来源:terminal.py

示例15: add_leaf_msgnet

def add_leaf_msgnet():
    import cryptography.fernet

    server_tags = get_ini(section="msg", key="server_tags", split=True)
    if not server_tags:
        raise ValueError(MSG_NO_SERVER_TAGS)

    if len(server_tags) == 1:
        server_tag = server_tags[0]
    else:
        while True:
            echo("chose a server tag: ")
            idx = 0
            for idx, tag in server_tags:
                echo(u"\r\n{0}. {1}".format(idx, tag))
            echo(u"\r\n: ")
            inp = LineEditor(width=len(str(idx)).read())
            if inp is None:
                return
            try:
                server_tag = server_tags[int(inp)]
                break
            except ValueError:
                pass

    with DBProxy("{0}keys".format(server_tag)) as key_db:
        board_id = max(map(int, key_db.keys()) or [-1]) + 1
        client_key = cryptography.fernet.Fernet.generate_key()
        key_db[board_id] = client_key
    echo(u"\r\n")
    echo(u"-" * 40)
    view_leaf_msgnet(server_tag, board_id)
开发者ID:gofore,项目名称:x84,代码行数:32,代码来源:sysop.py


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