Skip to content

Commit

Permalink
Standardize on 4 spaces for indenting
Browse files Browse the repository at this point in the history
  • Loading branch information
wichert committed Apr 20, 2009
1 parent db1a622 commit 40c7eab
Show file tree
Hide file tree
Showing 20 changed files with 1,247 additions and 1,244 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Pyrad 1.2 (unreleased)
======================

* Standardize on 4 spaces for indents. Patch by Kristoffer Grönlund / Purplescout.

* Make sure all encoding utility methods raise a TypeError if a value of
the wrong type is passed in.

Expand Down
20 changes: 10 additions & 10 deletions example/acct.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
from pyrad.dictionary import Dictionary

def SendPacket(srv, req):
try:
srv.SendPacket(req)
except pyrad.client.Timeout:
print "RADIUS server does not reply"
sys.exit(1)
except socket.error, error:
print "Network error: " + error[1]
sys.exit(1)
try:
srv.SendPacket(req)
except pyrad.client.Timeout:
print "RADIUS server does not reply"
sys.exit(1)
except socket.error, error:
print "Network error: " + error[1]
sys.exit(1)

srv=Client(server="localhost",
secret="Kah3choteereethiejeimaeziecumi",
dict=Dictionary("dictionary"))
secret="Kah3choteereethiejeimaeziecumi",
dict=Dictionary("dictionary"))

req=srv.CreateAcctPacket(User_Name="wichert")

Expand Down
36 changes: 18 additions & 18 deletions example/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,36 @@
from pyrad.dictionary import Dictionary

srv=Client(server="localhost",
secret="Kah3choteereethiejeimaeziecumi",
dict=Dictionary("dictionary"))
secret="Kah3choteereethiejeimaeziecumi",
dict=Dictionary("dictionary"))

req=srv.CreateAuthPacket(code=pyrad.packet.AccessRequest,
User_Name="wichert")
User_Name="wichert")

req["NAS-IP-Address"] = "192.168.1.10"
req["NAS-Port"] = 0
req["Service-Type"] = "Login-User"
req["NAS-Identifier"] = "trillian"
req["Called-Station-Id"] = "00-04-5F-00-0F-D1"
req["NAS-IP-Address"] = "192.168.1.10"
req["NAS-Port"] = 0
req["Service-Type"] = "Login-User"
req["NAS-Identifier"] = "trillian"
req["Called-Station-Id"] = "00-04-5F-00-0F-D1"
req["Calling-Station-Id"] = "00-01-24-80-B3-9C"
req["Framed-IP-Address"] = "10.0.0.100"
req["Framed-IP-Address"] = "10.0.0.100"

try:
print "Sending authentication request"
reply=srv.SendPacket(req)
print "Sending authentication request"
reply=srv.SendPacket(req)
except pyrad.client.Timeout:
print "RADIUS server does not reply"
sys.exit(1)
print "RADIUS server does not reply"
sys.exit(1)
except socket.error, error:
print "Network error: " + error[1]
sys.exit(1)
print "Network error: " + error[1]
sys.exit(1)

if reply.code==pyrad.packet.AccessAccept:
print "Access accepted"
print "Access accepted"
else:
print "Access denied"
print "Access denied"

print "Attributes returned by server:"
for i in reply.keys():
print "%s: %s" % (i, reply[i])
print "%s: %s" % (i, reply[i])

43 changes: 22 additions & 21 deletions example/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,35 @@
from pyrad import dictionary, packet, server

class FakeServer(server.Server):
def _HandleAuthPacket(self, pkt):
server.Server._HandleAuthPacket(self, pkt)
def _HandleAuthPacket(self, pkt):
server.Server._HandleAuthPacket(self, pkt)

print "Received an authentication request"
print "Attributes: "
for attr in pkt.keys():
print "%s: %s" % (attr, pkt[attr])
print
print "Received an authentication request"
print "Attributes: "
for attr in pkt.keys():
print "%s: %s" % (attr, pkt[attr])
print

reply=self.CreateReplyPacket(pkt)
reply.code=packet.AccessAccept
self.SendReplyPacket(pkt.fd, reply)

