THRIFT-4405: fix cygwin on appveyor
diff --git a/.flake8 b/.flake8
new file mode 100644
index 0000000..df8fdb2
--- /dev/null
+++ b/.flake8
@@ -0,0 +1,5 @@
+[flake8]
+exclude = .git,__pycache__,**/gen-*/**,contrib/**,docs/source/conf.py,old,build,dist
+ignore = W504,E402,E501
+max-complexity = 30
+max-line-length = 120
diff --git a/build/appveyor/CYGW-appveyor-install.bat b/build/appveyor/CYGW-appveyor-install.bat
index 79b6ef0..72712b2 100644
--- a/build/appveyor/CYGW-appveyor-install.bat
+++ b/build/appveyor/CYGW-appveyor-install.bat
@@ -26,6 +26,12 @@
 CALL cl_showenv.bat                        || EXIT /B
 
 ::
+:: Upgrades cygwin to the latest, if you want...
+::
+:: appveyor DownloadFile "https://cygwin.com/setup-x86_64.exe"
+:: setup-x86_64.exe --quiet-mode --wait --upgrade-also --packages="gcc-g++"
+
+::
 :: Install apt-cyg for package management
 ::
 
diff --git a/build/docker/scripts/sca.sh b/build/docker/scripts/sca.sh
index 16d5826..42128fc 100755
--- a/build/docker/scripts/sca.sh
+++ b/build/docker/scripts/sca.sh
@@ -39,15 +39,7 @@
 cppcheck --force --quiet --inline-suppr --error-exitcode=1 -j2 lib/c_glib/src lib/c_glib/test test/c_glib/src tutorial/c_glib
 
 # Python code style
-flake8 --ignore=W504,E501 lib/py
-flake8 --exclude=tutorial/py/build tutorial/py
-# THRIFT-4371 : generated files are excluded because they haven't been scrubbed yet
-flake8 --ignore=E501 --exclude="*/gen-py*/*",test/py/build test/py
-flake8 test/py.twisted
-flake8 test/py.tornado
-flake8 --ignore=E501 test/test.py
-flake8 --ignore=E501,E722 test/crossrunner
-flake8 test/features
+flake8
 
 # PHP code style
 composer install --quiet
diff --git a/lib/nodejs/examples/httpServer.py b/lib/nodejs/examples/httpServer.py
index b712fcd..76e9f4a 100644
--- a/lib/nodejs/examples/httpServer.py
+++ b/lib/nodejs/examples/httpServer.py
@@ -5,10 +5,12 @@
 from thrift.protocol import TJSONProtocol
 from thrift.server import THttpServer
 
+
 class HelloSvcHandler:
-  def hello_func(self):
-    print("Hello Called")
-    return "hello from Python"
+    def hello_func(self):
+        print("Hello Called")
+        return "hello from Python"
+
 
 processor = HelloSvc.Processor(HelloSvcHandler())
 protoFactory = TJSONProtocol.TJSONProtocolFactory()
diff --git a/test/cpp/src/TestClient.cpp b/test/cpp/src/TestClient.cpp
index 33ba203..c4146cc 100644
--- a/test/cpp/src/TestClient.cpp
+++ b/test/cpp/src/TestClient.cpp
@@ -69,12 +69,12 @@
 // agreement between client and server.
 //
 
-template<class _P>
-class TPedanticProtocol : public _P
+template<typename Proto>
+class TPedanticProtocol : public Proto 
 {
     public:
         TPedanticProtocol(std::shared_ptr<TTransport>& transport)
-          : _P(transport), m_last_seqid((std::numeric_limits<int32_t>::max)() - 10) { }
+          : Proto(transport), m_last_seqid((std::numeric_limits<int32_t>::max)() - 10) { }
 
         virtual uint32_t writeMessageBegin_virt(const std::string& name,
                                            const TMessageType messageType,
@@ -85,14 +85,14 @@
                 seqid = ++m_last_seqid;
             }
 
-            return _P::writeMessageBegin_virt(name, messageType, seqid);
+            return Proto::writeMessageBegin_virt(name, messageType, seqid);
         }
 
         virtual uint32_t readMessageBegin_virt(std::string& name,
                                           TMessageType& messageType,
                                           int32_t& seqid) override
         {
-            uint32_t result = _P::readMessageBegin_virt(name, messageType, seqid);
+            uint32_t result = Proto::readMessageBegin_virt(name, messageType, seqid);
             if (seqid != m_last_seqid) {
                 std::stringstream ss;
                 ss << "ERROR: send request with seqid " << m_last_seqid << " and got reply with seqid " << seqid;
diff --git a/test/crossrunner/run.py b/test/crossrunner/run.py
index ef8fb60..bb06d25 100644
--- a/test/crossrunner/run.py
+++ b/test/crossrunner/run.py
@@ -259,7 +259,7 @@
             raise
         logger.warn('Error executing [%s]', test.name, exc_info=True)
         return (retry_count, RESULT_ERROR)
-    except:
+    except Exception:
         logger.info('Interrupted execution', exc_info=True)
         if not async_mode:
             raise
diff --git a/test/py/TestClient.py b/test/py/TestClient.py
index cc9185c..a85098e 100755
--- a/test/py/TestClient.py
+++ b/test/py/TestClient.py
@@ -26,9 +26,7 @@
 
 from optparse import OptionParser
 from util import local_libpath
-
 sys.path.insert(0, local_libpath())
-
 from thrift.protocol import TProtocolDecorator
 from thrift.protocol import TProtocol
 
@@ -277,6 +275,7 @@
 # running on it (when multiplexec)
 LAST_SEQID = None
 
+
 class TPedanticSequenceIdProtocolWrapper(TProtocolDecorator.TProtocolDecorator):
     """
     Wraps any protocol with sequence ID checking: looks for outbound
@@ -289,7 +288,8 @@
     def writeMessageBegin(self, name, type, seqid):
         global LAST_SEQID
         if LAST_SEQID and LAST_SEQID == seqid:
-            raise TProtocol.TProtocolException(INVALID_DATA,
+            raise TProtocol.TProtocolException(
+                TProtocol.TProtocolException.INVALID_DATA,
                 "Python client reused sequence ID {0}".format(seqid))
         LAST_SEQID = seqid
         super(TPedanticSequenceIdProtocolWrapper, self).writeMessageBegin(
@@ -300,7 +300,8 @@
         (name, type, seqid) =\
             super(TPedanticSequenceIdProtocolWrapper, self).readMessageBegin()
         if LAST_SEQID != seqid:
-            raise TProtocol.TProtocolException(INVALID_DATA,
+            raise TProtocol.TProtocolException(
+                TProtocol.TProtocolException.INVALID_DATA,
                 "We sent seqid {0} and server returned seqid {1}".format(
                     self.last, seqid))
         return (name, type, seqid)
@@ -310,6 +311,7 @@
     """ Wrap a protocol in the pedantic sequence ID wrapper. """
     return TPedanticSequenceIdProtocolWrapper(proto)
 
+
 class MultiplexedOptionalTest(AbstractTest):
     def get_protocol2(self, transport):
         return None
diff --git a/tutorial/php/runserver.py b/tutorial/php/runserver.py
index 077daa1..8cc30fb 100755
--- a/tutorial/php/runserver.py
+++ b/tutorial/php/runserver.py
@@ -30,4 +30,5 @@
 class Handler(CGIHTTPServer.CGIHTTPRequestHandler):
     cgi_directories = ['/php']
 
+
 BaseHTTPServer.HTTPServer(('', 8080), Handler).serve_forever()
diff --git a/tutorial/py.twisted/PythonClient.py b/tutorial/py.twisted/PythonClient.py
index 63dde7e..2976495 100755
--- a/tutorial/py.twisted/PythonClient.py
+++ b/tutorial/py.twisted/PythonClient.py
@@ -67,6 +67,7 @@
     print(('Check log: %s' % (log.value)))
     reactor.stop()
 
+
 if __name__ == '__main__':
     d = ClientCreator(reactor,
                       TTwisted.ThriftClientProtocol,
diff --git a/tutorial/py.twisted/PythonServer.py b/tutorial/py.twisted/PythonServer.py
index 1b0e2d5..034e4a3 100755
--- a/tutorial/py.twisted/PythonServer.py
+++ b/tutorial/py.twisted/PythonServer.py
@@ -85,6 +85,7 @@
     def zip(self):
         print('zip()')
 
+
 if __name__ == '__main__':
     handler = CalculatorHandler()
     processor = Calculator.Processor(handler)