Skip to content

Commit

Permalink
Flake8 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
njoyce committed Feb 9, 2015
1 parent c2b6bb1 commit 21d38dd
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 34 deletions.
15 changes: 11 additions & 4 deletions pyamf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -853,15 +853,22 @@ def register_package(module=None, package=None, separator='.', ignore=None,
module = prev_frame.f_locals

if type(module) is dict:
has = lambda x: x in module
def has(x):
return x in module

get = module.__getitem__
elif type(module) is list:
has = lambda x: x in module
def has(x):
return x in module

get = module.__getitem__
strict = False
else:
has = lambda x: hasattr(module, x)
get = lambda x: getattr(module, x)
def has(x):
return hasattr(module, x)

def get(x):
return getattr(module, x)

if package is None:
if has('__name__'):
Expand Down
2 changes: 1 addition & 1 deletion pyamf/remoting/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

#: List of available status response codes.
STATUS_CODES = {
STATUS_OK: '/onResult',
STATUS_OK: '/onResult',
STATUS_ERROR: '/onStatus',
STATUS_DEBUG: '/onDebugEvents'
}
Expand Down
9 changes: 5 additions & 4 deletions pyamf/remoting/gateway/django.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@
@since: 0.1.0
"""

import pyamf
from pyamf import remoting
from pyamf.remoting import gateway


django = __import__('django.http')
http = django.http
conf = __import__('django.conf')
conf = conf.conf

import pyamf
from pyamf import remoting
from pyamf.remoting import gateway

__all__ = ['DjangoGateway']


Expand Down
6 changes: 3 additions & 3 deletions pyamf/remoting/gateway/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
import sys
import os.path

from pyamf import remoting, DecodeError
from pyamf.remoting import gateway

try:
sys.path.remove(os.path.dirname(os.path.abspath(__file__)))
except ValueError:
Expand All @@ -23,9 +26,6 @@
google = __import__('google.appengine.ext.webapp')
webapp = google.appengine.ext.webapp

from pyamf import remoting, DecodeError
from pyamf.remoting import gateway

__all__ = ['WebAppGateway']


Expand Down
10 changes: 6 additions & 4 deletions pyamf/remoting/gateway/twisted.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import sys
import os.path

from pyamf import remoting
from pyamf.remoting import gateway, amf0, amf3

try:
sys.path.remove('')
except ValueError:
Expand All @@ -35,9 +38,6 @@
resource = twisted.web.resource
server = twisted.web.server

from pyamf import remoting
from pyamf.remoting import gateway, amf0, amf3

__all__ = ['TwistedGateway']


Expand Down Expand Up @@ -324,8 +324,10 @@ def eb(failure):
self.logger.error(errMesg)
self.logger.error(failure.getTraceback())

body = "500 Internal Server Error\n\nThere was an error encoding " \
body = (
"500 Internal Server Error\n\nThere was an error encoding "
"the response."
)

if self.debug:
body += "\n\nTraceback:\n\n%s" % failure.getTraceback()
Expand Down
3 changes: 2 additions & 1 deletion pyamf/tests/test_amf0.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,8 @@ def test_elementtree_tag(self):
encoding an xml type.
"""
class NotAnElement(object):
items = lambda self: []
def items(self):
return []

def __iter__(self):
return iter([])
Expand Down
23 changes: 12 additions & 11 deletions pyamf/tests/test_amf3.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,8 @@ class Person(object):

def test_elementtree_tag(self):
class NotAnElement(object):
items = lambda self: []
def items(self):
return []

def __iter__(self):
return iter([])
Expand Down Expand Up @@ -473,20 +474,20 @@ def test_29b_ints(self):

def test_number(self):
vals = [
(0, '\x04\x00'),
(0.2, '\x05\x3f\xc9\x99\x99\x99\x99\x99\x9a'),
(1, '\x04\x01'),
(127, '\x04\x7f'),
(128, '\x04\x81\x00'),
(0x3fff, '\x04\xff\x7f'),
(0x4000, '\x04\x81\x80\x00'),
(0, '\x04\x00'),
(0.2, '\x05\x3f\xc9\x99\x99\x99\x99\x99\x9a'),
(1, '\x04\x01'),
(127, '\x04\x7f'),
(128, '\x04\x81\x00'),
(0x3fff, '\x04\xff\x7f'),
(0x4000, '\x04\x81\x80\x00'),
(0x1FFFFF, '\x04\xff\xff\x7f'),
(0x200000, '\x04\x80\xc0\x80\x00'),
(0x3FFFFF, '\x04\x80\xff\xff\xff'),
(0x400000, '\x04\x81\x80\x80\x00'),
(-1, '\x04\xff\xff\xff\xff'),
(42, '\x04\x2a'),
(-123, '\x04\xff\xff\xff\x85'),
(-1, '\x04\xff\xff\xff\xff'),
(42, '\x04\x2a'),
(-123, '\x04\xff\xff\xff\x85'),
(amf3.MIN_29B_INT, '\x04\xc0\x80\x80\x00'),
(amf3.MAX_29B_INT, '\x04\xbf\xff\xff\xff'),
(1.23456789, '\x05\x3f\xf3\xc0\xca\x42\x83\xde\x1b')
Expand Down
12 changes: 9 additions & 3 deletions pyamf/tests/test_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,9 @@ def test_empty_target(self):
class QueryBrowserTestCase(unittest.TestCase):
def test_request(self):
gw = gateway.BaseGateway()
echo = lambda x: x

def echo(x):
return x

gw.addService(echo, 'echo', description='This is a test')

Expand Down Expand Up @@ -507,7 +509,9 @@ def _auth(self, username, password):

def test_gateway(self):
gw = gateway.BaseGateway(authenticator=self._auth)
echo = lambda x: x

def echo(x):
return x

gw.addService(echo, 'echo')

Expand All @@ -524,7 +528,9 @@ def test_gateway(self):

def test_service(self):
gw = gateway.BaseGateway()
echo = lambda x: x

def echo(x):
return x

gw.addService(echo, 'echo', authenticator=self._auth)

Expand Down
11 changes: 8 additions & 3 deletions pyamf/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,16 @@ def get_class_meta(klass):
a = klass.__amf__

if type(a) is dict:
in_func = lambda x: x in a
def in_func(x):
return x in a

get_func = a.__getitem__
else:
in_func = lambda x: hasattr(a, x)
get_func = lambda x: getattr(a, x)
def in_func(x):
return hasattr(a, x)

def get_func(x):
return getattr(a, x)

for prop in ['alias', 'amf3', 'dynamic', 'external']:
if in_func(prop):
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,4 @@ sourcecode: yes

[flake8]
exclude=doc,.ropeproject
ignore=E402

0 comments on commit 21d38dd

Please sign in to comment.