From 65c62a46c7aafcf7e379cdb5cf09e66089da15cc Mon Sep 17 00:00:00 2001 From: Matt Seymour Date: Tue, 11 Jan 2022 12:07:53 +0000 Subject: [PATCH 1/5] Update and reformat license Update the License formatting to match that of other jazzband projects. --- LICENSE | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/LICENSE b/LICENSE index 7d98256..1dde6c6 100644 --- a/LICENSE +++ b/LICENSE @@ -1,8 +1,27 @@ Copyright (c) Kenneth Reitz & individual contributors All rights reserved. -Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: -Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. -Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + 3. Neither the name of Django nor the names of its contributors may be used + to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file From 90d36f0fce39e3f13d51f7704a03d91469973243 Mon Sep 17 00:00:00 2001 From: Matt Seymour Date: Tue, 11 Jan 2022 12:14:14 +0000 Subject: [PATCH 2/5] Add default contributing.md file Jazzband projects need to include a CONTRIBUTING.md file. This is the minimum contribution file required. This should be expanded in the future. --- CONTRIBUTING.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..829a22a --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,7 @@ +[![Jazzband](https://jazzband.co/static/img/jazzband.svg)](https://jazzband.co/) + +This is a [Jazzband](https://jazzband.co/) project. By contributing you agree to abide by the [Contributor Code of Conduct](https://jazzband.co/about/conduct) and follow the [guidelines](https://jazzband.co/about/guidelines). + +Please see the +[full contributing documentation](https://django-debug-toolbar.readthedocs.io/en/stable/contributing.html) +for more help. From 572877e22ab91a5f343cae5b804944343c603a26 Mon Sep 17 00:00:00 2001 From: Matt Seymour Date: Tue, 11 Jan 2022 12:16:50 +0000 Subject: [PATCH 3/5] Add jazzband code of conduct file Add the default code of conduct as found in jazzband projects. --- CODE_OF_CONDUCT.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 CODE_OF_CONDUCT.md diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..e0d5efa --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,46 @@ +# Code of Conduct + +As contributors and maintainers of the Jazzband projects, and in the interest of +fostering an open and welcoming community, we pledge to respect all people who +contribute through reporting issues, posting feature requests, updating documentation, +submitting pull requests or patches, and other activities. + +We are committed to making participation in the Jazzband a harassment-free experience +for everyone, regardless of the level of experience, gender, gender identity and +expression, sexual orientation, disability, personal appearance, body size, race, +ethnicity, age, religion, or nationality. + +Examples of unacceptable behavior by participants include: + +- The use of sexualized language or imagery +- Personal attacks +- Trolling or insulting/derogatory comments +- Public or private harassment +- Publishing other's private information, such as physical or electronic addresses, + without explicit permission +- Other unethical or unprofessional conduct + +The Jazzband roadies have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are not +aligned to this Code of Conduct, or to ban temporarily or permanently any contributor +for other behaviors that they deem inappropriate, threatening, offensive, or harmful. + +By adopting this Code of Conduct, the roadies commit themselves to fairly and +consistently applying these principles to every aspect of managing the jazzband +projects. Roadies who do not follow or enforce the Code of Conduct may be permanently +removed from the Jazzband roadies. + +This code of conduct applies both within project spaces and in public spaces when an +individual is representing the project or its community. + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by +contacting the roadies at `roadies@jazzband.co`. All complaints will be reviewed and +investigated and will result in a response that is deemed necessary and appropriate to +the circumstances. Roadies are obligated to maintain confidentiality with regard to the +reporter of an incident. + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version +1.3.0, available at [https://contributor-covenant.org/version/1/3/0/][version] + +[homepage]: https://contributor-covenant.org +[version]: https://contributor-covenant.org/version/1/3/0/ From a42c0ba71e258437dfe43be7522a5c716235209e Mon Sep 17 00:00:00 2001 From: Matt Seymour Date: Tue, 11 Jan 2022 12:39:25 +0000 Subject: [PATCH 4/5] Update README.rst with contributing guidelines --- README.rst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.rst b/README.rst index a9cf2aa..c3075a3 100644 --- a/README.rst +++ b/README.rst @@ -90,3 +90,26 @@ URL schema from using other Oracle tools (like SQLPlus) i.e. user and password are separated by ``:`` not by ``/``. Also you can omit ``HOST`` and ``PORT`` and provide a full DSN string or TNS name in ``NAME`` part. + +Contributing +------------ + +We welcome contributions to this project. Projects can take two forms: + +1. Raising issues or helping others through the github issue tracker. +2. Contributing code. + +Raising Issues or helping others: +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +When submitting an issue or helping other remember you are talking to humans who have feelings, jobs and lives of their +own. Be nice, be kind, be polite. Remember english may not be someone first language, if you do not understand or +something is not clear be polite and re-ask/ re-word. + +Contributing code: +^^^^^^^^^^^^^^^^^^ + +* Before writing code be sure to check existing PR's and issues in the tracker. +* Write code to the pylint spec. +* Large or wide sweeping changes will take longer, and may face more scrutiny than smaller confined changes. +* Code should be pass `black` and `flake8` validation. From 973b0bcf35e87cb603debea2f23ee6e57b1add02 Mon Sep 17 00:00:00 2001 From: Matt Seymour Date: Tue, 11 Jan 2022 12:56:27 +0000 Subject: [PATCH 5/5] Add flake8 and black config, re-format * Adds a basic black and flake8 compatible config * Reformat the code with black using skip string normalization --- .flake8 | 5 +++++ dj_database_url.py | 34 +++++++++++++++++++--------------- pyproject.toml | 2 ++ test_dj_database_url.py | 37 +++++++++++++++++++++++-------------- 4 files changed, 49 insertions(+), 29 deletions(-) create mode 100644 .flake8 create mode 100644 pyproject.toml diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..8cf868e --- /dev/null +++ b/.flake8 @@ -0,0 +1,5 @@ +[flake8] +max-line-length = 88 +extend-ignore = E203 +per-file-ignores= + test_dj_database_url.py: E501, E265 \ No newline at end of file diff --git a/dj_database_url.py b/dj_database_url.py index 2c3626c..cc3e287 100644 --- a/dj_database_url.py +++ b/dj_database_url.py @@ -56,7 +56,9 @@ else: SCHEMES['pgsql'] = 'django.db.backends.postgresql' -def config(env=DEFAULT_ENV, default=None, engine=None, conn_max_age=0, ssl_require=False): +def config( + env=DEFAULT_ENV, default=None, engine=None, conn_max_age=0, ssl_require=False +): """Returns configured DATABASE dictionary from DATABASE_URL.""" config = {} @@ -76,10 +78,7 @@ def parse(url, engine=None, conn_max_age=0, ssl_require=False): # this is a special case, because if we pass this URL into # urlparse, urlparse will choke trying to interpret "memory" # as a port number - return { - 'ENGINE': SCHEMES['sqlite'], - 'NAME': ':memory:' - } + return {'ENGINE': SCHEMES['sqlite'], 'NAME': ':memory:'} # note: no other settings are required for sqlite # otherwise parse the url as normal @@ -114,18 +113,23 @@ def parse(url, engine=None, conn_max_age=0, ssl_require=False): # Lookup specified engine. engine = SCHEMES[url.scheme] if engine is None else engine - port = (str(url.port) if url.port and engine in [SCHEMES['oracle'], SCHEMES['mssql']] - else url.port) + port = ( + str(url.port) + if url.port and engine in [SCHEMES['oracle'], SCHEMES['mssql']] + else url.port + ) # Update with environment configuration. - config.update({ - 'NAME': urlparse.unquote(path or ''), - 'USER': urlparse.unquote(url.username or ''), - 'PASSWORD': urlparse.unquote(url.password or ''), - 'HOST': hostname, - 'PORT': port or '', - 'CONN_MAX_AGE': conn_max_age, - }) + config.update( + { + 'NAME': urlparse.unquote(path or ''), + 'USER': urlparse.unquote(url.username or ''), + 'PASSWORD': urlparse.unquote(url.password or ''), + 'HOST': hostname, + 'PORT': port or '', + 'CONN_MAX_AGE': conn_max_age, + } + ) # Pass the query string into OPTIONS. options = {} diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..466435c --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,2 @@ +[tool.black] +skip-string-normalization = 1 \ No newline at end of file diff --git a/test_dj_database_url.py b/test_dj_database_url.py index b869019..1992d55 100644 --- a/test_dj_database_url.py +++ b/test_dj_database_url.py @@ -19,7 +19,6 @@ if DJANGO_VERSION < (2, 0): class DatabaseTestSuite(unittest.TestCase): - def test_postgres_parsing(self): url = 'postgres://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn' url = dj_database_url.parse(url) @@ -146,7 +145,9 @@ class DatabaseTestSuite(unittest.TestCase): a = dj_database_url.config() assert not a - os.environ['DATABASE_URL'] = 'postgres://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn' + os.environ[ + 'DATABASE_URL' + ] = 'postgres://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn' url = dj_database_url.config() @@ -180,7 +181,9 @@ class DatabaseTestSuite(unittest.TestCase): def test_config_engine_setting(self): engine = 'django_mysqlpool.backends.mysqlpool' - os.environ['DATABASE_URL'] = 'mysql://bea6eb025ca0d8:69772142@us-cdbr-east.cleardb.com/heroku_97681db3eff7580?reconnect=true' + os.environ[ + 'DATABASE_URL' + ] = 'mysql://bea6eb025ca0d8:69772142@us-cdbr-east.cleardb.com/heroku_97681db3eff7580?reconnect=true' url = dj_database_url.config(engine=engine) assert url['ENGINE'] == engine @@ -194,14 +197,18 @@ class DatabaseTestSuite(unittest.TestCase): def test_config_conn_max_age_setting(self): conn_max_age = 600 - os.environ['DATABASE_URL'] = 'mysql://bea6eb025ca0d8:69772142@us-cdbr-east.cleardb.com/heroku_97681db3eff7580?reconnect=true' + os.environ[ + 'DATABASE_URL' + ] = 'mysql://bea6eb025ca0d8:69772142@us-cdbr-east.cleardb.com/heroku_97681db3eff7580?reconnect=true' url = dj_database_url.config(conn_max_age=conn_max_age) assert url['CONN_MAX_AGE'] == conn_max_age def test_database_url_with_options(self): # Test full options - os.environ['DATABASE_URL'] = 'postgres://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn?sslrootcert=rds-combined-ca-bundle.pem&sslmode=verify-full' + os.environ[ + 'DATABASE_URL' + ] = 'postgres://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn?sslrootcert=rds-combined-ca-bundle.pem&sslmode=verify-full' url = dj_database_url.config() assert url['ENGINE'] == EXPECTED_POSTGRES_ENGINE @@ -212,16 +219,20 @@ class DatabaseTestSuite(unittest.TestCase): assert url['PORT'] == 5431 assert url['OPTIONS'] == { 'sslrootcert': 'rds-combined-ca-bundle.pem', - 'sslmode': 'verify-full' + 'sslmode': 'verify-full', } # Test empty options - os.environ['DATABASE_URL'] = 'postgres://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn?' + os.environ[ + 'DATABASE_URL' + ] = 'postgres://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn?' url = dj_database_url.config() assert 'OPTIONS' not in url def test_mysql_database_url_with_sslca_options(self): - os.environ['DATABASE_URL'] = 'mysql://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:3306/d8r82722r2kuvn?ssl-ca=rds-combined-ca-bundle.pem' + os.environ[ + 'DATABASE_URL' + ] = 'mysql://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:3306/d8r82722r2kuvn?ssl-ca=rds-combined-ca-bundle.pem' url = dj_database_url.config() assert url['ENGINE'] == 'django.db.backends.mysql' @@ -230,14 +241,12 @@ class DatabaseTestSuite(unittest.TestCase): assert url['USER'] == 'uf07k1i6d8ia0v' assert url['PASSWORD'] == 'wegauwhgeuioweg' assert url['PORT'] == 3306 - assert url['OPTIONS'] == { - 'ssl': { - 'ca': 'rds-combined-ca-bundle.pem' - } - } + assert url['OPTIONS'] == {'ssl': {'ca': 'rds-combined-ca-bundle.pem'}} # Test empty options - os.environ['DATABASE_URL'] = 'mysql://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:3306/d8r82722r2kuvn?' + os.environ[ + 'DATABASE_URL' + ] = 'mysql://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:3306/d8r82722r2kuvn?' url = dj_database_url.config() assert 'OPTIONS' not in url