예제 #1
0
def main(args=None):
    print('Use extension: %r' % b64._has_extension)
    with open(sys.argv[1], mode='rb') as f:
        filecontent = f.read()
    start = timer()
    encodedcontent = b64.standard_b64encode(filecontent)
    end = timer()
    print('pybase64.standard_b64encode: %8.5f s' % (end - start))
    start = timer()
    decodedcontent = b64.standard_b64decode(encodedcontent)
    end = timer()
    print('pybase64.standard_b64decode: %8.5f s' % (end - start))
    if not decodedcontent == filecontent:
        print('error got %d bytes, expected %d bytes' %
              (len(decodedcontent), len(filecontent)))
    start = timer()
    encodedcontent = base64.standard_b64encode(filecontent)
    end = timer()
    print('base64.standard_b64encode: %8.5f s' % (end - start))
    start = timer()
    decodedcontent = base64.standard_b64decode(encodedcontent)
    end = timer()
    print('base64.standard_b64decode: %8.5f s' % (end - start))
    if not decodedcontent == filecontent:
        print('error got %d bytes, expected %d bytes' %
              (len(decodedcontent), len(filecontent)))
예제 #2
0
 def test_standard_roundtrip(self):
     '''
     Round trip shall return identity
     '''
     self.assertEqual(
         pybase64.standard_b64decode(
             pybase64.standard_b64encode(b'this is a test')),
         b'this is a test')
예제 #3
0
    def emit_frame(self, drawn_frame, cam):
        encoded, buffer = cv2.imencode('.jpg', drawn_frame,
                                       [int(cv2.IMWRITE_JPEG_QUALITY), 20])
        base64_frame = pybase64.standard_b64encode(buffer)

        self.App.Sockets.Client.emit('frame', {
            'cam_id': cam.getId(),
            'body': base64_frame
        })
예제 #4
0
 async def tobase64(self, ctx, encoding: Optional[PySupportedEncoding], *,
                    text: str):
     """Encode text to Base64"""
     if not encoding:
         encoding = "utf-8"
     text = text.encode(encoding=encoding, errors="replace")
     output = pybase64.standard_b64encode(text)
     result = output.decode()
     for page in chat.pagify(result):
         await ctx.send(chat.box(page))
예제 #5
0
def tx_send(ComPort):
    logger.info('Starting TX thread with ID: ' + str(tx_thread.ident))
    mqtt_tx=MqttClient.Client('mqtt_tx')
    try:
        logger.info('Trying to connect to MQTT broker @ ' + mqtt_ip + ':' + mqtt_port)
        mqtt_tx.connect(mqtt_ip, int(mqtt_port))
        logger.info('Connected to MQTT broker @ ' + mqtt_ip + ':' + mqtt_port)
    except Exception as e:
        logger.error(e)
        logger.error('TX thread now will exit and application will terminate from the main thread')
        IPC_Queue.put('E:' + str(tx_thread.ident) + ':10')
    while True:
        payload = ComPort.readline().strip().decode('utf-8')
        if payload=='':
            pass
        else:
            mqtt_tx.publish('device/' + device_id, pybase64.standard_b64encode(payload.encode('utf-8')))
            logger.info('Wrote payload to MQTT broker - payload is: ' + str(pybase64.standard_b64encode(payload.encode('utf-8'))))
        time.sleep(0.2)
예제 #6
0
    def emit_event(self, event, frame):
        encoded, buffer = cv2.imencode('.jpg', frame.frame,
                                       [int(cv2.IMWRITE_JPEG_QUALITY), 20])
        base64_frame = pybase64.standard_b64encode(buffer)

        self.App.Sockets.Client.emit('event', {
            'cam_id': frame.Cam.getId(),
            'body': event,
            'frame': base64_frame
        })
예제 #7
0
    def unpack(self, payload, offset, length):
        res, offset, length = self._unpack_members(payload, offset, length)

        res['preamble'] = self.preamble
        res['msg_type'] = self.msg_type
        res['sender'] = self.sender
        if self.payload is not None:
            res['payload'] = standard_b64encode(
                self.payload.tobytes()).decode('ascii')
        res['crc'] = self.crc
        res['length'] = self.length
        return res, offset, length
