Mercurial > p > roundup > code
comparison roundup/backends/back_postgresql.py @ 5248:198b6e810c67
Use Python-3-compatible 'as' syntax for except statements
Many raise statements near these are also fixed.
So are two ivorrect file encoding marks ('utf8'->'utf-8').
| author | Eric S. Raymond <esr@thyrsus.com> |
|---|---|
| date | Thu, 24 Aug 2017 22:21:37 -0400 |
| parents | 57452bc6d989 |
| children | 62de601bdf6f |
comparison
equal
deleted
inserted
replaced
| 5247:7f00a47b3559 | 5248:198b6e810c67 |
|---|---|
| 72 template1 = connection_dict(config) | 72 template1 = connection_dict(config) |
| 73 template1['database'] = database | 73 template1['database'] = database |
| 74 | 74 |
| 75 try: | 75 try: |
| 76 conn = psycopg.connect(**template1) | 76 conn = psycopg.connect(**template1) |
| 77 except psycopg.OperationalError, message: | 77 except psycopg.OperationalError as message: |
| 78 if str(message).find('database "postgres" does not exist') >= 0: | 78 if str(message).find('database "postgres" does not exist') >= 0: |
| 79 return db_command(config, command, database='template1') | 79 return db_command(config, command, database='template1') |
| 80 raise hyperdb.DatabaseError(message) | 80 raise hyperdb.DatabaseError(message) |
| 81 | 81 |
| 82 conn.set_isolation_level(0) | 82 conn.set_isolation_level(0) |
| 95 | 95 |
| 96 If there is a concurrent update, retry the command. | 96 If there is a concurrent update, retry the command. |
| 97 ''' | 97 ''' |
| 98 try: | 98 try: |
| 99 cursor.execute(command) | 99 cursor.execute(command) |
| 100 except psycopg.DatabaseError, err: | 100 except psycopg.DatabaseError as err: |
| 101 response = str(err).split('\n')[0] | 101 response = str(err).split('\n')[0] |
| 102 if "FATAL" not in response : | 102 if "FATAL" not in response : |
| 103 msgs = ( | 103 msgs = ( |
| 104 'is being accessed by other users', | 104 'is being accessed by other users', |
| 105 'could not serialize access due to concurrent update', | 105 'could not serialize access due to concurrent update', |
| 123 | 123 |
| 124 class Sessions(sessions_rdbms.Sessions): | 124 class Sessions(sessions_rdbms.Sessions): |
| 125 def set(self, *args, **kwargs): | 125 def set(self, *args, **kwargs): |
| 126 try: | 126 try: |
| 127 sessions_rdbms.Sessions.set(self, *args, **kwargs) | 127 sessions_rdbms.Sessions.set(self, *args, **kwargs) |
| 128 except ProgrammingError, err: | 128 except ProgrammingError as err: |
| 129 response = str(err).split('\n')[0] | 129 response = str(err).split('\n')[0] |
| 130 if -1 != response.find('ERROR') and \ | 130 if -1 != response.find('ERROR') and \ |
| 131 -1 != response.find('could not serialize access due to concurrent update'): | 131 -1 != response.find('could not serialize access due to concurrent update'): |
| 132 # another client just updated, and we're running on | 132 # another client just updated, and we're running on |
| 133 # serializable isolation. | 133 # serializable isolation. |
| 158 db = connection_dict(self.config, 'database') | 158 db = connection_dict(self.config, 'database') |
| 159 logging.getLogger('roundup.hyperdb').info( | 159 logging.getLogger('roundup.hyperdb').info( |
| 160 'open database %r'%db['database']) | 160 'open database %r'%db['database']) |
| 161 try: | 161 try: |
| 162 conn = psycopg.connect(**db) | 162 conn = psycopg.connect(**db) |
| 163 except psycopg.OperationalError, message: | 163 except psycopg.OperationalError as message: |
| 164 raise hyperdb.DatabaseError(message) | 164 raise hyperdb.DatabaseError(message) |
| 165 | 165 |
| 166 cursor = conn.cursor() | 166 cursor = conn.cursor() |
| 167 if ISOLATION_LEVEL_REPEATABLE_READ is not None: | 167 if ISOLATION_LEVEL_REPEATABLE_READ is not None: |
| 168 lvl = isolation_levels [self.config.RDBMS_ISOLATION_LEVEL] | 168 lvl = isolation_levels [self.config.RDBMS_ISOLATION_LEVEL] |
| 176 | 176 |
| 177 self.conn, self.cursor = self.sql_open_connection() | 177 self.conn, self.cursor = self.sql_open_connection() |
| 178 | 178 |
| 179 try: | 179 try: |
| 180 self.load_dbschema() | 180 self.load_dbschema() |
| 181 except ProgrammingError, message: | 181 except ProgrammingError as message: |
| 182 if str(message).find('schema') == -1: | 182 if str(message).find('schema') == -1: |
| 183 raise | 183 raise |
| 184 self.rollback() | 184 self.rollback() |
| 185 self.init_dbschema() | 185 self.init_dbschema() |
| 186 self.sql("CREATE TABLE schema (schema TEXT)") | 186 self.sql("CREATE TABLE schema (schema TEXT)") |
| 249 ''' | 249 ''' |
| 250 logging.getLogger('roundup.hyperdb').info('commit') | 250 logging.getLogger('roundup.hyperdb').info('commit') |
| 251 | 251 |
| 252 try: | 252 try: |
| 253 self.conn.commit() | 253 self.conn.commit() |
| 254 except ProgrammingError, message: | 254 except ProgrammingError as message: |
| 255 # we've been instructed that this commit is allowed to fail | 255 # we've been instructed that this commit is allowed to fail |
| 256 if fail_ok and str(message).endswith('could not serialize ' | 256 if fail_ok and str(message).endswith('could not serialize ' |
| 257 'access due to concurrent update'): | 257 'access due to concurrent update'): |
| 258 logging.getLogger('roundup.hyperdb').info( | 258 logging.getLogger('roundup.hyperdb').info( |
| 259 'commit FAILED, but fail_ok') | 259 'commit FAILED, but fail_ok') |
