예제 #1
0
def encode_string(encoding, data):
    encoded = data
    if encoding == 'base64':
        encoded = base64_encodebytes(data).decode('ascii')
    elif encoding == 'quoted-printable':
        encoded = quopri.encodestring(data).decode('ascii')
    return encoded
예제 #2
0
def get_signature(consumer_secret, sig_url):
    """Generate the has using customer secret key and create the digest
    :param sig_url:
    :param consumer_secret:
    """
    hmac_key = "{}&".format(consumer_secret)
    digest = hmac.new(hmac_key.encode('utf-8'), sig_url.encode('utf-8'), digestmod=hashlib.sha1).digest()
    sig = base64_encodebytes(digest).rstrip()  # Encode string, dropping the leading
    return sig
예제 #3
0
 def set_basic_auth(self, user_name, password):
     """Set basic authentication"""
     u_p = ("%s:%s" % (user_name, password)).encode("utf8")
     b64 = base64_encodebytes(u_p)
     # encodestring() returns a bytestring. We want a native str on Python 3
     if not type(b64) is str:
         b64 = b64.decode("utf8")
     auth = "Basic %s" % b64.strip()
     self._username = user_name
     self._password = password
     self.headers["Authorization"] = auth
예제 #4
0
파일: davclient.py 프로젝트: mar10/wsgidav
 def set_basic_auth(self, user_name, password):
     """Set basic authentication"""
     u_p = ("%s:%s" % (user_name, password)).encode("utf8")
     b64 = base64_encodebytes(u_p)
     # encodestring() returns a bytestring. We want a native str on Python 3
     if not type(b64) is str:
         b64 = b64.decode("utf8")
     auth = "Basic %s" % b64.strip()
     self._username = user_name
     self._password = password
     self.headers["Authorization"] = auth
예제 #5
0
def get_signature(consumer_secret, sig_url):
    """Generate the has using customer secret key and create the digest
    :param sig_url:
    :param consumer_secret:
    """
    hmac_key = "{}&".format(consumer_secret)
    digest = hmac.new(hmac_key.encode('utf-8'),
                      sig_url.encode('utf-8'),
                      digestmod=hashlib.sha1).digest()
    sig = base64_encodebytes(
        digest).rstrip()  # Encode string, dropping the leading
    return sig
예제 #6
0
파일: yagpy.py 프로젝트: vitaly-krugl/yagpy
    def _encode_basic_auth(user, password):
        """base64-encode Basic Authentication header value

        :param str user:
        :param str password:
        :return: Basic Authentication header value
        :rtype: str
        """
        # NOTE: encodebytes adds a trailing newline that we don't want
        cred = base64_encodebytes(  # pylint: disable=W1505
            '{}:{}'.format(user, password).encode()).decode().rstrip('\n')

        return 'Basic {}'.format(cred)
예제 #7
0
파일: xmldom.py 프로젝트: srand/jolt
 def child_set(self, value):
     _check_value(value, values)
     if value is None:
         return
     if not hasattr(self, '_' + varname):
         e = SubElement(attribute)
         self.append(e)
         setattr(self, '_' + varname, e)
     if base64:
         value = value.encode()
         if zlib:
             value = codecs.encode(value, "zlib")
         value = base64_encodebytes(value).decode()
     getattr(self, '_' + varname).text = value
예제 #8
0
파일: xmldom.py 프로젝트: srand/jolt
 def attr_set(self, value):
     if value is None:
         try:
             self.attrib.pop(attribute)
         except Exception:
             pass
         finally:
             return
     _check_value(value, values)
     if base64:
         value = value.encode()
         if zlib:
             value = codecs.encode(value, "zlib")
         value = base64_encodebytes(value).decode()
     return self.set(attribute, value)
예제 #9
0
 def test_to_message_multipart_with_b64encoding(self):
     from pyramid_mailer.response import MIMEPart
     response = self._makeOne(To='To', From='From', Subject='Subject',
                              Body='Body', Html='Html')
     try:
         from base64 import encodebytes as base64_encodebytes
         # pyflakes
         base64_encodebytes  # pragma: no cover
     except ImportError:  # pragma: no cover
         # BBB Python 2 compat
         from base64 import encodestring as base64_encodebytes
     import os
     this = os.path.abspath(__file__)
     data = self._read_filedata(this, mode='rb')
     response = self._makeOne()
     response.attach(filename=this, content_type='text/plain',
                     disposition='disposition', transfer_encoding='base64')
     message = response.to_message()
     self.assertEqual(message.__class__, MIMEPart)
     payload = message.get_payload()[0]
     self.assertEqual(payload.get('Content-Transfer-Encoding'), 'base64')
     self.assertEqual(payload.get_payload(),
                      base64_encodebytes(data).decode('ascii'))
예제 #10
0
def encode_label(args):
    return base64_encodebytes(pickle.dumps(args)).strip().decode('latin1')