{"nwo":"EDCD\/EDDN","sha":"e23d5d3b29405a5154811876358c7170d6cd3ee0","path":"setup.py","language":"python","identifier":"open_file_perms_recursive","parameters":"(dirname)","argument_list":"","return_statement":"","docstring":"Open up file perms on the given directory and its contents.","docstring_summary":"Open up file perms on the given directory and its contents.","docstring_tokens":["Open","up","file","perms","on","the","given","directory","and","its","contents","."],"function":"def open_file_perms_recursive(dirname):\n \"\"\"Open up file perms on the given directory and its contents.\"\"\"\n print 'open_file_perms_recursive: %s' % ( dirname )\n names = os.listdir(dirname)\n for name in names:\n n = '%s\/%s' % ( dirname, name )\n print 'open_file_perms_recursive: %s' % ( n )\n if (os.path.isdir(n)):\n os.chmod(n, 0755)\n # Recurse\n open_file_perms_recursive(n)\n \n else:\n os.chmod(n, 0644)","function_tokens":["def","open_file_perms_recursive","(","dirname",")",":","print","'open_file_perms_recursive: %s'","%","(","dirname",")","names","=","os",".","listdir","(","dirname",")","for","name","in","names",":","n","=","'%s\/%s'","%","(","dirname",",","name",")","print","'open_file_perms_recursive: %s'","%","(","n",")","if","(","os",".","path",".","isdir","(","n",")",")",":","os",".","chmod","(","n",",","0755",")","# Recurse","open_file_perms_recursive","(","n",")","else",":","os",".","chmod","(","n",",","0644",")"],"url":"https:\/\/github.com\/EDCD\/EDDN\/blob\/e23d5d3b29405a5154811876358c7170d6cd3ee0\/setup.py#L116-L129"} {"nwo":"EDCD\/EDDN","sha":"e23d5d3b29405a5154811876358c7170d6cd3ee0","path":"src\/eddn\/Gateway.py","language":"python","identifier":"push_message","parameters":"(parsed_message, topic)","argument_list":"","return_statement":"","docstring":"Spawned as a greenlet to push messages (strings) through ZeroMQ.\n This is a dumb method that just pushes strings; it assumes you've already validated\n and serialised as you want to.","docstring_summary":"Spawned as a greenlet to push messages (strings) through ZeroMQ.\n This is a dumb method that just pushes strings; it assumes you've already validated\n and serialised as you want to.","docstring_tokens":["Spawned","as","a","greenlet","to","push","messages","(","strings",")","through","ZeroMQ",".","This","is","a","dumb","method","that","just","pushes","strings",";","it","assumes","you","ve","already","validated","and","serialised","as","you","want","to","."],"function":"def push_message(parsed_message, topic):\n \"\"\"\n Spawned as a greenlet to push messages (strings) through ZeroMQ.\n This is a dumb method that just pushes strings; it assumes you've already validated\n and serialised as you want to.\n \"\"\"\n string_message = simplejson.dumps(parsed_message, ensure_ascii=False).encode('utf-8')\n\n # Push a zlib compressed JSON representation of the message to\n # announcers with schema as topic\n compressed_msg = zlib.compress(string_message)\n \n send_message = \"%s |-| %s\" % (str(topic), compressed_msg)\n \n sender.send(send_message)\n statsCollector.tally(\"outbound\")","function_tokens":["def","push_message","(","parsed_message",",","topic",")",":","string_message","=","simplejson",".","dumps","(","parsed_message",",","ensure_ascii","=","False",")",".","encode","(","'utf-8'",")","# Push a zlib compressed JSON representation of the message to","# announcers with schema as topic","compressed_msg","=","zlib",".","compress","(","string_message",")","send_message","=","\"%s |-| %s\"","%","(","str","(","topic",")",",","compressed_msg",")","sender",".","send","(","send_message",")","statsCollector",".","tally","(","\"outbound\"",")"],"url":"https:\/\/github.com\/EDCD\/EDDN\/blob\/e23d5d3b29405a5154811876358c7170d6cd3ee0\/src\/eddn\/Gateway.py#L118-L133"} {"nwo":"EDCD\/EDDN","sha":"e23d5d3b29405a5154811876358c7170d6cd3ee0","path":"src\/eddn\/Gateway.py","language":"python","identifier":"get_remote_address","parameters":"()","argument_list":"","return_statement":"return request.headers.get('X-Forwarded-For', request.remote_addr)","docstring":"Determines the address of the uploading client. First checks the for\n proxy-forwarded headers, then falls back to request.remote_addr.\n :rtype: str","docstring_summary":"Determines the address of the uploading client. First checks the for\n proxy-forwarded headers, then falls back to request.remote_addr.\n :rtype: str","docstring_tokens":["Determines","the","address","of","the","uploading","client",".","First","checks","the","for","proxy","-","forwarded","headers","then","falls","back","to","request",".","remote_addr",".",":","rtype",":","str"],"function":"def get_remote_address():\n \"\"\"\n Determines the address of the uploading client. First checks the for\n proxy-forwarded headers, then falls back to request.remote_addr.\n :rtype: str\n \"\"\"\n return request.headers.get('X-Forwarded-For', request.remote_addr)","function_tokens":["def","get_remote_address","(",")",":","return","request",".","headers",".","get","(","'X-Forwarded-For'",",","request",".","remote_addr",")"],"url":"https:\/\/github.com\/EDCD\/EDDN\/blob\/e23d5d3b29405a5154811876358c7170d6cd3ee0\/src\/eddn\/Gateway.py#L136-L142"} {"nwo":"EDCD\/EDDN","sha":"e23d5d3b29405a5154811876358c7170d6cd3ee0","path":"src\/eddn\/Gateway.py","language":"python","identifier":"get_decompressed_message","parameters":"()","argument_list":"","return_statement":"return message_body","docstring":"For upload formats that support it, detect gzip Content-Encoding headers\n and de-compress on the fly.\n :rtype: str\n :returns: The de-compressed request body.","docstring_summary":"For upload formats that support it, detect gzip Content-Encoding headers\n and de-compress on the fly.\n :rtype: str\n :returns: The de-compressed request body.","docstring_tokens":["For","upload","formats","that","support","it","detect","gzip","Content","-","Encoding","headers","and","de","-","compress","on","the","fly",".",":","rtype",":","str",":","returns",":","The","de","-","compressed","request","body","."],"function":"def get_decompressed_message():\n \"\"\"\n For upload formats that support it, detect gzip Content-Encoding headers\n and de-compress on the fly.\n :rtype: str\n :returns: The de-compressed request body.\n \"\"\"\n content_encoding = request.headers.get('Content-Encoding', '')\n logger.debug('Content-Encoding: ' + content_encoding)\n\n if content_encoding in ['gzip', 'deflate']:\n logger.debug('Content-Encoding of gzip or deflate...')\n # Compressed request. We have to decompress the body, then figure out\n # if it's form-encoded.\n try:\n # Auto header checking.\n logger.debug('Trying zlib.decompress (15 + 32)...')\n message_body = zlib.decompress(request.body.read(), 15 + 32)\n\n except zlib.error:\n logger.error('zlib.error, trying zlib.decompress (-15)')\n # Negative wbits suppresses adler32 checksumming.\n message_body = zlib.decompress(request.body.read(), -15)\n logger.debug('Resulting message_body:\\n%s\\n' % (message_body))\n\n # At this point, we're not sure whether we're dealing with a straight\n # un-encoded POST body, or a form-encoded POST. Attempt to parse the\n # body. If it's not form-encoded, this will return an empty dict.\n form_enc_parsed = urlparse.parse_qs(message_body)\n if form_enc_parsed:\n logger.info('Request is form-encoded, compressed, from %s' % (get_remote_address()))\n # This is a form-encoded POST. The value of the data attrib will\n # be the body we're looking for.\n try:\n message_body = form_enc_parsed['data'][0]\n\n except (KeyError, IndexError):\n logger.error('form-encoded, compressed, upload did not contain a \"data\" key. From %s', get_remote_address())\n raise MalformedUploadError(\n \"No 'data' POST key\/value found. Check your POST key \"\n \"name for spelling, and make sure you're passing a value.\"\n )\n\n else:\n logger.debug('Request is *NOT* form-encoded')\n\n else:\n logger.debug('Content-Encoding indicates *not* compressed...')\n\n # Uncompressed request. Bottle handles all of the parsing of the\n # POST key\/vals, or un-encoded body.\n data_key = request.forms.get('data')\n if data_key:\n logger.info('Request is form-encoded, uncompressed, from %s' % (get_remote_address()))\n # This is a form-encoded POST. Support the silly people.\n message_body = data_key\n\n else:\n logger.debug('Plain POST request detected...')\n # This is a non form-encoded POST body.\n message_body = request.body.read()\n\n return message_body","function_tokens":["def","get_decompressed_message","(",")",":","content_encoding","=","request",".","headers",".","get","(","'Content-Encoding'",",","''",")","logger",".","debug","(","'Content-Encoding: '","+","content_encoding",")","if","content_encoding","in","[","'gzip'",",","'deflate'","]",":","logger",".","debug","(","'Content-Encoding of gzip or deflate...'",")","# Compressed request. We have to decompress the body, then figure out","# if it's form-encoded.","try",":","# Auto header checking.","logger",".","debug","(","'Trying zlib.decompress (15 + 32)...'",")","message_body","=","zlib",".","decompress","(","request",".","body",".","read","(",")",",","15","+","32",")","except","zlib",".","error",":","logger",".","error","(","'zlib.error, trying zlib.decompress (-15)'",")","# Negative wbits suppresses adler32 checksumming.","message_body","=","zlib",".","decompress","(","request",".","body",".","read","(",")",",","-","15",")","logger",".","debug","(","'Resulting message_body:\\n%s\\n'","%","(","message_body",")",")","# At this point, we're not sure whether we're dealing with a straight","# un-encoded POST body, or a form-encoded POST. Attempt to parse the","# body. If it's not form-encoded, this will return an empty dict.","form_enc_parsed","=","urlparse",".","parse_qs","(","message_body",")","if","form_enc_parsed",":","logger",".","info","(","'Request is form-encoded, compressed, from %s'","%","(","get_remote_address","(",")",")",")","# This is a form-encoded POST. The value of the data attrib will","# be the body we're looking for.","try",":","message_body","=","form_enc_parsed","[","'data'","]","[","0","]","except","(","KeyError",",","IndexError",")",":","logger",".","error","(","'form-encoded, compressed, upload did not contain a \"data\" key. From %s'",",","get_remote_address","(",")",")","raise","MalformedUploadError","(","\"No 'data' POST key\/value found. Check your POST key \"","\"name for spelling, and make sure you're passing a value.\"",")","else",":","logger",".","debug","(","'Request is *NOT* form-encoded'",")","else",":","logger",".","debug","(","'Content-Encoding indicates *not* compressed...'",")","# Uncompressed request. Bottle handles all of the parsing of the","# POST key\/vals, or un-encoded body.","data_key","=","request",".","forms",".","get","(","'data'",")","if","data_key",":","logger",".","info","(","'Request is form-encoded, uncompressed, from %s'","%","(","get_remote_address","(",")",")",")","# This is a form-encoded POST. Support the silly people.","message_body","=","data_key","else",":","logger",".","debug","(","'Plain POST request detected...'",")","# This is a non form-encoded POST body.","message_body","=","request",".","body",".","read","(",")","return","message_body"],"url":"https:\/\/github.com\/EDCD\/EDDN\/blob\/e23d5d3b29405a5154811876358c7170d6cd3ee0\/src\/eddn\/Gateway.py#L145-L207"} {"nwo":"EDCD\/EDDN","sha":"e23d5d3b29405a5154811876358c7170d6cd3ee0","path":"src\/eddn\/Gateway.py","language":"python","identifier":"health_check","parameters":"()","argument_list":"","return_statement":"return Settings.EDDN_VERSION","docstring":"This should only be used by the gateway monitoring script. It is used\n to detect whether the gateway is still alive, and whether it should remain\n in the DNS rotation.","docstring_summary":"This should only be used by the gateway monitoring script. It is used\n to detect whether the gateway is still alive, and whether it should remain\n in the DNS rotation.","docstring_tokens":["This","should","only","be","used","by","the","gateway","monitoring","script",".","It","is","used","to","detect","whether","the","gateway","is","still","alive","and","whether","it","should","remain","in","the","DNS","rotation","."],"function":"def health_check():\n \"\"\"\n This should only be used by the gateway monitoring script. It is used\n to detect whether the gateway is still alive, and whether it should remain\n in the DNS rotation.\n \"\"\"\n return Settings.EDDN_VERSION","function_tokens":["def","health_check","(",")",":","return","Settings",".","EDDN_VERSION"],"url":"https:\/\/github.com\/EDCD\/EDDN\/blob\/e23d5d3b29405a5154811876358c7170d6cd3ee0\/src\/eddn\/Gateway.py#L326-L332"} {"nwo":"EDCD\/EDDN","sha":"e23d5d3b29405a5154811876358c7170d6cd3ee0","path":"src\/eddn\/Relay.py","language":"python","identifier":"Relay.run","parameters":"(self)","argument_list":"","return_statement":"","docstring":"Fires up the relay process.","docstring_summary":"Fires up the relay process.","docstring_tokens":["Fires","up","the","relay","process","."],"function":"def run(self):\n \"\"\"\n Fires up the relay process.\n \"\"\"\n # These form the connection to the Gateway daemon(s) upstream.\n context = zmq.Context()\n\n receiver = context.socket(zmq.SUB)\n\n # Filters on topics or not...\n if Settings.RELAY_RECEIVE_ONLY_GATEWAY_EXTRA_JSON is True:\n for schemaRef, schemaFile in Settings.GATEWAY_JSON_SCHEMAS.iteritems():\n receiver.setsockopt(zmq.SUBSCRIBE, schemaRef)\n for schemaRef, schemaFile in Settings.RELAY_EXTRA_JSON_SCHEMAS.iteritems():\n receiver.setsockopt(zmq.SUBSCRIBE, schemaRef)\n else:\n receiver.setsockopt(zmq.SUBSCRIBE, '')\n\n for binding in Settings.RELAY_RECEIVER_BINDINGS:\n # Relays bind upstream to an Announcer, or another Relay.\n receiver.connect(binding)\n\n sender = context.socket(zmq.PUB)\n sender.setsockopt(zmq.SNDHWM, 500)\n\n for binding in Settings.RELAY_SENDER_BINDINGS:\n # End users, or other relays, may attach here.\n sender.bind(binding)\n\n def relay_worker(message):\n \"\"\"\n This is the worker function that re-sends the incoming messages out\n to any subscribers.\n :param str message: A JSON string to re-broadcast.\n \"\"\"\n # Separate topic from message\n message = message.split(' |-| ')\n\n # Handle gateway not sending topic\n if len(message) > 1:\n message = message[1]\n else:\n message = message[0]\n\n message = zlib.decompress(message)\n json = simplejson.loads(message)\n\n # Handle duplicate message\n if Settings.RELAY_DUPLICATE_MAX_MINUTES:\n if duplicateMessages.isDuplicated(json):\n # We've already seen this message recently. Discard it.\n statsCollector.tally(\"duplicate\")\n return\n\n # Mask the uploader with a randomised nonce but still make it unique\n # for each uploader\n if 'uploaderID' in json['header']:\n json['header']['uploaderID'] = self.scramble_uploader(json['header']['uploaderID'])\n\n # Remove IP to end consumer\n if 'uploaderIP' in json['header']:\n del json['header']['uploaderIP']\n\n # Convert message back to JSON\n message = simplejson.dumps(json, sort_keys=True)\n\n # Recompress message\n message = zlib.compress(message)\n\n # Send message\n sender.send(message)\n statsCollector.tally(\"outbound\")\n\n while True:\n # For each incoming message, spawn a greenlet using the relay_worker\n # function.\n inboundMessage = receiver.recv()\n statsCollector.tally(\"inbound\")\n gevent.spawn(relay_worker, inboundMessage)","function_tokens":["def","run","(","self",")",":","# These form the connection to the Gateway daemon(s) upstream.","context","=","zmq",".","Context","(",")","receiver","=","context",".","socket","(","zmq",".","SUB",")","# Filters on topics or not...","if","Settings",".","RELAY_RECEIVE_ONLY_GATEWAY_EXTRA_JSON","is","True",":","for","schemaRef",",","schemaFile","in","Settings",".","GATEWAY_JSON_SCHEMAS",".","iteritems","(",")",":","receiver",".","setsockopt","(","zmq",".","SUBSCRIBE",",","schemaRef",")","for","schemaRef",",","schemaFile","in","Settings",".","RELAY_EXTRA_JSON_SCHEMAS",".","iteritems","(",")",":","receiver",".","setsockopt","(","zmq",".","SUBSCRIBE",",","schemaRef",")","else",":","receiver",".","setsockopt","(","zmq",".","SUBSCRIBE",",","''",")","for","binding","in","Settings",".","RELAY_RECEIVER_BINDINGS",":","# Relays bind upstream to an Announcer, or another Relay.","receiver",".","connect","(","binding",")","sender","=","context",".","socket","(","zmq",".","PUB",")","sender",".","setsockopt","(","zmq",".","SNDHWM",",","500",")","for","binding","in","Settings",".","RELAY_SENDER_BINDINGS",":","# End users, or other relays, may attach here.","sender",".","bind","(","binding",")","def","relay_worker","(","message",")",":","\"\"\"\n This is the worker function that re-sends the incoming messages out\n to any subscribers.\n :param str message: A JSON string to re-broadcast.\n \"\"\"","# Separate topic from message","message","=","message",".","split","(","' |-| '",")","# Handle gateway not sending topic","if","len","(","message",")",">","1",":","message","=","message","[","1","]","else",":","message","=","message","[","0","]","message","=","zlib",".","decompress","(","message",")","json","=","simplejson",".","loads","(","message",")","# Handle duplicate message","if","Settings",".","RELAY_DUPLICATE_MAX_MINUTES",":","if","duplicateMessages",".","isDuplicated","(","json",")",":","# We've already seen this message recently. Discard it.","statsCollector",".","tally","(","\"duplicate\"",")","return","# Mask the uploader with a randomised nonce but still make it unique","# for each uploader","if","'uploaderID'","in","json","[","'header'","]",":","json","[","'header'","]","[","'uploaderID'","]","=","self",".","scramble_uploader","(","json","[","'header'","]","[","'uploaderID'","]",")","# Remove IP to end consumer","if","'uploaderIP'","in","json","[","'header'","]",":","del","json","[","'header'","]","[","'uploaderIP'","]","# Convert message back to JSON","message","=","simplejson",".","dumps","(","json",",","sort_keys","=","True",")","# Recompress message","message","=","zlib",".","compress","(","message",")","# Send message","sender",".","send","(","message",")","statsCollector",".","tally","(","\"outbound\"",")","while","True",":","# For each incoming message, spawn a greenlet using the relay_worker","# function.","inboundMessage","=","receiver",".","recv","(",")","statsCollector",".","tally","(","\"inbound\"",")","gevent",".","spawn","(","relay_worker",",","inboundMessage",")"],"url":"https:\/\/github.com\/EDCD\/EDDN\/blob\/e23d5d3b29405a5154811876358c7170d6cd3ee0\/src\/eddn\/Relay.py#L100-L178"} {"nwo":"EDCD\/EDDN","sha":"e23d5d3b29405a5154811876358c7170d6cd3ee0","path":"src\/eddn\/Relay.py","language":"python","identifier":"EnableCors.apply","parameters":"(self, fn, context)","argument_list":"","return_statement":"return _enable_cors","docstring":"Apply a CORS handler.\n\n Ref: ","docstring_summary":"Apply a CORS handler.","docstring_tokens":["Apply","a","CORS","handler","."],"function":"def apply(self, fn, context):\n \"\"\"\n Apply a CORS handler.\n\n Ref: \n \"\"\"\n def _enable_cors(*args, **kwargs):\n \"\"\"Set CORS Headers.\"\"\"\n response.headers['Access-Control-Allow-Origin'] = '*'\n response.headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, OPTIONS'\n response.headers['Access-Control-Allow-Headers'] = 'Origin, Accept, Content-Type, X-Requested-With, X-CSRF-Token'\n\n if request.method != 'OPTIONS':\n # actual request; reply with the actual response\n return fn(*args, **kwargs)\n\n return _enable_cors","function_tokens":["def","apply","(","self",",","fn",",","context",")",":","def","_enable_cors","(","*","args",",","*","*","kwargs",")",":","\"\"\"Set CORS Headers.\"\"\"","response",".","headers","[","'Access-Control-Allow-Origin'","]","=","'*'","response",".","headers","[","'Access-Control-Allow-Methods'","]","=","'GET, POST, PUT, OPTIONS'","response",".","headers","[","'Access-Control-Allow-Headers'","]","=","'Origin, Accept, Content-Type, X-Requested-With, X-CSRF-Token'","if","request",".","method","!=","'OPTIONS'",":","# actual request; reply with the actual response","return","fn","(","*","args",",","*","*","kwargs",")","return","_enable_cors"],"url":"https:\/\/github.com\/EDCD\/EDDN\/blob\/e23d5d3b29405a5154811876358c7170d6cd3ee0\/src\/eddn\/Relay.py#L187-L203"} {"nwo":"EDCD\/EDDN","sha":"e23d5d3b29405a5154811876358c7170d6cd3ee0","path":"src\/eddn\/Bouncer.py","language":"python","identifier":"push_message","parameters":"(message_body)","argument_list":"","return_statement":"","docstring":"Spawned as a greenlet to push messages (strings) through ZeroMQ.\n This is a dumb method that just pushes strings; it assumes you've already validated\n and serialised as you want to.","docstring_summary":"Spawned as a greenlet to push messages (strings) through ZeroMQ.\n This is a dumb method that just pushes strings; it assumes you've already validated\n and serialised as you want to.","docstring_tokens":["Spawned","as","a","greenlet","to","push","messages","(","strings",")","through","ZeroMQ",".","This","is","a","dumb","method","that","just","pushes","strings",";","it","assumes","you","ve","already","validated","and","serialised","as","you","want","to","."],"function":"def push_message(message_body):\n \"\"\"\n Spawned as a greenlet to push messages (strings) through ZeroMQ.\n This is a dumb method that just pushes strings; it assumes you've already validated\n and serialised as you want to.\n \"\"\"\n try:\n r = requests.post(\n Settings.BOUNCER_LIVE_GATEWAY_URL,\n data=message_body,\n )\n\n except Exception as e:\n logger.error('Failed sending message on', exc_info=e)\n\n else:\n if r.status_code != requests.codes.ok:\n logger.error('Response from %s:\\n%s\\n' % (BOUNCER_LIVE_GATEWAY_URL,\n r.text))\n\n else:\n statsCollector.tally(\"outbound\")","function_tokens":["def","push_message","(","message_body",")",":","try",":","r","=","requests",".","post","(","Settings",".","BOUNCER_LIVE_GATEWAY_URL",",","data","=","message_body",",",")","except","Exception","as","e",":","logger",".","error","(","'Failed sending message on'",",","exc_info","=","e",")","else",":","if","r",".","status_code","!=","requests",".","codes",".","ok",":","logger",".","error","(","'Response from %s:\\n%s\\n'","%","(","BOUNCER_LIVE_GATEWAY_URL",",","r",".","text",")",")","else",":","statsCollector",".","tally","(","\"outbound\"",")"],"url":"https:\/\/github.com\/EDCD\/EDDN\/blob\/e23d5d3b29405a5154811876358c7170d6cd3ee0\/src\/eddn\/Bouncer.py#L89-L110"} {"nwo":"EDCD\/EDDN","sha":"e23d5d3b29405a5154811876358c7170d6cd3ee0","path":"src\/eddn\/Bouncer.py","language":"python","identifier":"get_remote_address","parameters":"()","argument_list":"","return_statement":"return request.headers.get('X-Forwarded-For', request.remote_addr)","docstring":"Determines the address of the uploading client. First checks the for\n proxy-forwarded headers, then falls back to request.remote_addr.\n :rtype: str","docstring_summary":"Determines the address of the uploading client. First checks the for\n proxy-forwarded headers, then falls back to request.remote_addr.\n :rtype: str","docstring_tokens":["Determines","the","address","of","the","uploading","client",".","First","checks","the","for","proxy","-","forwarded","headers","then","falls","back","to","request",".","remote_addr",".",":","rtype",":","str"],"function":"def get_remote_address():\n \"\"\"\n Determines the address of the uploading client. First checks the for\n proxy-forwarded headers, then falls back to request.remote_addr.\n :rtype: str\n \"\"\"\n return request.headers.get('X-Forwarded-For', request.remote_addr)","function_tokens":["def","get_remote_address","(",")",":","return","request",".","headers",".","get","(","'X-Forwarded-For'",",","request",".","remote_addr",")"],"url":"https:\/\/github.com\/EDCD\/EDDN\/blob\/e23d5d3b29405a5154811876358c7170d6cd3ee0\/src\/eddn\/Bouncer.py#L113-L119"} {"nwo":"EDCD\/EDDN","sha":"e23d5d3b29405a5154811876358c7170d6cd3ee0","path":"src\/eddn\/Bouncer.py","language":"python","identifier":"get_decompressed_message","parameters":"()","argument_list":"","return_statement":"return message_body","docstring":"For upload formats that support it, detect gzip Content-Encoding headers\n and de-compress on the fly.\n :rtype: str\n :returns: The de-compressed request body.","docstring_summary":"For upload formats that support it, detect gzip Content-Encoding headers\n and de-compress on the fly.\n :rtype: str\n :returns: The de-compressed request body.","docstring_tokens":["For","upload","formats","that","support","it","detect","gzip","Content","-","Encoding","headers","and","de","-","compress","on","the","fly",".",":","rtype",":","str",":","returns",":","The","de","-","compressed","request","body","."],"function":"def get_decompressed_message():\n \"\"\"\n For upload formats that support it, detect gzip Content-Encoding headers\n and de-compress on the fly.\n :rtype: str\n :returns: The de-compressed request body.\n \"\"\"\n content_encoding = request.headers.get('Content-Encoding', '')\n\n if content_encoding in ['gzip', 'deflate']:\n # Compressed request. We have to decompress the body, then figure out\n # if it's form-encoded.\n try:\n # Auto header checking.\n message_body = zlib.decompress(request.body.read(), 15 + 32)\n except zlib.error:\n # Negative wbits suppresses adler32 checksumming.\n message_body = zlib.decompress(request.body.read(), -15)\n\n # At this point, we're not sure whether we're dealing with a straight\n # un-encoded POST body, or a form-encoded POST. Attempt to parse the\n # body. If it's not form-encoded, this will return an empty dict.\n form_enc_parsed = urlparse.parse_qs(message_body)\n if form_enc_parsed:\n # This is a form-encoded POST. The value of the data attrib will\n # be the body we're looking for.\n try:\n message_body = form_enc_parsed['data'][0]\n except (KeyError, IndexError):\n raise MalformedUploadError(\n \"No 'data' POST key\/value found. Check your POST key \"\n \"name for spelling, and make sure you're passing a value.\"\n )\n else:\n # Uncompressed request. Bottle handles all of the parsing of the\n # POST key\/vals, or un-encoded body.\n data_key = request.forms.get('data')\n if data_key:\n # This is a form-encoded POST. Support the silly people.\n message_body = data_key\n else:\n # This is a non form-encoded POST body.\n message_body = request.body.read()\n\n return message_body","function_tokens":["def","get_decompressed_message","(",")",":","content_encoding","=","request",".","headers",".","get","(","'Content-Encoding'",",","''",")","if","content_encoding","in","[","'gzip'",",","'deflate'","]",":","# Compressed request. We have to decompress the body, then figure out","# if it's form-encoded.","try",":","# Auto header checking.","message_body","=","zlib",".","decompress","(","request",".","body",".","read","(",")",",","15","+","32",")","except","zlib",".","error",":","# Negative wbits suppresses adler32 checksumming.","message_body","=","zlib",".","decompress","(","request",".","body",".","read","(",")",",","-","15",")","# At this point, we're not sure whether we're dealing with a straight","# un-encoded POST body, or a form-encoded POST. Attempt to parse the","# body. If it's not form-encoded, this will return an empty dict.","form_enc_parsed","=","urlparse",".","parse_qs","(","message_body",")","if","form_enc_parsed",":","# This is a form-encoded POST. The value of the data attrib will","# be the body we're looking for.","try",":","message_body","=","form_enc_parsed","[","'data'","]","[","0","]","except","(","KeyError",",","IndexError",")",":","raise","MalformedUploadError","(","\"No 'data' POST key\/value found. Check your POST key \"","\"name for spelling, and make sure you're passing a value.\"",")","else",":","# Uncompressed request. Bottle handles all of the parsing of the","# POST key\/vals, or un-encoded body.","data_key","=","request",".","forms",".","get","(","'data'",")","if","data_key",":","# This is a form-encoded POST. Support the silly people.","message_body","=","data_key","else",":","# This is a non form-encoded POST body.","message_body","=","request",".","body",".","read","(",")","return","message_body"],"url":"https:\/\/github.com\/EDCD\/EDDN\/blob\/e23d5d3b29405a5154811876358c7170d6cd3ee0\/src\/eddn\/Bouncer.py#L122-L166"} {"nwo":"EDCD\/EDDN","sha":"e23d5d3b29405a5154811876358c7170d6cd3ee0","path":"src\/eddn\/Bouncer.py","language":"python","identifier":"health_check","parameters":"()","argument_list":"","return_statement":"return Settings.EDDN_VERSION","docstring":"This should only be used by the gateway monitoring script. It is used\n to detect whether the gateway is still alive, and whether it should remain\n in the DNS rotation.","docstring_summary":"This should only be used by the gateway monitoring script. It is used\n to detect whether the gateway is still alive, and whether it should remain\n in the DNS rotation.","docstring_tokens":["This","should","only","be","used","by","the","gateway","monitoring","script",".","It","is","used","to","detect","whether","the","gateway","is","still","alive","and","whether","it","should","remain","in","the","DNS","rotation","."],"function":"def health_check():\n \"\"\"\n This should only be used by the gateway monitoring script. It is used\n to detect whether the gateway is still alive, and whether it should remain\n in the DNS rotation.\n \"\"\"\n return Settings.EDDN_VERSION","function_tokens":["def","health_check","(",")",":","return","Settings",".","EDDN_VERSION"],"url":"https:\/\/github.com\/EDCD\/EDDN\/blob\/e23d5d3b29405a5154811876358c7170d6cd3ee0\/src\/eddn\/Bouncer.py#L203-L209"} {"nwo":"EDCD\/EDDN","sha":"e23d5d3b29405a5154811876358c7170d6cd3ee0","path":"src\/eddn\/Monitor.py","language":"python","identifier":"EnableCors.apply","parameters":"(self, fn, context)","argument_list":"","return_statement":"return _enable_cors","docstring":"Apply a CORS handler.\n\n Ref: ","docstring_summary":"Apply a CORS handler.","docstring_tokens":["Apply","a","CORS","handler","."],"function":"def apply(self, fn, context):\n \"\"\"\n Apply a CORS handler.\n\n Ref: \n \"\"\"\n def _enable_cors(*args, **kwargs):\n \"\"\"Set CORS Headers.\"\"\"\n response.headers['Access-Control-Allow-Origin'] = '*'\n response.headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, OPTIONS'\n response.headers['Access-Control-Allow-Headers'] = 'Origin, Accept, Content-Type, X-Requested-With, X-CSRF-Token'\n\n if request.method != 'OPTIONS':\n # actual request; reply with the actual response\n return fn(*args, **kwargs)\n\n return _enable_cors","function_tokens":["def","apply","(","self",",","fn",",","context",")",":","def","_enable_cors","(","*","args",",","*","*","kwargs",")",":","\"\"\"Set CORS Headers.\"\"\"","response",".","headers","[","'Access-Control-Allow-Origin'","]","=","'*'","response",".","headers","[","'Access-Control-Allow-Methods'","]","=","'GET, POST, PUT, OPTIONS'","response",".","headers","[","'Access-Control-Allow-Headers'","]","=","'Origin, Accept, Content-Type, X-Requested-With, X-CSRF-Token'","if","request",".","method","!=","'OPTIONS'",":","# actual request; reply with the actual response","return","fn","(","*","args",",","*","*","kwargs",")","return","_enable_cors"],"url":"https:\/\/github.com\/EDCD\/EDDN\/blob\/e23d5d3b29405a5154811876358c7170d6cd3ee0\/src\/eddn\/Monitor.py#L242-L258"} {"nwo":"EDCD\/EDDN","sha":"e23d5d3b29405a5154811876358c7170d6cd3ee0","path":"src\/eddn\/conf\/Settings.py","language":"python","identifier":"loadConfig","parameters":"(cl_args)","argument_list":"","return_statement":"","docstring":"Load in a commandline-specified settings file, if applicable.\n\n A convenience method if you don't need other things specified as commandline\n options. Otherwise, point the filename to Settings.loadFrom().\n\n :param cl_args: An `argparse.parse_args()` return.","docstring_summary":"Load in a commandline-specified settings file, if applicable.","docstring_tokens":["Load","in","a","commandline","-","specified","settings","file","if","applicable","."],"function":"def loadConfig(cl_args):\n \"\"\"\n Load in a commandline-specified settings file, if applicable.\n\n A convenience method if you don't need other things specified as commandline\n options. Otherwise, point the filename to Settings.loadFrom().\n\n :param cl_args: An `argparse.parse_args()` return.\n \"\"\"\n if cl_args.config:\n Settings.loadFrom(cl_args.config)","function_tokens":["def","loadConfig","(","cl_args",")",":","if","cl_args",".","config",":","Settings",".","loadFrom","(","cl_args",".","config",")"],"url":"https:\/\/github.com\/EDCD\/EDDN\/blob\/e23d5d3b29405a5154811876358c7170d6cd3ee0\/src\/eddn\/conf\/Settings.py#L136-L146"}