Пример #1
0
def dictionary(dict_type='aspell', dict_language='en_GB'):
    wordlist = set()
    join = os.path.join
    fpath = join(susx._sussex_root, 'data', 'aspell', 'en-common.wl')
    with open(fpath, 'r') as fh:
        wordlist.union(_read_word_list(fh))

    if dict_type not in _dict_types:
        raise AttributeError('Unrecognized dictionary type (%s), must be '
                             'one of %s.' % (dict_type, ' '.join(_dict_types)))

    if dict_language not in _dict_languages:
        raise AttributeError('Unrecognized dictionary language (%s), must be '
                             'one of %s.' %
                             (dict_language, ' '.join(_dict_languages)))

    wl_files = []
    if dict_type == 'aspell':
        wl_files = os.listdir(os.path.join(susx._sussex_root, 'data',
                                           'aspell'))
        wl_files = [f for f in wl_files if f.startswith(dict_language)]
        for wl in wl_files:
            with open(join(susx._sussex_root, 'data', 'aspell', wl),
                      'r') as fh:
                wordlist = wordlist.union(_read_word_list(fh))

    return wordlist
Пример #2
0
    def __init__(self, name, problemStructureDict):
        threading.Thread.__init__(self, name=name)
        self.shutdownFlag = threading.Event()
        self._config = problemStructureDict[name]
        self.receiveQueue = Queue.Queue(maxsize=0)
        self.sendQueue = Queue.Queue(maxsize=0)
        self.listenThread = self._ReceiveingThread("%s-listener" % self.name,
                                                   self._config.port,
                                                   self.receiveQueue)
        self.sendThread = self._SendingThread("%s-sender" % self.name,
                                              self._config.sPort,
                                              self.sendQueue, self._config)
        self.others = problemStructureDict.copy()
        self._maxFaulty = int((len(self.others) - 1) / 3.0)
        if self.others.pop(self.name) is None:
            raise AttributeError("Did not find self in soluton")
        #Initialize self state
        self._state = None
        self._maxMessages = self._getMaxMessages(len(self.others) + 1)
        self._timeoutS = float(self._maxMessages * len(self.others)) * 0.02 + 3
        logger.info("Timeout set to %f seconds", self._timeoutS)
        self._timeoutTime = 0
        self._decision = None
        self._givenOrder = None
        self._decisionTree = None

        self._debugCounter = 0
        self._uniqueUpdates = 0
Пример #3
0
 def __delattr__(self, name):
     """ Deletes an attribute and updates hash
     """
     if name not in self._data_holder:
         raise AttributeError(name)
     del self._data_holder[name]
     self._update_hash()
Пример #4
0
 def __setattr__(self, key, value):
     if self._is_frozen and key in self._parent_names:
         raise AttributeError(
             "Class {} parents are frozen: cannot set {} = {}".format(
                 self.name, key, value))
     else:
         object.__setattr__(self, key, value)
Пример #5
0
 def __init__(self, size=None, palette=None):
     if size is not None:
         self.size = size
         self.cmap = np.empty((self.size, 3), dtype=np.uint8)
     elif palette is not None:
         self._buildPalette(palette)
     else:
         raise AttributeError("Invalid Colormap Initializer")
Пример #6
0
 def __getattr__(self, key):
     if key.startswith("_") or not key in self._meta.storage_attributes:
         raise AttributeError("Unknown attribute %s" % key)
     else:
         try:
             return self._storage_dict[key]
         except KeyError:
             attr = self._meta.storage_attributes[key]
             if attr.optional:
                 return None
             elif attr.default is not None:
                 if callable(attr.default):
                     return attr.default(self._storage_dict)
                 else:
                     return attr.default
             else:
                 log.error("Missing attribute %s, %s" % (key, self._storage_dict))
                 raise AttributeError("attribute %s not found" % key)
