예제 #1
0
 def storeAssociation(self, server_url, association):
     try:
         assoc = Association.objects.get(server_url=server_url,
                                         handle=association.handle)
     except Association.DoesNotExist:
         assoc = Association(server_url=server_url,
                             handle=association.handle,
                             secret=base64.encodestring(association.secret),
                             issued=association.issued,
                             lifetime=association.lifetime,
                             assoc_type=association.assoc_type)
     else:
         assoc.secret = base64.encodestring(association.secret)
         assoc.issued = association.issued
         assoc.lifetime = association.lifetime
         assoc.assoc_type = association.assoc_type
     assoc.save()
예제 #2
0
파일: store.py 프로젝트: 15580056814/hue
 def storeAssociation(self, server_url, association):
     try:
         assoc = Association.objects.get(
             server_url=server_url, handle=association.handle)
     except Association.DoesNotExist:
         assoc = Association(
             server_url=server_url,
             handle=association.handle,
             secret=base64.encodestring(association.secret),
             issued=association.issued,
             lifetime=association.lifetime,
             assoc_type=association.assoc_type)
     else:
         assoc.secret = base64.encodestring(association.secret)
         assoc.issued = association.issued
         assoc.lifetime = association.lifetime
         assoc.assoc_type = association.assoc_type
     assoc.save()
예제 #3
0
 def storeAssociation(self, server_url, association):
     try:
         assoc = Association.objects.get(
             server_url=server_url, handle=association.handle)
         if isinstance(assoc.secret, str) and PY3:
             try:
                 assoc.secret = assoc.secret.split("b'")[1].split("'")[0]
             except Exception:
                 pass
             assoc.secret = bytes(assoc.secret, 'utf-8')
     except Association.DoesNotExist:
         if isinstance(association.secret, str) and PY3:
             association.secret = association.secret.split("b'")[1].split("'")[0]
             association.secret = bytes(association.secret, 'utf-8')
         if PY3:
             secret = base64.encodebytes(association.secret)
         else:
             secret = base64.encodestring(association.secret)
         assoc = Association(
             server_url=server_url,
             handle=association.handle,
             secret=secret,
             issued=association.issued,
             lifetime=association.lifetime,
             assoc_type=association.assoc_type)
     else:
         if isinstance(assoc.secret, str) and PY3:
             try:
                 assoc.secret = assoc.secret.split("b'")[1].split("'")[0]
             except Exception:
                 pass
             assoc.secret = bytes(assoc.secret, 'utf-8')
         if PY3:
             secret = base64.encodebytes(association.secret)
         else:
             secret = base64.encodestring(association.secret)
         assoc.secret = secret
         assoc.issued = association.issued
         assoc.lifetime = association.lifetime
         assoc.assoc_type = association.assoc_type
     if isinstance(assoc.secret, bytes) and PY3:
         assoc.secret = bytes(assoc.secret.decode('utf-8').rstrip(), 'utf-8')
     assoc.save()