Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
UCC
UCC Snack Machine Server Code
Commits
9ac8ba25
Commit
9ac8ba25
authored
Nov 08, 2014
by
Mark Tearle
Browse files
First prune of top level directory
parent
8796ba14
Changes
3
Hide whitespace changes
Inline
Side-by-side
BankAccount.py
deleted
100644 → 0
View file @
8796ba14
import
pickle
ACCOUNT_FILE
=
'bank.pck'
class
BankAccount
:
def
__init__
(
self
):
f
=
None
self
.
bank
=
{}
try
:
f
=
open
(
ACCOUNT_FILE
)
except
IOError
:
pass
if
f
!=
None
:
self
.
bank
=
pickle
.
load
(
f
)
self
.
sanity_check
(
self
.
bank
)
f
.
close
()
self
.
save
()
def
sanity_check_user
(
self
,
user
):
wanted_fields
=
[
'balance'
]
for
f
in
user
:
if
f
in
wanted_fields
:
if
f
==
'balance'
:
if
not
isinstance
(
user
[
'balance'
],
tuple
):
return
False
if
len
(
user
[
'balance'
])
!=
2
:
return
False
if
not
isinstance
(
user
[
0
],
int
)
or
\
not
isinstance
(
user
[
1
],
int
):
return
False
del
wanted_fields
[
f
]
else
:
return
False
if
len
(
wanted_fields
)
!=
0
:
return
False
return
True
def
sanity_check
(
self
,
bank
):
for
u
in
bank
:
if
not
self
.
sanity_check_user
(
u
):
return
False
return
True
def
save
(
self
):
f
=
open
(
ACCOUNT_FILE
,
'w'
)
pickle
.
dump
(
self
.
bank
,
f
)
f
.
close
()
def
ensure_user_exists
(
self
,
username
):
if
self
.
bank
.
has_key
(
username
):
return
self
.
bank
[
username
]
=
{}
self
.
bank
[
username
][
'balance'
]
=
(
0
,
0
)
def
get_balance
(
self
,
username
):
if
self
.
bank
.
has_key
(
username
):
return
self
.
bank
[
username
][
'balance'
]
return
(
0
,
0
)
def
add_amount
(
self
,
username
,
amount
):
self
.
ensure_user_exists
(
username
)
(
cur_cents
,
cur_bytes
)
=
self
.
bank
[
username
][
'balance'
]
(
add_cents
,
add_bytes
)
=
amount
self
.
bank
[
username
][
'balance'
]
=
(
cur_cents
+
add_cents
,
cur_bytes
+
add_bytes
)
self
.
save
()
DispenseServer.py
deleted
100755 → 0
View file @
8796ba14
#!/usr/bin/python
from
SOAPpy
import
*
from
BankAccount
import
BankAccount
namespace
=
'Dispense'
bind_port
=
9900
server
=
None
def
hello
():
return
"hello"
if
__name__
==
'__main__'
:
server
=
SOAPServer
((
'0.0.0.0'
,
9900
))
bank
=
BankAccount
()
for
f
in
[
hello
]:
server
.
registerFunction
(
f
,
namespace
)
print
"Serving forever ..."
server
.
serve_forever
()
codesnippets/horizscroll.py
deleted
100644 → 0
View file @
8796ba14
#!/usr/bin/env python
import
string
import
sys
import
time
class
HorizScroll
:
def
__init__
(
self
,
text
):
self
.
text
=
text
pass
def
expand
(
self
,
padding
=
None
,
paddingchar
=
" "
,
dir
=
None
):
if
len
(
self
.
text
)
<=
10
:
return
[
text
]
if
not
padding
:
padding
=
len
(
self
.
text
)
/
2
format
=
"%-"
+
str
(
padding
)
+
"."
+
str
(
padding
)
+
"s"
pad
=
string
.
replace
(
format
%
" "
,
" "
,
paddingchar
)
padtext
=
self
.
text
+
pad
expansion
=
[]
for
x
in
range
(
0
,
len
(
padtext
)):
expansion
.
append
(
padtext
[
x
:]
+
padtext
[:
x
])
if
dir
==
-
1
:
expansion
.
reverse
()
return
expansion
if
__name__
==
'__main__'
:
h
=
HorizScroll
(
"hello cruel world"
)
eh
=
h
.
expand
()
while
1
:
for
x
in
eh
:
sys
.
stdout
.
write
(
"
\r
"
)
print
"%-10.10s"
%
x
,
sys
.
stdout
.
flush
()
time
.
sleep
(
0.1
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment