3333
3434from roundup .exceptions import RoundupException
3535
36- ### Exceptions
36+ # Exceptions
3737
3838
3939class ConfigurationError (RoundupException ):
@@ -119,7 +119,7 @@ def __str__(self):
119119def create_token (size = 32 ):
120120 return b2s (binascii .b2a_base64 (random_ .token_bytes (size )).strip ())
121121
122- ### Option classes
122+ # Option classes
123123
124124
125125class Option :
@@ -434,41 +434,41 @@ class IndexerOption(Option):
434434 # SELECT cfgname FROM pg_ts_config;
435435 # on a postgresql 14.1 server.
436436 # So the best we can do is hardcode this.
437- valid_langs = [ "simple" ,
438- "custom1" ,
439- "custom2" ,
440- "custom3" ,
441- "custom4" ,
442- "custom5" ,
443- "arabic" ,
444- "armenian" ,
445- "basque" ,
446- "catalan" ,
447- "danish" ,
448- "dutch" ,
449- "english" ,
450- "finnish" ,
451- "french" ,
452- "german" ,
453- "greek" ,
454- "hindi" ,
455- "hungarian" ,
456- "indonesian" ,
457- "irish" ,
458- "italian" ,
459- "lithuanian" ,
460- "nepali" ,
461- "norwegian" ,
462- "portuguese" ,
463- "romanian" ,
464- "russian" ,
465- "serbian" ,
466- "spanish" ,
467- "swedish" ,
468- "tamil" ,
469- "turkish" ,
470- "yiddish" ]
471-
437+ valid_langs = ["simple" ,
438+ "custom1" ,
439+ "custom2" ,
440+ "custom3" ,
441+ "custom4" ,
442+ "custom5" ,
443+ "arabic" ,
444+ "armenian" ,
445+ "basque" ,
446+ "catalan" ,
447+ "danish" ,
448+ "dutch" ,
449+ "english" ,
450+ "finnish" ,
451+ "french" ,
452+ "german" ,
453+ "greek" ,
454+ "hindi" ,
455+ "hungarian" ,
456+ "indonesian" ,
457+ "irish" ,
458+ "italian" ,
459+ "lithuanian" ,
460+ "nepali" ,
461+ "norwegian" ,
462+ "portuguese" ,
463+ "romanian" ,
464+ "russian" ,
465+ "serbian" ,
466+ "spanish" ,
467+ "swedish" ,
468+ "tamil" ,
469+ "turkish" ,
470+ "yiddish" ]
471+
472472 def str2value (self , value ):
473473 _val = value .lower ()
474474 if _val in self .allowed :
@@ -495,18 +495,19 @@ def validate(self, options):
495495 lang_avail , 75 ,
496496 subsequent_indent = " " )
497497 raise OptionValueError (options ["INDEXER_LANGUAGE" ],
498- lang , languages )
498+ lang , languages )
499499
500500 if self ._value == "native-fts" :
501501 lang = options ["INDEXER_LANGUAGE" ]._value
502502 if lang not in self .valid_langs :
503503 import textwrap
504504 languages = textwrap .fill (_ ("Expected languages: " ) +
505- " " .join (self .valid_langs ), 75 ,
506- subsequent_indent = " " )
505+ " " .join (self .valid_langs ), 75 ,
506+ subsequent_indent = " " )
507507 raise OptionValueError (options ["INDEXER_LANGUAGE" ],
508508 lang , languages )
509509
510+
510511class MailAddressOption (Option ):
511512
512513 """Email address
@@ -540,6 +541,7 @@ def get(self):
540541 _val = os .path .join (self .config ["HOME" ], _val )
541542 return _val
542543
544+
543545class SpaceSeparatedListOption (Option ):
544546
545547 """List of space seperated elements.
@@ -551,31 +553,32 @@ def get(self):
551553 pathlist = []
552554 _val = Option .get (self )
553555 for elem in _val .split ():
554- pathlist .append (elem )
556+ pathlist .append (elem )
555557 if pathlist :
556558 return pathlist
557559 else :
558560 return None
559561
562+
560563class OriginHeadersListOption (Option ):
561564
562565 """List of space seperated origin header values.
563566 """
564567
565568 class_description = "A list of space separated case sensitive origin headers 'scheme://host'."
566569
567-
568570 def set (self , _val ):
569571 pathlist = self ._value = []
570572 for elem in _val .split ():
571- pathlist .append (elem )
573+ pathlist .append (elem )
572574 if '*' in pathlist and len (pathlist ) != 1 :
573575 raise OptionValueError (self , _val ,
574576 "If using '*' it must be the only element." )
575577
576578 def _value2str (self , value ):
577579 return ',' .join (value )
578580
581+
579582class MultiFilePathOption (Option ):
580583
581584 """List of space seperated File or directory path name
@@ -684,13 +687,14 @@ class SecretOption(Option):
684687
685688 """
686689
687- class_description = \
688- "A string that starts with 'file://' is interpreted as a file path \n " \
689- "relative to the tracker home. Using 'file:///' defines an absolute \n " \
690- "path. The first line of the file will be used as the value. Any \n " \
691- "string that does not start with 'file://' is used as is. It \n " \
692- "removes any whitespace at the end of the line, so a newline can \n " \
693- "be put in the file.\n "
690+ class_description = (
691+ "A string that starts with 'file://' is interpreted\n "
692+ "as a file path relative to the tracker home. Using\n "
693+ "'file:///' defines an absolute path. The first\n "
694+ "line of the file will be used as the value. Any\n "
695+ "string that does not start with 'file://' is used\n "
696+ "as is. It removes any whitespace at the end of the\n "
697+ "line, so a newline can be put in the file.\n " )
694698
695699 def get (self ):
696700 _val = Option .get (self )
@@ -707,7 +711,8 @@ def get(self):
707711 if e .errno != errno .ENOENT :
708712 raise
709713 else :
710- raise OptionValueError (self , _val ,
714+ raise OptionValueError (
715+ self , _val ,
711716 "Unable to read value for %s. Error opening "
712717 "%s: %s." % (self .name , e .filename , e .args [1 ]))
713718 return self .str2value (_val )
@@ -722,9 +727,10 @@ def validate(self, options):
722727 self .get ()
723728 except OptionUnsetError :
724729 # provide error message with link to MAIL_USERNAME
725- raise OptionValueError (options ["MAIL_PASSWORD" ],
726- "not defined" ,
727- "Mail username is set, so this must be defined." )
730+ raise OptionValueError (
731+ options ["MAIL_PASSWORD" ],
732+ "not defined" ,
733+ "Mail username is set, so this must be defined." )
728734 else :
729735 self .get ()
730736
@@ -802,6 +808,7 @@ class SecretNullableOption(NullableOption, SecretOption):
802808 get = SecretOption .get
803809 class_description = SecretOption .class_description
804810
811+
805812class RedisUrlOption (SecretNullableOption ):
806813 """Do required check to make sure known bad parameters are not
807814 put in the url.
@@ -810,7 +817,7 @@ class RedisUrlOption(SecretNullableOption):
810817 redis, rediss, unix? How many cycles to invest
811818 to keep users from their own mistakes?
812819 """
813-
820+
814821 class_description = SecretNullableOption .class_description
815822
816823 def str2value (self , value ):
@@ -820,6 +827,7 @@ def str2value(self, value):
820827 "the option." )
821828 return value
822829
830+
823831class SessiondbBackendOption (Option ):
824832 """Make sure that sessiondb is compatile with the primary db.
825833 Fail with error and suggestions if they are incompatible.
@@ -852,32 +860,34 @@ def validate(self, options):
852860
853861 redis_available = False
854862 try :
855- import redis
863+ import redis # noqa: F401
856864 redis_available = True
857865 except ImportError :
858866 if sessiondb_backend == 'redis' :
859867 valid_session_backends = ', ' .join (sorted (list (
860- [ x [1 ] for x in self .compatibility_matrix
861- if x [0 ] == rdbms_backend and x [1 ] != 'redis' ])
868+ [x [1 ] for x in self .compatibility_matrix
869+ if x [0 ] == rdbms_backend and x [1 ] != 'redis' ])
862870 ))
863- raise OptionValueError (self , sessiondb_backend ,
864- "Unable to load redis module. Please install "
865- "a redis library or choose\n an alternate "
866- "session db: %(valid_session_backends)s" % locals ())
871+ raise OptionValueError (
872+ self , sessiondb_backend ,
873+ "Unable to load redis module. Please install "
874+ "a redis library or choose\n an alternate "
875+ "session db: %(valid_session_backends)s" % locals ())
867876
868- if ( (rdbms_backend , sessiondb_backend ) not in
869- self .compatibility_matrix ):
877+ if ((rdbms_backend , sessiondb_backend ) not in
878+ self .compatibility_matrix ):
870879
871880 valid_session_backends = ', ' .join (sorted (list (
872- set ([ x [1 ] for x in self .compatibility_matrix
873- if x [0 ] == rdbms_backend and
874- ( redis_available or x [1 ] != 'redis' )])
881+ set ([x [1 ] for x in self .compatibility_matrix
882+ if x [0 ] == rdbms_backend and
883+ ( redis_available or x [1 ] != 'redis' )])
875884 )))
876885
877- raise OptionValueError (self , sessiondb_backend ,
886+ raise OptionValueError (
887+ self , sessiondb_backend ,
878888 "You can not use session db type: %(sessiondb_backend)s "
879889 "with %(rdbms_backend)s.\n Valid session db types: "
880- "%(valid_session_backends)s." % locals ())
890+ "%(valid_session_backends)s." % locals ())
881891
882892
883893class TimezoneOption (Option ):
@@ -900,8 +910,9 @@ def str2value(self, value):
900910 try :
901911 roundup .date .get_timezone (value )
902912 except KeyError :
903- raise OptionValueError (self , value ,
904- "Timezone name or numeric hour offset required" )
913+ raise OptionValueError (
914+ self , value ,
915+ "Timezone name or numeric hour offset required" )
905916 return value
906917
907918
@@ -911,7 +922,8 @@ class HttpVersionOption(Option):
911922
912923 def str2value (self , value ):
913924 if value not in ["HTTP/1.0" , "HTTP/1.1" ]:
914- raise OptionValueError (self , value ,
925+ raise OptionValueError (
926+ self , value ,
915927 "Valid vaues for -V or --http_version are: HTTP/1.0, HTTP/1.1" )
916928 return value
917929
@@ -947,13 +959,14 @@ def str2value(self, value):
947959 value = value .decode ("utf-8" )
948960 return re .compile (value , self .flags )
949961
962+
950963try :
951- import jinja2
952- jinja2_avail = "Available found"
964+ import jinja2 # noqa: F401
965+ jinja2_avail = "Available found"
953966except ImportError :
954- jinja2_avail = "Unavailable needs"
967+ jinja2_avail = "Unavailable needs"
955968
956- ### Main configuration layout.
969+ # Main configuration layout.
957970# Config is described as a sequence of sections,
958971# where each section name is followed by a sequence
959972# of Option definitions. Each Option definition
@@ -973,7 +986,7 @@ def str2value(self, value):
973986 " 'zopetal' for the old TAL engine ported from Zope,\n "
974987 " 'chameleon' for Chameleon,\n "
975988 " 'jinja2' for jinja2 templating.\n "
976- " %s jinja2 module." % jinja2_avail ),
989+ " %s jinja2 module." % jinja2_avail ),
977990 (FilePathOption , "templates" , "html" ,
978991 "Path to the HTML templates directory." ),
979992 (MultiFilePathOption , "static_files" , "" ,
@@ -1705,7 +1718,7 @@ def str2value(self, value):
17051718 ), "Markdown rendering options." ),
17061719)
17071720
1708- ### Configuration classes
1721+ # Configuration classes
17091722
17101723
17111724class Config :
@@ -2200,8 +2213,9 @@ def reset(self):
22002213 def init_logging (self ):
22012214 _file = self ["LOGGING_CONFIG" ]
22022215 if _file and os .path .isfile (_file ):
2203- logging .config .fileConfig (_file ,
2204- disable_existing_loggers = self ["LOGGING_DISABLE_LOGGERS" ])
2216+ logging .config .fileConfig (
2217+ _file ,
2218+ disable_existing_loggers = self ["LOGGING_DISABLE_LOGGERS" ])
22052219 return
22062220
22072221 _file = self ["LOGGING_FILENAME" ]
0 commit comments