def archive_sql_protocol(user): """Löscht die Daten aus der Protokolltabelle und schreibt sie in eine Archivdatei. Code weitestgehend von MSG übernommen.""" tmp_yek = "2001.12.31" # ?? :-) # diesen abschnitt. hier wird zu erst in eine datei archiviert, dann gelöscht # zeit generieren und fileobjekt erstellen. local_time_insec = time.time() local_time_tupel = time.localtime(local_time_insec) zeitstempel = time.strftime("%d%m%y%H%M%S", local_time_tupel) zeitstempel2 =time.strftime("%d.%m.%y um %H:%M:%S", local_time_tupel) pfad = os.path.join(config.PROTOCOL_DIR, zeitstempel + ".txt") #if os.exists(PROTOCOL_DIR) != true: #mkdir(PROTOCOL_DIR) fdatei = open(pfad, "wb") # jede zeile aus der protokolltabelle wird in die datei geschrieben protokolleintraege = ProtokollList(where = '', order='nr') rot = rotor.newrotor(tmp_yek) from ebkus.app_surface.protokoll_templates import datei_t for p in protokolleintraege: fdatei.write(rot.encryptmore(datei_t % p)) fdatei.write(rot.encryptmore('<br>')) fdatei.write(rot.encryptmore("""<br>****************************<br> Die Protokolltabellen wurden am %s von %s geloescht und in die Datei %s archiviert. <br>****************************<br>""" % (zeitstempel2, user, pfad))) fdatei.close() # Maxist protokolltabelle wird gesetzt tab = Tabelle(tabelle='protokoll') tab.update({'maxist': 0}) # protokolltabelle wird gelöscht protokolleintraege2 = ProtokollList(where = '') protokolleintraege2.deleteall()
def __init__(self): """Create and grid several components into the frame""" Frame.__init__(self) self.grid(sticky=W + E + N + S) self.master.title("Python Encryption and Decryption") self.master.rowconfigure(0, weight=1) self.master.columnconfigure(0, weight=1) self.button1 = Button(self, text="Encrypt", width=15, command=self.encrypt) # specify position of Button component button1 self.button1.grid(row=0, column=1, sticky=W + E + N + S) self.button2 = Button(self, text="Decrypt", width=15, command=self.decrypt) self.button2.grid(row=0, column=2, sticky=W + E + N + S) self.text1 = Text(self, width=30, height=15) # text component spans three rows and all available space self.text1.grid(row=3, column=1, columnspan=2, sticky=W + E + N + S) self.text1.insert(INSERT, "Text") # makes second row/column expand self.rowconfigure(1, weight=1) self.columnconfigure(1, weight=1) self.ciper = rotor.newrotor("deitelkey", 12)
def decrypt(data): key_a = "!@#$%^&*" key_b = "abcdefgh" key_c = '<>{}:"' secret = key_a*4 + '|' + (key_b + key_a + key_c)*2 + '|' + key_b*2 + 'EOF' rot = rotor.newrotor(secret) return rot.decrypt(data)
def __init__(self, f, rot): self._c=zlib.decompressobj() self._b='' if type(rot) is type(''): rot=rotor.newrotor(rot) self._rot=rot rot.decrypt('') self._f=f
def Save_Cycle(name='cycle', passwd='123', file='cycle'): """ Save the contents of our document to disk. """ objSave = [] m = hashlib.md5() m.update(passwd) rt = rotor.newrotor(m.digest()) objSave.append(['period', cal_year.cycle.period]) objSave.append(['by_average', cal_year.cycle.by_average]) objSave.append(['disp', cal_year.cycle.disp]) objSave.append(['first_week_day', cal_year.cycle.first_week_day]) objSave.append(['note', cal_year.cycle.note]) for d in cal_year.cycle.begin: objSave.append(['begin', [d.GetDay(), d.GetMonth(), d.GetYear()]]) for d in cal_year.cycle.last: objSave.append(['last', [d.GetDay(), d.GetMonth(), d.GetYear()]]) for d in cal_year.cycle.tablet: objSave.append(['tablet', [d.GetDay(), d.GetMonth(), d.GetYear()]]) for d in cal_year.cycle.colour_set.keys(): objSave.append(['colour', [d, cal_year.cycle.colour_set[d].Get()]]) tmp = rt.encrypt('Cycle' + cPickle.dumps(objSave)) tmp = "UserName="******"===" + tmp p, f_name = get_f_name(file) if not os.path.exists(p): os.mkdir(p, 0700) f = open(f_name, "wb") f.write(tmp) f.close()
def init_rotor(): asdf_dn = 'j2h56ogodh3se' asdf_dt = '=dziaq.' asdf_df = '|os=5v7!"-234' asdf_tm = asdf_dn * 4 + (asdf_dt + asdf_dn + asdf_df) * 5 + '!' + '#' + asdf_dt * 7 + asdf_df * 2 + '*' + '&' + "'" rot = rotor.newrotor(asdf_tm) return rot
def encrypt(data): key_a = "!@#$%^&*" key_b = "abcdefgh" key_c = "<>{}:\"" secret = key_a * 4 + '|' + ( (key_b + key_a) + key_c) * 2 + '|' + key_b * 2 + 'EOF' rot = rotor.newrotor(secret) return rot.encrypt(data)
def encrypt(data): key_a = '!@#$%^&*' key_b = 'abcdefgh' key_c = '<>{}:"' secret = '|' + key_b + key_a + key_c + '|' + key_b + 'EOF' rot = rotor.newrotor(secret)
def __init__(self, f, rot): self._c = zlib.decompressobj() self._b = '' if isinstance(rot, str): import rotor rot = rotor.newrotor(rot) self._rot = rot rot.decrypt('') self._f = f
def decrypt(data): key_a = '!@#$%^&*' key_b = 'abcdefgh' key_c = '<>{}:"' secret = key_a + key_b + key_c rot = rotor.newrotor(secret) return rot.decrypt(data)
def encrypt(data): key_a = '!@#$%^&*' key_b = 'abcdefgh' key_c = '<>{}:"' secret = key_a * 4 + '|' + (key_b + key_a + key_c) * 2 + '|' + key_b * 2 + 'EOF' print secret rot = rotor.newrotor(secret) return rot.encrypt(data)
def __init__(self, f, rot): self._c=zlib.decompressobj() self._b='' if isinstance(rot, str): import rotor rot=rotor.newrotor(rot) self._rot=rot rot.decrypt('') self._f=f
def unnpk(data): asdf_dn = 'j2h56ogodh3se' asdf_dt = '=dziaq.' asdf_df = '|os=5v7!"-234' asdf_tm = asdf_dn * 4 + (asdf_dt + asdf_dn + asdf_df) * 5 + '!' + '#' + asdf_dt * 7 + asdf_df * 2 + '*' + '&' + "'" import rotor rotor = rotor.newrotor(asdf_tm) data = rotor.decrypt(data) data = zlib.decompress(data) data = _reverse_string(data) return data
def Load_Cycle(name='cycle', passwd='123', file='cycle'): p, f_name = get_f_name(file) if os.path.isfile(f_name): m = hashlib.md5() m.update(passwd) rt = rotor.newrotor(m.digest()) f = open(f_name, "rb") tmp = f.read() if tmp[:len("UserName="******"UserName="******"===") + len("===") tmp = tmp[n:] #remove username tmp = rt.decrypt(tmp) f.close() if tmp[0:5] != 'Cycle': # print 'Password is invalid' return False else: tmp = tmp[5:] #remove control word 'Cycle' objLoad = cPickle.loads(tmp) set_color_default() for type, d in objLoad: # print "Load: ", type, d if type == 'period': cal_year.cycle.period = int(d) elif type == 'by_average': cal_year.cycle.by_average = int(d) elif type == 'disp': cal_year.cycle.disp = int(d) elif type == 'first_week_day': cal_year.cycle.first_week_day = int(d) elif type == 'begin': dt = wx.DateTimeFromDMY(d[0], d[1], d[2]) cal_year.cycle.begin.append(dt) elif type == 'last': dt = wx.DateTimeFromDMY(d[0], d[1], d[2]) cal_year.cycle.last.append(dt) elif type == 'tablet': dt = wx.DateTimeFromDMY(d[0], d[1], d[2]) cal_year.cycle.tablet.append(dt) elif type == 'note': cal_year.cycle.note = d.copy() elif type == 'colour': # d=['item', (r,g,b)] c = wx.Colour(d[1][0], d[1][1], d[1][2]) if cal_year.cycle.colour_set.has_key(d[0]): cal_year.cycle.colour_set[d[0]] = c else: cal_yaar.cycle.colour_set.update({d[0]: c}) # print "Load OK" return True
def _profileMe(): # Wrap a built-in C function. wrappedEval = wrap(eval) print wrappedEval('1+2*3') # Replace a C module with its wrapped equivalent. import os os = wrap(os) print os.getcwd() # Wrap a C object. import rotor r = wrap(rotor.newrotor('key')) print repr(r.encrypt('Plaintext'))
def _profileMe(): # Wrap a built-in C function. wrappedEval = wrap( eval ) print wrappedEval( '1+2*3' ) # Replace a C module with its wrapped equivalent. import os os = wrap( os ) print os.getcwd() # Wrap a C object. import rotor r = wrap( rotor.newrotor( 'key' ) ) print repr( r.encrypt( 'Plaintext' ) )
def crypt(key, s, decrypt): """En/decrypt a string with a key The technique here is still weak. We crypt with rotor to get a reasonable diffusion, then xor against an SHA-based key for stronger confusion, then rotor again to further diffuse the bytes """ import rotor r = rotor.newrotor(key, 12) if decrypt: rot = r.decrypt else: rot = r.encrypt xor = xor_key(key) s = rot(s) chars = [chr(ord(s[i]) ^ ord(xor[i])) for i in range(len(s))] s = "".join(chars) s = rot(s) return s
def crypt(key, s, decrypt): """En/decrypt a string with a key The technique here is still weak. We crypt with rotor to get a reasonable diffusion, then xor against an SHA-based key for stronger confusion, then rotor again to further diffuse the bytes """ import rotor r = rotor.newrotor(key, 12) if decrypt: rot = r.decrypt else: rot = r.encrypt xor = xor_key(key) s = rot(s) chars = [chr(ord(s[i])^ord(xor[i])) for i in range(len(s))] s = "".join(chars) s = rot(s) return s
import rotor f = open('encrypted_flag', 'rb') encrypted_flag = f.read() key_a = '!@#$%^&*' key_b = 'abcdefgh' key_c = '<>{}:"' secret = key_a * 4 + '|' + (key_b + key_a + key_c) * 2 + '|' + key_b * 2 + 'EOF' rt = rotor.newrotor(secret) rot = rt.decrypt(encrypted_flag) print 'Decrypted: ' print rot
import rotor r = rotor.newrotor("you'll never guess this") r = rotor.newrotor("you'll never guess this", 12) A = 'spam and eggs' B = 'cheese shop' a = r.encrypt(A) print ` a ` b = r.encryptmore(B) print ` b ` A1 = r.decrypt(a) print A1 if A1 != A: print 'decrypt failed' B1 = r.decryptmore(b) print B1 if B1 != B: print 'decryptmore failed' try: r.setkey() except TypeError: pass r.setkey('you guessed it!')
def Encrypt(self, cleartext, key): """override this function for your own crypto funcs""" rt = rotor.newrotor(key, 12) return rt.encrypt(cleartext)
def do_decode(pswd): robj = rotor.newrotor(mykey) return robj.decrypt(pswd)
import rotor SECRET_KEY = "spam" MESSAGE = "the holy grail" r = rotor.newrotor(SECRET_KEY) encoded_message = r.encrypt(MESSAGE) decoded_message = r.decrypt(encoded_message) print "original:", repr(MESSAGE) print "encoded message:", repr(encoded_message) print "decoded message:", repr(decoded_message) ## original: 'the holy grail' ## encoded message: '\227\271\244\015\305sw\3340\337\252\237\340U' ## decoded message: 'the holy grail'
def processForm(self, REQUEST, RESPONSE): # Formulardaten holen archivfiles = os.listdir(config.PROTOCOL_DIR) protokolleintrag = self.form.get('protokolleintrag') von_id = self.form.get('von_id') bis_id = self.form.get('bis_id') archivdatei = self.form.get('archiv_datei') protocolanaus = self.form.get('protocolanaus') # toggle Protokoll an/aus if protocolanaus == 'protocolanaus': if protocol.is_on(): protocol.off() anaustext = 'aus' else: protocol.on() anaustext = 'an' meldung = { 'titel':'Prokollierung', 'legende':'Protokollierung', 'url':'menu_protocol', 'zeile1':'Folgende Änderungen wurden durchgeführt:', 'zeile2':'Die Protokollierung wurde %sgeschaltet' % anaustext } return meldung_weiterleitung_t % meldung res = [] res.append(head_normal_ohne_help_t % ('Protokollansicht/-bearbeitung')) # Einzelanzeige if protokolleintrag: res.append(singleprotocolview_head_t) protokolleintraege = self.get_protokoll_eintraege(id_list=protokolleintrag) for p in protokolleintraege: res.append(singleprotocolview_mid_t % p) res.append(singleprotocolview_end_t) return ''.join(res) # Archivdatei anzeigen if archivdatei: # für Datumskonvertierung tmp_yek = "2001.12.31" archivfile = os.path.join(config.PROTOCOL_DIR, archivdatei) rot = rotor.newrotor(tmp_yek) fdatei1 = open(archivfile, "rb") line = fdatei1.readline() res.append(dateitop_t) while line: res.append( rot.decryptmore(line)) line = fdatei1.readline() res.append(dateiend_t) fdatei1.close() return ''.join(res) # Ansonsten Menu anzeigen if protocol.is_on(): anaustext = 'Aus' else: anaustext = 'An' protokolleintraege = self.get_protokoll_eintraege(von_id, bis_id) von_id = von_id or protokolleintraege and protokolleintraege[0]['nr'] or '0' bis_id = bis_id or protokolleintraege and protokolleintraege[-1]['nr'] or '0' res.append(auswahlprotocol_t % (anaustext, von_id, bis_id, self.get_max_id())) for p in protokolleintraege: res.append(protocolauswahl_t % p) res.append(protocolsubmit_t ) res.append(archivfile_head_t) files_to_sort = [(os.stat(os.path.join(config.PROTOCOL_DIR, f))[stat.ST_CTIME], f) for f in archivfiles] files_to_sort.sort() files_to_sort.reverse() for ctime, afile in files_to_sort: dateides = os.stat(os.path.join(config.PROTOCOL_DIR, afile)) dateigroesse = dateides[6] local_time_tupel = time.localtime(ctime) dateitime =time.strftime("%d.%m.%y um %H:%M:%S", local_time_tupel) local_time_tupel = time.localtime(dateides[8]) # ST_MTIME dateitime2 =time.strftime("%d.%m.%y um %H:%M:%S", local_time_tupel) res.append(archivfile_mid_t % ("archiv_datei", afile, afile, dateigroesse, dateitime, dateitime2)) res.append(archivfile_end_t) return ''.join(res)
def __init__(self, parent, id): wx.MDIChildFrame.__init__(self, parent, id, title=_("Options"), size=(450,350), style = wx.MINIMIZE_BOX | wx.SYSTEM_MENU | wx.CAPTION) self.parent = parent self.rt = rotor.newrotor('cbtcbt', 12) self.images = Images(".") self.xrc = wxXmlResource('panels.xrc') self.xrc.LoadPanel(self, "panelOptions") self.SetIcon(self.images.GetImage("icn_conf")) self.opt_login = XRCCTRL(self, "opt_login") self.opt_password = XRCCTRL(self, "opt_password") self.opt_rpcurl = XRCCTRL(self, "opt_rpcurl") self.btnSave = XRCCTRL(self, "btnSave") self.btnCancel = XRCCTRL(self, "btnCancel") self.btnPath1 = XRCCTRL(self, "btnPath1") self.btnPath2 = XRCCTRL(self, "btnPath2") self.opt_destdir = XRCCTRL(self, "opt_destdir") self.opt_torrentdir = XRCCTRL(self, "opt_torrentdir") self.opt_splash = XRCCTRL(self, "opt_splash") self.opt_lang = XRCCTRL(self, "opt_lang") # XRCCTRL(self, "opt_notebook").SetPageText( 0, _("Base options") ) XRCCTRL(self, "opt_notebook").SetPageText( 1, _("Engine options") ) XRCCTRL(self, "opt_notebook").SetFont(defFontB) XRCCTRL(self, "opt_box1").SetLabel( _("Community settings:") ) XRCCTRL(self, "opt_box2").SetLabel( _("GUI settings:") ) XRCCTRL(self, "opt_box3").SetLabel( _("Paths:") ) XRCCTRL(self, "opt_lab1").SetLabel( _("Login:"******"opt_lab2").SetLabel( _("Password:"******"opt_lab3").SetLabel( _("URL:") ) XRCCTRL(self, "opt_lab4").SetLabel( _("Download dir:") ) XRCCTRL(self, "opt_lab5").SetLabel( _("Torrents dir:") ) XRCCTRL(self, "opt_lab6").SetLabel( _("Language:") ) XRCCTRL(self, "opt_splash").SetLabel( _("Show splash screen") ) XRCCTRL(self, "btnSave").SetLabel( _("Apply") ) XRCCTRL(self, "btnCancel").SetLabel( _("Cancel") ) XRCCTRL(self, "opt_lang").Insert( _("Polski"), 0 ) XRCCTRL(self, "opt_lang").Insert( _("English"), 1 ) # opts groups opts = { _("Connection settings") : { 1: { "name": _("Min port"), "val": policy.MIN_PORT, "type": "int"}, 2: { "name": _("Max port"), "val": policy.MAX_PORT, "type": "int"}, 3: { "name": _("Min peer"), "val": policy.MIN_PEER, "type": "int"}, 4: { "name": _("Max peer"), "val": policy.MAX_PEER, "type": "int"}, }, _("Bandwidth") : { 1: { "name": _("Max upload rate"), "val": policy.MAX_UPLOAD_RATE, "type": "int"}, 2: { "name": _("Max download rate"), "val": policy.MAX_DOWNLOAD_RATE, "type": "int"}, }, _("Seeding") : { 1: { "name": _("Minimum share ratio"), "val": policy.MIN_SHARE_RATIO, "type": "int"}, 2: { "name": _("Maximum share ratio"), "val": policy.MAX_SHARE_RATIO, "type": "int"}, } } self.opt_panel = XRCCTRL(self, "optPanel") self.opt_box = scrolled.ScrolledPanel(self.opt_panel, -1, size=(435, 270), style = wx.TAB_TRAVERSAL ) self.opt_grid = wx.FlexGridSizer(1,2) for cat, subitems in opts.iteritems(): l = wx.StaticText(self.opt_box, -1, str(cat)) l.SetFont(defFontB) self.opt_grid.Add( l, 0, wx.ALIGN_LEFT | wx.ALL, 5 ) self.opt_grid.Add( (20,20) ) for itemid, item in subitems.iteritems(): l = wx.StaticText(self.opt_box, -1, str(item['name'])) l.SetFont(defFontN) self.opt_grid.Add( l, 0, wx.ALIGN_LEFT | wx.ALL, 5 ) if item['type'] == 'int': i = wx.TextCtrl(self.opt_box, -1, value=str(self.parent.pol(item['val']))) self.opt_grid.Add( i, 0, wx.ALIGN_LEFT | wx.ALL, 5 ) self.opt_box.SetSizer(self.opt_grid) self.opt_box.SetAutoLayout(1) self.opt_box.SetupScrolling() # self.Bind(wx.EVT_BUTTON, self.OnCancel, id=XRCID("btnCancel")) self.Bind(wx.EVT_BUTTON, self.OnSave, id=XRCID("btnSave")) self.Bind(wx.EVT_BUTTON, self.OnPath1, id=XRCID("btnPath1")) self.Bind(wx.EVT_BUTTON, self.OnPath2, id=XRCID("btnPath2")) self.Bind(wx.EVT_CLOSE, self.OnClose) self.Activate() self.SetDefaults()
import rotor r = rotor.newrotor("you'll never guess this") r = rotor.newrotor("you'll never guess this", 12) A = 'spam and eggs' B = 'cheese shop' a = r.encrypt(A) print `a` b = r.encryptmore(B) print `b` A1 = r.decrypt(a) print A1 if A1 != A: print 'decrypt failed' B1 = r.decryptmore(b) print B1 if B1 != B: print 'decryptmore failed' try: r.setkey() except TypeError: pass r.setkey('you guessed it!')
def do_encode(pswd): robj = rotor.newrotor(mykey) # use enigma encryption return robj.encrypt(pswd)
def getObject(module, name, reload=0, # The use of a mutable default is intentional here, # because modules is a module cache. modules={} ): # The use of modules here is not thread safe, however, there is # no real harm in a rece condition here. If two threads # update the cache, then one will have simply worked a little # harder than need be. So, in this case, we won't incur # the expense of a lock. if modules.has_key(module): old=modules[module] if old.has_key(name) and not reload: return old[name] else: old=None if module[-3:]=='.py': p=module[:-3] elif module[-4:]=='.pyp': p=module[:-4] elif module[-4:]=='.pyc': p=module[:-4] else: p=module p=getPath('Extensions', p, suffixes=('','py','pyp','pyc')) if p is None: raise "Module Error", ( "The specified module, <em>%s</em>, couldn't be found." % module) __traceback_info__=p, module if p[-4:]=='.pyc': file = open(p, 'rb') binmod=imp.load_compiled('Extension', p, file) file.close() m=binmod.__dict__ elif p[-4:]=='.pyp': prod_id=module.split('.')[0] data=zlib.decompress( rotor.newrotor(prod_id +' shshsh').decrypt(open(p,'rb').read()) ) execsrc=compile(data, module, 'exec') m={} exec execsrc in m else: try: execsrc=open(p) except: raise "Module Error", ( "The specified module, <em>%s</em>, couldn't be opened." % module) m={} exec execsrc in m try: r=m[name] except KeyError: raise 'Invalid Object Name', ( "The specified object, <em>%s</em>, was not found in module, " "<em>%s</em>." % (name, module)) if old: for k, v in m.items(): old[k]=v modules[module]=m return r
import rotor SECRET_KEY = "spam" MESSAGE = "the holy grail" r = rotor.newrotor(SECRET_KEY) encoded_message = r.encrypt(MESSAGE) decoded_message = r.decrypt(encoded_message) print("original:", repr(MESSAGE)) print("encoded message:", repr(encoded_message)) print("decoded message:", repr(decoded_message)) ## original: 'the holy grail' ## encoded message: '\227\271\244\015\305sw\3340\337\252\237\340U' ## decoded message: 'the holy grail'
def do_encode(pswd): robj = rotor.newrotor(mykey) # использовать алгоритм enigma return robj.encrypt(pswd)
def Decrypt(self, ciphertext, key, identtag): """override this function for your own crypto funcs""" rt = rotor.newrotor(key, 12) return rt.decrypt(ciphertext)
def _distribution(self): # Return a distribution if self.__dict__.has_key('manage_options'): raise TypeError, 'This product is <b>not</b> redistributable.' id=self.id import rotor import tar rot=rotor.newrotor(id+' shshsh') ar=tar.tgzarchive("%s-%s" % (id, self.version)) prefix="Products/%s/" % self.id # __init__.py ar.add(prefix+"__init__.py", '''"Product %s" ''' % id ) # Extensions pp=id+'.' lpp=len(pp) ed=os.path.join(getConfiguration().instancehome,'Extensions') if os.path.exists(ed): for name in os.listdir(ed): suffix='' if name[:lpp]==pp: path=os.path.join(ed, name) try: f=open(path) data=f.read() f.close() if name[-3:]=='.py': data=rot.encrypt(zlib.compress(data)) suffix='p' except: data=None if data: ar.add("%sExtensions/%s%s" % (prefix,name[lpp:],suffix), data) # version.txt ar.add(prefix+'version.txt', self.version) # product.dat f=CompressedOutputFile(rot) if self.redistributable: # Since it's redistributable, make all objects configurable. objectList = self._objects else: objectList = tuple(filter( lambda o, obs=self.configurable_objects_: o['id'] in obs, self._objects)) meta={ '_objects': objectList, 'redistributable': self.redistributable, } f.write(cPickle.dumps(meta,1)) self._p_jar.exportFile(self._p_oid, f) ar.add(prefix+'product.dat', f.getdata()) ar.finish() return str(ar)
def __init__(self): wx.MDIParentFrame.__init__(self, None, -1, prog_name_full, size=(770,590), style = wx.DEFAULT_FRAME_STYLE) ID_New = wx.NewId() ID_Exit = wx.NewId() ID_Navbar = wx.NewId() self.rt = rotor.newrotor('cbtcbt', 12) self.userid = None #~ self.Maximize() # icons init self.images = Images(".") self.SetIcon(self.images.GetImage('icn_cbt')) self.windows = {"transfers":0, "chat":0, "public":0, "my":0, "options":0, "maketorrent":0} self.windowsi = {} self.tdwindows = {} # btq init if sys.platform == 'win32' or not os.environ.get('HOME'): root_path = os.path.dirname(os.path.abspath(sys.argv[0])) else: root_path = os.path.join(os.environ.get('HOME'),'.cbt') #from BitQueue.manager import Daemon #app = Daemon() #try: #app.daemonize() #except Exception,why: #print why self.pol = policy.Policy(root_path) self.pol.set_default() # menu menu = wx.Menu() menu.Append(ID_New, _("&Create new torrent")) menu.Append(ID_Exit, _("E&xit") ) menubar = wx.MenuBar() menubar.Append(menu, "communityBT") self.SetMenuBar(menubar) self.CreateStatusBar(2) self.SetStatusWidths([100,-1]) self.Bind(wx.EVT_MENU, self.OnNewTorrent, id=ID_New) self.Bind(wx.EVT_MENU, self.OnExit, id=ID_Exit) self.Bind(wx.EVT_CLOSE, self.OnClose) self.Bind(wx.EVT_SIZE, self.OnSize) # main window self.bg_bmp = self.images.GetImage("app_bg") self.GetClientWindow().Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground) win = wx.SashLayoutWindow(self, ID_Navbar, style=wx.NO_BORDER) win.SetDefaultSize((158, 1000)) win.SetOrientation(wx.LAYOUT_VERTICAL) win.SetAlignment(wx.LAYOUT_LEFT) win.SetSashVisible(wx.SASH_RIGHT, True) self.navbar = CbtNavbar(win, ID_Navbar, act=self.OnNewWindow) # log window self.log = PanelLog(self, -1) self.windows["log"] = 1 self.log.Show(True) self.log.SetSize((500,320)) # tray if (sys.platform == 'win32'): self.tray = wx.TaskBarIcon() self.trayicon = self.images.GetImage('icn_cbt') self.tray.SetIcon(self.trayicon, '') self.TBMENU_RESTORE = 60100 self.TBMENU_CLOSE = 60101 self.iconized = False wx.EVT_ICONIZE(self, self.onIconify) wx.EVT_TASKBAR_LEFT_DCLICK(self.tray, self.onTaskBarActivate) wx.EVT_TASKBAR_RIGHT_UP(self.tray, self.onTaskBarMenu) wx.EVT_MENU(self.tray, self.TBMENU_RESTORE, self.onTaskBarActivate) wx.EVT_MENU(self.tray, self.TBMENU_CLOSE, self.OnClose) # btq start from BitQueue.manager import Cbt self.btq = Cbt() # timers self.timer1 = wx.PyTimer(self.OnTimer1) self.timer1.Start(1500) self.OnTimer1() # login try: self.remote = Server( self.pol(policy.CBT_RPCURL) ) except Exception, e: self.log.AddMsg( _('Server'), _("Error") + ": " + str(e), "error" )
def getObject(module, name, reload=0, # The use of a mutable default is intentional here, # because modules is a module cache. modules={} ): # The use of modules here is not thread safe, however, there is # no real harm in a race condition here. If two threads # update the cache, then one will have simply worked a little # harder than need be. So, in this case, we won't incur # the expense of a lock. old = modules.get(module) if old is not None and name in old and not reload: return old[name] base, ext = os.path.splitext(module) if ext in ('py', 'pyp', 'pyc'): # XXX should never happen; splitext() keeps '.' with the extension p = base else: p = module p=getPath('Extensions', p, suffixes=('','py','pyp','pyc')) if p is None: raise NotFound, ( "The specified module, <em>%s</em>, couldn't be found." % module) __traceback_info__=p, module base, ext = os.path.splitext(p) if ext=='.pyc': file = open(p, 'rb') binmod=imp.load_compiled('Extension', p, file) file.close() m=binmod.__dict__ elif ext=='.pyp': import rotor prod_id=module.split('.', 1)[0] data=zlib.decompress( rotor.newrotor(prod_id +' shshsh').decrypt(open(p,'rb').read()) ) execsrc=compile(data, module, 'exec') m={} exec execsrc in m else: try: execsrc=open(p) except: raise NotFound, ( "The specified module, <em>%s</em>, couldn't be opened." % module) m={} exec execsrc in m if old is not None: old.update(m) else: modules[module] = m try: return m[name] except KeyError: raise NotFound, ( "The specified object, <em>%s</em>, was not found in module, " "<em>%s</em>." % (name, module))