本文整理汇总了Python中grouper.models.counter.Counter类的典型用法代码示例。如果您正苦于以下问题:Python Counter类的具体用法?Python Counter怎么用?Python Counter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Counter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
def post(self, tag_id=None, name=None):
tag = PublicKeyTag.get(self.session, tag_id, name)
if not tag:
return self.notfound()
if not user_has_permission(self.session, self.current_user, TAG_EDIT, tag.name):
return self.forbidden()
form = TagEditForm(self.request.arguments, obj=tag)
if not form.validate():
return self.render(
"tag-edit.html", tag=tag, form=form,
alerts=self.get_form_alerts(form.errors)
)
tag.description = form.data["description"]
tag.enabled = form.data["enabled"]
Counter.incr(self.session, "updates")
try:
self.session.commit()
except IntegrityError:
self.session.rollback()
form.tagname.errors.append(
"{} already exists".format(form.data["tagname"])
)
return self.render(
"tag-edit.html", tag=tag, form=form,
alerts=self.get_form_alerts(form.errors)
)
AuditLog.log(self.session, self.current_user.id, 'edit_tag',
'Edited tag.', on_tag_id=tag.id)
return self.redirect("/tags/{}".format(tag.name))
示例2: disable_user
def disable_user(session, user):
"""Disables an enabled user"""
get_plugin_proxy().will_disable_user(session, user)
user.enabled = False
Counter.incr(session, "updates")
示例3: update_status
def update_status(self, requester, status, reason):
now = datetime.utcnow()
current_status = self.status
self.status = status
request_status_change = RequestStatusChange(
request=self,
user_id=requester.id,
from_status=current_status,
to_status=status,
change_at=now
).add(self.session)
self.session.flush()
Comment(
obj_type=OBJ_TYPES_IDX.index("RequestStatusChange"),
obj_pk=request_status_change.id,
user_id=requester.id,
comment=reason,
created_on=now
).add(self.session)
if status == "actioned":
edge = self.session.query(GroupEdge).filter_by(
id=self.edge_id
).one()
edge.apply_changes(self)
Counter.incr(self.session, "updates")
示例4: test_passwords_api
def test_passwords_api(session, users, http_client, base_url, graph):
user = users['[email protected]']
TEST_PASSWORD = "test_password_please_ignore"
add_new_user_password(session, "test", TEST_PASSWORD, user.id)
assert len(user_passwords(session, user)) == 1, "The user should only have a single password"
graph.update_from_db(session)
c = Counter.get(session, name="updates")
api_url = url(base_url, '/users/{}'.format(user.username))
resp = yield http_client.fetch(api_url)
body = json.loads(resp.body)
assert body["checkpoint"] == c.count, "The API response is not up to date"
assert body["data"]["user"]["passwords"] != [], "The user should not have an empty passwords field"
assert body["data"]["user"]["passwords"][0]["name"] == "test", "The password should have the same name"
assert body["data"]["user"]["passwords"][0]["func"] == "crypt(3)-$6$", "This test does not support any hash functions other than crypt(3)-$6$"
assert body["data"]["user"]["passwords"][0]["hash"] == crypt.crypt(TEST_PASSWORD, body["data"]["user"]["passwords"][0]["salt"]), "The hash should be the same as hashing the password and the salt together using the hashing function"
assert body["data"]["user"]["passwords"][0]["hash"] != crypt.crypt("hello", body["data"]["user"]["passwords"][0]["salt"]), "The hash should not be the same as hashing the wrong password and the salt together using the hashing function"
delete_user_password(session, "test", user.id)
c = Counter.get(session, name="updates")
graph.update_from_db(session)
api_url = url(base_url, '/users/{}'.format(user.username))
resp = yield http_client.fetch(api_url)
body = json.loads(resp.body)
assert body["checkpoint"] == c.count, "The API response is not up to date"
assert body["data"]["user"]["passwords"] == [], "The user should not have any passwords"
示例5: grant_permission_to_tag
def grant_permission_to_tag(session, tag_id, permission_id, argument=''):
# type: (Session, int, int, str) -> bool
"""
Grant a permission to this tag. This will fail if the (permission, argument) has already
been granted to this tag.
Args:
session(models.base.session.Sessioan): database session
tag_id(int): the id of the tag we're granting the permission to
permission_id(int): the id of the permission to be granted
argument(str): must match constants.ARGUMENT_VALIDATION
Throws:
AssertError if argument does not match ARGUMENT_VALIDATION regex
Returns:
bool indicating whether the function succeeded or not
"""
assert re.match(ARGUMENT_VALIDATION + r"$", argument), \
'Permission argument does not match regex.'
try:
mapping = TagPermissionMap(permission_id=permission_id, tag_id=tag_id, argument=argument)
mapping.add(session)
Counter.incr(session, "updates")
except IntegrityError:
session.rollback()
return False
session.commit()
return True
示例6: post
def post(self, name=None, mapping_id=None):
grantable = self.current_user.my_grantable_permissions()
if not grantable:
return self.forbidden()
mapping = PermissionMap.get(self.session, id=mapping_id)
if not mapping:
return self.notfound()
allowed = False
for perm in grantable:
if perm[0].name == mapping.permission.name:
if matches_glob(perm[1], mapping.argument):
allowed = True
if not allowed:
return self.forbidden()
permission = mapping.permission
group = mapping.group
mapping.delete(self.session)
Counter.incr(self.session, "updates")
self.session.commit()
AuditLog.log(self.session, self.current_user.id, 'revoke_permission',
'Revoked permission with argument: {}'.format(mapping.argument),
on_group_id=group.id, on_permission_id=permission.id)
return self.redirect('/groups/{}?refresh=yes'.format(group.name))
示例7: set_metadata
def set_metadata(self, key, value):
if not re.match(PERMISSION_VALIDATION, key):
raise ValueError('Metadata key does not match regex.')
row = None
for try_row in self.my_metadata():
if try_row.data_key == key:
row = try_row
break
if row:
if value is None:
row.delete(self.session)
else:
row.data_value = value
else:
if value is None:
# Do nothing, a delete on a key that's not set
return
else:
row = UserMetadata(user_id=self.id, data_key=key, data_value=value)
row.add(self.session)
Counter.incr(self.session, "updates")
self.session.commit()
示例8: post
def post(self):
form = TagCreateForm(self.request.arguments)
if not form.validate():
return self.render(
"tag-create.html", form=form,
alerts=self.get_form_alerts(form.errors)
)
tag = PublicKeyTag(
name=form.data["tagname"],
description=form.data["description"],
)
try:
tag.add(self.session)
self.session.flush()
except IntegrityError:
self.session.rollback()
form.tagname.errors.append(
"{} already exists".format(form.data["tagname"])
)
return self.render(
"tag-create.html", form=form,
alerts=self.get_form_alerts(form.errors)
)
Counter.incr(self.session, "updates")
self.session.commit()
AuditLog.log(self.session, self.current_user.id, 'create_tag',
'Created new tag.', on_tag_id=tag.id)
return self.redirect("/tags/{}?refresh=yes".format(tag.name))
示例9: add_public_key
def add_public_key(session, user, public_key_str):
"""Add a public key for a particular user.
Args:
session: db session
user: User model of user in question
public_key_str: public key to add
Return created PublicKey model or raises DuplicateKey if key is already in use.
"""
pubkey = sshpubkey.PublicKey.from_str(public_key_str)
db_pubkey = PublicKey(
user=user,
public_key='%s %s %s' % (pubkey.key_type, pubkey.key, pubkey.comment),
fingerprint=pubkey.fingerprint,
key_size=pubkey.key_size,
key_type=pubkey.key_type,
)
try:
db_pubkey.add(session)
Counter.incr(session, "updates")
except IntegrityError:
session.rollback()
raise DuplicateKey()
session.commit()
return db_pubkey
示例10: post
def post(self, group_id=None, name=None, account_id=None, accountname=None, mapping_id=None):
group = Group.get(self.session, group_id, name)
if not group:
return self.notfound()
service_account = ServiceAccount.get(self.session, account_id, accountname)
if not service_account:
return self.notfound()
if not self.check_access(self.session, self.current_user, service_account):
return self.forbidden()
mapping = ServiceAccountPermissionMap.get(self.session, mapping_id)
if not mapping:
return self.notfound()
permission = mapping.permission
argument = mapping.argument
mapping.delete(self.session)
Counter.incr(self.session, "updates")
self.session.commit()
AuditLog.log(
self.session,
self.current_user.id,
"revoke_permission",
"Revoked permission with argument: {}".format(argument),
on_permission_id=permission.id,
on_group_id=group.id,
on_user_id=service_account.user.id,
)
return self.redirect(
"/groups/{}/service/{}?refresh=yes".format(group.name, service_account.user.username)
)
示例11: disable_permission_auditing
def disable_permission_auditing(session, permission_name, actor_user_id):
"""Set a permission as audited.
Args:
session(models.base.session.Session): database session
permission_name(str): name of permission in question
actor_user_id(int): id of user who is disabling auditing
"""
permission = get_permission(session, permission_name)
if not permission:
raise NoSuchPermission(name=permission_name)
permission.audited = False
AuditLog.log(
session,
actor_user_id,
"disable_auditing",
"Disabled auditing.",
on_permission_id=permission.id,
)
Counter.incr(session, "updates")
session.commit()
示例12: grant_permission_to_service_account
def grant_permission_to_service_account(session, account, permission, argument=""):
"""
Grant a permission to this service account. This will fail if the (permission, argument) has
already been granted to this group.
Args:
session(models.base.session.Session): database session
account(ServiceAccount): a ServiceAccount object being granted a permission
permission(Permission): a Permission object being granted
argument(str): must match constants.ARGUMENT_VALIDATION
Throws:
AssertError if argument does not match ARGUMENT_VALIDATION regex
"""
assert re.match(
ARGUMENT_VALIDATION + r"$", argument
), "Permission argument does not match regex."
mapping = ServiceAccountPermissionMap(
permission_id=permission.id, service_account_id=account.id, argument=argument
)
mapping.add(session)
Counter.incr(session, "updates")
session.commit()
示例13: add_service_account
def add_service_account(session, group, service_account):
# type: (Session, Group, ServiceAccount) -> None
"""Add a service account to a group."""
logging.debug("Adding service account %s to %s", service_account.user.username,
group.groupname)
GroupServiceAccount(group_id=group.id, service_account=service_account).add(session)
Counter.incr(session, "updates")
session.commit()
示例14: revoke_member
def revoke_member(self, requester, user_or_group, reason):
""" Revoke a member (User or Group) from this group.
Arguments:
requester: A User object of the person requesting the addition
user_or_group: A User/Group object of the member
reason: A comment on why this member should exist
"""
now = datetime.utcnow()
logging.debug(
"Revoking member (%s) from %s", user_or_group.name, self.groupname
)
# Create the edge even if it doesn't exist so that we can explicitly
# disable it.
edge, new = GroupEdge.get_or_create(
self.session,
group_id=self.id,
member_type=user_or_group.member_type,
member_pk=user_or_group.id,
)
self.session.flush()
request = Request(
requester_id=requester.id,
requesting_id=self.id,
on_behalf_obj_type=user_or_group.member_type,
on_behalf_obj_pk=user_or_group.id,
requested_at=now,
edge_id=edge.id,
status="actioned",
changes=build_changes(
edge, role="member", expiration=None, active=False
)
).add(self.session)
self.session.flush()
request_status_change = RequestStatusChange(
request=request,
user_id=requester.id,
to_status="actioned",
change_at=now
).add(self.session)
self.session.flush()
Comment(
obj_type=OBJ_TYPES_IDX.index("RequestStatusChange"),
obj_pk=request_status_change.id,
user_id=requester.id,
comment=reason,
created_on=now
).add(self.session)
edge.apply_changes(request)
self.session.flush()
Counter.incr(self.session, "updates")
示例15: disable_user_token
def disable_user_token(session, user_token):
"""Disable specified user token.
Args:
session(grouper.models.base.session.Session): database session
user_token(grouper.models.user_token.UserToken): token to disable
"""
user_token.disabled_at = datetime.utcnow()
Counter.incr(session, "updates")