11""":mod:`nirum.rpc`
22~~~~~~~~~~~~~~~~~~~
33
4+ .. deprecated:: 0.6.0
5+ This module and all it has provided are deprecated or obsolete. The most
6+ of them are now distributed as separated packages, or replaced by a newer
7+ concept.
8+
9+ It will be completely obsolete at version 0.7.0.
10+
411"""
5- import argparse
612import collections
713import json
814import typing
15+ import warnings
916
1017from six import integer_types , string_types
1118from six .moves import urllib
1219from werkzeug .exceptions import HTTPException
1320from werkzeug .http import HTTP_STATUS_CODES
1421from werkzeug .routing import Map , Rule
15- from werkzeug .serving import run_simple
1622from werkzeug .wrappers import Request as WsgiRequest , Response as WsgiResponse
1723
18- from .constructs import NameDict
1924from .deserialize import deserialize_meta
20- from .exc import (InvalidNirumServiceMethodNameError ,
21- InvalidNirumServiceMethodTypeError ,
22- NirumProcedureArgumentRequiredError ,
25+ from .exc import (NirumProcedureArgumentRequiredError ,
2326 NirumProcedureArgumentValueError ,
2427 UnexpectedNirumResponseError )
25- from .func import import_string , url_endswith_slash
28+ from .func import url_endswith_slash
2629from .serialize import serialize_meta
30+ from .service import Service as BaseService
2731
2832__all__ = 'Client' , 'WsgiApp' , 'Service' , 'client_type' , 'service_type'
2933JSONType = typing .Mapping [
3034 str , typing .Union [str , float , int , bool , object ]
3135]
3236
3337
34- class Service (object ):
35- """Nirum RPC service."""
38+ class Service (BaseService ):
39+ """Abstract base of Nirum services.
3640
37- __nirum_service_methods__ = {}
38- __nirum_method_names__ = NameDict ([])
41+ .. deprecated:: 0.6.0
42+ Use :class:`nirum.service.Service` instead.
43+ It will be completely obsolete at version 0.7.0.
3944
40- @staticmethod
41- def __nirum_method_error_types__ (k , d = None ):
42- return d
45+ """
4346
4447 def __init__ (self ):
45- for method_name in self .__nirum_service_methods__ :
46- try :
47- method = getattr (self , method_name )
48- except AttributeError :
49- raise InvalidNirumServiceMethodNameError (
50- "{0}.{1} inexist." .format (
51- typing ._type_repr (self .__class__ ), method_name
52- )
53- )
54- if not callable (method ):
55- raise InvalidNirumServiceMethodTypeError (
56- "{0}.{1} isn't callable" .format (
57- typing ._type_repr (self .__class__ ), method_name
58- )
59- )
48+ warnings .warn (
49+ 'nirum.rpc.Service is deprecated; use nirum.service.Service '
50+ 'instead. It will be completely obsolete at version 0.7.0.' ,
51+ DeprecationWarning
52+ )
53+ super (Service , self ).__init__ ()
6054
6155
6256class WsgiApp :
6357 """Create WSGI application adapt Nirum service.
6458
6559 :param service: A nirum service.
6660
61+ .. deprecated:: 0.6.0
62+ Use ``nirum_wsgi.WsgiApp`` (provided by `nirum-wsgi
63+ <https://github.com/spoqa/nirum-python-wsgi>`_ package) instead.
64+
65+ It will be completely obsolete at version 0.7.0.
66+
6767 """
6868
6969 #: (:class:`werkzeug.routing.Map`) url map
@@ -73,6 +73,12 @@ class WsgiApp:
7373 ])
7474
7575 def __init__ (self , service ):
76+ warnings .warn (
77+ 'nirum.rpc.WsgiApp is deprecated; use nirum_wsgi.WsgiApp '
78+ '(provided by nirum-wsgi package). It will be completely '
79+ 'obsolete at version 0.7.0.' ,
80+ DeprecationWarning
81+ )
7682 self .service = service
7783
7884 def __call__ (self , environ , start_response ):
@@ -323,8 +329,23 @@ def _raw_response(self, status_code, response_json, **kwargs):
323329
324330
325331class Client (object ):
332+ """HTTP service client base class.
333+
334+ .. deprecated:: 0.6.0
335+ Use :class:`nirum.transport.Transport` and
336+ :mod:`nirum_http.HttpTransport` (provided by `nirum-http
337+ <https://github.com/spoqa/nirum-python-http>` package) instead.
338+ It will be completely obsolete at version 0.7.0.
339+
340+ """
326341
327342 def __init__ (self , url , opener = urllib .request .build_opener ()):
343+ warnings .warn (
344+ 'nirum.rpc.Client is deprecated; use nirum.transport.Transport '
345+ 'and nirum_http.HttpTransport (provided by nirum-http package) '
346+ 'instead. It will be completely obsolete at version 0.7.0.' ,
347+ DeprecationWarning
348+ )
328349 self .url = url_endswith_slash (url )
329350 self .opener = opener
330351
@@ -431,21 +452,3 @@ def do_request(self, request_url, payload):
431452# with postfix named `_type`
432453service_type = Service
433454client_type = Client
434-
435-
436- def main ():
437- parser = argparse .ArgumentParser (description = 'Nirum service runner' )
438- parser .add_argument ('-H' , '--host' , help = 'the host to listen' ,
439- default = '0.0.0.0' )
440- parser .add_argument ('-p' , '--port' , help = 'the port number to listen' ,
441- type = int , default = 9322 )
442- parser .add_argument ('-d' , '--debug' , help = 'debug mode' ,
443- action = 'store_true' , default = False )
444- parser .add_argument ('service_impl' , help = 'service implementation name' )
445- args = parser .parse_args ()
446- service_impl = import_string (args .service_impl )
447- run_simple (
448- args .host , args .port , WsgiApp (service_impl ),
449- use_reloader = args .debug , use_debugger = args .debug ,
450- use_evalex = args .debug
451- )
0 commit comments