Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
engine
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AURA
engine
Commits
7af546c6
Commit
7af546c6
authored
2 years ago
by
David Trattnig
Browse files
Options
Downloads
Patches
Plain Diff
add new private decorator
parent
bdc5aed2
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/aura_engine/base/lang.py
+49
-0
49 additions, 0 deletions
src/aura_engine/base/lang.py
with
49 additions
and
0 deletions
src/aura_engine/base/lang.py
0 → 100644
+
49
−
0
View file @
7af546c6
#
# Aura Engine (https://gitlab.servus.at/aura/engine)
#
# Copyright (C) 2017-2020 - The Aura Engine Team.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
A collection of Python language utilities.
"""
import
inspect
from
functools
import
wraps
def
private
(
member
):
"""
@private Decorator.
Use this to annotate your methods for private-visibility.
This is an more expressive alternative to the pythonic underscore visibility.
"""
@wraps
(
member
)
def
wrapper
(
*
args
):
me
=
member
.
__name__
stack
=
inspect
.
stack
()
calling_class
=
stack
[
1
][
0
].
f_locals
[
"
self
"
].
__class__
.
__name__
calling_method
=
stack
[
1
][
0
].
f_code
.
co_name
if
calling_method
not
in
dir
(
args
[
0
])
and
calling_method
is
not
me
:
msg
=
f
'"
{
me
}
(..)
"
called by
"
{
calling_class
}
.
{
calling_method
}
(..)
"
is private
'
print
(
msg
)
raise
Exception
(
msg
)
return
member
(
*
args
)
return
wrapper
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment