Skip to content

Commit 7bfa1c0

Browse files
authored
Merge pull request #170 from whtsky/config-docs
Config docs
2 parents 38204e8 + 7552d00 commit 7bfa1c0

File tree

5 files changed

+62
-3
lines changed

5 files changed

+62
-3
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ matrix:
1818
- PYTHON_VERSION=3.5
1919
- PYTHON_INSTALL_METHOD=macpython
2020
- osx_image: xcode7.3 # OS X 10.11
21-
- osx_image: xcode8.1 # macOS 10.12
21+
- osx_image: xcode8.2 # macOS 10.12
2222
allow_failures:
23-
- osx_image: xcode8.1
23+
- osx_image: xcode8.2
2424
cache:
2525
directories:
2626
- $HOME/.pyenv

docs/config.rst

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
``WeRoBot.Config``
2+
=====================
3+
4+
WeRoBot 使用 ``WeRoBot.Config`` 类来存储配置信息。 ``WeRoBot`` 类实例的 ``config`` 属性是一个 :class:`WeRobot.config.Config` 实例。
5+
6+
:class:`WeRobot.config.Config` 继承自 `dict` 。因此, 你可以像使用普通 dict 一样使用它 ::
7+
8+
from werobot import WeRoBot
9+
robot = WeRoBot(token='2333')
10+
11+
robot.config.update(
12+
HOST='0.0.0.0',
13+
PORT=80
14+
)
15+
16+
与普通 `dict` 不同的是, 你可以先把配置文件保存在一个对象或是文件中, 然后在 :class:`WeRoBot.config.Config` 中导入配置 ::
17+
18+
from werobot import WeRoBot
19+
robot = WeRoBot(token='2333')
20+
21+
class MyConfig(object):
22+
HOST = '0.0.0.0'
23+
PORT = 80
24+
25+
robot.config.from_object(MyConfig)
26+
robot.config.from_pyfile("config.py")
27+
28+
29+
默认配置
30+
----------
31+
32+
.. code:: python
33+
34+
dict(
35+
TOKEN=None,
36+
SERVER="auto",
37+
HOST="127.0.0.1",
38+
PORT="8888",
39+
SESSION_STORAGE=None,
40+
APP_ID=None,
41+
APP_SECRET=None,
42+
ENCODING_AES_KEY=None
43+
)
44+
45+
46+
API
47+
----------
48+
49+
.. module:: werobot.config
50+
.. autoclass:: Config
51+
:members:

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ WeRoBot 是一个微信公众号开发框架。
1515
events
1616
replies
1717
session
18+
config
1819
contrib
1920
error-page
2021
client

werobot/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class Config(dict):
2525
def from_pyfile(self, filename):
2626
"""
2727
在一个 Python 文件中读取配置。
28+
2829
:param filename: 配置文件的文件名。
2930
"""
3031
d = imp.new_module('config')
@@ -37,6 +38,7 @@ def from_pyfile(self, filename):
3738
def from_object(self, obj):
3839
"""
3940
在给定的 Python 对象中读取配置。
41+
4042
:param obj: 一个 Python 对象
4143
"""
4244
for key in dir(obj):

werobot/robot.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,14 @@
1919
__all__ = ['BaseRoBot', 'WeRoBot']
2020

2121
_DEFAULT_CONFIG = dict(
22+
TOKEN=None,
2223
SERVER="auto",
2324
HOST="127.0.0.1",
24-
PORT="8888"
25+
PORT="8888",
26+
SESSION_STORAGE=None,
27+
APP_ID=None,
28+
APP_SECRET=None,
29+
ENCODING_AES_KEY=None
2530
)
2631

2732

0 commit comments

Comments
 (0)