Skip to content

Commit

Permalink
black/isort everything
Browse files Browse the repository at this point in the history
  • Loading branch information
mdipierro committed May 7, 2023
1 parent 48a7adb commit ef60cc0
Show file tree
Hide file tree
Showing 32 changed files with 290 additions and 264 deletions.
16 changes: 9 additions & 7 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys, os, shutil
import os
import shutil
import sys

on_rtd = os.environ.get("READTHEDOCS", None) == "True"

Expand Down Expand Up @@ -56,8 +58,8 @@
master_doc = "index"

# General information about the project.
project = u"pyDAL"
copyright = u"2014, web2py-developers"
project = "pyDAL"
copyright = "2014, web2py-developers"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down Expand Up @@ -188,7 +190,7 @@
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
("index", "pydal.tex", u"pyDAL Documentation", u"web2py-developers", "manual"),
("index", "pydal.tex", "pyDAL Documentation", "web2py-developers", "manual"),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -216,7 +218,7 @@

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [("index", "pyDAL", u"pyDAL Documentation", [u"web2py-developers"], 1)]
man_pages = [("index", "pyDAL", "pyDAL Documentation", ["web2py-developers"], 1)]

# If true, show URL addresses after external links.
# man_show_urls = False
Expand All @@ -231,8 +233,8 @@
(
"index",
"pyDAL",
u"pyDAL Documentation",
u"web2py-developers",
"pyDAL Documentation",
"web2py-developers",
"pyDAL",
"pyDAL",
"Miscellaneous",
Expand Down
1 change: 0 additions & 1 deletion pydal/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ def to_native(obj, charset="utf8", errors="strict"):
return obj
return obj.encode(charset, errors)


else:
import _thread as thread
import builtins as builtin
Expand Down
2 changes: 1 addition & 1 deletion pydal/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def close(self, action="commit", really=True):

@staticmethod
def close_all_instances(action):
""" to close cleanly databases in a multithreaded environment """
"""to close cleanly databases in a multithreaded environment"""
dbs = getattr(THREAD_LOCAL, "_pydal_db_instances_", {}).items()
for db_uid, db_group in dbs:
for db in db_group:
Expand Down
4 changes: 2 additions & 2 deletions pydal/contrib/imap_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ def header_represent(f, r):
return text

def encode_text(self, text, charset, errors="replace"):
""" convert text for mail to unicode"""
"""convert text for mail to unicode"""
if text is None:
text = ""
if PY2:
Expand All @@ -429,7 +429,7 @@ def get_charset(self, message):
return charset

def get_mailboxes(self):
""" Query the mail database for mailbox names """
"""Query the mail database for mailbox names"""
if self.static_names:
# statically defined mailbox names
self.connection.mailbox_names = self.static_names
Expand Down
10 changes: 4 additions & 6 deletions pydal/contrib/ipaddress.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
def _compat_bytes_to_byte_vals(byt):
return byt


else:

def _compat_bytes_to_byte_vals(byt):
Expand All @@ -55,11 +54,11 @@ def _compat_to_bytes(intval, length, endianess):
assert isinstance(intval, _compat_int_types)
assert endianess == "big"
if length == 4:
if intval < 0 or intval >= 2 ** 32:
if intval < 0 or intval >= 2**32:
raise struct.error("integer out of range for 'I' format code")
return struct.pack(b"!I", intval)
elif length == 16:
if intval < 0 or intval >= 2 ** 128:
if intval < 0 or intval >= 2**128:
raise struct.error("integer out of range for 'QQ' format code")
return struct.pack(b"!QQ", intval >> 64, intval & 0xFFFFFFFFFFFFFFFF)
else:
Expand All @@ -71,7 +70,6 @@ def _compat_to_bytes(intval, length, endianess):
def _compat_bit_length(i):
return i.bit_length()


else:

def _compat_bit_length(i):
Expand Down Expand Up @@ -1225,7 +1223,7 @@ class _BaseV4(object):
__slots__ = ()
_version = 4
# Equivalent to 255.255.255.255 or 32 bits of 1's.
_ALL_ONES = (2 ** IPV4LENGTH) - 1
_ALL_ONES = (2**IPV4LENGTH) - 1
_DECIMAL_DIGITS = frozenset("0123456789")

# the valid octets for host and netmasks. only useful for IPv4.
Expand Down Expand Up @@ -1740,7 +1738,7 @@ class _BaseV6(object):

__slots__ = ()
_version = 6
_ALL_ONES = (2 ** IPV6LENGTH) - 1
_ALL_ONES = (2**IPV6LENGTH) - 1
_HEXTET_COUNT = 8
_HEX_DIGITS = frozenset("0123456789ABCDEFabcdef")
_max_prefixlen = IPV6LENGTH
Expand Down
2 changes: 0 additions & 2 deletions pydal/contrib/portalocker.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ def unlock(file):
overlapped = OVERLAPPED()
UnlockFileEx(hfile, 0, 0, 0xFFFF0000, ctypes.byref(overlapped))


elif os_locking == "posix":
LOCK_EX = fcntl.LOCK_EX
LOCK_SH = fcntl.LOCK_SH
Expand All @@ -150,7 +149,6 @@ def lock(file, flags):
def unlock(file):
fcntl.flock(file.fileno(), fcntl.LOCK_UN)


else:
if os_locking != "gae":
logger.debug("no file locking, this will cause problems")
Expand Down
6 changes: 3 additions & 3 deletions pydal/default_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ def default_validators(db, field):
elif field_type == "double" or field_type == "float":
requires.append(validators.IS_FLOAT_IN_RANGE(-1e100, 1e100))
elif field_type == "integer":
requires.append(validators.IS_INT_IN_RANGE(-(2 ** 31), 2 ** 31))
requires.append(validators.IS_INT_IN_RANGE(-(2**31), 2**31))
elif field_type == "bigint":
requires.append(validators.IS_INT_IN_RANGE(-(2 ** 63), 2 ** 63))
requires.append(validators.IS_INT_IN_RANGE(-(2**63), 2**63))
elif field_type.startswith("decimal"):
requires.append(validators.IS_DECIMAL_IN_RANGE(-(10 ** 10), 10 ** 10))
requires.append(validators.IS_DECIMAL_IN_RANGE(-(10**10), 10**10))
elif field_type == "date":
requires.append(validators.IS_DATE())
elif field_type == "time":
Expand Down
18 changes: 7 additions & 11 deletions pydal/dialects/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,17 +501,13 @@ def gte(self, first, second=None, query_env={}):
)

