def randfunc(self, n): """Return a random string of n bytes (sic: not bits).""" check.check_has_type(n, types.IntType) str = curr = os.read(self.fildes, n) remaining = n - len(str) shown = 0 while remaining >= 0 and curr != '': if not shown: #utility.stdin_echo(0) print (_("Stalled while reading from %s; please generate some\n" + "randomness by moving the mouse around (assuming you're\n" + "running Circle locally) or typing randomly at the keyboard.") % dev_random_path) shown = 1 curr = os.read(self.fildes, remaining) str += curr remaining -= len(curr) if shown: #utility.stdin_echo(1) print _("\n\nHave enough randomness now, thanks.\n") check.check_assertion(remaining == 0) # If the above fails then either the random device is behaving # strangely (randomly?), or there's a bug in this code. # Either way, we'd prefer to die with check_assertion (and hopefully # have the bug reported) than silently continue with a broken # random number generation for cryptography. check.check_assertion(len(str) == n) return str
def __init__(self, fterm, start=None, end=None, next=None): """Field.__init__: fterm: a reference back to the owning FieldTerm object start: offset of the start of the field end: offset of the end of the field next: the next field in the list. action: this function is called when a mouse button is clicked in this field. """ if (start is not None or end is not None): check.check_has_type(start, types.IntType) check.check_has_type(end, types.IntType) fterm.lock.acquire() try: self.text='' self.fterm = fterm self.closed = 0 self.attr = {} self.active = 0 if start is not None: self.start = start self.end = end else: self.start = fterm.prompt_start self.end = fterm.prompt_start if next is not None: self.next = next self.prev = next.prev next.prev = self if self.prev: self.prev.next = self else: self.next = None self.prev = fterm.last_field if fterm.last_field is not None: fterm.last_field.next=self if fterm.first_field is None: fterm.first_field = self fterm.last_field=self finally: fterm.lock.release()
def show_gtk(self,str,tags=[],augmentation=None): """display text in the field. to be called from gtk thread only""" check.check_has_type(str, types.StringType) circle_gtk.check_is_gtkthread() if self.closed: return if type(tags) != type([]): tags = [tags] if tags == []: tags = [ "black" ] if type(str) == type(''): str = unicode(str,'ascii','replace') self.text = str change = len(str) - (self.end - self.start) self.offset_successors(change) self.gtk_show(str,tags,augmentation,self.start, self.end) self.end = self.end + change