Пример #7
0
 def drawlines(self, path):
     if self.data is None:
         raise AttributeError("data or keypoint not initilized")
     import matplotlib
     matplotlib.use('Agg')
     from matplotlib import pyplot as plt
     ma = self.ma.as_matrix()
     plt.figure(1, figsize=(200, 20))
     xline = range(len(self.ma))
     yline = self.data_np[:, 0]
     plt.plot(xline, yline, 'r-')
     yline1 = ma[:, 0]
     plt.plot(xline, yline1, 'g-')
     plt.savefig(path)
Пример #8
0
    def translate(self, matrix, hue=None, colormap=None):
        if hue is None and colormap is None:
            raise AttributeError("Need either a hue or colormap")

        vmin = np.min(self.values)
        vmax = np.max(self.values)
        values = (self.values - vmin) / (vmax - vmin)

        if colormap is None:
            for x in range(self.width):
                for y in range(self.height):
                    color = hsvToRgb(hue + values[x, y] / 5, 1, values[x, y])
                    matrix.drawPixel(x, y, color)
        else:
            buffer = colormap.apply(values)
            matrix.copyBuffer(buffer)
Пример #9
0
 def add_parameter(self, name, classname):
     """ Helper to add a parameter's instance to your Test instance
     @param name: the name you want to give to this parameter
     @param module : name of the module/class to load (as string). Should be something like "filename.ClassName",
     the "path" of domogik will be appended
     @raise ImportError if the module can't be imported
     @raise AttributeError if a parameter with this name already exists
     """
     if name in self._parameters:
         raise AttributeError("A parameter instance already exists with this name")
     modonly = classname.split('.')[0]
     classonly = classname.split('.')[1]
     module_name = "domogik.scenario.parameters.{0}".format(modonly)
     #This may raise ImportError
     cname = getattr(__import__(module_name, fromlist = [modonly]), classonly)
     p = cname(log=self.log, trigger=self.cb_trigger)
     self._parameters[name] = p
Пример #10
0
 def drawlines(self, path):
     if self.data is None:
         raise AttributeError("data or keypoint not initilized")
     import matplotlib
     matplotlib.use('Agg')
     from matplotlib import pyplot as plt
     boll = self.boll.as_matrix()
     plt.figure(1, figsize=(200, 20))
     xline = range(len(self.boll))
     plt.subplot(2, 1, 1)
     yline = self.data_np[:, 0]
     plt.plot(xline, yline, 'r-')
     plt.subplot(2, 1, 2)
     yline1 = boll[:, 0]
     yline2 = boll[:, 1]
     yline3 = boll[:, 2]
     plt.plot(xline, yline1, 'r-')
     plt.plot(xline, yline2, 'g-')
     plt.plot(xline, yline3, 'b-')
     plt.savefig(path)
Пример #11
0
 def drawlines(self, path):
     if self.data is None or self.keypoint is None:
         raise AttributeError("data or keypoint not initilized")
     import matplotlib
     matplotlib.use('Agg')
     from matplotlib import pyplot as plt
     xline1 = [
         self.rsi.index.indexer_at_time(e)[0] for e in self.keypoint.index
     ]
     rsi = self.rsi.as_matrix()
     plt.figure(1, figsize=(200, 20))
     xline = range(len(self.rsi))
     plt.subplot(2, 1, 1)
     yline = self.data_np
     plt.plot(xline, yline, 'r-')
     plt.plot(xline1, yline[xline1], '*')
     plt.subplot(2, 1, 2)
     yline1 = rsi[:, 0]
     yline2 = rsi[:, 1]
     plt.plot(xline, yline2, 'y-')
     plt.plot(xline, yline1, 'r-')
     plt.plot(xline1, yline1[xline1], '*')
     plt.savefig(path)
Пример #12
0
 def __getattr__(self, name):
     if name not in self._data_holder:
         raise AttributeError(name)
     return self._data_holder[name]
Пример #13
0
 def __init__(self, path=''):
     if self.__tablename__ == '':
         from exceptions import AttributeError
         raise AttributeError('__tablename__ must be needed.')
     super(TableBase, self).__init__(path)