Skip to content

Commit

Permalink
Blacked files
Browse files Browse the repository at this point in the history
  • Loading branch information
sgeulette committed Jun 4, 2024
1 parent 77626ef commit b84494d
Show file tree
Hide file tree
Showing 8 changed files with 325 additions and 284 deletions.
6 changes: 4 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ Changelog
1.0.4 (unreleased)
------------------

- Nothing changed yet.

- Blacked files.
[sgeulette]
- Added `system.post_request` to send a POST request.
[sgeulette]

1.0.3 (2024-05-24)
------------------
Expand Down
3 changes: 2 additions & 1 deletion imio/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
try:
__import__('pkg_resources').declare_namespace(__name__)
__import__("pkg_resources").declare_namespace(__name__)
except ImportError:
from pkgutil import extend_path

__path__ = extend_path(__path__, __name__)
4 changes: 2 additions & 2 deletions imio/pyutils/bs.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ def remove_comments(element):


def remove_elements(element, to_remove=[]):
"""Removes sub tags and all their content """
"""Removes sub tags and all their content"""
for tagtr in to_remove:
for tag in element.find_all(tagtr):
tag.decompose()


def replace_entire_strings(element, replace=u'\n', by=u''):
def replace_entire_strings(element, replace="\n", by=""):
"""Replaces an entire string by another value. With default params, removes newlines.
:param element: bs item
Expand Down
37 changes: 22 additions & 15 deletions imio/pyutils/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

# dsn="host=localhost port=5432 dbname= user= password="
def openConnection(dsn):
""" open a postgres connection """
"""open a postgres connection"""
conn = None
try:
conn = psycopg2.connect(dsn)
Expand All @@ -23,11 +23,12 @@ def openConnection(dsn):
raise Exception(msg)
return conn


# ------------------------------------------------------------------------------


def insertInTable(dsn, table, columns, vals, TRACE=False):
""" insert values in a table """
"""insert values in a table"""
conn = openConnection(dsn)
cursor = conn.cursor()
req = "insert into %s(%s) values(%s)" % (table, columns, vals)
Expand All @@ -45,16 +46,17 @@ def insertInTable(dsn, table, columns, vals, TRACE=False):
conn.close()
return True


# ------------------------------------------------------------------------------


def updateTable(dsn, table, updates, condition='', TRACE=False):
""" update columns in a table """
def updateTable(dsn, table, updates, condition="", TRACE=False):
"""update columns in a table"""
conn = openConnection(dsn)
cursor = conn.cursor()
req = "update %s set %s" % (table, updates)
if condition:
req += ' where %s' % condition
req += " where %s" % condition
trace(TRACE, "Update: %s" % req)
try:
cursor.execute(req)
Expand All @@ -69,11 +71,12 @@ def updateTable(dsn, table, updates, condition='', TRACE=False):
conn.close()
return True


# ------------------------------------------------------------------------------


def selectWithSQLRequest(dsn, sql, TRACE=False):
""" select multiple lines in a table with a complete sql """
"""select multiple lines in a table with a complete sql"""
conn = openConnection(dsn)
cursor = conn.cursor()
req = sql
Expand All @@ -90,16 +93,17 @@ def selectWithSQLRequest(dsn, sql, TRACE=False):
conn.close()
return data


# ------------------------------------------------------------------------------


def selectAllInTable(dsn, table, selection, condition='', TRACE=False):
""" select multiple lines in a table """
def selectAllInTable(dsn, table, selection, condition="", TRACE=False):
"""select multiple lines in a table"""
conn = openConnection(dsn)
cursor = conn.cursor()
req = "select %s from %s" % (selection, table)
if condition:
req += ' where %s' % condition
req += " where %s" % condition
trace(TRACE, "Selection: %s" % req)
try:
cursor.execute(req)
Expand All @@ -113,16 +117,17 @@ def selectAllInTable(dsn, table, selection, condition='', TRACE=False):
conn.close()
return data


# ------------------------------------------------------------------------------


def selectOneInTable(dsn, table, selection, condition='', TRACE=False):
""" select a single line in a table """
def selectOneInTable(dsn, table, selection, condition="", TRACE=False):
"""select a single line in a table"""
conn = openConnection(dsn)
cursor = conn.cursor()
req = "select %s from %s" % (selection, table)
if condition:
req += ' where %s' % condition
req += " where %s" % condition
trace(TRACE, "Selection: %s" % req)
try:
cursor.execute(req)
Expand All @@ -136,16 +141,17 @@ def selectOneInTable(dsn, table, selection, condition='', TRACE=False):
conn.close()
return data


# ------------------------------------------------------------------------------


def deleteTable(dsn, table, condition='', TRACE=False):
""" delete a table """
def deleteTable(dsn, table, condition="", TRACE=False):
"""delete a table"""
conn = openConnection(dsn)
cursor = conn.cursor()
req = "delete from %s" % table
if condition:
req += ' where %s' % condition
req += " where %s" % condition
trace(TRACE, "Deletion : %s" % req)
try:
cursor.execute(req)
Expand All @@ -160,4 +166,5 @@ def deleteTable(dsn, table, condition='', TRACE=False):
conn.close()
return True


# ------------------------------------------------------------------------------
Loading

0 comments on commit b84494d

Please sign in to comment.