@ -1,5 +1,3 @@
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
"""
The authentication system .
@ -158,28 +156,28 @@ class AutoForm(BoundForm):
@@ -158,28 +156,28 @@ class AutoForm(BoundForm):
def __init__ ( self , model_or_instance , mode = ' add ' , prefix = None , name = None , title = None , method = None , action = None ) :
if not name :
name = ' %s - %s ' % ( self . model . __name__ , self . instance . handle_string . replace ( ' . ' , ' - ' ) )
name = f " { self . model . __name__ } - { self . instance . handle_string . replace ( ' . ' , ' - ' ) } "
super ( AutoForm , self ) . __init__ ( model_or_instance , mode = mode , prefix = prefix , name = name , title = title , method = method , action = action )
if not title :
if hasattr ( self . instance , ' title ' ) and self . instance . title :
self . title = " %s %s ' %s ' " % ( self . mode , self . model . __name__ , self . instance . title )
self . title = f " { self . mode } { self . model . __name__ } ' { self . instance . title } ' "
elif self . instance . name :
self . title = " %s %s ' %s ' " % ( self . mode , self . model . __name__ , self . instance . name )
self . title = f " { self . mode } { self . model . __name__ } ' { self . instance . name } ' "
elif self . instance . id :
self . title = " %s %s # %d " % ( self . mode , self . model . __name__ , self . instance . id )
self . title = f " { self . mode } { self . model . __name__ } # { self . instance . id } "
else :
try :
if self . instance . _pk :
self . title = " %s %s ' %s ' " % ( self . mode , self . model . __name__ , self . instance . _pk )
self . title = f " { self . mode } { self . model . __name__ } ' { self . instance . _pk } ' "
else :
self . title = " %s %s " % ( self . mode , self . model . __name__ )
self . title = f " { self . mode } { self . model . __name__ } "
except Exception as e :
self . title = " %s %s " % ( self . mode , self . model . __name__ )
self . title = f " { self . mode } { self . model . __name__ } "
for name , field in self . fields . items ( ) :
#if hasattr(self.instance, name): # fucks up with DoesNotExist on unfilled foreign keys
@ -218,7 +216,7 @@ class AutoForm(BoundForm):
@@ -218,7 +216,7 @@ class AutoForm(BoundForm):
saved = self . instance . save ( )
if saved :
flash ( u " Saved %s %s . " % ( self . model . __name__ , self . instance . handle_string ) )
flash ( f " Saved { self . model . __name__ } { self . instance . handle_string } . " )
try :
self . process_all_fieldsets ( submit )
except Exception as e :
@ -236,7 +234,7 @@ class AutoForm(BoundForm):
@@ -236,7 +234,7 @@ class AutoForm(BoundForm):
return self
else :
flash ( u " Couldn ' t save %s . " % self . model . __name__ )
flash ( f " Couldn ' t save { self . model . __name__ } . " )
except poobrains . errors . ValidationError as e :
@ -250,21 +248,21 @@ class AutoForm(BoundForm):
@@ -250,21 +248,21 @@ class AutoForm(BoundForm):
if exceptions :
raise
flash ( u ' Integrity error: %s ' % str ( e ) , ' error ' )
app . logger . error ( u " Integrity error: %s " % str ( e ) )
flash ( f ' Integrity error: { str ( e ) } ' , ' error ' )
app . logger . error ( f " Integrity error: { str ( e ) } " )
except Exception as e :
if exceptions :
raise
flash ( u " Couldn ' t save %s for mysterious reasons. " % self . model . __name__ )
app . logger . error ( u " Couldn ' t save %s . %s : %s " % ( self . model . __name__ , type ( e ) . __name__ , str ( e ) ) )
flash ( f " Couldn ' t save { self . model . __name__ } for mysterious reasons. " )
app . logger . error ( f " Couldn ' t save { self . model . __name__ } . { type ( e ) . __name__ } : { str ( e ) } " )
elif submit == ' preview ' :
self . preview = self . instance . render ( ' full ' )
else :
flash ( u " Not handling readonly form ' %s ' . " % self . name )
flash ( f " Not handling readonly form ' { self . name } ' . " )
return self
@ -277,7 +275,7 @@ class DeleteForm(BoundForm):
@@ -277,7 +275,7 @@ class DeleteForm(BoundForm):
f = super ( DeleteForm , cls ) . __new__ ( cls , model_or_instance , prefix = prefix , name = None , title = title , method = method , action = action )
f . title = " Delete %s " % f . instance . name
f . title = f " Delete { f . instance . name } "
f . warning = poobrains . form . fields . Message ( ' deletion_irrevocable ' , value = ' Deletion is not revocable. Proceed? ' )
f . submit = poobrains . form . Button ( ' submit ' , name = ' submit ' , value = ' delete ' , label = u ' ☠ ' )
@ -287,16 +285,16 @@ class DeleteForm(BoundForm):
@@ -287,16 +285,16 @@ class DeleteForm(BoundForm):
super ( DeleteForm , self ) . __init__ ( model_or_instance , mode = mode , prefix = prefix , name = self . name , title = title , method = method , action = action )
if not title :
if hasattr ( self . instance , ' title ' ) and self . instance . title :
self . title = " Delete %s %s " % ( self . model . __name__ , self . instance . title )
self . title = f " Delete { self . model . __name__ } { self . instance . title } "
else :
self . title = " Delete %s %s " % ( self . model . __name__ , str ( self . instance . _pk ) )
self . title = f " Delete { self . model . __name__ } { str ( self . instance . _pk ) } "
def process ( self , submit ) :
if hasattr ( self . instance , ' title ' ) and self . instance . title :
message = " Deleted %s ' %s ' . " % ( self . model . __name__ , self . instance . title )
message = f " Deleted { self . model . __name__ } ' { self . instance . title } ' . "
else :
message = " Deleted %s ' %s ' . " % ( self . model . __name__ , str ( self . instance . _pk ) )
message = f " Deleted { self . model . __name__ } ' { str ( self . instance . _pk ) } ' . "
self . instance . delete_instance ( recursive = True )
flash ( message )
@ -329,7 +327,7 @@ class AccessField(poobrains.form.fields.Field):
@@ -329,7 +327,7 @@ class AccessField(poobrains.form.fields.Field):
if name == ' prefix ' :
for field in [ self . read , self . update , self . delete ] :
field . prefix = ' %s . %s ' % ( value , self . name )
field . prefix = f ' { value } . { self . name } '
elif name == ' value ' :
@ -395,7 +393,7 @@ class Permission(poobrains.helpers.ChildAware):
@@ -395,7 +393,7 @@ class Permission(poobrains.helpers.ChildAware):
@classmethod
def check ( cls , user ) :
msg = " Permission %s denied. " % cls . __name__
msg = f " Permission { cls . __name__ } denied. "
granted = None
# check user-assigned permission state
@ -447,7 +445,7 @@ class Permission(poobrains.helpers.ChildAware):
@@ -447,7 +445,7 @@ class Permission(poobrains.helpers.ChildAware):
granted = self . _check_values [ user ]
if not granted :
raise AccessDenied ( " Permission %s denied. " % self . __class__ . __name__ )
raise AccessDenied ( f " Permission { self . __class__ . __name__ } denied. " )
return granted
@ -504,8 +502,8 @@ class PermissionInjection(poobrains.helpers.MetaCompatibility):
@@ -504,8 +502,8 @@ class PermissionInjection(poobrains.helpers.MetaCompatibility):
#for op in ['create', 'read', 'update', 'delete']:
for op in set ( cls . _meta . modes . values ( ) ) :
perm_name = " %s _ %s " % ( cls . __name__ , op )
perm_label = " %s %s " % ( op . capitalize ( ) , cls . __name__ )
perm_name = f " { cls . __name__ } _ { op } "
perm_label = f " { op . capitalize ( ) } { cls . __name__ } "
#cls._meta.permissions[mode] = type(perm_name, (cls._meta.permission_class,), {})
perm_attrs = dict ( )
perm_attrs [ ' op ' ] = op
@ -538,7 +536,7 @@ class PermissionParamType(poobrains.form.types.StringParamType):
@@ -538,7 +536,7 @@ class PermissionParamType(poobrains.form.types.StringParamType):
try :
permission , access = cleaned_string . split ( ' . ' )
except Exception as e :
self . fail ( ' Could not split value to permission and access: %s ' % cleaned_string )
self . fail ( f ' Could not split value to permission and access: { cleaned_string } ' )
return ( permission , access )
@ -560,25 +558,25 @@ class FormPermissionField(poobrains.form.fields.Select):
@@ -560,25 +558,25 @@ class FormPermissionField(poobrains.form.fields.Select):
permissions = Permission . class_children_keyed ( )
for perm_name in sorted ( permissions ) :
perm = permissions [ perm_name ]
self . choices . append ( ( [ ( ' %s . %s ' % ( perm_name , value ) , label ) for ( value , label ) in perm . choices ] , perm_name ) )
self . choices . append ( ( [ ( f ' { perm_name } . { value } ' , label ) for ( value , label ) in perm . choices ] , perm_name ) )
def validate ( self ) :
permission , access = self . value
if not permission in Permission . class_children_keyed ( ) . keys ( ) :
raise poobrains . errors . ValidationError ( ' Unknown permission: %s ' % permission )
raise poobrains . errors . ValidationError ( f ' Unknown permission: { permission } ' )
perm_class = Permission . class_children_keyed ( ) [ permission ]
choice_values = [ t [ 0 ] for t in perm_class . choices ]
if not access in choice_values :
raise poobrains . errors . ValidationError ( " Unknown access mode ' %s ' for permission ' %s ' . " % ( access , permission ) )
raise poobrains . errors . ValidationError ( f " Unknown access mode ' { access } ' for permission ' { permission } ' . " )
def admin_listing_actions ( cls ) :
m = poobrains . rendering . Menu ( ' actions ' )
if ' add ' in cls . _meta . modes :
m . append ( cls . url ( ' add ' ) , ' add new %s ' % ( cls . __name__ , ) )
m . append ( cls . url ( ' add ' ) , f ' add new { cls . __name__ } ' )
return m
@ -597,7 +595,7 @@ def admin_menu():
@@ -597,7 +595,7 @@ def admin_menu():
for mode , endpoints in listings . items ( ) :
for endpoint in endpoints : # iterates through endpoints.keys()
menu . append ( url_for ( ' admin. %s ' % endpoint ) , administerable . __name__ )
menu . append ( url_for ( f ' admin. { endpoint } ' ) , administerable . __name__ )
return menu
@ -618,11 +616,11 @@ def admin_index():
@@ -618,11 +616,11 @@ def admin_index():
for administerable , listings in app . admin . listings . items ( ) :
subcontainer = poobrains . rendering . Container ( css_class = ' administerable-actions ' , mode = ' full ' )
menu = poobrains . rendering . Menu ( ' listings- %s ' % administerable . __name__ )
menu = poobrains . rendering . Menu ( f ' listings- { administerable . __name__ } ' )
for mode , endpoints in listings . items ( ) :
for endpoint in endpoints : # iterates through endpoints.keys()
menu . append ( url_for ( ' admin. %s ' % endpoint ) , administerable . __name__ )
menu . append ( url_for ( f ' admin. { endpoint } ' ) , administerable . __name__ )
subcontainer . append ( menu )
if administerable . __doc__ :
@ -664,17 +662,16 @@ def protected(func):
@@ -664,17 +662,16 @@ def protected(func):
cls = cls_or_instance
if not ( issubclass ( cls , Protected ) or isinstance ( cls_or_instance , Protected ) ) :
raise ValueError ( " @protected used with non-protected class ' %s ' . " % cls . __name__ )
raise ValueError ( f " @protected used with non-protected class ' { cls . __name__ } ' . " )
if not mode in cls . _meta . modes :
raise AccessDenied ( " Unknown mode ' %s ' for accessing %s . " % ( mode , cls . __name__ ) )
raise AccessDenied ( f " Unknown mode ' { mode } ' for accessing { cls . __name__ } . " )
op = cls . _meta . modes [ mode ]
if not op in [ ' create ' , ' read ' , ' update ' , ' delete ' ] :
raise AccessDenied ( " Unknown access op ' %s ' for accessing %s . " ( op , cls . __name__ ) )
raise AccessDenied ( f " Unknown access op ' { op } ' for accessing { cls . __name__ } . " )
if not op in cls_or_instance . permissions :
raise NotImplementedError ( " Did not find permission for op ' %s ' in cls_or_instance of class ' %s ' . " % ( op , cls . __name__ ) )
raise NotImplementedError ( f " Did not find permission for op ' { op } ' in cls_or_instance of class ' { cls . __name__ } ' . " )
cls_or_instance . permissions [ op ] . check ( user )
@ -743,11 +740,11 @@ class ClientCertForm(poobrains.form.Form):
@@ -743,11 +740,11 @@ class ClientCertForm(poobrains.form.Form):
if self . controls [ ' tls_submit ' ] . value :
r = app . response_class ( pkcs12 . export ( passphrase = passphrase ) )
r . mimetype = ' application/pkcs-12 '
flash ( u " The passphrase for this delicious bundle of crypto is ' %s ' " % passphrase )
flash ( f " The passphrase for this delicious bundle of crypto is ' { passphrase } ' " )
else : # means pgp mail
text = " Hello %s . Here ' s your new set of keys to the gates of Shambala. \n Your passphrase is ' %s ' . " % ( token . user . name , passphrase )
text = f " Hello { token . user . name } . Here ' s your new set of keys to the gates of Shambala. \n Your passphrase is ' { passphrase } ' . "
mail = poobrains . mailing . Mail ( token . user . pgp_fingerprint )
mail [ ' Subject ' ] = ' Bow before entropy '
@ -759,11 +756,10 @@ class ClientCertForm(poobrains.form.Form):
@@ -759,11 +756,10 @@ class ClientCertForm(poobrains.form.Form):
mail . send ( )
flash ( u " Your private key and client certificate have been send to ' %s ' . " % token . user . mail )
flash ( f " Your private key and client certificate have been send to ' { token . user . mail } ' . " )
r = self
try :
cert_info . save ( )
@ -813,7 +809,7 @@ class OwnedPermission(Permission):
@@ -813,7 +809,7 @@ class OwnedPermission(Permission):
return True
else :
app . logger . warning ( " Unknown access mode ' %s ' for User %d with Permission %s " % ( access , user . id , cls . __name__ ) )
app . logger . warning ( f " Unknown access mode ' { access } ' for User # { user . id } with Permission { cls . __name__ } " )
raise AccessDenied ( " YOU SHALL NOT PASS! " )
else :
@ -972,7 +968,7 @@ class RelatedForm(poobrains.form.Form):
@@ -972,7 +968,7 @@ class RelatedForm(poobrains.form.Form):
endpoint = request . endpoint
if not endpoint . endswith ( ' _offset ' ) :
endpoint = ' %s _offset ' % ( endpoint , )
endpoint = f ' { endpoint } _offset '
f = super ( RelatedForm , cls ) . __new__ ( cls , prefix = prefix , name = name , title = title , method = method , action = action )
@ -1011,7 +1007,7 @@ class RelatedForm(poobrains.form.Form):
@@ -1011,7 +1007,7 @@ class RelatedForm(poobrains.form.Form):
self . related_model = related_model
self . related_field = related_field
self . title = " %s for %s %s " % ( self . related_model . __name__ , self . instance . __class__ . __name__ , self . instance . handle_string )
self . title = f " { self . related_model . __name__ } for { self . instance . __class__ . __name__ } { self . instance . handle_string } "
def process ( self , submit ) :
@ -1021,8 +1017,8 @@ class RelatedForm(poobrains.form.Form):
@@ -1021,8 +1017,8 @@ class RelatedForm(poobrains.form.Form):
try :
fieldset . process ( submit )
except Exception as e :
flash ( u " Failed to process fieldset ' %s . %s ' . " % ( fieldset . prefix , fieldset . name ) )
app . logger . error ( " Failed to process fieldset %s . %s - %s : %s " % ( fieldset . prefix , fieldset . name , type ( e ) . __name__ , str ( e ) ) )
flash ( f " Failed to process fieldset ' { fieldset . prefix } . { fieldset . name } ' . " )
app . logger . error ( f " Failed to process fieldset { fieldset . prefix } . { fieldset . name } - { type ( e ) . __name__ } : { str ( e ) } " )
return redirect ( request . url )
return self
@ -1129,7 +1125,7 @@ class Protected(poobrains.rendering.Renderable, metaclass=PermissionInjection):
@@ -1129,7 +1125,7 @@ class Protected(poobrains.rendering.Renderable, metaclass=PermissionInjection):
except AccessDenied :
if mode == ' inline ' :
return Markup ( poobrains . rendering . RenderString ( " Access Denied for %s . " % self . __class__ . __name__ ) )
return Markup ( poobrains . rendering . RenderString ( f " Access Denied for { self . __class__ . __name__ } . " ) )
raise
@ -1253,7 +1249,7 @@ class Administerable(poobrains.storage.Storable, Protected, metaclass=BaseAdmini
@@ -1253,7 +1249,7 @@ class Administerable(poobrains.storage.Storable, Protected, metaclass=BaseAdmini
actions . append ( self . url ( mode ) , mode )
except AccessDenied :
app . logger . debug ( " Not generating %s link for %s %s because this user is not authorized for it. " % ( mode , self . __class__ . __name__ , self . handle_string ) )
app . logger . debug ( f " Not generating { mode } link for { self . __class__ . __name__ } { self . handle_string } because this user is not authorized for it. " )
except LookupError :
pass
#app.logger.debug("Couldn't create %s link for %s" % (mode, self.handle_string))
@ -1291,9 +1287,9 @@ class Administerable(poobrains.storage.Storable, Protected, metaclass=BaseAdmini
@@ -1291,9 +1287,9 @@ class Administerable(poobrains.storage.Storable, Protected, metaclass=BaseAdmini
def form ( self , mode = None ) :
n = ' form_ %s ' % mode
n = f ' form_ { mode } '
if not hasattr ( self , n ) :
raise NotImplementedError ( " Form class %s . %s missing. " % ( self . __class__ . __name__ , n ) )
raise NotImplementedError ( f " Form class { self . __class__ . __name__ } . { n } missing. " )
form_class = getattr ( self , n )
return form_class ( mode = mode ) #, name=None, title=None, method=None, action=None)
@ -1349,7 +1345,7 @@ class Administerable(poobrains.storage.Storable, Protected, metaclass=BaseAdmini
@@ -1349,7 +1345,7 @@ class Administerable(poobrains.storage.Storable, Protected, metaclass=BaseAdmini
def related_view ( cls , related_field = None , handle = None , offset = 0 ) :
if related_field is None :
raise TypeError ( " %s .related_view needs Field instance for parameter ' related_field ' . Got %s ( %s ) instead. " % ( cls . __name__ , type ( field ) . __name__ , str ( field ) ) )
raise TypeError ( f " { cls . __name__ } .related_view needs Field instance for parameter ' related_field ' . Got { type ( field ) . __name__ } ( { str ( field ) } ) instead. " )
related_model = related_field . model
instance = cls . load ( handle )
@ -1478,9 +1474,9 @@ class User(ProtectedNamed):
@@ -1478,9 +1474,9 @@ class User(ProtectedNamed):
invalid_after = datetime . datetime . now ( ) + datetime . timedelta ( seconds = app . config [ ' CERT_MAX_LIFETIME ' ] ) # FIXME: DRY!
if not_after > invalid_after :
raise poobrains . errors . ExposedError ( " not_after too far into the future, max allowed %s but got %s " % ( invalid_after , not_after ) )
raise poobrains . errors . ExposedError ( f " not_after too far into the future, max allowed { invalid_after } but got { not_after } " )
common_name = ' %s : %s @ %s ' % ( self . name , name , app . config [ ' SITE_NAME ' ] )
common_name = f " { self . name } : { name } @ { app . config [ ' SITE_NAME ' ] } "
fd = open ( app . config [ ' CA_KEY ' ] , ' rb ' )
ca_key = openssl . crypto . load_privatekey ( openssl . crypto . FILETYPE_PEM , fd . read ( ) )
@ -1556,8 +1552,8 @@ class User(ProtectedNamed):
@@ -1556,8 +1552,8 @@ class User(ProtectedNamed):
NOTE : the passed model needs to have a datetime field with the name ' date ' . This is needed for ordering .
"""
assert issubclass ( model , Owned ) and hasattr ( model , ' date ' ) , " Only Owned subclasses with a ' date ' field can be @User.profile ' d. %s does not qualify. " % model . __name__
assert hasattr ( model , ' id ' ) and isinstance ( model . id , poobrains . storage . fields . AutoField ) , " @on_profile model without id: %s " % model . __name__
assert issubclass ( model , Owned ) and hasattr ( model , ' date ' ) , f " Only Owned subclasses with a ' date ' field can be @User.profile ' d. { model . __name__ } does not qualify. "
assert hasattr ( model , ' id ' ) and isinstance ( model . id , poobrains . storage . fields . AutoField ) , f " @on_profile model without id: { model . __name__ } "
cls . _on_profile . append ( model )
@ -1588,7 +1584,7 @@ class User(ProtectedNamed):
@@ -1588,7 +1584,7 @@ class User(ProtectedNamed):
for model in self . models_on_profile :
try :
queries . append ( model . list ( ' read ' , g . user , ordered = False , fields = [ peewee . SQL ( " ' %s ' " % model . __name__ ) . alias ( ' model ' ) , model . id , model . date . alias ( ' date ' ) ] ) . where ( model . owner == self ) )
queries . append ( model . list ( ' read ' , g . user , ordered = False , fields = [ peewee . SQL ( f " ' { model . __name__ } ' " ) . alias ( ' model ' ) , model . id , model . date . alias ( ' date ' ) ] ) . where ( model . owner == self ) )
except AccessDenied :
pass # ignore models we aren't allowed to read
@ -1653,7 +1649,7 @@ class UserPermission(Administerable):
@@ -1653,7 +1649,7 @@ class UserPermission(Administerable):
return Permission . class_children_keyed ( ) [ self . permission ]
except KeyError :
app . logger . error ( " Unknown permission ' %s ' associated to user # %d . " % ( self . permission , self . user_id ) ) # can't use self.user.name because dat recursion
app . logger . error ( f " Unknown permission ' { self . permission } ' associated to user # { self . user_id } . " ) # can't use self.user.name because dat recursion
#TODO: Do we want to do more, like define a permission_class that always denies access?
def save ( self , * args , * * kwargs ) :
@ -1663,7 +1659,7 @@ class UserPermission(Administerable):
@@ -1663,7 +1659,7 @@ class UserPermission(Administerable):
valid_permission_names . append ( cls . __name__ )
if self . permission not in valid_permission_names :
raise ValueError ( " Invalid permission name: %s " % self . permission )
raise ValueError ( f " Invalid permission name: { self . permission } " )
return super ( UserPermission , self ) . save ( * args , * * kwargs )
@ -1732,7 +1728,7 @@ class GroupPermission(Administerable):
@@ -1732,7 +1728,7 @@ class GroupPermission(Administerable):
return Permission . class_children_keyed ( ) [ self . permission ]
except KeyError :
app . logger . error ( " Unknown permission ' %s ' associated to user # %d . " % ( self . permission , self . group_id ) ) # can't use self.group.name because dat recursion
app . logger . error ( f " Unknown permission ' { self . permission } ' associated to user # { self . group_id } . " ) # can't use self.group.name because dat recursion
#TODO: Do we want to do more, like define a permission_class that always denies access?
def form ( self , mode = None ) :
@ -1757,7 +1753,7 @@ class GroupPermission(Administerable):
@@ -1757,7 +1753,7 @@ class GroupPermission(Administerable):
except Group . DoesNotExist :
name = ' FNORD '
return " %s - %s " % ( name , self . permission )
return f " { name } - { self . permission } "
class ClientCertTokenAddForm ( AutoForm ) :
@ -1766,7 +1762,7 @@ class ClientCertTokenAddForm(AutoForm):
@@ -1766,7 +1762,7 @@ class ClientCertTokenAddForm(AutoForm):
r = super ( ClientCertTokenAddForm , self ) . process ( submit , exceptions = exceptions )
self . instance . user . notify ( " A new certificate token was created in your name! \n The token is * %s *. \n It will expire on %s . \n The certificate will be named ' %s ' " % ( self . instance . token , self . instance . expiry_date , self . instance . cert_name ) ) # TODO: check if token was actually saved
self . instance . user . notify ( f " A new certificate token was created in your name! \n The token is * { self . instance . token } *. \n It will expire on { self . instance . expiry_date } . \n The certificate will be named ' { self . instance . cert_name } ' " ) # TODO: check if token was actually saved
return r
@ -1804,18 +1800,14 @@ class ClientCertToken(Administerable, Protected):
@@ -1804,18 +1800,14 @@ class ClientCertToken(Administerable, Protected):
if user_token_count > = app . config [ ' MAX_TOKENS ' ] :
raise ValueError ( # TODO: Is ValueError really the most fitting exception there is?
" User %s already has %d out of %d client certificate tokens. " % (
self . user . name ,
user_token_count ,
app . config [ ' MAX_TOKENS ' ]
)
f " User { self . user . name } already has { user_token_count } out of { app . config [ ' MAX_TOKENS ' ] } client certificate tokens. "
)
if self . __class__ . select ( ) . where ( self . __class__ . user == self . user , self . __class__ . cert_name == self . cert_name ) . count ( ) :
raise ValueError ( " User %s already has a client certificate token for a certificate named ' %s ' . " % ( self . user . name , self . cert_name ) )
raise ValueError ( f " User { self . user . name } already has a client certificate token for a certificate named ' { self . cert_name } ' . " )
if ClientCert . select ( ) . where ( ClientCert . user == self . user , ClientCert . name == self . cert_name ) . count ( ) :
raise ValueError ( " User %s already has a client certificate named ' %s ' . " % ( self . user . name , self . cert_name ) )