shanbay / sea Goto Github PK
View Code? Open in Web Editor NEWrpc framework built on grpc
Home Page: https://shanbay.github.io/sea/
License: MIT License
rpc framework built on grpc
Home Page: https://shanbay.github.io/sea/
License: MIT License
gRPC 官方的 Java 和 Go 版本,提供了接口,Python 没有提供接口。不知道 sea 有没有解决呢?
Hi,
Did you planned to translate the documentation in english ?
Regards,
Why the scopes of app
and cache
in test fixtures are not session
nor module
?
@pytest.fixture
def app():
return current_app
@pytest.fixture
def cache(app):
cache = app.extensions.cache
cache.clear()
yield cache
cache.clear()
Python grpc doesn't handle unicode inside an exception message #11442
因此 sea 的 RpcException 实现会导致出现非 ASCII 字符时产生错误, 同时客户端收到 Internal Server Error 错误.
class RpcException(Exception):
code = None
details = None
def __init__(self, message=None, *args, **kwargs):
if isinstance(message, (list, dict)):
message = json.dumps(
message, default=str, ensure_ascii=False)
if not isinstance(message, str):
message = str(message)
if message is not None:
self.details = message
super().__init__(message, *args, **kwargs)
另外我尝试使用 metadata 发送 Unicode 内容, 但同样是不行的.
因此如果需要传送 Unicode 内容时, 可以将 Unicode 字符串转义为 ASCII, 具体做法是使json.dumps
的 ensure_ascii=True
, 对于一般字符串, 可以调用json.encoder.py_encode_basestring_ascii
对Unicode字符串进行转义.
或者用 base64 之类的方法进行编码.
此类方法需要调用端做响应的配合, 加大了 client 和 server 的 耦合程度.
maybe use celery
request对象包含另一个对象的时候,msg2dict(request)
没有把子对象变成字典,得要再手动msg2dict一次。
目前sea server
会一直挂在命令行监听相关信息:
(rpc_demo) macbookdeMacBook-Air-2:helloworld HJ$ sea server
[2019-12-14 22:01:24,838 INFO in middleware] [2019-12-14T14:01:24.838320+00:00] HelloworldServicer.SayHello Called. Processed in 8.8e-05s
[2019-12-14 22:01:25,873 INFO in middleware] [2019-12-14T14:01:25.873557+00:00] HelloworldServicer.SayHello Called. Processed in 5.5e-05s
sea server -h
没有查看到对应信息Solution:
用 getattr(instance, instance__primary_key__)
替换
由于在本地测试时顺手将Redis扩展配置写为了REDIS_h
:
# Redis相关配置
REDIS_h = 'localhost'
REDIS_p = 6699
REDIS_d = 0
结果调试时发现sea的Config类在读取处理时并不会将它解析,看完Config.from_object
,Config.get_namespace
源码后发现在读取时加了if key.isupper():
这个判断。
虽然REDIS_h
大小写混合的写法并不规范,不过翻看了一遍sea的文档,似乎在配置项部分没有要求全部大写->sea项目配置
是否需要将文档更新,或者是在源码中取消if key.isupper():
这一判断?
目前仅在 ServiceLogMiddleware
中用到了…
而且这个库对 Windows 开发者不友好
假如觉得可行的话,我提个 PR?
based on pytest
Traceback (most recent call last):
File "d:\anaconda\envs\python3\lib\runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "d:\anaconda\envs\python3\lib\runpy.py", line 85, in run_code
exec(code, run_globals)
File "D:\anaconda\envs\python3\Scripts\sea.exe_main.py", line 9, in
File "d:\anaconda\envs\python3\lib\site-packages\sea\cli.py", line 113, in main
return _run(root)
File "d:\anaconda\envs\python3\lib\site-packages\sea\cli.py", line 100, in _run
return handler(**kwargs)
File "d:\anaconda\envs\python3\lib\site-packages\sea\cmds.py", line 126, in new
_gen_project(path, skip=_build_skip_files(extra), ctx=ctx)
File "d:\anaconda\envs\python3\lib\site-packages\sea\cmds.py", line 114, in _gen_project
tmpl = env.get_template(relfn)
File "d:\anaconda\envs\python3\lib\site-packages\jinja2\environment.py", line 830, in get_template
return self._load_template(name, self.make_globals(globals))
File "d:\anaconda\envs\python3\lib\site-packages\jinja2\environment.py", line 804, in _load_template
template = self.loader.load(self, name, globals)
File "d:\anaconda\envs\python3\lib\site-packages\jinja2\loaders.py", line 113, in load
source, filename, uptodate = self.get_source(environment, name)
File "d:\anaconda\envs\python3\lib\site-packages\jinja2\loaders.py", line 168, in get_source
pieces = split_template_path(template)
File "d:\anaconda\envs\python3\lib\site-packages\jinja2\loaders.py", line 31, in split_template_path
raise TemplateNotFound(template)
jinja2.exceptions.TemplateNotFound: app\extensions.py.tmpl
在python3.3 之后 __init__.py
文件对于一个module来说并不是必须的了。
https://www.python.org/dev/peps/pep-0420/
based on consul
运行pip install -r test-requirements.txt
有这么一句,
pytest-cov 2.7.1 has requirement coverage>=4.4, but you'll have coverage 4.3.4 which is incompatible.
然后安装了低版本pytest-cov解决了,是不是要在test-requirements.txt里改一下配置?
Line 12 in 552bb12
Dependabot couldn't authenticate with https://pypi.python.org/simple/.
You can provide authentication details in your Dependabot dashboard by clicking into the account menu (in the top right) and selecting 'Config variables'.
sea generate
这个命令前会create_app然后拿current_app.root_path。
但是有了代码但是没有生成protos/pb2.py
文件的时候,或者git merge的时候pb2文件有conflict(pb2.py文件里有了很多<<<<<,不是合法的Python代码了)。这时因为pb2文件有问题,app/servicers.py又import了它,sea g
这个命令就没办法执行了。
class ConstantsObject(ImmutableDict):
def __getattr__(self, name):
return self[name]
def __dir__(self):
return self.keys()
ImmutableDict
和 ConstantsObject
都没有重载 __setattr__
, 因此给一个 ConstantsObject
赋值将改变原来的值.
In[25]: c = ConstantsObject({'a':1})
In[26]: c.a
Out[26]: 1
In[27]: c.a = 2
In[28]: c.a
Out[28]: 2
默认的 fixture scope 为 function, 将其作为 test function 的参数每次都会生成一遍.
app, db 这两个 fixture 的数据应当是全局的, 尤其是 db , 每次以它为参数都会进行一次 migrate , 这是相当耗时的, 并且也没有这个必要.
相应文档见:
Scope: sharing a fixture instance across tests in a class, module or session
DAL built on SQLAlcemy
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.