def _is_numerical(self, field_type):
return (
field_type
in (
"integer",
"float",
"double",
"bigint",
"boolean",
)
or field_type.startswith("decimal")
)
return field_type in (
"integer",
"float",
"double",
"bigint",
"boolean",
) or field_type.startswith("decimal")

def add(self, first, second, query_env={}):
if self._is_numerical(first.type) or isinstance(first.type, Field):
Expand Down
4 changes: 3 additions & 1 deletion pydal/dialects/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,9 @@ def lower(self, first, query_env={}):
def upper(self, first, query_env={}):
return {"$toUpper": self.expand(first, query_env=query_env)}

def regexp(self, first, second, match_parameter=None, case_sensitive=True, query_env={}):
def regexp(
self, first, second, match_parameter=None, case_sensitive=True, query_env={}
):
"""MongoDB provides regular expression capabilities for pattern
matching strings in queries. MongoDB uses Perl compatible
regular expressions (i.e. 'PCRE') version 8.36 with UTF-8 support.
Expand Down
6 changes: 4 additions & 2 deletions pydal/dialects/oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,16 @@ def eq(self, first, second=None, query_env={}):

def regexp(self, first, second, match_parameter, query_env={}):
if match_parameter:
_match_parameter = ","+self.expand(match_parameter, "string", query_env=query_env)
_match_parameter = "," + self.expand(
match_parameter, "string", query_env=query_env
)
else:
_match_parameter = ""

return "REGEXP_LIKE(%s, %s %s)" % (
self.expand(first, query_env=query_env),
self.expand(second, "string", query_env=query_env),
_match_parameter
_match_parameter,
)

def insert(self, table, fields, values):
Expand Down
8 changes: 4 additions & 4 deletions pydal/dialects/postgre.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,15 @@ def st_asgeojson(self, first, second, query_env={}):
)

def json_key(self, first, key, query_env=None):
""" Get the json in key which you can use for more queries """
"""Get the json in key which you can use for more queries"""
if isinstance(key, basestring):
key = self.expand(key, "string", query_env=query_env)
elif not isinstance(key, integer_types):
raise TypeError("Key must be a string or int")
return "%s->%s" % (self.expand(first, query_env=query_env or {}), key)

def json_key_value(self, first, key, query_env=None):
""" Get the value int or text in key """
"""Get the value int or text in key"""
if isinstance(key, basestring):
key = self.expand(key, "string", query_env=query_env)
elif isinstance(key, integer_types):
Expand All @@ -321,11 +321,11 @@ def json_key_value(self, first, key, query_env=None):
return "%s->>%s" % (self.expand(first, query_env=query_env or {}), key)

def json_path(self, first, path, query_env=None):
""" Get the json in path which you can use for more queries """
"""Get the json in path which you can use for more queries"""
return "%s#>'%s'" % (self.expand(first, query_env=query_env or {}), path)

def json_path_value(self, first, path, query_env=None):
""" Get the json in path which you can use for more queries """
"""Get the json in path which you can use for more queries"""
return "%s#>>'%s'" % (self.expand(first, query_env=query_env or {}), path)

# JSON Queries
Expand Down
7 changes: 3 additions & 4 deletions pydal/dialects/snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ def select(
else:
whr2 = self.where("w_row > %i" % lmin)


return "SELECT%s%s%s %s FROM %s%s%s%s;" % (
dst,
limit,
Expand Down Expand Up @@ -232,10 +231,10 @@ def st_asgeojson(self, first, second, query_env={}):
second["precision"],
second["options"],
)

def unquote(self, val):
if (val[0] == '"' and val[-1] == '"'):
val=val.replace('"','')
if val[0] == '"' and val[-1] == '"':
val = val.replace('"', "")
return val

def st_astext(self, first, query_env={}):
Expand Down
14 changes: 10 additions & 4 deletions pydal/helpers/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,11 @@ def try_create_web2py_filesystem(db):
raise NotImplementedError(
"DatabaseStoredFile only supported by mysql, potresql, sqlite"
)
blobType = "BYTEA" if db._adapter.dbengine == "postgres" else "BLOB"
sql = "CREATE TABLE IF NOT EXISTS web2py_filesystem (path VARCHAR(255), content %(blobType)s, PRIMARY KEY(path));" % {"blobType": blobType}
blobType = "BYTEA" if db._adapter.dbengine == "postgres" else "BLOB"
sql = (
"CREATE TABLE IF NOT EXISTS web2py_filesystem (path VARCHAR(255), content %(blobType)s, PRIMARY KEY(path));"
% {"blobType": blobType}
)
if db._adapter.dbengine == "mysql":
sql = sql[:-1] + " ENGINE=InnoDB;"
db.executesql(sql)
Expand Down Expand Up @@ -547,8 +550,11 @@ def close_connection(self):
self.db.executesql(
"DELETE FROM web2py_filesystem WHERE path='%s'" % self.filename
)
placeholder = "?" if self.db._adapter.dbengine == "sqlite" else "%s"
query = "INSERT INTO web2py_filesystem(path,content) VALUES (%(placeholder)s, %(placeholder)s)" % {"placeholder": placeholder}
placeholder = "?" if self.db._adapter.dbengine == "sqlite" else "%s"
query = (
"INSERT INTO web2py_filesystem(path,content) VALUES (%(placeholder)s, %(placeholder)s)"
% {"placeholder": placeholder}
)
args = (self.filename, self.data)
self.db.executesql(query, args)
self.db.commit()
Expand Down
11 changes: 8 additions & 3 deletions pydal/migrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,8 @@ def create_table(self, table, migrate=True, fake_migrate=False, polymodel=None):
uri = self.adapter.uri
if isinstance(self, InDBMigrator):
# No filesystem path should be used when storing table details in database.
dbpath = ''
self.adapter.folder = ''
dbpath = ""
self.adapter.folder = ""
elif uri.startswith("sqlite:///") or uri.startswith("spatialite:///"):
if PY2:
path_encoding = (
Expand Down Expand Up @@ -586,7 +586,12 @@ def log(self, message, table=None):
writelog = bool(logfilename)
if writelog:
isabs = os.path.isabs(logfilename)
if table and table._dbt and writelog and (self.adapter.folder or isinstance(self, InDBMigrator)):
if (
table
and table._dbt
and writelog
and (self.adapter.folder or isinstance(self, InDBMigrator))
):
if isabs:
table._loggername = logfilename
else:
Expand Down
Loading

0 comments on commit ef60cc0

Please sign in to comment.