Example #1
0
def render_element(tag, value, redact=False):
    if type(tag) == Tag:
        tag = tag.id

    if redact and tag in SENSITIVE_TAGS:
        return '[REDACTED]'

    if type(value).__name__ in ('TLV', 'DOL', 'TagList'):
        return repr(value)
    parse = ELEMENT_FORMAT.get(tag)
    if parse is None:
        return format_bytes(value)
    if parse == Parse.ASCII:
        return '"' + ''.join(map(chr, value)) + '"'
    if parse == Parse.DEC:
        return str(from_hex_int(value))
    if parse == Parse.DATE:
        return from_hex_date(value)
    if parse == Parse.INT:
        return str(decode_int(value))
    if parse == Parse.COUNTRY:
        return pycountry.countries.get(numeric=str(from_hex_int(value))).alpha_2
    if parse == Parse.CURRENCY:
        return pycountry.currencies.get(numeric=str(from_hex_int(value))).alpha_3
    if parse == Parse.HEX:
        return str(hex_int(value))
    return format_bytes(value)
Example #2
0
def download_and_install(url):
    """
    Downloads and launches the specified file.
    """
    global update_window, url_opener
    try:
        is_cancelled = False
        parent = wx.GetApp().TopWindow
        filename, tmp_dir = os.path.split(url)[-1], tempfile.mkdtemp()
        dlg_progress = \
            controls.ProgressWindow(parent, "Downloading %s" % filename)
        dlg_progress.SetGaugeForegroundColour(conf.GaugeColour)
        dlg_progress.Position = (parent.Position.x + parent.Size.width -
                                 dlg_progress.Size.width, parent.Position.y +
                                 parent.Size.height - dlg_progress.Size.height)
        update_window = dlg_progress
        urlfile = url_opener.open(url)
        filepath = os.path.join(tmp_dir, filename)
        main.log("Downloading %s to %s.", url, filepath)
        filesize = int(urlfile.headers.get("content-length", sys.maxint))
        with open(filepath, "wb") as f:
            BLOCKSIZE = 65536
            bytes_downloaded = 0
            buf = urlfile.read(BLOCKSIZE)
            while len(buf):
                f.write(buf)
                bytes_downloaded += len(buf)
                percent = 100 * bytes_downloaded / filesize
                msg = "%d%% of %s" % (percent, util.format_bytes(filesize))
                is_cancelled = not dlg_progress.Update(percent, msg)
                if is_cancelled:
                    break  # break while len(buf)
                wx.YieldIfNeeded()
                buf = urlfile.read(BLOCKSIZE)
        dlg_progress.Destroy()
        update_window = None
        if is_cancelled:
            main.log("Upgrade cancelled, erasing temporary file %s.", filepath)
            util.try_until(lambda: os.unlink(filepath))
            util.try_until(lambda: os.rmdir(tmp_dir))
        else:
            main.log("Successfully downloaded %s of %s.",
                     util.format_bytes(filesize), filename)
            dlg_proceed = controls.NonModalOKDialog(
                parent, "Update information",
                "Ready to open %s. You should close %s before upgrading." %
                (filename, conf.Title))

            def proceed_handler(event):
                global update_window
                update_window = None
                dlg_proceed.Destroy()
                util.start_file(filepath)

            update_window = dlg_proceed
            dlg_proceed.Bind(wx.EVT_CLOSE, proceed_handler)
    except Exception:
        main.log("Failed to download new version from %s.\n\n%s", url,
                 traceback.format_exc())