def _HandleAcctPacket(self, pkt):
server.Server._HandleAcctPacket(self, pkt)
reply=self.CreateReplyPacket(pkt)
reply.code=packet.AccessAccept
self.SendReplyPacket(pkt.fd, reply)

print "Received an accounting request"
print "Attributes: "
for attr in pkt.keys():
print "%s: %s" % (attr, pkt[attr])
print
def _HandleAcctPacket(self, pkt):
server.Server._HandleAcctPacket(self, pkt)

reply=self.CreateReplyPacket(pkt)
self.SendReplyPacket(pkt.fd, reply)
print "Received an accounting request"
print "Attributes: "
for attr in pkt.keys():
print "%s: %s" % (attr, pkt[attr])
print

reply=self.CreateReplyPacket(pkt)
self.SendReplyPacket(pkt.fd, reply)


srv=FakeServer(dict=dictionary.Dictionary("dictionary"))
srv.hosts["127.0.0.1"]=server.RemoteHost("127.0.0.1",
"Kah3choteereethiejeimaeziecumi", "localhost")
"Kah3choteereethiejeimaeziecumi",
"localhost")
srv.BindToAddress("")
srv.Run()
14 changes: 7 additions & 7 deletions pyrad/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pyrad is an implementation of a RADIUS client as described in RFC2865.
It takes care of all the details like building RADIUS packets, sending
them and decoding responses.
them and decoding responses.
Here is an example of doing a authentication request::
Expand All @@ -11,10 +11,10 @@
from pyrad.dictionary import Dictionary
srv=Client(server="radius.my.domain", secret="s3cr3t",
dict=Dictionary("dicts/dictionary", "dictionary.acc"))
dict=Dictionary("dicts/dictionary", "dictionary.acc"))
req=srv.CreatePacket(code=pyrad.packet.AccessRequest,
User_Name="wichert", NAS_Identifier="localhost")
User_Name="wichert", NAS_Identifier="localhost")
req["User-Password"]=req.PwCrypt("password")
reply=srv.SendPacket(req)
Expand All @@ -36,11 +36,11 @@
- tools: utility functions
"""

__docformat__ = "epytext en"
__docformat__ = "epytext en"

__author__ = "Wichert Akkerman <wichert@wiggy.net>"
__url__ = "http://www.wiggy.net/code/pyrad.xhtml"
__copyright__ = "Copyright 2002-2007 Wichert Akkerman"
__author__ = "Wichert Akkerman <wichert@wiggy.net>"
__url__ = "http://www.wiggy.net/code/pyrad.xhtml"
__copyright__ = "Copyright 2002-2007 Wichert Akkerman"

__all__ = [ "client", "dictionary", "packet", "server", "tools" ]

52 changes: 26 additions & 26 deletions pyrad/bidict.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,45 @@
# Bidirectional map

class BiDict:
def __init__(self):
self.forward={}
self.backward={}

def __init__(self):
self.forward={}
self.backward={}

def Add(self, one, two):
self.forward[one]=two
self.backward[two]=one

def Add(self, one, two):
self.forward[one]=two
self.backward[two]=one

def __len__(self):
return len(self.forward)

def __len__(self):
return len(self.forward)

def __getitem__(self, key):
return self.GetForward(key)

def __getitem__(self, key):
return self.GetForward(key)

def __delitem__(self, key):
if self.forward.has_key(key):
del self.backward[self.forward[key]]
del self.forward[key]
else:
del self.forward[self.backward[key]]
del self.backward[key]

def GetForward(self, key):
return self.forward[key]
def __delitem__(self, key):
if self.forward.has_key(key):
del self.backward[self.forward[key]]
del self.forward[key]
else:
del self.forward[self.backward[key]]
del self.backward[key]

def GetForward(self, key):
return self.forward[key]

def HasForward(self, key):
return self.forward.has_key(key)

def HasForward(self, key):
return self.forward.has_key(key)

def GetBackward(self, key):
return self.backward[key]

def GetBackward(self, key):
return self.backward[key]

def HasBackward(self, key):
return self.backward.has_key(key)

def HasBackward(self, key):
return self.backward.has_key(key)


Loading

0 comments on commit 40c7eab

Please sign in to comment.