Skip to content

Commit

Permalink
Move import statements
Browse files Browse the repository at this point in the history
  • Loading branch information
christoph2 committed Dec 22, 2018
1 parent 4888356 commit 0466bbf
Showing 1 changed file with 27 additions and 26 deletions.
53 changes: 27 additions & 26 deletions pyxcp/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

__copyright__="""
__copyright__ = """
pySART - Simplified AUTOSAR-Toolkit for Python.
(C) 2009-2018 by Christoph Schueler <cpu12.gems@googlemail.com>
Expand All @@ -24,16 +24,19 @@
"""

import ctypes
import mmap
import os
import sys
import subprocess
import threading
import types

try:
import win32api, win32process, win32con
except ImportError:
winApi = False
WINAPI = False
else:
winApi = True
WINAPI = True


def hexDump(arr):
Expand Down Expand Up @@ -155,7 +158,6 @@ def __str__(self):
__repr__ = __str__


import subprocess

class CommandError(Exception):
pass
Expand Down Expand Up @@ -184,35 +186,34 @@ def __new__(cls, *args, **kws):
return cls._instance


class RepresentationMixIn(object):

def __repr__(self):
keys = [k for k in self.__dict__ if not (k.startswith('__') and k.endswith('__'))]
result = []
result.append("{0!s} {{".format(self.__class__.__name__))
for key in keys:
value = getattr(self, key)
if isinstance(value, (int, long)):
line = " {0!s} = 0x{1:X}".format(key, value)
elif isinstance(value, (float, types.NoneType)):
line = " {0!s} = {1!s}".format(key, value)
elif isinstance(value, array):
line = " {0!s} = {1!s}".format(key, helper.hexDump(value))
else:
line = " {0!s} = '{1!s}'".format(key, value)
result.append(line)
result.append("}")
return '\n'.join(result)

import mmap
# class RepresentationMixIn(object):
#
# def __repr__(self):
# keys = [k for k in self.__dict__ if not (k.startswith('__') and k.endswith('__'))]
# result = []
# result.append("{0!s} {{".format(self.__class__.__name__))
# for key in keys:
# value = getattr(self, key)
# if isinstance(value, (int, )):
# line = " {0!s} = 0x{1:X}".format(key, value)
# elif isinstance(value, (float, types.NoneType)):
# line = " {0!s} = {1!s}".format(key, value)
# elif isinstance(value, array):
# line = " {0!s} = {1!s}".format(key, hexDump(value))
# else:
# line = " {0!s} = '{1!s}'".format(key, value)
# result.append(line)
# result.append("}")
# return '\n'.join(result)
#

def memoryMap(filename, writeable = False):
size = os.path.getsize(filename)
fd = os.open(filename, os.O_RDWR if writeable else os.O_RDONLY)
return mmap.mmap(fd, size, access = mmap.ACCESS_WRITE if writeable else mmap.ACCESS_READ)


if sys.platform == "win32" and winApi:
if sys.platform == "win32" and WINAPI:

##
## Code snippet taken from http://code.activestate.com/recipes/496767-set-process-priority-in-windows/
Expand Down

0 comments on commit 0466bbf

Please sign in to comment.