File tree Expand file tree Collapse file tree 6 files changed +30
-5
lines changed
Expand file tree Collapse file tree 6 files changed +30
-5
lines changed Original file line number Diff line number Diff line change 99from .buildin import Buildin
1010from .protocol import Proto , Protocol
1111from ..exceptions import NodeError , AuthError
12+ from ..util import strip_code
1213
1314
1415class Client (Buildin ):
@@ -324,7 +325,7 @@ def query(
324325 if scope is None :
325326 scope = self ._scope
326327
327- code = code . strip () # strip white space characters
328+ code = strip_code ( code )
328329 data = [scope , code ]
329330 if kwargs :
330331 data .append (kwargs )
@@ -581,7 +582,7 @@ def _on_event(self, pkg):
581582 if pkg .tp == Proto .ON_WARN :
582583 warn = pkg .data
583584 logging .warn (
584- f'Warning from ThingsDB: '
585+ f'ThingsDB: '
585586 f'{ warn ["warn_msg" ]} ({ warn ["warn_code" ]} )' )
586587 else :
587588 logging .warn (f'Unexpected event: tp:{ pkg .tp } data:{ pkg .data } ' )
Original file line number Diff line number Diff line change @@ -52,3 +52,10 @@ def on_delete(self) -> None:
5252 Called when the room is removed from ThingsDB.
5353 """
5454 pass
55+
56+ def on_emit (self , event , * args ):
57+ """On emit
58+ Called when no event handler is configured for the event.
59+ """
60+ logging .debug (f"No emit handler found for `{ event } `" )
61+ pass
Original file line number Diff line number Diff line change @@ -151,6 +151,10 @@ async def on_join(self) -> None:
151151 def on_leave (self ) -> None :
152152 pass
153153
154+ @abc .abstractmethod
155+ def on_emit (self , event : str , * args ) -> None :
156+ pass
157+
154158 async def _on_first_join (self ):
155159 fut = self ._wait_join
156160 self ._wait_join = None
@@ -184,8 +188,7 @@ def _emit_handler(self, data):
184188 try :
185189 fun = cls ._event_handlers [event ]
186190 except KeyError :
187- logging .debug (
188- f"No emit handler found for `{ event } ` on { cls .__name__ } " )
191+ self .on_emit (event , * data ['args' ])
189192 else :
190193 fun (self , * data ['args' ])
191194
Original file line number Diff line number Diff line change 11from .cnscope import cnscope
22from .access import Access
3+ from .cleancode import strip_code
Original file line number Diff line number Diff line change 1+ import re
2+
3+
4+ rbegin = re .compile (r'^\s*(\/\/.*)?\s*' )
5+
6+
7+ def strip_code (code : str ):
8+ """Strip white space and start comment from query code.
9+
10+ This function now removes only white space and the first line comment
11+ when starting with // from code.
12+ """
13+ return rbegin .sub ('' , code ).rstrip ()
Original file line number Diff line number Diff line change 1- __version__ = '1.0.1 '
1+ __version__ = '1.0.2 '
You can’t perform that action at this time.
0 commit comments