...
 
#!/usr/bin/python3
"""__init__.py - package definition module for DHParser
Copyright 2016 by Eckhart Arnold (arnold@badw.de)
......
......@@ -560,7 +560,7 @@ class Grammar:
Example for direct instantiation of a grammar::
>>> number = RE('\d+') + RE('\.') + RE('\d+') | RE('\d+')
>>> number = RE(r'\d+') + RE(r'\.') + RE(r'\d+') | RE(r'\d+')
>>> number_parser = Grammar(number)
>>> number_parser("3.1416").content
'3.1416'
......@@ -766,7 +766,7 @@ class Grammar:
class Grammar(Grammar):
...
symbol = RE('(?!\\d)\\w+')
symbol = RE(r'(?!\\d)\\w+')
After the call of this method symbol.pname == "symbol" holds.
Parser names starting or ending with a double underscore like
......@@ -1720,7 +1720,7 @@ class Series(NaryParser):
Example::
>>> variable_name = RegExp('(?!\d)\w') + RE('\w*')
>>> variable_name = RegExp(r'(?!\d)\w') + RE(r'\w*')
>>> Grammar(variable_name)('variable_1').content
'variable_1'
>>> str(Grammar(variable_name)('1_variable'))
......@@ -1852,12 +1852,12 @@ class Alternative(NaryParser):
are broken by selecting the first match.::
# the order of the sub-expression matters!
>>> number = RE('\d+') | RE('\d+') + RE('\.') + RE('\d+')
>>> number = RE(r'\d+') | RE(r'\d+') + RE(r'\.') + RE(r'\d+')
>>> str(Grammar(number)("3.1416"))
'3 <<< Error on ".141" | Parser stopped before end! trying to recover... >>> '
# the most selective expression should be put first:
>>> number = RE('\d+') + RE('\.') + RE('\d+') | RE('\d+')
>>> number = RE(r'\d+') + RE(r'\.') + RE(r'\d+') | RE(r'\d+')
>>> Grammar(number)("3.1416").content
'3.1416'
......
#!/usr/bin/python3
"""__init__.py - package definition module for DHParser/scrips
Copyright 2019 by Eckhart Arnold (arnold@badw.de)
......
......@@ -208,7 +208,11 @@ async def asyncio_connect(host: str = USE_DEFAULT_HOST, port: int = USE_DEFAULT_
reader, writer = None, None
while delay < retry_timeout:
try:
reader, writer = await asyncio.open_connection(host, port)
if sys.version_info >= (3, 8):
stream = await asyncio.connect(host, port)
reader, writer = stream, stream
else:
reader, writer = await asyncio.open_connection(host, port)
delay = retry_timeout
connected = True
except ConnectionRefusedError as error:
......@@ -299,7 +303,6 @@ class Server:
self.max_source_size = get_config_value('max_rpc_size') #type: int
# self.server_messages = Queue() # type: Queue
self.server_process = None # type: Optional[Process]
# shared variables
self.stage = Value('b', SERVER_OFFLINE) # type: Value
......@@ -309,6 +312,7 @@ class Server:
# if the server is run in a separate process, the following variables
# should only be accessed from the server process
self.server = None # type: Optional[asyncio.AbstractServer]
self.serving_task = None # type: Optional[asyncio.Task]
self.stop_response = '' # type: str
self.pp_executor = None # type: Optional[ProcessPoolExecutor]
self.tp_executor = None # type: Optional[ThreadPoolExecutor]
......@@ -635,11 +639,15 @@ class Server:
self.stage.value = SERVER_TERMINATE
if sys.version_info >= (3, 7):
await writer.wait_closed()
self.server.close() # break self.server.serve_forever()
self.serving_task.cancel()
else:
self.server.close() # break self.server.serve_forever()
if sys.version_info < (3, 7) and self.loop is not None:
self.loop.stop()
self.kill_switch = False # reset flag
async def connection_py38(self, stream: 'asyncio.Stream'):
await self.connection(stream, stream)
async def serve(self, host: str = USE_DEFAULT_HOST, port: int = USE_DEFAULT_PORT):
host, port = substitute_default_host_and_port(host, port)
......@@ -655,14 +663,18 @@ class Server:
self.port.value = port
self.loop = asyncio.get_running_loop() if sys.version_info >= (3, 7) \
else asyncio.get_event_loop()
self.server = cast(asyncio.base_events.Server,
await asyncio.start_server(self.connection, host, port))
if sys.version_info >= (3, 8):
self.server = asyncio.StreamServer(self.connection_py38, host, port)
else:
self.server = cast(asyncio.base_events.Server,
await asyncio.start_server(self.connection, host, port))
async with self.server:
self.stage.value = SERVER_ONLINE
# self.server_messages.put(SERVER_ONLINE)
await self.server.serve_forever()
self.serving_task = asyncio.create_task(self.server.serve_forever())
await self.serving_task
finally:
if self.server is not None:
if self.server is not None and sys.version_info < (3, 8):
await self.server.wait_closed()
if self.tp_executor is not None:
self.tp_executor.shutdown(wait=True)
......@@ -752,7 +764,7 @@ if len(path) < 20:
def run_server(host, port):
from DHParser.server import asyncio_run, Server, stop_server, has_server_stopped
stop_server(host, port, 1.0)
stop_server(host, port, 2.0)
server = Server({PARAMETERS})
server.run_server(host, port)
......
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100755 to 100644
#!/usr/bin/python
import os
def fix_permissions(path):
entries = os.listdir(path)
for entry in entries:
entry_path = os.path.join(path, entry)
if os.path.isdir(entry_path):
os.chmod(entry_path, 0o755)
fix_permissions(entry_path)
else:
with open(entry_path, 'rb') as f:
shebang = f.read(2)
if entry.endswith('.bat') or (not entry.endswith('.pyi') and shebang == b'#!'):
os.chmod(entry_path, 0o755)
else:
os.chmod(entry_path, 0o644)
if __name__ == "__main__":
cwd = os.getcwd()
while not os.getcwd().rstrip(r'\/').endswith('DHParser'):
os.chdir('..')
fix_permissions('.')
os.chdir(cwd)
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100755 to 100644
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755