I18n string cleanup and refactoring
This commit is contained in:
parent
59dd0b007a
commit
7ff8cbb341
62 changed files with 890 additions and 738 deletions
|
|
@ -11,81 +11,6 @@ Note that `accessing_obj` and `accessed_obj` can be any object type
|
|||
with a lock variable/field, so be careful to not expect
|
||||
a certain object type.
|
||||
|
||||
|
||||
**Appendix: MUX locks**
|
||||
|
||||
Below is a list nicked from the MUX help file on the locks available
|
||||
in standard MUX. Most of these are not relevant to core Evennia since
|
||||
locks in Evennia are considerably more flexible and can be implemented
|
||||
on an individual command/typeclass basis rather than as globally
|
||||
available like the MUX ones. So many of these are not available in
|
||||
basic Evennia, but could all be implemented easily if needed for the
|
||||
individual game.
|
||||
|
||||
```
|
||||
MUX Name: Affects: Effect:
|
||||
----------------------------------------------------------------------
|
||||
DefaultLock: Exits: controls who may traverse the exit to
|
||||
its destination.
|
||||
Evennia: "traverse:<lockfunc()>"
|
||||
Rooms: controls whether the account sees the
|
||||
SUCC or FAIL message for the room
|
||||
following the room description when
|
||||
looking at the room.
|
||||
Evennia: Custom typeclass
|
||||
Accounts/Things: controls who may GET the object.
|
||||
Evennia: "get:<lockfunc()"
|
||||
EnterLock: Accounts/Things: controls who may ENTER the object
|
||||
Evennia:
|
||||
GetFromLock: All but Exits: controls who may gets things from a
|
||||
given location.
|
||||
Evennia:
|
||||
GiveLock: Accounts/Things: controls who may give the object.
|
||||
Evennia:
|
||||
LeaveLock: Accounts/Things: controls who may LEAVE the object.
|
||||
Evennia:
|
||||
LinkLock: All but Exits: controls who may link to the location
|
||||
if the location is LINK_OK (for linking
|
||||
exits or setting drop-tos) or ABODE (for
|
||||
setting homes)
|
||||
Evennia:
|
||||
MailLock: Accounts: controls who may @mail the account.
|
||||
Evennia:
|
||||
OpenLock: All but Exits: controls who may open an exit.
|
||||
Evennia:
|
||||
PageLock: Accounts: controls who may page the account.
|
||||
Evennia: "send:<lockfunc()>"
|
||||
ParentLock: All: controls who may make @parent links to
|
||||
the object.
|
||||
Evennia: Typeclasses and
|
||||
"puppet:<lockstring()>"
|
||||
ReceiveLock: Accounts/Things: controls who may give things to the
|
||||
object.
|
||||
Evennia:
|
||||
SpeechLock: All but Exits: controls who may speak in that location
|
||||
Evennia:
|
||||
TeloutLock: All but Exits: controls who may teleport out of the
|
||||
location.
|
||||
Evennia:
|
||||
TportLock: Rooms/Things: controls who may teleport there
|
||||
Evennia:
|
||||
UseLock: All but Exits: controls who may USE the object, GIVE
|
||||
the object money and have the PAY
|
||||
attributes run, have their messages
|
||||
heard and possibly acted on by LISTEN
|
||||
and AxHEAR, and invoke $-commands
|
||||
stored on the object.
|
||||
Evennia: Commands and Cmdsets.
|
||||
DropLock: All but rooms: controls who may drop that object.
|
||||
Evennia:
|
||||
VisibleLock: All: Controls object visibility when the
|
||||
object is not dark and the looker
|
||||
passes the lock. In DARK locations, the
|
||||
object must also be set LIGHT and the
|
||||
viewer must pass the VisibleLock.
|
||||
Evennia: Room typeclass with
|
||||
Dark/light script
|
||||
```
|
||||
"""
|
||||
|
||||
|
||||
|
|
@ -112,16 +37,21 @@ def _to_account(accessing_obj):
|
|||
|
||||
|
||||
def true(*args, **kwargs):
|
||||
"Always returns True."
|
||||
return True
|
||||
"""
|
||||
Always returns True.
|
||||
|
||||
"""
|
||||
return True
|
||||
|
||||
def all(*args, **kwargs):
|
||||
return True
|
||||
|
||||
|
||||
def false(*args, **kwargs):
|
||||
"Always returns False"
|
||||
"""
|
||||
Always returns False
|
||||
|
||||
"""
|
||||
return False
|
||||
|
||||
|
||||
|
|
@ -129,6 +59,10 @@ def none(*args, **kwargs):
|
|||
return False
|
||||
|
||||
|
||||
def superuser(*args, **kwargs):
|
||||
return False
|
||||
|
||||
|
||||
def self(accessing_obj, accessed_obj, *args, **kwargs):
|
||||
"""
|
||||
Check if accessing_obj is the same as accessed_obj
|
||||
|
|
@ -167,7 +101,7 @@ def perm(accessing_obj, accessed_obj, *args, **kwargs):
|
|||
try:
|
||||
permission = args[0].lower()
|
||||
perms_object = accessing_obj.permissions.all()
|
||||
except (AttributeError, IndexError) as err:
|
||||
except (AttributeError, IndexError):
|
||||
return False
|
||||
|
||||
gtmode = kwargs.pop("_greater_than", False)
|
||||
|
|
@ -644,17 +578,6 @@ def holds(accessing_obj, accessed_obj, *args, **kwargs):
|
|||
return False
|
||||
|
||||
|
||||
def superuser(*args, **kwargs):
|
||||
"""
|
||||
Only accepts an accesing_obj that is superuser (e.g. user #1)
|
||||
|
||||
Since a superuser would not ever reach this check (superusers
|
||||
bypass the lock entirely), any user who gets this far cannot be a
|
||||
superuser, hence we just return False. :)
|
||||
"""
|
||||
return False
|
||||
|
||||
|
||||
def has_account(accessing_obj, accessed_obj, *args, **kwargs):
|
||||
"""
|
||||
Only returns true if accessing_obj has_account is true, that is,
|
||||
|
|
|
|||
|
|
@ -124,6 +124,7 @@ _LOCK_HANDLER = None
|
|||
class LockException(Exception):
|
||||
"""
|
||||
Raised during an error in a lock.
|
||||
|
||||
"""
|
||||
|
||||
pass
|
||||
|
|
@ -139,6 +140,7 @@ _LOCKFUNCS = {}
|
|||
def _cache_lockfuncs():
|
||||
"""
|
||||
Updates the cache.
|
||||
|
||||
"""
|
||||
global _LOCKFUNCS
|
||||
_LOCKFUNCS = {}
|
||||
|
|
@ -163,7 +165,7 @@ _RE_OK = re.compile(r"%s|and|or|not")
|
|||
#
|
||||
|
||||
|
||||
class LockHandler(object):
|
||||
class LockHandler:
|
||||
"""
|
||||
This handler should be attached to all objects implementing
|
||||
permission checks, under the property 'lockhandler'.
|
||||
|
|
@ -260,16 +262,13 @@ class LockHandler(object):
|
|||
continue
|
||||
if access_type in locks:
|
||||
duplicates += 1
|
||||
wlist.append(
|
||||
_(
|
||||
"LockHandler on %(obj)s: access type '%(access_type)s' changed from '%(source)s' to '%(goal)s' "
|
||||
% {
|
||||
"obj": self.obj,
|
||||
"access_type": access_type,
|
||||
"source": locks[access_type][2],
|
||||
"goal": raw_lockstring,
|
||||
}
|
||||
)
|
||||
wlist.append(_(
|
||||
"LockHandler on {obj}: access type '{access_type}' "
|
||||
"changed from '{source}' to '{goal}' ".format(
|
||||
obj=self.obj,
|
||||
access_type=access_type,
|
||||
source=locks[access_type][2],
|
||||
goal=raw_lockstring))
|
||||
)
|
||||
locks[access_type] = (evalstring, tuple(lock_funcs), raw_lockstring)
|
||||
if wlist and WARNING_LOG:
|
||||
|
|
@ -284,12 +283,14 @@ class LockHandler(object):
|
|||
def _cache_locks(self, storage_lockstring):
|
||||
"""
|
||||
Store data
|
||||
|
||||
"""
|
||||
self.locks = self._parse_lockstring(storage_lockstring)
|
||||
|
||||
def _save_locks(self):
|
||||
"""
|
||||
Store locks to obj
|
||||
|
||||
"""
|
||||
self.obj.lock_storage = ";".join([tup[2] for tup in self.locks.values()])
|
||||
|
||||
|
|
@ -693,8 +694,7 @@ def check_lockstring(
|
|||
access_type=access_type,
|
||||
)
|
||||
|
||||
def check_perm(
|
||||
obj, permission, no_superuser_bypass=False):
|
||||
def check_perm(obj, permission, no_superuser_bypass=False):
|
||||
"""
|
||||
Shortcut for checking if an object has the given `permission`. If the
|
||||
permission is in `settings.PERMISSION_HIERARCHY`, the check passes
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue