Zahlensysteme + modifikationen an deployserver und fakeftp
This commit is contained in:
parent
d33988f3c5
commit
7bf087e64f
3 changed files with 91 additions and 1 deletions
|
@ -124,5 +124,6 @@ def deploy(port=1234,deploys=[],logger=NullLogger()):
|
||||||
run(host="",port=port)
|
run(host="",port=port)
|
||||||
|
|
||||||
deploy(deploys=[
|
deploy(deploys=[
|
||||||
Deploy(key="foo",commands=[ExecCommand("touch fu.txt",shell=True)], cwd="/home/madmaurice/Public/")
|
Deploy(key="frontend",branch="master",commands=[ExecCommand("./deploy_master.sh",shell=True)]),
|
||||||
|
Deploy(key="frontend",branch="develop",commands=[ExecCommand("./deploy_develop.sh",shell=True)])
|
||||||
],logger=FileLogger("deploy.log"))
|
],logger=FileLogger("deploy.log"))
|
||||||
|
|
|
@ -3,6 +3,7 @@ import threading
|
||||||
import socket
|
import socket
|
||||||
from random import randint
|
from random import randint
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
class Utils:
|
class Utils:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def mask(rights):
|
def mask(rights):
|
||||||
|
@ -655,6 +656,8 @@ class LineReader:
|
||||||
|
|
||||||
class FTPHandler(SocketServer.BaseRequestHandler):
|
class FTPHandler(SocketServer.BaseRequestHandler):
|
||||||
logger = StdoutLogger()
|
logger = StdoutLogger()
|
||||||
|
rootDirectory = Directory("")
|
||||||
|
authorizer = FailAuthorizer()
|
||||||
|
|
||||||
def log(self, message):
|
def log(self, message):
|
||||||
self.logger.log(self,message)
|
self.logger.log(self,message)
|
||||||
|
@ -729,6 +732,8 @@ class FTPHandler(SocketServer.BaseRequestHandler):
|
||||||
|
|
||||||
self.log("Client disconnected")
|
self.log("Client disconnected")
|
||||||
|
|
||||||
|
#Sample configuration:
|
||||||
|
|
||||||
handler = FTPHandler
|
handler = FTPHandler
|
||||||
handler.authorizer = AnonymousAuthorizer()
|
handler.authorizer = AnonymousAuthorizer()
|
||||||
|
|
||||||
|
|
84
zahlensysteme.py
Normal file
84
zahlensysteme.py
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
class NumberException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class NumericSystemException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class Zahlensystem:
|
||||||
|
chars = map(str, range(0,10)) + map(chr, range(ord('A'), ord('F')+1))
|
||||||
|
def __init__(self, basis):
|
||||||
|
self.basis = int(basis)
|
||||||
|
if self.basis > 16 or self.basis < 2:
|
||||||
|
raise NumberException("Numeric system %d is invalid" % (self.basis,))
|
||||||
|
|
||||||
|
def fromNum(self, num):
|
||||||
|
if type(num) != str:
|
||||||
|
num = str(num)
|
||||||
|
|
||||||
|
if "." in num:
|
||||||
|
pre, post = num.split(".",2)
|
||||||
|
else:
|
||||||
|
pre = num
|
||||||
|
post = ""
|
||||||
|
|
||||||
|
value = 0
|
||||||
|
|
||||||
|
for i,c in enumerate(pre):
|
||||||
|
e = (len(pre)-i-1)
|
||||||
|
try:
|
||||||
|
f = self.chars[:self.basis].index(c.upper())
|
||||||
|
except ValueError:
|
||||||
|
raise NumberException("%d isn't a %d based number" % (f,self.basis))
|
||||||
|
|
||||||
|
value += f * self.basis**e
|
||||||
|
|
||||||
|
for i,c in enumerate(post):
|
||||||
|
e = (-i-1)
|
||||||
|
try:
|
||||||
|
f = self.chars[:self.basis].index(c.upper())
|
||||||
|
except ValueError:
|
||||||
|
raise NumberException("%d isn't a %d based number" % (f,self.basis))
|
||||||
|
|
||||||
|
value += f * self.basis**e
|
||||||
|
|
||||||
|
return value
|
||||||
|
|
||||||
|
def toNum(self, num):
|
||||||
|
num = float(num)
|
||||||
|
|
||||||
|
if num < 0:
|
||||||
|
neg = True
|
||||||
|
num = -num
|
||||||
|
else:
|
||||||
|
neg = False
|
||||||
|
|
||||||
|
pre, post = divmod(num, 1)
|
||||||
|
|
||||||
|
v = ""
|
||||||
|
|
||||||
|
if pre != 0:
|
||||||
|
n = pre
|
||||||
|
while n != 0:
|
||||||
|
n, r = divmod(n, self.basis)
|
||||||
|
v = self.chars[int(r)] + v
|
||||||
|
else:
|
||||||
|
v = "0"
|
||||||
|
|
||||||
|
if post != 0:
|
||||||
|
v = v + "."
|
||||||
|
n = post
|
||||||
|
while n != 0:
|
||||||
|
r, n = divmod(n * self.basis, 1)
|
||||||
|
v = v + self.chars[int(r)]
|
||||||
|
|
||||||
|
if neg:
|
||||||
|
v = "-" + v
|
||||||
|
|
||||||
|
return v
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
num = raw_input("Num> ")
|
||||||
|
fr = int(raw_input("From> "))
|
||||||
|
to = int(raw_input("To> "))
|
||||||
|
|
||||||
|
print Zahlensystem(to).toNum(Zahlensystem(fr).fromNum(num))
|
Loading…
Reference in a new issue