513 lines
21 KiB
Plaintext
513 lines
21 KiB
Plaintext
|
|
{
|
||
|
|
"cells": [
|
||
|
|
{
|
||
|
|
"cell_type": "code",
|
||
|
|
"execution_count": null,
|
||
|
|
"metadata": {},
|
||
|
|
"outputs": [],
|
||
|
|
"source": [
|
||
|
|
"async def readBinaryRecord(reader):\n",
|
||
|
|
" print(\"begin of readBinaryRecord().\")\n",
|
||
|
|
" Type = await reader.readexactly(1)\n",
|
||
|
|
" Type = int.from_bytes(Type, byteorder='big', signed=False)\n",
|
||
|
|
" print(\"first byte read in readBinaryRecord()\")\n",
|
||
|
|
" print(Type)\n",
|
||
|
|
" \n",
|
||
|
|
" Type_dict = {\"BIN_LONGLIST\": 0,\n",
|
||
|
|
" \"BIN_INTEGER\": 1,\n",
|
||
|
|
" \"BIN_REAL\": 2,\n",
|
||
|
|
" \"BIN_BOOLEAN\": 3,\n",
|
||
|
|
" \"BIN_LONGSTRING\": 4,\n",
|
||
|
|
" \"BIN_LONGSYMBOL\": 5,\n",
|
||
|
|
" \"BIN_LONGTEXT\": 6,\n",
|
||
|
|
" \"BIN_LIST\": 10,\n",
|
||
|
|
" \"BIN_SHORTLIST\": 11,\n",
|
||
|
|
" \"BIN_SHORTINT\": 12,\n",
|
||
|
|
" \"BIN_BYTE\":13,\n",
|
||
|
|
" \"BIN_STRING\": 14,\n",
|
||
|
|
" \"BIN_SHORTSTRING\": 15,\n",
|
||
|
|
" \"BIN_SYMBOL\": 16,\n",
|
||
|
|
" \"BIN_SHORTSYMBOL\": 17,\n",
|
||
|
|
" \"BIN_TEXT\": 18,\n",
|
||
|
|
" \"BIN_SHORTTEXT\": 19,\n",
|
||
|
|
" \"BIN_DOUBLE\": 20}\n",
|
||
|
|
" typeCode = None\n",
|
||
|
|
" for typ, val in Type_dict.items():\n",
|
||
|
|
" if val == Type:\n",
|
||
|
|
" typeCode = val\n",
|
||
|
|
" break\n",
|
||
|
|
" \n",
|
||
|
|
" if typeCode == 0: #LongList\n",
|
||
|
|
" print(\"LongList\")\n",
|
||
|
|
" LE = []\n",
|
||
|
|
" barray = bytearray(4) ####readInt()\n",
|
||
|
|
" barray = await reader.readexactly(4)\n",
|
||
|
|
" print(barray)\n",
|
||
|
|
" assert (int.from_bytes(barray, byteorder = 'big', signed = True)) >= 0, \"Invalid Integer-Byte read from Stream!\"\n",
|
||
|
|
" r = unpack('>I',barray)[0]\n",
|
||
|
|
" ####\n",
|
||
|
|
" if r == 0:\n",
|
||
|
|
" return LE\n",
|
||
|
|
" else:\n",
|
||
|
|
" for i in range(r):\n",
|
||
|
|
" LE.append(await readBinaryRecord())\n",
|
||
|
|
" return LE\n",
|
||
|
|
" \n",
|
||
|
|
" elif typeCode == 1:\n",
|
||
|
|
" ####readInt()\n",
|
||
|
|
" \n",
|
||
|
|
" print(\"Int\")\n",
|
||
|
|
" barray = bytearray(4)\n",
|
||
|
|
" barray = await reader.readexactly(4)\n",
|
||
|
|
" print(barray)\n",
|
||
|
|
" assert (int.from_bytes(barray, byteorder = 'big', signed = True)) >= 0, \"Invalid Integer-Byte read from Stream!\"\n",
|
||
|
|
" r = unpack('>I',barray)[0]\n",
|
||
|
|
" ####\n",
|
||
|
|
" print(\"int: \")\n",
|
||
|
|
" print(r)\n",
|
||
|
|
" return r \n",
|
||
|
|
" \n",
|
||
|
|
" elif typeCode == 2:\n",
|
||
|
|
" ####readReal()\n",
|
||
|
|
" print(\"Real\")\n",
|
||
|
|
" barray = bytearray(4)\n",
|
||
|
|
" barray = await reader.readexactly(4)\n",
|
||
|
|
" print(barray)\n",
|
||
|
|
" assert (int.from_bytes(barray, order = 'big', signed = True)) >= 0, \"Invalid Real-Byte read from Stream!\"\n",
|
||
|
|
" r = unpack('>f',barray)[0]\n",
|
||
|
|
" ####\n",
|
||
|
|
" print(\"real: \")\n",
|
||
|
|
" print(r)\n",
|
||
|
|
" return r \n",
|
||
|
|
" \n",
|
||
|
|
" elif typeCode == 3:\n",
|
||
|
|
" ####readBool()\n",
|
||
|
|
" print(\"Bool\")\n",
|
||
|
|
" barray = bytearray(1)\n",
|
||
|
|
" barray = await reader.readexactly(1)\n",
|
||
|
|
" print(barray)\n",
|
||
|
|
" assert (int.from_bytes(barray, order = 'big', signed = True)) >= 0, \"Invalid Boolean-Byte read from Stream!\"\n",
|
||
|
|
" r = unpack('?',barray)[0]\n",
|
||
|
|
" ####\n",
|
||
|
|
" print(\"bool: \")\n",
|
||
|
|
" print(r)\n",
|
||
|
|
" return r\n",
|
||
|
|
" \n",
|
||
|
|
" \n",
|
||
|
|
" elif typeCode == 4:\n",
|
||
|
|
" ####readLongString()\n",
|
||
|
|
" print(\"LongString\")\n",
|
||
|
|
" barray = bytearray(4) #readInt()\n",
|
||
|
|
" barray = await reader.readexactly(4)\n",
|
||
|
|
" print(barray)\n",
|
||
|
|
" for b in barray:\n",
|
||
|
|
" assert (int.from_bytes(b, order = 'big', signed = True)) >= 0, \"Invalid Int-Byte read from Stream!\"\n",
|
||
|
|
" len = unpack('>I',barray)[0]\n",
|
||
|
|
" barray = bytearray(len)\n",
|
||
|
|
" barray = await reader.readexactly(len)\n",
|
||
|
|
" print(barray)\n",
|
||
|
|
" #for b in barray:\n",
|
||
|
|
" #assert (int.from_bytes(b, order = 'big', signed = True)) >= 0, \"Invalid LongSymbol-Byte read from Stream!\"\n",
|
||
|
|
" ###checking Environment.ENCODING not considered yet\n",
|
||
|
|
" print(\"long string: \")\n",
|
||
|
|
" print(barray.decode())\n",
|
||
|
|
" return '\"' + barray.decode() + '\"'\n",
|
||
|
|
" \n",
|
||
|
|
" elif typeCode == 5:\n",
|
||
|
|
" ####readLongSymbol()\n",
|
||
|
|
" print(\"LongSymbol\")\n",
|
||
|
|
" barray = bytearray(4) #readInt()\n",
|
||
|
|
" barray = await reader.readexactly(4)\n",
|
||
|
|
" print(barray)\n",
|
||
|
|
" for b in barray:\n",
|
||
|
|
" assert (int.from_bytes(b, order = 'big', signed = True)) >= 0, \"Invalid Int-Byte read from Stream!\"\n",
|
||
|
|
" len = unpack('>I',barray)[0]\n",
|
||
|
|
" barray = bytearray(len)\n",
|
||
|
|
" barray = await reader.readexactly(len)\n",
|
||
|
|
" print(barray)\n",
|
||
|
|
" #for b in barray:\n",
|
||
|
|
" #assert (int.from_bytes(b, order = 'big', signed = True)) >= 0, \"Invalid LongSymbol-Byte read from Stream!\"\n",
|
||
|
|
" ###checking Environment.ENCODING not considered yet\n",
|
||
|
|
" print(\"long symbol: \")\n",
|
||
|
|
" print(barray.decode())\n",
|
||
|
|
" return barray.decode()\n",
|
||
|
|
" \n",
|
||
|
|
" elif typeCode == 6:\n",
|
||
|
|
" ####readLongText()\n",
|
||
|
|
" print(\"LongText\")\n",
|
||
|
|
" barray = bytearray(4) #readInt()\n",
|
||
|
|
" barray = await reader.readexactly(4)\n",
|
||
|
|
" print(barray)\n",
|
||
|
|
" for b in barray:\n",
|
||
|
|
" assert (int.from_bytes(b, order = 'big', signed = True)) >= 0, \"Invalid Int-Byte read from Stream!\"\n",
|
||
|
|
" len = unpack('>I',barray)[0]\n",
|
||
|
|
" barray = bytearray(len)\n",
|
||
|
|
" barray = await reader.readexactly(len)\n",
|
||
|
|
" print(barray)\n",
|
||
|
|
" #for b in barray:\n",
|
||
|
|
" #assert (int.from_bytes(b, order = 'big', signed = True)) >= 0, \"Invalid LongText-Byte read from Stream!\"\n",
|
||
|
|
" ###checking Environment.ENCODING not considered yet\n",
|
||
|
|
" print(\"Long Text: \")\n",
|
||
|
|
" txt = barray.decode()\n",
|
||
|
|
" if not txt.startswith('<text>'):\n",
|
||
|
|
" txt = '\"<text>' + txt + '</text--->\"'\n",
|
||
|
|
" \n",
|
||
|
|
" print(txt)\n",
|
||
|
|
" return txt\n",
|
||
|
|
" \n",
|
||
|
|
" elif typeCode == 10: #List\n",
|
||
|
|
" print(\"List\")\n",
|
||
|
|
" LE = []\n",
|
||
|
|
" ####readShort()\n",
|
||
|
|
" barray = bytearray(2)\n",
|
||
|
|
" barray = await reader.readexactly(2)\n",
|
||
|
|
" print(barray)\n",
|
||
|
|
" for b in barray:\n",
|
||
|
|
" assert (int.from_bytes(b, order = 'big', signed = True)) >= 0, \"Invalid ShortInt-Byte read from Stream!\"\n",
|
||
|
|
" r = unpack('>H',barray)[0]\n",
|
||
|
|
" ####\n",
|
||
|
|
" if r == 0:\n",
|
||
|
|
" return LE\n",
|
||
|
|
" else:\n",
|
||
|
|
" for i in range(r):\n",
|
||
|
|
" LE.append(await readBinaryRecord())\n",
|
||
|
|
" return LE\n",
|
||
|
|
" \n",
|
||
|
|
" elif typeCode == 11: #ShortList\n",
|
||
|
|
" print(\"ShortList\")\n",
|
||
|
|
" LE = []\n",
|
||
|
|
" ####readByte()\n",
|
||
|
|
" barray = bytearray(1)\n",
|
||
|
|
" barray = await reader.readexactly(1)\n",
|
||
|
|
" print(barray)\n",
|
||
|
|
" assert (int.from_bytes(barray, byteorder = 'big', signed = True)) >= 0, \"Invalid Byte read from Stream!\"\n",
|
||
|
|
" r = int.from_bytes(barray, byteorder = 'big', signed = False)\n",
|
||
|
|
" ####\n",
|
||
|
|
" if r == 0:\n",
|
||
|
|
" return LE\n",
|
||
|
|
" else:\n",
|
||
|
|
" for i in range(r):\n",
|
||
|
|
" LE.append(await readBinaryRecord())\n",
|
||
|
|
" return LE\n",
|
||
|
|
" \n",
|
||
|
|
" elif typeCode == 12:\n",
|
||
|
|
" ####readShort()\n",
|
||
|
|
" print(\"readShort\")\n",
|
||
|
|
" barray = bytearray(2)\n",
|
||
|
|
" barray = await reader.readexactly(2)\n",
|
||
|
|
" print(barray)\n",
|
||
|
|
" #for b in barray:\n",
|
||
|
|
" #assert (int.from_bytes(b, byteorder = 'big', signed = True)) >= 0, \"Invalid ShortInt-Byte read from Stream!\"\n",
|
||
|
|
" r = unpack('>H',barray)[0]\n",
|
||
|
|
" print(\"short: \")\n",
|
||
|
|
" print(r)\n",
|
||
|
|
" return r\n",
|
||
|
|
" \n",
|
||
|
|
" elif typeCode == 13:\n",
|
||
|
|
" ####readByte()\n",
|
||
|
|
" print(\"Byte\")\n",
|
||
|
|
" barray = bytearray(1)\n",
|
||
|
|
" barray = await reader.readexactly(1)\n",
|
||
|
|
" print(barray)\n",
|
||
|
|
" #assert (int.from_bytes(barray, byteorder = 'big', signed = True)) >= 0, \"Invalid Byte read from Stream!\"\n",
|
||
|
|
" r = int.from_bytes(barray, byteorder = 'big', signed = True)\n",
|
||
|
|
" print(\"byte: \")\n",
|
||
|
|
" print(r)\n",
|
||
|
|
" return r\n",
|
||
|
|
" \n",
|
||
|
|
" elif typeCode == 14:\n",
|
||
|
|
" ####readString()\n",
|
||
|
|
" print(\"String\")\n",
|
||
|
|
" barray = bytearray(2)\n",
|
||
|
|
" barray = await reader.readexactly(2)\n",
|
||
|
|
" print(barray)\n",
|
||
|
|
" for b in barray:\n",
|
||
|
|
" assert (int.from_bytes(b, byteorder = 'big', signed = True)) >= 0, \"Invalid ShortInt-Byte read from Stream!\"\n",
|
||
|
|
" len = unpack('>H',barray)[0]\n",
|
||
|
|
" barray = bytearray(len)\n",
|
||
|
|
" barray = await reader.readexactly(len)\n",
|
||
|
|
" print(barray)\n",
|
||
|
|
" #for b in barray:\n",
|
||
|
|
" #assert (int.from_bytes(b, byteorder = 'big', signed = True)) >= 0, \"Invalid String-Byte read from Stream!\"\n",
|
||
|
|
" ###checking Environment.ENCODING not considered yet\n",
|
||
|
|
" print(\"string: \")\n",
|
||
|
|
" print(barray.decode())\n",
|
||
|
|
" return '\"' + barray.decode() + '\"'\n",
|
||
|
|
" \n",
|
||
|
|
" elif typeCode == 15:\n",
|
||
|
|
" ####readShortString()\n",
|
||
|
|
" print(\"ShortString\")\n",
|
||
|
|
" barray = bytearray(1)\n",
|
||
|
|
" barray = await reader.readexactly(1)\n",
|
||
|
|
" print(barray)\n",
|
||
|
|
" assert (int.from_bytes(barray, byteorder = 'big', signed = True)) >= 0, \"Invalid Byte read from Stream!\"\n",
|
||
|
|
" len = int.from_bytes(barray, byteorder = 'big', signed = False)\n",
|
||
|
|
" barray = bytearray(len)\n",
|
||
|
|
" barray = await reader.readexactly(len)\n",
|
||
|
|
" print(barray)\n",
|
||
|
|
" #for b in barray:\n",
|
||
|
|
" #assert (int.from_bytes(b, byteorder = 'big', signed = True)) >= 0, \"Invalid ShortString-Byte read from Stream!\"\n",
|
||
|
|
" ###checking Environment.ENCODING not considered yet\n",
|
||
|
|
" print(\"short string: \")\n",
|
||
|
|
" print(barray.decode())\n",
|
||
|
|
" return '\"' + barray.decode() + '\"'\n",
|
||
|
|
" \n",
|
||
|
|
" elif typeCode == 16:\n",
|
||
|
|
" ####readSymbol()\n",
|
||
|
|
" print(\"Symbol\")\n",
|
||
|
|
" barray = bytearray(2) #readShort()\n",
|
||
|
|
" barray = await reader.readexactly(2)\n",
|
||
|
|
" print(barray)\n",
|
||
|
|
" for b in barray:\n",
|
||
|
|
" assert (int.from_bytes(b, byteorder = 'big', signed = True)) >= 0, \"Invalid ShortInt-Byte read from Stream!\"\n",
|
||
|
|
" len = unpack('>H',barray)[0]\n",
|
||
|
|
" barray = bytearray(len)\n",
|
||
|
|
" barray = await reader.readexactly(len)\n",
|
||
|
|
" print(barray)\n",
|
||
|
|
" #for b in barray:\n",
|
||
|
|
" #assert (int.from_bytes(b, byteorder = 'big', signed = True)) >= 0, \"Invalid String-Byte read from Stream!\"\n",
|
||
|
|
" ###checking Environment.ENCODING not considered yet\n",
|
||
|
|
" print(\"symbol: \")\n",
|
||
|
|
" print(barray.decode())\n",
|
||
|
|
" return barray.decode()\n",
|
||
|
|
" \n",
|
||
|
|
" elif typeCode == 17:\n",
|
||
|
|
" ####readShortSymbol()\n",
|
||
|
|
" print(\"ShortSymbol\")\n",
|
||
|
|
" barray = bytearray(1) #readByte()\n",
|
||
|
|
" barray = await reader.readexactly(1)\n",
|
||
|
|
" print(barray)\n",
|
||
|
|
" assert (int.from_bytes(barray, byteorder = 'big', signed = True)) >= 0, \"Invalid Byte read from Stream!\"\n",
|
||
|
|
" len = int.from_bytes(barray, byteorder = 'big', signed = False)\n",
|
||
|
|
" barray = bytearray(len)\n",
|
||
|
|
" barray = await reader.readexactly(len)\n",
|
||
|
|
" print(barray)\n",
|
||
|
|
" #for b in barray:\n",
|
||
|
|
" #assert (int.from_bytes(b, byteorder = 'big', signed = True)) >= 0, \"Invalid ShortString-Byte read from Stream!\"\n",
|
||
|
|
" ###checking Environment.ENCODING not considered yet\n",
|
||
|
|
" print(\"short symbol: \")\n",
|
||
|
|
" print(barray.decode())\n",
|
||
|
|
" return barray.decode()\n",
|
||
|
|
" \n",
|
||
|
|
" elif typeCode == 18:\n",
|
||
|
|
" ####readText()\n",
|
||
|
|
" print(\"Text\")\n",
|
||
|
|
" barray = bytearray(2) #readShort()\n",
|
||
|
|
" barray = await reader.readexactly(2)\n",
|
||
|
|
" print(barray)\n",
|
||
|
|
" #for b in barray:\n",
|
||
|
|
" # assert (int.from_bytes(b, byteorder = 'big', signed = True)) >= 0, \"Invalid ShortInt-Byte read from Stream!\"\n",
|
||
|
|
" len = unpack('>H',barray)[0]\n",
|
||
|
|
" barray = bytearray(len)\n",
|
||
|
|
" barray = await reader.readexactly(len)\n",
|
||
|
|
" print(barray)\n",
|
||
|
|
" #for b in barray:\n",
|
||
|
|
" #assert (int.from_bytes(b, byteorder = 'big', signed = True)) >= 0, \"Invalid Text-Byte read from Stream!\"\n",
|
||
|
|
" ###checking Environment.ENCODING not considered yet\n",
|
||
|
|
" txt = barray.decode()\n",
|
||
|
|
" if not txt.startswith('<text>'):\n",
|
||
|
|
" txt = '\"<text>' + txt + '</text--->\"'\n",
|
||
|
|
" \n",
|
||
|
|
" print(txt)\n",
|
||
|
|
" return txt\n",
|
||
|
|
" \n",
|
||
|
|
" \n",
|
||
|
|
" elif typeCode == 19:\n",
|
||
|
|
" ####readShortText()\n",
|
||
|
|
" print(\"ShortText\")\n",
|
||
|
|
" barray = bytearray(1) #readByte()\n",
|
||
|
|
" barray = await reader.readexactly(1)\n",
|
||
|
|
" print(barray)\n",
|
||
|
|
" #assert (int.from_bytes(barray, byteorder = 'big', signed = True)) >= 0, \"Invalid Byte read from Stream!\"\n",
|
||
|
|
" len = int.from_bytes(barray, byteorder = 'big', signed = False)\n",
|
||
|
|
" barray = bytearray(len)\n",
|
||
|
|
" barray = await reader.readexactly(len)\n",
|
||
|
|
" print(barray)\n",
|
||
|
|
" #for b in barray:\n",
|
||
|
|
" #assert (int.from_bytes(b, byteorder = 'big', signed = True)) >= 0, \"Invalid ShortText-Byte read from Stream!\"\n",
|
||
|
|
" ###checking Environment.ENCODING not considered yet\n",
|
||
|
|
" print(\"short Text: \")\n",
|
||
|
|
" txt = barray.decode()\n",
|
||
|
|
" if not txt.startswith('<text>'):\n",
|
||
|
|
" txt = '\"<text>' + txt + '</text--->\"'\n",
|
||
|
|
" \n",
|
||
|
|
" print(txt)\n",
|
||
|
|
" return txt\n",
|
||
|
|
" \n",
|
||
|
|
" elif typeCode == 20:\n",
|
||
|
|
" ####readDouble()\n",
|
||
|
|
" print(\"Double\")\n",
|
||
|
|
" barray = bytearray(8)\n",
|
||
|
|
" barray = await reader.readexactly(8)\n",
|
||
|
|
" print(barray)\n",
|
||
|
|
" assert (int.from_bytes(barray, byteorder = 'big', signed = True)) >= 0, \"Invalid Double-Byte read from Stream!\"\n",
|
||
|
|
" r = unpack('>d',barray)[0]\n",
|
||
|
|
" ####\n",
|
||
|
|
" print(\"Double: \")\n",
|
||
|
|
" print(r)\n",
|
||
|
|
" return r\n",
|
||
|
|
"\n",
|
||
|
|
"\n",
|
||
|
|
"###################################################\n",
|
||
|
|
"\n",
|
||
|
|
"\n",
|
||
|
|
"async def Receive_List(reader, finalToken, binLists):\n",
|
||
|
|
" print(\"begin of Receive_List()\")\n",
|
||
|
|
" answerList = []\n",
|
||
|
|
" if not binLists:\n",
|
||
|
|
" result = ''\n",
|
||
|
|
" count = 1\n",
|
||
|
|
" while True: \n",
|
||
|
|
" line = await reader.readline()\n",
|
||
|
|
" print(str(count) + \"th line in Receive_List() read.\")\n",
|
||
|
|
" print(line)\n",
|
||
|
|
" count += 1\n",
|
||
|
|
" #line = line.decode().rstrip()\n",
|
||
|
|
" line = line.decode('ISO-8859-1').rstrip()\n",
|
||
|
|
" if finalToken in line:\n",
|
||
|
|
" #result += line + \"\\n\"\n",
|
||
|
|
" result += line\n",
|
||
|
|
" break\n",
|
||
|
|
" if line:\n",
|
||
|
|
" #result += line + \"\\n\"\n",
|
||
|
|
" result += line # + ' '\n",
|
||
|
|
" else:\n",
|
||
|
|
" print(\"Empty Line read by Receive_List()!\")\n",
|
||
|
|
" print(result)\n",
|
||
|
|
" answerList= NLparse(result, False)\n",
|
||
|
|
" \n",
|
||
|
|
" else: #binLists = True --> readBinaryFrom(inputStream)\n",
|
||
|
|
" #answer = await reader.readline()\n",
|
||
|
|
" #print(answer)\n",
|
||
|
|
" print(\"binarylist = True.\")\n",
|
||
|
|
" line = await reader.readexactly(3)\n",
|
||
|
|
" signature = line.decode().rstrip()\n",
|
||
|
|
" print(\"signature: \" + signature)\n",
|
||
|
|
" \n",
|
||
|
|
" #readShort()\n",
|
||
|
|
" barray = bytearray(2)\n",
|
||
|
|
" barray = await reader.readexactly(2)\n",
|
||
|
|
" major = unpack('>H',barray)\n",
|
||
|
|
" major = major[0]\n",
|
||
|
|
" print(\"major: \" + str(major))\n",
|
||
|
|
" \n",
|
||
|
|
" \n",
|
||
|
|
" barray = await reader.readexactly(2)\n",
|
||
|
|
" minor = unpack('>H',barray)\n",
|
||
|
|
" minor = minor[0]\n",
|
||
|
|
" print(\"minor: \" + str(minor))\n",
|
||
|
|
" \n",
|
||
|
|
" \n",
|
||
|
|
" if signature != \"bnl\":\n",
|
||
|
|
" print(signatur + \" is wrong Signatur!\")\n",
|
||
|
|
" return None\n",
|
||
|
|
" if (major != 1 or (minor != 0 and minor != 1 and minor != 2)):\n",
|
||
|
|
" print(str(major) + \".\" + str(minor) + \" is wrong Version Number!\")\n",
|
||
|
|
" return None\n",
|
||
|
|
" print(\"readBinaryRecords() is called.\")\n",
|
||
|
|
" answerList = await readBinaryRecord(reader)\n",
|
||
|
|
" ####check finalToken here#####\n",
|
||
|
|
" line = await reader.readline()\n",
|
||
|
|
" print(\"last line in Receive_list() in binarylist mode: \")\n",
|
||
|
|
" print(line.decode())\n",
|
||
|
|
" \n",
|
||
|
|
" print('last result in Receive_List(): ')\n",
|
||
|
|
" print(answerList)\n",
|
||
|
|
" return answerList\n",
|
||
|
|
"\n",
|
||
|
|
"\n",
|
||
|
|
"\n",
|
||
|
|
"\n",
|
||
|
|
"\n",
|
||
|
|
"####################################################\n",
|
||
|
|
"\n",
|
||
|
|
"\n",
|
||
|
|
"async def Receive_Response(reader, bin_list):\n",
|
||
|
|
" \n",
|
||
|
|
" if not reader:\n",
|
||
|
|
" print('Connection to SecondoServer reset!')\n",
|
||
|
|
" return None\n",
|
||
|
|
" print(\"We r in Receive_Response() before reading.\")\n",
|
||
|
|
" line = await reader.readline()\n",
|
||
|
|
" print(\"first line read in Receive_Response(): \")\n",
|
||
|
|
" print(line)\n",
|
||
|
|
" line = line.decode().rstrip()\n",
|
||
|
|
" if not line:\n",
|
||
|
|
" print(\"Network Error!\")\n",
|
||
|
|
" return None\n",
|
||
|
|
" count = 2\n",
|
||
|
|
" while line == \"<Message>\":\n",
|
||
|
|
" print(\"Receive_List(</Message>) called.\")\n",
|
||
|
|
" Message_List = await Receive_List(reader, \"</Message>\", bin_list)\n",
|
||
|
|
" if not Message_List:\n",
|
||
|
|
" print(\"Error- MessageList is empty!\")\n",
|
||
|
|
" return None\n",
|
||
|
|
" \n",
|
||
|
|
" line = await reader.readline()\n",
|
||
|
|
" print(str(count) + \"th line read in Receive_Response(): \")\n",
|
||
|
|
" print(line)\n",
|
||
|
|
" count += 1\n",
|
||
|
|
" line = line.decode().rstrip()\n",
|
||
|
|
" if not line:\n",
|
||
|
|
" print(\"Network Error!\")\n",
|
||
|
|
" return None\n",
|
||
|
|
" \n",
|
||
|
|
" if line == \"<SecondoError>\":\n",
|
||
|
|
" line = await reader.readline()\n",
|
||
|
|
" print(\"first line read in Receive_Response() after <SecondoError>: \")\n",
|
||
|
|
" print(line)\n",
|
||
|
|
" line = line.decode().rstrip()\n",
|
||
|
|
" if line:\n",
|
||
|
|
" line = await reader.readline()\n",
|
||
|
|
" print(\"second line read in Receive_Response() after <SecondoError>: \")\n",
|
||
|
|
" print(line)\n",
|
||
|
|
" line = line.decode().rstrip()\n",
|
||
|
|
" \n",
|
||
|
|
" else:\n",
|
||
|
|
" print(\"Error reading SecondoError!\")\n",
|
||
|
|
" return None\n",
|
||
|
|
" return None\n",
|
||
|
|
" \n",
|
||
|
|
" if line != \"<SecondoResponse>\":\n",
|
||
|
|
" print(\"Protocol Error!\")\n",
|
||
|
|
" return None\n",
|
||
|
|
" \n",
|
||
|
|
" print(\"Receive_List(</SecondoResponse>) is called.\")\n",
|
||
|
|
" answerList = await Receive_List(reader, \"</SecondoResponse>\", bin_list)\n",
|
||
|
|
" print('result in Receive_Response():')\n",
|
||
|
|
" print(answerList)\n",
|
||
|
|
" if not answerList:\n",
|
||
|
|
" return None\n",
|
||
|
|
" \n",
|
||
|
|
" #Error_Code = answerList[0]\n",
|
||
|
|
" #Error_Pos = answerList[1]\n",
|
||
|
|
" #Error_Message = answerList[2]\n",
|
||
|
|
" #Result_List = answerList[3]\n",
|
||
|
|
" #return Result_List\n",
|
||
|
|
" return answerList"
|
||
|
|
]
|
||
|
|
}
|
||
|
|
],
|
||
|
|
"metadata": {
|
||
|
|
"kernelspec": {
|
||
|
|
"display_name": "Python 3",
|
||
|
|
"language": "python",
|
||
|
|
"name": "python3"
|
||
|
|
},
|
||
|
|
"language_info": {
|
||
|
|
"codemirror_mode": {
|
||
|
|
"name": "ipython",
|
||
|
|
"version": 3
|
||
|
|
},
|
||
|
|
"file_extension": ".py",
|
||
|
|
"mimetype": "text/x-python",
|
||
|
|
"name": "python",
|
||
|
|
"nbconvert_exporter": "python",
|
||
|
|
"pygments_lexer": "ipython3",
|
||
|
|
"version": "3.7.4"
|
||
|
|
}
|
||
|
|
},
|
||
|
|
"nbformat": 4,
|
||
|
|
"nbformat_minor": 2
|
||
|
|
}
|