Python base64.decodestring() Examples
The following are 30
code examples of base64.decodestring().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
base64
, or try the search function
.
Example #1
Source File: rich_ipython_widget.py From Computable with MIT License | 6 votes |
def _handle_pyout(self, msg): """ Overridden to handle rich data types, like SVG. """ if not self._hidden and self._is_from_this_session(msg): content = msg['content'] prompt_number = content.get('execution_count', 0) data = content['data'] metadata = msg['content']['metadata'] if 'image/svg+xml' in data: self._pre_image_append(msg, prompt_number) self._append_svg(data['image/svg+xml'], True) self._append_html(self.output_sep2, True) elif 'image/png' in data: self._pre_image_append(msg, prompt_number) png = decodestring(data['image/png'].encode('ascii')) self._append_png(png, True, metadata=metadata.get('image/png', None)) self._append_html(self.output_sep2, True) elif 'image/jpeg' in data and self._jpg_supported: self._pre_image_append(msg, prompt_number) jpg = decodestring(data['image/jpeg'].encode('ascii')) self._append_jpg(jpg, True, metadata=metadata.get('image/jpeg', None)) self._append_html(self.output_sep2, True) else: # Default back to the plain text representation. return super(RichIPythonWidget, self)._handle_pyout(msg)
Example #2
Source File: base64_codec.py From Computable with MIT License | 6 votes |
def base64_decode(input,errors='strict'): """ Decodes the object input and returns a tuple (output object, length consumed). input must be an object which provides the bf_getreadbuf buffer slot. Python strings, buffer objects and memory mapped files are examples of objects providing this slot. errors defines the error handling to apply. It defaults to 'strict' handling which is the only currently supported error handling for this codec. """ assert errors == 'strict' output = base64.decodestring(input) return (output, len(input))
Example #3
Source File: rwbase.py From Computable with MIT License | 6 votes |
def base64_decode(nb): """Restore all bytes objects in the notebook from base64-encoded strings. Note: This is never used """ for ws in nb.worksheets: for cell in ws.cells: if cell.cell_type == 'code': for output in cell.outputs: if 'png' in output: if isinstance(output.png, unicode): output.png = output.png.encode('ascii') output.png = decodestring(output.png) if 'jpeg' in output: if isinstance(output.jpeg, unicode): output.jpeg = output.jpeg.encode('ascii') output.jpeg = decodestring(output.jpeg) return nb
Example #4
Source File: test_json.py From Computable with MIT License | 6 votes |
def test_read_jpeg(self): """JPEG output data is b64 unicode""" s = writes(nb0) nb1 = nbjson.reads(s) found_jpeg = False for cell in nb1.worksheets[0].cells: if not 'outputs' in cell: continue for output in cell.outputs: if 'jpeg' in output: found_jpeg = True jpegdata = output['jpeg'] self.assertEqual(type(jpegdata), unicode) # test that it is valid b64 data b64bytes = jpegdata.encode('ascii') raw_bytes = decodestring(b64bytes) assert found_jpeg, "never found jpeg output"
Example #5
Source File: rwbase.py From Computable with MIT License | 6 votes |
def base64_decode(nb): """Restore all bytes objects in the notebook from base64-encoded strings. Note: This is never used """ for ws in nb.worksheets: for cell in ws.cells: if cell.cell_type == 'code': for output in cell.outputs: if 'png' in output: if isinstance(output.png, unicode): output.png = output.png.encode('ascii') output.png = decodestring(output.png) if 'jpeg' in output: if isinstance(output.jpeg, unicode): output.jpeg = output.jpeg.encode('ascii') output.jpeg = decodestring(output.jpeg) return nb
Example #6
Source File: NetCreds.py From 3vilTwinAttacker with MIT License | 6 votes |
def parse_basic_auth(src_ip_port, dst_ip_port, headers, authorization_header): ''' Parse basic authentication over HTTP ''' if authorization_header: # authorization_header sometimes is triggered by failed ftp try: header_val = headers[authorization_header.group()] except KeyError: return b64_auth_re = re.match('basic (.+)', header_val, re.IGNORECASE) if b64_auth_re != None: basic_auth_b64 = b64_auth_re.group(1) basic_auth_creds = base64.decodestring(basic_auth_b64) msg = 'Basic Authentication: %s' % basic_auth_creds printer(src_ip_port, dst_ip_port, msg)
Example #7
Source File: NetCreds.py From 3vilTwinAttacker with MIT License | 6 votes |
def parse_netntlm_resp_msg(headers, resp_header, seq): ''' Parse the client response to the challenge ''' try: header_val3 = headers[resp_header] except KeyError: return header_val3 = header_val3.split(' ', 1) # The header value can either start with NTLM or Negotiate if header_val3[0] == 'NTLM' or header_val3[0] == 'Negotiate': try: msg3 = base64.decodestring(header_val3[1]) except binascii.Error: return return parse_ntlm_resp(msg3, seq)
Example #8
Source File: net-creds.py From net-creds with GNU General Public License v3.0 | 6 votes |
def parse_basic_auth(src_ip_port, dst_ip_port, headers, authorization_header): ''' Parse basic authentication over HTTP ''' if authorization_header: # authorization_header sometimes is triggered by failed ftp try: header_val = headers[authorization_header.group()] except KeyError: return b64_auth_re = re.match('basic (.+)', header_val, re.IGNORECASE) if b64_auth_re != None: basic_auth_b64 = b64_auth_re.group(1) try: basic_auth_creds = base64.decodestring(basic_auth_b64) except Exception: return msg = 'Basic Authentication: %s' % basic_auth_creds printer(src_ip_port, dst_ip_port, msg)
Example #9
Source File: net-creds.py From net-creds with GNU General Public License v3.0 | 6 votes |
def parse_netntlm_chal(headers, chal_header, ack): ''' Parse the netntlm server challenge https://code.google.com/p/python-ntlm/source/browse/trunk/python26/ntlm/ntlm.py ''' try: header_val2 = headers[chal_header] except KeyError: return header_val2 = header_val2.split(' ', 1) # The header value can either start with NTLM or Negotiate if header_val2[0] == 'NTLM' or header_val2[0].lower() == 'negotiate': try: msg2 = header_val2[1] except IndexError: return msg2 = base64.decodestring(msg2) parse_ntlm_chal(msg2, ack)
Example #10
Source File: net-creds.py From net-creds with GNU General Public License v3.0 | 6 votes |
def parse_netntlm_resp_msg(headers, resp_header, seq): ''' Parse the client response to the challenge ''' try: header_val3 = headers[resp_header] except KeyError: return header_val3 = header_val3.split(' ', 1) # The header value can either start with NTLM or Negotiate if header_val3[0] == 'NTLM' or header_val3[0] == 'Negotiate': try: msg3 = base64.decodestring(header_val3[1]) except binascii.Error: return return parse_ntlm_resp(msg3, seq)
Example #11
Source File: cookie.py From mishkal with GNU General Public License v3.0 | 6 votes |
def auth(self, cookie): """ Authenticate the cooke using the signature, verify that it has not expired; and return the cookie's content """ decode = base64.decodestring( cookie.replace("_", "/").replace("~", "=")) signature = decode[:_signature_size] expires = decode[_signature_size:_header_size] content = decode[_header_size:] if signature == hmac.new(self.secret, content, sha1).digest(): if int(expires) > int(make_time(time.time())): return content else: # This is the normal case of an expired cookie; just # don't bother doing anything here. pass else: # This case can happen if the server is restarted with a # different secret; or if the user's IP address changed # due to a proxy. However, it could also be a break-in # attempt -- so should it be reported? pass
Example #12
Source File: base64_codec.py From meddle with MIT License | 6 votes |
def base64_decode(input,errors='strict'): """ Decodes the object input and returns a tuple (output object, length consumed). input must be an object which provides the bf_getreadbuf buffer slot. Python strings, buffer objects and memory mapped files are examples of objects providing this slot. errors defines the error handling to apply. It defaults to 'strict' handling which is the only currently supported error handling for this codec. """ assert errors == 'strict' output = base64.decodestring(input) return (output, len(input))
Example #13
Source File: test_email_renamed.py From BinderFilter with MIT License | 5 votes |
def test_encoding(self): payload = self._au.get_payload() self.assertEqual(base64.decodestring(payload), self._audiodata)
Example #14
Source File: xmlrpclib.py From BinderFilter with MIT License | 5 votes |
def decode(self, data): self.data = base64.decodestring(data)
Example #15
Source File: test_email.py From BinderFilter with MIT License | 5 votes |
def test_encoding(self): payload = self._im.get_payload() self.assertEqual(base64.decodestring(payload), self._imgdata)
Example #16
Source File: test_gettext.py From BinderFilter with MIT License | 5 votes |
def setUp(self): if not os.path.isdir(LOCALEDIR): os.makedirs(LOCALEDIR) with open(MOFILE, 'wb') as fp: fp.write(base64.decodestring(GNU_MO_DATA)) with open(UMOFILE, 'wb') as fp: fp.write(base64.decodestring(UMO_DATA)) with open(MMOFILE, 'wb') as fp: fp.write(base64.decodestring(MMO_DATA)) self.env = test_support.EnvironmentVarGuard() self.env['LANGUAGE'] = 'xx' gettext._translations.clear()
Example #17
Source File: test_websocket.py From vnpy_crypto with MIT License | 5 votes |
def testNonce(self): """ WebSocket key should be a random 16-byte nonce. """ key = _create_sec_websocket_key() nonce = base64decode(key.encode("utf-8")) self.assertEqual(16, len(nonce))
Example #18
Source File: msvs.py From web2board with GNU Lesser General Public License v3.0 | 5 votes |
def Parse(self): try: dswfile = open(self.dswfile,'r') except IOError: return # doesn't exist yet, so can't add anything to configs. line = dswfile.readline() while line: if line[:9] == "EndGlobal": break line = dswfile.readline() line = dswfile.readline() datas = line while line: line = dswfile.readline() datas = datas + line # OK, we've found our little pickled cache of data. try: datas = base64.decodestring(datas) data = pickle.loads(datas) except KeyboardInterrupt: raise except: return # unable to unpickle any data for some reason self.configs.update(data)
Example #19
Source File: utils.py From Computable with MIT License | 5 votes |
def _bdecode(s): """Decodes a base64 string. This function is equivalent to base64.decodestring and it's retained only for backward compatibility. It used to remove the last \n of the decoded string, if it had any (see issue 7143). """ if not s: return s return base64.decodestring(s)
Example #20
Source File: test_jsonutil.py From Computable with MIT License | 5 votes |
def test_encode_images(): # invalid data, but the header and footer are from real files pngdata = b'\x89PNG\r\n\x1a\nblahblahnotactuallyvalidIEND\xaeB`\x82' jpegdata = b'\xff\xd8\xff\xe0\x00\x10JFIFblahblahjpeg(\xa0\x0f\xff\xd9' fmt = { 'image/png' : pngdata, 'image/jpeg' : jpegdata, } encoded = encode_images(fmt) for key, value in fmt.iteritems(): # encoded has unicode, want bytes decoded = decodestring(encoded[key].encode('ascii')) yield nt.assert_equal(decoded, value) encoded2 = encode_images(encoded) yield nt.assert_equal(encoded, encoded2) b64_str = {} for key, encoded in encoded.iteritems(): b64_str[key] = unicode_to_str(encoded) encoded3 = encode_images(b64_str) yield nt.assert_equal(encoded3, b64_str) for key, value in fmt.iteritems(): # encoded3 has str, want bytes decoded = decodestring(str_to_bytes(encoded3[key])) yield nt.assert_equal(decoded, value)
Example #21
Source File: test_email.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_encoding(self): payload = self._au.get_payload() self.assertEqual(base64.decodestring(payload), self._audiodata)
Example #22
Source File: px.py From px with MIT License | 5 votes |
def b64decode(val): try: return base64.decodebytes(val.encode("utf-8")) except AttributeError: return base64.decodestring(val)
Example #23
Source File: rich_ipython_widget.py From Computable with MIT License | 5 votes |
def _handle_display_data(self, msg): """ Overridden to handle rich data types, like SVG. """ if not self._hidden and self._is_from_this_session(msg): source = msg['content']['source'] data = msg['content']['data'] metadata = msg['content']['metadata'] # Try to use the svg or html representations. # FIXME: Is this the right ordering of things to try? if 'image/svg+xml' in data: self.log.debug("display: %s", msg.get('content', '')) svg = data['image/svg+xml'] self._append_svg(svg, True) elif 'image/png' in data: self.log.debug("display: %s", msg.get('content', '')) # PNG data is base64 encoded as it passes over the network # in a JSON structure so we decode it. png = decodestring(data['image/png'].encode('ascii')) self._append_png(png, True, metadata=metadata.get('image/png', None)) elif 'image/jpeg' in data and self._jpg_supported: self.log.debug("display: %s", msg.get('content', '')) jpg = decodestring(data['image/jpeg'].encode('ascii')) self._append_jpg(jpg, True, metadata=metadata.get('image/jpeg', None)) else: # Default back to the plain text representation. return super(RichIPythonWidget, self)._handle_display_data(msg) #--------------------------------------------------------------------------- # 'RichIPythonWidget' protected interface #---------------------------------------------------------------------------
Example #24
Source File: base64_enc_dec.py From Some-Examples-of-Simple-Python-Script with GNU Affero General Public License v3.0 | 5 votes |
def _base64_decode_string(self, decode_string): #sample string: 'c3Nz\n' decoder = base64.decodestring(decode_string) return decoder
Example #25
Source File: test_stdmodules.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_cp5566(self): import base64 self.assertEqual(base64.decodestring('w/=='), '\xc3') test_str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789~!@#$%^&*()_+-=[]\{}|;':,.//<>?\"" test_str+= "/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/A/B/C/D/E/F/G/H/I/J/K/L/M/N/O/P/Q/R/S/T/U/V/W/X/Y/Z/0/1/2/3/4/5/6/7/8/9/~/!/@/#/$/%/^/&/*/(/)/_/+/-/=/[/]/\/{/}/|/;/'/:/,/.///</>/?\"" for str_function in [str, unicode]: self.assertEqual(base64.decodestring(str_function(test_str)), 'i\xb7\x1dy\xf8!\x8a9%\x9az)\xaa\xbb-\xba\xfc1\xcb0\x01\x081\x05\x18r\t(\xb3\r8\xf4\x11I5\x15Yv\x19\xd3]\xb7\xe3\x9e\xbb\xf3\xdf')
Example #26
Source File: test_gettext.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_plural_form_error_issue17898(self): with open(MOFILE, 'wb') as fp: fp.write(base64.decodestring(GNU_MO_DATA_ISSUE_17898)) with open(MOFILE, 'rb') as fp: # If this runs cleanly, the bug is fixed. t = gettext.GNUTranslations(fp)
Example #27
Source File: test_gettext.py From ironpython2 with Apache License 2.0 | 5 votes |
def setUp(self): if not os.path.isdir(LOCALEDIR): os.makedirs(LOCALEDIR) with open(MOFILE, 'wb') as fp: fp.write(base64.decodestring(GNU_MO_DATA)) with open(UMOFILE, 'wb') as fp: fp.write(base64.decodestring(UMO_DATA)) with open(MMOFILE, 'wb') as fp: fp.write(base64.decodestring(MMO_DATA)) self.env = test_support.EnvironmentVarGuard() self.env['LANGUAGE'] = 'xx' gettext._translations.clear()
Example #28
Source File: test_base64.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_decodestring(self): eq = self.assertEqual eq(base64.decodestring("d3d3LnB5dGhvbi5vcmc=\n"), "www.python.org") eq(base64.decodestring("YQ==\n"), "a") eq(base64.decodestring("YWI=\n"), "ab") eq(base64.decodestring("YWJj\n"), "abc") eq(base64.decodestring("YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE" "RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0\nNT" "Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==\n"), "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789!@#0^&*();:<>,. []{}") eq(base64.decodestring(''), '') # Non-bytes eq(base64.decodestring(bytearray("YWJj\n")), "abc")
Example #29
Source File: markov.py From indras_net with GNU General Public License v3.0 | 5 votes |
def from_json(self, json_input): # get the encoded json dump enc = json_input["matrix"] # build the numpy data type dataType = np.dtype(enc[0]) # decode the base64 encoded numpy array data and create a new numpy array with this data & type dataArray = np.frombuffer(base64.decodestring(enc[1].encode('utf-8')), dataType) # if the array had more than one data set it has to be reshaped if len(enc) > 2: dataArray = dataArray.reshape(enc[2]) # return the reshaped numpy array containing several data sets self.matrix = np.matrix(dataArray)
Example #30
Source File: UTscapy.py From CyberScan with GNU General Public License v3.0 | 5 votes |
def get_local(self): return bz2.decompress(base64.decodestring(self.local))