Adrià Vilanova MartÃnez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 1 | # Copyright 2016 The Chromium Authors |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 4 | |
| 5 | """Some constants used throughout Monorail.""" |
| 6 | from __future__ import print_function |
| 7 | from __future__ import division |
| 8 | from __future__ import absolute_import |
| 9 | |
| 10 | import os |
| 11 | import re |
| 12 | |
| 13 | |
| 14 | # Number of seconds in various periods. |
| 15 | SECS_PER_MINUTE = 60 |
| 16 | SECS_PER_HOUR = SECS_PER_MINUTE * 60 |
| 17 | SECS_PER_DAY = SECS_PER_HOUR * 24 |
| 18 | SECS_PER_MONTH = SECS_PER_DAY * 30 |
| 19 | SECS_PER_YEAR = SECS_PER_DAY * 365 |
| 20 | |
| 21 | # When we write to memcache, let the values expire so that we don't |
| 22 | # get any unexpected super-old values as we make code changes over the |
| 23 | # years. Also, searches can contain date terms like [opened<today-1] |
| 24 | # that would become wrong if cached for a long time. |
| 25 | CACHE_EXPIRATION = 6 * SECS_PER_HOUR |
| 26 | |
| 27 | # Fulltext indexing happens asynchronously and we get no notification |
| 28 | # when the indexing operation has completed. So, when we cache searches |
| 29 | # that use fulltext terms, the results might be stale. We still do |
| 30 | # cache them and use the cached values, but we expire them so that the |
| 31 | # results cannot be stale for a long period of time. |
| 32 | FULLTEXT_MEMCACHE_EXPIRATION = 3 * SECS_PER_MINUTE |
| 33 | |
| 34 | # Size in bytes of the largest form submission that we will accept |
| 35 | MAX_POST_BODY_SIZE = 10 * 1024 * 1024 # = 10 MB |
| 36 | |
| 37 | # Special issue ID to use when an issue is explicitly not specified. |
| 38 | NO_ISSUE_SPECIFIED = 0 |
| 39 | |
| 40 | # Special user ID and name to use when no user was specified. |
| 41 | NO_USER_SPECIFIED = 0 |
| 42 | NO_SESSION_SPECIFIED = 0 |
| 43 | NO_USER_NAME = '----' |
| 44 | DELETED_USER_NAME = 'a_deleted_user' |
| 45 | DELETED_USER_ID = 1 |
| 46 | USER_NOT_FOUND_NAME = 'user_not_found' |
| 47 | |
| 48 | # Queues for deleting users tasks. |
| 49 | QUEUE_SEND_WIPEOUT_USER_LISTS = 'wipeoutsendusers' |
| 50 | QUEUE_FETCH_WIPEOUT_DELETED_USERS = 'wipeoutdeleteusers' |
| 51 | QUEUE_DELETE_USERS = 'deleteusers' |
| 52 | |
| 53 | # We remember the time of each user's last page view, but to reduce the |
| 54 | # number of database writes, we only update it if it is newer by an hour. |
| 55 | VISIT_RESOLUTION = 1 * SECS_PER_HOUR |
| 56 | |
| 57 | # String to display when some field has no value. |
| 58 | NO_VALUES = '----' |
| 59 | |
| 60 | # If the user enters one or more dashes, that means "no value". This is useful |
| 61 | # in bulk edit, inbound email, and commit log command where a blank field |
| 62 | # means "keep what was there" or is ignored. |
| 63 | NO_VALUE_RE = re.compile(r'^-+$') |
| 64 | |
| 65 | # Used to loosely validate column spec. Mainly guards against malicious input. |
| 66 | COLSPEC_RE = re.compile(r'^[-.\w\s/]*$', re.UNICODE) |
| 67 | COLSPEC_COL_RE = re.compile(r'[-.\w/]+', re.UNICODE) |
| 68 | MAX_COL_PARTS = 25 |
| 69 | MAX_COL_LEN = 50 |
| 70 | |
| 71 | # Used to loosely validate sort spec. Mainly guards against malicious input. |
| 72 | SORTSPEC_RE = re.compile(r'^[-.\w\s/]*$', re.UNICODE) |
| 73 | MAX_SORT_PARTS = 6 |
| 74 | |
| 75 | # For the artifact search box autosizing when the user types a long query. |
| 76 | MIN_ARTIFACT_SEARCH_FIELD_SIZE = 38 |
| 77 | MAX_ARTIFACT_SEARCH_FIELD_SIZE = 75 |
| 78 | AUTOSIZE_STEP = 3 |
| 79 | |
| 80 | # Regular expressions used in parsing label and status configuration text |
| 81 | IDENTIFIER_REGEX = r'[-.\w]+' |
| 82 | IDENTIFIER_RE = re.compile(IDENTIFIER_REGEX, re.UNICODE) |
| 83 | # Labels and status values that are prefixed by a pound-sign are not displayed |
| 84 | # in autocomplete menus. |
| 85 | IDENTIFIER_DOCSTRING_RE = re.compile( |
| 86 | r'^(#?%s)[ \t]*=?[ \t]*(.*)$' % IDENTIFIER_REGEX, |
| 87 | re.MULTILINE | re.UNICODE) |
| 88 | |
| 89 | # Number of label text fields that we can display on a web form for issues. |
| 90 | MAX_LABELS = 24 |
| 91 | |
| 92 | # Default number of comments to display on an artifact detail page at one time. |
| 93 | # Other comments will be paginated. |
| 94 | DEFAULT_COMMENTS_PER_PAGE = 100 |
| 95 | |
| 96 | # Content type to use when serving JSON. |
| 97 | CONTENT_TYPE_JSON = 'application/json; charset=UTF-8' |
| 98 | CONTENT_TYPE_JSON_OPTIONS = 'nosniff' |
| 99 | |
| 100 | # Maximum comments to index to keep the search index from choking. E.g., if an |
| 101 | # artifact had 1200 comments, only 0..99 and 701..1200 would be indexed. |
| 102 | # This mainly affects advocacy issues which are highly redundant anyway. |
| 103 | INITIAL_COMMENTS_TO_INDEX = 100 |
| 104 | FINAL_COMMENTS_TO_INDEX = 500 |
| 105 | |
| 106 | # This is the longest string that GAE search will accept in one field. |
| 107 | # The entire search document is also limited to 1MB, so our limit is 200 * 1024 |
| 108 | # chars so that each can be 4 bytes and the comments leave room for metadata. |
| 109 | # https://cloud.google.com/appengine/docs/standard/python/search/#documents |
| 110 | MAX_FTS_FIELD_SIZE = 200 * 1024 |
| 111 | |
| 112 | # Base path to EZT templates. |
| 113 | this_dir = os.path.dirname(__file__) |
| 114 | TEMPLATE_PATH = this_dir[:this_dir.rindex('/')] + '/templates/' |
| 115 | |
| 116 | # Defaults for dooming a project. |
| 117 | DEFAULT_DOOM_REASON = 'No longer needed' |
| 118 | DEFAULT_DOOM_PERIOD = SECS_PER_DAY * 90 |
| 119 | |
| 120 | MAX_PROJECT_PEOPLE = 1000 |
| 121 | |
| 122 | MAX_HOTLIST_NAME_LENGTH = 80 |
| 123 | |
| 124 | # When logging potentially long debugging strings, only show this many chars. |
| 125 | LOGGING_MAX_LENGTH = 2000 |
| 126 | |
| 127 | # Maps languages supported by google-code-prettify |
| 128 | # to the class name that should be added to code blocks in that language. |
| 129 | # This list should be kept in sync with the handlers registered |
| 130 | # in lang-*.js and prettify.js from the prettify project. |
| 131 | PRETTIFY_CLASS_MAP = { |
| 132 | ext: 'lang-' + ext |
| 133 | for ext in [ |
| 134 | # Supported in lang-*.js |
| 135 | 'apollo', 'agc', 'aea', 'lisp', 'el', 'cl', 'scm', |
| 136 | 'css', 'go', 'hs', 'lua', 'fs', 'ml', 'proto', 'scala', 'sql', 'vb', |
| 137 | 'vbs', 'vhdl', 'vhd', 'wiki', 'yaml', 'yml', 'clj', |
| 138 | # Supported in prettify.js |
| 139 | 'htm', 'html', 'mxml', 'xhtml', 'xml', 'xsl', |
| 140 | 'c', 'cc', 'cpp', 'cxx', 'cyc', 'm', |
| 141 | 'json', 'cs', 'java', 'bsh', 'csh', 'sh', 'cv', 'py', 'perl', 'pl', |
| 142 | 'pm', 'rb', 'js', 'coffee', |
| 143 | ]} |
| 144 | |
| 145 | # Languages which are not specifically mentioned in prettify.js |
| 146 | # but which render intelligibly with the default handler. |
| 147 | PRETTIFY_CLASS_MAP.update( |
| 148 | (ext, '') for ext in [ |
| 149 | 'hpp', 'hxx', 'hh', 'h', 'inl', 'idl', 'swig', 'd', |
| 150 | 'php', 'tcl', 'aspx', 'cfc', 'cfm', |
| 151 | 'ent', 'mod', 'as', |
| 152 | 'y', 'lex', 'awk', 'n', 'pde', |
| 153 | ]) |
| 154 | |
| 155 | # Languages which are not specifically mentioned in prettify.js |
| 156 | # but which should be rendered using a certain prettify module. |
| 157 | PRETTIFY_CLASS_MAP.update({ |
| 158 | 'docbook': 'lang-xml', |
| 159 | 'dtd': 'lang-xml', |
| 160 | 'duby': 'lang-rb', |
| 161 | 'mk': 'lang-sh', |
| 162 | 'mak': 'lang-sh', |
| 163 | 'make': 'lang-sh', |
| 164 | 'mirah': 'lang-rb', |
| 165 | 'ss': 'lang-lisp', |
| 166 | 'vcproj': 'lang-xml', |
| 167 | 'xsd': 'lang-xml', |
| 168 | 'xslt': 'lang-xml', |
| 169 | }) |
| 170 | |
| 171 | PRETTIFY_FILENAME_CLASS_MAP = { |
| 172 | 'makefile': 'lang-sh', |
| 173 | 'makefile.in': 'lang-sh', |
| 174 | 'doxyfile': 'lang-sh', # Key-value pairs with hash comments |
| 175 | '.checkstyle': 'lang-xml', |
| 176 | '.classpath': 'lang-xml', |
| 177 | '.project': 'lang-xml', |
| 178 | } |
| 179 | |
| 180 | OAUTH_SCOPE = 'https://www.googleapis.com/auth/userinfo.email' |
| 181 | MONORAIL_SCOPE = 'https://www.googleapis.com/auth/monorail' |
| 182 | |
| 183 | FILENAME_RE = re.compile('^[-_.a-zA-Z0-9 #+()]+$') |