This function tests to see whether an accessor's site is considered off-campus or not.
We expect that the accessor will be either a single name,
or a form like “a.b.c.d”. An accessor is considered local in the former
case, or if its trailing parts match symDomain, or if
its leading parts match ipDomain.
# - - - P a g e G e t . i s F a r - - -
def isFar ( self, symDomain, ipDomain ):
"""Is this record from our domain?
[ (symDomain is a list of the trailing parts of the local IP
domain as strings) and
(ipDomain is a list of the leading parts of the local
IP domain as numbers in string form) ->
if self represents a fetch from symDomain or
ipDomain ->
return False
else -> return True ]
"""
First we split the accessor's domain using "." as the delimiter:
#-- 1 --
# [ L := list of parts of self.accessor split on "." ]
L = self.accessor.split ( "." )
Before trying to match pieces of L against symDomain and
ipDomain, we need to make sure
that L is at least as long as
they are. If L is too short,
there are two cases:
If the accessor is recorded as "unknown", that's considered a remote
accessor.
Otherwise this is considered a local access, because
accesses from local machines omit the ".nmt.edu" qualifier.
#-- 2 --
# [ if L is at least as long as both symDomain and
# ipDomain ->
# I
# else if L[0] is "unknown" ->
# return False
# else -> return True ]
if ( ( len ( L ) < len ( symDomain ) ) or
( len ( L ) < len ( ipDomain ) ) ):
if L[0] == "unknown": return True
else: return False
Now that we know L is at least
as long as symDomain and
ipDomain, we can compare its
leading parts against ipDomain
and its trailing parts against symDomain.
#-- 3 --
# [ if ipDomain matches the initial elements of L ->
# return False
# else -> I ]
if ipDomain == L[:len(ipDomain)]:
return False
#-- 4 --
# [ if symDomain matches the final elements of L ->
# return False
# else ->
# return True ]
if symDomain == L[-len(symDomain):]: return False
else: return True