Skip to content

Commit

Permalink
Install funcsigs only in versions less than 3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
helloqiu committed Aug 14, 2016
1 parent bf69b1e commit 97fc267
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions docs/changelog.rst
Expand Up @@ -22,6 +22,7 @@ Version 1.0.0
+ 将图文消息单个消息的渲染函数放到 :class:`werobot.replies.Article` 内
+ 取消对 Python2.6, Python3.3 的支持
+ 增加与 Django 1.6+, Flask, Bottle, Tornado 集成的支持
+ 替换 `inspect.getargspec()`

Version 0.6.1
----------------
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
@@ -1,4 +1,4 @@
bottle
requests
six
xmltodict
xmltodict
8 changes: 7 additions & 1 deletion setup.py
Expand Up @@ -3,13 +3,19 @@

import io
import werobot
import platform

from setuptools import setup, find_packages

with io.open("README.rst", encoding="utf8") as f:
readme = f.read().replace("develop", "master")
readme = readme.replace("latest", werobot.__version__)

version = platform.python_version_tuple()
install_requires = open("requirements.txt").readlines()
if version < ('3', '3'):
install_requires.append('funcsigs')

setup(
name='WeRoBot',
version=werobot.__version__,
Expand All @@ -23,7 +29,7 @@
setup_requires=[
'pytest-runner',
],
install_requires=open("requirements.txt").readlines(),
install_requires=install_requires,
include_package_data=True,
license='MIT License',
classifiers=[
Expand Down
12 changes: 8 additions & 4 deletions werobot/robot.py
Expand Up @@ -2,7 +2,6 @@
from __future__ import absolute_import, unicode_literals

import six
import inspect

import werobot

Expand All @@ -12,6 +11,11 @@
from werobot.replies import process_function_reply
from werobot.utils import to_binary, to_text, check_signature

try:
from inspect import signature
except ImportError:
from funcsigs import signature

__all__ = ['BaseRoBot', 'WeRoBot']

_DEFAULT_CONFIG = dict(
Expand Down Expand Up @@ -189,7 +193,7 @@ def key_click(self, key):
"""

def wraps(f):
argc = len(inspect.getargspec(f).args)
argc = len(signature(f).parameters.keys())

@self.click
def onclick(message, session=None):
Expand Down Expand Up @@ -234,7 +238,7 @@ def wraps(f):
for x in args:
self.filter(x)(f)
return f
argc = len(inspect.getargspec(f).args)
argc = len(signature(f).parameters.keys())

@self.text
def _f(message, session=None):
Expand All @@ -252,7 +256,7 @@ def add_handler(self, func, type='all'):
if not callable(func):
raise ValueError("{} is not callable".format(func))

self._handlers[type].append((func, len(inspect.getargspec(func).args)))
self._handlers[type].append((func, len(signature(func).parameters.keys())))

def get_handlers(self, type):
return self._handlers.get(type, []) + self._handlers['all']
Expand Down

0 comments on commit 97fc267

Please sign in to comment.