Skip to content

Commit bbf96c3

Browse files
committed
Pep8
1 parent d31b394 commit bbf96c3

File tree

11 files changed

+70
-59
lines changed

11 files changed

+70
-59
lines changed

python/multicorn/__init__.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,8 @@ def list_any_or_all(self):
6363
def __repr__(self):
6464
if self.is_list_operator:
6565
value = '%s(%s)' % (
66-
'ANY' if self.list_any_or_all == ANY
67-
else 'ALL',
68-
self.value)
66+
'ANY' if self.list_any_or_all == ANY else 'ALL',
67+
self.value)
6968
operator = self.operator[0]
7069
else:
7170
value = self.value
@@ -135,9 +134,11 @@ def execute(self, quals, columns):
135134

136135
@property
137136
def rowid_column(self):
138-
"""Returns a column name which will act as a rowid column, for delete/update
139-
operations. This can be either an existing column name, or a made-up one.
140-
This column name should be subsequently present in every returned resultset.
137+
"""Returns a column name which will act as a rowid column,
138+
for delete/update operations. This can be either an existing column
139+
name, or a made-up one.
140+
This column name should be subsequently present in every
141+
returned resultset.
141142
"""
142143
raise NotImplementedError("This FDW does not support the writable API")
143144

@@ -181,7 +182,8 @@ def sub_commit(self, level):
181182
class TransactionAwareForeignDataWrapper(ForeignDataWrapper):
182183

183184
def __init__(self, fdw_options, fdw_columns):
184-
super(TransactionAwareForeignDataWrapper, self).__init__(fdw_options, fdw_columns)
185+
super(TransactionAwareForeignDataWrapper, self).__init__(
186+
fdw_options, fdw_columns)
185187
self._init_transaction_state()
186188

187189
def _init_transaction_state(self):
@@ -191,7 +193,8 @@ def insert(self, values):
191193
self.current_transaction_state.append(('insert', values))
192194

193195
def update(self, oldvalues, newvalues):
194-
self.current_transaction_state.append(('update', (oldvalues, newvalues)))
196+
self.current_transaction_state.append(
197+
('update', (oldvalues, newvalues)))
195198

196199
def delete(self, oldvalues):
197200
self.current_transaction_state.append(('delete', oldvalues))
@@ -216,7 +219,7 @@ def _resolve_name(name, package, level):
216219
dot = package.rindex('.', 0, dot)
217220
except ValueError:
218221
raise ValueError("attempted relative import beyond top-level "
219-
"package")
222+
"package")
220223
return "%s.%s" % (package[:dot], name)
221224

222225

python/multicorn/compat.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,3 @@
1010
except NameError:
1111
# Python3
1212
basestring_ = str
13-

python/multicorn/fsfdw/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ def __init__(self, options, columns):
3636
self.content_column = options.get('content_column', None)
3737
self.filename_column = options.get('filename_column', None)
3838
self.file_mode = int(options.get('file_mode', '700'), 8)
39-
self.structured_directory = StructuredDirectory(root_dir, pattern,
40-
file_mode=self.file_mode)
39+
self.structured_directory = StructuredDirectory(
40+
root_dir, pattern,
41+
file_mode=self.file_mode)
4142
self.folder_columns = [key[0] for key in
4243
self.structured_directory._path_parts_properties
4344
if key]

python/multicorn/fsfdw/structuredfs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def open(self, shared_lock=True, fail_if=None):
222222
# Do nothing if we already have a file descriptor
223223
else:
224224
if (self._fd is None or
225-
not (fcntl.fcntl(self._fd, fcntl.F_GETFL) & os.O_RDWR)):
225+
not (fcntl.fcntl(self._fd, fcntl.F_GETFL) & os.O_RDWR)):
226226
# Open it with an exclusive lock, sync mode, and fail if the
227227
# file already exists.
228228
dirname = os.path.dirname(self.full_filename)

python/multicorn/gcfdw.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
from multicorn import ForeignDataWrapper
22
import gc
33
import sys
4-
import random
5-
from multicorn.compat import unicode_, basestring_
4+
from multicorn.compat import unicode_
65

76

87
class MyClass(object):
@@ -11,6 +10,7 @@ def __init__(self, num, rand):
1110
self.num = num
1211
self.rand = rand
1312

13+
1414
class GCForeignDataWrapper(ForeignDataWrapper):
1515

1616
def execute(self, quals, columns):
@@ -31,11 +31,12 @@ def execute(self, quals, columns):
3131
except (UnicodeEncodeError, UnicodeDecodeError):
3232
obj = unicode_("<NA>")
3333
result.append({'object': obj,
34-
'type': unicode_(tobj),
35-
'id': unicode_(id(obj)),
36-
'refcount': unicode_(sys.getrefcount(obj))})
34+
'type': unicode_(tobj),
35+
'id': unicode_(id(obj)),
36+
'refcount': unicode_(sys.getrefcount(obj))})
3737
return result
3838

39+
3940
class MemStressFDW(ForeignDataWrapper):
4041

4142
def __init__(self, options, columns):
@@ -48,5 +49,5 @@ def execute(self, quals, columns):
4849
for i in range(self.nb):
4950
num = i / 100.
5051
yield {'value': str(MyClass(i, num)),
51-
'i': i,
52-
'num': num}
52+
'i': i,
53+
'num': num}

python/multicorn/gitfdw.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def execute(self, quals, columns):
2727
def enc(unicode_str):
2828
"""Encode the string in the self given encoding."""
2929
return unicode_str.encode(self.encoding)
30-
for log in brigit.Git(self.path).pretty_log():
30+
for log in brigit.Git(self.path).pretty_log():
3131
yield {
3232
'author_name': enc(log["author"]['name']),
3333
'author_email': enc(log["author"]['email']),

python/multicorn/imapfdw.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919

2020

2121
STANDARD_FLAGS = {
22-
'seen': 'Seen',
23-
'flagged': 'Flagged',
24-
'delete': 'Deleted',
25-
'draft': 'Draft',
26-
'recent': 'Recent'
22+
'seen': 'Seen',
23+
'flagged': 'Flagged',
24+
'delete': 'Deleted',
25+
'draft': 'Draft',
26+
'recent': 'Recent'
2727
}
2828

2929
SEARCH_HEADERS = ['BCC', 'CC', 'FROM', 'TO']
@@ -73,7 +73,7 @@ def __init__(self, options, columns):
7373
self.host = options.get('host', None)
7474
if self.host is None:
7575
log_to_postgres('You MUST set the imap host',
76-
ERROR)
76+
ERROR)
7777
self.port = options.get('port', None)
7878
self.ssl = options.get('ssl', False)
7979
self.login = options.get('login', None)
@@ -87,7 +87,8 @@ def __init__(self, options, columns):
8787

8888
def get_rel_size(self, quals, columns):
8989
"""Inform the planner that it can be EXTREMELY costly to use the
90-
payload column, and that a query on Message-ID will return only one row."""
90+
payload column, and that a query on Message-ID will return
91+
only one row."""
9192
width = len(columns) * 100
9293
nb_rows = 1000000
9394
if self.payload_column in columns:
@@ -97,7 +98,8 @@ def get_rel_size(self, quals, columns):
9798
if qual.field_name.lower() == 'in-reply-to' and\
9899
qual.operator == '=':
99100
nb_rows = 10
100-
if qual.field_name.lower() == 'message-id' and qual.operator == '=':
101+
if (qual.field_name.lower() == 'message-id' and
102+
qual.operator == '='):
101103
nb_rows = 1
102104
break
103105
return (nb_rows, width)
@@ -119,8 +121,8 @@ def imap_agent(self):
119121
return self._imap_agent
120122

