#NEWLINE# def pem( b , name ) : #NEWLINE# #INDENT# 'Encode a payload bytearray into a PEM string.\n    \n    The input will be base64 encoded, then wrapped in a PEM prefix/postfix\n    based on the name string, e.g. for name="CERTIFICATE"::\n    \n        -----BEGIN CERTIFICATE-----\n        MIIBXDCCAUSgAwIBAgIBADANBgkqhkiG9w0BAQUFADAPMQ0wCwYDVQQDEwRUQUNL\n        ...\n        KoZIhvcNAQEFBQADAwA5kw==\n        -----END CERTIFICATE-----\n    ' #NEWLINE# s1 = b2a_base64 ( b ) [ : ( - 1 ) ] #NEWLINE# s2 = '' #NEWLINE# while s1 : #NEWLINE# #INDENT# s2 += ( s1 [ : 64 ] + '\n' ) #NEWLINE# s1 = s1 [ 64 : ] #NEWLINE# #UNINDENT# s = ( ( ( '-----BEGIN %s-----\n' % name ) + s2 ) + ( '-----END %s-----\n' % name ) ) #NEWLINE# return s