Copy Link
Add to Bookmark
Report

NULL mag Issue 08 27 Better access() mpy function

eZine's profile picture
Published in 
null magazine
 · 26 Dec 2020

  




mystics mpy language has a function to check if an acs string is valid,
depending the current users level. while trying to use it, i think i
found an abnormal behavior... or at least, that the function is not
100% accurate implemented.

the problem was, that when you try to use the access() function, of
mpy, with an acs string like "g1s20", even if the user level is
greater than 20, it will return a false value. the reason is that the
function expects only a "s20" type string, with only the security
level code and not other acs codes.

so i wrote another function that can manipulate any type of acs
string. the function will only tell you about the users security level
and other types of acs codes, like if a user has chosen a specific
file/msg base etc.

the syntax is simple: isacs(useracs,otheracs)

where useracs, is the acs level of the user we want to check ex.20 and
otheracs is any type of an acs string ex."z1g2s40" etc. for example:

isacs('20','g1s40'), will return False cause 20 is less than 40.

the complete function is this:


def isacs(useracs,otheracs):
if otheracs == "":
return True
val = ""
inacs = False
s = otheracs
i = 0
while i <= len(s)-1:
if inacs:
if s[i].isdigit():
val = val + s[i]
else:
break
if s[i] == 's':
inacs = True
i += 1

if useracs >= int(val):
return True
else:
return False




<<< null e-magazine x008 (text edition) >>>
____ _____ _____ _____ http://github.com/xqtr/null
___/. \/ /_________/. /__/. /__jp!_ andr01d.zapto.org:9999
//_ \ . / / \ / _// agency.bbs.nz
/____/\____/ / /__________________\ d1st.org
\________/

← previous
next →
loading
sending ...
New to Neperos ? Sign Up for free
download Neperos App from Google Play
install Neperos as PWA

Let's discover also

Recent Articles

Recent Comments

Neperos cookies
This website uses cookies to store your preferences and improve the service. Cookies authorization will allow me and / or my partners to process personal data such as browsing behaviour.

By pressing OK you agree to the Terms of Service and acknowledge the Privacy Policy

By pressing REJECT you will be able to continue to use Neperos (like read articles or write comments) but some important cookies will not be set. This may affect certain features and functions of the platform.
OK
REJECT