121123
def get_path_keys(self):
122-
"""Helps the planner by supplying a list of list of access keys, as well
123-
as a row estimate for each one."""
124+
"""Helps the planner by supplying a list of list of access keys,
125+
as well as a row estimate for each one."""
124126
return [(('Message-ID',), 1), (('From',), 100), (('To',), 100),
125127
(('In-Reply-To',), 10)]
126128

@@ -153,12 +155,12 @@ def _make_condition(self, key, operator, value):
153155
# Contains on flags
154156
return ' '.join(['%s%s' % (prefix,
155157
(STANDARD_FLAGS.get(atom.lower(), '%s %s'
156-
% ('KEYWORD', atom)))) for atom in value])
158+
% ('KEYWORD', atom)))) for atom in value])
157159
elif operator == '&&':
158160
# Overlaps on flags => Or
159161
values = ['(%s%s)' %
160162
(prefix, (STANDARD_FLAGS.get(atom.lower(), '%s %s' %
161-
('KEYWORD', atom)))) for atom in value]
163+
('KEYWORD', atom)))) for atom in value]
162164
return make_or(values)
163165
else:
164166
value = '\\\\%s' % value
@@ -184,17 +186,18 @@ def extract_conditions(self, quals):
184186
if qual.list_any_or_all == ANY:
185187
values = [
186188
'(%s)' % self._make_condition(qual.field_name,
187-
qual.operator[0], value)
189+
qual.operator[0], value)
188190
for value in qual.value]
189191
conditions.append(make_or(values))
190192
elif qual.list_any_or_all == ALL:
191193
conditions.extend([
192194
self._make_condition(qual.field_name, qual.operator[0],
193-
value)
195+
value)
194196
for value in qual.value])
195197
else:
196198
# its not a list, so everything is fine
197-
conditions.append(self._make_condition(qual.field_name,
199+
conditions.append(self._make_condition(
200+
qual.field_name,
198201
qual.operator, qual.value))
199202
conditions = [x for x in conditions if x not in (None, '()')]
200203
return conditions
@@ -211,8 +214,8 @@ def execute(self, quals, columns):
211214
elif column == self.internaldate_column:
212215
col_to_imap[column] = 'INTERNALDATE'
213216
else:
214-
col_to_imap[column] = 'BODY[HEADER.FIELDS (%s)]' %\
215-
column.upper()
217+
col_to_imap[column] = ('BODY[HEADER.FIELDS (%s)]' %
218+
column.upper())
216219
headers.append(column)
217220
try:
218221
conditions = self.extract_conditions(quals) or ['ALL']
@@ -237,10 +240,10 @@ def execute(self, quals, columns):
237240
if charset:
238241
try:
239242
item[column] = decoded_header.decode(
240-
charset)
243+
charset)
241244
except LookupError:
242245
log_to_postgres('Unknown encoding: %s' %
243-
charset, WARNING)
246+
charset, WARNING)
244247
else:
245248
item[column] = decoded_header
246249
yield item