예제 #8
0
 async def tobase64(self, ctx, encoding: Optional[PySupportedEncoding], *,
                    text: str):
     """Encode text to Base64"""
     if not encoding:
         encoding = "utf-8"
     try:
         text = text.encode(encoding=encoding, errors="replace")
     except UnicodeError:
         await ctx.send(
             chat.error(
                 _("Unable to encode provided string to `{}` encoding.").
                 format(encoding)))
         return
     output = pybase64.standard_b64encode(text)
     result = output.decode()
     for page in chat.pagify(result):
         await ctx.send(chat.box(page))
예제 #9
0
from github import Github

new_repo = "newRepository"
g = Github("b678440c02e85ae287d3ec8ececedf4f4c208920")
user = g.get_user()

repo = g.get_user().get_repo(new_repo)
print(repo)

file = repo.get_file_contents("/path.txt")

print(file)

file_content = "To protect your rights, we need to prevent others from denying you \
these rights or asking you to surrender the rights.  Therefore, you have\
certain responsibilities if you distribute copies of the software, or if\
you modify it: responsibilities to respect the freedom of others\
For example, if you distribute copies of such a program, whether\
gratis or for a fee, you must pass on to the recipients the same\
freedoms that you received.  You must make sure that they, too, receive\
or can get the source code.  And you must show them these terms so they\
know their rights."

# update
repo.update_file("/path.txt", "your_commit_message", file_content, file.sha)
'''
import pybase64

string_base64 = b'i have tried to add some data to my file'
print(pybase64.standard_b64encode(string_base64))
예제 #10
0
 def test_standard_b64encode(self):
     '''
     standard_b64encode shall give the same result as base64 built-in module
     '''
     self.assertEqual(pybase64.standard_b64encode(b'this is a test'),
                      base64.standard_b64encode(b'this is a test'))
예제 #11
0
import pybase64

cluster = Cluster(['cassandra'])
session = cluster.connect()
app = Flask(__name__, instance_relative_config=True)

app.config.from_object('config')
app.config.from_pyfile('config.py')

#The twitter API requires a single key that is a string of a base64 encoded version
#of the two keys separated by a colon
client_key = app.config['CLIENT_KEY']
client_secret = app.config['CLIENT_SECRET']

key_secret = '{}:{}'.format(client_key, client_secret).encode('ascii')
b64_encoded_key = pybase64.standard_b64encode(key_secret).decode('ascii')


#/database/search/ returns the list of all tweets in the stored database through GET request
@app.route('/database/search/', methods=['POST', 'GET'])
def databasesearch():
    q = "Select * From tweettable.stats"
    q = list(session.execute(q))
    return jsonify(list(q))


#The UI asks user to enter the query in the URL
@app.route('/database')
def welcome():
    return (
        '<h1>Hello, Enter in the URL to search the saved tweets: database/{query} </h1>'
예제 #12
0
 def createBase64ID(self):
     encodedID = pybase64.standard_b64encode((self.client_id + ":" + self.client_secret).encode('ascii'))
     return encodedID.decode()
예제 #13
0
def b64encode(value):
    return pybase64.standard_b64encode(str.encode(value)).decode('utf-8')
예제 #14
0
from string import ascii_lowercase
from collections import Counter
import time
import os
import sys
import codecs


mode = False
while True:
    askmode = str(input("type encrypt to type a new message in, type decrypt to solve an existing message: "))
    #askey = str(input("insert key: "))
    if askmode == "encrypt":
        enterpass = str(input("message: "))
        encodedpass = enterpass.encode('utf-8')
        cr = pybase64.standard_b64encode(encodedpass)
        cr = cr.decode('utf-8')
        cr = codecs.encode(cr)
        print(cr)
    if askmode == "decrypt":
        enterpass = str(input("message: "))
        enterpass = codecs.decode(cr)
        enterpass = pybase64.standard_b64decode(enterpass)
        enterpass = str(enterpass)
        enterpass = enterpass[2:]
        enterpass = enterpass[:-1]
        #enterpass = enterpass + str(askey*9)
        print(enterpass)
        #enterpass = "******"