def get_response(cmd, conn):
resp = conn.socket().makefile('<STR_LIT:rb>', -<NUM_LIT:1>)<EOL>resp_dict = dict(<EOL>code=<NUM_LIT:0>,<EOL>message='<STR_LIT>',<EOL>isspam=False,<EOL>score=<NUM_LIT:0.0>,<EOL>basescore=<NUM_LIT:0.0>,<EOL>report=[],<EOL>symbols=[],<EOL>headers={},<EOL>)<EOL>if cmd == '<STR_LIT>':<EOL><INDENT>resp_dict['<STR_LIT>'] = False<EOL>resp_dict['<STR_LIT>'] = False<EOL><DEDENT>data = resp.read()<EOL>lines = data.split('<STR_LIT:\r\n>')<EOL>for index, line in enumerate(lines):<EOL><INDENT>if index == <NUM_LIT:0>:<EOL><INDENT>match = RESPONSE_RE.match(line)<EOL>if not match:<EOL><INDENT>raise SpamCResponseError(<EOL>'<STR_LIT>' % data)<EOL><DEDENT>resp_dict.update(match.groupdict())<EOL>resp_dict['<STR_LIT:code>'] = int(resp_dict['<STR_LIT:code>'])<EOL><DEDENT>else:<EOL><INDENT>if not line.strip():<EOL><INDENT>continue<EOL><DEDENT>match = SPAM_RE.match(line)<EOL>if match:<EOL><INDENT>tmp = match.groupdict()<EOL>resp_dict['<STR_LIT>'] = float(tmp['<STR_LIT>'])<EOL>resp_dict['<STR_LIT>'] = float(tmp['<STR_LIT>'])<EOL>resp_dict['<STR_LIT>'] = tmp['<STR_LIT>'] in ['<STR_LIT:True>', '<STR_LIT>']<EOL><DEDENT>if not match:<EOL><INDENT>if cmd == '<STR_LIT>':<EOL><INDENT>match = PART_RE.findall(line)<EOL>for part in match:<EOL><INDENT>resp_dict['<STR_LIT>'].append(part)<EOL><DEDENT><DEDENT><DEDENT>if not match and cmd != '<STR_LIT>':<EOL><INDENT>match = RULE_RE.findall(line)<EOL>if match:<EOL><INDENT>resp_dict['<STR_LIT>'] = []<EOL>for part in match:<EOL><INDENT>score = part[<NUM_LIT:0>] + part[<NUM_LIT:1>]<EOL>score = score.strip()<EOL>resp_dict['<STR_LIT>'].append(<EOL>dict(score=score,<EOL>name=part[<NUM_LIT:2>],<EOL>description=SPACE_RE.sub("<STR_LIT:U+0020>", part[<NUM_LIT:3>])))<EOL><DEDENT><DEDENT><DEDENT>if line.startswith('<STR_LIT>'):<EOL><INDENT>resp_dict['<STR_LIT>'] = True<EOL><DEDENT>if line.startswith('<STR_LIT>'):<EOL><INDENT>resp_dict['<STR_LIT>'] = True<EOL><DEDENT><DEDENT><DEDENT>if cmd == '<STR_LIT>':<EOL><INDENT>resp_dict['<STR_LIT:message>'] = '<STR_LIT>'.join(lines[<NUM_LIT:4>:]) + '<STR_LIT:\r\n>'<EOL><DEDENT>if cmd == '<STR_LIT>':<EOL><INDENT>parser = Parser()<EOL>headers = parser.parsestr('<STR_LIT:\r\n>'.join(lines[<NUM_LIT:4>:]), headersonly=True)<EOL>for key in headers.keys():<EOL><INDENT>resp_dict['<STR_LIT>'][key] = headers[key]<EOL><DEDENT><DEDENT>return resp_dict<EOL>
Return a response