python/multicorn/sqlalchemyfdw.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def delete(self, rowid):
167167

168168
def _get_column_type(self, format_type):
169169
"""Blatant ripoff from PG_Dialect.get_column_info"""
170-
## strip (*) from character varying(5), timestamp(5)
170+
# strip (*) from character varying(5), timestamp(5)
171171
# with time zone, geometry(POLYGON), etc.
172172
attype = re.sub(r'\(.*\)', '', format_type)
173173

python/multicorn/testfdw.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# -*- coding: utf-8 -*-
22
from multicorn import ForeignDataWrapper
3-
from multicorn.compat import unicode_
43
from .utils import log_to_postgres, WARNING, ERROR
54
from itertools import cycle
65
from datetime import datetime
@@ -40,32 +39,36 @@ def _as_generator(self, quals, columns):
4039
line = {}
4140
for column_name, column in self.columns.items():
4241
if self.test_type == 'list':
43-
line[column_name] = [column_name, next(random_thing),
44-
index, '%s,"%s"' % (column_name, index),
45-
'{some value, \\" \' 2}']
42+
line[column_name] = [
43+
column_name, next(random_thing),
44+
index, '%s,"%s"' % (column_name, index),
45+
'{some value, \\" \' 2}']
4646
elif self.test_type == 'dict':
47-
line[column_name] = {"column_name": column_name,
48-
"repeater": next(random_thing),
49-
"index": index,
50-
"maybe_hstore": "a => b"}
47+
line[column_name] = {
48+
"column_name": column_name,
49+
"repeater": next(random_thing),
50+
"index": index,
51+
"maybe_hstore": "a => b"}
5152
elif self.test_type == 'date':
5253
line[column_name] = datetime(2011, (index % 12) + 1,
5354
next(random_thing), 14,
5455
30, 25)
5556
elif self.test_type == 'int':
5657
line[column_name] = index
5758
elif self.test_type == 'encoding':
58-
line[column_name] = b'\xc3\xa9\xc3\xa0\xc2\xa4'.decode('utf-8')
59+
line[column_name] = (b'\xc3\xa9\xc3\xa0\xc2\xa4'
60+
.decode('utf-8'))
5961
elif self.test_type == 'nested_list':
60-
line[column_name] = [[column_name, column_name], [next(random_thing), '{some value, \\" 2}'],
61-
[index, '%s,"%s"' % (column_name, index)]]
62+
line[column_name] = [
63+
[column_name, column_name],
64+
[next(random_thing), '{some value, \\" 2}'],
65+
[index, '%s,"%s"' % (column_name, index)]]
6266
else:
6367
line[column_name] = '%s %s %s' % (column_name,
6468
next(random_thing),
6569
index)
6670
yield line
6771

68-
6972
def execute(self, quals, columns):
7073
log_to_postgres(str(sorted(quals)))
7174
log_to_postgres(str(sorted(columns)))
@@ -76,7 +79,6 @@ def execute(self, quals, columns):
7679
else:
7780
return self._as_generator(quals, columns)
7881

79-
8082
def get_rel_size(self, quals, columns):
8183
if self.test_type == 'planner':
8284
return (10000000, len(columns) * 10)

python/multicorn/utils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ def _log_to_postgres(message, level=0, hint=None, detail=None):
1111

1212

1313
REPORT_CODES = {
14-
DEBUG: 0,
15-
INFO: 1,
16-
WARNING: 2,
17-
ERROR: 3,
18-
CRITICAL: 4
14+
DEBUG: 0,
15+
INFO: 1,
16+
WARNING: 2,
17+
ERROR: 3,
18+
CRITICAL: 4
1919
}
2020

2121

0 commit comments

Comments
 (0)