Example #3
0
def download_and_install(url):
    """
    Downloads and launches the specified file.
    """
    global update_window, url_opener
    try:
        is_cancelled = False
        parent = wx.GetApp().TopWindow
        filename, tmp_dir = os.path.split(url)[-1], tempfile.mkdtemp()
        dlg_progress = \
            controls.ProgressWindow(parent, "Downloading %s" % filename)
        dlg_progress.SetGaugeForegroundColour(conf.GaugeColour)
        dlg_progress.Position = (
            parent.Position.x + parent.Size.width  - dlg_progress.Size.width,
            parent.Position.y + parent.Size.height - dlg_progress.Size.height)
        update_window = dlg_progress
        urlfile = url_opener.open(url)
        filepath = os.path.join(tmp_dir, filename)
        main.log("Downloading %s to %s.", url, filepath)
        filesize = int(urlfile.headers.get("content-length", sys.maxint))
        with open(filepath, "wb") as f:
            BLOCKSIZE = 65536
            bytes_downloaded = 0
            buf = urlfile.read(BLOCKSIZE)
            while len(buf):
                f.write(buf)
                bytes_downloaded += len(buf)
                percent = 100 * bytes_downloaded / filesize
                msg = "%d%% of %s" % (percent, util.format_bytes(filesize))
                is_cancelled = not dlg_progress.Update(percent, msg)
                if is_cancelled:
                    break # break while len(buf)
                wx.YieldIfNeeded()
                buf = urlfile.read(BLOCKSIZE)
        dlg_progress.Destroy()
        update_window = None
        if is_cancelled:
            main.log("Upgrade cancelled, erasing temporary file %s.", filepath)
            util.try_until(lambda: os.unlink(filepath))
            util.try_until(lambda: os.rmdir(tmp_dir))
        else:
            main.log("Successfully downloaded %s of %s.",
                     util.format_bytes(filesize), filename)
            dlg_proceed = controls.NonModalOKDialog(parent,
                "Update information",
                "Ready to open %s. You should close %s before upgrading."
                % (filename, conf.Title))
            def proceed_handler(event):
                global update_window
                update_window = None
                dlg_proceed.Destroy()
                util.start_file(filepath)
            update_window = dlg_proceed
            dlg_proceed.Bind(wx.EVT_CLOSE, proceed_handler)
    except Exception:
        main.log("Failed to download new version from %s.\n\n%s", url,
                 traceback.format_exc())
Example #4
0
    def transmit(self, raw_data):
        """ Send raw data to the card, and receive the reply.

            tx_data should be a list of bytes.

            Returns a tuple of (data, sw1, sw2) where sw1 and sw2
            are the protocol status bytes.
        """
        self.log.debug('Raw_Data: %s', format_bytes(raw_data))
        data, sw1, sw2 = self.connection.transmit(raw_data)
        self.log.debug('Response_Data: %s, SW1: %02x, SW2: %02x',
                       format_bytes(data), sw1, sw2)
        return data, sw1, sw2
Example #5
0
    def __repr__(self):
        if type(self.value) == list:
            val = format_bytes(self.value)
        else:
            val = '%02X' % self.value

        if self.name:
            return '(%s) %s' % (val, self.name)
        else:
            return val
Example #6
0
def getFileInfo():
    path = request.args["path"]
    userId, profile = verify()
    if userId and profile:
        try:

            sftp = profile.connect()
            stats = sftp.lstat(path)
            created = datetime.datetime.fromtimestamp(stats.st_atime)
            modified = datetime.datetime.fromtimestamp(stats.st_mtime)

            return jsonify({
                "size": format_bytes(stats.st_size),
                "created": created,
                "last_modified": modified,
                "path": path,
                "name": path.split('/')[-1],
                "permission": '',
                "isFile": sftp.isfile(path)
            })
        except Exception as ex:
            return Response(False)
    else:
        return jsonify("Invalid profile"), 500
Example #7
0
import numpy as np
import util

path = "/media/rico/Data/TU/thesis/data/Random_Delay/"
traces_path = path + "traces/"
traces_filename = traces_path + "traces_complete.csv.npy"

model_path = path + "Value/"
model_filename = model_path + "model.csv.npy"
model_csv_filename = model_path + "model.csv"

x = np.load(model_filename)
x = x.reshape((50000, ))
print(x.shape)
print(x)
print("mem usage {}".format(util.format_bytes(util.get_memory())))

y_train = util.load_csv(model_csv_filename,
                        delimiter=' ',
                        dtype=np.long,
                        start=0,
                        size=50000)

print(y_train.shape)
print(y_train)
for i in range(len(y_train)):
    if x[i] != y_train[i]:
        print("Error at {}".format(i))
Example #8
0
 def __repr__(self):
     return '<Command[%s] P1:%02x,P2:%02x, data: %s, Le: %02x>' % (
         self.name,self.p1,self.p2,format_bytes(self.data),self.le or 0)