free software resistance

 the cost of computing freedom is eternal vigilance

### codex.rose.py *original date:* oct 2017 *originally posted:* oct 2024 codex.rose.py: ``` #!/usr/bin/env python # encoding: utf-8 # rose translator version: rose 0.2 import sys, os from sys import stdin, stdout from sys import argv as roseargv try: from colorama import init ; init() except: pass # (only) windows users want colorama installed or ansi.sys enabled from random import randint from time import sleep from os import chdir as roseoch from os import popen as rosepo from os import system as rosesh from os import name as roseosname rosesysteme = 0 rosefilehandles = {} rosefilecounters = {} from sys import stdout def roselocate(x, l = "ignore", c = "ignore"): import sys if l == "ignore" and c == "ignore": pass # do nothing. want it to return an error? elif l < 1 and c != "ignore": sys.stdout.write("[" + str(c) + "G") # not ansi.sys compatible elif l != "ignore" and c == "ignore": sys.stdout.write("[" + str(l) + ";" + str(1) + "H") else: sys.stdout.write("[" + str(l) + ";" + str(c) + "H") import time def rosenonz(p, n=None): if n==None: if p == 0: return 1 else: if p == 0: return n return p def rosenot(p): if p: return 0 return -1 rosebac = None roseprsbac = None sub = None def rosenone(p, rosebac): if p == None: return rosebac return p return -1 def stopgraphics(): global yourscreen global roseraphics roseraphics = 0 def rosecolortext(x, f): b = 0 if f == None: f = 0 if b == None: b = 0 n = "0" if f > 7: n = "1" ; f = f - 8 if f == 1: f = 4 ## switch ansi colours for qb colours elif f == 4: f = 1 ## 1 = blue not red, 4 = red not blue, etc. if f == 3: f = 6 elif f == 6: f = 3 if b > 7: b = b - 8 if b == 1: b = 4 elif b == 4: b = 1 if b == 3: b = 6 elif b == 6: b = 3 stdout.write("\x1b[" + n + ";" + str(30+f) + "m") return "\x1b[" + n + ";" + str(30+f) + ";" + str(40+b) + "m" def rosecolourtext(x, f): b = 0 if f == None: f = 0 if b == None: b = 0 n = "0" if f > 7: n = "1" ; f = f - 8 if f == 1: f = 4 ## switch ansi colours for qb colours elif f == 4: f = 1 ## 1 = blue not red, 4 = red not blue, etc. if f == 3: f = 6 elif f == 6: f = 3 if b > 7: b = b - 8 if b == 1: b = 4 elif b == 4: b = 1 if b == 3: b = 6 elif b == 6: b = 3 stdout.write("\x1b[" + n + ";" + str(30+f) + "m") return "\x1b[" + n + ";" + str(30+f) + ";" + str(40+b) + "m" rosecgapal = [(0, 0, 0), (0, 0, 170), (0, 170, 0), (0, 170, 170), (170, 0, 0), (170, 0, 170), (170, 85, 0), (170, 170, 170), (85, 85, 85), (85, 85, 255), (85, 255, 85), (85, 255, 255), (255, 85, 85), (255, 85, 255), (255, 255, 85), (255, 255, 255)] def roseget(p, s): return s def rosehighlight(x, b): f = None if f == None: f = 0 if b == None: b = 0 n = "0" if f > 7: n = "1" ; f = f - 8 if f == 1: f = 4 ## switch ansi colours for qb colours elif f == 4: f = 1 ## 1 = blue not red, 4 = red not blue, etc. if f == 3: f = 6 elif f == 6: f = 3 if b > 7: b = b - 8 if b == 1: b = 4 elif b == 4: b = 1 if b == 3: b = 6 elif b == 6: b = 3 stdout.write("\x1b[" + n + str(40+b) + "m") return "\x1b[" + n + str(40+b) + "m" def roseinstr(x, p, e): try: return p.index(e) + 1 except: return 0 def rosechdir(p): try: roseoch(p) except: print "no such file or directory: " + str(p) ; roseend(1) def roseshell(p): global rosesysteme try: rosesysteme = rosesh(p) except: print "error running shell command: " + chr(34) + str(p) + chr(34) roseend(1) def rosecdxshell(c): global rosesysteme try: rosesysteme = 0 sh = rosepo(c) ps = sh.read().replace(chr(13) + chr(10), chr(10)).replace(chr(13), chr(10)).split(chr(10)) rosesysteme = sh.close() except: print "error running cdxshell command: " + chr(34) + str(c) + chr(34) roseend(1) return ps[:] def rosesgn(p): p = float(p) if p > 0: return 1 if p < 0: return -1 return 0 def rosestr(p): return str(p) def rosedisplay(p): print rosearr2cdx("", p) def rosechr(p): if type(p) == str: if len(p) > 0: return p[0] return chr(p) def rosedisplays(p): stdout.write(str(p)) ; sys.stdout.flush() def roseleft(p, s): return p[:s] def rosemid(p, s, x): cdx = 0 if type(p) == list or type(p) == tuple: cdx = 1 rt = p[s - 1:x + s - 1] if cdx and len(rt) == 1: rt = rt[0] return rt def roseright(p, s): return p[-s:] def roserandint(x, s, f): return randint(s, f) def roselcase(p): return p.lower() def roseucase(p): return p.upper() def roseint(p): return int(p) def rosecdxset(x, p, s): if 1: #if type(p) == str: p = p + s # str(s) if you want it easier if type(x) == dict: if type(s) == tuple: if len(s) == 1: fas = s[0] elif type(s) == list: if len(s) == 1: fas = s[0] else: fas = s x[p] = s else: #type(p) == list: if type(s) == tuple: if len(s) == 1: fas = s[0] elif type(s) == list: if len(s) == 1: fas = s[0] else: fas = s x[p - 1] = s #if type(p) == tuple: # if type(s) == tuple: # p = tuple(list(p) + list(s)) # elif type(s) == list: # p = tuple(list(p) + s[:]) # else: # p = tuple(list(p) + [s]) #if type(p) == str: p = p + s # str(s) if you want it easier def rosefprint(x, s): fon = roseosname sep = chr(10) if fon == "nt": sep = chr(13) + chr(10) rosefilehandles[s].write(str(x) + sep) def roseflineinput(x, s): try: p = rosefilehandles[s][rosefilecounters[s]].replace(chr(13), "").replace(chr(10), "") rosefilecounters[s] += 1 except: p = chr(10) return p def roseclose(x): if (x) in rosefilehandles.keys(): rosefilehandles[x].close() ; del rosefilehandles[x] try: del rosefilecounters[x] except: pass def roseesc(x): if roseosname == "nt": esc = rosesh("cls") else: stdout.write("") ; sys.stdout.flush() def rosecdxload(x, s): x = open(s).read().replace(chr(13) + chr(10), chr(10)).replace(chr(13), chr(10)).split(chr(10)) return x[:] def rosecdxsave(v, dx): sep = chr(10) if roseosname == "nt": sep = chr(13) + chr(10) try: v = rosecdx2arr(v) if len(v) > 1 and v[-1:] == "": v = v[:-1] except: pass rosefilehandle = open(dx, "w") rosefilehandle.write(rosecdxjoin('', v, sep) + sep) rosefilehandle.close() def rosecdxcurl(x, s): from urllib import urlopen x = str(urlopen(s).read()) ; x = x.replace(chr(13) + chr(10), chr(10)).replace(chr(13), chr(10)).split(chr(10)) return x[:] def rosecdxin(x): ps = [] for p in stdin: ps += [p[:-1]] return ps[:] def rosecdxget(x, p, s): if type(p) == dict: return p[s] else: return p[s - 1] def roseadd(p, s): if type(p) in (float, int): if type(s) in (float, int): p = p + s else: p = p + s # float(s) if you want it easier if p == float(int(p)): p = int(p) else: if type(p) == str: p = p + s # str(s) if you want it easier if type(p) == list: if type(s) == tuple: p = p + list(s) elif type(s) == list: p = p + s[:] else: p = p + [s] if type(p) == dict: if type(s) == dict: for t in s.keys(): p[t] = s[t] p = p + s[:] else: p[len(p) + 1] = s if type(p) == tuple: if type(s) == tuple: p = tuple(list(p) + list(s)) elif type(s) == list: p = tuple(list(p) + s[:]) else: p = tuple(list(p) + [s]) return p def rosecdxjoin(p, x, s): t = "" if type(x) == list: x = rosearr2cdx("", x) k = x.keys() ; k.sort() if len(k) : t = str(x[k[0]]) for c in range(len(k)): if c > 0: t += str(s) + str(x[k[c]]) return t # s.join(x) def rosecdx(x): if type(x) in (float, int, str): p = {} ; p[1] = x else: p = {} ; p[1] = rosecdx2arr("", x)[0] return p def rosedict(x): if type(x) in (float, int, str): p = {} ; p[1] = x else: p = {} ; p[1] = rosecdx2arr("", x)[0] return p def rosearr2cdx(p, x): if type(x) == list: p = x[:] x = {} c = 0 for t in p: c += 1 ; x[c] = t return x return x def rosecdx2arr(p, x): if type(x) == dict: p = {} for t in x.keys(): p[t] = x[t] x = [] t = p.keys() ; t.sort() for c in t: x += [p[c],] return x def rosecdxsplit(p, x, s): return rosearr2cdx("", x.split(s)) def roseval(n): n = float(n) if float(int(n)) == float(n): n = int(n) return n def rosetimes(p, s): if type(p) in (float, int): p = p * s # float(s) if you want it easier if p == float(int(p)): p = int(p) else: if type(p) == list: p = p[:] * s # roseval(s) else: p = p * s # roseval(s) if you want it easer return p def rosedivby(p, s): p = float(p) / s if p == float(int(p)): p = int(p) return p def rosesubtract(p, s): return p - s def roseexp(p, s): p = p ** s if p == float(int(p)): p = int(p) return p def rosemod(p, s): return p % s def rosecos(p): from math import cos ; p = cos(p) if p == float(int(p)): p = int(p) return p def rosesin(p): from math import sin ; p = sin(p) if p == float(int(p)): p = int(p) return p def roseltrim(p): return p.lstrip() def roselineinput(p): return raw_input() def roselen(p): return len(p) def roseasc(p): return ord(p[0]) def rosepi(p): return 3.14159265359 def rosehex(p): return hex(p) def rosertrim(p): return p.rstrip() def rosestring(x, p, n): if type(n) == str: return n * p return chr(n) * p def rosetime(p): from time import strftime ; return strftime("%H:%M:%S") def rosedate(p): from time import strftime ; return strftime("%m/%d/%Y") def rosecdxcmd(p): return roseargv[1:] def roseoct(p): return oct(p) def rosesleep(p, s): #print lc () + p #addto[0] = 1 sleep(s) def rosecdxsort(p): p.sort() def rosereverse(p): if type(p) == list: p.reverse() ; return p elif type(p) == str: p = map(str, p) ; p.reverse() p = "".join(p) return p def rosecdxeverse(p): p.reverse() def rosefunction(p, s): return p def roseend(x): quit() def roseif(p, s): return p def rosethen(p, s): return p def roseexit(x): quit() roselist = 0 try: roselist = int(type(p) in (list, dict, float, int, str)) except NameError: pass if not roselist: p = 0 p = "each of these get their" ; roselist = 0 try: roselist = int(type(p) in (list, dict, float, int, str)) except NameError: pass if not roselist: p = 0 rosecolourtext(p, 10) ; roselist = 0 try: roselist = int(type(p) in (list, dict, float, int, str)) except NameError: pass if not roselist: p = 0 rosedisplay(p) ; roselist = 0 try: roselist = int(type(p) in (list, dict, float, int, str)) except NameError: pass if not roselist: p = 0 p = rosecdxsplit(p, p, " ") ; roselist = 0 try: roselist = int(type(p) in (list, dict, float, int, str)) except NameError: pass if not roselist: p = 0 rosecolourtext(p, 2) ; for x in rosecdx2arr(0, p): roselist = 0 try: roselist = int(type(x) in (list, dict, float, int, str)) except NameError: pass if not roselist: x = 0 rosedisplay(x) ; roselist = 0 try: roselist = int(type(x) in (list, dict, float, int, str)) except NameError: pass if not roselist: x = 0 rosecolourtext(x, 7) ; roselist = 0 try: roselist = int(type(x) in (list, dict, float, int, str)) except NameError: pass if not roselist: x = 0 x = "" ; roselist = 0 try: roselist = int(type(x) in (list, dict, float, int, str)) except NameError: pass if not roselist: x = 0 rosedisplays(x) ; roselist = 0 try: roselist = int(type(p) in (list, dict, float, int, str)) except NameError: pass if not roselist: p = 0 p = roseadd(p, "own") ; roselist = 0 try: roselist = int(type(p) in (list, dict, float, int, str)) except NameError: pass if not roselist: p = 0 rosecdxset(p, "this is a key", "line") ; roselist = 0 try: roselist = int(type(p) in (list, dict, float, int, str)) except NameError: pass if not roselist: p = 0 rosedisplay(p) ; roselist = 0 try: roselist = int(type(p) in (list, dict, float, int, str)) except NameError: pass if not roselist: p = 0 rosecdxsave(p, "each.txt") ; roselist = 0 try: roselist = int(type(p) in (list, dict, float, int, str)) except NameError: pass if not roselist: p = 0 p = "echo $(cat each.txt | sed 's/will/does/g'), but this combines them" ; roselist = 0 try: roselist = int(type(p) in (list, dict, float, int, str)) except NameError: pass if not roselist: p = 0 roseshell(p) ; # license: creative commons cc0 1.0 (public domain) # http://creativecommons.org/publicdomain/zero/1.0/ ``` license: 0-clause bsd ``` # 2017 mn # # Permission to use, copy, modify, and/or distribute this software for any # purpose with or without fee is hereby granted. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ``` => https://freesoftwareresistance.neocities.org