Changeset 740 for trunk/pgdb.py


Ignore:
Timestamp:
Jan 13, 2016, 9:35:55 PM (4 years ago)
Author:
cito
Message:

Reformat some error messages and docstrings

Try to achieve a somewhat consistent style of docstrings and error
messages in the trunk. The docstrings use PEP 257, with a slight
variation between C code and Python code. The error messages are
capitalized and do not end with a period. (I prefer the periods,
but most Python code I have seen doesn't use them.)

(I know, a foolish consistency is the hobgoblin of little minds.)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/pgdb.py

    r711 r740  
    6262
    6363    connection.close() # close the connection
    64 
    6564"""
    6665
     
    166165
    167166def _db_error(msg, cls=DatabaseError):
    168     """Returns DatabaseError with empty sqlstate attribute."""
     167    """Return DatabaseError with empty sqlstate attribute."""
    169168    error = cls(msg)
    170169    error.sqlstate = None
     
    173172
    174173def _op_error(msg):
    175     """Returns OperationalError."""
     174    """Return OperationalError."""
    176175    return _db_error(msg, OperationalError)
    177176
     
    218217
    219218    The quote attribute must be set to the desired quote function.
    220 
    221219    """
    222220
     
    250248
    251249    def __iter__(self):
    252         """Make cursors compatible to the iteration protocol."""
     250        """Make cursor compatible to the iteration protocol."""
    253251        return self
    254252
     
    297295
    298296        This function works for both mappings and sequences.
    299 
    300297        """
    301298        if isinstance(parameters, dict):
     
    401398        determines the number of rows to be fetched. If you set
    402399        the keep parameter to true, this is kept as new arraysize.
    403 
    404400        """
    405401        if size is None:
     
    427423        The procedure may also provide a result set as output. These can be
    428424        requested through the standard fetch methods of the cursor.
    429 
    430425        """
    431426        n = parameters and len(parameters) or 0
     
    451446        The copy operation can be restricted to a subset of columns. If no
    452447        columns are specified, all of them will be copied.
    453 
    454448        """
    455449        binary_format = format == 'binary'
     
    468462            if isinstance(stream, basestring):
    469463                if not isinstance(stream, input_type):
    470                     raise ValueError("the input must be %s" % type_name)
     464                    raise ValueError("The input must be %s" % type_name)
    471465                if not binary_format:
    472466                    if isinstance(stream, str):
     
    486480                        if not isinstance(chunk, input_type):
    487481                            raise ValueError(
    488                                 "input stream must consist of %s" % type_name)
     482                                "Input stream must consist of %s" % type_name)
    489483                        if isinstance(chunk, str):
    490484                            if not chunk.endswith('\n'):
     
    496490
    497491            else:
    498                 raise TypeError("need an input stream to copy from")
     492                raise TypeError("Need an input stream to copy from")
    499493        else:
    500494            if size is None:
     
    502496            if size > 0:
    503497                if not isinstance(size, int):
    504                     raise TypeError("the size option must be an integer")
     498                    raise TypeError("The size option must be an integer")
    505499
    506500                def chunks():
     
    517511
    518512        if not table or not isinstance(table, basestring):
    519             raise TypeError("need a table to copy to")
     513            raise TypeError("Need a table to copy to")
    520514        if table.lower().startswith('select'):
    521                 raise ValueError("must specify a table, not a query")
     515                raise ValueError("Must specify a table, not a query")
    522516        else:
    523517            table = '"%s"' % (table,)
     
    527521        if format is not None:
    528522            if not isinstance(format, basestring):
    529                 raise TypeError("the format options be a string")
     523                raise TypeError("format option must be be a string")
    530524            if format not in ('text', 'csv', 'binary'):
    531525                raise ValueError("invalid format")
     
    533527        if sep is not None:
    534528            if not isinstance(sep, basestring):
    535                 raise TypeError("the sep option must be a string")
     529                raise TypeError("sep option must be a string")
    536530            if format == 'binary':
    537531                raise ValueError("sep is not allowed with binary format")
     
    542536        if null is not None:
    543537            if not isinstance(null, basestring):
    544                 raise TypeError("the null option must be a string")
     538                raise TypeError("null option must be a string")
    545539            options.append('null %s')
    546540            params.append(null)
     
    588582        The copy operation can be restricted to a subset of columns. If no
    589583        columns are specified, all of them will be copied.
    590 
    591584        """
    592585        binary_format = format == 'binary'
     
    609602        if format is not None:
    610603            if not isinstance(format, basestring):
    611                 raise TypeError("the format options be a string")
     604                raise TypeError("format option must be a string")
    612605            if format not in ('text', 'csv', 'binary'):
    613606                raise ValueError("invalid format")
     
    615608        if sep is not None:
    616609            if not isinstance(sep, basestring):
    617                 raise TypeError("the sep option must be a string")
     610                raise TypeError("sep option must be a string")
    618611            if binary_format:
    619612                raise ValueError("sep is not allowed with binary format")
     
    624617        if null is not None:
    625618            if not isinstance(null, basestring):
    626                 raise TypeError("the null option must be a string")
     619                raise TypeError("null option must be a string")
    627620            options.append('null %s')
    628621            params.append(null)
     
    634627        else:
    635628            if not isinstance(decode, (int, bool)):
    636                 raise TypeError("the decode option must be a boolean")
     629                raise TypeError("decode option must be a boolean")
    637630            if decode and binary_format:
    638631                raise ValueError("decode is not allowed with binary format")
     
    716709            cur = DictCursor(con)  # get one DictCursor instance or
    717710            con.cursor_type = DictCursor  # always use DictCursor instances
    718 
    719711        """
    720712        raise NotImplementedError
     
    726718        You can overwrite this method if you want to dynamically create
    727719        different row factories whenever the column description changes.
    728 
    729720        """
    730721        colnames = self.colnames
     
    779770
    780771        The runtime context can be used for running transactions.
    781 
    782772        """
    783773        return self
     
    787777
    788778        This does not close the connection, but it ends a transaction.
    789 
    790779        """
    791780        if et is None and ev is None and tb is None:
     
    867856        user=None, password=None,
    868857        host=None, database=None):
    869     """Connects to a database."""
     858    """Connect to a database."""
    870859    # first get params from DSN
    871860    dbport = -1
     
    918907    PostgreSQL is object-oriented: types are dynamic.
    919908    We must thus use type names as internal type codes.
    920 
    921909    """
    922910
     
    977965
    978966def Timestamp(year, month, day, hour=0, minute=0, second=0, microsecond=0):
    979     """construct an object holding a time stamp value."""
     967    """construct an object holding a time stamp valu."""
    980968    return datetime(year, month, day, hour, minute, second, microsecond)
    981969
Note: See TracChangeset for help on using the changeset viewer.