diff --git a/CHANGELOG b/CHANGELOG
new file mode 100644
index 00000000..aed051f0
--- /dev/null
+++ b/CHANGELOG
@@ -0,0 +1,343 @@
+pysmb-1.1.26, 5 Jan 2019
+========================
+- Prevents OperationError from being raised when listPath() operation does not
+  return any matching file results.
+- SMBConnection is now a context manager #122.
+
+pysmb-1.1.25, 28 July 2018
+========================
+- Fix buggy support for search parameter in listPath() method. Add
+  SMB_FILE_ATTRIBUTE_INCL_NORMAL bit constant to include 'normal' files with
+  other file types in the returned result. From now on, pysmb defines a 'normal' file
+  as a file entry that is not read-only, not hidden, not system, not archive and
+  not a directory; it ignores other attributes like compression, indexed, sparse,
+  temporary and encryption. listPath() method will now include 'normal' files
+  using the default search parameter.
+- Add isNormal property to SharedFile class to support test if the file is a
+  'normal' file (according to pysmb definition of 'normal' file).
+
+pysmb-1.1.24, 19 July 2018
+========================
+- Improve listPath implementation for SMB1
+- Support for STATUS_PENDING responses across all SMB2 operations.
+
+pysmb-1.1.23, 5 May 2018
+========================
+- Fix bug in listShares() method which fails when the remote server has many shares.
+- Improve echo() method to test and fail if the provided data to echo is not a bytes object.
+- Fix bug in listPath() method where the path to query is not properly terminated.
+
+pysmb-1.1.22, 17 Sep 2017
+========================
+- Fix bug in getAttributes() method which should return only the filename
+  instead of the entire path for the filename property for the return result.
+
+pysmb-1.1.21, 9 Sep 2017
+========================
+- Fix bug where timestamp values for SMB1 getAttributes() response are not
+  converted properly from FILETIME to epoch time values.
+
+pysmb-1.1.20, 13 Aug 2017
+=========================
+- Add getSecurity() method to support security descriptors query via SMB2
+- Improve retrieveFile() and retrieveFileFromOffset() methods to allow file
+  retrievals over SMB2 even when the file is being locked on the server.
+- Silently discards NMB SESSION_KEEPALIVE packets instead of raising warnings.
+- SMB sessionID will be sent in ECHO requests to conform to SMB2 specs.
+- Fix type errors for MD4 functions in python3.
+
+pysmb-1.1.19, 13 Nov 2016
+=========================
+- Ignore STATUS_PENDING during delete and file store operations
+
+pysmb-1.1.18, 9 Apr 2016
+========================
+
+- Rollback fixes to NTLMv2 response algorithm in pysmb 1.1.17. The fixes
+  fail to work with some servers.
+- Add missing errno imports in SMBConnection.py
+- Fix UnboundLocalError raised when using type() in SMBConnection.py
+
+pysmb-1.1.17, 11 Nov 2015
+=========================
+
+- Fix crashes in directory listing with keyerror 'support_dfs'
+- Fix bugs in NTLMv2 response algorithm.
+- Fix bugs where client domain is not included as part of the session negotiation.
+
+pysmb-1.1.16, 10 May 2015
+=========================
+
+- Fix typo errors in authentication error messages
+- Improve share listings on SMB2 protocol by ignoring interim STATUS_PENDING responses.
+
+pysmb-1.1.15, 15 Feb 2015
+=========================
+
+- Add new parameter to SMBConnection's storeFileFromOffset method to determine
+  whether the remote file is to be truncated before writing.
+
+pysmb-1.1.14, 1 Feb 2015
+========================
+
+- Add support for DFS shares in listPath()
+- Bug fix for python3's _listPath_SMB2 implementation
+
+pysmb-1.1.13, 18 Oct 2014
+=========================
+
+- Add missing methods and improve compatibility with python3
+- Fix bug in SMB2 rename implementation which fails to rename directory
+
+pysmb-1.1.12, 21 Sep 2014
+=========================
+
+- Fix syntax error for python3 NBNSProtocol implementation
+- Fix bug in SMB1 implementation which results in access denied errors with Samba 3.0
+
+pysmb-1.1.11, 13 Sep 2014
+=========================
+
+- Add support for unicode characters in domain, username and password.
+- Add storeFileFromOffset method to SMB API
+- Fix bug in getAttributes implementation for SMB1
+- Fix bug for NMB which uses broadcast flag for unicast queries
+- Update the Tree Connect Andx request implementation to MS-SMB 2.2.4.7.1 extensions
+
+pysmb-1.1.10, 29 Jun 2014
+=========================
+
+- Add getAttributes() method to SMBConnection and SMBProtocolFactory class
+- Add isReadOnly property to SharedFile class
+
+pysmb-1.1.9, 1 Jun 2014
+=======================
+
+- Add support for domains in smb:// URLs
+- Fix a bug which fails to test for the correct GSS security provider OID values
+
+pysmb-1.1.8, 21 Dec 2013
+========================
+
+- Fix a bug in storeFile() method when the destination file is not overwritten if
+  it exists in SMB1 communication
+- Fix a SMB1 authentication problem when extended negotation is not carried out
+  because the remote server has specified its support for extended security in the
+  payload, instead of in the message flags2.
+
+pysmb-1.1.7, 27 Sep 2013
+========================
+
+- Improve listShares() function which can fail with the listing response is
+  separated into multiple SMB packets for large number of shares.
+- Fix bug in python3 implementation where session connection can fail when
+  remote server supports message signing.
+
+pysmb-1.1.6, 16 Aug 2013
+========================
+
+- Fix bug where the status of the SMB_COM_NEGOTIATE reply is not checked for error
+  before allowing further processing.
+
+pysmb-1.1.5, 19 June 2013
+=========================
+
+- Adds support for Direct hosting of SMB over TCP/IP (TCP port: 445)
+
+pysmb-1.1.4, 31 May 2013
+========================
+
+- Improve query performance for query IP addresses for NetBIOS names in
+  NetBIOSProtocol.py
+- Fix bugs in SMBConnection when sending large data packets can result in
+  AssertionError.
+
+pysmb-1.1.3, 18 Mar 2013
+========================
+
+- Fix bug which results in endless loop in SMBConnection when remote CIFS
+  server closes the connection.
+
+pysmb-1.1.2, 28 Sep 2012
+========================
+
+- Improve queryIPForName() in nmb.NetBIOS and nmb.NBNSProtocol class to
+  return only server machine name and ignore workgroup names.
+
+pysmb-1.1.1, 9 June 2012
+========================
+
+- Adds support for Python3. Noted that the Python3 SMB/NMB protocol implementations
+  for Twisted are not well-tested as Twisted (as of v12.1) is not Python3 ready yet.
+- Adds support for retrieving list of shadow copies (also known as
+  "previous versions" in Windows). Note that not all Windows editions support shadow
+  copies.
+
+
+pysmb-1.1.0, 1 June 2012
+========================
+
+- Adds SMB2 protocol implementation with signing for outgoing SMB2 messages.
+  pysmb will utilize SMB2 protocol with servers that support SMB2
+  (eg. Windows Vista, Windows 7 and Samba 3).
+  If the remote server does not support SMB2, pysmb will fall back automatically
+  to using SMB1 protocol.
+
+
+pysmb-1.0.5, 7 May 2012
+=======================
+
+- Add supports for SMB message signing. pysmb will sign all SMB messages from
+  the CIFS client to the server, but it does not verify the signatures of the
+  SMB messages from the server.
+
+
+pysmb-1.0.4, 1 May 2012
+=======================
+
+- Adds support for "smb://" URL in urllib2 python packages to retrieve or upload
+  files from/to remote CIFS servers.
+- Improve documentation
+
+
+pysmb-1.0.3, 28 April 2012
+===========================
+
+- Fix a crash in SMB._storFile() method which occurs when the remote CIFS server
+  utilizes a max raw size larger than 65535 bytes. The bug was discovered with
+  Windows 7 Pro SP1.
+- Fix a bug in SMB._listPath() method where the files/folders time information are
+  not properly converted to Epoch time.
+- Add NBNSProtocol.queryIPForName() and NetBIOS.queryIPForName() methods to
+  query for a machine's NetBIOS name at the given IP address.
+- Add SMBProtocol.retrieveFileFromOffset() and SMBConnection.retrieveFileFromOffset()
+  methods for a finer control of file retrieval operation with read offset and write
+  limits.
+
+
+pysmb-1.0.2, 31 March 2012
+==========================
+
+- Fix a bug in SMB._handleSessionChallenge() method in base.py where the domain attribute
+  was not used to generate the corresponding NTLM authentication packets, resulting in
+  the default WORKGROUP domain for used for all subsequent authentications.
+
+pysmb-1.0.1, 25 Jan 2012
+========================
+
+- Fixes a bug in listPath() method which causes directory listing for
+  sub-directories to return an empty list.
+- Fixes an incorrect implementation of the TRANS2_FIND_FIRST2 and
+  TRANS2_FIND_NEXT2 request/response handling which causes directory listing
+  to crash when the remote directory contains a certain number of entries.
+
+
+pysmb-1.0.0, 25 Dec 2011
+========================
+
+- Completely rewrites pysmb. API is not compatible with previous pysmb-0.x.x
+- Supports NTLMv1 and NTLMv2 authentication
+- Adds in NMB/SMB protocol implementation for use with Twisted framework
+- Tested with Windows XP SP3, Windows Vista, Windows 7 and Samba 3.x
+- Requires Python 2.4.4 or later, and pyasn1. Not tested with Python3
+
+pysmb-0.4.5, 22 Jun 2009
+========================
+
+- Prevents pysmb from failing when there are too many files/folders to
+  be returned in a single SMB TRANS2 call. pysmb will "resume" requesting
+  for more files/folders information in subsequent SMB TRANS2 requests.
+
+pysmb-0.4.4, 12 Jan 2004
+========================
+
+- Add in support for AMK's Python Cryptography Toolkit which will be used
+  for DES password hashing. If AMK's pycrypto is found, it will be used
+  instead of mxCrypto.
+
+pysmb-0.4.3, 22 Feb 2003
+========================
+
+- Fix a bug which fails to close the socket in nmb.py on socket exception
+- Fix a bug which fails to close the NetBIOSSession in smb.py if the session
+  has not been properly established yet.
+
+pysmb-0.4.2, 03 Aug 2002
+========================
+
+- Add new methods to SharedFile instances, get_mtime_epoch, get_atime_epoch
+  and get_ctime_epoch. These methods will return the mtime, atime and ctime in
+  epoch time rather than SMB time.
+- Remove debugging printout in smb.py which has been released accidentally
+  with the last release.
+- Fix a bug in smbcp which causes to local to remote copy to fail
+
+pysmb-0.4.1, 22 Jun 2002
+========================
+
+- Fix a bug in smb.py which does not return the correct file size for files
+  with their archive bits turned off. This results in these files not being
+  retrieved or sent properly.
+- Fix some typo error in the documentations
+
+pysmb-0.4.0, 17 Apr 2002
+========================
+
+- Use NT LM0.12 dialect.
+- New smb.SMBMachine class
+- Add SMB.get_server_domain(), smb.get_server_os(), SMB.get_server_lanman()
+
+pysmb-0.3.1, 12 Nov 2001
+========================
+
+- Fix a problem with some Windows server where an UID is required when server is in share mode.
+  Now, pysmb calls login() with empty authentication information when server is in share mode.
+- Add TYPE_DOMAIN_MASTER constant and description to nmb.py.
+
+pysmb-0.3.0, 10 Nov 2001
+========================
+
+- Add support for services in share mode. Minor changes to smb.SMB class API.
+- Fix a bug in smb.py's __raw_retr_file which has failed to initialize the max_buf_size prior to usage.
+- Fix a bug in smblistshare which fails to print the correct NMB error message
+- Modify smb.py not throw AttributeError in the destructor when there is an error while creating a session
+  in the constructor
+
+pysmb-0.2.0, 04 Oct 2001
+========================
+
+- Add support for encrypted authentication using DES
+- Fix a bug(?) which treats all services and filenames as case-sensitive
+
+pysmb-0.1.3, 03 Sep 2001
+========================
+
+- Fix a bug in smblistshare and smbdu which fails to catch the nmb.NetBIOSError raised when session
+  setup fails.
+- Fix a bug in smb.SMB that arises from the change in nmb.NetBIOSSession which sends
+  the session port number as the remote host type.
+
+pysmb-0.1.2, 01 Sep 2001
+========================
+
+- Fix a bug in nmb.NetBIOSSession which specifies a TYPE_WORKSTATION for remote host instead of TYPE_SERVER.
+- Minor change to nmb.NetBIOSSession constructor API.
+- Fix a bug in smbdu which raises OverflowError when printing long file size values.
+- Fix a bug in smbcp which does not handle the destination path correctly when
+  the source file is copied to a different filename.
+
+pysmb-0.1.1, 25 Aug 2001
+========================
+
+- Change nmb's NetBIOS and NetBIOSSession class such that they raise a NetBIOSError
+  with a tuple of ( err_msg, err_class, err_code )
+- Add a function strerror() in both smb and nmb to return human readable messages
+  for error codes.
+- Fix a bug in smbcp which fails to print an error message and terminate when the
+  remote source path is not found.
+- Add in another utility, smblistshare.
+
+pysmb-0.1.0, 20 Aug 2001
+========================
+
+- First public release
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 00000000..7eaccfaf
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,20 @@
+
+Copyright (C) 2001-2019 Michael Teo <miketeo (a) miketeo.net>
+
+This software is provided 'as-is', without any express or implied warranty.
+In no event will the author be held liable for any damages arising from the
+use of this software.
+
+Permission is granted to anyone to use this software for any purpose,
+including commercial applications, and to alter it and redistribute it
+freely, subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must not
+   claim that you wrote the original software. If you use this software
+   in a product, an acknowledgment in the product documentation would be
+   appreciated but is not required.
+
+2. Altered source versions must be plainly marked as such, and must not be
+   misrepresented as being the original software.
+
+3. This notice cannot be removed or altered from any source distribution.
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 00000000..b22628d9
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1,11 @@
+include LICENSE
+include CHANGELOG
+recursive-include python2 *
+recursive-exclude python2 *.pyc
+recursive-exclude python2 *~
+recursive-include python3 *
+recursive-exclude python3 *.pyc
+recursive-exclude python3 *~
+recursive-include sphinx *
+recursive-include docs *
+recursive-exclude docs *.zip
diff --git a/PKG-INFO b/PKG-INFO
new file mode 100644
index 00000000..9f8779df
--- /dev/null
+++ b/PKG-INFO
@@ -0,0 +1,23 @@
+Metadata-Version: 1.1
+Name: pysmb
+Version: 1.1.26
+Summary: pysmb is an experimental SMB/CIFS library written in Python to support file sharing between Windows and Linux machines
+Home-page: https://miketeo.net/projects/pysmb
+Author: Michael Teo
+Author-email: miketeo@miketeo.net
+License: zlib/libpng
+Description: pysmb is an experimental SMB/CIFS library written in Python. It implements the client-side SMB/CIFS protocol which allows your Python application to access and transfer files to/from SMB/CIFS shared folders like your Windows file sharing and Samba folders.
+Keywords: windows samba cifs sharing ftp smb linux
+Platform: UNKNOWN
+Classifier: Development Status :: 5 - Production/Stable
+Classifier: Environment :: Win32 (MS Windows)
+Classifier: Environment :: Console
+Classifier: License :: OSI Approved :: zlib/libpng License
+Classifier: Operating System :: Microsoft :: Windows
+Classifier: Operating System :: POSIX
+Classifier: Programming Language :: Python
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3
+Classifier: Topic :: Communications :: File Sharing
+Classifier: Topic :: Software Development :: Libraries :: Python Modules
+Classifier: Topic :: System :: Networking
diff --git a/README.txt b/README.txt
new file mode 100644
index 00000000..a23a4b25
--- /dev/null
+++ b/README.txt
@@ -0,0 +1,3 @@
+pysmb is an experimental SMB/CIFS library written in Python.
+It implements the client-side SMB/CIFS protocol (SMB1 and SMB2) which allows your Python application to access
+and transfer files to/from SMB/CIFS shared folders like your Windows file sharing and Samba folders.
diff --git a/docs/doctrees/api/nmb_NBNSProtocol.doctree b/docs/doctrees/api/nmb_NBNSProtocol.doctree
new file mode 100644
index 00000000..63a5cd01
Binary files /dev/null and b/docs/doctrees/api/nmb_NBNSProtocol.doctree differ
diff --git a/docs/doctrees/api/nmb_NetBIOS.doctree b/docs/doctrees/api/nmb_NetBIOS.doctree
new file mode 100644
index 00000000..970596a9
Binary files /dev/null and b/docs/doctrees/api/nmb_NetBIOS.doctree differ
diff --git a/docs/doctrees/api/smb_SMBConnection.doctree b/docs/doctrees/api/smb_SMBConnection.doctree
new file mode 100644
index 00000000..063d5625
Binary files /dev/null and b/docs/doctrees/api/smb_SMBConnection.doctree differ
diff --git a/docs/doctrees/api/smb_SMBHandler.doctree b/docs/doctrees/api/smb_SMBHandler.doctree
new file mode 100644
index 00000000..5b414de8
Binary files /dev/null and b/docs/doctrees/api/smb_SMBHandler.doctree differ
diff --git a/docs/doctrees/api/smb_SMBProtocolFactory.doctree b/docs/doctrees/api/smb_SMBProtocolFactory.doctree
new file mode 100644
index 00000000..1e5933d1
Binary files /dev/null and b/docs/doctrees/api/smb_SMBProtocolFactory.doctree differ
diff --git a/docs/doctrees/api/smb_SharedDevice.doctree b/docs/doctrees/api/smb_SharedDevice.doctree
new file mode 100644
index 00000000..d2b2c340
Binary files /dev/null and b/docs/doctrees/api/smb_SharedDevice.doctree differ
diff --git a/docs/doctrees/api/smb_SharedFile.doctree b/docs/doctrees/api/smb_SharedFile.doctree
new file mode 100644
index 00000000..d4d3b8ac
Binary files /dev/null and b/docs/doctrees/api/smb_SharedFile.doctree differ
diff --git a/docs/doctrees/api/smb_exceptions.doctree b/docs/doctrees/api/smb_exceptions.doctree
new file mode 100644
index 00000000..31eff133
Binary files /dev/null and b/docs/doctrees/api/smb_exceptions.doctree differ
diff --git a/docs/doctrees/api/smb_security_descriptors.doctree b/docs/doctrees/api/smb_security_descriptors.doctree
new file mode 100644
index 00000000..734f4f6e
Binary files /dev/null and b/docs/doctrees/api/smb_security_descriptors.doctree differ
diff --git a/docs/doctrees/environment.pickle b/docs/doctrees/environment.pickle
new file mode 100644
index 00000000..843712b8
Binary files /dev/null and b/docs/doctrees/environment.pickle differ
diff --git a/docs/doctrees/extending.doctree b/docs/doctrees/extending.doctree
new file mode 100644
index 00000000..4031973c
Binary files /dev/null and b/docs/doctrees/extending.doctree differ
diff --git a/docs/doctrees/index.doctree b/docs/doctrees/index.doctree
new file mode 100644
index 00000000..abeb85f2
Binary files /dev/null and b/docs/doctrees/index.doctree differ
diff --git a/docs/html/.buildinfo b/docs/html/.buildinfo
new file mode 100644
index 00000000..69caef73
--- /dev/null
+++ b/docs/html/.buildinfo
@@ -0,0 +1,4 @@
+# Sphinx build info version 1
+# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
+config: 24e4dd110b51998b070280bf87a2d415
+tags: 645f666f9bcd5a90fca523b33c5a78b7
diff --git a/docs/html/_modules/index.html b/docs/html/_modules/index.html
new file mode 100644
index 00000000..972635b8
--- /dev/null
+++ b/docs/html/_modules/index.html
@@ -0,0 +1,93 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    
+    <title>Overview: module code &mdash; pysmb 1.1.25 documentation</title>
+    
+    <link rel="stylesheet" href="../_static/sphinxdoc.css" type="text/css" />
+    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
+    
+    <script type="text/javascript">
+      var DOCUMENTATION_OPTIONS = {
+        URL_ROOT:    '../',
+        VERSION:     '1.1.25',
+        COLLAPSE_INDEX: false,
+        FILE_SUFFIX: '.html',
+        HAS_SOURCE:  true
+      };
+    </script>
+    <script type="text/javascript" src="../_static/jquery.js"></script>
+    <script type="text/javascript" src="../_static/underscore.js"></script>
+    <script type="text/javascript" src="../_static/doctools.js"></script>
+    <link rel="top" title="pysmb 1.1.25 documentation" href="../index.html" /> 
+  </head>
+  <body role="document">
+    <div class="related" role="navigation" aria-label="related navigation">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="../genindex.html" title="General Index"
+             accesskey="I">index</a></li>
+        <li class="right" >
+          <a href="../py-modindex.html" title="Python Module Index"
+             >modules</a> |</li>
+        <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.1.25 documentation</a> &raquo;</li> 
+      </ul>
+    </div>
+      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
+        <div class="sphinxsidebarwrapper">
+<div id="searchbox" style="display: none" role="search">
+  <h3>Quick search</h3>
+    <form class="search" action="../search.html" method="get">
+      <input type="text" name="q" />
+      <input type="submit" value="Go" />
+      <input type="hidden" name="check_keywords" value="yes" />
+      <input type="hidden" name="area" value="default" />
+    </form>
+    <p class="searchtip" style="font-size: 90%">
+    Enter search terms or a module, class or function name.
+    </p>
+</div>
+<script type="text/javascript">$('#searchbox').show(0);</script>
+        </div>
+      </div>
+
+    <div class="document">
+      <div class="documentwrapper">
+        <div class="bodywrapper">
+          <div class="body" role="main">
+            
+  <h1>All modules for which code is available</h1>
+<ul><li><a href="nmb/NetBIOS.html">nmb.NetBIOS</a></li>
+<li><a href="nmb/NetBIOSProtocol.html">nmb.NetBIOSProtocol</a></li>
+<li><a href="smb/security_descriptors.html">smb.security_descriptors</a></li>
+<li><a href="smb/smb_structs.html">smb.smb_structs</a></li>
+</ul>
+
+          </div>
+        </div>
+      </div>
+      <div class="clearer"></div>
+    </div>
+    <div class="related" role="navigation" aria-label="related navigation">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="../genindex.html" title="General Index"
+             >index</a></li>
+        <li class="right" >
+          <a href="../py-modindex.html" title="Python Module Index"
+             >modules</a> |</li>
+        <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.1.25 documentation</a> &raquo;</li> 
+      </ul>
+    </div>
+    <div class="footer" role="contentinfo">
+        &copy; Copyright 2001-2018, Michael Teo http://miketeo.net/.
+      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.6.
+    </div>
+  </body>
+</html>
\ No newline at end of file
diff --git a/docs/html/_modules/nmb/NetBIOS.html b/docs/html/_modules/nmb/NetBIOS.html
new file mode 100644
index 00000000..680ececc
--- /dev/null
+++ b/docs/html/_modules/nmb/NetBIOS.html
@@ -0,0 +1,236 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    
+    <title>nmb.NetBIOS &mdash; pysmb 1.1.25 documentation</title>
+    
+    <link rel="stylesheet" href="../../_static/sphinxdoc.css" type="text/css" />
+    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
+    
+    <script type="text/javascript">
+      var DOCUMENTATION_OPTIONS = {
+        URL_ROOT:    '../../',
+        VERSION:     '1.1.25',
+        COLLAPSE_INDEX: false,
+        FILE_SUFFIX: '.html',
+        HAS_SOURCE:  true
+      };
+    </script>
+    <script type="text/javascript" src="../../_static/jquery.js"></script>
+    <script type="text/javascript" src="../../_static/underscore.js"></script>
+    <script type="text/javascript" src="../../_static/doctools.js"></script>
+    <link rel="top" title="pysmb 1.1.25 documentation" href="../../index.html" />
+    <link rel="up" title="Module code" href="../index.html" /> 
+  </head>
+  <body role="document">
+    <div class="related" role="navigation" aria-label="related navigation">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="../../genindex.html" title="General Index"
+             accesskey="I">index</a></li>
+        <li class="right" >
+          <a href="../../py-modindex.html" title="Python Module Index"
+             >modules</a> |</li>
+        <li class="nav-item nav-item-0"><a href="../../index.html">pysmb 1.1.25 documentation</a> &raquo;</li>
+          <li class="nav-item nav-item-1"><a href="../index.html" accesskey="U">Module code</a> &raquo;</li> 
+      </ul>
+    </div>
+      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
+        <div class="sphinxsidebarwrapper">
+<div id="searchbox" style="display: none" role="search">
+  <h3>Quick search</h3>
+    <form class="search" action="../../search.html" method="get">
+      <input type="text" name="q" />
+      <input type="submit" value="Go" />
+      <input type="hidden" name="check_keywords" value="yes" />
+      <input type="hidden" name="area" value="default" />
+    </form>
+    <p class="searchtip" style="font-size: 90%">
+    Enter search terms or a module, class or function name.
+    </p>
+</div>
+<script type="text/javascript">$('#searchbox').show(0);</script>
+        </div>
+      </div>
+
+    <div class="document">
+      <div class="documentwrapper">
+        <div class="bodywrapper">
+          <div class="body" role="main">
+            
+  <h1>Source code for nmb.NetBIOS</h1><div class="highlight"><pre>
+
+<span class="kn">import</span> <span class="nn">os</span><span class="o">,</span> <span class="nn">logging</span><span class="o">,</span> <span class="nn">random</span><span class="o">,</span> <span class="nn">socket</span><span class="o">,</span> <span class="nn">time</span><span class="o">,</span> <span class="nn">select</span>
+<span class="kn">from</span> <span class="nn">base</span> <span class="kn">import</span> <span class="n">NBNS</span><span class="p">,</span> <span class="n">NotConnectedError</span>
+<span class="kn">from</span> <span class="nn">nmb_constants</span> <span class="kn">import</span> <span class="n">TYPE_CLIENT</span><span class="p">,</span> <span class="n">TYPE_SERVER</span><span class="p">,</span> <span class="n">TYPE_WORKSTATION</span>
+
+<div class="viewcode-block" id="NetBIOS"><a class="viewcode-back" href="../../api/nmb_NetBIOS.html#nmb.NetBIOS.NetBIOS">[docs]</a><span class="k">class</span> <span class="nc">NetBIOS</span><span class="p">(</span><span class="n">NBNS</span><span class="p">):</span>
+
+    <span class="n">log</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="s1">&#39;NMB.NetBIOS&#39;</span><span class="p">)</span>
+
+<div class="viewcode-block" id="NetBIOS.__init__"><a class="viewcode-back" href="../../api/nmb_NetBIOS.html#nmb.NetBIOS.NetBIOS.__init__">[docs]</a>    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">broadcast</span> <span class="o">=</span> <span class="bp">True</span><span class="p">,</span> <span class="n">listen_port</span> <span class="o">=</span> <span class="mi">0</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Instantiate a NetBIOS instance, and creates a IPv4 UDP socket to listen/send NBNS packets.</span>
+
+<span class="sd">        :param boolean broadcast: A boolean flag to indicate if we should setup the listening UDP port in broadcast mode</span>
+<span class="sd">        :param integer listen_port: Specifies the UDP port number to bind to for listening. If zero, OS will automatically select a free port number.</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">broadcast</span> <span class="o">=</span> <span class="n">broadcast</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">sock</span> <span class="o">=</span> <span class="n">socket</span><span class="o">.</span><span class="n">socket</span><span class="p">(</span><span class="n">socket</span><span class="o">.</span><span class="n">AF_INET</span><span class="p">,</span> <span class="n">socket</span><span class="o">.</span><span class="n">SOCK_DGRAM</span><span class="p">)</span>
+        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">broadcast</span><span class="p">:</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">sock</span><span class="o">.</span><span class="n">setsockopt</span><span class="p">(</span><span class="n">socket</span><span class="o">.</span><span class="n">SOL_SOCKET</span><span class="p">,</span> <span class="n">socket</span><span class="o">.</span><span class="n">SO_BROADCAST</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
+        <span class="k">if</span> <span class="n">listen_port</span><span class="p">:</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">sock</span><span class="o">.</span><span class="n">bind</span><span class="p">((</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="n">listen_port</span> <span class="p">))</span></div>
+
+<div class="viewcode-block" id="NetBIOS.close"><a class="viewcode-back" href="../../api/nmb_NetBIOS.html#nmb.NetBIOS.NetBIOS.close">[docs]</a>    <span class="k">def</span> <span class="nf">close</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Close the underlying and free resources.</span>
+
+<span class="sd">        The NetBIOS instance should not be used to perform any operations after this method returns.</span>
+
+<span class="sd">        :return: None</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">sock</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">sock</span> <span class="o">=</span> <span class="bp">None</span></div>
+
+    <span class="k">def</span> <span class="nf">write</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">ip</span><span class="p">,</span> <span class="n">port</span><span class="p">):</span>
+        <span class="k">assert</span> <span class="bp">self</span><span class="o">.</span><span class="n">sock</span><span class="p">,</span> <span class="s1">&#39;Socket is already closed&#39;</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">sock</span><span class="o">.</span><span class="n">sendto</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="p">(</span> <span class="n">ip</span><span class="p">,</span> <span class="n">port</span> <span class="p">))</span>
+
+<div class="viewcode-block" id="NetBIOS.queryName"><a class="viewcode-back" href="../../api/nmb_NetBIOS.html#nmb.NetBIOS.NetBIOS.queryName">[docs]</a>    <span class="k">def</span> <span class="nf">queryName</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">ip</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="n">port</span> <span class="o">=</span> <span class="mi">137</span><span class="p">,</span> <span class="n">timeout</span> <span class="o">=</span> <span class="mi">30</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Send a query on the network and hopes that if machine matching the *name* will reply with its IP address.</span>
+
+<span class="sd">        :param string ip: If the NBNSProtocol instance was instianted with broadcast=True, then this parameter can be an empty string. We will leave it to the OS to determine an appropriate broadcast address.</span>
+<span class="sd">                          If the NBNSProtocol instance was instianted with broadcast=False, then you should provide a target IP to send the query.</span>
+<span class="sd">        :param integer port: The NetBIOS-NS port (IANA standard defines this port to be 137). You should not touch this parameter unless you know what you are doing.</span>
+<span class="sd">        :param integer/float timeout: Number of seconds to wait for a reply, after which the method will return None</span>
+<span class="sd">        :return: A list of IP addresses in dotted notation (aaa.bbb.ccc.ddd). On timeout, returns None.</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="k">assert</span> <span class="bp">self</span><span class="o">.</span><span class="n">sock</span><span class="p">,</span> <span class="s1">&#39;Socket is already closed&#39;</span>
+
+        <span class="n">trn_id</span> <span class="o">=</span> <span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mh">0xFFFF</span><span class="p">)</span>
+        <span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">prepareNameQuery</span><span class="p">(</span><span class="n">trn_id</span><span class="p">,</span> <span class="n">name</span><span class="p">)</span>
+        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">broadcast</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">ip</span><span class="p">:</span>
+            <span class="n">ip</span> <span class="o">=</span> <span class="s1">&#39;&lt;broadcast&gt;&#39;</span>
+        <span class="k">elif</span> <span class="ow">not</span> <span class="n">ip</span><span class="p">:</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">log</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s1">&#39;queryName: ip parameter is empty. OS might not transmit this query to the network&#39;</span><span class="p">)</span>
+
+        <span class="bp">self</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">ip</span><span class="p">,</span> <span class="n">port</span><span class="p">)</span>
+
+        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_pollForNetBIOSPacket</span><span class="p">(</span><span class="n">trn_id</span><span class="p">,</span> <span class="n">timeout</span><span class="p">)</span></div>
+
+<div class="viewcode-block" id="NetBIOS.queryIPForName"><a class="viewcode-back" href="../../api/nmb_NetBIOS.html#nmb.NetBIOS.NetBIOS.queryIPForName">[docs]</a>    <span class="k">def</span> <span class="nf">queryIPForName</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ip</span><span class="p">,</span> <span class="n">port</span> <span class="o">=</span> <span class="mi">137</span><span class="p">,</span> <span class="n">timeout</span> <span class="o">=</span> <span class="mi">30</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Send a query to the machine with *ip* and hopes that the machine will reply back with its name.</span>
+
+<span class="sd">        The implementation of this function is contributed by Jason Anderson.</span>
+
+<span class="sd">        :param string ip: If the NBNSProtocol instance was instianted with broadcast=True, then this parameter can be an empty string. We will leave it to the OS to determine an appropriate broadcast address.</span>
+<span class="sd">                          If the NBNSProtocol instance was instianted with broadcast=False, then you should provide a target IP to send the query.</span>
+<span class="sd">        :param integer port: The NetBIOS-NS port (IANA standard defines this port to be 137). You should not touch this parameter unless you know what you are doing.</span>
+<span class="sd">        :param integer/float timeout: Number of seconds to wait for a reply, after which the method will return None</span>
+<span class="sd">        :return: A list of string containing the names of the machine at *ip*. On timeout, returns None.</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="k">assert</span> <span class="bp">self</span><span class="o">.</span><span class="n">sock</span><span class="p">,</span> <span class="s1">&#39;Socket is already closed&#39;</span>
+
+        <span class="n">trn_id</span> <span class="o">=</span> <span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mh">0xFFFF</span><span class="p">)</span>
+        <span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">prepareNetNameQuery</span><span class="p">(</span><span class="n">trn_id</span><span class="p">,</span> <span class="bp">False</span><span class="p">)</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">ip</span><span class="p">,</span> <span class="n">port</span><span class="p">)</span>
+        <span class="n">ret</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_pollForQueryPacket</span><span class="p">(</span><span class="n">trn_id</span><span class="p">,</span> <span class="n">timeout</span><span class="p">)</span>
+        <span class="k">if</span> <span class="n">ret</span><span class="p">:</span>
+            <span class="k">return</span> <span class="nb">map</span><span class="p">(</span><span class="k">lambda</span> <span class="n">s</span><span class="p">:</span> <span class="n">s</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="nb">filter</span><span class="p">(</span><span class="k">lambda</span> <span class="n">s</span><span class="p">:</span> <span class="n">s</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="n">TYPE_SERVER</span><span class="p">,</span> <span class="n">ret</span><span class="p">))</span>
+        <span class="k">else</span><span class="p">:</span>
+            <span class="k">return</span> <span class="bp">None</span></div>
+
+    <span class="c1">#</span>
+    <span class="c1"># Protected Methods</span>
+    <span class="c1">#</span>
+
+    <span class="k">def</span> <span class="nf">_pollForNetBIOSPacket</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">wait_trn_id</span><span class="p">,</span> <span class="n">timeout</span><span class="p">):</span>
+        <span class="n">end_time</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> <span class="o">+</span> <span class="n">timeout</span>
+        <span class="k">while</span> <span class="bp">True</span><span class="p">:</span>
+            <span class="k">try</span><span class="p">:</span>
+                <span class="n">_timeout</span> <span class="o">=</span> <span class="n">end_time</span> <span class="o">-</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
+                <span class="k">if</span> <span class="n">_timeout</span> <span class="o">&lt;=</span> <span class="mi">0</span><span class="p">:</span>
+                    <span class="k">return</span> <span class="bp">None</span>
+
+                <span class="n">ready</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">_</span> <span class="o">=</span> <span class="n">select</span><span class="o">.</span><span class="n">select</span><span class="p">([</span> <span class="bp">self</span><span class="o">.</span><span class="n">sock</span><span class="o">.</span><span class="n">fileno</span><span class="p">()</span> <span class="p">],</span> <span class="p">[</span> <span class="p">],</span> <span class="p">[</span> <span class="p">],</span> <span class="n">_timeout</span><span class="p">)</span>
+                <span class="k">if</span> <span class="ow">not</span> <span class="n">ready</span><span class="p">:</span>
+                    <span class="k">return</span> <span class="bp">None</span>
+
+                <span class="n">data</span><span class="p">,</span> <span class="n">_</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sock</span><span class="o">.</span><span class="n">recvfrom</span><span class="p">(</span><span class="mh">0xFFFF</span><span class="p">)</span>
+                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
+                    <span class="k">raise</span> <span class="n">NotConnectedError</span>
+
+                <span class="n">trn_id</span><span class="p">,</span> <span class="n">ret</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">decodePacket</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
+
+                <span class="k">if</span> <span class="n">trn_id</span> <span class="o">==</span> <span class="n">wait_trn_id</span><span class="p">:</span>
+                    <span class="k">return</span> <span class="n">ret</span>
+            <span class="k">except</span> <span class="n">select</span><span class="o">.</span><span class="n">error</span><span class="p">,</span> <span class="n">ex</span><span class="p">:</span>
+                <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">ex</span><span class="p">)</span> <span class="ow">is</span> <span class="n">types</span><span class="o">.</span><span class="n">TupleType</span><span class="p">:</span>
+                    <span class="k">if</span> <span class="n">ex</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">!=</span> <span class="n">errno</span><span class="o">.</span><span class="n">EINTR</span> <span class="ow">and</span> <span class="n">ex</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">!=</span> <span class="n">errno</span><span class="o">.</span><span class="n">EAGAIN</span><span class="p">:</span>
+                        <span class="k">raise</span> <span class="n">ex</span>
+                <span class="k">else</span><span class="p">:</span>
+                    <span class="k">raise</span> <span class="n">ex</span>
+
+    <span class="c1">#</span>
+    <span class="c1"># Contributed by Jason Anderson</span>
+    <span class="c1">#</span>
+    <span class="k">def</span> <span class="nf">_pollForQueryPacket</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">wait_trn_id</span><span class="p">,</span> <span class="n">timeout</span><span class="p">):</span>
+        <span class="n">end_time</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> <span class="o">+</span> <span class="n">timeout</span>
+        <span class="k">while</span> <span class="bp">True</span><span class="p">:</span>
+            <span class="k">try</span><span class="p">:</span>
+                <span class="n">_timeout</span> <span class="o">=</span> <span class="n">end_time</span> <span class="o">-</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
+                <span class="k">if</span> <span class="n">_timeout</span> <span class="o">&lt;=</span> <span class="mi">0</span><span class="p">:</span>
+                    <span class="k">return</span> <span class="bp">None</span>
+
+                <span class="n">ready</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">_</span> <span class="o">=</span> <span class="n">select</span><span class="o">.</span><span class="n">select</span><span class="p">([</span> <span class="bp">self</span><span class="o">.</span><span class="n">sock</span><span class="o">.</span><span class="n">fileno</span><span class="p">()</span> <span class="p">],</span> <span class="p">[</span> <span class="p">],</span> <span class="p">[</span> <span class="p">],</span> <span class="n">_timeout</span><span class="p">)</span>
+                <span class="k">if</span> <span class="ow">not</span> <span class="n">ready</span><span class="p">:</span>
+                    <span class="k">return</span> <span class="bp">None</span>
+
+                <span class="n">data</span><span class="p">,</span> <span class="n">_</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sock</span><span class="o">.</span><span class="n">recvfrom</span><span class="p">(</span><span class="mh">0xFFFF</span><span class="p">)</span>
+                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
+                    <span class="k">raise</span> <span class="n">NotConnectedError</span>
+
+                <span class="n">trn_id</span><span class="p">,</span> <span class="n">ret</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">decodeIPQueryPacket</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
+
+                <span class="k">if</span> <span class="n">trn_id</span> <span class="o">==</span> <span class="n">wait_trn_id</span><span class="p">:</span>
+                    <span class="k">return</span> <span class="n">ret</span>
+            <span class="k">except</span> <span class="n">select</span><span class="o">.</span><span class="n">error</span><span class="p">,</span> <span class="n">ex</span><span class="p">:</span>
+                <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">ex</span><span class="p">)</span> <span class="ow">is</span> <span class="n">types</span><span class="o">.</span><span class="n">TupleType</span><span class="p">:</span>
+                    <span class="k">if</span> <span class="n">ex</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">!=</span> <span class="n">errno</span><span class="o">.</span><span class="n">EINTR</span> <span class="ow">and</span> <span class="n">ex</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">!=</span> <span class="n">errno</span><span class="o">.</span><span class="n">EAGAIN</span><span class="p">:</span>
+                        <span class="k">raise</span> <span class="n">ex</span>
+                <span class="k">else</span><span class="p">:</span>
+                    <span class="k">raise</span> <span class="n">ex</span></div>
+</pre></div>
+
+          </div>
+        </div>
+      </div>
+      <div class="clearer"></div>
+    </div>
+    <div class="related" role="navigation" aria-label="related navigation">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="../../genindex.html" title="General Index"
+             >index</a></li>
+        <li class="right" >
+          <a href="../../py-modindex.html" title="Python Module Index"
+             >modules</a> |</li>
+        <li class="nav-item nav-item-0"><a href="../../index.html">pysmb 1.1.25 documentation</a> &raquo;</li>
+          <li class="nav-item nav-item-1"><a href="../index.html" >Module code</a> &raquo;</li> 
+      </ul>
+    </div>
+    <div class="footer" role="contentinfo">
+        &copy; Copyright 2001-2018, Michael Teo http://miketeo.net/.
+      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.6.
+    </div>
+  </body>
+</html>
\ No newline at end of file
diff --git a/docs/html/_modules/nmb/NetBIOSProtocol.html b/docs/html/_modules/nmb/NetBIOSProtocol.html
new file mode 100644
index 00000000..05991f52
--- /dev/null
+++ b/docs/html/_modules/nmb/NetBIOSProtocol.html
@@ -0,0 +1,228 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    
+    <title>nmb.NetBIOSProtocol &mdash; pysmb 1.1.25 documentation</title>
+    
+    <link rel="stylesheet" href="../../_static/sphinxdoc.css" type="text/css" />
+    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
+    
+    <script type="text/javascript">
+      var DOCUMENTATION_OPTIONS = {
+        URL_ROOT:    '../../',
+        VERSION:     '1.1.25',
+        COLLAPSE_INDEX: false,
+        FILE_SUFFIX: '.html',
+        HAS_SOURCE:  true
+      };
+    </script>
+    <script type="text/javascript" src="../../_static/jquery.js"></script>
+    <script type="text/javascript" src="../../_static/underscore.js"></script>
+    <script type="text/javascript" src="../../_static/doctools.js"></script>
+    <link rel="top" title="pysmb 1.1.25 documentation" href="../../index.html" />
+    <link rel="up" title="Module code" href="../index.html" /> 
+  </head>
+  <body role="document">
+    <div class="related" role="navigation" aria-label="related navigation">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="../../genindex.html" title="General Index"
+             accesskey="I">index</a></li>
+        <li class="right" >
+          <a href="../../py-modindex.html" title="Python Module Index"
+             >modules</a> |</li>
+        <li class="nav-item nav-item-0"><a href="../../index.html">pysmb 1.1.25 documentation</a> &raquo;</li>
+          <li class="nav-item nav-item-1"><a href="../index.html" accesskey="U">Module code</a> &raquo;</li> 
+      </ul>
+    </div>
+      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
+        <div class="sphinxsidebarwrapper">
+<div id="searchbox" style="display: none" role="search">
+  <h3>Quick search</h3>
+    <form class="search" action="../../search.html" method="get">
+      <input type="text" name="q" />
+      <input type="submit" value="Go" />
+      <input type="hidden" name="check_keywords" value="yes" />
+      <input type="hidden" name="area" value="default" />
+    </form>
+    <p class="searchtip" style="font-size: 90%">
+    Enter search terms or a module, class or function name.
+    </p>
+</div>
+<script type="text/javascript">$('#searchbox').show(0);</script>
+        </div>
+      </div>
+
+    <div class="document">
+      <div class="documentwrapper">
+        <div class="bodywrapper">
+          <div class="body" role="main">
+            
+  <h1>Source code for nmb.NetBIOSProtocol</h1><div class="highlight"><pre>
+
+<span class="kn">import</span> <span class="nn">os</span><span class="o">,</span> <span class="nn">logging</span><span class="o">,</span> <span class="nn">random</span><span class="o">,</span> <span class="nn">socket</span><span class="o">,</span> <span class="nn">time</span>
+<span class="kn">from</span> <span class="nn">twisted.internet</span> <span class="kn">import</span> <span class="n">reactor</span><span class="p">,</span> <span class="n">defer</span>
+<span class="kn">from</span> <span class="nn">twisted.internet.protocol</span> <span class="kn">import</span> <span class="n">DatagramProtocol</span>
+<span class="kn">from</span> <span class="nn">nmb_constants</span> <span class="kn">import</span> <span class="n">TYPE_SERVER</span>
+<span class="kn">from</span> <span class="nn">base</span> <span class="kn">import</span> <span class="n">NBNS</span>
+
+<span class="n">IP_QUERY</span><span class="p">,</span> <span class="n">NAME_QUERY</span> <span class="o">=</span> <span class="nb">range</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
+
+<div class="viewcode-block" id="NetBIOSTimeout"><a class="viewcode-back" href="../../api/nmb_NBNSProtocol.html#nmb.NetBIOSProtocol.NetBIOSTimeout">[docs]</a><span class="k">class</span> <span class="nc">NetBIOSTimeout</span><span class="p">(</span><span class="ne">Exception</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;Raised in NBNSProtocol via Deferred.errback method when queryName method has timeout waiting for reply&quot;&quot;&quot;</span>
+    <span class="k">pass</span></div>
+
+<div class="viewcode-block" id="NBNSProtocol"><a class="viewcode-back" href="../../api/nmb_NBNSProtocol.html#nmb.NetBIOSProtocol.NBNSProtocol">[docs]</a><span class="k">class</span> <span class="nc">NBNSProtocol</span><span class="p">(</span><span class="n">DatagramProtocol</span><span class="p">,</span> <span class="n">NBNS</span><span class="p">):</span>
+
+    <span class="n">log</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="s1">&#39;NMB.NBNSProtocol&#39;</span><span class="p">)</span>
+
+<div class="viewcode-block" id="NBNSProtocol.__init__"><a class="viewcode-back" href="../../api/nmb_NBNSProtocol.html#nmb.NetBIOSProtocol.NBNSProtocol.__init__">[docs]</a>    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">broadcast</span> <span class="o">=</span> <span class="bp">True</span><span class="p">,</span> <span class="n">listen_port</span> <span class="o">=</span> <span class="mi">0</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Instantiate a NBNSProtocol instance.</span>
+
+<span class="sd">        This automatically calls reactor.listenUDP method to start listening for incoming packets, so you **must not** call the listenUDP method again.</span>
+
+<span class="sd">        :param boolean broadcast: A boolean flag to indicate if we should setup the listening UDP port in broadcast mode</span>
+<span class="sd">        :param integer listen_port: Specifies the UDP port number to bind to for listening. If zero, OS will automatically select a free port number.</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">broadcast</span> <span class="o">=</span> <span class="n">broadcast</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">pending_trns</span> <span class="o">=</span> <span class="p">{</span> <span class="p">}</span>  <span class="c1"># TRN ID -&gt; ( expiry_time, name, Deferred instance )</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">transport</span> <span class="o">=</span> <span class="n">reactor</span><span class="o">.</span><span class="n">listenUDP</span><span class="p">(</span><span class="n">listen_port</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span>
+        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">broadcast</span><span class="p">:</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">transport</span><span class="o">.</span><span class="n">getHandle</span><span class="p">()</span><span class="o">.</span><span class="n">setsockopt</span><span class="p">(</span><span class="n">socket</span><span class="o">.</span><span class="n">SOL_SOCKET</span><span class="p">,</span> <span class="n">socket</span><span class="o">.</span><span class="n">SO_BROADCAST</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
+        <span class="n">reactor</span><span class="o">.</span><span class="n">callLater</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">cleanupPendingTrns</span><span class="p">)</span></div>
+
+    <span class="k">def</span> <span class="nf">datagramReceived</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">from_info</span><span class="p">):</span>
+        <span class="n">host</span><span class="p">,</span> <span class="n">port</span> <span class="o">=</span> <span class="n">from_info</span>
+        <span class="n">trn_id</span><span class="p">,</span> <span class="n">ret</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">decodePacket</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
+
+        <span class="c1"># pending transaction exists for trn_id - handle it and remove from queue</span>
+        <span class="k">if</span> <span class="n">trn_id</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">pending_trns</span><span class="p">:</span>
+            <span class="n">_</span><span class="p">,</span> <span class="n">ip</span><span class="p">,</span> <span class="n">d</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">pending_trns</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="n">trn_id</span><span class="p">)</span>
+            <span class="k">if</span> <span class="n">ip</span> <span class="ow">is</span> <span class="n">NAME_QUERY</span><span class="p">:</span>
+                <span class="c1"># decode as query packet</span>
+                <span class="n">trn_id</span><span class="p">,</span> <span class="n">ret</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">decodeIPQueryPacket</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
+            <span class="n">d</span><span class="o">.</span><span class="n">callback</span><span class="p">(</span><span class="n">ret</span><span class="p">)</span>
+
+    <span class="k">def</span> <span class="nf">write</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">ip</span><span class="p">,</span> <span class="n">port</span><span class="p">):</span>
+        <span class="c1"># We don&#39;t use the transport.write method directly as it keeps raising DeprecationWarning for ip=&#39;&lt;broadcast&gt;&#39;</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">transport</span><span class="o">.</span><span class="n">getHandle</span><span class="p">()</span><span class="o">.</span><span class="n">sendto</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="p">(</span> <span class="n">ip</span><span class="p">,</span> <span class="n">port</span> <span class="p">))</span>
+
+<div class="viewcode-block" id="NBNSProtocol.queryName"><a class="viewcode-back" href="../../api/nmb_NBNSProtocol.html#nmb.NetBIOSProtocol.NBNSProtocol.queryName">[docs]</a>    <span class="k">def</span> <span class="nf">queryName</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">ip</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="n">port</span> <span class="o">=</span> <span class="mi">137</span><span class="p">,</span> <span class="n">timeout</span> <span class="o">=</span> <span class="mi">30</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Send a query on the network and hopes that if machine matching the *name* will reply with its IP address.</span>
+
+<span class="sd">        :param string ip: If the NBNSProtocol instance was instianted with broadcast=True, then this parameter can be an empty string. We will leave it to the OS to determine an appropriate broadcast address.</span>
+<span class="sd">                          If the NBNSProtocol instance was instianted with broadcast=False, then you should provide a target IP to send the query.</span>
+<span class="sd">        :param integer port: The NetBIOS-NS port (IANA standard defines this port to be 137). You should not touch this parameter unless you know what you are doing.</span>
+<span class="sd">        :param integer/float timeout: Number of seconds to wait for a reply, after which the returned Deferred instance will be called with a NetBIOSTimeout exception.</span>
+<span class="sd">        :return: A *twisted.internet.defer.Deferred* instance. The callback function will be called with a list of IP addresses in dotted notation (aaa.bbb.ccc.ddd).</span>
+<span class="sd">                 On timeout, the errback function will be called with a Failure instance wrapping around a NetBIOSTimeout exception</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="n">trn_id</span> <span class="o">=</span> <span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mh">0xFFFF</span><span class="p">)</span>
+        <span class="k">while</span> <span class="bp">True</span><span class="p">:</span>
+            <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">pending_trns</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="n">trn_id</span><span class="p">):</span>
+                <span class="k">break</span>
+            <span class="k">else</span><span class="p">:</span>
+                <span class="n">trn_id</span> <span class="o">=</span> <span class="p">(</span><span class="n">trn_id</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">&amp;</span> <span class="mh">0xFFFF</span>
+
+        <span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">prepareNameQuery</span><span class="p">(</span><span class="n">trn_id</span><span class="p">,</span> <span class="n">name</span><span class="p">)</span>
+        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">broadcast</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">ip</span><span class="p">:</span>
+            <span class="n">ip</span> <span class="o">=</span> <span class="s1">&#39;&lt;broadcast&gt;&#39;</span>
+        <span class="k">elif</span> <span class="ow">not</span> <span class="n">ip</span><span class="p">:</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">log</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s1">&#39;queryName: ip parameter is empty. OS might not transmit this query to the network&#39;</span><span class="p">)</span>
+
+        <span class="bp">self</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">ip</span><span class="p">,</span> <span class="n">port</span><span class="p">)</span>
+
+        <span class="n">d</span> <span class="o">=</span> <span class="n">defer</span><span class="o">.</span><span class="n">Deferred</span><span class="p">()</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">pending_trns</span><span class="p">[</span><span class="n">trn_id</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span><span class="o">+</span><span class="n">timeout</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">d</span> <span class="p">)</span>
+        <span class="k">return</span> <span class="n">d</span></div>
+
+<div class="viewcode-block" id="NBNSProtocol.queryIPForName"><a class="viewcode-back" href="../../api/nmb_NBNSProtocol.html#nmb.NetBIOSProtocol.NBNSProtocol.queryIPForName">[docs]</a>    <span class="k">def</span> <span class="nf">queryIPForName</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ip</span><span class="p">,</span> <span class="n">port</span> <span class="o">=</span> <span class="mi">137</span><span class="p">,</span> <span class="n">timeout</span> <span class="o">=</span> <span class="mi">30</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Send a query to the machine with *ip* and hopes that the machine will reply back with its name.</span>
+
+<span class="sd">        The implementation of this function is contributed by Jason Anderson.</span>
+
+<span class="sd">        :param string ip: If the NBNSProtocol instance was instianted with broadcast=True, then this parameter can be an empty string. We will leave it to the OS to determine an appropriate broadcast address.</span>
+<span class="sd">                          If the NBNSProtocol instance was instianted with broadcast=False, then you should provide a target IP to send the query.</span>
+<span class="sd">        :param integer port: The NetBIOS-NS port (IANA standard defines this port to be 137). You should not touch this parameter unless you know what you are doing.</span>
+<span class="sd">        :param integer/float timeout: Number of seconds to wait for a reply, after which the method will return None</span>
+<span class="sd">        :return: A *twisted.internet.defer.Deferred* instance. The callback function will be called with a list of names of the machine at *ip*.</span>
+<span class="sd">                 On timeout, the errback function will be called with a Failure instance wrapping around a NetBIOSTimeout exception</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="n">trn_id</span> <span class="o">=</span> <span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mh">0xFFFF</span><span class="p">)</span>
+        <span class="k">while</span> <span class="bp">True</span><span class="p">:</span>
+            <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">pending_trns</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="n">trn_id</span><span class="p">):</span>
+                <span class="k">break</span>
+            <span class="k">else</span><span class="p">:</span>
+                <span class="n">trn_id</span> <span class="o">=</span> <span class="p">(</span><span class="n">trn_id</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">&amp;</span> <span class="mh">0xFFFF</span>
+
+        <span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">prepareNetNameQuery</span><span class="p">(</span><span class="n">trn_id</span><span class="p">)</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">ip</span><span class="p">,</span> <span class="n">port</span><span class="p">)</span>
+
+        <span class="n">d</span> <span class="o">=</span> <span class="n">defer</span><span class="o">.</span><span class="n">Deferred</span><span class="p">()</span>
+        <span class="n">d2</span> <span class="o">=</span> <span class="n">defer</span><span class="o">.</span><span class="n">Deferred</span><span class="p">()</span>
+        <span class="n">d2</span><span class="o">.</span><span class="n">addErrback</span><span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">errback</span><span class="p">)</span>
+
+        <span class="k">def</span> <span class="nf">stripCode</span><span class="p">(</span><span class="n">ret</span><span class="p">):</span>
+            <span class="k">if</span> <span class="n">ret</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span> <span class="c1"># got valid response. Somehow the callback is also called when there is an error.</span>
+                <span class="n">d</span><span class="o">.</span><span class="n">callback</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span><span class="k">lambda</span> <span class="n">s</span><span class="p">:</span> <span class="n">s</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="nb">filter</span><span class="p">(</span><span class="k">lambda</span> <span class="n">s</span><span class="p">:</span> <span class="n">s</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="n">TYPE_SERVER</span><span class="p">,</span> <span class="n">ret</span><span class="p">)))</span>
+
+        <span class="n">d2</span><span class="o">.</span><span class="n">addCallback</span><span class="p">(</span><span class="n">stripCode</span><span class="p">)</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">pending_trns</span><span class="p">[</span><span class="n">trn_id</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span><span class="o">+</span><span class="n">timeout</span><span class="p">,</span> <span class="n">NAME_QUERY</span><span class="p">,</span> <span class="n">d2</span> <span class="p">)</span>
+        <span class="k">return</span> <span class="n">d</span></div>
+
+    <span class="k">def</span> <span class="nf">stopProtocol</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="n">DatagramProtocol</span><span class="o">.</span><span class="n">stopProtocol</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
+
+    <span class="k">def</span> <span class="nf">cleanupPendingTrns</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="n">now</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
+
+        <span class="c1"># reply should have been received in the past</span>
+        <span class="n">expired</span> <span class="o">=</span> <span class="nb">filter</span><span class="p">(</span><span class="k">lambda</span> <span class="p">(</span><span class="n">trn_id</span><span class="p">,</span> <span class="p">(</span><span class="n">expiry_time</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">d</span><span class="p">)):</span> <span class="n">expiry_time</span> <span class="o">&lt;</span> <span class="n">now</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">pending_trns</span><span class="o">.</span><span class="n">iteritems</span><span class="p">())</span>
+
+        <span class="c1"># remove expired items from dict + call errback</span>
+        <span class="k">def</span> <span class="nf">expire_item</span><span class="p">(</span><span class="n">item</span><span class="p">):</span>
+            <span class="n">trn_id</span><span class="p">,</span> <span class="p">(</span><span class="n">expiry_time</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">d</span><span class="p">)</span> <span class="o">=</span> <span class="n">item</span>
+
+            <span class="k">del</span> <span class="bp">self</span><span class="o">.</span><span class="n">pending_trns</span><span class="p">[</span><span class="n">trn_id</span><span class="p">]</span>
+            <span class="k">try</span><span class="p">:</span>
+                <span class="n">d</span><span class="o">.</span><span class="n">errback</span><span class="p">(</span><span class="n">NetBIOSTimeout</span><span class="p">(</span><span class="n">name</span><span class="p">))</span>
+            <span class="k">except</span><span class="p">:</span> <span class="k">pass</span>
+
+        <span class="nb">map</span><span class="p">(</span><span class="n">expire_item</span><span class="p">,</span> <span class="n">expired</span><span class="p">)</span>
+
+        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">transport</span><span class="p">:</span>
+            <span class="n">reactor</span><span class="o">.</span><span class="n">callLater</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">cleanupPendingTrns</span><span class="p">)</span></div>
+</pre></div>
+
+          </div>
+        </div>
+      </div>
+      <div class="clearer"></div>
+    </div>
+    <div class="related" role="navigation" aria-label="related navigation">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="../../genindex.html" title="General Index"
+             >index</a></li>
+        <li class="right" >
+          <a href="../../py-modindex.html" title="Python Module Index"
+             >modules</a> |</li>
+        <li class="nav-item nav-item-0"><a href="../../index.html">pysmb 1.1.25 documentation</a> &raquo;</li>
+          <li class="nav-item nav-item-1"><a href="../index.html" >Module code</a> &raquo;</li> 
+      </ul>
+    </div>
+    <div class="footer" role="contentinfo">
+        &copy; Copyright 2001-2018, Michael Teo http://miketeo.net/.
+      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.6.
+    </div>
+  </body>
+</html>
\ No newline at end of file
diff --git a/docs/html/_modules/smb/security_descriptors.html b/docs/html/_modules/smb/security_descriptors.html
new file mode 100644
index 00000000..cbd41f32
--- /dev/null
+++ b/docs/html/_modules/smb/security_descriptors.html
@@ -0,0 +1,459 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    
+    <title>smb.security_descriptors &mdash; pysmb 1.1.25 documentation</title>
+    
+    <link rel="stylesheet" href="../../_static/sphinxdoc.css" type="text/css" />
+    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
+    
+    <script type="text/javascript">
+      var DOCUMENTATION_OPTIONS = {
+        URL_ROOT:    '../../',
+        VERSION:     '1.1.25',
+        COLLAPSE_INDEX: false,
+        FILE_SUFFIX: '.html',
+        HAS_SOURCE:  true
+      };
+    </script>
+    <script type="text/javascript" src="../../_static/jquery.js"></script>
+    <script type="text/javascript" src="../../_static/underscore.js"></script>
+    <script type="text/javascript" src="../../_static/doctools.js"></script>
+    <link rel="top" title="pysmb 1.1.25 documentation" href="../../index.html" />
+    <link rel="up" title="Module code" href="../index.html" /> 
+  </head>
+  <body role="document">
+    <div class="related" role="navigation" aria-label="related navigation">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="../../genindex.html" title="General Index"
+             accesskey="I">index</a></li>
+        <li class="right" >
+          <a href="../../py-modindex.html" title="Python Module Index"
+             >modules</a> |</li>
+        <li class="nav-item nav-item-0"><a href="../../index.html">pysmb 1.1.25 documentation</a> &raquo;</li>
+          <li class="nav-item nav-item-1"><a href="../index.html" accesskey="U">Module code</a> &raquo;</li> 
+      </ul>
+    </div>
+      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
+        <div class="sphinxsidebarwrapper">
+<div id="searchbox" style="display: none" role="search">
+  <h3>Quick search</h3>
+    <form class="search" action="../../search.html" method="get">
+      <input type="text" name="q" />
+      <input type="submit" value="Go" />
+      <input type="hidden" name="check_keywords" value="yes" />
+      <input type="hidden" name="area" value="default" />
+    </form>
+    <p class="searchtip" style="font-size: 90%">
+    Enter search terms or a module, class or function name.
+    </p>
+</div>
+<script type="text/javascript">$('#searchbox').show(0);</script>
+        </div>
+      </div>
+
+    <div class="document">
+      <div class="documentwrapper">
+        <div class="bodywrapper">
+          <div class="body" role="main">
+            
+  <h1>Source code for smb.security_descriptors</h1><div class="highlight"><pre>
+<span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">This module implements security descriptors, and the partial structures</span>
+<span class="sd">used in them, as specified in [MS-DTYP].</span>
+<span class="sd">&quot;&quot;&quot;</span>
+
+<span class="kn">import</span> <span class="nn">struct</span>
+
+
+<span class="c1"># Security descriptor control flags</span>
+<span class="c1"># [MS-DTYP]: 2.4.6</span>
+<span class="n">SECURITY_DESCRIPTOR_OWNER_DEFAULTED</span> <span class="o">=</span> <span class="mh">0x0001</span>
+<span class="n">SECURITY_DESCRIPTOR_GROUP_DEFAULTED</span> <span class="o">=</span> <span class="mh">0x0002</span>
+<span class="n">SECURITY_DESCRIPTOR_DACL_PRESENT</span> <span class="o">=</span> <span class="mh">0x0004</span>
+<span class="n">SECURITY_DESCRIPTOR_DACL_DEFAULTED</span> <span class="o">=</span> <span class="mh">0x0008</span>
+<span class="n">SECURITY_DESCRIPTOR_SACL_PRESENT</span> <span class="o">=</span> <span class="mh">0x0010</span>
+<span class="n">SECURITY_DESCRIPTOR_SACL_DEFAULTED</span> <span class="o">=</span> <span class="mh">0x0020</span>
+<span class="n">SECURITY_DESCRIPTOR_SERVER_SECURITY</span> <span class="o">=</span> <span class="mh">0x0040</span>
+<span class="n">SECURITY_DESCRIPTOR_DACL_TRUSTED</span> <span class="o">=</span> <span class="mh">0x0080</span>
+<span class="n">SECURITY_DESCRIPTOR_DACL_COMPUTED_INHERITANCE_REQUIRED</span> <span class="o">=</span> <span class="mh">0x0100</span>
+<span class="n">SECURITY_DESCRIPTOR_SACL_COMPUTED_INHERITANCE_REQUIRED</span> <span class="o">=</span> <span class="mh">0x0200</span>
+<span class="n">SECURITY_DESCRIPTOR_DACL_AUTO_INHERITED</span> <span class="o">=</span> <span class="mh">0x0400</span>
+<span class="n">SECURITY_DESCRIPTOR_SACL_AUTO_INHERITED</span> <span class="o">=</span> <span class="mh">0x0800</span>
+<span class="n">SECURITY_DESCRIPTOR_DACL_PROTECTED</span> <span class="o">=</span> <span class="mh">0x1000</span>
+<span class="n">SECURITY_DESCRIPTOR_SACL_PROTECTED</span> <span class="o">=</span> <span class="mh">0x2000</span>
+<span class="n">SECURITY_DESCRIPTOR_RM_CONTROL_VALID</span> <span class="o">=</span> <span class="mh">0x4000</span>
+<span class="n">SECURITY_DESCRIPTOR_SELF_RELATIVE</span> <span class="o">=</span> <span class="mh">0x8000</span>
+
+<span class="c1"># ACE types</span>
+<span class="c1"># [MS-DTYP]: 2.4.4.1</span>
+<span class="n">ACE_TYPE_ACCESS_ALLOWED</span> <span class="o">=</span> <span class="mh">0x00</span>
+<span class="n">ACE_TYPE_ACCESS_DENIED</span> <span class="o">=</span> <span class="mh">0x01</span>
+<span class="n">ACE_TYPE_SYSTEM_AUDIT</span> <span class="o">=</span> <span class="mh">0x02</span>
+<span class="n">ACE_TYPE_SYSTEM_ALARM</span> <span class="o">=</span> <span class="mh">0x03</span>
+<span class="n">ACE_TYPE_ACCESS_ALLOWED_COMPOUND</span> <span class="o">=</span> <span class="mh">0x04</span>
+<span class="n">ACE_TYPE_ACCESS_ALLOWED_OBJECT</span> <span class="o">=</span> <span class="mh">0x05</span>
+<span class="n">ACE_TYPE_ACCESS_DENIED_OBJECT</span> <span class="o">=</span> <span class="mh">0x06</span>
+<span class="n">ACE_TYPE_SYSTEM_AUDIT_OBJECT</span> <span class="o">=</span> <span class="mh">0x07</span>
+<span class="n">ACE_TYPE_SYSTEM_ALARM_OBJECT</span> <span class="o">=</span> <span class="mh">0x08</span>
+<span class="n">ACE_TYPE_ACCESS_ALLOWED_CALLBACK</span> <span class="o">=</span> <span class="mh">0x09</span>
+<span class="n">ACE_TYPE_ACCESS_DENIED_CALLBACK</span> <span class="o">=</span> <span class="mh">0x0A</span>
+<span class="n">ACE_TYPE_ACCESS_ALLOWED_CALLBACK_OBJECT</span> <span class="o">=</span> <span class="mh">0x0B</span>
+<span class="n">ACE_TYPE_ACCESS_DENIED_CALLBACK_OBJECT</span> <span class="o">=</span> <span class="mh">0x0C</span>
+<span class="n">ACE_TYPE_SYSTEM_AUDIT_CALLBACK</span> <span class="o">=</span> <span class="mh">0x0D</span>
+<span class="n">ACE_TYPE_SYSTEM_ALARM_CALLBACK</span> <span class="o">=</span> <span class="mh">0x0E</span>
+<span class="n">ACE_TYPE_SYSTEM_AUDIT_CALLBACK_OBJECT</span> <span class="o">=</span> <span class="mh">0x0F</span>
+<span class="n">ACE_TYPE_SYSTEM_ALARM_CALLBACK_OBJECT</span> <span class="o">=</span> <span class="mh">0x10</span>
+<span class="n">ACE_TYPE_SYSTEM_MANDATORY_LABEL</span> <span class="o">=</span> <span class="mh">0x11</span>
+<span class="n">ACE_TYPE_SYSTEM_RESOURCE_ATTRIBUTE</span> <span class="o">=</span> <span class="mh">0x12</span>
+<span class="n">ACE_TYPE_SYSTEM_SCOPED_POLICY_ID</span> <span class="o">=</span> <span class="mh">0x13</span>
+
+<span class="c1"># ACE flags</span>
+<span class="c1"># [MS-DTYP]: 2.4.4.1</span>
+<span class="n">ACE_FLAG_OBJECT_INHERIT</span> <span class="o">=</span> <span class="mh">0x01</span>
+<span class="n">ACE_FLAG_CONTAINER_INHERIT</span> <span class="o">=</span> <span class="mh">0x02</span>
+<span class="n">ACE_FLAG_NO_PROPAGATE_INHERIT</span> <span class="o">=</span> <span class="mh">0x04</span>
+<span class="n">ACE_FLAG_INHERIT_ONLY</span> <span class="o">=</span> <span class="mh">0x08</span>
+<span class="n">ACE_FLAG_INHERITED</span> <span class="o">=</span> <span class="mh">0x10</span>
+<span class="n">ACE_FLAG_SUCCESSFUL_ACCESS</span> <span class="o">=</span> <span class="mh">0x40</span>
+<span class="n">ACE_FLAG_FAILED_ACCESS</span> <span class="o">=</span> <span class="mh">0x80</span>
+
+<span class="c1"># Pre-defined well-known SIDs</span>
+<span class="c1"># [MS-DTYP]: 2.4.2.4</span>
+<span class="n">SID_NULL</span> <span class="o">=</span> <span class="s2">&quot;S-1-0-0&quot;</span>
+<span class="n">SID_EVERYONE</span> <span class="o">=</span> <span class="s2">&quot;S-1-1-0&quot;</span>
+<span class="n">SID_LOCAL</span> <span class="o">=</span> <span class="s2">&quot;S-1-2-0&quot;</span>
+<span class="n">SID_CONSOLE_LOGON</span> <span class="o">=</span> <span class="s2">&quot;S-1-2-1&quot;</span>
+<span class="n">SID_CREATOR_OWNER</span> <span class="o">=</span> <span class="s2">&quot;S-1-3-0&quot;</span>
+<span class="n">SID_CREATOR_GROUP</span> <span class="o">=</span> <span class="s2">&quot;S-1-3-1&quot;</span>
+<span class="n">SID_OWNER_SERVER</span> <span class="o">=</span> <span class="s2">&quot;S-1-3-2&quot;</span>
+<span class="n">SID_GROUP_SERVER</span> <span class="o">=</span> <span class="s2">&quot;S-1-3-3&quot;</span>
+<span class="n">SID_OWNER_RIGHTS</span> <span class="o">=</span> <span class="s2">&quot;S-1-3-4&quot;</span>
+<span class="n">SID_NT_AUTHORITY</span> <span class="o">=</span> <span class="s2">&quot;S-1-5&quot;</span>
+<span class="n">SID_DIALUP</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-1&quot;</span>
+<span class="n">SID_NETWORK</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-2&quot;</span>
+<span class="n">SID_BATCH</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-3&quot;</span>
+<span class="n">SID_INTERACTIVE</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-4&quot;</span>
+<span class="n">SID_SERVICE</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-6&quot;</span>
+<span class="n">SID_ANONYMOUS</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-7&quot;</span>
+<span class="n">SID_PROXY</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-8&quot;</span>
+<span class="n">SID_ENTERPRISE_DOMAIN_CONTROLLERS</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-9&quot;</span>
+<span class="n">SID_PRINCIPAL_SELF</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-10&quot;</span>
+<span class="n">SID_AUTHENTICATED_USERS</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-11&quot;</span>
+<span class="n">SID_RESTRICTED_CODE</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-12&quot;</span>
+<span class="n">SID_TERMINAL_SERVER_USER</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-13&quot;</span>
+<span class="n">SID_REMOTE_INTERACTIVE_LOGON</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-14&quot;</span>
+<span class="n">SID_THIS_ORGANIZATION</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-15&quot;</span>
+<span class="n">SID_IUSR</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-17&quot;</span>
+<span class="n">SID_LOCAL_SYSTEM</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-18&quot;</span>
+<span class="n">SID_LOCAL_SERVICE</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-19&quot;</span>
+<span class="n">SID_NETWORK_SERVICE</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-20&quot;</span>
+<span class="n">SID_COMPOUNDED_AUTHENTICATION</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-21-0-0-0-496&quot;</span>
+<span class="n">SID_CLAIMS_VALID</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-21-0-0-0-497&quot;</span>
+<span class="n">SID_BUILTIN_ADMINISTRATORS</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-32-544&quot;</span>
+<span class="n">SID_BUILTIN_USERS</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-32-545&quot;</span>
+<span class="n">SID_BUILTIN_GUESTS</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-32-546&quot;</span>
+<span class="n">SID_POWER_USERS</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-32-547&quot;</span>
+<span class="n">SID_ACCOUNT_OPERATORS</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-32-548&quot;</span>
+<span class="n">SID_SERVER_OPERATORS</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-32-549&quot;</span>
+<span class="n">SID_PRINTER_OPERATORS</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-32-550&quot;</span>
+<span class="n">SID_BACKUP_OPERATORS</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-32-551&quot;</span>
+<span class="n">SID_REPLICATOR</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-32-552&quot;</span>
+<span class="n">SID_ALIAS_PREW2KCOMPACC</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-32-554&quot;</span>
+<span class="n">SID_REMOTE_DESKTOP</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-32-555&quot;</span>
+<span class="n">SID_NETWORK_CONFIGURATION_OPS</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-32-556&quot;</span>
+<span class="n">SID_INCOMING_FOREST_TRUST_BUILDERS</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-32-557&quot;</span>
+<span class="n">SID_PERFMON_USERS</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-32-558&quot;</span>
+<span class="n">SID_PERFLOG_USERS</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-32-559&quot;</span>
+<span class="n">SID_WINDOWS_AUTHORIZATION_ACCESS_GROUP</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-32-560&quot;</span>
+<span class="n">SID_TERMINAL_SERVER_LICENSE_SERVERS</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-32-561&quot;</span>
+<span class="n">SID_DISTRIBUTED_COM_USERS</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-32-562&quot;</span>
+<span class="n">SID_IIS_IUSRS</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-32-568&quot;</span>
+<span class="n">SID_CRYPTOGRAPHIC_OPERATORS</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-32-569&quot;</span>
+<span class="n">SID_EVENT_LOG_READERS</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-32-573&quot;</span>
+<span class="n">SID_CERTIFICATE_SERVICE_DCOM_ACCESS</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-32-574&quot;</span>
+<span class="n">SID_RDS_REMOTE_ACCESS_SERVERS</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-32-575&quot;</span>
+<span class="n">SID_RDS_ENDPOINT_SERVERS</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-32-576&quot;</span>
+<span class="n">SID_RDS_MANAGEMENT_SERVERS</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-32-577&quot;</span>
+<span class="n">SID_HYPER_V_ADMINS</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-32-578&quot;</span>
+<span class="n">SID_ACCESS_CONTROL_ASSISTANCE_OPS</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-32-579&quot;</span>
+<span class="n">SID_REMOTE_MANAGEMENT_USERS</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-32-580&quot;</span>
+<span class="n">SID_WRITE_RESTRICTED_CODE</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-33&quot;</span>
+<span class="n">SID_NTLM_AUTHENTICATION</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-64-10&quot;</span>
+<span class="n">SID_SCHANNEL_AUTHENTICATION</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-64-14&quot;</span>
+<span class="n">SID_DIGEST_AUTHENTICATION</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-64-21&quot;</span>
+<span class="n">SID_THIS_ORGANIZATION_CERTIFICATE</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-65-1&quot;</span>
+<span class="n">SID_NT_SERVICE</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-80&quot;</span>
+<span class="n">SID_USER_MODE_DRIVERS</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-84-0-0-0-0-0&quot;</span>
+<span class="n">SID_LOCAL_ACCOUNT</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-113&quot;</span>
+<span class="n">SID_LOCAL_ACCOUNT_AND_MEMBER_OF_ADMINISTRATORS_GROUP</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-114&quot;</span>
+<span class="n">SID_OTHER_ORGANIZATION</span> <span class="o">=</span> <span class="s2">&quot;S-1-5-1000&quot;</span>
+<span class="n">SID_ALL_APP_PACKAGES</span> <span class="o">=</span> <span class="s2">&quot;S-1-15-2-1&quot;</span>
+<span class="n">SID_ML_UNTRUSTED</span> <span class="o">=</span> <span class="s2">&quot;S-1-16-0&quot;</span>
+<span class="n">SID_ML_LOW</span> <span class="o">=</span> <span class="s2">&quot;S-1-16-4096&quot;</span>
+<span class="n">SID_ML_MEDIUM</span> <span class="o">=</span> <span class="s2">&quot;S-1-16-8192&quot;</span>
+<span class="n">SID_ML_MEDIUM_PLUS</span> <span class="o">=</span> <span class="s2">&quot;S-1-16-8448&quot;</span>
+<span class="n">SID_ML_HIGH</span> <span class="o">=</span> <span class="s2">&quot;S-1-16-12288&quot;</span>
+<span class="n">SID_ML_SYSTEM</span> <span class="o">=</span> <span class="s2">&quot;S-1-16-16384&quot;</span>
+<span class="n">SID_ML_PROTECTED_PROCESS</span> <span class="o">=</span> <span class="s2">&quot;S-1-16-20480&quot;</span>
+<span class="n">SID_AUTHENTICATION_AUTHORITY_ASSERTED_IDENTITY</span> <span class="o">=</span> <span class="s2">&quot;S-1-18-1&quot;</span>
+<span class="n">SID_SERVICE_ASSERTED_IDENTITY</span> <span class="o">=</span> <span class="s2">&quot;S-1-18-2&quot;</span>
+<span class="n">SID_FRESH_PUBLIC_KEY_IDENTITY</span> <span class="o">=</span> <span class="s2">&quot;S-1-18-3&quot;</span>
+<span class="n">SID_KEY_TRUST_IDENTITY</span> <span class="o">=</span> <span class="s2">&quot;S-1-18-4&quot;</span>
+<span class="n">SID_KEY_PROPERTY_MFA</span> <span class="o">=</span> <span class="s2">&quot;S-1-18-5&quot;</span>
+<span class="n">SID_KEY_PROPERTY_ATTESTATION</span> <span class="o">=</span> <span class="s2">&quot;S-1-18-6&quot;</span>
+
+
+<div class="viewcode-block" id="SID"><a class="viewcode-back" href="../../api/smb_security_descriptors.html#smb.security_descriptors.SID">[docs]</a><span class="k">class</span> <span class="nc">SID</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    A Windows security identifier. Represents a single principal, such a</span>
+<span class="sd">    user or a group, as a sequence of numbers consisting of the revision,</span>
+<span class="sd">    identifier authority, and a variable-length list of subauthorities.</span>
+
+<span class="sd">    See [MS-DTYP]: 2.4.2</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">revision</span><span class="p">,</span> <span class="n">identifier_authority</span><span class="p">,</span> <span class="n">subauthorities</span><span class="p">):</span>
+        <span class="c1">#: Revision, should always be 1.</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">revision</span> <span class="o">=</span> <span class="n">revision</span>
+        <span class="c1">#: An integer representing the identifier authority.</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">identifier_authority</span> <span class="o">=</span> <span class="n">identifier_authority</span>
+        <span class="c1">#: A list of integers representing all subauthorities.</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">subauthorities</span> <span class="o">=</span> <span class="n">subauthorities</span>
+
+    <span class="k">def</span> <span class="nf">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        String representation, as specified in [MS-DTYP]: 2.4.2.1</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">identifier_authority</span> <span class="o">&gt;=</span> <span class="mi">2</span><span class="o">**</span><span class="mi">32</span><span class="p">:</span>
+            <span class="n">id_auth</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">%#x</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">identifier_authority</span><span class="p">,)</span>
+        <span class="k">else</span><span class="p">:</span>
+            <span class="n">id_auth</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">identifier_authority</span>
+        <span class="n">auths</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">revision</span><span class="p">,</span> <span class="n">id_auth</span><span class="p">]</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">subauthorities</span>
+        <span class="k">return</span> <span class="s1">&#39;S-&#39;</span> <span class="o">+</span> <span class="s1">&#39;-&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">subauth</span><span class="p">)</span> <span class="k">for</span> <span class="n">subauth</span> <span class="ow">in</span> <span class="n">auths</span><span class="p">)</span>
+
+    <span class="k">def</span> <span class="nf">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="k">return</span> <span class="s1">&#39;SID(</span><span class="si">%r</span><span class="s1">)&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="p">),)</span>
+
+    <span class="nd">@classmethod</span>
+    <span class="k">def</span> <span class="nf">from_bytes</span><span class="p">(</span><span class="n">cls</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">return_tail</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
+        <span class="n">revision</span><span class="p">,</span> <span class="n">subauth_count</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">unpack</span><span class="p">(</span><span class="s1">&#39;&lt;BB&#39;</span><span class="p">,</span> <span class="n">data</span><span class="p">[:</span><span class="mi">2</span><span class="p">])</span>
+        <span class="n">identifier_authority</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">unpack</span><span class="p">(</span><span class="s1">&#39;&gt;Q&#39;</span><span class="p">,</span> <span class="s1">&#39;</span><span class="se">\x00\x00</span><span class="s1">&#39;</span> <span class="o">+</span> <span class="n">data</span><span class="p">[</span><span class="mi">2</span><span class="p">:</span><span class="mi">8</span><span class="p">])[</span><span class="mi">0</span><span class="p">]</span>
+        <span class="n">subauth_data</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="mi">8</span><span class="p">:]</span>
+        <span class="n">subauthorities</span> <span class="o">=</span> <span class="p">[</span><span class="n">struct</span><span class="o">.</span><span class="n">unpack</span><span class="p">(</span><span class="s1">&#39;&lt;L&#39;</span><span class="p">,</span> <span class="n">subauth_data</span><span class="p">[</span><span class="mi">4</span> <span class="o">*</span> <span class="n">i</span> <span class="p">:</span> <span class="mi">4</span> <span class="o">*</span> <span class="p">(</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">)])[</span><span class="mi">0</span><span class="p">]</span>
+                          <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">subauth_count</span><span class="p">)]</span>
+        <span class="n">sid</span> <span class="o">=</span> <span class="n">cls</span><span class="p">(</span><span class="n">revision</span><span class="p">,</span> <span class="n">identifier_authority</span><span class="p">,</span> <span class="n">subauthorities</span><span class="p">)</span>
+        <span class="k">if</span> <span class="n">return_tail</span><span class="p">:</span>
+            <span class="k">return</span> <span class="n">sid</span><span class="p">,</span> <span class="n">subauth_data</span><span class="p">[</span><span class="mi">4</span> <span class="o">*</span> <span class="n">subauth_count</span> <span class="p">:]</span>
+        <span class="k">return</span> <span class="n">sid</span></div>
+
+
+<div class="viewcode-block" id="ACE"><a class="viewcode-back" href="../../api/smb_security_descriptors.html#smb.security_descriptors.ACE">[docs]</a><span class="k">class</span> <span class="nc">ACE</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    Represents a single access control entry.</span>
+
+<span class="sd">    See [MS-DTYP]: 2.4.4</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+    <span class="n">HEADER_FORMAT</span> <span class="o">=</span> <span class="s1">&#39;&lt;BBH&#39;</span>
+
+    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">type_</span><span class="p">,</span> <span class="n">flags</span><span class="p">,</span> <span class="n">mask</span><span class="p">,</span> <span class="n">sid</span><span class="p">,</span> <span class="n">additional_data</span><span class="p">):</span>
+        <span class="c1">#: An integer representing the type of the ACE. One of the</span>
+        <span class="c1">#: ``ACE_TYPE_*`` constants. Corresponds to the ``AceType`` field</span>
+        <span class="c1">#: from [MS-DTYP] 2.4.4.1.</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">type_</span>
+        <span class="c1">#: An integer bitmask with ACE flags, corresponds to the</span>
+        <span class="c1">#: ``AceFlags`` field.</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">flags</span> <span class="o">=</span> <span class="n">flags</span>
+        <span class="c1">#: An integer representing the ``ACCESS_MASK`` as specified in</span>
+        <span class="c1">#: [MS-DTYP] 2.4.3.</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">mask</span> <span class="o">=</span> <span class="n">mask</span>
+        <span class="c1">#: The :class:`SID` of a trustee.</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">sid</span> <span class="o">=</span> <span class="n">sid</span>
+        <span class="c1">#: A dictionary of additional fields present in the ACE, depending</span>
+        <span class="c1">#: on the type. The following fields can be present:</span>
+        <span class="c1">#:</span>
+        <span class="c1">#: * ``flags``</span>
+        <span class="c1">#: * ``object_type``</span>
+        <span class="c1">#: * ``inherited_object_type``</span>
+        <span class="c1">#: * ``application_data``</span>
+        <span class="c1">#: * ``attribute_data``</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">additional_data</span> <span class="o">=</span> <span class="n">additional_data</span>
+
+    <span class="k">def</span> <span class="nf">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="k">return</span> <span class="s2">&quot;ACE(type=</span><span class="si">%#04x</span><span class="s2">, flags=</span><span class="si">%#04x</span><span class="s2">, mask=</span><span class="si">%#010x</span><span class="s2">, sid=</span><span class="si">%s</span><span class="s2">)&quot;</span> <span class="o">%</span> <span class="p">(</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">type</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">mask</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">sid</span><span class="p">,</span>
+        <span class="p">)</span>
+
+    <span class="nd">@property</span>
+    <span class="k">def</span> <span class="nf">isInheritOnly</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;Convenience property which indicates if this ACE is inherit</span>
+<span class="sd">        only, meaning that it doesn&#39;t apply to the object itself.&quot;&quot;&quot;</span>
+        <span class="k">return</span> <span class="nb">bool</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flags</span> <span class="o">&amp;</span> <span class="n">ACE_FLAG_INHERIT_ONLY</span><span class="p">)</span>
+
+    <span class="nd">@classmethod</span>
+    <span class="k">def</span> <span class="nf">from_bytes</span><span class="p">(</span><span class="n">cls</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
+        <span class="n">header_size</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">calcsize</span><span class="p">(</span><span class="n">cls</span><span class="o">.</span><span class="n">HEADER_FORMAT</span><span class="p">)</span>
+        <span class="n">header</span> <span class="o">=</span> <span class="n">data</span><span class="p">[:</span><span class="n">header_size</span><span class="p">]</span>
+        <span class="n">type_</span><span class="p">,</span> <span class="n">flags</span><span class="p">,</span> <span class="n">size</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">unpack</span><span class="p">(</span><span class="n">cls</span><span class="o">.</span><span class="n">HEADER_FORMAT</span><span class="p">,</span> <span class="n">header</span><span class="p">)</span>
+
+        <span class="k">assert</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> <span class="o">&gt;=</span> <span class="n">size</span>
+
+        <span class="n">body</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="n">header_size</span><span class="p">:</span><span class="n">size</span><span class="p">]</span>
+        <span class="n">additional_data</span> <span class="o">=</span> <span class="p">{}</span>
+
+        <span class="c1"># In all ACE types, the mask immediately follows the header.</span>
+        <span class="n">mask</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">unpack</span><span class="p">(</span><span class="s1">&#39;&lt;I&#39;</span><span class="p">,</span> <span class="n">body</span><span class="p">[:</span><span class="mi">4</span><span class="p">])[</span><span class="mi">0</span><span class="p">]</span>
+        <span class="n">body</span> <span class="o">=</span> <span class="n">body</span><span class="p">[</span><span class="mi">4</span><span class="p">:]</span>
+
+        <span class="c1"># All OBJECT-type ACEs contain additional flags, and two GUIDs as</span>
+        <span class="c1"># the following fields.</span>
+        <span class="k">if</span> <span class="n">type_</span> <span class="ow">in</span> <span class="p">(</span><span class="n">ACE_TYPE_ACCESS_ALLOWED_OBJECT</span><span class="p">,</span>
+                     <span class="n">ACE_TYPE_ACCESS_DENIED_OBJECT</span><span class="p">,</span>
+                     <span class="n">ACE_TYPE_ACCESS_ALLOWED_CALLBACK_OBJECT</span><span class="p">,</span>
+                     <span class="n">ACE_TYPE_ACCESS_DENIED_CALLBACK_OBJECT</span><span class="p">,</span>
+                     <span class="n">ACE_TYPE_SYSTEM_AUDIT_OBJECT</span><span class="p">,</span>
+                     <span class="n">ACE_TYPE_SYSTEM_AUDIT_CALLBACK_OBJECT</span><span class="p">):</span>
+            <span class="n">additional_data</span><span class="p">[</span><span class="s1">&#39;flags&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">unpack</span><span class="p">(</span><span class="s1">&#39;&lt;I&#39;</span><span class="p">,</span> <span class="n">body</span><span class="p">[:</span><span class="mi">4</span><span class="p">])[</span><span class="mi">0</span><span class="p">]</span>
+            <span class="n">additional_data</span><span class="p">[</span><span class="s1">&#39;object_type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">body</span><span class="p">[</span><span class="mi">4</span><span class="p">:</span><span class="mi">20</span><span class="p">]</span>
+            <span class="n">additional_data</span><span class="p">[</span><span class="s1">&#39;inherited_object_type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">body</span><span class="p">[</span><span class="mi">20</span><span class="p">:</span><span class="mi">36</span><span class="p">]</span>
+            <span class="n">body</span> <span class="o">=</span> <span class="n">body</span><span class="p">[</span><span class="mi">36</span><span class="p">:]</span>
+
+        <span class="c1"># Then the SID in all types.</span>
+        <span class="n">sid</span><span class="p">,</span> <span class="n">body</span> <span class="o">=</span> <span class="n">SID</span><span class="o">.</span><span class="n">from_bytes</span><span class="p">(</span><span class="n">body</span><span class="p">,</span> <span class="n">return_tail</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
+
+        <span class="c1"># CALLBACK-type ACEs (and for some obscure reason,</span>
+        <span class="c1"># SYSTEM_AUDIT_OBJECT) have a final tail of application data.</span>
+        <span class="k">if</span> <span class="n">type_</span> <span class="ow">in</span> <span class="p">(</span><span class="n">ACE_TYPE_ACCESS_ALLOWED_CALLBACK</span><span class="p">,</span>
+                     <span class="n">ACE_TYPE_ACCESS_DENIED_CALLBACK</span><span class="p">,</span>
+                     <span class="n">ACE_TYPE_ACCESS_ALLOWED_CALLBACK_OBJECT</span><span class="p">,</span>
+                     <span class="n">ACE_TYPE_ACCESS_DENIED_CALLBACK_OBJECT</span><span class="p">,</span>
+                     <span class="n">ACE_TYPE_SYSTEM_AUDIT_OBJECT</span><span class="p">,</span>
+                     <span class="n">ACE_TYPE_SYSTEM_AUDIT_CALLBACK</span><span class="p">,</span>
+                     <span class="n">ACE_TYPE_SYSTEM_AUDIT_CALLBACK_OBJECT</span><span class="p">):</span>
+            <span class="n">additional_data</span><span class="p">[</span><span class="s1">&#39;application_data&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">body</span>
+
+        <span class="c1"># SYSTEM_RESOURCE_ATTRIBUTE ACEs have a tail of attribute data.</span>
+        <span class="k">if</span> <span class="n">type_</span> <span class="o">==</span> <span class="n">ACE_TYPE_SYSTEM_RESOURCE_ATTRIBUTE</span><span class="p">:</span>
+            <span class="n">additional_data</span><span class="p">[</span><span class="s1">&#39;attribute_data&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">body</span>
+
+        <span class="k">return</span> <span class="n">cls</span><span class="p">(</span><span class="n">type_</span><span class="p">,</span> <span class="n">flags</span><span class="p">,</span> <span class="n">mask</span><span class="p">,</span> <span class="n">sid</span><span class="p">,</span> <span class="n">additional_data</span><span class="p">)</span></div>
+
+
+<div class="viewcode-block" id="ACL"><a class="viewcode-back" href="../../api/smb_security_descriptors.html#smb.security_descriptors.ACL">[docs]</a><span class="k">class</span> <span class="nc">ACL</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    Access control list, encapsulating a sequence of access control</span>
+<span class="sd">    entries.</span>
+
+<span class="sd">    See [MS-DTYP]: 2.4.5</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+    <span class="n">HEADER_FORMAT</span> <span class="o">=</span> <span class="s1">&#39;&lt;BBHHH&#39;</span>
+
+    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">revision</span><span class="p">,</span> <span class="n">aces</span><span class="p">):</span>
+        <span class="c1">#: Integer value of the revision.</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">revision</span> <span class="o">=</span> <span class="n">revision</span>
+        <span class="c1">#: List of :class:`ACE` instances.</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">aces</span> <span class="o">=</span> <span class="n">aces</span>
+
+    <span class="k">def</span> <span class="nf">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="k">return</span> <span class="s2">&quot;ACL(</span><span class="si">%r</span><span class="s2">)&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">aces</span><span class="p">,)</span>
+
+    <span class="nd">@classmethod</span>
+    <span class="k">def</span> <span class="nf">from_bytes</span><span class="p">(</span><span class="n">cls</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
+        <span class="n">revision</span> <span class="o">=</span> <span class="bp">None</span>
+        <span class="n">aces</span> <span class="o">=</span> <span class="p">[]</span>
+
+        <span class="n">header_size</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">calcsize</span><span class="p">(</span><span class="n">cls</span><span class="o">.</span><span class="n">HEADER_FORMAT</span><span class="p">)</span>
+        <span class="n">header</span><span class="p">,</span> <span class="n">remaining</span> <span class="o">=</span> <span class="n">data</span><span class="p">[:</span><span class="n">header_size</span><span class="p">],</span> <span class="n">data</span><span class="p">[</span><span class="n">header_size</span><span class="p">:]</span>
+        <span class="n">revision</span><span class="p">,</span> <span class="n">sbz1</span><span class="p">,</span> <span class="n">size</span><span class="p">,</span> <span class="n">count</span><span class="p">,</span> <span class="n">sbz2</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">unpack</span><span class="p">(</span><span class="n">cls</span><span class="o">.</span><span class="n">HEADER_FORMAT</span><span class="p">,</span> <span class="n">header</span><span class="p">)</span>
+
+        <span class="k">assert</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> <span class="o">&gt;=</span> <span class="n">size</span>
+
+        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">count</span><span class="p">):</span>
+            <span class="n">ace_size</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">unpack</span><span class="p">(</span><span class="s1">&#39;&lt;H&#39;</span><span class="p">,</span> <span class="n">remaining</span><span class="p">[</span><span class="mi">2</span><span class="p">:</span><span class="mi">4</span><span class="p">])[</span><span class="mi">0</span><span class="p">]</span>
+            <span class="n">ace_data</span><span class="p">,</span> <span class="n">remaining</span> <span class="o">=</span> <span class="n">remaining</span><span class="p">[:</span><span class="n">ace_size</span><span class="p">],</span> <span class="n">remaining</span><span class="p">[</span><span class="n">ace_size</span><span class="p">:]</span>
+            <span class="n">aces</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">ACE</span><span class="o">.</span><span class="n">from_bytes</span><span class="p">(</span><span class="n">ace_data</span><span class="p">))</span>
+
+        <span class="k">return</span> <span class="n">cls</span><span class="p">(</span><span class="n">revision</span><span class="p">,</span> <span class="n">aces</span><span class="p">)</span></div>
+
+
+<div class="viewcode-block" id="SecurityDescriptor"><a class="viewcode-back" href="../../api/smb_security_descriptors.html#smb.security_descriptors.SecurityDescriptor">[docs]</a><span class="k">class</span> <span class="nc">SecurityDescriptor</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    Represents a security descriptor.</span>
+
+<span class="sd">    See [MS-DTYP]: 2.4.6</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+
+    <span class="n">HEADER_FORMAT</span> <span class="o">=</span> <span class="s1">&#39;&lt;BBHIIII&#39;</span>
+
+    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">flags</span><span class="p">,</span> <span class="n">owner</span><span class="p">,</span> <span class="n">group</span><span class="p">,</span> <span class="n">dacl</span><span class="p">,</span> <span class="n">sacl</span><span class="p">):</span>
+        <span class="c1">#: Integer bitmask of control flags. Corresponds to the</span>
+        <span class="c1">#: ``Control`` field in [MS-DTYP] 2.4.6.</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">flags</span> <span class="o">=</span> <span class="n">flags</span>
+        <span class="c1">#: Instance of :class:`SID` representing the owner user.</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">owner</span> <span class="o">=</span> <span class="n">owner</span>
+        <span class="c1">#: Instance of :class:`SID` representing the owner group.</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">group</span> <span class="o">=</span> <span class="n">group</span>
+        <span class="c1">#: Instance of :class:`ACL` representing the discretionary access</span>
+        <span class="c1">#: control list, which specifies access restrictions of an object.</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">dacl</span> <span class="o">=</span> <span class="n">dacl</span>
+        <span class="c1">#: Instance of :class:`ACL` representing the system access control</span>
+        <span class="c1">#: list, which specifies audit logging of an object.</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">sacl</span> <span class="o">=</span> <span class="n">sacl</span>
+
+    <span class="nd">@classmethod</span>
+    <span class="k">def</span> <span class="nf">from_bytes</span><span class="p">(</span><span class="n">cls</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
+        <span class="n">owner</span> <span class="o">=</span> <span class="bp">None</span>
+        <span class="n">group</span> <span class="o">=</span> <span class="bp">None</span>
+        <span class="n">dacl</span> <span class="o">=</span> <span class="bp">None</span>
+        <span class="n">sacl</span> <span class="o">=</span> <span class="bp">None</span>
+
+        <span class="n">header</span> <span class="o">=</span> <span class="n">data</span><span class="p">[:</span><span class="n">struct</span><span class="o">.</span><span class="n">calcsize</span><span class="p">(</span><span class="n">cls</span><span class="o">.</span><span class="n">HEADER_FORMAT</span><span class="p">)]</span>
+        <span class="p">(</span><span class="n">revision</span><span class="p">,</span> <span class="n">sbz1</span><span class="p">,</span> <span class="n">flags</span><span class="p">,</span> <span class="n">owner_offset</span><span class="p">,</span> <span class="n">group_offset</span><span class="p">,</span> <span class="n">sacl_offset</span><span class="p">,</span>
+         <span class="n">dacl_offset</span><span class="p">)</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">unpack</span><span class="p">(</span><span class="n">cls</span><span class="o">.</span><span class="n">HEADER_FORMAT</span><span class="p">,</span> <span class="n">header</span><span class="p">)</span>
+
+        <span class="k">assert</span> <span class="n">revision</span> <span class="o">==</span> <span class="mi">1</span>
+        <span class="k">assert</span> <span class="n">flags</span> <span class="o">&amp;</span> <span class="n">SECURITY_DESCRIPTOR_SELF_RELATIVE</span>
+        <span class="k">for</span> <span class="n">offset</span> <span class="ow">in</span> <span class="p">(</span><span class="n">owner_offset</span><span class="p">,</span> <span class="n">group_offset</span><span class="p">,</span> <span class="n">sacl_offset</span><span class="p">,</span> <span class="n">dacl_offset</span><span class="p">):</span>
+            <span class="k">assert</span> <span class="mi">0</span> <span class="o">&lt;=</span> <span class="n">offset</span> <span class="o">&lt;</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
+
+        <span class="k">if</span> <span class="n">owner_offset</span><span class="p">:</span>
+            <span class="n">owner</span> <span class="o">=</span> <span class="n">SID</span><span class="o">.</span><span class="n">from_bytes</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">owner_offset</span><span class="p">:])</span>
+        <span class="k">if</span> <span class="n">group_offset</span><span class="p">:</span>
+            <span class="n">group</span> <span class="o">=</span> <span class="n">SID</span><span class="o">.</span><span class="n">from_bytes</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">group_offset</span><span class="p">:])</span>
+        <span class="k">if</span> <span class="n">dacl_offset</span><span class="p">:</span>
+            <span class="n">dacl</span> <span class="o">=</span> <span class="n">ACL</span><span class="o">.</span><span class="n">from_bytes</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">dacl_offset</span><span class="p">:])</span>
+        <span class="k">if</span> <span class="n">sacl_offset</span><span class="p">:</span>
+            <span class="n">sacl</span> <span class="o">=</span> <span class="n">ACL</span><span class="o">.</span><span class="n">from_bytes</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">sacl_offset</span><span class="p">:])</span>
+
+        <span class="k">return</span> <span class="n">cls</span><span class="p">(</span><span class="n">flags</span><span class="p">,</span> <span class="n">owner</span><span class="p">,</span> <span class="n">group</span><span class="p">,</span> <span class="n">dacl</span><span class="p">,</span> <span class="n">sacl</span><span class="p">)</span></div>
+</pre></div>
+
+          </div>
+        </div>
+      </div>
+      <div class="clearer"></div>
+    </div>
+    <div class="related" role="navigation" aria-label="related navigation">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="../../genindex.html" title="General Index"
+             >index</a></li>
+        <li class="right" >
+          <a href="../../py-modindex.html" title="Python Module Index"
+             >modules</a> |</li>
+        <li class="nav-item nav-item-0"><a href="../../index.html">pysmb 1.1.25 documentation</a> &raquo;</li>
+          <li class="nav-item nav-item-1"><a href="../index.html" >Module code</a> &raquo;</li> 
+      </ul>
+    </div>
+    <div class="footer" role="contentinfo">
+        &copy; Copyright 2001-2018, Michael Teo http://miketeo.net/.
+      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.6.
+    </div>
+  </body>
+</html>
\ No newline at end of file
diff --git a/docs/html/_modules/smb/smb_structs.html b/docs/html/_modules/smb/smb_structs.html
new file mode 100644
index 00000000..e90a7266
--- /dev/null
+++ b/docs/html/_modules/smb/smb_structs.html
@@ -0,0 +1,1513 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    
+    <title>smb.smb_structs &mdash; pysmb 1.1.25 documentation</title>
+    
+    <link rel="stylesheet" href="../../_static/sphinxdoc.css" type="text/css" />
+    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
+    
+    <script type="text/javascript">
+      var DOCUMENTATION_OPTIONS = {
+        URL_ROOT:    '../../',
+        VERSION:     '1.1.25',
+        COLLAPSE_INDEX: false,
+        FILE_SUFFIX: '.html',
+        HAS_SOURCE:  true
+      };
+    </script>
+    <script type="text/javascript" src="../../_static/jquery.js"></script>
+    <script type="text/javascript" src="../../_static/underscore.js"></script>
+    <script type="text/javascript" src="../../_static/doctools.js"></script>
+    <link rel="top" title="pysmb 1.1.25 documentation" href="../../index.html" />
+    <link rel="up" title="Module code" href="../index.html" /> 
+  </head>
+  <body role="document">
+    <div class="related" role="navigation" aria-label="related navigation">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="../../genindex.html" title="General Index"
+             accesskey="I">index</a></li>
+        <li class="right" >
+          <a href="../../py-modindex.html" title="Python Module Index"
+             >modules</a> |</li>
+        <li class="nav-item nav-item-0"><a href="../../index.html">pysmb 1.1.25 documentation</a> &raquo;</li>
+          <li class="nav-item nav-item-1"><a href="../index.html" accesskey="U">Module code</a> &raquo;</li> 
+      </ul>
+    </div>
+      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
+        <div class="sphinxsidebarwrapper">
+<div id="searchbox" style="display: none" role="search">
+  <h3>Quick search</h3>
+    <form class="search" action="../../search.html" method="get">
+      <input type="text" name="q" />
+      <input type="submit" value="Go" />
+      <input type="hidden" name="check_keywords" value="yes" />
+      <input type="hidden" name="area" value="default" />
+    </form>
+    <p class="searchtip" style="font-size: 90%">
+    Enter search terms or a module, class or function name.
+    </p>
+</div>
+<script type="text/javascript">$('#searchbox').show(0);</script>
+        </div>
+      </div>
+
+    <div class="document">
+      <div class="documentwrapper">
+        <div class="bodywrapper">
+          <div class="body" role="main">
+            
+  <h1>Source code for smb.smb_structs</h1><div class="highlight"><pre>
+
+<span class="kn">import</span> <span class="nn">os</span><span class="o">,</span> <span class="nn">sys</span><span class="o">,</span> <span class="nn">struct</span><span class="o">,</span> <span class="nn">types</span><span class="o">,</span> <span class="nn">logging</span><span class="o">,</span> <span class="nn">binascii</span><span class="o">,</span> <span class="nn">time</span>
+<span class="kn">from</span> <span class="nn">StringIO</span> <span class="kn">import</span> <span class="n">StringIO</span>
+<span class="kn">from</span> <span class="nn">smb_constants</span> <span class="kn">import</span> <span class="o">*</span>
+
+
+<span class="c1"># Set to True if you want to enable support for extended security. Required for Windows Vista and later</span>
+<span class="n">SUPPORT_EXTENDED_SECURITY</span> <span class="o">=</span> <span class="bp">True</span>
+
+<span class="c1"># Set to True if you want to enable SMB2 protocol.</span>
+<span class="n">SUPPORT_SMB2</span> <span class="o">=</span> <span class="bp">True</span>
+
+<span class="c1"># Set to True if you want to enable SMB2.1 and above protocol.</span>
+<span class="n">SUPPORT_SMB2x</span> <span class="o">=</span> <span class="bp">True</span>
+
+<span class="c1"># Supported dialects</span>
+<span class="n">NT_LAN_MANAGER_DIALECT</span> <span class="o">=</span> <span class="mi">0</span>  <span class="c1"># &#39;NT LM 0.12&#39; is always the first element in the dialect list and must always be included (MS-SMB 2.2.4.5.1)</span>
+
+<span class="c1"># Return the list of support SMB dialects based on the SUPPORT_x constants</span>
+<span class="k">def</span> <span class="nf">init_dialects_list</span><span class="p">():</span>
+    <span class="n">dialects</span> <span class="o">=</span> <span class="p">[</span> <span class="s1">&#39;NT LM 0.12&#39;</span> <span class="p">]</span>
+    <span class="k">if</span> <span class="n">SUPPORT_SMB2</span><span class="p">:</span>
+        <span class="n">dialects</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;SMB 2.002&#39;</span><span class="p">)</span>
+    <span class="k">if</span> <span class="n">SUPPORT_SMB2x</span><span class="p">:</span>
+        <span class="n">dialects</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;SMB 2.???&#39;</span><span class="p">)</span>
+    <span class="k">return</span> <span class="n">dialects</span>
+
+<div class="viewcode-block" id="UnsupportedFeature"><a class="viewcode-back" href="../../api/smb_exceptions.html#smb.smb_structs.UnsupportedFeature">[docs]</a><span class="k">class</span> <span class="nc">UnsupportedFeature</span><span class="p">(</span><span class="ne">Exception</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    Raised when an supported feature is present/required in the protocol but is not</span>
+<span class="sd">    currently supported by pysmb</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+    <span class="k">pass</span></div>
+
+
+<div class="viewcode-block" id="ProtocolError"><a class="viewcode-back" href="../../api/smb_exceptions.html#smb.smb_structs.ProtocolError">[docs]</a><span class="k">class</span> <span class="nc">ProtocolError</span><span class="p">(</span><span class="ne">Exception</span><span class="p">):</span>
+
+    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">,</span> <span class="n">data_buf</span> <span class="o">=</span> <span class="bp">None</span><span class="p">,</span> <span class="n">smb_message</span> <span class="o">=</span> <span class="bp">None</span><span class="p">):</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">message</span> <span class="o">=</span> <span class="n">message</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">data_buf</span> <span class="o">=</span> <span class="n">data_buf</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">smb_message</span> <span class="o">=</span> <span class="n">smb_message</span>
+
+    <span class="k">def</span> <span class="nf">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="n">b</span> <span class="o">=</span> <span class="n">StringIO</span><span class="p">()</span>
+        <span class="n">b</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">message</span> <span class="o">+</span> <span class="n">os</span><span class="o">.</span><span class="n">linesep</span><span class="p">)</span>
+        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">smb_message</span><span class="p">:</span>
+            <span class="n">b</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;=&#39;</span> <span class="o">*</span> <span class="mi">20</span> <span class="o">+</span> <span class="s1">&#39; SMB Message &#39;</span> <span class="o">+</span> <span class="s1">&#39;=&#39;</span> <span class="o">*</span> <span class="mi">20</span> <span class="o">+</span> <span class="n">os</span><span class="o">.</span><span class="n">linesep</span><span class="p">)</span>
+            <span class="n">b</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">smb_message</span><span class="p">))</span>
+
+        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_buf</span><span class="p">:</span>
+            <span class="n">b</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;=&#39;</span> <span class="o">*</span> <span class="mi">20</span> <span class="o">+</span> <span class="s1">&#39; SMB Data Packet (hex) &#39;</span> <span class="o">+</span> <span class="s1">&#39;=&#39;</span> <span class="o">*</span> <span class="mi">20</span> <span class="o">+</span> <span class="n">os</span><span class="o">.</span><span class="n">linesep</span><span class="p">)</span>
+            <span class="n">b</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">binascii</span><span class="o">.</span><span class="n">hexlify</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data_buf</span><span class="p">))</span>
+            <span class="n">b</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">linesep</span><span class="p">)</span>
+
+        <span class="k">return</span> <span class="n">b</span><span class="o">.</span><span class="n">getvalue</span><span class="p">()</span></div>
+
+<span class="k">class</span> <span class="nc">SMB2ProtocolHeaderError</span><span class="p">(</span><span class="n">ProtocolError</span><span class="p">):</span>
+
+    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="n">ProtocolError</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s2">&quot;Packet header belongs to SMB2&quot;</span><span class="p">)</span>
+
+<div class="viewcode-block" id="OperationFailure"><a class="viewcode-back" href="../../api/smb_exceptions.html#smb.smb_structs.OperationFailure">[docs]</a><span class="k">class</span> <span class="nc">OperationFailure</span><span class="p">(</span><span class="ne">Exception</span><span class="p">):</span>
+
+    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">,</span> <span class="n">smb_messages</span><span class="p">):</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">args</span> <span class="o">=</span> <span class="p">[</span> <span class="n">message</span> <span class="p">]</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">message</span> <span class="o">=</span> <span class="n">message</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">smb_messages</span> <span class="o">=</span> <span class="n">smb_messages</span>
+
+    <span class="k">def</span> <span class="nf">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="n">b</span> <span class="o">=</span> <span class="n">StringIO</span><span class="p">()</span>
+        <span class="n">b</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">message</span> <span class="o">+</span> <span class="n">os</span><span class="o">.</span><span class="n">linesep</span><span class="p">)</span>
+
+        <span class="k">for</span> <span class="n">idx</span><span class="p">,</span> <span class="n">m</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">smb_messages</span><span class="p">):</span>
+            <span class="n">b</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;=&#39;</span> <span class="o">*</span> <span class="mi">20</span> <span class="o">+</span> <span class="s1">&#39; SMB Message </span><span class="si">%d</span><span class="s1"> &#39;</span> <span class="o">%</span> <span class="n">idx</span> <span class="o">+</span> <span class="s1">&#39;=&#39;</span> <span class="o">*</span> <span class="mi">20</span> <span class="o">+</span> <span class="n">os</span><span class="o">.</span><span class="n">linesep</span><span class="p">)</span>
+            <span class="n">b</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;SMB Header:&#39;</span> <span class="o">+</span> <span class="n">os</span><span class="o">.</span><span class="n">linesep</span><span class="p">)</span>
+            <span class="n">b</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;-----------&#39;</span> <span class="o">+</span> <span class="n">os</span><span class="o">.</span><span class="n">linesep</span><span class="p">)</span>
+            <span class="n">b</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">m</span><span class="p">))</span>
+            <span class="n">b</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;SMB Data Packet (hex):&#39;</span> <span class="o">+</span> <span class="n">os</span><span class="o">.</span><span class="n">linesep</span><span class="p">)</span>
+            <span class="n">b</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;----------------------&#39;</span> <span class="o">+</span> <span class="n">os</span><span class="o">.</span><span class="n">linesep</span><span class="p">)</span>
+            <span class="n">b</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">binascii</span><span class="o">.</span><span class="n">hexlify</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">raw_data</span><span class="p">))</span>
+            <span class="n">b</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">linesep</span><span class="p">)</span>
+
+        <span class="k">return</span> <span class="n">b</span><span class="o">.</span><span class="n">getvalue</span><span class="p">()</span></div>
+
+
+<span class="k">class</span> <span class="nc">SMBError</span><span class="p">:</span>
+
+    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">reset</span><span class="p">()</span>
+
+    <span class="k">def</span> <span class="nf">reset</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">internal_value</span> <span class="o">=</span> <span class="il">0L</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">is_ntstatus</span> <span class="o">=</span> <span class="bp">True</span>
+
+    <span class="k">def</span> <span class="nf">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_ntstatus</span><span class="p">:</span>
+            <span class="k">return</span> <span class="s1">&#39;NTSTATUS=0x</span><span class="si">%08X</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">internal_value</span>
+        <span class="k">else</span><span class="p">:</span>
+            <span class="k">return</span> <span class="s1">&#39;ErrorClass=0x</span><span class="si">%02X</span><span class="s1"> ErrorCode=0x</span><span class="si">%04X</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span> <span class="bp">self</span><span class="o">.</span><span class="n">internal_value</span> <span class="o">&gt;&gt;</span> <span class="mi">24</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">internal_value</span> <span class="o">&amp;</span> <span class="mh">0xFFFF</span> <span class="p">)</span>
+
+    <span class="nd">@property</span>
+    <span class="k">def</span> <span class="nf">hasError</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">internal_value</span> <span class="o">!=</span> <span class="mi">0</span>
+
+
+<span class="k">class</span> <span class="nc">SMBMessage</span><span class="p">:</span>
+
+    <span class="n">HEADER_STRUCT_FORMAT</span> <span class="o">=</span> <span class="s2">&quot;&lt;4sBIBHHQxxHHHHB&quot;</span>
+    <span class="n">HEADER_STRUCT_SIZE</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">calcsize</span><span class="p">(</span><span class="n">HEADER_STRUCT_FORMAT</span><span class="p">)</span>
+
+    <span class="n">log</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="s1">&#39;SMB.SMBMessage&#39;</span><span class="p">)</span>
+    <span class="n">protocol</span> <span class="o">=</span> <span class="mi">1</span>
+
+    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">conn</span><span class="p">,</span> <span class="n">payload</span> <span class="o">=</span> <span class="bp">None</span><span class="p">):</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">reset</span><span class="p">()</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">conn</span> <span class="o">=</span> <span class="n">conn</span>
+        <span class="k">if</span> <span class="n">payload</span><span class="p">:</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">payload</span> <span class="o">=</span> <span class="n">payload</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">payload</span><span class="o">.</span><span class="n">initMessage</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
+
+    <span class="k">def</span> <span class="nf">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="n">b</span> <span class="o">=</span> <span class="n">StringIO</span><span class="p">()</span>
+        <span class="n">b</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;Command: 0x</span><span class="si">%02X</span><span class="s1"> (</span><span class="si">%s</span><span class="s1">) </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span> <span class="bp">self</span><span class="o">.</span><span class="n">command</span><span class="p">,</span> <span class="n">SMB_COMMAND_NAMES</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">command</span><span class="p">,</span> <span class="s1">&#39;&lt;unknown&gt;&#39;</span><span class="p">),</span> <span class="n">os</span><span class="o">.</span><span class="n">linesep</span> <span class="p">))</span>
+        <span class="n">b</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;Status: </span><span class="si">%s</span><span class="s1"> </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">status</span><span class="p">),</span> <span class="n">os</span><span class="o">.</span><span class="n">linesep</span> <span class="p">))</span>
+        <span class="n">b</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;Flags: 0x</span><span class="si">%02X</span><span class="s1"> </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span> <span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">linesep</span> <span class="p">))</span>
+        <span class="n">b</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;Flags2: 0x</span><span class="si">%04X</span><span class="s1"> </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span> <span class="bp">self</span><span class="o">.</span><span class="n">flags2</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">linesep</span> <span class="p">))</span>
+        <span class="n">b</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;PID: </span><span class="si">%d</span><span class="s1"> </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span> <span class="bp">self</span><span class="o">.</span><span class="n">pid</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">linesep</span> <span class="p">))</span>
+        <span class="n">b</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;UID: </span><span class="si">%d</span><span class="s1"> </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span> <span class="bp">self</span><span class="o">.</span><span class="n">uid</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">linesep</span> <span class="p">))</span>
+        <span class="n">b</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;MID: </span><span class="si">%d</span><span class="s1"> </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span> <span class="bp">self</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">linesep</span> <span class="p">))</span>
+        <span class="n">b</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;TID: </span><span class="si">%d</span><span class="s1"> </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span> <span class="bp">self</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">linesep</span> <span class="p">))</span>
+        <span class="n">b</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;Security: 0x</span><span class="si">%016X</span><span class="s1"> </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span> <span class="bp">self</span><span class="o">.</span><span class="n">security</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">linesep</span> <span class="p">))</span>
+        <span class="n">b</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;Parameters: </span><span class="si">%d</span><span class="s1"> bytes </span><span class="si">%s%s</span><span class="s1"> </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">parameters_data</span><span class="p">),</span> <span class="n">os</span><span class="o">.</span><span class="n">linesep</span><span class="p">,</span> <span class="n">binascii</span><span class="o">.</span><span class="n">hexlify</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">parameters_data</span><span class="p">),</span> <span class="n">os</span><span class="o">.</span><span class="n">linesep</span> <span class="p">))</span>
+        <span class="n">b</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;Data: </span><span class="si">%d</span><span class="s1"> bytes </span><span class="si">%s%s</span><span class="s1"> </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">),</span> <span class="n">os</span><span class="o">.</span><span class="n">linesep</span><span class="p">,</span> <span class="n">binascii</span><span class="o">.</span><span class="n">hexlify</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">),</span> <span class="n">os</span><span class="o">.</span><span class="n">linesep</span> <span class="p">))</span>
+        <span class="k">return</span> <span class="n">b</span><span class="o">.</span><span class="n">getvalue</span><span class="p">()</span>
+
+    <span class="k">def</span> <span class="nf">reset</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">raw_data</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">command</span> <span class="o">=</span> <span class="mi">0</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">status</span> <span class="o">=</span> <span class="n">SMBError</span><span class="p">()</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">flags</span> <span class="o">=</span> <span class="mi">0</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">flags2</span> <span class="o">=</span> <span class="mi">0</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">pid</span> <span class="o">=</span> <span class="mi">0</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">tid</span> <span class="o">=</span> <span class="mi">0</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">uid</span> <span class="o">=</span> <span class="mi">0</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">mid</span> <span class="o">=</span> <span class="mi">0</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">security</span> <span class="o">=</span> <span class="il">0L</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">parameters_data</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">payload</span> <span class="o">=</span> <span class="bp">None</span>
+
+    <span class="nd">@property</span>
+    <span class="k">def</span> <span class="nf">isReply</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="k">return</span> <span class="nb">bool</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flags</span> <span class="o">&amp;</span> <span class="n">SMB_FLAGS_REPLY</span><span class="p">)</span>
+
+    <span class="nd">@property</span>
+    <span class="k">def</span> <span class="nf">hasExtendedSecurity</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="k">return</span> <span class="nb">bool</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flags2</span> <span class="o">&amp;</span> <span class="n">SMB_FLAGS2_EXTENDED_SECURITY</span><span class="p">)</span>
+
+    <span class="k">def</span> <span class="nf">encode</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Encode this SMB message into a series of bytes suitable to be embedded with a NetBIOS session message.</span>
+<span class="sd">        AssertionError will be raised if this SMB message has not been initialized with a Payload instance</span>
+
+<span class="sd">        @return: a string containing the encoded SMB message</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="k">assert</span> <span class="bp">self</span><span class="o">.</span><span class="n">payload</span>
+
+        <span class="bp">self</span><span class="o">.</span><span class="n">pid</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">getpid</span><span class="p">()</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">payload</span><span class="o">.</span><span class="n">prepare</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
+
+        <span class="n">parameters_len</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">parameters_data</span><span class="p">)</span>
+        <span class="k">assert</span> <span class="n">parameters_len</span> <span class="o">%</span> <span class="mi">2</span> <span class="o">==</span> <span class="mi">0</span>
+
+        <span class="n">headers_data</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">HEADER_STRUCT_FORMAT</span><span class="p">,</span>
+                                   <span class="s1">&#39;</span><span class="se">\xFF</span><span class="s1">SMB&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">command</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">internal_value</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">,</span>
+                                   <span class="bp">self</span><span class="o">.</span><span class="n">flags2</span><span class="p">,</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">pid</span> <span class="o">&gt;&gt;</span> <span class="mi">16</span><span class="p">)</span> <span class="o">&amp;</span> <span class="mh">0xFFFF</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">security</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span>
+                                   <span class="bp">self</span><span class="o">.</span><span class="n">pid</span> <span class="o">&amp;</span> <span class="mh">0xFFFF</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">uid</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="n">parameters_len</span> <span class="o">/</span> <span class="mi">2</span><span class="p">))</span>
+        <span class="k">return</span> <span class="n">headers_data</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">parameters_data</span> <span class="o">+</span> <span class="n">struct</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="s1">&#39;&lt;H&#39;</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">))</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span>
+
+    <span class="k">def</span> <span class="nf">decode</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">buf</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Decodes the SMB message in buf.</span>
+<span class="sd">        All fields of the SMBMessage object will be reset to default values before decoding.</span>
+<span class="sd">        On errors, do not assume that the fields will be reinstated back to what they are before</span>
+<span class="sd">        this method is invoked.</span>
+
+<span class="sd">        @param buf: data containing one complete SMB message</span>
+<span class="sd">        @type buf: string</span>
+<span class="sd">        @return: a positive integer indicating the number of bytes used in buf to decode this SMB message</span>
+<span class="sd">        @raise ProtocolError: raised when decoding fails</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="n">buf_len</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">buf</span><span class="p">)</span>
+        <span class="k">if</span> <span class="n">buf_len</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">HEADER_STRUCT_SIZE</span><span class="p">:</span>
+            <span class="c1"># We need at least 32 bytes (header) + 1 byte (parameter count)</span>
+            <span class="k">raise</span> <span class="n">ProtocolError</span><span class="p">(</span><span class="s1">&#39;Not enough data to decode SMB header&#39;</span><span class="p">,</span> <span class="n">buf</span><span class="p">)</span>
+
+        <span class="bp">self</span><span class="o">.</span><span class="n">reset</span><span class="p">()</span>
+
+        <span class="n">protocol</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">command</span><span class="p">,</span> <span class="n">status</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">,</span> \
+        <span class="bp">self</span><span class="o">.</span><span class="n">flags2</span><span class="p">,</span> <span class="n">pid_high</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">security</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">tid</span><span class="p">,</span> \
+        <span class="n">pid_low</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">uid</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">mid</span><span class="p">,</span> <span class="n">params_count</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">unpack</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">HEADER_STRUCT_FORMAT</span><span class="p">,</span> <span class="n">buf</span><span class="p">[:</span><span class="bp">self</span><span class="o">.</span><span class="n">HEADER_STRUCT_SIZE</span><span class="p">])</span>
+
+        <span class="k">if</span> <span class="n">protocol</span> <span class="o">==</span> <span class="s1">&#39;</span><span class="se">\xFE</span><span class="s1">SMB&#39;</span><span class="p">:</span>
+            <span class="k">raise</span> <span class="n">SMB2ProtocolHeaderError</span><span class="p">()</span>
+        <span class="k">if</span> <span class="n">protocol</span> <span class="o">!=</span> <span class="s1">&#39;</span><span class="se">\xFF</span><span class="s1">SMB&#39;</span><span class="p">:</span>
+            <span class="k">raise</span> <span class="n">ProtocolError</span><span class="p">(</span><span class="s1">&#39;Invalid 4-byte protocol field&#39;</span><span class="p">,</span> <span class="n">buf</span><span class="p">)</span>
+
+        <span class="bp">self</span><span class="o">.</span><span class="n">pid</span> <span class="o">=</span> <span class="p">(</span><span class="n">pid_high</span> <span class="o">&lt;&lt;</span> <span class="mi">16</span><span class="p">)</span> <span class="o">|</span> <span class="n">pid_low</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">internal_value</span> <span class="o">=</span> <span class="n">status</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">is_ntstatus</span> <span class="o">=</span> <span class="nb">bool</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flags2</span> <span class="o">&amp;</span> <span class="n">SMB_FLAGS2_NT_STATUS</span><span class="p">)</span>
+
+        <span class="n">offset</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">HEADER_STRUCT_SIZE</span>
+        <span class="k">if</span> <span class="n">buf_len</span> <span class="o">&lt;</span> <span class="n">params_count</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">+</span> <span class="mi">2</span><span class="p">:</span>
+            <span class="c1"># Not enough data in buf to decode up to body length</span>
+            <span class="k">raise</span> <span class="n">ProtocolError</span><span class="p">(</span><span class="s1">&#39;Not enough data. Parameters list decoding failed&#39;</span><span class="p">,</span> <span class="n">buf</span><span class="p">)</span>
+
+        <span class="n">datalen_offset</span> <span class="o">=</span> <span class="n">offset</span> <span class="o">+</span> <span class="n">params_count</span><span class="o">*</span><span class="mi">2</span>
+        <span class="n">body_len</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">unpack</span><span class="p">(</span><span class="s1">&#39;&lt;H&#39;</span><span class="p">,</span> <span class="n">buf</span><span class="p">[</span><span class="n">datalen_offset</span><span class="p">:</span><span class="n">datalen_offset</span><span class="o">+</span><span class="mi">2</span><span class="p">])[</span><span class="mi">0</span><span class="p">]</span>
+        <span class="k">if</span> <span class="n">body_len</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">buf_len</span> <span class="o">&lt;</span> <span class="p">(</span><span class="n">datalen_offset</span> <span class="o">+</span> <span class="mi">2</span> <span class="o">+</span> <span class="n">body_len</span><span class="p">):</span>
+            <span class="c1"># Not enough data in buf to decode body</span>
+            <span class="k">raise</span> <span class="n">ProtocolError</span><span class="p">(</span><span class="s1">&#39;Not enough data. Body decoding failed&#39;</span><span class="p">,</span> <span class="n">buf</span><span class="p">)</span>
+
+        <span class="bp">self</span><span class="o">.</span><span class="n">parameters_data</span> <span class="o">=</span> <span class="n">buf</span><span class="p">[</span><span class="n">offset</span><span class="p">:</span><span class="n">datalen_offset</span><span class="p">]</span>
+
+        <span class="k">if</span> <span class="n">body_len</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">buf</span><span class="p">[</span><span class="n">datalen_offset</span><span class="o">+</span><span class="mi">2</span><span class="p">:</span><span class="n">datalen_offset</span><span class="o">+</span><span class="mi">2</span><span class="o">+</span><span class="n">body_len</span><span class="p">]</span>
+
+        <span class="bp">self</span><span class="o">.</span><span class="n">raw_data</span> <span class="o">=</span> <span class="n">buf</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">_decodePayload</span><span class="p">()</span>
+
+        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">HEADER_STRUCT_SIZE</span> <span class="o">+</span> <span class="n">params_count</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">+</span> <span class="mi">2</span> <span class="o">+</span> <span class="n">body_len</span>
+
+    <span class="k">def</span> <span class="nf">_decodePayload</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">command</span> <span class="o">==</span> <span class="n">SMB_COM_READ_ANDX</span><span class="p">:</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">payload</span> <span class="o">=</span> <span class="n">ComReadAndxResponse</span><span class="p">()</span>
+        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">command</span> <span class="o">==</span> <span class="n">SMB_COM_WRITE_ANDX</span><span class="p">:</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">payload</span> <span class="o">=</span> <span class="n">ComWriteAndxResponse</span><span class="p">()</span>
+        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">command</span> <span class="o">==</span> <span class="n">SMB_COM_TRANSACTION</span><span class="p">:</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">payload</span> <span class="o">=</span> <span class="n">ComTransactionResponse</span><span class="p">()</span>
+        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">command</span> <span class="o">==</span> <span class="n">SMB_COM_TRANSACTION2</span><span class="p">:</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">payload</span> <span class="o">=</span> <span class="n">ComTransaction2Response</span><span class="p">()</span>
+        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">command</span> <span class="o">==</span> <span class="n">SMB_COM_OPEN_ANDX</span><span class="p">:</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">payload</span> <span class="o">=</span> <span class="n">ComOpenAndxResponse</span><span class="p">()</span>
+        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">command</span> <span class="o">==</span> <span class="n">SMB_COM_NT_CREATE_ANDX</span><span class="p">:</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">payload</span> <span class="o">=</span> <span class="n">ComNTCreateAndxResponse</span><span class="p">()</span>
+        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">command</span> <span class="o">==</span> <span class="n">SMB_COM_TREE_CONNECT_ANDX</span><span class="p">:</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">payload</span> <span class="o">=</span> <span class="n">ComTreeConnectAndxResponse</span><span class="p">()</span>
+        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">command</span> <span class="o">==</span> <span class="n">SMB_COM_ECHO</span><span class="p">:</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">payload</span> <span class="o">=</span> <span class="n">ComEchoResponse</span><span class="p">()</span>
+        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">command</span> <span class="o">==</span> <span class="n">SMB_COM_SESSION_SETUP_ANDX</span><span class="p">:</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">payload</span> <span class="o">=</span> <span class="n">ComSessionSetupAndxResponse</span><span class="p">()</span>
+        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">command</span> <span class="o">==</span> <span class="n">SMB_COM_NEGOTIATE</span><span class="p">:</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">payload</span> <span class="o">=</span> <span class="n">ComNegotiateResponse</span><span class="p">()</span>
+
+        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">payload</span><span class="p">:</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">payload</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
+
+
+<span class="k">class</span> <span class="nc">Payload</span><span class="p">:</span>
+
+    <span class="n">DEFAULT_ANDX_PARAM_HEADER</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="se">\xFF\x00\x00\x00</span><span class="s1">&#39;</span>
+    <span class="n">DEFAULT_ANDX_PARAM_SIZE</span> <span class="o">=</span> <span class="mi">4</span>
+
+    <span class="k">def</span> <span class="nf">initMessage</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="c1"># SMB_FLAGS2_UNICODE must always be enabled. Without this, almost all the Payload subclasses will need to be</span>
+        <span class="c1"># rewritten to check for OEM/Unicode strings which will be tedious. Fortunately, almost all tested CIFS services</span>
+        <span class="c1"># support SMB_FLAGS2_UNICODE by default.</span>
+        <span class="k">assert</span> <span class="n">message</span><span class="o">.</span><span class="n">payload</span> <span class="o">==</span> <span class="bp">self</span>
+        <span class="n">message</span><span class="o">.</span><span class="n">flags</span> <span class="o">=</span>  <span class="n">SMB_FLAGS_CASE_INSENSITIVE</span> <span class="o">|</span> <span class="n">SMB_FLAGS_CANONICALIZED_PATHS</span>
+        <span class="n">message</span><span class="o">.</span><span class="n">flags2</span> <span class="o">=</span> <span class="n">SMB_FLAGS2_UNICODE</span> <span class="o">|</span> <span class="n">SMB_FLAGS2_NT_STATUS</span> <span class="o">|</span> <span class="n">SMB_FLAGS2_LONG_NAMES</span> <span class="o">|</span> <span class="n">SMB_FLAGS2_EAS</span>
+
+        <span class="k">if</span> <span class="n">SUPPORT_EXTENDED_SECURITY</span><span class="p">:</span>
+            <span class="n">message</span><span class="o">.</span><span class="n">flags2</span> <span class="o">|=</span> <span class="n">SMB_FLAGS2_EXTENDED_SECURITY</span> <span class="o">|</span> <span class="n">SMB_FLAGS2_SMB_SECURITY_SIGNATURE</span>
+
+    <span class="k">def</span> <span class="nf">prepare</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="k">raise</span> <span class="ne">NotImplementedError</span>
+
+    <span class="k">def</span> <span class="nf">decode</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="k">raise</span> <span class="ne">NotImplementedError</span>
+
+
+<span class="k">class</span> <span class="nc">ComNegotiateRequest</span><span class="p">(</span><span class="n">Payload</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    References:</span>
+<span class="sd">    ===========</span>
+<span class="sd">    - [MS-CIFS]: 2.2.4.52.1</span>
+<span class="sd">    - [MS-SMB]: 2.2.4.5.1</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+
+    <span class="k">def</span> <span class="nf">initMessage</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="n">Payload</span><span class="o">.</span><span class="n">initMessage</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">)</span>
+        <span class="n">message</span><span class="o">.</span><span class="n">command</span> <span class="o">=</span> <span class="n">SMB_COM_NEGOTIATE</span>
+
+    <span class="k">def</span> <span class="nf">prepare</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="k">assert</span> <span class="n">message</span><span class="o">.</span><span class="n">payload</span> <span class="o">==</span> <span class="bp">self</span>
+        <span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
+        <span class="n">message</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span><span class="k">lambda</span> <span class="n">s</span><span class="p">:</span> <span class="s1">&#39;</span><span class="se">\x02</span><span class="s1">&#39;</span><span class="o">+</span><span class="n">s</span><span class="o">+</span><span class="s1">&#39;</span><span class="se">\x00</span><span class="s1">&#39;</span><span class="p">,</span> <span class="n">init_dialects_list</span><span class="p">()))</span>
+
+
+<span class="k">class</span> <span class="nc">ComNegotiateResponse</span><span class="p">(</span><span class="n">Payload</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    Contains information on the SMB_COM_NEGOTIATE response from server</span>
+
+<span class="sd">    After calling the decode method, each instance will contain the following attributes,</span>
+<span class="sd">    - security_mode (integer)</span>
+<span class="sd">    - max_mpx_count (integer)</span>
+<span class="sd">    - max_number_vcs (integer)</span>
+<span class="sd">    - max_buffer_size (long)</span>
+<span class="sd">    - max_raw_size (long)</span>
+<span class="sd">    - session_key (long)</span>
+<span class="sd">    - capabilities (long)</span>
+<span class="sd">    - system_time (long)</span>
+<span class="sd">    - server_time_zone (integer)</span>
+<span class="sd">    - challenge_length (integer)</span>
+
+<span class="sd">    If the underlying SMB message&#39;s flag2 does not have SMB_FLAGS2_EXTENDED_SECURITY bit enabled,</span>
+<span class="sd">    then the instance will have the following additional attributes,</span>
+<span class="sd">    - challenge (string)</span>
+<span class="sd">    - domain (unicode)</span>
+
+<span class="sd">    If the underlying SMB message&#39;s flags2 has SMB_FLAGS2_EXTENDED_SECURITY bit enabled,</span>
+<span class="sd">    then the instance will have the following additional attributes,</span>
+<span class="sd">    - server_guid (string)</span>
+<span class="sd">    - security_blob (string)</span>
+
+<span class="sd">    References:</span>
+<span class="sd">    ===========</span>
+<span class="sd">    - [MS-SMB]: 2.2.4.5.2.1</span>
+<span class="sd">    - [MS-CIFS]: 2.2.4.52.2</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+
+    <span class="n">PAYLOAD_STRUCT_FORMAT</span> <span class="o">=</span> <span class="s1">&#39;&lt;HBHHIIIIQHB&#39;</span>
+    <span class="n">PAYLOAD_STRUCT_SIZE</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">calcsize</span><span class="p">(</span><span class="n">PAYLOAD_STRUCT_FORMAT</span><span class="p">)</span>
+
+    <span class="k">def</span> <span class="nf">decode</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="k">assert</span> <span class="n">message</span><span class="o">.</span><span class="n">command</span> <span class="o">==</span> <span class="n">SMB_COM_NEGOTIATE</span>
+
+        <span class="k">if</span> <span class="ow">not</span> <span class="n">message</span><span class="o">.</span><span class="n">isReply</span><span class="p">:</span>
+            <span class="k">raise</span> <span class="n">ProtocolError</span><span class="p">(</span><span class="s1">&#39;Not a SMB_COM_NEGOTIATE reply&#39;</span><span class="p">,</span> <span class="n">message</span><span class="o">.</span><span class="n">raw_data</span><span class="p">,</span> <span class="n">message</span><span class="p">)</span>
+
+        <span class="bp">self</span><span class="o">.</span><span class="n">security_mode</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_mpx_count</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_number_vcs</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_buffer_size</span><span class="p">,</span> \
+        <span class="bp">self</span><span class="o">.</span><span class="n">max_raw_size</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">session_key</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">capabilities</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">system_time</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">server_time_zone</span><span class="p">,</span> \
+        <span class="bp">self</span><span class="o">.</span><span class="n">challenge_length</span> <span class="o">=</span> <span class="p">(</span> <span class="mi">0</span><span class="p">,</span> <span class="p">)</span> <span class="o">*</span> <span class="mi">10</span>
+
+        <span class="n">data_len</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span><span class="p">)</span>
+        <span class="k">if</span> <span class="n">data_len</span> <span class="o">&lt;</span> <span class="mi">2</span><span class="p">:</span>
+            <span class="k">raise</span> <span class="n">ProtocolError</span><span class="p">(</span><span class="s1">&#39;Not enough data to decode SMB_COM_NEGOTIATE dialect_index field&#39;</span><span class="p">,</span> <span class="n">message</span><span class="o">.</span><span class="n">raw_data</span><span class="p">,</span> <span class="n">message</span><span class="p">)</span>
+
+        <span class="bp">self</span><span class="o">.</span><span class="n">dialect_index</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">unpack</span><span class="p">(</span><span class="s1">&#39;&lt;H&#39;</span><span class="p">,</span> <span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span><span class="p">[:</span><span class="mi">2</span><span class="p">])[</span><span class="mi">0</span><span class="p">]</span>
+        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">dialect_index</span> <span class="o">==</span> <span class="n">NT_LAN_MANAGER_DIALECT</span><span class="p">:</span>
+            <span class="k">if</span> <span class="n">data_len</span> <span class="o">!=</span> <span class="p">(</span><span class="mh">0x11</span> <span class="o">*</span> <span class="mi">2</span><span class="p">):</span>
+                <span class="k">raise</span> <span class="n">ProtocolError</span><span class="p">(</span><span class="s1">&#39;NT LAN Manager dialect selected in SMB_COM_NEGOTIATE but parameters bytes count (</span><span class="si">%d</span><span class="s1">) does not meet specs&#39;</span> <span class="o">%</span> <span class="n">data_len</span><span class="p">,</span>
+                                    <span class="n">message</span><span class="o">.</span><span class="n">raw_data</span><span class="p">,</span> <span class="n">message</span><span class="p">)</span>
+            <span class="k">else</span><span class="p">:</span>
+                <span class="n">_</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">security_mode</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_mpx_count</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_number_vcs</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_buffer_size</span><span class="p">,</span> \
+                <span class="bp">self</span><span class="o">.</span><span class="n">max_raw_size</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">session_key</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">capabilities</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">system_time</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">server_time_zone</span><span class="p">,</span> \
+                <span class="bp">self</span><span class="o">.</span><span class="n">challenge_length</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">unpack</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_FORMAT</span><span class="p">,</span> <span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span><span class="p">[:</span><span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_SIZE</span><span class="p">])</span>
+        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">dialect_index</span> <span class="o">==</span> <span class="mh">0xFFFF</span><span class="p">:</span>
+            <span class="k">raise</span> <span class="n">ProtocolError</span><span class="p">(</span><span class="s1">&#39;Server does not support any of the pysmb dialects. Please email pysmb to add in support for your OS&#39;</span><span class="p">,</span>
+                                <span class="n">message</span><span class="o">.</span><span class="n">raw_data</span><span class="p">,</span> <span class="n">message</span><span class="p">)</span>
+        <span class="k">else</span><span class="p">:</span>
+            <span class="k">raise</span> <span class="n">ProtocolError</span><span class="p">(</span><span class="s1">&#39;Unknown dialect index (0x</span><span class="si">%04X</span><span class="s1">)&#39;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">dialect_index</span><span class="p">,</span> <span class="n">message</span><span class="o">.</span><span class="n">raw_data</span><span class="p">,</span> <span class="n">message</span><span class="p">)</span>
+
+        <span class="n">data_len</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">data</span><span class="p">)</span>
+        <span class="k">if</span> <span class="ow">not</span> <span class="n">message</span><span class="o">.</span><span class="n">hasExtendedSecurity</span><span class="p">:</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">challenge</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">domain</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span>
+            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">challenge_length</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
+                <span class="k">if</span> <span class="n">data_len</span> <span class="o">&gt;=</span> <span class="bp">self</span><span class="o">.</span><span class="n">challenge_length</span><span class="p">:</span>
+                    <span class="bp">self</span><span class="o">.</span><span class="n">challenge</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="n">data</span><span class="p">[:</span><span class="bp">self</span><span class="o">.</span><span class="n">challenge_length</span><span class="p">]</span>
+
+                    <span class="n">s</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
+                    <span class="n">offset</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">challenge_length</span>
+                    <span class="k">while</span> <span class="n">offset</span> <span class="o">&lt;</span> <span class="n">data_len</span><span class="p">:</span>
+                        <span class="n">_s</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">offset</span><span class="p">:</span><span class="n">offset</span><span class="o">+</span><span class="mi">2</span><span class="p">]</span>
+                        <span class="k">if</span> <span class="n">_s</span> <span class="o">==</span> <span class="s1">&#39;</span><span class="se">\0\0</span><span class="s1">&#39;</span><span class="p">:</span>
+                            <span class="bp">self</span><span class="o">.</span><span class="n">domain</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s1">&#39;UTF-16LE&#39;</span><span class="p">)</span>
+                            <span class="k">break</span>
+                        <span class="k">else</span><span class="p">:</span>
+                            <span class="n">s</span> <span class="o">+=</span> <span class="n">_s</span>
+                            <span class="n">offset</span> <span class="o">+=</span> <span class="mi">2</span>
+                <span class="k">else</span><span class="p">:</span>
+                    <span class="k">raise</span> <span class="n">ProtocolError</span><span class="p">(</span><span class="s1">&#39;Not enough data to decode SMB_COM_NEGOTIATE (without security extensions) Challenge field&#39;</span><span class="p">,</span> <span class="n">message</span><span class="o">.</span><span class="n">raw_data</span><span class="p">,</span> <span class="n">message</span><span class="p">)</span>
+        <span class="k">else</span><span class="p">:</span>
+            <span class="k">if</span> <span class="n">data_len</span> <span class="o">&lt;</span> <span class="mi">16</span><span class="p">:</span>
+                <span class="k">raise</span> <span class="n">ProtocolError</span><span class="p">(</span><span class="s1">&#39;Not enough data to decode SMB_COM_NEGOTIATE (with security extensions) ServerGUID field&#39;</span><span class="p">,</span> <span class="n">message</span><span class="o">.</span><span class="n">raw_data</span><span class="p">,</span> <span class="n">message</span><span class="p">)</span>
+
+            <span class="bp">self</span><span class="o">.</span><span class="n">server_guid</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="n">data</span><span class="p">[:</span><span class="mi">16</span><span class="p">]</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">security_blob</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="mi">16</span><span class="p">:]</span>
+
+    <span class="nd">@property</span>
+    <span class="k">def</span> <span class="nf">supportsExtendedSecurity</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="k">return</span> <span class="nb">bool</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">capabilities</span> <span class="o">&amp;</span> <span class="n">CAP_EXTENDED_SECURITY</span><span class="p">)</span>
+
+
+<span class="k">class</span> <span class="nc">ComSessionSetupAndxRequest__WithSecurityExtension</span><span class="p">(</span><span class="n">Payload</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    References:</span>
+<span class="sd">    ===========</span>
+<span class="sd">    - [MS-SMB]: 2.2.4.6.1</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+
+    <span class="n">PAYLOAD_STRUCT_FORMAT</span> <span class="o">=</span> <span class="s1">&#39;&lt;HHHIHII&#39;</span>
+
+    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">session_key</span><span class="p">,</span> <span class="n">security_blob</span><span class="p">):</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">session_key</span> <span class="o">=</span> <span class="n">session_key</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">security_blob</span> <span class="o">=</span> <span class="n">security_blob</span>
+
+    <span class="k">def</span> <span class="nf">initMessage</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="n">Payload</span><span class="o">.</span><span class="n">initMessage</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">)</span>
+        <span class="n">message</span><span class="o">.</span><span class="n">command</span> <span class="o">=</span> <span class="n">SMB_COM_SESSION_SETUP_ANDX</span>
+
+    <span class="k">def</span> <span class="nf">prepare</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="k">assert</span> <span class="n">message</span><span class="o">.</span><span class="n">hasExtendedSecurity</span>
+
+        <span class="n">message</span><span class="o">.</span><span class="n">flags2</span> <span class="o">|=</span> <span class="n">SMB_FLAGS2_UNICODE</span>
+
+        <span class="n">cap</span> <span class="o">=</span> <span class="n">CAP_UNICODE</span> <span class="o">|</span> <span class="n">CAP_STATUS32</span> <span class="o">|</span> <span class="n">CAP_EXTENDED_SECURITY</span> <span class="o">|</span> <span class="n">CAP_NT_SMBS</span>
+
+        <span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span> <span class="o">=</span> \
+            <span class="bp">self</span><span class="o">.</span><span class="n">DEFAULT_ANDX_PARAM_HEADER</span> <span class="o">+</span> \
+            <span class="n">struct</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_FORMAT</span><span class="p">,</span>
+                        <span class="mi">16644</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">session_key</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">security_blob</span><span class="p">),</span> <span class="mi">0</span><span class="p">,</span> <span class="n">cap</span><span class="p">)</span>
+
+        <span class="n">message</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">security_blob</span>
+        <span class="k">if</span> <span class="p">(</span><span class="n">SMBMessage</span><span class="o">.</span><span class="n">HEADER_STRUCT_SIZE</span> <span class="o">+</span> <span class="nb">len</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span><span class="p">)</span> <span class="o">+</span> <span class="nb">len</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">data</span><span class="p">))</span> <span class="o">%</span> <span class="mi">2</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
+            <span class="n">message</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="n">data</span> <span class="o">+</span> <span class="s1">&#39;</span><span class="se">\0</span><span class="s1">&#39;</span>
+        <span class="n">message</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="n">data</span> <span class="o">+</span> <span class="s1">&#39;</span><span class="se">\0</span><span class="s1">&#39;</span> <span class="o">*</span> <span class="mi">4</span>
+
+
+<span class="k">class</span> <span class="nc">ComSessionSetupAndxRequest__NoSecurityExtension</span><span class="p">(</span><span class="n">Payload</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    References:</span>
+<span class="sd">    ===========</span>
+<span class="sd">    - [MS-CIFS]: 2.2.4.53.1</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+
+    <span class="n">PAYLOAD_STRUCT_FORMAT</span> <span class="o">=</span> <span class="s1">&#39;&lt;HHHIHHII&#39;</span>
+
+    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">session_key</span><span class="p">,</span> <span class="n">username</span><span class="p">,</span> <span class="n">password</span><span class="p">,</span> <span class="n">is_unicode</span><span class="p">,</span> <span class="n">domain</span><span class="p">):</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">username</span> <span class="o">=</span> <span class="n">username</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">session_key</span> <span class="o">=</span> <span class="n">session_key</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">password</span> <span class="o">=</span> <span class="n">password</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">is_unicode</span> <span class="o">=</span> <span class="n">is_unicode</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">domain</span> <span class="o">=</span> <span class="n">domain</span>
+
+    <span class="k">def</span> <span class="nf">initMessage</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="n">Payload</span><span class="o">.</span><span class="n">initMessage</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">)</span>
+        <span class="n">message</span><span class="o">.</span><span class="n">command</span> <span class="o">=</span> <span class="n">SMB_COM_SESSION_SETUP_ANDX</span>
+
+    <span class="k">def</span> <span class="nf">prepare</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_unicode</span><span class="p">:</span>
+            <span class="n">message</span><span class="o">.</span><span class="n">flags2</span> <span class="o">|=</span> <span class="n">SMB_FLAGS2_UNICODE</span>
+        <span class="k">else</span><span class="p">:</span>
+            <span class="n">message</span><span class="o">.</span><span class="n">flags2</span> <span class="o">&amp;=</span> <span class="p">(</span><span class="o">~</span><span class="n">SMB_FLAGS2_UNICODE</span> <span class="o">&amp;</span> <span class="mh">0xFFFF</span><span class="p">)</span>
+
+        <span class="n">password_len</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">password</span><span class="p">)</span>
+        <span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span> <span class="o">=</span> \
+            <span class="bp">self</span><span class="o">.</span><span class="n">DEFAULT_ANDX_PARAM_HEADER</span> <span class="o">+</span> \
+            <span class="n">struct</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_FORMAT</span><span class="p">,</span>
+                        <span class="mi">16644</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">session_key</span><span class="p">,</span>
+                        <span class="p">(</span><span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_unicode</span> <span class="ow">and</span> <span class="n">password_len</span><span class="p">)</span> <span class="ow">or</span> <span class="mi">0</span><span class="p">,</span>
+                        <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">is_unicode</span> <span class="ow">and</span> <span class="n">password_len</span><span class="p">)</span> <span class="ow">or</span> <span class="mi">0</span><span class="p">,</span>
+                        <span class="mi">0</span><span class="p">,</span>
+                        <span class="n">CAP_UNICODE</span> <span class="o">|</span> <span class="n">CAP_LARGE_FILES</span> <span class="o">|</span> <span class="n">CAP_STATUS32</span><span class="p">)</span>
+
+        <span class="n">est_offset</span> <span class="o">=</span> <span class="n">SMBMessage</span><span class="o">.</span><span class="n">HEADER_STRUCT_SIZE</span> <span class="o">+</span> <span class="nb">len</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span><span class="p">)</span>  <span class="c1"># To check if data until SMB paramaters are aligned to a 16-bit boundary</span>
+
+        <span class="n">message</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">password</span>
+        <span class="k">if</span> <span class="p">(</span><span class="n">est_offset</span> <span class="o">+</span> <span class="nb">len</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">data</span><span class="p">))</span> <span class="o">%</span> <span class="mi">2</span> <span class="o">!=</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">message</span><span class="o">.</span><span class="n">flags2</span> <span class="o">&amp;</span> <span class="n">SMB_FLAGS2_UNICODE</span><span class="p">:</span>
+            <span class="n">message</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="n">data</span> <span class="o">+</span> <span class="s1">&#39;</span><span class="se">\0</span><span class="s1">&#39;</span>
+
+        <span class="k">if</span> <span class="n">message</span><span class="o">.</span><span class="n">flags2</span> <span class="o">&amp;</span> <span class="n">SMB_FLAGS2_UNICODE</span><span class="p">:</span>
+            <span class="n">message</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="n">data</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">username</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s1">&#39;UTF-16LE&#39;</span><span class="p">)</span> <span class="o">+</span> <span class="s1">&#39;</span><span class="se">\0</span><span class="s1">&#39;</span>
+        <span class="k">else</span><span class="p">:</span>
+            <span class="n">message</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="n">data</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">username</span><span class="p">)</span> <span class="o">+</span> <span class="s1">&#39;</span><span class="se">\0</span><span class="s1">&#39;</span>
+
+        <span class="k">if</span> <span class="p">(</span><span class="n">est_offset</span> <span class="o">+</span> <span class="nb">len</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">data</span><span class="p">))</span> <span class="o">%</span> <span class="mi">2</span> <span class="o">!=</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">message</span><span class="o">.</span><span class="n">flags2</span> <span class="o">&amp;</span> <span class="n">SMB_FLAGS2_UNICODE</span><span class="p">:</span>
+            <span class="n">message</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="n">data</span> <span class="o">+</span> <span class="s1">&#39;</span><span class="se">\0</span><span class="s1">&#39;</span>
+
+        <span class="k">if</span> <span class="n">message</span><span class="o">.</span><span class="n">flags2</span> <span class="o">&amp;</span> <span class="n">SMB_FLAGS2_UNICODE</span><span class="p">:</span>
+            <span class="n">message</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="n">data</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">domain</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s1">&#39;UTF-16LE&#39;</span><span class="p">)</span> <span class="o">+</span> <span class="s1">&#39;</span><span class="se">\0\0</span><span class="s1">&#39;</span> <span class="o">+</span> <span class="s1">&#39;pysmb&#39;</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s1">&#39;UTF-16LE&#39;</span><span class="p">)</span> <span class="o">+</span> <span class="s1">&#39;</span><span class="se">\0\0</span><span class="s1">&#39;</span>
+        <span class="k">else</span><span class="p">:</span>
+            <span class="n">message</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="n">data</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">domain</span> <span class="o">+</span> <span class="s1">&#39;</span><span class="se">\0</span><span class="s1">pysmb</span><span class="se">\0</span><span class="s1">&#39;</span>
+
+
+<span class="k">class</span> <span class="nc">ComSessionSetupAndxResponse</span><span class="p">(</span><span class="n">Payload</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    Contains information on the SMB_COM_SESSION_SETUP_ANDX response from server</span>
+
+<span class="sd">    If the underlying SMB message&#39;s flags2 does not have SMB_FLAGS2_EXTENDED_SECURITY bit enabled,</span>
+<span class="sd">    then the instance will have the following attributes,</span>
+<span class="sd">    - action</span>
+
+<span class="sd">    If the underlying SMB message&#39;s flags2 has SMB_FLAGS2_EXTENDED_SECURITY bit enabled</span>
+<span class="sd">    and the message status is STATUS_MORE_PROCESSING_REQUIRED or equals to 0x00 (no error),</span>
+<span class="sd">    then the instance will have the following attributes,</span>
+<span class="sd">    - action</span>
+<span class="sd">    - securityblob</span>
+
+<span class="sd">    If the underlying SMB message&#39;s flags2 has SMB_FLAGS2_EXTENDED_SECURITY bit enabled but</span>
+<span class="sd">    the message status is not STATUS_MORE_PROCESSING_REQUIRED</span>
+
+<span class="sd">    References:</span>
+<span class="sd">    ===========</span>
+<span class="sd">    - [MS-SMB]: 2.2.4.6.2</span>
+<span class="sd">    - [MS-CIFS]: 2.2.4.53.2</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+
+    <span class="n">NOSECURE_PARAMETER_STRUCT_FORMAT</span> <span class="o">=</span> <span class="s1">&#39;&lt;BBHH&#39;</span>
+    <span class="n">NOSECURE_PARAMETER_STRUCT_SIZE</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">calcsize</span><span class="p">(</span><span class="n">NOSECURE_PARAMETER_STRUCT_FORMAT</span><span class="p">)</span>
+
+    <span class="n">SECURE_PARAMETER_STRUCT_FORMAT</span> <span class="o">=</span> <span class="s1">&#39;&lt;BBHHH&#39;</span>
+    <span class="n">SECURE_PARAMETER_STRUCT_SIZE</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">calcsize</span><span class="p">(</span><span class="n">SECURE_PARAMETER_STRUCT_FORMAT</span><span class="p">)</span>
+
+    <span class="k">def</span> <span class="nf">decode</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="k">assert</span> <span class="n">message</span><span class="o">.</span><span class="n">command</span> <span class="o">==</span> <span class="n">SMB_COM_SESSION_SETUP_ANDX</span>
+        <span class="k">if</span> <span class="ow">not</span> <span class="n">message</span><span class="o">.</span><span class="n">hasExtendedSecurity</span><span class="p">:</span>
+            <span class="k">if</span> <span class="ow">not</span> <span class="n">message</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">hasError</span><span class="p">:</span>
+                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span><span class="p">)</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">NOSECURE_PARAMETER_STRUCT_SIZE</span><span class="p">:</span>
+                    <span class="k">raise</span> <span class="n">ProtocolError</span><span class="p">(</span><span class="s1">&#39;Not enough data to decode SMB_COM_SESSION_SETUP_ANDX (no security extensions) parameters&#39;</span><span class="p">,</span> <span class="n">message</span><span class="o">.</span><span class="n">raw_data</span><span class="p">,</span> <span class="n">message</span><span class="p">)</span>
+
+                <span class="n">_</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">action</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">unpack</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">NOSECURE_PARAMETER_STRUCT_FORMAT</span><span class="p">,</span> <span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span><span class="p">[:</span><span class="bp">self</span><span class="o">.</span><span class="n">NOSECURE_PARAMETER_STRUCT_SIZE</span><span class="p">])</span>
+        <span class="k">else</span><span class="p">:</span>
+            <span class="k">if</span> <span class="ow">not</span> <span class="n">message</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">hasError</span> <span class="ow">or</span> <span class="n">message</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">internal_value</span> <span class="o">==</span> <span class="mh">0xc0000016</span><span class="p">:</span>   <span class="c1"># STATUS_MORE_PROCESSING_REQUIRED</span>
+                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span><span class="p">)</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">SECURE_PARAMETER_STRUCT_SIZE</span><span class="p">:</span>
+                    <span class="k">raise</span> <span class="n">ProtocolError</span><span class="p">(</span><span class="s1">&#39;Not enough data to decode SMB_COM_SESSION_SETUP_ANDX (with security extensions) parameters&#39;</span><span class="p">,</span> <span class="n">message</span><span class="o">.</span><span class="n">raw_data</span><span class="p">,</span> <span class="n">message</span><span class="p">)</span>
+
+                <span class="n">_</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">action</span><span class="p">,</span> <span class="n">blob_length</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">unpack</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">SECURE_PARAMETER_STRUCT_FORMAT</span><span class="p">,</span> <span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span><span class="p">[:</span><span class="bp">self</span><span class="o">.</span><span class="n">SECURE_PARAMETER_STRUCT_SIZE</span><span class="p">])</span>
+                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">data</span><span class="p">)</span> <span class="o">&lt;</span> <span class="n">blob_length</span><span class="p">:</span>
+                    <span class="k">raise</span> <span class="n">ProtocolError</span><span class="p">(</span><span class="s1">&#39;Not enough data to decode SMB_COM_SESSION_SETUP_ANDX (with security extensions) security blob&#39;</span><span class="p">,</span> <span class="n">message</span><span class="o">.</span><span class="n">raw_data</span><span class="p">,</span> <span class="n">message</span><span class="p">)</span>
+
+                <span class="bp">self</span><span class="o">.</span><span class="n">security_blob</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="n">data</span><span class="p">[:</span><span class="n">blob_length</span><span class="p">]</span>
+
+
+<span class="k">class</span> <span class="nc">ComTreeConnectAndxRequest</span><span class="p">(</span><span class="n">Payload</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    References:</span>
+<span class="sd">    ===========</span>
+<span class="sd">    - [MS-CIFS]: 2.2.4.55.1</span>
+<span class="sd">    - [MS-SMB]: 2.2.4.7.1</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+
+    <span class="n">PAYLOAD_STRUCT_FORMAT</span> <span class="o">=</span> <span class="s1">&#39;&lt;HH&#39;</span>
+    <span class="n">PAYLOAD_STRUCT_SIZE</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">calcsize</span><span class="p">(</span><span class="n">PAYLOAD_STRUCT_FORMAT</span><span class="p">)</span>
+
+    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">path</span><span class="p">,</span> <span class="n">service</span><span class="p">,</span> <span class="n">password</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span><span class="p">):</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">path</span> <span class="o">=</span> <span class="n">path</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">service</span> <span class="o">=</span> <span class="n">service</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">password</span> <span class="o">=</span> <span class="n">password</span> <span class="o">+</span> <span class="s1">&#39;</span><span class="se">\0</span><span class="s1">&#39;</span>
+
+    <span class="k">def</span> <span class="nf">initMessage</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="n">Payload</span><span class="o">.</span><span class="n">initMessage</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">)</span>
+        <span class="n">message</span><span class="o">.</span><span class="n">command</span> <span class="o">=</span> <span class="n">SMB_COM_TREE_CONNECT_ANDX</span>
+
+    <span class="k">def</span> <span class="nf">prepare</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="n">password_len</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">password</span><span class="p">)</span>
+        <span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span> <span class="o">=</span> \
+            <span class="bp">self</span><span class="o">.</span><span class="n">DEFAULT_ANDX_PARAM_HEADER</span> <span class="o">+</span> \
+            <span class="n">struct</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_FORMAT</span><span class="p">,</span>
+                        <span class="mh">0x08</span> <span class="o">|</span> \
+                            <span class="p">((</span><span class="n">message</span><span class="o">.</span><span class="n">hasExtendedSecurity</span> <span class="ow">and</span> <span class="mh">0x0004</span><span class="p">)</span> <span class="ow">or</span> <span class="mh">0x00</span><span class="p">)</span> <span class="o">|</span> \
+                            <span class="p">((</span><span class="n">message</span><span class="o">.</span><span class="n">tid</span> <span class="ow">and</span> <span class="n">message</span><span class="o">.</span><span class="n">tid</span> <span class="o">!=</span> <span class="mh">0xFFFF</span> <span class="ow">and</span> <span class="mh">0x0001</span><span class="p">)</span> <span class="ow">or</span> <span class="mh">0x00</span><span class="p">),</span>  <span class="c1"># Disconnect tid, if message.tid must be non-zero</span>
+                        <span class="n">password_len</span><span class="p">)</span>
+
+        <span class="n">padding</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
+        <span class="k">if</span> <span class="n">password_len</span> <span class="o">%</span> <span class="mi">2</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
+            <span class="n">padding</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="se">\0</span><span class="s1">&#39;</span>
+
+        <span class="c1"># Note that service field is never encoded in UTF-16LE. [MS-CIFS]: 2.2.1.1</span>
+        <span class="n">message</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">password</span> <span class="o">+</span> <span class="n">padding</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s1">&#39;UTF-16LE&#39;</span><span class="p">)</span> <span class="o">+</span> <span class="s1">&#39;</span><span class="se">\0\0</span><span class="s1">&#39;</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">service</span> <span class="o">+</span> <span class="s1">&#39;</span><span class="se">\0</span><span class="s1">&#39;</span>
+
+
+<span class="k">class</span> <span class="nc">ComTreeConnectAndxResponse</span><span class="p">(</span><span class="n">Payload</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    Contains information about the SMB_COM_TREE_CONNECT_ANDX response from the server.</span>
+
+<span class="sd">    If the message has no errors, each instance contains the following attributes:</span>
+<span class="sd">    - optional_support</span>
+
+<span class="sd">    References:</span>
+<span class="sd">    ===========</span>
+<span class="sd">    - [MS-CIFS]: 2.2.4.55.2</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+
+    <span class="n">PAYLOAD_STRUCT_FORMAT</span> <span class="o">=</span> <span class="s1">&#39;&lt;BBHH&#39;</span>
+    <span class="n">PAYLOAD_STRUCT_SIZE</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">calcsize</span><span class="p">(</span><span class="n">PAYLOAD_STRUCT_FORMAT</span><span class="p">)</span>
+
+    <span class="k">def</span> <span class="nf">decode</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="k">assert</span> <span class="n">message</span><span class="o">.</span><span class="n">command</span> <span class="o">==</span> <span class="n">SMB_COM_TREE_CONNECT_ANDX</span>
+
+        <span class="k">if</span> <span class="ow">not</span> <span class="n">message</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">hasError</span><span class="p">:</span>
+            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span><span class="p">)</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_SIZE</span><span class="p">:</span>
+                <span class="k">raise</span> <span class="n">ProtocolError</span><span class="p">(</span><span class="s1">&#39;Not enough data to decode SMB_COM_TREE_CONNECT_ANDX parameters&#39;</span><span class="p">,</span> <span class="n">message</span><span class="o">.</span><span class="n">raw_data</span><span class="p">,</span> <span class="n">message</span><span class="p">)</span>
+
+            <span class="n">_</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">optional_support</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">unpack</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_FORMAT</span><span class="p">,</span> <span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span><span class="p">[:</span><span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_SIZE</span><span class="p">])</span>
+
+
+<span class="k">class</span> <span class="nc">ComNTCreateAndxRequest</span><span class="p">(</span><span class="n">Payload</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    References:</span>
+<span class="sd">    ===========</span>
+<span class="sd">    - [MS-CIFS]: 2.2.4.64.1</span>
+<span class="sd">    - [MS-SMB]: 2.2.4.9.1</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+
+    <span class="n">PAYLOAD_STRUCT_FORMAT</span> <span class="o">=</span> <span class="s1">&#39;&lt;BHIIIQIIIIIB&#39;</span>
+    <span class="n">PAYLOAD_STRUCT_SIZE</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">calcsize</span><span class="p">(</span><span class="n">PAYLOAD_STRUCT_FORMAT</span><span class="p">)</span>
+
+    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">flags</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">root_fid</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">access_mask</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">allocation_size</span> <span class="o">=</span> <span class="il">0L</span><span class="p">,</span> <span class="n">ext_attr</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span>
+                 <span class="n">share_access</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">create_disp</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">create_options</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">impersonation</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">security_flags</span> <span class="o">=</span> <span class="mi">0</span><span class="p">):</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">filename</span> <span class="o">=</span> <span class="p">(</span><span class="n">filename</span> <span class="o">+</span> <span class="s1">&#39;</span><span class="se">\0</span><span class="s1">&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s1">&#39;UTF-16LE&#39;</span><span class="p">)</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">flags</span> <span class="o">=</span> <span class="n">flags</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">root_fid</span> <span class="o">=</span> <span class="n">root_fid</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">access_mask</span> <span class="o">=</span> <span class="n">access_mask</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">allocation_size</span> <span class="o">=</span> <span class="n">allocation_size</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">ext_attr</span> <span class="o">=</span> <span class="n">ext_attr</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">share_access</span> <span class="o">=</span> <span class="n">share_access</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">create_disp</span> <span class="o">=</span> <span class="n">create_disp</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">create_options</span> <span class="o">=</span> <span class="n">create_options</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">impersonation</span> <span class="o">=</span> <span class="n">impersonation</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">security_flags</span> <span class="o">=</span> <span class="n">security_flags</span>
+
+    <span class="k">def</span> <span class="nf">initMessage</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="n">Payload</span><span class="o">.</span><span class="n">initMessage</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">)</span>
+        <span class="n">message</span><span class="o">.</span><span class="n">command</span> <span class="o">=</span> <span class="n">SMB_COM_NT_CREATE_ANDX</span>
+
+    <span class="k">def</span> <span class="nf">prepare</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="n">filename_len</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">filename</span><span class="p">)</span>
+
+        <span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span> <span class="o">=</span> \
+            <span class="bp">self</span><span class="o">.</span><span class="n">DEFAULT_ANDX_PARAM_HEADER</span> <span class="o">+</span> \
+            <span class="n">struct</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_FORMAT</span><span class="p">,</span>
+                        <span class="mh">0x00</span><span class="p">,</span>                  <span class="c1"># reserved</span>
+                        <span class="n">filename_len</span><span class="p">,</span>          <span class="c1"># NameLength</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">,</span>            <span class="c1"># Flags</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">root_fid</span><span class="p">,</span>         <span class="c1"># RootDirectoryFID</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">access_mask</span><span class="p">,</span>      <span class="c1"># DesiredAccess</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">allocation_size</span><span class="p">,</span>  <span class="c1"># AllocationSize</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">ext_attr</span><span class="p">,</span>         <span class="c1"># ExtFileAttributes</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">share_access</span><span class="p">,</span>     <span class="c1"># ShareAccess</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">create_disp</span><span class="p">,</span>      <span class="c1"># CreateDisposition</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">create_options</span><span class="p">,</span>   <span class="c1"># CreateOptions</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">impersonation</span><span class="p">,</span>    <span class="c1"># ImpersonationLevel</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">security_flags</span><span class="p">)</span>   <span class="c1"># SecurityFlags</span>
+
+        <span class="n">padding</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
+        <span class="k">if</span> <span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">HEADER_STRUCT_SIZE</span> <span class="o">+</span> <span class="nb">len</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span><span class="p">))</span> <span class="o">%</span> <span class="mi">2</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
+            <span class="n">padding</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="se">\0</span><span class="s1">&#39;</span>
+
+        <span class="n">message</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">padding</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">filename</span>
+
+
+<span class="k">class</span> <span class="nc">ComNTCreateAndxResponse</span><span class="p">(</span><span class="n">Payload</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    Contains (partial) information about the SMB_COM_NT_CREATE_ANDX response from the server.</span>
+
+<span class="sd">    Each instance contains the following attributes after decoding:</span>
+<span class="sd">    - oplock_level</span>
+<span class="sd">    - fid</span>
+
+<span class="sd">    References:</span>
+<span class="sd">    ===========</span>
+<span class="sd">    - [MS-CIFS]: 2.2.4.64.2</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+    <span class="n">PAYLOAD_STRUCT_FORMAT</span> <span class="o">=</span> <span class="s1">&#39;&lt;BBHBH&#39;</span>
+    <span class="n">PAYLOAD_STRUCT_SIZE</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">calcsize</span><span class="p">(</span><span class="n">PAYLOAD_STRUCT_FORMAT</span><span class="p">)</span>
+
+    <span class="k">def</span> <span class="nf">decode</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="k">assert</span> <span class="n">message</span><span class="o">.</span><span class="n">command</span> <span class="o">==</span> <span class="n">SMB_COM_NT_CREATE_ANDX</span>
+
+        <span class="k">if</span> <span class="ow">not</span> <span class="n">message</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">hasError</span><span class="p">:</span>
+            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span><span class="p">)</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_SIZE</span><span class="p">:</span>
+                <span class="k">raise</span> <span class="n">ProtocolError</span><span class="p">(</span><span class="s1">&#39;Not enough data to decode SMB_COM_NT_CREATE_ANDX parameters&#39;</span><span class="p">,</span> <span class="n">message</span><span class="o">.</span><span class="n">raw_data</span><span class="p">,</span> <span class="n">message</span><span class="p">)</span>
+
+            <span class="n">_</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">oplock_level</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">fid</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">unpack</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_FORMAT</span><span class="p">,</span> <span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span><span class="p">[:</span><span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_SIZE</span><span class="p">])</span>
+
+
+<span class="k">class</span> <span class="nc">ComTransactionRequest</span><span class="p">(</span><span class="n">Payload</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    References:</span>
+<span class="sd">    ===========</span>
+<span class="sd">    - [MS-CIFS]: 2.2.4.33.1</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+
+    <span class="n">PAYLOAD_STRUCT_FORMAT</span> <span class="o">=</span> <span class="s1">&#39;&lt;HHHHBBHIHHHHHH&#39;</span>
+    <span class="n">PAYLOAD_STRUCT_SIZE</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">calcsize</span><span class="p">(</span><span class="n">PAYLOAD_STRUCT_FORMAT</span><span class="p">)</span>
+
+    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">max_params_count</span><span class="p">,</span> <span class="n">max_data_count</span><span class="p">,</span> <span class="n">max_setup_count</span><span class="p">,</span>
+                 <span class="n">total_params_count</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">total_data_count</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span>
+                 <span class="n">params_bytes</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="n">data_bytes</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="n">setup_bytes</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span><span class="p">,</span>
+                 <span class="n">flags</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">timeout</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">name</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="se">\\</span><span class="s2">PIPE</span><span class="se">\\</span><span class="s2">&quot;</span><span class="p">):</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">total_params_count</span> <span class="o">=</span> <span class="n">total_params_count</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">params_bytes</span><span class="p">)</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">total_data_count</span> <span class="o">=</span> <span class="n">total_data_count</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">data_bytes</span><span class="p">)</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">max_params_count</span> <span class="o">=</span> <span class="n">max_params_count</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">max_data_count</span> <span class="o">=</span> <span class="n">max_data_count</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">max_setup_count</span> <span class="o">=</span> <span class="n">max_setup_count</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">flags</span> <span class="o">=</span> <span class="n">flags</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">timeout</span> <span class="o">=</span> <span class="n">timeout</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">params_bytes</span> <span class="o">=</span> <span class="n">params_bytes</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">data_bytes</span> <span class="o">=</span> <span class="n">data_bytes</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">setup_bytes</span> <span class="o">=</span> <span class="n">setup_bytes</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">name</span>
+
+    <span class="k">def</span> <span class="nf">initMessage</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="n">Payload</span><span class="o">.</span><span class="n">initMessage</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">)</span>
+        <span class="n">message</span><span class="o">.</span><span class="n">command</span> <span class="o">=</span> <span class="n">SMB_COM_TRANSACTION</span>
+
+    <span class="k">def</span> <span class="nf">prepare</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="n">name</span> <span class="o">=</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">+</span> <span class="s1">&#39;</span><span class="se">\0</span><span class="s1">&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s1">&#39;UTF-16LE&#39;</span><span class="p">)</span>
+        <span class="n">name_len</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
+        <span class="n">setup_bytes_len</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">setup_bytes</span><span class="p">)</span>
+        <span class="n">params_bytes_len</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">params_bytes</span><span class="p">)</span>
+        <span class="n">data_bytes_len</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data_bytes</span><span class="p">)</span>
+
+        <span class="n">padding0</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
+        <span class="n">offset</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="n">HEADER_STRUCT_SIZE</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_SIZE</span> <span class="o">+</span> <span class="n">setup_bytes_len</span> <span class="o">+</span> <span class="mi">2</span> <span class="c1"># constant 2 is for the ByteCount field in the SMB header (i.e. field which indicates number of data bytes after the SMB parameters)</span>
+        <span class="k">if</span> <span class="n">offset</span> <span class="o">%</span> <span class="mi">2</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
+            <span class="n">padding0</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="se">\0</span><span class="s1">&#39;</span>
+            <span class="n">offset</span> <span class="o">+=</span> <span class="mi">1</span>
+
+        <span class="n">offset</span> <span class="o">+=</span> <span class="n">name_len</span>  <span class="c1"># For the name field</span>
+        <span class="n">padding1</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
+        <span class="k">if</span> <span class="n">offset</span> <span class="o">%</span> <span class="mi">4</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
+            <span class="n">padding1</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="se">\0</span><span class="s1">&#39;</span><span class="o">*</span><span class="p">(</span><span class="mi">4</span><span class="o">-</span><span class="n">offset</span><span class="o">%</span><span class="mi">4</span><span class="p">)</span>
+            <span class="n">offset</span> <span class="o">+=</span> <span class="p">(</span><span class="mi">4</span><span class="o">-</span><span class="n">offset</span><span class="o">%</span><span class="mi">4</span><span class="p">)</span>
+
+        <span class="k">if</span> <span class="n">params_bytes_len</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
+            <span class="n">params_bytes_offset</span> <span class="o">=</span> <span class="n">offset</span>
+            <span class="n">offset</span> <span class="o">+=</span> <span class="n">params_bytes_len</span>
+        <span class="k">else</span><span class="p">:</span>
+            <span class="n">params_bytes_offset</span> <span class="o">=</span> <span class="mi">0</span>
+
+        <span class="n">padding2</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
+        <span class="k">if</span> <span class="n">offset</span> <span class="o">%</span> <span class="mi">4</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
+            <span class="n">padding2</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="se">\0</span><span class="s1">&#39;</span><span class="o">*</span><span class="p">(</span><span class="mi">4</span><span class="o">-</span><span class="n">offset</span><span class="o">%</span><span class="mi">4</span><span class="p">)</span>
+            <span class="n">offset</span> <span class="o">+=</span> <span class="p">(</span><span class="mi">4</span><span class="o">-</span><span class="n">offset</span><span class="o">%</span><span class="mi">4</span><span class="p">)</span>
+
+        <span class="k">if</span> <span class="n">data_bytes_len</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
+            <span class="n">data_bytes_offset</span> <span class="o">=</span> <span class="n">offset</span>
+        <span class="k">else</span><span class="p">:</span>
+            <span class="n">data_bytes_offset</span> <span class="o">=</span> <span class="mi">0</span>
+
+        <span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span> <span class="o">=</span> \
+            <span class="n">struct</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_FORMAT</span><span class="p">,</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">total_params_count</span><span class="p">,</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">total_data_count</span><span class="p">,</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">max_params_count</span><span class="p">,</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">max_data_count</span><span class="p">,</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">max_setup_count</span><span class="p">,</span>
+                        <span class="mh">0x00</span><span class="p">,</span>           <span class="c1"># Reserved1. Must be 0x00</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">,</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">timeout</span><span class="p">,</span>
+                        <span class="mh">0x0000</span><span class="p">,</span>         <span class="c1"># Reserved2. Must be 0x0000</span>
+                        <span class="n">params_bytes_len</span><span class="p">,</span>
+                        <span class="n">params_bytes_offset</span><span class="p">,</span>
+                        <span class="n">data_bytes_len</span><span class="p">,</span>
+                        <span class="n">data_bytes_offset</span><span class="p">,</span>
+                        <span class="nb">int</span><span class="p">(</span><span class="n">setup_bytes_len</span> <span class="o">/</span> <span class="mi">2</span><span class="p">))</span> <span class="o">+</span> \
+            <span class="bp">self</span><span class="o">.</span><span class="n">setup_bytes</span>
+
+        <span class="n">message</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">padding0</span> <span class="o">+</span> <span class="n">name</span> <span class="o">+</span> <span class="n">padding1</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">params_bytes</span> <span class="o">+</span> <span class="n">padding2</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_bytes</span>
+
+
+<span class="k">class</span> <span class="nc">ComTransactionResponse</span><span class="p">(</span><span class="n">Payload</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    Contains information about a SMB_COM_TRANSACTION response from the server</span>
+
+<span class="sd">    After decoding, each instance contains the following attributes:</span>
+<span class="sd">    - total_params_count (integer)</span>
+<span class="sd">    - total_data_count (integer)</span>
+<span class="sd">    - setup_bytes (string)</span>
+<span class="sd">    - data_bytes (string)</span>
+<span class="sd">    - params_bytes (string)</span>
+
+<span class="sd">    References:</span>
+<span class="sd">    ===========</span>
+<span class="sd">    - [MS-CIFS]: 2.2.4.33.2</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+
+    <span class="n">PAYLOAD_STRUCT_FORMAT</span> <span class="o">=</span> <span class="s1">&#39;&lt;HHHHHHHHHH&#39;</span>
+    <span class="n">PAYLOAD_STRUCT_SIZE</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">calcsize</span><span class="p">(</span><span class="n">PAYLOAD_STRUCT_FORMAT</span><span class="p">)</span>
+
+    <span class="k">def</span> <span class="nf">decode</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="k">assert</span> <span class="n">message</span><span class="o">.</span><span class="n">command</span> <span class="o">==</span> <span class="n">SMB_COM_TRANSACTION</span>
+
+        <span class="k">if</span> <span class="ow">not</span> <span class="n">message</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">hasError</span><span class="p">:</span>
+            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span><span class="p">)</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_SIZE</span><span class="p">:</span>
+                <span class="k">raise</span> <span class="n">ProtocolError</span><span class="p">(</span><span class="s1">&#39;Not enough data to decode SMB_COM_TRANSACTION parameters&#39;</span><span class="p">,</span> <span class="n">message</span><span class="o">.</span><span class="n">raw_data</span><span class="p">,</span> <span class="n">message</span><span class="p">)</span>
+
+            <span class="bp">self</span><span class="o">.</span><span class="n">total_params_count</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">total_data_count</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> \
+            <span class="n">params_bytes_len</span><span class="p">,</span> <span class="n">params_bytes_offset</span><span class="p">,</span> <span class="n">params_bytes_displ</span><span class="p">,</span> \
+            <span class="n">data_bytes_len</span><span class="p">,</span> <span class="n">data_bytes_offset</span><span class="p">,</span> <span class="n">data_bytes_displ</span><span class="p">,</span> \
+            <span class="n">setup_count</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">unpack</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_FORMAT</span><span class="p">,</span> <span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span><span class="p">[:</span><span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_SIZE</span><span class="p">])</span>
+
+            <span class="k">if</span> <span class="n">setup_count</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
+                <span class="n">setup_bytes_len</span> <span class="o">=</span> <span class="n">setup_count</span> <span class="o">*</span> <span class="mi">2</span>
+
+                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span><span class="p">)</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_SIZE</span> <span class="o">+</span> <span class="n">setup_bytes_len</span><span class="p">:</span>
+                    <span class="k">raise</span> <span class="n">ProtocolError</span><span class="p">(</span><span class="s1">&#39;Not enough data to decode SMB_COM_TRANSACTION parameters&#39;</span><span class="p">,</span> <span class="n">message</span><span class="o">.</span><span class="n">raw_data</span><span class="p">,</span> <span class="n">message</span><span class="p">)</span>
+
+                <span class="bp">self</span><span class="o">.</span><span class="n">setup_bytes</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_SIZE</span><span class="p">:</span><span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_SIZE</span><span class="o">+</span><span class="n">setup_bytes_len</span><span class="p">]</span>
+            <span class="k">else</span><span class="p">:</span>
+                <span class="bp">self</span><span class="o">.</span><span class="n">setup_bytes</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
+
+            <span class="n">offset</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="n">HEADER_STRUCT_SIZE</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_SIZE</span> <span class="o">+</span> <span class="n">setup_count</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">+</span> <span class="mi">2</span> <span class="c1"># constant 2 is for the ByteCount field in the SMB header (i.e. field which indicates number of data bytes after the SMB parameters)</span>
+
+            <span class="k">if</span> <span class="n">params_bytes_len</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
+                <span class="bp">self</span><span class="o">.</span><span class="n">params_bytes</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">params_bytes_offset</span><span class="o">-</span><span class="n">offset</span><span class="p">:</span><span class="n">params_bytes_offset</span><span class="o">-</span><span class="n">offset</span><span class="o">+</span><span class="n">params_bytes_len</span><span class="p">]</span>
+            <span class="k">else</span><span class="p">:</span>
+                <span class="bp">self</span><span class="o">.</span><span class="n">params_bytes</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
+
+            <span class="k">if</span> <span class="n">data_bytes_len</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
+                <span class="bp">self</span><span class="o">.</span><span class="n">data_bytes</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">data_bytes_offset</span><span class="o">-</span><span class="n">offset</span><span class="p">:</span><span class="n">data_bytes_offset</span><span class="o">-</span><span class="n">offset</span><span class="o">+</span><span class="n">data_bytes_len</span><span class="p">]</span>
+            <span class="k">else</span><span class="p">:</span>
+                <span class="bp">self</span><span class="o">.</span><span class="n">data_bytes</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
+
+
+<span class="k">class</span> <span class="nc">ComTransaction2Request</span><span class="p">(</span><span class="n">Payload</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    References:</span>
+<span class="sd">    ===========</span>
+<span class="sd">    - [MS-CIFS]: 2.2.4.46.1</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+
+    <span class="n">PAYLOAD_STRUCT_FORMAT</span> <span class="o">=</span> <span class="s1">&#39;HHHHBBHIHHHHHH&#39;</span>
+    <span class="n">PAYLOAD_STRUCT_SIZE</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">calcsize</span><span class="p">(</span><span class="n">PAYLOAD_STRUCT_FORMAT</span><span class="p">)</span>
+
+    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">max_params_count</span><span class="p">,</span> <span class="n">max_data_count</span><span class="p">,</span> <span class="n">max_setup_count</span><span class="p">,</span>
+                 <span class="n">total_params_count</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">total_data_count</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span>
+                 <span class="n">params_bytes</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="n">data_bytes</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="n">setup_bytes</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span><span class="p">,</span>
+                 <span class="n">flags</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">timeout</span> <span class="o">=</span> <span class="mi">0</span><span class="p">):</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">total_params_count</span> <span class="o">=</span> <span class="n">total_params_count</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">params_bytes</span><span class="p">)</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">total_data_count</span> <span class="o">=</span> <span class="n">total_data_count</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">data_bytes</span><span class="p">)</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">max_params_count</span> <span class="o">=</span> <span class="n">max_params_count</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">max_data_count</span> <span class="o">=</span> <span class="n">max_data_count</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">max_setup_count</span> <span class="o">=</span> <span class="n">max_setup_count</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">flags</span> <span class="o">=</span> <span class="n">flags</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">timeout</span> <span class="o">=</span> <span class="n">timeout</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">params_bytes</span> <span class="o">=</span> <span class="n">params_bytes</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">data_bytes</span> <span class="o">=</span> <span class="n">data_bytes</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">setup_bytes</span> <span class="o">=</span> <span class="n">setup_bytes</span>
+
+    <span class="k">def</span> <span class="nf">initMessage</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="n">Payload</span><span class="o">.</span><span class="n">initMessage</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">)</span>
+        <span class="n">message</span><span class="o">.</span><span class="n">command</span> <span class="o">=</span> <span class="n">SMB_COM_TRANSACTION2</span>
+
+    <span class="k">def</span> <span class="nf">prepare</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="n">setup_bytes_len</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">setup_bytes</span><span class="p">)</span>
+        <span class="n">params_bytes_len</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">params_bytes</span><span class="p">)</span>
+        <span class="n">data_bytes_len</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data_bytes</span><span class="p">)</span>
+        <span class="n">name</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="se">\0\0</span><span class="s1">&#39;</span>
+
+        <span class="n">padding0</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
+        <span class="n">offset</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="n">HEADER_STRUCT_SIZE</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_SIZE</span> <span class="o">+</span> <span class="n">setup_bytes_len</span> <span class="o">+</span> <span class="mi">2</span> <span class="c1"># constant 2 is for the ByteCount field in the SMB header (i.e. field which indicates number of data bytes after the SMB parameters)</span>
+        <span class="k">if</span> <span class="n">offset</span> <span class="o">%</span> <span class="mi">2</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
+            <span class="n">padding0</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="se">\0</span><span class="s1">&#39;</span>
+            <span class="n">offset</span> <span class="o">+=</span> <span class="mi">1</span>
+
+        <span class="n">offset</span> <span class="o">+=</span> <span class="mi">2</span>  <span class="c1"># For the name field</span>
+        <span class="n">padding1</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
+        <span class="k">if</span> <span class="n">offset</span> <span class="o">%</span> <span class="mi">4</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
+            <span class="n">padding1</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="se">\0</span><span class="s1">&#39;</span><span class="o">*</span><span class="p">(</span><span class="mi">4</span><span class="o">-</span><span class="n">offset</span><span class="o">%</span><span class="mi">4</span><span class="p">)</span>
+
+        <span class="k">if</span> <span class="n">params_bytes_len</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
+            <span class="n">params_bytes_offset</span> <span class="o">=</span> <span class="n">offset</span>
+            <span class="n">offset</span> <span class="o">+=</span> <span class="n">params_bytes_len</span>
+        <span class="k">else</span><span class="p">:</span>
+            <span class="n">params_bytes_offset</span> <span class="o">=</span> <span class="mi">0</span>
+
+        <span class="n">padding2</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
+        <span class="k">if</span> <span class="n">offset</span> <span class="o">%</span> <span class="mi">4</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
+            <span class="n">padding2</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="se">\0</span><span class="s1">&#39;</span><span class="o">*</span><span class="p">(</span><span class="mi">4</span><span class="o">-</span><span class="n">offset</span><span class="o">%</span><span class="mi">4</span><span class="p">)</span>
+
+        <span class="k">if</span> <span class="n">data_bytes_len</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
+            <span class="n">data_bytes_offset</span> <span class="o">=</span> <span class="n">offset</span>
+        <span class="k">else</span><span class="p">:</span>
+            <span class="n">data_bytes_offset</span> <span class="o">=</span> <span class="mi">0</span>
+
+        <span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span> <span class="o">=</span> \
+            <span class="n">struct</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_FORMAT</span><span class="p">,</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">total_params_count</span><span class="p">,</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">total_data_count</span><span class="p">,</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">max_params_count</span><span class="p">,</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">max_data_count</span><span class="p">,</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">max_setup_count</span><span class="p">,</span>
+                        <span class="mh">0x00</span><span class="p">,</span>           <span class="c1"># Reserved1. Must be 0x00</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">,</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">timeout</span><span class="p">,</span>
+                        <span class="mh">0x0000</span><span class="p">,</span>         <span class="c1"># Reserved2. Must be 0x0000</span>
+                        <span class="n">params_bytes_len</span><span class="p">,</span>
+                        <span class="n">params_bytes_offset</span><span class="p">,</span>
+                        <span class="n">data_bytes_len</span><span class="p">,</span>
+                        <span class="n">data_bytes_offset</span><span class="p">,</span>
+                        <span class="nb">int</span><span class="p">(</span><span class="n">setup_bytes_len</span> <span class="o">/</span> <span class="mi">2</span><span class="p">))</span> <span class="o">+</span> \
+            <span class="bp">self</span><span class="o">.</span><span class="n">setup_bytes</span>
+
+        <span class="n">message</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">padding0</span> <span class="o">+</span> <span class="n">name</span> <span class="o">+</span> <span class="n">padding1</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">params_bytes</span> <span class="o">+</span> <span class="n">padding2</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_bytes</span>
+
+
+<span class="k">class</span> <span class="nc">ComTransaction2Response</span><span class="p">(</span><span class="n">Payload</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    Contains information about a SMB_COM_TRANSACTION2 response from the server</span>
+
+<span class="sd">    After decoding, each instance contains the following attributes:</span>
+<span class="sd">    - total_params_count (integer)</span>
+<span class="sd">    - total_data_count (integer)</span>
+<span class="sd">    - setup_bytes (string)</span>
+<span class="sd">    - data_bytes (string)</span>
+<span class="sd">    - params_bytes (string)</span>
+
+<span class="sd">    References:</span>
+<span class="sd">    ===========</span>
+<span class="sd">    - [MS-CIFS]: 2.2.4.46.2</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+
+    <span class="n">PAYLOAD_STRUCT_FORMAT</span> <span class="o">=</span> <span class="s1">&#39;&lt;HHHHHHHHHBB&#39;</span>
+    <span class="n">PAYLOAD_STRUCT_SIZE</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">calcsize</span><span class="p">(</span><span class="n">PAYLOAD_STRUCT_FORMAT</span><span class="p">)</span>
+
+    <span class="k">def</span> <span class="nf">decode</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="k">assert</span> <span class="n">message</span><span class="o">.</span><span class="n">command</span> <span class="o">==</span> <span class="n">SMB_COM_TRANSACTION2</span>
+
+        <span class="k">if</span> <span class="ow">not</span> <span class="n">message</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">hasError</span><span class="p">:</span>
+            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span><span class="p">)</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_SIZE</span><span class="p">:</span>
+                <span class="k">raise</span> <span class="n">ProtocolError</span><span class="p">(</span><span class="s1">&#39;Not enough data to decode SMB_COM_TRANSACTION2 parameters&#39;</span><span class="p">,</span> <span class="n">message</span><span class="o">.</span><span class="n">raw_data</span><span class="p">,</span> <span class="n">message</span><span class="p">)</span>
+
+            <span class="bp">self</span><span class="o">.</span><span class="n">total_params_count</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">total_data_count</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> \
+            <span class="n">params_bytes_len</span><span class="p">,</span> <span class="n">params_bytes_offset</span><span class="p">,</span> <span class="n">params_bytes_displ</span><span class="p">,</span> \
+            <span class="n">data_bytes_len</span><span class="p">,</span> <span class="n">data_bytes_offset</span><span class="p">,</span> <span class="n">data_bytes_displ</span><span class="p">,</span> \
+            <span class="n">setup_count</span><span class="p">,</span> <span class="n">_</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">unpack</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_FORMAT</span><span class="p">,</span> <span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span><span class="p">[:</span><span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_SIZE</span><span class="p">])</span>
+
+            <span class="k">if</span> <span class="n">setup_count</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
+                <span class="n">setup_bytes_len</span> <span class="o">=</span> <span class="n">setup_count</span> <span class="o">*</span> <span class="mi">2</span>
+
+                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span><span class="p">)</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_SIZE</span> <span class="o">+</span> <span class="n">setup_bytes_len</span><span class="p">:</span>
+                    <span class="k">raise</span> <span class="n">ProtocolError</span><span class="p">(</span><span class="s1">&#39;Not enough data to decode SMB_COM_TRANSACTION parameters&#39;</span><span class="p">,</span> <span class="n">message</span><span class="o">.</span><span class="n">raw_data</span><span class="p">,</span> <span class="n">message</span><span class="p">)</span>
+
+                <span class="bp">self</span><span class="o">.</span><span class="n">setup_bytes</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_SIZE</span><span class="p">:</span><span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_SIZE</span><span class="o">+</span><span class="n">setup_bytes_len</span><span class="p">]</span>
+            <span class="k">else</span><span class="p">:</span>
+                <span class="bp">self</span><span class="o">.</span><span class="n">setup_bytes</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
+
+            <span class="n">offset</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="n">HEADER_STRUCT_SIZE</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_SIZE</span> <span class="o">+</span> <span class="n">setup_count</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">+</span> <span class="mi">2</span> <span class="c1"># constant 2 is for the ByteCount field in the SMB header (i.e. field which indicates number of data bytes after the SMB parameters)</span>
+
+            <span class="k">if</span> <span class="n">params_bytes_len</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
+                <span class="bp">self</span><span class="o">.</span><span class="n">params_bytes</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">params_bytes_offset</span><span class="o">-</span><span class="n">offset</span><span class="p">:</span><span class="n">params_bytes_offset</span><span class="o">-</span><span class="n">offset</span><span class="o">+</span><span class="n">params_bytes_len</span><span class="p">]</span>
+            <span class="k">else</span><span class="p">:</span>
+                <span class="bp">self</span><span class="o">.</span><span class="n">params_bytes</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
+
+            <span class="k">if</span> <span class="n">data_bytes_len</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
+                <span class="bp">self</span><span class="o">.</span><span class="n">data_bytes</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">data_bytes_offset</span><span class="o">-</span><span class="n">offset</span><span class="p">:</span><span class="n">data_bytes_offset</span><span class="o">-</span><span class="n">offset</span><span class="o">+</span><span class="n">data_bytes_len</span><span class="p">]</span>
+            <span class="k">else</span><span class="p">:</span>
+                <span class="bp">self</span><span class="o">.</span><span class="n">data_bytes</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
+
+
+<span class="k">class</span> <span class="nc">ComCloseRequest</span><span class="p">(</span><span class="n">Payload</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    References:</span>
+<span class="sd">    ===========</span>
+<span class="sd">    - [MS-CIFS]: 2.2.4.5.1</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+
+    <span class="n">PAYLOAD_STRUCT_FORMAT</span> <span class="o">=</span> <span class="s1">&#39;&lt;HI&#39;</span>
+    <span class="n">PAYLOAD_STRUCT_SIZE</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">calcsize</span><span class="p">(</span><span class="n">PAYLOAD_STRUCT_FORMAT</span><span class="p">)</span>
+
+    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">fid</span><span class="p">,</span> <span class="n">last_modified_time</span> <span class="o">=</span> <span class="mh">0xFFFFFFFF</span><span class="p">):</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">fid</span> <span class="o">=</span> <span class="n">fid</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">last_modified_time</span> <span class="o">=</span> <span class="n">last_modified_time</span>
+
+    <span class="k">def</span> <span class="nf">initMessage</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="n">Payload</span><span class="o">.</span><span class="n">initMessage</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">)</span>
+        <span class="n">message</span><span class="o">.</span><span class="n">command</span> <span class="o">=</span> <span class="n">SMB_COM_CLOSE</span>
+
+    <span class="k">def</span> <span class="nf">prepare</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_FORMAT</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">fid</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">last_modified_time</span><span class="p">)</span>
+        <span class="n">message</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
+
+
+<span class="k">class</span> <span class="nc">ComOpenAndxRequest</span><span class="p">(</span><span class="n">Payload</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    References:</span>
+<span class="sd">    ===========</span>
+<span class="sd">    - [MS-CIFS]: 2.2.4.41.1</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+
+    <span class="n">PAYLOAD_STRUCT_FORMAT</span> <span class="o">=</span> <span class="s1">&#39;&lt;HHHHIHIII&#39;</span>
+    <span class="n">PAYLOAD_STRUCT_SIZE</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">calcsize</span><span class="p">(</span><span class="n">PAYLOAD_STRUCT_FORMAT</span><span class="p">)</span>
+
+    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">access_mode</span><span class="p">,</span> <span class="n">open_mode</span><span class="p">,</span> <span class="n">flags</span> <span class="o">=</span> <span class="mh">0x0000</span><span class="p">,</span> <span class="n">search_attributes</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">file_attributes</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">create_time</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">timeout</span> <span class="o">=</span> <span class="mi">0</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        @param create_time: Epoch time value to indicate the time of creation for this file. If zero, we will automatically assign the current time</span>
+<span class="sd">        @type create_time: int</span>
+<span class="sd">        @param timeout: Number of milliseconds to wait for blocked open request before failing</span>
+<span class="sd">        @type timeout: int</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">filename</span> <span class="o">=</span> <span class="n">filename</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">access_mode</span> <span class="o">=</span> <span class="n">access_mode</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">open_mode</span> <span class="o">=</span> <span class="n">open_mode</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">flags</span> <span class="o">=</span> <span class="n">flags</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">search_attributes</span> <span class="o">=</span> <span class="n">search_attributes</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">file_attributes</span> <span class="o">=</span> <span class="n">file_attributes</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">create_time</span> <span class="o">=</span> <span class="n">create_time</span> <span class="ow">or</span> <span class="nb">int</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">())</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">timeout</span> <span class="o">=</span> <span class="n">timeout</span>
+
+    <span class="k">def</span> <span class="nf">initMessage</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="n">Payload</span><span class="o">.</span><span class="n">initMessage</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">)</span>
+        <span class="n">message</span><span class="o">.</span><span class="n">command</span> <span class="o">=</span> <span class="n">SMB_COM_OPEN_ANDX</span>
+
+    <span class="k">def</span> <span class="nf">prepare</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span> <span class="o">=</span> \
+            <span class="bp">self</span><span class="o">.</span><span class="n">DEFAULT_ANDX_PARAM_HEADER</span> <span class="o">+</span> \
+            <span class="n">struct</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_FORMAT</span><span class="p">,</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">flags</span><span class="p">,</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">access_mode</span><span class="p">,</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">search_attributes</span><span class="p">,</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">file_attributes</span><span class="p">,</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">create_time</span><span class="p">,</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">open_mode</span><span class="p">,</span>
+                        <span class="mi">0</span><span class="p">,</span>  <span class="c1"># AllocationSize</span>
+                        <span class="mi">0</span><span class="p">,</span>  <span class="c1"># Timeout (in milli-secs)</span>
+                        <span class="mi">0</span><span class="p">)</span>  <span class="c1"># Reserved</span>
+
+        <span class="n">message</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="se">\0</span><span class="s1">&#39;</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">filename</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s1">&#39;UTF-16LE&#39;</span><span class="p">)</span> <span class="o">+</span> <span class="s1">&#39;</span><span class="se">\0\0</span><span class="s1">&#39;</span>
+
+
+<span class="k">class</span> <span class="nc">ComOpenAndxResponse</span><span class="p">(</span><span class="n">Payload</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    Contains information about a SMB_COM_OPEN_ANDX response from the server</span>
+
+<span class="sd">    After decoding, each instance will contain the following attributes:</span>
+<span class="sd">    - fid (integer)</span>
+<span class="sd">    - file_attributes (integer)</span>
+<span class="sd">    - last_write_time (long)</span>
+<span class="sd">    - access_rights (integer)</span>
+<span class="sd">    - resource_type (integer)</span>
+<span class="sd">    - open_results (integer)</span>
+
+<span class="sd">    References:</span>
+<span class="sd">    ===========</span>
+<span class="sd">    - [MS-CIFS]: 2.2.4.41.2</span>
+<span class="sd">    - [MS-SMB]: 2.2.4.1.2</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+
+    <span class="n">PAYLOAD_STRUCT_FORMAT</span> <span class="o">=</span> <span class="s1">&#39;&lt;BBHHHIIHHHHHHH&#39;</span>
+    <span class="n">PAYLOAD_STRUCT_SIZE</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">calcsize</span><span class="p">(</span><span class="n">PAYLOAD_STRUCT_FORMAT</span><span class="p">)</span>
+
+    <span class="k">def</span> <span class="nf">decode</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="k">assert</span> <span class="n">message</span><span class="o">.</span><span class="n">command</span> <span class="o">==</span> <span class="n">SMB_COM_OPEN_ANDX</span>
+
+        <span class="k">if</span> <span class="ow">not</span> <span class="n">message</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">hasError</span><span class="p">:</span>
+            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span><span class="p">)</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_SIZE</span><span class="p">:</span>
+                <span class="k">raise</span> <span class="n">ProtocolError</span><span class="p">(</span><span class="s1">&#39;Not enough data to decode SMB_COM_OPEN_ANDX parameters&#39;</span><span class="p">,</span> <span class="n">message</span><span class="o">.</span><span class="n">raw_data</span><span class="p">,</span> <span class="n">message</span><span class="p">)</span>
+
+            <span class="n">_</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">fid</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">file_attributes</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">last_write_time</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> \
+            <span class="bp">self</span><span class="o">.</span><span class="n">access_rights</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">resource_type</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">open_results</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">_</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">unpack</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_FORMAT</span><span class="p">,</span>
+                                                                                                  <span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span><span class="p">[:</span><span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_SIZE</span><span class="p">])</span>
+
+
+<span class="k">class</span> <span class="nc">ComWriteAndxRequest</span><span class="p">(</span><span class="n">Payload</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    References:</span>
+<span class="sd">    ===========</span>
+<span class="sd">    - [MS-CIFS]: 2.2.4.43.1</span>
+<span class="sd">    - [MS-SMB]: 2.2.4.3.1</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+
+    <span class="n">PAYLOAD_STRUCT_FORMAT</span> <span class="o">=</span> <span class="s1">&#39;&lt;HIIHHHHHI&#39;</span>
+    <span class="n">PAYLOAD_STRUCT_SIZE</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">calcsize</span><span class="p">(</span><span class="n">PAYLOAD_STRUCT_FORMAT</span><span class="p">)</span>
+
+    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">fid</span><span class="p">,</span> <span class="n">data_bytes</span><span class="p">,</span> <span class="n">offset</span><span class="p">,</span> <span class="n">write_mode</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">timeout</span> <span class="o">=</span> <span class="mi">0</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        @param timeout: Number of milliseconds to wait for blocked write request before failing. Must be zero for writing to regular file</span>
+<span class="sd">        @type timeout: int</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">fid</span> <span class="o">=</span> <span class="n">fid</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">offset</span> <span class="o">=</span> <span class="n">offset</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">data_bytes</span> <span class="o">=</span> <span class="n">data_bytes</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">timeout</span> <span class="o">=</span> <span class="n">timeout</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">write_mode</span> <span class="o">=</span> <span class="n">write_mode</span>
+
+    <span class="k">def</span> <span class="nf">initMessage</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="n">Payload</span><span class="o">.</span><span class="n">initMessage</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">)</span>
+        <span class="n">message</span><span class="o">.</span><span class="n">command</span> <span class="o">=</span> <span class="n">SMB_COM_WRITE_ANDX</span>
+
+    <span class="k">def</span> <span class="nf">prepare</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="c1"># constant 1 is to account for the pad byte in the message.data</span>
+        <span class="c1"># constant 2 is for the ByteCount field in the SMB header (i.e. field which indicates number of data bytes after the SMB parameters)</span>
+        <span class="n">data_offset</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="n">HEADER_STRUCT_SIZE</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">DEFAULT_ANDX_PARAM_SIZE</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_SIZE</span> <span class="o">+</span> <span class="mi">1</span> <span class="o">+</span> <span class="mi">2</span>
+        <span class="n">data_len</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data_bytes</span><span class="p">)</span>
+
+        <span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span> <span class="o">=</span> \
+            <span class="bp">self</span><span class="o">.</span><span class="n">DEFAULT_ANDX_PARAM_HEADER</span> <span class="o">+</span> \
+            <span class="n">struct</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_FORMAT</span><span class="p">,</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">fid</span><span class="p">,</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">offset</span> <span class="o">&amp;</span> <span class="mh">0xFFFFFFFF</span><span class="p">,</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">timeout</span><span class="p">,</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">write_mode</span><span class="p">,</span>
+                        <span class="n">data_len</span><span class="p">,</span>   <span class="c1"># Remaining</span>
+                        <span class="mh">0x0000</span><span class="p">,</span>     <span class="c1"># Reserved</span>
+                        <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data_bytes</span><span class="p">),</span>  <span class="c1"># DataLength</span>
+                        <span class="n">data_offset</span><span class="p">,</span>           <span class="c1"># DataOffset</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">offset</span> <span class="o">&gt;&gt;</span> <span class="mi">32</span><span class="p">)</span>     <span class="c1"># OffsetHigh field defined in [MS-SMB]: 2.2.4.3.1</span>
+
+        <span class="n">message</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="se">\0</span><span class="s1">&#39;</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_bytes</span>
+
+
+<span class="k">class</span> <span class="nc">ComWriteAndxResponse</span><span class="p">(</span><span class="n">Payload</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    References:</span>
+<span class="sd">    ===========</span>
+<span class="sd">    - [MS-CIFS]: 2.2.4.43.2</span>
+<span class="sd">    - [MS-SMB]: 2.2.4.3.2</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+
+    <span class="n">PAYLOAD_STRUCT_FORMAT</span> <span class="o">=</span> <span class="s1">&#39;&lt;BBHHHHH&#39;</span>  <span class="c1"># We follow the SMB_COM_WRITEX_ANDX server extensions in [MS-SMB]: 2.2.4.3.2</span>
+    <span class="n">PAYLOAD_STRUCT_SIZE</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">calcsize</span><span class="p">(</span><span class="n">PAYLOAD_STRUCT_FORMAT</span><span class="p">)</span>
+
+    <span class="k">def</span> <span class="nf">decode</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="k">assert</span> <span class="n">message</span><span class="o">.</span><span class="n">command</span> <span class="o">==</span> <span class="n">SMB_COM_WRITE_ANDX</span>
+
+        <span class="k">if</span> <span class="ow">not</span> <span class="n">message</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">hasError</span><span class="p">:</span>
+            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span><span class="p">)</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_SIZE</span><span class="p">:</span>
+                <span class="k">raise</span> <span class="n">ProtocolError</span><span class="p">(</span><span class="s1">&#39;Not enough data to decode SMB_COM_WRITE_ANDX parameters&#39;</span><span class="p">,</span> <span class="n">message</span><span class="o">.</span><span class="n">raw_data</span><span class="p">,</span> <span class="n">message</span><span class="p">)</span>
+
+            <span class="n">_</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">count</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">available</span><span class="p">,</span> <span class="n">high_count</span><span class="p">,</span> <span class="n">_</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">unpack</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_FORMAT</span><span class="p">,</span> <span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span><span class="p">[:</span><span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_SIZE</span><span class="p">])</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">count</span> <span class="o">=</span> <span class="p">(</span><span class="n">count</span> <span class="o">&amp;</span> <span class="mh">0xFFFF</span><span class="p">)</span> <span class="o">|</span> <span class="p">(</span><span class="n">high_count</span> <span class="o">&lt;&lt;</span> <span class="mi">16</span><span class="p">)</span>
+
+
+<span class="k">class</span> <span class="nc">ComReadAndxRequest</span><span class="p">(</span><span class="n">Payload</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    References:</span>
+<span class="sd">    ===========</span>
+<span class="sd">    - [MS-CIFS]: 2.2.4.42.1</span>
+<span class="sd">    - [MS-SMB]: 2.2.4.2.1</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+
+    <span class="n">PAYLOAD_STRUCT_FORMAT</span> <span class="o">=</span> <span class="s1">&#39;&lt;HIHHIHI&#39;</span>
+    <span class="n">PAYLOAD_STRUCT_SIZE</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">calcsize</span><span class="p">(</span><span class="n">PAYLOAD_STRUCT_FORMAT</span><span class="p">)</span>
+
+    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">fid</span><span class="p">,</span> <span class="n">offset</span><span class="p">,</span> <span class="n">max_return_bytes_count</span><span class="p">,</span> <span class="n">min_return_bytes_count</span><span class="p">,</span> <span class="n">timeout</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">remaining</span> <span class="o">=</span> <span class="mi">0</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        @param timeout: If reading from a regular file, this parameter must be 0.</span>
+<span class="sd">        @type timeout: int</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">fid</span> <span class="o">=</span> <span class="n">fid</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">remaining</span> <span class="o">=</span> <span class="n">remaining</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">max_return_bytes_count</span> <span class="o">=</span> <span class="n">max_return_bytes_count</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">min_return_bytes_count</span> <span class="o">=</span> <span class="n">min_return_bytes_count</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">offset</span> <span class="o">=</span> <span class="n">offset</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">timeout</span> <span class="o">=</span> <span class="n">timeout</span>
+
+    <span class="k">def</span> <span class="nf">initMessage</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="n">Payload</span><span class="o">.</span><span class="n">initMessage</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">)</span>
+        <span class="n">message</span><span class="o">.</span><span class="n">command</span> <span class="o">=</span> <span class="n">SMB_COM_READ_ANDX</span>
+
+    <span class="k">def</span> <span class="nf">prepare</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span> <span class="o">=</span> \
+            <span class="bp">self</span><span class="o">.</span><span class="n">DEFAULT_ANDX_PARAM_HEADER</span> <span class="o">+</span> \
+            <span class="n">struct</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_FORMAT</span><span class="p">,</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">fid</span><span class="p">,</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">offset</span> <span class="o">&amp;</span> <span class="mh">0xFFFFFFFF</span><span class="p">,</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">max_return_bytes_count</span><span class="p">,</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">min_return_bytes_count</span><span class="p">,</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">timeout</span> <span class="ow">or</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">max_return_bytes_count</span> <span class="o">&gt;&gt;</span> <span class="mi">32</span><span class="p">),</span>  <span class="c1"># Note that in [MS-SMB]: 2.2.4.2.1, this field can also act as MaxCountHigh field</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">remaining</span><span class="p">,</span> <span class="c1"># In [MS-CIFS]: 2.2.4.42.1, this field must be set to 0x0000</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">offset</span> <span class="o">&gt;&gt;</span> <span class="mi">32</span><span class="p">)</span>
+
+        <span class="n">message</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
+
+
+<span class="k">class</span> <span class="nc">ComReadAndxResponse</span><span class="p">(</span><span class="n">Payload</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    References:</span>
+<span class="sd">    ===========</span>
+<span class="sd">    - [MS-CIFS]: 2.2.4.42.2</span>
+<span class="sd">    - [MS-SMB]: 2.2.4.2.2</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+
+    <span class="n">PAYLOAD_STRUCT_FORMAT</span> <span class="o">=</span> <span class="s1">&#39;&lt;BBHHHHHHHHHHH&#39;</span>
+    <span class="n">PAYLOAD_STRUCT_SIZE</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">calcsize</span><span class="p">(</span><span class="n">PAYLOAD_STRUCT_FORMAT</span><span class="p">)</span>
+
+    <span class="k">def</span> <span class="nf">decode</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="k">assert</span> <span class="n">message</span><span class="o">.</span><span class="n">command</span> <span class="o">==</span> <span class="n">SMB_COM_READ_ANDX</span>
+
+        <span class="k">if</span> <span class="ow">not</span> <span class="n">message</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">hasError</span><span class="p">:</span>
+            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span><span class="p">)</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_SIZE</span><span class="p">:</span>
+                <span class="k">raise</span> <span class="n">ProtocolError</span><span class="p">(</span><span class="s1">&#39;Not enough data to decode SMB_COM_READ_ANDX parameters&#39;</span><span class="p">,</span> <span class="n">message</span><span class="o">.</span><span class="n">raw_data</span><span class="p">,</span> <span class="n">message</span><span class="p">)</span>
+
+            <span class="n">_</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_length</span><span class="p">,</span> <span class="n">data_offset</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">_</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">unpack</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_FORMAT</span><span class="p">,</span>
+                                                                                           <span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span><span class="p">[:</span><span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_SIZE</span><span class="p">])</span>
+
+            <span class="n">offset</span> <span class="o">=</span> <span class="n">data_offset</span> <span class="o">-</span> <span class="n">message</span><span class="o">.</span><span class="n">HEADER_STRUCT_SIZE</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_SIZE</span> <span class="o">-</span> <span class="mi">2</span>  <span class="c1"># constant 2 is for the ByteCount field in the SMB header (i.e. field which indicates number of data bytes after the SMB parameters)</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">offset</span><span class="p">:</span><span class="n">offset</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">data_length</span><span class="p">]</span>
+            <span class="k">assert</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">)</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_length</span>
+
+
+<span class="k">class</span> <span class="nc">ComDeleteRequest</span><span class="p">(</span><span class="n">Payload</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    References:</span>
+<span class="sd">    ===========</span>
+<span class="sd">    - [MS-CIFS]: 2.2.4.7.1</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+
+    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename_pattern</span><span class="p">,</span> <span class="n">search_attributes</span> <span class="o">=</span> <span class="mi">0</span><span class="p">):</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">filename_pattern</span> <span class="o">=</span> <span class="n">filename_pattern</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">search_attributes</span> <span class="o">=</span> <span class="n">search_attributes</span>
+
+    <span class="k">def</span> <span class="nf">initMessage</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="n">Payload</span><span class="o">.</span><span class="n">initMessage</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">)</span>
+        <span class="n">message</span><span class="o">.</span><span class="n">command</span> <span class="o">=</span> <span class="n">SMB_COM_DELETE</span>
+
+    <span class="k">def</span> <span class="nf">prepare</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="s1">&#39;&lt;H&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">search_attributes</span><span class="p">)</span>
+        <span class="n">message</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="se">\x04</span><span class="s1">&#39;</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">filename_pattern</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s1">&#39;UTF-16LE&#39;</span><span class="p">)</span> <span class="o">+</span> <span class="s1">&#39;</span><span class="se">\0\0</span><span class="s1">&#39;</span>
+
+
+<span class="k">class</span> <span class="nc">ComCreateDirectoryRequest</span><span class="p">(</span><span class="n">Payload</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    Although this command has been marked deprecated in [MS-CIFS], we continue to use it for its simplicity</span>
+<span class="sd">    as compared to its replacement TRANS2_CREATE_DIRECTORY sub-command [MS-CIFS]: 2.2.6.14</span>
+
+<span class="sd">    References:</span>
+<span class="sd">    ===========</span>
+<span class="sd">    - [MS-CIFS]: 2.2.4.1.1</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+
+    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">path</span><span class="p">):</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">path</span> <span class="o">=</span> <span class="n">path</span>
+
+    <span class="k">def</span> <span class="nf">initMessage</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="n">Payload</span><span class="o">.</span><span class="n">initMessage</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">)</span>
+        <span class="n">message</span><span class="o">.</span><span class="n">command</span> <span class="o">=</span> <span class="n">SMB_COM_CREATE_DIRECTORY</span>
+
+    <span class="k">def</span> <span class="nf">prepare</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
+        <span class="n">message</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="se">\x04</span><span class="s1">&#39;</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s1">&#39;UTF-16LE&#39;</span><span class="p">)</span> <span class="o">+</span> <span class="s1">&#39;</span><span class="se">\0\0</span><span class="s1">&#39;</span>
+
+
+<span class="k">class</span> <span class="nc">ComDeleteDirectoryRequest</span><span class="p">(</span><span class="n">Payload</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    References:</span>
+<span class="sd">    ===========</span>
+<span class="sd">    - [MS-CIFS]: 2.2.4.2.1</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+
+    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">path</span><span class="p">):</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">path</span> <span class="o">=</span> <span class="n">path</span>
+
+    <span class="k">def</span> <span class="nf">initMessage</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="n">Payload</span><span class="o">.</span><span class="n">initMessage</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">)</span>
+        <span class="n">message</span><span class="o">.</span><span class="n">command</span> <span class="o">=</span> <span class="n">SMB_COM_DELETE_DIRECTORY</span>
+
+    <span class="k">def</span> <span class="nf">prepare</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
+        <span class="n">message</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="se">\x04</span><span class="s1">&#39;</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s1">&#39;UTF-16LE&#39;</span><span class="p">)</span> <span class="o">+</span> <span class="s1">&#39;</span><span class="se">\0\0</span><span class="s1">&#39;</span>
+
+
+<span class="k">class</span> <span class="nc">ComRenameRequest</span><span class="p">(</span><span class="n">Payload</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    References:</span>
+<span class="sd">    ===========</span>
+<span class="sd">    - [MS-CIFS]: 2.2.4.8.1</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+
+    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">old_path</span><span class="p">,</span> <span class="n">new_path</span><span class="p">,</span> <span class="n">search_attributes</span> <span class="o">=</span> <span class="mi">0</span><span class="p">):</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">old_path</span> <span class="o">=</span> <span class="n">old_path</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">new_path</span> <span class="o">=</span> <span class="n">new_path</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">search_attributes</span> <span class="o">=</span> <span class="n">search_attributes</span>
+
+    <span class="k">def</span> <span class="nf">initMessage</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="n">Payload</span><span class="o">.</span><span class="n">initMessage</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">)</span>
+        <span class="n">message</span><span class="o">.</span><span class="n">command</span> <span class="o">=</span> <span class="n">SMB_COM_RENAME</span>
+
+    <span class="k">def</span> <span class="nf">prepare</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="s1">&#39;&lt;H&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">search_attributes</span><span class="p">)</span>
+        <span class="n">message</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="se">\x04</span><span class="s1">&#39;</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">old_path</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s1">&#39;UTF-16LE&#39;</span><span class="p">)</span> <span class="o">+</span> <span class="s1">&#39;</span><span class="se">\x00\x00\x04\x00</span><span class="s1">&#39;</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">new_path</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s1">&#39;UTF-16LE&#39;</span><span class="p">)</span> <span class="o">+</span> <span class="s1">&#39;</span><span class="se">\x00\x00</span><span class="s1">&#39;</span>
+
+
+<span class="k">class</span> <span class="nc">ComEchoRequest</span><span class="p">(</span><span class="n">Payload</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    References:</span>
+<span class="sd">    ===========</span>
+<span class="sd">    - [MS-CIFS]: 2.2.4.39.1</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+
+    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">echo_data</span> <span class="o">=</span> <span class="n">b</span><span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="n">echo_count</span> <span class="o">=</span> <span class="mi">1</span><span class="p">):</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">echo_count</span> <span class="o">=</span> <span class="n">echo_count</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">echo_data</span> <span class="o">=</span> <span class="n">echo_data</span>
+
+    <span class="k">def</span> <span class="nf">initMessage</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="n">Payload</span><span class="o">.</span><span class="n">initMessage</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">)</span>
+        <span class="n">message</span><span class="o">.</span><span class="n">command</span> <span class="o">=</span> <span class="n">SMB_COM_ECHO</span>
+        <span class="n">message</span><span class="o">.</span><span class="n">tid</span> <span class="o">=</span> <span class="mh">0xFFFF</span>
+
+    <span class="k">def</span> <span class="nf">prepare</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="s1">&#39;&lt;H&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">echo_count</span><span class="p">)</span>
+        <span class="n">message</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">echo_data</span>
+
+
+<span class="k">class</span> <span class="nc">ComEchoResponse</span><span class="p">(</span><span class="n">Payload</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    References:</span>
+<span class="sd">    ===========</span>
+<span class="sd">    - [MS-CIFS]: 2.2.4.39.2</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+
+    <span class="k">def</span> <span class="nf">decode</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">sequence_number</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">unpack</span><span class="p">(</span><span class="s1">&#39;&lt;H&#39;</span><span class="p">,</span> <span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span><span class="p">[:</span><span class="mi">2</span><span class="p">])[</span><span class="mi">0</span><span class="p">]</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="n">data</span>
+
+
+<span class="k">class</span> <span class="nc">ComNTTransactRequest</span><span class="p">(</span><span class="n">Payload</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    References:</span>
+<span class="sd">    ===========</span>
+<span class="sd">    - [MS-CIFS]: 2.2.4.62.1</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+    <span class="n">PAYLOAD_STRUCT_FORMAT</span> <span class="o">=</span> <span class="s1">&#39;&lt;BHIIIIIIIIBH&#39;</span>
+    <span class="n">PAYLOAD_STRUCT_SIZE</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">calcsize</span><span class="p">(</span><span class="n">PAYLOAD_STRUCT_FORMAT</span><span class="p">)</span>
+
+    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">function</span><span class="p">,</span> <span class="n">max_params_count</span><span class="p">,</span> <span class="n">max_data_count</span><span class="p">,</span> <span class="n">max_setup_count</span><span class="p">,</span>
+                 <span class="n">total_params_count</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">total_data_count</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span>
+                 <span class="n">params_bytes</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="n">setup_bytes</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="n">data_bytes</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span><span class="p">):</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">function</span> <span class="o">=</span> <span class="n">function</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">total_params_count</span> <span class="o">=</span> <span class="n">total_params_count</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">params_bytes</span><span class="p">)</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">total_data_count</span> <span class="o">=</span> <span class="n">total_data_count</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">data_bytes</span><span class="p">)</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">max_params_count</span> <span class="o">=</span> <span class="n">max_params_count</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">max_data_count</span> <span class="o">=</span> <span class="n">max_data_count</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">max_setup_count</span> <span class="o">=</span> <span class="n">max_setup_count</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">params_bytes</span> <span class="o">=</span> <span class="n">params_bytes</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">setup_bytes</span> <span class="o">=</span> <span class="n">setup_bytes</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">data_bytes</span> <span class="o">=</span> <span class="n">data_bytes</span>
+
+    <span class="k">def</span> <span class="nf">initMessage</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="n">Payload</span><span class="o">.</span><span class="n">initMessage</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">)</span>
+        <span class="n">message</span><span class="o">.</span><span class="n">command</span> <span class="o">=</span> <span class="n">SMB_COM_NT_TRANSACT</span>
+
+    <span class="k">def</span> <span class="nf">prepare</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="n">setup_bytes_len</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">setup_bytes</span><span class="p">)</span>
+        <span class="n">params_bytes_len</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">params_bytes</span><span class="p">)</span>
+        <span class="n">data_bytes_len</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data_bytes</span><span class="p">)</span>
+
+        <span class="n">padding0</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
+        <span class="n">offset</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="n">HEADER_STRUCT_SIZE</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_SIZE</span> <span class="o">+</span> <span class="n">setup_bytes_len</span> <span class="o">+</span> <span class="mi">2</span> <span class="c1"># constant 2 is for the ByteCount field in the SMB header (i.e. field which indicates number of data bytes after the SMB parameters)</span>
+        <span class="k">if</span> <span class="n">offset</span> <span class="o">%</span> <span class="mi">4</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
+            <span class="n">padding0</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="se">\0</span><span class="s1">&#39;</span><span class="o">*</span><span class="p">(</span><span class="mi">4</span><span class="o">-</span><span class="n">offset</span><span class="o">%</span><span class="mi">4</span><span class="p">)</span>
+            <span class="n">offset</span> <span class="o">+=</span> <span class="p">(</span><span class="mi">4</span><span class="o">-</span><span class="n">offset</span><span class="o">%</span><span class="mi">4</span><span class="p">)</span>
+
+        <span class="k">if</span> <span class="n">params_bytes_len</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
+            <span class="n">params_bytes_offset</span> <span class="o">=</span> <span class="n">offset</span>
+        <span class="k">else</span><span class="p">:</span>
+            <span class="n">params_bytes_offset</span> <span class="o">=</span> <span class="mi">0</span>
+
+        <span class="n">offset</span> <span class="o">+=</span> <span class="n">params_bytes_len</span>
+        <span class="n">padding1</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
+        <span class="k">if</span> <span class="n">offset</span> <span class="o">%</span> <span class="mi">4</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
+            <span class="n">padding1</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="se">\0</span><span class="s1">&#39;</span><span class="o">*</span><span class="p">(</span><span class="mi">4</span><span class="o">-</span><span class="n">offset</span><span class="o">%</span><span class="mi">4</span><span class="p">)</span>
+            <span class="n">offset</span> <span class="o">+=</span> <span class="p">(</span><span class="mi">4</span><span class="o">-</span><span class="n">offset</span><span class="o">%</span><span class="mi">4</span><span class="p">)</span>
+
+        <span class="k">if</span> <span class="n">data_bytes_len</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
+            <span class="n">data_bytes_offset</span> <span class="o">=</span> <span class="n">offset</span>
+        <span class="k">else</span><span class="p">:</span>
+            <span class="n">data_bytes_offset</span> <span class="o">=</span> <span class="mi">0</span>
+
+        <span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span> <span class="o">=</span> \
+            <span class="n">struct</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_FORMAT</span><span class="p">,</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">max_setup_count</span><span class="p">,</span>
+                        <span class="mh">0x00</span><span class="p">,</span>           <span class="c1"># Reserved1. Must be 0x00</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">total_params_count</span><span class="p">,</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">total_data_count</span><span class="p">,</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">max_params_count</span><span class="p">,</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">max_data_count</span><span class="p">,</span>
+                        <span class="n">params_bytes_len</span><span class="p">,</span>
+                        <span class="n">params_bytes_offset</span><span class="p">,</span>
+                        <span class="n">data_bytes_len</span><span class="p">,</span>
+                        <span class="n">data_bytes_offset</span><span class="p">,</span>
+                        <span class="nb">int</span><span class="p">(</span><span class="n">setup_bytes_len</span> <span class="o">/</span> <span class="mi">2</span><span class="p">),</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">function</span><span class="p">)</span> <span class="o">+</span> \
+            <span class="bp">self</span><span class="o">.</span><span class="n">setup_bytes</span>
+
+        <span class="n">message</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">padding0</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">params_bytes</span> <span class="o">+</span> <span class="n">padding1</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_bytes</span>
+
+
+<span class="k">class</span> <span class="nc">ComNTTransactResponse</span><span class="p">(</span><span class="n">Payload</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    Contains information about a SMB_COM_NT_TRANSACT response from the server</span>
+
+<span class="sd">    After decoding, each instance contains the following attributes:</span>
+<span class="sd">    - total_params_count (integer)</span>
+<span class="sd">    - total_data_count (integer)</span>
+<span class="sd">    - setup_bytes (string)</span>
+<span class="sd">    - data_bytes (string)</span>
+<span class="sd">    - params_bytes (string)</span>
+
+<span class="sd">    References:</span>
+<span class="sd">    ===========</span>
+<span class="sd">    - [MS-CIFS]: 2.2.4.62.2</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+    <span class="n">PAYLOAD_STRUCT_FORMAT</span> <span class="o">=</span> <span class="s1">&#39;&lt;3sIIIIIIIIBH&#39;</span>
+    <span class="n">PAYLOAD_STRUCT_SIZE</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">calcsize</span><span class="p">(</span><span class="n">PAYLOAD_STRUCT_FORMAT</span><span class="p">)</span>
+
+    <span class="k">def</span> <span class="nf">decode</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
+        <span class="k">assert</span> <span class="n">message</span><span class="o">.</span><span class="n">command</span> <span class="o">==</span> <span class="n">SMB_COM_NT_TRANSACT</span>
+
+        <span class="k">if</span> <span class="ow">not</span> <span class="n">message</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">hasError</span><span class="p">:</span>
+            <span class="n">_</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">total_params_count</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">total_data_count</span><span class="p">,</span> \
+            <span class="n">params_count</span><span class="p">,</span> <span class="n">params_offset</span><span class="p">,</span> <span class="n">params_displ</span><span class="p">,</span> \
+            <span class="n">data_count</span><span class="p">,</span> <span class="n">data_offset</span><span class="p">,</span> <span class="n">data_displ</span><span class="p">,</span> <span class="n">setup_count</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">unpack</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_FORMAT</span><span class="p">,</span>
+                                                                             <span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span><span class="p">[:</span><span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_SIZE</span><span class="p">])</span>
+
+            <span class="bp">self</span><span class="o">.</span><span class="n">setup_bytes</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="n">parameters_data</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_SIZE</span><span class="p">:</span><span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_SIZE</span><span class="o">+</span><span class="n">setup_count</span><span class="o">*</span><span class="mi">2</span><span class="p">]</span>
+
+            <span class="k">if</span> <span class="n">params_count</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
+                <span class="n">params_offset</span> <span class="o">-=</span> <span class="n">message</span><span class="o">.</span><span class="n">HEADER_STRUCT_SIZE</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_SIZE</span> <span class="o">+</span> <span class="n">setup_count</span><span class="o">*</span><span class="mi">2</span> <span class="o">+</span> <span class="mi">2</span>
+                <span class="bp">self</span><span class="o">.</span><span class="n">params_bytes</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">params_offset</span><span class="p">:</span><span class="n">params_offset</span><span class="o">+</span><span class="n">params_count</span><span class="p">]</span>
+            <span class="k">else</span><span class="p">:</span>
+                <span class="bp">self</span><span class="o">.</span><span class="n">params_bytes</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
+
+            <span class="k">if</span> <span class="n">data_count</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
+                <span class="n">data_offset</span> <span class="o">-=</span> <span class="n">message</span><span class="o">.</span><span class="n">HEADER_STRUCT_SIZE</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">PAYLOAD_STRUCT_SIZE</span> <span class="o">+</span> <span class="n">setup_count</span><span class="o">*</span><span class="mi">2</span> <span class="o">+</span> <span class="mi">2</span>
+                <span class="bp">self</span><span class="o">.</span><span class="n">data_bytes</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">data_offset</span><span class="p">:</span><span class="n">data_offset</span><span class="o">+</span><span class="n">data_count</span><span class="p">]</span>
+            <span class="k">else</span><span class="p">:</span>
+                <span class="bp">self</span><span class="o">.</span><span class="n">data_bytes</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
+</pre></div>
+
+          </div>
+        </div>
+      </div>
+      <div class="clearer"></div>
+    </div>
+    <div class="related" role="navigation" aria-label="related navigation">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="../../genindex.html" title="General Index"
+             >index</a></li>
+        <li class="right" >
+          <a href="../../py-modindex.html" title="Python Module Index"
+             >modules</a> |</li>
+        <li class="nav-item nav-item-0"><a href="../../index.html">pysmb 1.1.25 documentation</a> &raquo;</li>
+          <li class="nav-item nav-item-1"><a href="../index.html" >Module code</a> &raquo;</li> 
+      </ul>
+    </div>
+    <div class="footer" role="contentinfo">
+        &copy; Copyright 2001-2018, Michael Teo http://miketeo.net/.
+      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.6.
+    </div>
+  </body>
+</html>
\ No newline at end of file
diff --git a/docs/html/_sources/api/nmb_NBNSProtocol.txt b/docs/html/_sources/api/nmb_NBNSProtocol.txt
new file mode 100644
index 00000000..94323fe2
--- /dev/null
+++ b/docs/html/_sources/api/nmb_NBNSProtocol.txt
@@ -0,0 +1,18 @@
+
+NBNSProtocol Class
+==================
+
+pysmb has a *NBNSProtocol* implementation for Twisted framework.
+This allows you to perform name query asynchronously without having your application to block and wait for the results.
+
+In your project,
+ 1. Create a NBNSProtocol instance.
+ 2. Just call *queryName* method which will return a *Deferred* instance. Add your callback function to the *Deferred* instance via *addCallback* method to receive the results of the name query.
+ 3. When you are done with the NBNSProtocol instance, call its <NBNSProtocol instance>.transport.stopListening method to remove this instance from the reactor.
+
+.. autoclass:: nmb.NetBIOSProtocol.NBNSProtocol
+    :members:
+    :special-members:
+
+.. autoclass:: nmb.NetBIOSProtocol.NetBIOSTimeout
+    :members:
diff --git a/docs/html/_sources/api/nmb_NetBIOS.txt b/docs/html/_sources/api/nmb_NetBIOS.txt
new file mode 100644
index 00000000..2949d952
--- /dev/null
+++ b/docs/html/_sources/api/nmb_NetBIOS.txt
@@ -0,0 +1,12 @@
+
+NetBIOS class
+=============
+
+To use the NetBIOS class in your application,
+ 1. Create a new NetBIOS instance
+ 2. Call *queryName* method for each name you wish to query. The method will block until a reply is received from the remote SMB/CIFS service, or until timeout.
+ 3. When you are done, call *close* method to release the underlying resources.
+
+.. autoclass:: nmb.NetBIOS.NetBIOS
+    :members:
+    :special-members:
diff --git a/docs/html/_sources/api/smb_SMBConnection.txt b/docs/html/_sources/api/smb_SMBConnection.txt
new file mode 100644
index 00000000..44782103
--- /dev/null
+++ b/docs/html/_sources/api/smb_SMBConnection.txt
@@ -0,0 +1,55 @@
+
+SMBConnection Class
+===================
+
+The SMBConnection is suitable for developers who wish to use pysmb to perform file operations with a remote SMB/CIFS server sequentially.
+
+Each file operation method, when invoked, will block and return after it has completed or has encountered an error.
+
+Example
+-------
+
+The following illustrates a simple file retrieving implementation.::
+
+    import tempfile
+    from smb.SMBConnection import SMBConnection
+
+    # There will be some mechanism to capture userID, password, client_machine_name, server_name and server_ip
+    # client_machine_name can be an arbitary ASCII string
+    # server_name should match the remote machine name, or else the connection will be rejected
+    conn = SMBConnection(userID, password, client_machine_name, server_name, use_ntlm_v2 = True)
+    assert conn.connect(server_ip, 139)
+
+    file_obj = tempfile.NamedTemporaryFile()
+    file_attributes, filesize = conn.retrieveFile('smbtest', '/rfc1001.txt', file_obj)
+
+    # Retrieved file contents are inside file_obj
+    # Do what you need with the file_obj and then close it
+    # Note that the file obj is positioned at the end-of-file,
+    # so you might need to perform a file_obj.seek() if you need
+    # to read from the beginning
+    file_obj.close()
+
+SMB2 Support
+-------------
+
+Starting from pysmb 1.1.0, pysmb will utilize SMB2 protocol for communication if the remote SMB/CIFS service supports SMB2.
+Otherwise, it will fallback automatically back to using SMB1 protocol.
+
+To disable SMB2 protocol in pysmb, set the *SUPPORT_SMB2* flag in the *smb_structs* module to *False* before creating the *SMBConnection* instance.::
+
+    from smb import smb_structs
+    smb_structs.SUPPORT_SMB2 = False
+
+Caveats
+-------
+
+* It is not meant to be used asynchronously.
+* A single *SMBConnection* instance should not be used to perform more than one operation concurrently at the same time.
+* Do not keep a *SMBConnection* instance "idle" for too long, i.e. keeping a *SMBConnection* instance but not using it.
+  Most SMB/CIFS servers have some sort of keepalive mechanism and impose a timeout limit.
+  If the clients fail to respond within the timeout limit, the SMB/CIFS server may disconnect the client.
+
+.. autoclass:: smb.SMBConnection.SMBConnection
+    :members:
+    :special-members:
diff --git a/docs/html/_sources/api/smb_SMBHandler.txt b/docs/html/_sources/api/smb_SMBHandler.txt
new file mode 100644
index 00000000..da106fee
--- /dev/null
+++ b/docs/html/_sources/api/smb_SMBHandler.txt
@@ -0,0 +1,48 @@
+
+SMbHandler Class
+================
+
+The SMBHandler class provides support for "smb://" URLs in the `urllib2 <http://docs.python.org/library/urllib2.html>`_ python package.
+
+Notes
+-----
+* Note that you need to pass in a valid hostname or IP address for the host component of the URL.
+  Do not use the Windows/NetBIOS machine name for the host component.
+* The first component of the path in the URL points to the name of the shared folder.
+  Subsequent path components will point to the directory/folder of the file.
+* You can retrieve and upload files, but you cannot delete files/folders or create folders.
+  In uploads, if the parent folders do not exist, an *urllib2.URLError* will be raised.
+
+Example
+-------
+
+The following code snippet illustrates file retrieval.::
+
+    # -*- coding: utf-8 -*-
+    import urllib2
+    from smb.SMBHandler import SMBHandler
+
+    director = urllib2.build_opener(SMBHandler)
+    fh = director.open('smb://myuserID:mypassword@192.168.1.1/sharedfolder/rfc1001.txt')
+
+    # Process fh like a file-like object and then close it.
+    fh.close()
+
+    # For paths/files with unicode characters, simply pass in the URL as an unicode string
+    fh2 = director.open(u'smb://myuserID:mypassword@192.168.1.1/sharedfolder/测试文件夹/垃圾文件.dat')
+
+    # Process fh2 like a file-like object and then close it.
+    fh2.close()
+
+The following code snippet illustrates file upload. You need to provide a file-like object for the *data* parameter in the *open()* method::
+
+    import urllib2
+    from smb.SMBHandler import SMBHandler
+
+    file_fh = open('local_file.dat', 'rb')
+
+    director = urllib2.build_opener(SMBHandler)
+    fh = director.open('smb://myuserID:mypassword@192.168.1.1/sharedfolder/upload_file.dat', data = file_fh)
+
+    # Reading from fh will only return an empty string
+    fh.close()
diff --git a/docs/html/_sources/api/smb_SMBProtocolFactory.txt b/docs/html/_sources/api/smb_SMBProtocolFactory.txt
new file mode 100644
index 00000000..dc967c39
--- /dev/null
+++ b/docs/html/_sources/api/smb_SMBProtocolFactory.txt
@@ -0,0 +1,93 @@
+
+SMBProtocolFactory Class
+========================
+
+For those who want to utilize pysmb in Twisted framework, pysmb has a *smb.SMBProtocol.SMBProtocol* implementation.
+In most cases, you do not need to touch or import the *SMBProtocol* directly. All the SMB functionalities are exposed in the *SMBProtocolFactory*.
+
+In your project,
+ 1. Create a new class and subclass *SMBProtocolFactory*.
+ 2. Override the *SMBProtocolFactory.onAuthOK* and *SMBProtocolFactory.onAuthFailed* instance methods to provide your own post-authenthentication handling.
+    Once *SMBProtocolFactory.onAuthOK* has been called by pymsb internals, your application is ready to communicate with the remote SMB/CIFS service through
+    the *SMBProtocolFactory* public methods such as *SMBProtocolFactory.storeFile*, *SMBProtocolFactory.retrieveFile*, etc.
+ 3. When you want to disconnect from the remote SMB/CIFS server, just call *SMBProtocolFactory.closeConnection* method.
+
+All the *SMBProtocolFactory* public methods that provide file functionlities will return a *twisted.internet.defer.Deferred* instance.
+A :doc:`NotReadyError<smb_exceptions>` exception is raised when the underlying SMB is not authenticated.
+If the underlying SMB connection has been terminated, a :doc:`NotConnectedError<smb_exceptions>` exception is raised.
+
+All the file operation methods in *SMBProtocolFactory* class accept a *timeout* parameter. This parameter specifies the time limit where pysmb will wait for the
+entire file operation (except *storeFile* and *retrieveFile* methods) to complete. If the file operation fails to complete within the timeout period, the returned
+*Deferred* instance's *errback* method will be called with a *SMBTimeout* exception.
+
+If you are interested in learning the results of the operation or to know when the operation has completed, you should
+add a handling method to the returned *Deferred* instance via *Deferred.addCallback*. If the file operation fails, the *Deferred.errback* function will be called
+with an :doc:`OperationFailure<smb_exceptions>`; on timeout, it will be called with a :doc:`SMBTimeout<smb_exceptions>`.
+
+Example
+-------
+
+The following illustrates a simple file retrieving implementation.::
+
+    import tempfile
+    from twisted.internet import reactor
+    from smb.SMBProtocol import SMBProtocolFactory
+
+    class RetrieveFileFactory(SMBProtocolFactory):
+
+        def __init__(self, *args, **kwargs):
+            SMBProtocolFactory.__init__(self, *args, **kwargs)
+
+        def fileRetrieved(self, write_result):
+            file_obj, file_attributes, file_size = write_result
+
+            # Retrieved file contents are inside file_obj
+            # Do what you need with the file_obj and then close it
+            # Note that the file obj is positioned at the end-of-file,
+            # so you might need to perform a file_obj.seek() to if you
+            # need to read from the beginning
+            file_obj.close()
+
+            self.transport.loseConnection()
+
+        def onAuthOK(self):
+            d = self.retrieveFile(self.service, self.path, tempfile.NamedTemporaryFile())
+            d.addCallback(self.fileRetrieved)
+            d.addErrback(self.d.errback)
+
+        def onAuthFailed(self):
+            print 'Auth failed'
+
+    # There will be some mechanism to capture userID, password, client_machine_name, server_name and server_ip
+    # client_machine_name can be an arbitary ASCII string
+    # server_name should match the remote machine name, or else the connection will be rejected
+    factory = RetrieveFileFactory(userID, password, client_machine_name, server_name, use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.path = '/rfc1001.txt'
+    reactor.connectTCP(server_ip, 139, factory)
+
+
+
+
+SMB2 Support
+-------------
+
+Starting from pysmb 1.1.0, pysmb will utilize SMB2 protocol for communication if the remote SMB/CIFS service supports SMB2.
+Otherwise, it will fallback automatically back to using SMB1 protocol.
+
+To disable SMB2 protocol in pysmb, set the *SUPPORT_SMB2* flag in the *smb_structs* module to *False* before creating the *SMBProtocolFactory* instance.::
+
+    from smb import smb_structs
+    smb_structs.SUPPORT_SMB2 = False
+
+Caveats
+-------
+
+* A new factory instance must be created for each SMB connection to the remote SMB/CIFS service. Avoid reusing the same factory instance for more than one SMB connection.
+* The remote SMB/CIFS server usually imposes a limit of the number of concurrent file operations for each client. For example, to transfer a thousand files, you may need to setup a queue in your application and call *storeFile* or *retrieveFile* in batches.
+* The *timeout* parameter in the file operation methods are not precise; it is accurate to within 1 second interval, i.e. with a timeout of 0.5 sec, pysmb might raise
+  *SMBTimeout* exception after 1.5 sec.
+
+.. autoclass:: smb.SMBProtocol.SMBProtocolFactory
+    :members:
+    :special-members:
diff --git a/docs/html/_sources/api/smb_SharedDevice.txt b/docs/html/_sources/api/smb_SharedDevice.txt
new file mode 100644
index 00000000..9ac39b7e
--- /dev/null
+++ b/docs/html/_sources/api/smb_SharedDevice.txt
@@ -0,0 +1,6 @@
+
+SharedDevice Class
+==================
+
+.. autoclass:: smb.base.SharedDevice
+    :members:
diff --git a/docs/html/_sources/api/smb_SharedFile.txt b/docs/html/_sources/api/smb_SharedFile.txt
new file mode 100644
index 00000000..d71e43ca
--- /dev/null
+++ b/docs/html/_sources/api/smb_SharedFile.txt
@@ -0,0 +1,6 @@
+
+SharedFile Class
+================
+
+.. autoclass:: smb.base.SharedFile
+    :members:
diff --git a/docs/html/_sources/api/smb_exceptions.txt b/docs/html/_sources/api/smb_exceptions.txt
new file mode 100644
index 00000000..73406390
--- /dev/null
+++ b/docs/html/_sources/api/smb_exceptions.txt
@@ -0,0 +1,21 @@
+
+SMB Exceptions
+==============
+
+.. autoclass:: smb.base.SMBTimeout
+    :members:
+
+.. autoclass:: smb.base.NotReadyError
+    :members:
+
+.. autoclass:: smb.base.NotConnectedError
+    :members:
+
+.. autoclass:: smb.smb_structs.UnsupportedFeature
+    :members:
+
+.. autoclass:: smb.smb_structs.ProtocolError
+    :members:
+
+.. autoclass:: smb.smb_structs.OperationFailure
+    :members:
diff --git a/docs/html/_sources/api/smb_security_descriptors.txt b/docs/html/_sources/api/smb_security_descriptors.txt
new file mode 100644
index 00000000..0f048fe8
--- /dev/null
+++ b/docs/html/_sources/api/smb_security_descriptors.txt
@@ -0,0 +1,23 @@
+
+Security Descriptors
+====================
+
+.. module:: smb.security_descriptors
+   :synopsis: Data structures used in Windows security descriptors.
+
+This module implements security descriptors, and associated data
+structures, as specified in `[MS-DTYP]`_.
+
+.. autoclass:: SID
+   :members:
+
+.. autoclass:: ACE
+   :members:
+
+.. autoclass:: ACL
+   :members:
+
+.. autoclass:: SecurityDescriptor
+   :members:
+
+.. _[MS-DTYP]: https://msdn.microsoft.com/en-us/library/cc230273.aspx
diff --git a/docs/html/_sources/extending.txt b/docs/html/_sources/extending.txt
new file mode 100644
index 00000000..9945212e
--- /dev/null
+++ b/docs/html/_sources/extending.txt
@@ -0,0 +1,19 @@
+
+Extending pysmb For Other Frameworks
+====================================
+
+This page briefly describes the steps involved in extending pysmb for other frameworks.
+
+In general, you need to take care of the SMB TCP connection setup, i.e. finding the IP address of the remote server and connect to the SMB/CIFS service.
+Then you need to read/write synchronously or asynchronously from and to the SMB socket. And you need to handle post-authentication callback methods, and from these methods,
+initiate file operations with the remote SMB/CIFS server.
+
+Now the above steps in more technical details:
+ 1. Create a new class which subclasses the *smb.base.SMB* class. Most often, the connection setup will be part of the *__init__* method.
+ 2. Override the *write(self, data)* method to provide an implementation which will write *data* to the socket.
+ 3. Write your own loop handling method to read data from the socket. Once data have been read, call *feedData* method with the parameter.
+    The *feedData* method has its own internal buffer, so it can accept incomplete NetBIOS session packet data.
+ 4. Override
+   * *onAuthOK* method to include your own operations to perform when authentication is successful. You can initiate file operations in this method.
+   * *onAuthFailed* method to include your own processing on what to do when authentication fails. You can report this as an error, or to try a different NTLM authentication algorithm (*use_ntlm_v2* parameter in the constructor).
+   * *onNMBSessionFailed* method to include your own processing on what to do when pysmb fails to setup the NetBIOS session with the remote server. Usually, this is due to a wrong *remote_name* parameter in the constructor.
diff --git a/docs/html/_sources/index.txt b/docs/html/_sources/index.txt
new file mode 100644
index 00000000..7638fcd8
--- /dev/null
+++ b/docs/html/_sources/index.txt
@@ -0,0 +1,106 @@
+.. pysmb documentation master file, created by
+   sphinx-quickstart on Sun Dec 18 15:54:40 2011.
+   You can adapt this file completely to your liking, but it should at least
+   contain the root `toctree` directive.
+
+Welcome to pysmb's documentation!
+=================================
+
+pysmb is a pure Python implementation of the client-side SMB/CIFS protocol (SMB1 and SMB2) which is the underlying protocol
+that facilitates file sharing and printing between Windows machines, as well as with Linux machines via the Samba server application.
+pysmb is developed in Python 2.4.6, Python 2.7.1 and Python 3.2.3 and has been tested against shared folders on Windows XP SP3, Windows Vista, Windows 7 and Samba 3.x.
+
+The latest version of pysmb is always available at the pysmb project page at `miketeo.net <http://miketeo.net/wp/index.php/projects/pysmb>`_.
+
+License
+-------
+pysmb itself is licensed under an opensource license.
+You are free to use pysmb in any applications, including for commercial purposes.
+For more details on the terms of use, please read the LICENSE file that comes with your pysmb source.
+
+pysmb depends on other 3rd-party modules whose terms of use are not covered by pysmb.
+Use of these modules could possibly conflict with your licensing needs. Please exercise your own discretion to determine their suitabilities.
+I have listed these modules in the following section.
+
+Credits
+-------
+pysmb is not alone. It is made possible with support from other modules.
+
+* **pyasn1** : Pure Python implementation of ASN.1 parsing and encoding (not included together with pysmb; needs to be installed separately)
+* **md4** and **U32** : Pure Python implementation of MD4 hashing algorithm and 32-bit unsigned integer by Dmitry Rozmanov. Licensed under LGPL and included together with pysmb.
+* **pyDes** : Pure Python implementation of the DES encryption algorithm by Todd Whiteman. Free domain and included together with pysmb.
+* **sha256** : Pure Python implementation of SHA-256 message digest by Thomas Dixon. Licensed under MIT and included together with pysmb. This module is imported only when
+  the Python standard library (usually Python 2.4) does not provide the SHA-256 hash algorithm.
+
+In various places, there are references to different specifications. Most of these referenced specifications
+can be downloaded from Microsoft web site under Microsoft's "Open Specification Promise". If you need to download
+a copy of these specifications, please google for it. For example, google for "MS-CIFS" to download the CIFS specification for NT LM dialect.
+
+Package Contents and Description
+================================
+
+pysmb is organized into 2 main packages: smb and nmb.
+The smb package contains all the functionalities related to Server Message Block (SMB) implementation.
+As an application developer, you will be importing this module into your application.
+Hence, please take some time to familiarize yourself with the smb package contents.
+
+* **nmb/base.py** :
+  Contains the NetBIOSSession and NBNS abstract class which implements NetBIOS session and NetBIOS Name Service communication
+  without any network transport specifics.
+* **nmb/NetBIOS.py**:
+  Provides a NBNS implementation to query IP addresses for machine names. All operations are blocking I/O.
+* **nmb/NetBIOSProtocol.py** :
+  Provides the NBNS protocol implementation for use in Twisted framework.
+
+* **smb/base.py** :
+  Contains the SMB abstract class which implements the SMB communication without any network transport specifics.
+* **smb/ntlm.py** :
+  Contains the NTLMv1 and NTLMv2 authentication routines and the decoding/encoding of NTLM authentication messages within SMB messages.
+* **smb/securityblob.py** :
+  Provides routines to encode/decode the NTLMSSP security blob in the SMB messages.
+* **smb/smb_constants.py** :
+  All the constants used in the smb package for SMB1 protocol
+* **smb/smb_structs.py** :
+  Contains the internal classes used in the SMB package for SMB1 protocol. These classes are usually used to encode/decode the parameter and data blocks of specific SMB1 message.
+* **smb/smb2_constants.py** :
+  All the constants used in the smb package for SMB2 protocol
+* **smb/smb2_structs.py** :
+  Contains the internal classes used in the SMB package for SMB2 protocol. These classes are usually used to encode/decode the parameter and data blocks of specific SMB2 message.
+* **smb/SMBConnection.py** :
+  Contains a SMB protocol implementation. All operations are blocking I/O.
+* **smb/SMBProtocol.py** :
+  Contains the SMB protocol implementation for use in the Twisted framework.
+* **smb/SMBHandler.py** :
+  Provides support for "smb://" URL in the urllib2 python package.
+
+Using pysmb
+===========
+
+As an application developer who is looking to use pysmb to translate NetBIOS names to IP addresses,
+ * To use pysmb in applications where you want the file operations to return after they have completed (synchronous style), please read
+   :doc:`nmb.NetBIOS.NetBIOS<api/nmb_NetBIOS>` documentation.
+ * To use pysmb in Twisted, please read :doc:`nmb.NetBIOSProtocol.NBNSProtocol<api/nmb_NBNSProtocol>` documentation.
+
+As an application developer who is looking to use pysmb to implement file transfer or authentication over SMB:
+ * To use pysmb in applications where you want the file operations to return after they have completed (synchronous style), please read
+   :doc:`smb.SMBConnection.SMBConnection<api/smb_SMBConnection>` documentation.
+ * To use pysmb in Twisted, please read :doc:`smb.SMBProtocol.SMBProtocolFactory<api/smb_SMBProtocolFactory>` documentation.
+ * To support "smb://" URL in urllib2 python package, read :doc:`smb.SMBHandler.SMBHandler<api/smb_SMBHandler>` documentation.
+
+As a software developer who is looking to modify pysmb so that you can integrate it to other network frameworks:
+ * Read :doc:`extending`
+
+
+
+Indices and tables
+==================
+
+.. toctree::
+    :glob:
+    :maxdepth: 1
+
+    api/*
+    extending
+
+* :ref:`genindex`
+* :ref:`search`
diff --git a/docs/html/_static/ajax-loader.gif b/docs/html/_static/ajax-loader.gif
new file mode 100644
index 00000000..61faf8ca
Binary files /dev/null and b/docs/html/_static/ajax-loader.gif differ
diff --git a/docs/html/_static/basic.css b/docs/html/_static/basic.css
new file mode 100644
index 00000000..c89fc7e9
--- /dev/null
+++ b/docs/html/_static/basic.css
@@ -0,0 +1,599 @@
+/*
+ * basic.css
+ * ~~~~~~~~~
+ *
+ * Sphinx stylesheet -- basic theme.
+ *
+ * :copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
+ * :license: BSD, see LICENSE for details.
+ *
+ */
+
+/* -- main layout ----------------------------------------------------------- */
+
+div.clearer {
+    clear: both;
+}
+
+/* -- relbar ---------------------------------------------------------------- */
+
+div.related {
+    width: 100%;
+    font-size: 90%;
+}
+
+div.related h3 {
+    display: none;
+}
+
+div.related ul {
+    margin: 0;
+    padding: 0 0 0 10px;
+    list-style: none;
+}
+
+div.related li {
+    display: inline;
+}
+
+div.related li.right {
+    float: right;
+    margin-right: 5px;
+}
+
+/* -- sidebar --------------------------------------------------------------- */
+
+div.sphinxsidebarwrapper {
+    padding: 10px 5px 0 10px;
+}
+
+div.sphinxsidebar {
+    float: left;
+    width: 230px;
+    margin-left: -100%;
+    font-size: 90%;
+}
+
+div.sphinxsidebar ul {
+    list-style: none;
+}
+
+div.sphinxsidebar ul ul,
+div.sphinxsidebar ul.want-points {
+    margin-left: 20px;
+    list-style: square;
+}
+
+div.sphinxsidebar ul ul {
+    margin-top: 0;
+    margin-bottom: 0;
+}
+
+div.sphinxsidebar form {
+    margin-top: 10px;
+}
+
+div.sphinxsidebar input {
+    border: 1px solid #98dbcc;
+    font-family: sans-serif;
+    font-size: 1em;
+}
+
+div.sphinxsidebar #searchbox input[type="text"] {
+    width: 170px;
+}
+
+div.sphinxsidebar #searchbox input[type="submit"] {
+    width: 30px;
+}
+
+img {
+    border: 0;
+    max-width: 100%;
+}
+
+/* -- search page ----------------------------------------------------------- */
+
+ul.search {
+    margin: 10px 0 0 20px;
+    padding: 0;
+}
+
+ul.search li {
+    padding: 5px 0 5px 20px;
+    background-image: url(file.png);
+    background-repeat: no-repeat;
+    background-position: 0 7px;
+}
+
+ul.search li a {
+    font-weight: bold;
+}
+
+ul.search li div.context {
+    color: #888;
+    margin: 2px 0 0 30px;
+    text-align: left;
+}
+
+ul.keywordmatches li.goodmatch a {
+    font-weight: bold;
+}
+
+/* -- index page ------------------------------------------------------------ */
+
+table.contentstable {
+    width: 90%;
+}
+
+table.contentstable p.biglink {
+    line-height: 150%;
+}
+
+a.biglink {
+    font-size: 1.3em;
+}
+
+span.linkdescr {
+    font-style: italic;
+    padding-top: 5px;
+    font-size: 90%;
+}
+
+/* -- general index --------------------------------------------------------- */
+
+table.indextable {
+    width: 100%;
+}
+
+table.indextable td {
+    text-align: left;
+    vertical-align: top;
+}
+
+table.indextable dl, table.indextable dd {
+    margin-top: 0;
+    margin-bottom: 0;
+}
+
+table.indextable tr.pcap {
+    height: 10px;
+}
+
+table.indextable tr.cap {
+    margin-top: 10px;
+    background-color: #f2f2f2;
+}
+
+img.toggler {
+    margin-right: 3px;
+    margin-top: 3px;
+    cursor: pointer;
+}
+
+div.modindex-jumpbox {
+    border-top: 1px solid #ddd;
+    border-bottom: 1px solid #ddd;
+    margin: 1em 0 1em 0;
+    padding: 0.4em;
+}
+
+div.genindex-jumpbox {
+    border-top: 1px solid #ddd;
+    border-bottom: 1px solid #ddd;
+    margin: 1em 0 1em 0;
+    padding: 0.4em;
+}
+
+/* -- general body styles --------------------------------------------------- */
+
+a.headerlink {
+    visibility: hidden;
+}
+
+h1:hover > a.headerlink,
+h2:hover > a.headerlink,
+h3:hover > a.headerlink,
+h4:hover > a.headerlink,
+h5:hover > a.headerlink,
+h6:hover > a.headerlink,
+dt:hover > a.headerlink,
+caption:hover > a.headerlink,
+p.caption:hover > a.headerlink,
+div.code-block-caption:hover > a.headerlink {
+    visibility: visible;
+}
+
+div.body p.caption {
+    text-align: inherit;
+}
+
+div.body td {
+    text-align: left;
+}
+
+.field-list ul {
+    padding-left: 1em;
+}
+
+.first {
+    margin-top: 0 !important;
+}
+
+p.rubric {
+    margin-top: 30px;
+    font-weight: bold;
+}
+
+img.align-left, .figure.align-left, object.align-left {
+    clear: left;
+    float: left;
+    margin-right: 1em;
+}
+
+img.align-right, .figure.align-right, object.align-right {
+    clear: right;
+    float: right;
+    margin-left: 1em;
+}
+
+img.align-center, .figure.align-center, object.align-center {
+  display: block;
+  margin-left: auto;
+  margin-right: auto;
+}
+
+.align-left {
+    text-align: left;
+}
+
+.align-center {
+    text-align: center;
+}
+
+.align-right {
+    text-align: right;
+}
+
+/* -- sidebars -------------------------------------------------------------- */
+
+div.sidebar {
+    margin: 0 0 0.5em 1em;
+    border: 1px solid #ddb;
+    padding: 7px 7px 0 7px;
+    background-color: #ffe;
+    width: 40%;
+    float: right;
+}
+
+p.sidebar-title {
+    font-weight: bold;
+}
+
+/* -- topics ---------------------------------------------------------------- */
+
+div.topic {
+    border: 1px solid #ccc;
+    padding: 7px 7px 0 7px;
+    margin: 10px 0 10px 0;
+}
+
+p.topic-title {
+    font-size: 1.1em;
+    font-weight: bold;
+    margin-top: 10px;
+}
+
+/* -- admonitions ----------------------------------------------------------- */
+
+div.admonition {
+    margin-top: 10px;
+    margin-bottom: 10px;
+    padding: 7px;
+}
+
+div.admonition dt {
+    font-weight: bold;
+}
+
+div.admonition dl {
+    margin-bottom: 0;
+}
+
+p.admonition-title {
+    margin: 0px 10px 5px 0px;
+    font-weight: bold;
+}
+
+div.body p.centered {
+    text-align: center;
+    margin-top: 25px;
+}
+
+/* -- tables ---------------------------------------------------------------- */
+
+table.docutils {
+    border: 0;
+    border-collapse: collapse;
+}
+
+table caption span.caption-number {
+    font-style: italic;
+}
+
+table caption span.caption-text {
+}
+
+table.docutils td, table.docutils th {
+    padding: 1px 8px 1px 5px;
+    border-top: 0;
+    border-left: 0;
+    border-right: 0;
+    border-bottom: 1px solid #aaa;
+}
+
+table.field-list td, table.field-list th {
+    border: 0 !important;
+}
+
+table.footnote td, table.footnote th {
+    border: 0 !important;
+}
+
+th {
+    text-align: left;
+    padding-right: 5px;
+}
+
+table.citation {
+    border-left: solid 1px gray;
+    margin-left: 1px;
+}
+
+table.citation td {
+    border-bottom: none;
+}
+
+/* -- figures --------------------------------------------------------------- */
+
+div.figure {
+    margin: 0.5em;
+    padding: 0.5em;
+}
+
+div.figure p.caption {
+    padding: 0.3em;
+}
+
+div.figure p.caption span.caption-number {
+    font-style: italic;
+}
+
+div.figure p.caption span.caption-text {
+}
+
+
+/* -- other body styles ----------------------------------------------------- */
+
+ol.arabic {
+    list-style: decimal;
+}
+
+ol.loweralpha {
+    list-style: lower-alpha;
+}
+
+ol.upperalpha {
+    list-style: upper-alpha;
+}
+
+ol.lowerroman {
+    list-style: lower-roman;
+}
+
+ol.upperroman {
+    list-style: upper-roman;
+}
+
+dl {
+    margin-bottom: 15px;
+}
+
+dd p {
+    margin-top: 0px;
+}
+
+dd ul, dd table {
+    margin-bottom: 10px;
+}
+
+dd {
+    margin-top: 3px;
+    margin-bottom: 10px;
+    margin-left: 30px;
+}
+
+dt:target, .highlighted {
+    background-color: #fbe54e;
+}
+
+dl.glossary dt {
+    font-weight: bold;
+    font-size: 1.1em;
+}
+
+.field-list ul {
+    margin: 0;
+    padding-left: 1em;
+}
+
+.field-list p {
+    margin: 0;
+}
+
+.optional {
+    font-size: 1.3em;
+}
+
+.sig-paren {
+    font-size: larger;
+}
+
+.versionmodified {
+    font-style: italic;
+}
+
+.system-message {
+    background-color: #fda;
+    padding: 5px;
+    border: 3px solid red;
+}
+
+.footnote:target  {
+    background-color: #ffa;
+}
+
+.line-block {
+    display: block;
+    margin-top: 1em;
+    margin-bottom: 1em;
+}
+
+.line-block .line-block {
+    margin-top: 0;
+    margin-bottom: 0;
+    margin-left: 1.5em;
+}
+
+.guilabel, .menuselection {
+    font-family: sans-serif;
+}
+
+.accelerator {
+    text-decoration: underline;
+}
+
+.classifier {
+    font-style: oblique;
+}
+
+abbr, acronym {
+    border-bottom: dotted 1px;
+    cursor: help;
+}
+
+/* -- code displays --------------------------------------------------------- */
+
+pre {
+    overflow: auto;
+    overflow-y: hidden;  /* fixes display issues on Chrome browsers */
+}
+
+td.linenos pre {
+    padding: 5px 0px;
+    border: 0;
+    background-color: transparent;
+    color: #aaa;
+}
+
+table.highlighttable {
+    margin-left: 0.5em;
+}
+
+table.highlighttable td {
+    padding: 0 0.5em 0 0.5em;
+}
+
+div.code-block-caption {
+    padding: 2px 5px;
+    font-size: small;
+}
+
+div.code-block-caption code {
+    background-color: transparent;
+}
+
+div.code-block-caption + div > div.highlight > pre {
+    margin-top: 0;
+}
+
+div.code-block-caption span.caption-number {
+    padding: 0.1em 0.3em;
+    font-style: italic;
+}
+
+div.code-block-caption span.caption-text {
+}
+
+div.literal-block-wrapper {
+    padding: 1em 1em 0;
+}
+
+div.literal-block-wrapper div.highlight {
+    margin: 0;
+}
+
+code.descname {
+    background-color: transparent;
+    font-weight: bold;
+    font-size: 1.2em;
+}
+
+code.descclassname {
+    background-color: transparent;
+}
+
+code.xref, a code {
+    background-color: transparent;
+    font-weight: bold;
+}
+
+h1 code, h2 code, h3 code, h4 code, h5 code, h6 code {
+    background-color: transparent;
+}
+
+.viewcode-link {
+    float: right;
+}
+
+.viewcode-back {
+    float: right;
+    font-family: sans-serif;
+}
+
+div.viewcode-block:target {
+    margin: -1px -10px;
+    padding: 0 10px;
+}
+
+/* -- math display ---------------------------------------------------------- */
+
+img.math {
+    vertical-align: middle;
+}
+
+div.body div.math p {
+    text-align: center;
+}
+
+span.eqno {
+    float: right;
+}
+
+/* -- printout stylesheet --------------------------------------------------- */
+
+@media print {
+    div.document,
+    div.documentwrapper,
+    div.bodywrapper {
+        margin: 0 !important;
+        width: 100%;
+    }
+
+    div.sphinxsidebar,
+    div.related,
+    div.footer,
+    #top-link {
+        display: none;
+    }
+}
\ No newline at end of file
diff --git a/docs/html/_static/comment-bright.png b/docs/html/_static/comment-bright.png
new file mode 100644
index 00000000..551517b8
Binary files /dev/null and b/docs/html/_static/comment-bright.png differ
diff --git a/docs/html/_static/comment-close.png b/docs/html/_static/comment-close.png
new file mode 100644
index 00000000..09b54be4
Binary files /dev/null and b/docs/html/_static/comment-close.png differ
diff --git a/docs/html/_static/comment.png b/docs/html/_static/comment.png
new file mode 100644
index 00000000..92feb52b
Binary files /dev/null and b/docs/html/_static/comment.png differ
diff --git a/docs/html/_static/contents.png b/docs/html/_static/contents.png
new file mode 100644
index 00000000..7fb82154
Binary files /dev/null and b/docs/html/_static/contents.png differ
diff --git a/docs/html/_static/doctools.js b/docs/html/_static/doctools.js
new file mode 100644
index 00000000..e2e70cc2
--- /dev/null
+++ b/docs/html/_static/doctools.js
@@ -0,0 +1,263 @@
+/*
+ * doctools.js
+ * ~~~~~~~~~~~
+ *
+ * Sphinx JavaScript utilities for all documentation.
+ *
+ * :copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
+ * :license: BSD, see LICENSE for details.
+ *
+ */
+
+/**
+ * select a different prefix for underscore
+ */
+$u = _.noConflict();
+
+/**
+ * make the code below compatible with browsers without
+ * an installed firebug like debugger
+if (!window.console || !console.firebug) {
+  var names = ["log", "debug", "info", "warn", "error", "assert", "dir",
+    "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace",
+    "profile", "profileEnd"];
+  window.console = {};
+  for (var i = 0; i < names.length; ++i)
+    window.console[names[i]] = function() {};
+}
+ */
+
+/**
+ * small helper function to urldecode strings
+ */
+jQuery.urldecode = function(x) {
+  return decodeURIComponent(x).replace(/\+/g, ' ');
+};
+
+/**
+ * small helper function to urlencode strings
+ */
+jQuery.urlencode = encodeURIComponent;
+
+/**
+ * This function returns the parsed url parameters of the
+ * current request. Multiple values per key are supported,
+ * it will always return arrays of strings for the value parts.
+ */
+jQuery.getQueryParameters = function(s) {
+  if (typeof s == 'undefined')
+    s = document.location.search;
+  var parts = s.substr(s.indexOf('?') + 1).split('&');
+  var result = {};
+  for (var i = 0; i < parts.length; i++) {
+    var tmp = parts[i].split('=', 2);
+    var key = jQuery.urldecode(tmp[0]);
+    var value = jQuery.urldecode(tmp[1]);
+    if (key in result)
+      result[key].push(value);
+    else
+      result[key] = [value];
+  }
+  return result;
+};
+
+/**
+ * highlight a given string on a jquery object by wrapping it in
+ * span elements with the given class name.
+ */
+jQuery.fn.highlightText = function(text, className) {
+  function highlight(node) {
+    if (node.nodeType == 3) {
+      var val = node.nodeValue;
+      var pos = val.toLowerCase().indexOf(text);
+      if (pos >= 0 && !jQuery(node.parentNode).hasClass(className)) {
+        var span = document.createElement("span");
+        span.className = className;
+        span.appendChild(document.createTextNode(val.substr(pos, text.length)));
+        node.parentNode.insertBefore(span, node.parentNode.insertBefore(
+          document.createTextNode(val.substr(pos + text.length)),
+          node.nextSibling));
+        node.nodeValue = val.substr(0, pos);
+      }
+    }
+    else if (!jQuery(node).is("button, select, textarea")) {
+      jQuery.each(node.childNodes, function() {
+        highlight(this);
+      });
+    }
+  }
+  return this.each(function() {
+    highlight(this);
+  });
+};
+
+/*
+ * backward compatibility for jQuery.browser
+ * This will be supported until firefox bug is fixed.
+ */
+if (!jQuery.browser) {
+  jQuery.uaMatch = function(ua) {
+    ua = ua.toLowerCase();
+
+    var match = /(chrome)[ \/]([\w.]+)/.exec(ua) ||
+      /(webkit)[ \/]([\w.]+)/.exec(ua) ||
+      /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) ||
+      /(msie) ([\w.]+)/.exec(ua) ||
+      ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) ||
+      [];
+
+    return {
+      browser: match[ 1 ] || "",
+      version: match[ 2 ] || "0"
+    };
+  };
+  jQuery.browser = {};
+  jQuery.browser[jQuery.uaMatch(navigator.userAgent).browser] = true;
+}
+
+/**
+ * Small JavaScript module for the documentation.
+ */
+var Documentation = {
+
+  init : function() {
+    this.fixFirefoxAnchorBug();
+    this.highlightSearchWords();
+    this.initIndexTable();
+  },
+
+  /**
+   * i18n support
+   */
+  TRANSLATIONS : {},
+  PLURAL_EXPR : function(n) { return n == 1 ? 0 : 1; },
+  LOCALE : 'unknown',
+
+  // gettext and ngettext don't access this so that the functions
+  // can safely bound to a different name (_ = Documentation.gettext)
+  gettext : function(string) {
+    var translated = Documentation.TRANSLATIONS[string];
+    if (typeof translated == 'undefined')
+      return string;
+    return (typeof translated == 'string') ? translated : translated[0];
+  },
+
+  ngettext : function(singular, plural, n) {
+    var translated = Documentation.TRANSLATIONS[singular];
+    if (typeof translated == 'undefined')
+      return (n == 1) ? singular : plural;
+    return translated[Documentation.PLURALEXPR(n)];
+  },
+
+  addTranslations : function(catalog) {
+    for (var key in catalog.messages)
+      this.TRANSLATIONS[key] = catalog.messages[key];
+    this.PLURAL_EXPR = new Function('n', 'return +(' + catalog.plural_expr + ')');
+    this.LOCALE = catalog.locale;
+  },
+
+  /**
+   * add context elements like header anchor links
+   */
+  addContextElements : function() {
+    $('div[id] > :header:first').each(function() {
+      $('<a class="headerlink">\u00B6</a>').
+      attr('href', '#' + this.id).
+      attr('title', _('Permalink to this headline')).
+      appendTo(this);
+    });
+    $('dt[id]').each(function() {
+      $('<a class="headerlink">\u00B6</a>').
+      attr('href', '#' + this.id).
+      attr('title', _('Permalink to this definition')).
+      appendTo(this);
+    });
+  },
+
+  /**
+   * workaround a firefox stupidity
+   * see: https://bugzilla.mozilla.org/show_bug.cgi?id=645075
+   */
+  fixFirefoxAnchorBug : function() {
+    if (document.location.hash)
+      window.setTimeout(function() {
+        document.location.href += '';
+      }, 10);
+  },
+
+  /**
+   * highlight the search words provided in the url in the text
+   */
+  highlightSearchWords : function() {
+    var params = $.getQueryParameters();
+    var terms = (params.highlight) ? params.highlight[0].split(/\s+/) : [];
+    if (terms.length) {
+      var body = $('div.body');
+      if (!body.length) {
+        body = $('body');
+      }
+      window.setTimeout(function() {
+        $.each(terms, function() {
+          body.highlightText(this.toLowerCase(), 'highlighted');
+        });
+      }, 10);
+      $('<p class="highlight-link"><a href="javascript:Documentation.' +
+        'hideSearchWords()">' + _('Hide Search Matches') + '</a></p>')
+          .appendTo($('#searchbox'));
+    }
+  },
+
+  /**
+   * init the domain index toggle buttons
+   */
+  initIndexTable : function() {
+    var togglers = $('img.toggler').click(function() {
+      var src = $(this).attr('src');
+      var idnum = $(this).attr('id').substr(7);
+      $('tr.cg-' + idnum).toggle();
+      if (src.substr(-9) == 'minus.png')
+        $(this).attr('src', src.substr(0, src.length-9) + 'plus.png');
+      else
+        $(this).attr('src', src.substr(0, src.length-8) + 'minus.png');
+    }).css('display', '');
+    if (DOCUMENTATION_OPTIONS.COLLAPSE_INDEX) {
+        togglers.click();
+    }
+  },
+
+  /**
+   * helper function to hide the search marks again
+   */
+  hideSearchWords : function() {
+    $('#searchbox .highlight-link').fadeOut(300);
+    $('span.highlighted').removeClass('highlighted');
+  },
+
+  /**
+   * make the url absolute
+   */
+  makeURL : function(relativeURL) {
+    return DOCUMENTATION_OPTIONS.URL_ROOT + '/' + relativeURL;
+  },
+
+  /**
+   * get the current relative url
+   */
+  getCurrentURL : function() {
+    var path = document.location.pathname;
+    var parts = path.split(/\//);
+    $.each(DOCUMENTATION_OPTIONS.URL_ROOT.split(/\//), function() {
+      if (this == '..')
+        parts.pop();
+    });
+    var url = parts.join('/');
+    return path.substring(url.lastIndexOf('/') + 1, path.length - 1);
+  }
+};
+
+// quick alias for translations
+_ = Documentation.gettext;
+
+$(document).ready(function() {
+  Documentation.init();
+});
diff --git a/docs/html/_static/down-pressed.png b/docs/html/_static/down-pressed.png
new file mode 100644
index 00000000..7c30d004
Binary files /dev/null and b/docs/html/_static/down-pressed.png differ
diff --git a/docs/html/_static/down.png b/docs/html/_static/down.png
new file mode 100644
index 00000000..f48098a4
Binary files /dev/null and b/docs/html/_static/down.png differ
diff --git a/docs/html/_static/file.png b/docs/html/_static/file.png
new file mode 100644
index 00000000..254c60bf
Binary files /dev/null and b/docs/html/_static/file.png differ
diff --git a/docs/html/_static/jquery.js b/docs/html/_static/jquery.js
new file mode 100644
index 00000000..415ff510
--- /dev/null
+++ b/docs/html/_static/jquery.js
@@ -0,0 +1,10351 @@
+/*!
+ * jQuery JavaScript Library v1.11.3
+ * http://jquery.com/
+ *
+ * Includes Sizzle.js
+ * http://sizzlejs.com/
+ *
+ * Copyright 2005, 2014 jQuery Foundation, Inc. and other contributors
+ * Released under the MIT license
+ * http://jquery.org/license
+ *
+ * Date: 2015-09-23T12:31Z
+ */
+
+(function( global, factory ) {
+
+	if ( typeof module === "object" && typeof module.exports === "object" ) {
+		// For CommonJS and CommonJS-like environments where a proper window is present,
+		// execute the factory and get jQuery
+		// For environments that do not inherently posses a window with a document
+		// (such as Node.js), expose a jQuery-making factory as module.exports
+		// This accentuates the need for the creation of a real window
+		// e.g. var jQuery = require("jquery")(window);
+		// See ticket #14549 for more info
+		module.exports = global.document ?
+			factory( global, true ) :
+			function( w ) {
+				if ( !w.document ) {
+					throw new Error( "jQuery requires a window with a document" );
+				}
+				return factory( w );
+			};
+	} else {
+		factory( global );
+	}
+
+// Pass this if window is not defined yet
+}(typeof window !== "undefined" ? window : this, function( window, noGlobal ) {
+
+// Can't do this because several apps including ASP.NET trace
+// the stack via arguments.caller.callee and Firefox dies if
+// you try to trace through "use strict" call chains. (#13335)
+// Support: Firefox 18+
+//
+var deletedIds = [];
+
+var slice = deletedIds.slice;
+
+var concat = deletedIds.concat;
+
+var push = deletedIds.push;
+
+var indexOf = deletedIds.indexOf;
+
+var class2type = {};
+
+var toString = class2type.toString;
+
+var hasOwn = class2type.hasOwnProperty;
+
+var support = {};
+
+
+
+var
+	version = "1.11.3",
+
+	// Define a local copy of jQuery
+	jQuery = function( selector, context ) {
+		// The jQuery object is actually just the init constructor 'enhanced'
+		// Need init if jQuery is called (just allow error to be thrown if not included)
+		return new jQuery.fn.init( selector, context );
+	},
+
+	// Support: Android<4.1, IE<9
+	// Make sure we trim BOM and NBSP
+	rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,
+
+	// Matches dashed string for camelizing
+	rmsPrefix = /^-ms-/,
+	rdashAlpha = /-([\da-z])/gi,
+
+	// Used by jQuery.camelCase as callback to replace()
+	fcamelCase = function( all, letter ) {
+		return letter.toUpperCase();
+	};
+
+jQuery.fn = jQuery.prototype = {
+	// The current version of jQuery being used
+	jquery: version,
+
+	constructor: jQuery,
+
+	// Start with an empty selector
+	selector: "",
+
+	// The default length of a jQuery object is 0
+	length: 0,
+
+	toArray: function() {
+		return slice.call( this );
+	},
+
+	// Get the Nth element in the matched element set OR
+	// Get the whole matched element set as a clean array
+	get: function( num ) {
+		return num != null ?
+
+			// Return just the one element from the set
+			( num < 0 ? this[ num + this.length ] : this[ num ] ) :
+
+			// Return all the elements in a clean array
+			slice.call( this );
+	},
+
+	// Take an array of elements and push it onto the stack
+	// (returning the new matched element set)
+	pushStack: function( elems ) {
+
+		// Build a new jQuery matched element set
+		var ret = jQuery.merge( this.constructor(), elems );
+
+		// Add the old object onto the stack (as a reference)
+		ret.prevObject = this;
+		ret.context = this.context;
+
+		// Return the newly-formed element set
+		return ret;
+	},
+
+	// Execute a callback for every element in the matched set.
+	// (You can seed the arguments with an array of args, but this is
+	// only used internally.)
+	each: function( callback, args ) {
+		return jQuery.each( this, callback, args );
+	},
+
+	map: function( callback ) {
+		return this.pushStack( jQuery.map(this, function( elem, i ) {
+			return callback.call( elem, i, elem );
+		}));
+	},
+
+	slice: function() {
+		return this.pushStack( slice.apply( this, arguments ) );
+	},
+
+	first: function() {
+		return this.eq( 0 );
+	},
+
+	last: function() {
+		return this.eq( -1 );
+	},
+
+	eq: function( i ) {
+		var len = this.length,
+			j = +i + ( i < 0 ? len : 0 );
+		return this.pushStack( j >= 0 && j < len ? [ this[j] ] : [] );
+	},
+
+	end: function() {
+		return this.prevObject || this.constructor(null);
+	},
+
+	// For internal use only.
+	// Behaves like an Array's method, not like a jQuery method.
+	push: push,
+	sort: deletedIds.sort,
+	splice: deletedIds.splice
+};
+
+jQuery.extend = jQuery.fn.extend = function() {
+	var src, copyIsArray, copy, name, options, clone,
+		target = arguments[0] || {},
+		i = 1,
+		length = arguments.length,
+		deep = false;
+
+	// Handle a deep copy situation
+	if ( typeof target === "boolean" ) {
+		deep = target;
+
+		// skip the boolean and the target
+		target = arguments[ i ] || {};
+		i++;
+	}
+
+	// Handle case when target is a string or something (possible in deep copy)
+	if ( typeof target !== "object" && !jQuery.isFunction(target) ) {
+		target = {};
+	}
+
+	// extend jQuery itself if only one argument is passed
+	if ( i === length ) {
+		target = this;
+		i--;
+	}
+
+	for ( ; i < length; i++ ) {
+		// Only deal with non-null/undefined values
+		if ( (options = arguments[ i ]) != null ) {
+			// Extend the base object
+			for ( name in options ) {
+				src = target[ name ];
+				copy = options[ name ];
+
+				// Prevent never-ending loop
+				if ( target === copy ) {
+					continue;
+				}
+
+				// Recurse if we're merging plain objects or arrays
+				if ( deep && copy && ( jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)) ) ) {
+					if ( copyIsArray ) {
+						copyIsArray = false;
+						clone = src && jQuery.isArray(src) ? src : [];
+
+					} else {
+						clone = src && jQuery.isPlainObject(src) ? src : {};
+					}
+
+					// Never move original objects, clone them
+					target[ name ] = jQuery.extend( deep, clone, copy );
+
+				// Don't bring in undefined values
+				} else if ( copy !== undefined ) {
+					target[ name ] = copy;
+				}
+			}
+		}
+	}
+
+	// Return the modified object
+	return target;
+};
+
+jQuery.extend({
+	// Unique for each copy of jQuery on the page
+	expando: "jQuery" + ( version + Math.random() ).replace( /\D/g, "" ),
+
+	// Assume jQuery is ready without the ready module
+	isReady: true,
+
+	error: function( msg ) {
+		throw new Error( msg );
+	},
+
+	noop: function() {},
+
+	// See test/unit/core.js for details concerning isFunction.
+	// Since version 1.3, DOM methods and functions like alert
+	// aren't supported. They return false on IE (#2968).
+	isFunction: function( obj ) {
+		return jQuery.type(obj) === "function";
+	},
+
+	isArray: Array.isArray || function( obj ) {
+		return jQuery.type(obj) === "array";
+	},
+
+	isWindow: function( obj ) {
+		/* jshint eqeqeq: false */
+		return obj != null && obj == obj.window;
+	},
+
+	isNumeric: function( obj ) {
+		// parseFloat NaNs numeric-cast false positives (null|true|false|"")
+		// ...but misinterprets leading-number strings, particularly hex literals ("0x...")
+		// subtraction forces infinities to NaN
+		// adding 1 corrects loss of precision from parseFloat (#15100)
+		return !jQuery.isArray( obj ) && (obj - parseFloat( obj ) + 1) >= 0;
+	},
+
+	isEmptyObject: function( obj ) {
+		var name;
+		for ( name in obj ) {
+			return false;
+		}
+		return true;
+	},
+
+	isPlainObject: function( obj ) {
+		var key;
+
+		// Must be an Object.
+		// Because of IE, we also have to check the presence of the constructor property.
+		// Make sure that DOM nodes and window objects don't pass through, as well
+		if ( !obj || jQuery.type(obj) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) {
+			return false;
+		}
+
+		try {
+			// Not own constructor property must be Object
+			if ( obj.constructor &&
+				!hasOwn.call(obj, "constructor") &&
+				!hasOwn.call(obj.constructor.prototype, "isPrototypeOf") ) {
+				return false;
+			}
+		} catch ( e ) {
+			// IE8,9 Will throw exceptions on certain host objects #9897
+			return false;
+		}
+
+		// Support: IE<9
+		// Handle iteration over inherited properties before own properties.
+		if ( support.ownLast ) {
+			for ( key in obj ) {
+				return hasOwn.call( obj, key );
+			}
+		}
+
+		// Own properties are enumerated firstly, so to speed up,
+		// if last one is own, then all properties are own.
+		for ( key in obj ) {}
+
+		return key === undefined || hasOwn.call( obj, key );
+	},
+
+	type: function( obj ) {
+		if ( obj == null ) {
+			return obj + "";
+		}
+		return typeof obj === "object" || typeof obj === "function" ?
+			class2type[ toString.call(obj) ] || "object" :
+			typeof obj;
+	},
+
+	// Evaluates a script in a global context
+	// Workarounds based on findings by Jim Driscoll
+	// http://weblogs.java.net/blog/driscoll/archive/2009/09/08/eval-javascript-global-context
+	globalEval: function( data ) {
+		if ( data && jQuery.trim( data ) ) {
+			// We use execScript on Internet Explorer
+			// We use an anonymous function so that context is window
+			// rather than jQuery in Firefox
+			( window.execScript || function( data ) {
+				window[ "eval" ].call( window, data );
+			} )( data );
+		}
+	},
+
+	// Convert dashed to camelCase; used by the css and data modules
+	// Microsoft forgot to hump their vendor prefix (#9572)
+	camelCase: function( string ) {
+		return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase );
+	},
+
+	nodeName: function( elem, name ) {
+		return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase();
+	},
+
+	// args is for internal usage only
+	each: function( obj, callback, args ) {
+		var value,
+			i = 0,
+			length = obj.length,
+			isArray = isArraylike( obj );
+
+		if ( args ) {
+			if ( isArray ) {
+				for ( ; i < length; i++ ) {
+					value = callback.apply( obj[ i ], args );
+
+					if ( value === false ) {
+						break;
+					}
+				}
+			} else {
+				for ( i in obj ) {
+					value = callback.apply( obj[ i ], args );
+
+					if ( value === false ) {
+						break;
+					}
+				}
+			}
+
+		// A special, fast, case for the most common use of each
+		} else {
+			if ( isArray ) {
+				for ( ; i < length; i++ ) {
+					value = callback.call( obj[ i ], i, obj[ i ] );
+
+					if ( value === false ) {
+						break;
+					}
+				}
+			} else {
+				for ( i in obj ) {
+					value = callback.call( obj[ i ], i, obj[ i ] );
+
+					if ( value === false ) {
+						break;
+					}
+				}
+			}
+		}
+
+		return obj;
+	},
+
+	// Support: Android<4.1, IE<9
+	trim: function( text ) {
+		return text == null ?
+			"" :
+			( text + "" ).replace( rtrim, "" );
+	},
+
+	// results is for internal usage only
+	makeArray: function( arr, results ) {
+		var ret = results || [];
+
+		if ( arr != null ) {
+			if ( isArraylike( Object(arr) ) ) {
+				jQuery.merge( ret,
+					typeof arr === "string" ?
+					[ arr ] : arr
+				);
+			} else {
+				push.call( ret, arr );
+			}
+		}
+
+		return ret;
+	},
+
+	inArray: function( elem, arr, i ) {
+		var len;
+
+		if ( arr ) {
+			if ( indexOf ) {
+				return indexOf.call( arr, elem, i );
+			}
+
+			len = arr.length;
+			i = i ? i < 0 ? Math.max( 0, len + i ) : i : 0;
+
+			for ( ; i < len; i++ ) {
+				// Skip accessing in sparse arrays
+				if ( i in arr && arr[ i ] === elem ) {
+					return i;
+				}
+			}
+		}
+
+		return -1;
+	},
+
+	merge: function( first, second ) {
+		var len = +second.length,
+			j = 0,
+			i = first.length;
+
+		while ( j < len ) {
+			first[ i++ ] = second[ j++ ];
+		}
+
+		// Support: IE<9
+		// Workaround casting of .length to NaN on otherwise arraylike objects (e.g., NodeLists)
+		if ( len !== len ) {
+			while ( second[j] !== undefined ) {
+				first[ i++ ] = second[ j++ ];
+			}
+		}
+
+		first.length = i;
+
+		return first;
+	},
+
+	grep: function( elems, callback, invert ) {
+		var callbackInverse,
+			matches = [],
+			i = 0,
+			length = elems.length,
+			callbackExpect = !invert;
+
+		// Go through the array, only saving the items
+		// that pass the validator function
+		for ( ; i < length; i++ ) {
+			callbackInverse = !callback( elems[ i ], i );
+			if ( callbackInverse !== callbackExpect ) {
+				matches.push( elems[ i ] );
+			}
+		}
+
+		return matches;
+	},
+
+	// arg is for internal usage only
+	map: function( elems, callback, arg ) {
+		var value,
+			i = 0,
+			length = elems.length,
+			isArray = isArraylike( elems ),
+			ret = [];
+
+		// Go through the array, translating each of the items to their new values
+		if ( isArray ) {
+			for ( ; i < length; i++ ) {
+				value = callback( elems[ i ], i, arg );
+
+				if ( value != null ) {
+					ret.push( value );
+				}
+			}
+
+		// Go through every key on the object,
+		} else {
+			for ( i in elems ) {
+				value = callback( elems[ i ], i, arg );
+
+				if ( value != null ) {
+					ret.push( value );
+				}
+			}
+		}
+
+		// Flatten any nested arrays
+		return concat.apply( [], ret );
+	},
+
+	// A global GUID counter for objects
+	guid: 1,
+
+	// Bind a function to a context, optionally partially applying any
+	// arguments.
+	proxy: function( fn, context ) {
+		var args, proxy, tmp;
+
+		if ( typeof context === "string" ) {
+			tmp = fn[ context ];
+			context = fn;
+			fn = tmp;
+		}
+
+		// Quick check to determine if target is callable, in the spec
+		// this throws a TypeError, but we will just return undefined.
+		if ( !jQuery.isFunction( fn ) ) {
+			return undefined;
+		}
+
+		// Simulated bind
+		args = slice.call( arguments, 2 );
+		proxy = function() {
+			return fn.apply( context || this, args.concat( slice.call( arguments ) ) );
+		};
+
+		// Set the guid of unique handler to the same of original handler, so it can be removed
+		proxy.guid = fn.guid = fn.guid || jQuery.guid++;
+
+		return proxy;
+	},
+
+	now: function() {
+		return +( new Date() );
+	},
+
+	// jQuery.support is not used in Core but other projects attach their
+	// properties to it so it needs to exist.
+	support: support
+});
+
+// Populate the class2type map
+jQuery.each("Boolean Number String Function Array Date RegExp Object Error".split(" "), function(i, name) {
+	class2type[ "[object " + name + "]" ] = name.toLowerCase();
+});
+
+function isArraylike( obj ) {
+
+	// Support: iOS 8.2 (not reproducible in simulator)
+	// `in` check used to prevent JIT error (gh-2145)
+	// hasOwn isn't used here due to false negatives
+	// regarding Nodelist length in IE
+	var length = "length" in obj && obj.length,
+		type = jQuery.type( obj );
+
+	if ( type === "function" || jQuery.isWindow( obj ) ) {
+		return false;
+	}
+
+	if ( obj.nodeType === 1 && length ) {
+		return true;
+	}
+
+	return type === "array" || length === 0 ||
+		typeof length === "number" && length > 0 && ( length - 1 ) in obj;
+}
+var Sizzle =
+/*!
+ * Sizzle CSS Selector Engine v2.2.0-pre
+ * http://sizzlejs.com/
+ *
+ * Copyright 2008, 2014 jQuery Foundation, Inc. and other contributors
+ * Released under the MIT license
+ * http://jquery.org/license
+ *
+ * Date: 2014-12-16
+ */
+(function( window ) {
+
+var i,
+	support,
+	Expr,
+	getText,
+	isXML,
+	tokenize,
+	compile,
+	select,
+	outermostContext,
+	sortInput,
+	hasDuplicate,
+
+	// Local document vars
+	setDocument,
+	document,
+	docElem,
+	documentIsHTML,
+	rbuggyQSA,
+	rbuggyMatches,
+	matches,
+	contains,
+
+	// Instance-specific data
+	expando = "sizzle" + 1 * new Date(),
+	preferredDoc = window.document,
+	dirruns = 0,
+	done = 0,
+	classCache = createCache(),
+	tokenCache = createCache(),
+	compilerCache = createCache(),
+	sortOrder = function( a, b ) {
+		if ( a === b ) {
+			hasDuplicate = true;
+		}
+		return 0;
+	},
+
+	// General-purpose constants
+	MAX_NEGATIVE = 1 << 31,
+
+	// Instance methods
+	hasOwn = ({}).hasOwnProperty,
+	arr = [],
+	pop = arr.pop,
+	push_native = arr.push,
+	push = arr.push,
+	slice = arr.slice,
+	// Use a stripped-down indexOf as it's faster than native
+	// http://jsperf.com/thor-indexof-vs-for/5
+	indexOf = function( list, elem ) {
+		var i = 0,
+			len = list.length;
+		for ( ; i < len; i++ ) {
+			if ( list[i] === elem ) {
+				return i;
+			}
+		}
+		return -1;
+	},
+
+	booleans = "checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",
+
+	// Regular expressions
+
+	// Whitespace characters http://www.w3.org/TR/css3-selectors/#whitespace
+	whitespace = "[\\x20\\t\\r\\n\\f]",
+	// http://www.w3.org/TR/css3-syntax/#characters
+	characterEncoding = "(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",
+
+	// Loosely modeled on CSS identifier characters
+	// An unquoted value should be a CSS identifier http://www.w3.org/TR/css3-selectors/#attribute-selectors
+	// Proper syntax: http://www.w3.org/TR/CSS21/syndata.html#value-def-identifier
+	identifier = characterEncoding.replace( "w", "w#" ),
+
+	// Attribute selectors: http://www.w3.org/TR/selectors/#attribute-selectors
+	attributes = "\\[" + whitespace + "*(" + characterEncoding + ")(?:" + whitespace +
+		// Operator (capture 2)
+		"*([*^$|!~]?=)" + whitespace +
+		// "Attribute values must be CSS identifiers [capture 5] or strings [capture 3 or capture 4]"
+		"*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|(" + identifier + "))|)" + whitespace +
+		"*\\]",
+
+	pseudos = ":(" + characterEncoding + ")(?:\\((" +
+		// To reduce the number of selectors needing tokenize in the preFilter, prefer arguments:
+		// 1. quoted (capture 3; capture 4 or capture 5)
+		"('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|" +
+		// 2. simple (capture 6)
+		"((?:\\\\.|[^\\\\()[\\]]|" + attributes + ")*)|" +
+		// 3. anything else (capture 2)
+		".*" +
+		")\\)|)",
+
+	// Leading and non-escaped trailing whitespace, capturing some non-whitespace characters preceding the latter
+	rwhitespace = new RegExp( whitespace + "+", "g" ),
+	rtrim = new RegExp( "^" + whitespace + "+|((?:^|[^\\\\])(?:\\\\.)*)" + whitespace + "+$", "g" ),
+
+	rcomma = new RegExp( "^" + whitespace + "*," + whitespace + "*" ),
+	rcombinators = new RegExp( "^" + whitespace + "*([>+~]|" + whitespace + ")" + whitespace + "*" ),
+
+	rattributeQuotes = new RegExp( "=" + whitespace + "*([^\\]'\"]*?)" + whitespace + "*\\]", "g" ),
+
+	rpseudo = new RegExp( pseudos ),
+	ridentifier = new RegExp( "^" + identifier + "$" ),
+
+	matchExpr = {
+		"ID": new RegExp( "^#(" + characterEncoding + ")" ),
+		"CLASS": new RegExp( "^\\.(" + characterEncoding + ")" ),
+		"TAG": new RegExp( "^(" + characterEncoding.replace( "w", "w*" ) + ")" ),
+		"ATTR": new RegExp( "^" + attributes ),
+		"PSEUDO": new RegExp( "^" + pseudos ),
+		"CHILD": new RegExp( "^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\(" + whitespace +
+			"*(even|odd|(([+-]|)(\\d*)n|)" + whitespace + "*(?:([+-]|)" + whitespace +
+			"*(\\d+)|))" + whitespace + "*\\)|)", "i" ),
+		"bool": new RegExp( "^(?:" + booleans + ")$", "i" ),
+		// For use in libraries implementing .is()
+		// We use this for POS matching in `select`
+		"needsContext": new RegExp( "^" + whitespace + "*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\(" +
+			whitespace + "*((?:-\\d)?\\d*)" + whitespace + "*\\)|)(?=[^-]|$)", "i" )
+	},
+
+	rinputs = /^(?:input|select|textarea|button)$/i,
+	rheader = /^h\d$/i,
+
+	rnative = /^[^{]+\{\s*\[native \w/,
+
+	// Easily-parseable/retrievable ID or TAG or CLASS selectors
+	rquickExpr = /^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,
+
+	rsibling = /[+~]/,
+	rescape = /'|\\/g,
+
+	// CSS escapes http://www.w3.org/TR/CSS21/syndata.html#escaped-characters
+	runescape = new RegExp( "\\\\([\\da-f]{1,6}" + whitespace + "?|(" + whitespace + ")|.)", "ig" ),
+	funescape = function( _, escaped, escapedWhitespace ) {
+		var high = "0x" + escaped - 0x10000;
+		// NaN means non-codepoint
+		// Support: Firefox<24
+		// Workaround erroneous numeric interpretation of +"0x"
+		return high !== high || escapedWhitespace ?
+			escaped :
+			high < 0 ?
+				// BMP codepoint
+				String.fromCharCode( high + 0x10000 ) :
+				// Supplemental Plane codepoint (surrogate pair)
+				String.fromCharCode( high >> 10 | 0xD800, high & 0x3FF | 0xDC00 );
+	},
+
+	// Used for iframes
+	// See setDocument()
+	// Removing the function wrapper causes a "Permission Denied"
+	// error in IE
+	unloadHandler = function() {
+		setDocument();
+	};
+
+// Optimize for push.apply( _, NodeList )
+try {
+	push.apply(
+		(arr = slice.call( preferredDoc.childNodes )),
+		preferredDoc.childNodes
+	);
+	// Support: Android<4.0
+	// Detect silently failing push.apply
+	arr[ preferredDoc.childNodes.length ].nodeType;
+} catch ( e ) {
+	push = { apply: arr.length ?
+
+		// Leverage slice if possible
+		function( target, els ) {
+			push_native.apply( target, slice.call(els) );
+		} :
+
+		// Support: IE<9
+		// Otherwise append directly
+		function( target, els ) {
+			var j = target.length,
+				i = 0;
+			// Can't trust NodeList.length
+			while ( (target[j++] = els[i++]) ) {}
+			target.length = j - 1;
+		}
+	};
+}
+
+function Sizzle( selector, context, results, seed ) {
+	var match, elem, m, nodeType,
+		// QSA vars
+		i, groups, old, nid, newContext, newSelector;
+
+	if ( ( context ? context.ownerDocument || context : preferredDoc ) !== document ) {
+		setDocument( context );
+	}
+
+	context = context || document;
+	results = results || [];
+	nodeType = context.nodeType;
+
+	if ( typeof selector !== "string" || !selector ||
+		nodeType !== 1 && nodeType !== 9 && nodeType !== 11 ) {
+
+		return results;
+	}
+
+	if ( !seed && documentIsHTML ) {
+
+		// Try to shortcut find operations when possible (e.g., not under DocumentFragment)
+		if ( nodeType !== 11 && (match = rquickExpr.exec( selector )) ) {
+			// Speed-up: Sizzle("#ID")
+			if ( (m = match[1]) ) {
+				if ( nodeType === 9 ) {
+					elem = context.getElementById( m );
+					// Check parentNode to catch when Blackberry 4.6 returns
+					// nodes that are no longer in the document (jQuery #6963)
+					if ( elem && elem.parentNode ) {
+						// Handle the case where IE, Opera, and Webkit return items
+						// by name instead of ID
+						if ( elem.id === m ) {
+							results.push( elem );
+							return results;
+						}
+					} else {
+						return results;
+					}
+				} else {
+					// Context is not a document
+					if ( context.ownerDocument && (elem = context.ownerDocument.getElementById( m )) &&
+						contains( context, elem ) && elem.id === m ) {
+						results.push( elem );
+						return results;
+					}
+				}
+
+			// Speed-up: Sizzle("TAG")
+			} else if ( match[2] ) {
+				push.apply( results, context.getElementsByTagName( selector ) );
+				return results;
+
+			// Speed-up: Sizzle(".CLASS")
+			} else if ( (m = match[3]) && support.getElementsByClassName ) {
+				push.apply( results, context.getElementsByClassName( m ) );
+				return results;
+			}
+		}
+
+		// QSA path
+		if ( support.qsa && (!rbuggyQSA || !rbuggyQSA.test( selector )) ) {
+			nid = old = expando;
+			newContext = context;
+			newSelector = nodeType !== 1 && selector;
+
+			// qSA works strangely on Element-rooted queries
+			// We can work around this by specifying an extra ID on the root
+			// and working up from there (Thanks to Andrew Dupont for the technique)
+			// IE 8 doesn't work on object elements
+			if ( nodeType === 1 && context.nodeName.toLowerCase() !== "object" ) {
+				groups = tokenize( selector );
+
+				if ( (old = context.getAttribute("id")) ) {
+					nid = old.replace( rescape, "\\$&" );
+				} else {
+					context.setAttribute( "id", nid );
+				}
+				nid = "[id='" + nid + "'] ";
+
+				i = groups.length;
+				while ( i-- ) {
+					groups[i] = nid + toSelector( groups[i] );
+				}
+				newContext = rsibling.test( selector ) && testContext( context.parentNode ) || context;
+				newSelector = groups.join(",");
+			}
+
+			if ( newSelector ) {
+				try {
+					push.apply( results,
+						newContext.querySelectorAll( newSelector )
+					);
+					return results;
+				} catch(qsaError) {
+				} finally {
+					if ( !old ) {
+						context.removeAttribute("id");
+					}
+				}
+			}
+		}
+	}
+
+	// All others
+	return select( selector.replace( rtrim, "$1" ), context, results, seed );
+}
+
+/**
+ * Create key-value caches of limited size
+ * @returns {Function(string, Object)} Returns the Object data after storing it on itself with
+ *	property name the (space-suffixed) string and (if the cache is larger than Expr.cacheLength)
+ *	deleting the oldest entry
+ */
+function createCache() {
+	var keys = [];
+
+	function cache( key, value ) {
+		// Use (key + " ") to avoid collision with native prototype properties (see Issue #157)
+		if ( keys.push( key + " " ) > Expr.cacheLength ) {
+			// Only keep the most recent entries
+			delete cache[ keys.shift() ];
+		}
+		return (cache[ key + " " ] = value);
+	}
+	return cache;
+}
+
+/**
+ * Mark a function for special use by Sizzle
+ * @param {Function} fn The function to mark
+ */
+function markFunction( fn ) {
+	fn[ expando ] = true;
+	return fn;
+}
+
+/**
+ * Support testing using an element
+ * @param {Function} fn Passed the created div and expects a boolean result
+ */
+function assert( fn ) {
+	var div = document.createElement("div");
+
+	try {
+		return !!fn( div );
+	} catch (e) {
+		return false;
+	} finally {
+		// Remove from its parent by default
+		if ( div.parentNode ) {
+			div.parentNode.removeChild( div );
+		}
+		// release memory in IE
+		div = null;
+	}
+}
+
+/**
+ * Adds the same handler for all of the specified attrs
+ * @param {String} attrs Pipe-separated list of attributes
+ * @param {Function} handler The method that will be applied
+ */
+function addHandle( attrs, handler ) {
+	var arr = attrs.split("|"),
+		i = attrs.length;
+
+	while ( i-- ) {
+		Expr.attrHandle[ arr[i] ] = handler;
+	}
+}
+
+/**
+ * Checks document order of two siblings
+ * @param {Element} a
+ * @param {Element} b
+ * @returns {Number} Returns less than 0 if a precedes b, greater than 0 if a follows b
+ */
+function siblingCheck( a, b ) {
+	var cur = b && a,
+		diff = cur && a.nodeType === 1 && b.nodeType === 1 &&
+			( ~b.sourceIndex || MAX_NEGATIVE ) -
+			( ~a.sourceIndex || MAX_NEGATIVE );
+
+	// Use IE sourceIndex if available on both nodes
+	if ( diff ) {
+		return diff;
+	}
+
+	// Check if b follows a
+	if ( cur ) {
+		while ( (cur = cur.nextSibling) ) {
+			if ( cur === b ) {
+				return -1;
+			}
+		}
+	}
+
+	return a ? 1 : -1;
+}
+
+/**
+ * Returns a function to use in pseudos for input types
+ * @param {String} type
+ */
+function createInputPseudo( type ) {
+	return function( elem ) {
+		var name = elem.nodeName.toLowerCase();
+		return name === "input" && elem.type === type;
+	};
+}
+
+/**
+ * Returns a function to use in pseudos for buttons
+ * @param {String} type
+ */
+function createButtonPseudo( type ) {
+	return function( elem ) {
+		var name = elem.nodeName.toLowerCase();
+		return (name === "input" || name === "button") && elem.type === type;
+	};
+}
+
+/**
+ * Returns a function to use in pseudos for positionals
+ * @param {Function} fn
+ */
+function createPositionalPseudo( fn ) {
+	return markFunction(function( argument ) {
+		argument = +argument;
+		return markFunction(function( seed, matches ) {
+			var j,
+				matchIndexes = fn( [], seed.length, argument ),
+				i = matchIndexes.length;
+
+			// Match elements found at the specified indexes
+			while ( i-- ) {
+				if ( seed[ (j = matchIndexes[i]) ] ) {
+					seed[j] = !(matches[j] = seed[j]);
+				}
+			}
+		});
+	});
+}
+
+/**
+ * Checks a node for validity as a Sizzle context
+ * @param {Element|Object=} context
+ * @returns {Element|Object|Boolean} The input node if acceptable, otherwise a falsy value
+ */
+function testContext( context ) {
+	return context && typeof context.getElementsByTagName !== "undefined" && context;
+}
+
+// Expose support vars for convenience
+support = Sizzle.support = {};
+
+/**
+ * Detects XML nodes
+ * @param {Element|Object} elem An element or a document
+ * @returns {Boolean} True iff elem is a non-HTML XML node
+ */
+isXML = Sizzle.isXML = function( elem ) {
+	// documentElement is verified for cases where it doesn't yet exist
+	// (such as loading iframes in IE - #4833)
+	var documentElement = elem && (elem.ownerDocument || elem).documentElement;
+	return documentElement ? documentElement.nodeName !== "HTML" : false;
+};
+
+/**
+ * Sets document-related variables once based on the current document
+ * @param {Element|Object} [doc] An element or document object to use to set the document
+ * @returns {Object} Returns the current document
+ */
+setDocument = Sizzle.setDocument = function( node ) {
+	var hasCompare, parent,
+		doc = node ? node.ownerDocument || node : preferredDoc;
+
+	// If no document and documentElement is available, return
+	if ( doc === document || doc.nodeType !== 9 || !doc.documentElement ) {
+		return document;
+	}
+
+	// Set our document
+	document = doc;
+	docElem = doc.documentElement;
+	parent = doc.defaultView;
+
+	// Support: IE>8
+	// If iframe document is assigned to "document" variable and if iframe has been reloaded,
+	// IE will throw "permission denied" error when accessing "document" variable, see jQuery #13936
+	// IE6-8 do not support the defaultView property so parent will be undefined
+	if ( parent && parent !== parent.top ) {
+		// IE11 does not have attachEvent, so all must suffer
+		if ( parent.addEventListener ) {
+			parent.addEventListener( "unload", unloadHandler, false );
+		} else if ( parent.attachEvent ) {
+			parent.attachEvent( "onunload", unloadHandler );
+		}
+	}
+
+	/* Support tests
+	---------------------------------------------------------------------- */
+	documentIsHTML = !isXML( doc );
+
+	/* Attributes
+	---------------------------------------------------------------------- */
+
+	// Support: IE<8
+	// Verify that getAttribute really returns attributes and not properties
+	// (excepting IE8 booleans)
+	support.attributes = assert(function( div ) {
+		div.className = "i";
+		return !div.getAttribute("className");
+	});
+
+	/* getElement(s)By*
+	---------------------------------------------------------------------- */
+
+	// Check if getElementsByTagName("*") returns only elements
+	support.getElementsByTagName = assert(function( div ) {
+		div.appendChild( doc.createComment("") );
+		return !div.getElementsByTagName("*").length;
+	});
+
+	// Support: IE<9
+	support.getElementsByClassName = rnative.test( doc.getElementsByClassName );
+
+	// Support: IE<10
+	// Check if getElementById returns elements by name
+	// The broken getElementById methods don't pick up programatically-set names,
+	// so use a roundabout getElementsByName test
+	support.getById = assert(function( div ) {
+		docElem.appendChild( div ).id = expando;
+		return !doc.getElementsByName || !doc.getElementsByName( expando ).length;
+	});
+
+	// ID find and filter
+	if ( support.getById ) {
+		Expr.find["ID"] = function( id, context ) {
+			if ( typeof context.getElementById !== "undefined" && documentIsHTML ) {
+				var m = context.getElementById( id );
+				// Check parentNode to catch when Blackberry 4.6 returns
+				// nodes that are no longer in the document #6963
+				return m && m.parentNode ? [ m ] : [];
+			}
+		};
+		Expr.filter["ID"] = function( id ) {
+			var attrId = id.replace( runescape, funescape );
+			return function( elem ) {
+				return elem.getAttribute("id") === attrId;
+			};
+		};
+	} else {
+		// Support: IE6/7
+		// getElementById is not reliable as a find shortcut
+		delete Expr.find["ID"];
+
+		Expr.filter["ID"] =  function( id ) {
+			var attrId = id.replace( runescape, funescape );
+			return function( elem ) {
+				var node = typeof elem.getAttributeNode !== "undefined" && elem.getAttributeNode("id");
+				return node && node.value === attrId;
+			};
+		};
+	}
+
+	// Tag
+	Expr.find["TAG"] = support.getElementsByTagName ?
+		function( tag, context ) {
+			if ( typeof context.getElementsByTagName !== "undefined" ) {
+				return context.getElementsByTagName( tag );
+
+			// DocumentFragment nodes don't have gEBTN
+			} else if ( support.qsa ) {
+				return context.querySelectorAll( tag );
+			}
+		} :
+
+		function( tag, context ) {
+			var elem,
+				tmp = [],
+				i = 0,
+				// By happy coincidence, a (broken) gEBTN appears on DocumentFragment nodes too
+				results = context.getElementsByTagName( tag );
+
+			// Filter out possible comments
+			if ( tag === "*" ) {
+				while ( (elem = results[i++]) ) {
+					if ( elem.nodeType === 1 ) {
+						tmp.push( elem );
+					}
+				}
+
+				return tmp;
+			}
+			return results;
+		};
+
+	// Class
+	Expr.find["CLASS"] = support.getElementsByClassName && function( className, context ) {
+		if ( documentIsHTML ) {
+			return context.getElementsByClassName( className );
+		}
+	};
+
+	/* QSA/matchesSelector
+	---------------------------------------------------------------------- */
+
+	// QSA and matchesSelector support
+
+	// matchesSelector(:active) reports false when true (IE9/Opera 11.5)
+	rbuggyMatches = [];
+
+	// qSa(:focus) reports false when true (Chrome 21)
+	// We allow this because of a bug in IE8/9 that throws an error
+	// whenever `document.activeElement` is accessed on an iframe
+	// So, we allow :focus to pass through QSA all the time to avoid the IE error
+	// See http://bugs.jquery.com/ticket/13378
+	rbuggyQSA = [];
+
+	if ( (support.qsa = rnative.test( doc.querySelectorAll )) ) {
+		// Build QSA regex
+		// Regex strategy adopted from Diego Perini
+		assert(function( div ) {
+			// Select is set to empty string on purpose
+			// This is to test IE's treatment of not explicitly
+			// setting a boolean content attribute,
+			// since its presence should be enough
+			// http://bugs.jquery.com/ticket/12359
+			docElem.appendChild( div ).innerHTML = "<a id='" + expando + "'></a>" +
+				"<select id='" + expando + "-\f]' msallowcapture=''>" +
+				"<option selected=''></option></select>";
+
+			// Support: IE8, Opera 11-12.16
+			// Nothing should be selected when empty strings follow ^= or $= or *=
+			// The test attribute must be unknown in Opera but "safe" for WinRT
+			// http://msdn.microsoft.com/en-us/library/ie/hh465388.aspx#attribute_section
+			if ( div.querySelectorAll("[msallowcapture^='']").length ) {
+				rbuggyQSA.push( "[*^$]=" + whitespace + "*(?:''|\"\")" );
+			}
+
+			// Support: IE8
+			// Boolean attributes and "value" are not treated correctly
+			if ( !div.querySelectorAll("[selected]").length ) {
+				rbuggyQSA.push( "\\[" + whitespace + "*(?:value|" + booleans + ")" );
+			}
+
+			// Support: Chrome<29, Android<4.2+, Safari<7.0+, iOS<7.0+, PhantomJS<1.9.7+
+			if ( !div.querySelectorAll( "[id~=" + expando + "-]" ).length ) {
+				rbuggyQSA.push("~=");
+			}
+
+			// Webkit/Opera - :checked should return selected option elements
+			// http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked
+			// IE8 throws error here and will not see later tests
+			if ( !div.querySelectorAll(":checked").length ) {
+				rbuggyQSA.push(":checked");
+			}
+
+			// Support: Safari 8+, iOS 8+
+			// https://bugs.webkit.org/show_bug.cgi?id=136851
+			// In-page `selector#id sibing-combinator selector` fails
+			if ( !div.querySelectorAll( "a#" + expando + "+*" ).length ) {
+				rbuggyQSA.push(".#.+[+~]");
+			}
+		});
+
+		assert(function( div ) {
+			// Support: Windows 8 Native Apps
+			// The type and name attributes are restricted during .innerHTML assignment
+			var input = doc.createElement("input");
+			input.setAttribute( "type", "hidden" );
+			div.appendChild( input ).setAttribute( "name", "D" );
+
+			// Support: IE8
+			// Enforce case-sensitivity of name attribute
+			if ( div.querySelectorAll("[name=d]").length ) {
+				rbuggyQSA.push( "name" + whitespace + "*[*^$|!~]?=" );
+			}
+
+			// FF 3.5 - :enabled/:disabled and hidden elements (hidden elements are still enabled)
+			// IE8 throws error here and will not see later tests
+			if ( !div.querySelectorAll(":enabled").length ) {
+				rbuggyQSA.push( ":enabled", ":disabled" );
+			}
+
+			// Opera 10-11 does not throw on post-comma invalid pseudos
+			div.querySelectorAll("*,:x");
+			rbuggyQSA.push(",.*:");
+		});
+	}
+
+	if ( (support.matchesSelector = rnative.test( (matches = docElem.matches ||
+		docElem.webkitMatchesSelector ||
+		docElem.mozMatchesSelector ||
+		docElem.oMatchesSelector ||
+		docElem.msMatchesSelector) )) ) {
+
+		assert(function( div ) {
+			// Check to see if it's possible to do matchesSelector
+			// on a disconnected node (IE 9)
+			support.disconnectedMatch = matches.call( div, "div" );
+
+			// This should fail with an exception
+			// Gecko does not error, returns false instead
+			matches.call( div, "[s!='']:x" );
+			rbuggyMatches.push( "!=", pseudos );
+		});
+	}
+
+	rbuggyQSA = rbuggyQSA.length && new RegExp( rbuggyQSA.join("|") );
+	rbuggyMatches = rbuggyMatches.length && new RegExp( rbuggyMatches.join("|") );
+
+	/* Contains
+	---------------------------------------------------------------------- */
+	hasCompare = rnative.test( docElem.compareDocumentPosition );
+
+	// Element contains another
+	// Purposefully does not implement inclusive descendent
+	// As in, an element does not contain itself
+	contains = hasCompare || rnative.test( docElem.contains ) ?
+		function( a, b ) {
+			var adown = a.nodeType === 9 ? a.documentElement : a,
+				bup = b && b.parentNode;
+			return a === bup || !!( bup && bup.nodeType === 1 && (
+				adown.contains ?
+					adown.contains( bup ) :
+					a.compareDocumentPosition && a.compareDocumentPosition( bup ) & 16
+			));
+		} :
+		function( a, b ) {
+			if ( b ) {
+				while ( (b = b.parentNode) ) {
+					if ( b === a ) {
+						return true;
+					}
+				}
+			}
+			return false;
+		};
+
+	/* Sorting
+	---------------------------------------------------------------------- */
+
+	// Document order sorting
+	sortOrder = hasCompare ?
+	function( a, b ) {
+
+		// Flag for duplicate removal
+		if ( a === b ) {
+			hasDuplicate = true;
+			return 0;
+		}
+
+		// Sort on method existence if only one input has compareDocumentPosition
+		var compare = !a.compareDocumentPosition - !b.compareDocumentPosition;
+		if ( compare ) {
+			return compare;
+		}
+
+		// Calculate position if both inputs belong to the same document
+		compare = ( a.ownerDocument || a ) === ( b.ownerDocument || b ) ?
+			a.compareDocumentPosition( b ) :
+
+			// Otherwise we know they are disconnected
+			1;
+
+		// Disconnected nodes
+		if ( compare & 1 ||
+			(!support.sortDetached && b.compareDocumentPosition( a ) === compare) ) {
+
+			// Choose the first element that is related to our preferred document
+			if ( a === doc || a.ownerDocument === preferredDoc && contains(preferredDoc, a) ) {
+				return -1;
+			}
+			if ( b === doc || b.ownerDocument === preferredDoc && contains(preferredDoc, b) ) {
+				return 1;
+			}
+
+			// Maintain original order
+			return sortInput ?
+				( indexOf( sortInput, a ) - indexOf( sortInput, b ) ) :
+				0;
+		}
+
+		return compare & 4 ? -1 : 1;
+	} :
+	function( a, b ) {
+		// Exit early if the nodes are identical
+		if ( a === b ) {
+			hasDuplicate = true;
+			return 0;
+		}
+
+		var cur,
+			i = 0,
+			aup = a.parentNode,
+			bup = b.parentNode,
+			ap = [ a ],
+			bp = [ b ];
+
+		// Parentless nodes are either documents or disconnected
+		if ( !aup || !bup ) {
+			return a === doc ? -1 :
+				b === doc ? 1 :
+				aup ? -1 :
+				bup ? 1 :
+				sortInput ?
+				( indexOf( sortInput, a ) - indexOf( sortInput, b ) ) :
+				0;
+
+		// If the nodes are siblings, we can do a quick check
+		} else if ( aup === bup ) {
+			return siblingCheck( a, b );
+		}
+
+		// Otherwise we need full lists of their ancestors for comparison
+		cur = a;
+		while ( (cur = cur.parentNode) ) {
+			ap.unshift( cur );
+		}
+		cur = b;
+		while ( (cur = cur.parentNode) ) {
+			bp.unshift( cur );
+		}
+
+		// Walk down the tree looking for a discrepancy
+		while ( ap[i] === bp[i] ) {
+			i++;
+		}
+
+		return i ?
+			// Do a sibling check if the nodes have a common ancestor
+			siblingCheck( ap[i], bp[i] ) :
+
+			// Otherwise nodes in our document sort first
+			ap[i] === preferredDoc ? -1 :
+			bp[i] === preferredDoc ? 1 :
+			0;
+	};
+
+	return doc;
+};
+
+Sizzle.matches = function( expr, elements ) {
+	return Sizzle( expr, null, null, elements );
+};
+
+Sizzle.matchesSelector = function( elem, expr ) {
+	// Set document vars if needed
+	if ( ( elem.ownerDocument || elem ) !== document ) {
+		setDocument( elem );
+	}
+
+	// Make sure that attribute selectors are quoted
+	expr = expr.replace( rattributeQuotes, "='$1']" );
+
+	if ( support.matchesSelector && documentIsHTML &&
+		( !rbuggyMatches || !rbuggyMatches.test( expr ) ) &&
+		( !rbuggyQSA     || !rbuggyQSA.test( expr ) ) ) {
+
+		try {
+			var ret = matches.call( elem, expr );
+
+			// IE 9's matchesSelector returns false on disconnected nodes
+			if ( ret || support.disconnectedMatch ||
+					// As well, disconnected nodes are said to be in a document
+					// fragment in IE 9
+					elem.document && elem.document.nodeType !== 11 ) {
+				return ret;
+			}
+		} catch (e) {}
+	}
+
+	return Sizzle( expr, document, null, [ elem ] ).length > 0;
+};
+
+Sizzle.contains = function( context, elem ) {
+	// Set document vars if needed
+	if ( ( context.ownerDocument || context ) !== document ) {
+		setDocument( context );
+	}
+	return contains( context, elem );
+};
+
+Sizzle.attr = function( elem, name ) {
+	// Set document vars if needed
+	if ( ( elem.ownerDocument || elem ) !== document ) {
+		setDocument( elem );
+	}
+
+	var fn = Expr.attrHandle[ name.toLowerCase() ],
+		// Don't get fooled by Object.prototype properties (jQuery #13807)
+		val = fn && hasOwn.call( Expr.attrHandle, name.toLowerCase() ) ?
+			fn( elem, name, !documentIsHTML ) :
+			undefined;
+
+	return val !== undefined ?
+		val :
+		support.attributes || !documentIsHTML ?
+			elem.getAttribute( name ) :
+			(val = elem.getAttributeNode(name)) && val.specified ?
+				val.value :
+				null;
+};
+
+Sizzle.error = function( msg ) {
+	throw new Error( "Syntax error, unrecognized expression: " + msg );
+};
+
+/**
+ * Document sorting and removing duplicates
+ * @param {ArrayLike} results
+ */
+Sizzle.uniqueSort = function( results ) {
+	var elem,
+		duplicates = [],
+		j = 0,
+		i = 0;
+
+	// Unless we *know* we can detect duplicates, assume their presence
+	hasDuplicate = !support.detectDuplicates;
+	sortInput = !support.sortStable && results.slice( 0 );
+	results.sort( sortOrder );
+
+	if ( hasDuplicate ) {
+		while ( (elem = results[i++]) ) {
+			if ( elem === results[ i ] ) {
+				j = duplicates.push( i );
+			}
+		}
+		while ( j-- ) {
+			results.splice( duplicates[ j ], 1 );
+		}
+	}
+
+	// Clear input after sorting to release objects
+	// See https://github.com/jquery/sizzle/pull/225
+	sortInput = null;
+
+	return results;
+};
+
+/**
+ * Utility function for retrieving the text value of an array of DOM nodes
+ * @param {Array|Element} elem
+ */
+getText = Sizzle.getText = function( elem ) {
+	var node,
+		ret = "",
+		i = 0,
+		nodeType = elem.nodeType;
+
+	if ( !nodeType ) {
+		// If no nodeType, this is expected to be an array
+		while ( (node = elem[i++]) ) {
+			// Do not traverse comment nodes
+			ret += getText( node );
+		}
+	} else if ( nodeType === 1 || nodeType === 9 || nodeType === 11 ) {
+		// Use textContent for elements
+		// innerText usage removed for consistency of new lines (jQuery #11153)
+		if ( typeof elem.textContent === "string" ) {
+			return elem.textContent;
+		} else {
+			// Traverse its children
+			for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) {
+				ret += getText( elem );
+			}
+		}
+	} else if ( nodeType === 3 || nodeType === 4 ) {
+		return elem.nodeValue;
+	}
+	// Do not include comment or processing instruction nodes
+
+	return ret;
+};
+
+Expr = Sizzle.selectors = {
+
+	// Can be adjusted by the user
+	cacheLength: 50,
+
+	createPseudo: markFunction,
+
+	match: matchExpr,
+
+	attrHandle: {},
+
+	find: {},
+
+	relative: {
+		">": { dir: "parentNode", first: true },
+		" ": { dir: "parentNode" },
+		"+": { dir: "previousSibling", first: true },
+		"~": { dir: "previousSibling" }
+	},
+
+	preFilter: {
+		"ATTR": function( match ) {
+			match[1] = match[1].replace( runescape, funescape );
+
+			// Move the given value to match[3] whether quoted or unquoted
+			match[3] = ( match[3] || match[4] || match[5] || "" ).replace( runescape, funescape );
+
+			if ( match[2] === "~=" ) {
+				match[3] = " " + match[3] + " ";
+			}
+
+			return match.slice( 0, 4 );
+		},
+
+		"CHILD": function( match ) {
+			/* matches from matchExpr["CHILD"]
+				1 type (only|nth|...)
+				2 what (child|of-type)
+				3 argument (even|odd|\d*|\d*n([+-]\d+)?|...)
+				4 xn-component of xn+y argument ([+-]?\d*n|)
+				5 sign of xn-component
+				6 x of xn-component
+				7 sign of y-component
+				8 y of y-component
+			*/
+			match[1] = match[1].toLowerCase();
+
+			if ( match[1].slice( 0, 3 ) === "nth" ) {
+				// nth-* requires argument
+				if ( !match[3] ) {
+					Sizzle.error( match[0] );
+				}
+
+				// numeric x and y parameters for Expr.filter.CHILD
+				// remember that false/true cast respectively to 0/1
+				match[4] = +( match[4] ? match[5] + (match[6] || 1) : 2 * ( match[3] === "even" || match[3] === "odd" ) );
+				match[5] = +( ( match[7] + match[8] ) || match[3] === "odd" );
+
+			// other types prohibit arguments
+			} else if ( match[3] ) {
+				Sizzle.error( match[0] );
+			}
+
+			return match;
+		},
+
+		"PSEUDO": function( match ) {
+			var excess,
+				unquoted = !match[6] && match[2];
+
+			if ( matchExpr["CHILD"].test( match[0] ) ) {
+				return null;
+			}
+
+			// Accept quoted arguments as-is
+			if ( match[3] ) {
+				match[2] = match[4] || match[5] || "";
+
+			// Strip excess characters from unquoted arguments
+			} else if ( unquoted && rpseudo.test( unquoted ) &&
+				// Get excess from tokenize (recursively)
+				(excess = tokenize( unquoted, true )) &&
+				// advance to the next closing parenthesis
+				(excess = unquoted.indexOf( ")", unquoted.length - excess ) - unquoted.length) ) {
+
+				// excess is a negative index
+				match[0] = match[0].slice( 0, excess );
+				match[2] = unquoted.slice( 0, excess );
+			}
+
+			// Return only captures needed by the pseudo filter method (type and argument)
+			return match.slice( 0, 3 );
+		}
+	},
+
+	filter: {
+
+		"TAG": function( nodeNameSelector ) {
+			var nodeName = nodeNameSelector.replace( runescape, funescape ).toLowerCase();
+			return nodeNameSelector === "*" ?
+				function() { return true; } :
+				function( elem ) {
+					return elem.nodeName && elem.nodeName.toLowerCase() === nodeName;
+				};
+		},
+
+		"CLASS": function( className ) {
+			var pattern = classCache[ className + " " ];
+
+			return pattern ||
+				(pattern = new RegExp( "(^|" + whitespace + ")" + className + "(" + whitespace + "|$)" )) &&
+				classCache( className, function( elem ) {
+					return pattern.test( typeof elem.className === "string" && elem.className || typeof elem.getAttribute !== "undefined" && elem.getAttribute("class") || "" );
+				});
+		},
+
+		"ATTR": function( name, operator, check ) {
+			return function( elem ) {
+				var result = Sizzle.attr( elem, name );
+
+				if ( result == null ) {
+					return operator === "!=";
+				}
+				if ( !operator ) {
+					return true;
+				}
+
+				result += "";
+
+				return operator === "=" ? result === check :
+					operator === "!=" ? result !== check :
+					operator === "^=" ? check && result.indexOf( check ) === 0 :
+					operator === "*=" ? check && result.indexOf( check ) > -1 :
+					operator === "$=" ? check && result.slice( -check.length ) === check :
+					operator === "~=" ? ( " " + result.replace( rwhitespace, " " ) + " " ).indexOf( check ) > -1 :
+					operator === "|=" ? result === check || result.slice( 0, check.length + 1 ) === check + "-" :
+					false;
+			};
+		},
+
+		"CHILD": function( type, what, argument, first, last ) {
+			var simple = type.slice( 0, 3 ) !== "nth",
+				forward = type.slice( -4 ) !== "last",
+				ofType = what === "of-type";
+
+			return first === 1 && last === 0 ?
+
+				// Shortcut for :nth-*(n)
+				function( elem ) {
+					return !!elem.parentNode;
+				} :
+
+				function( elem, context, xml ) {
+					var cache, outerCache, node, diff, nodeIndex, start,
+						dir = simple !== forward ? "nextSibling" : "previousSibling",
+						parent = elem.parentNode,
+						name = ofType && elem.nodeName.toLowerCase(),
+						useCache = !xml && !ofType;
+
+					if ( parent ) {
+
+						// :(first|last|only)-(child|of-type)
+						if ( simple ) {
+							while ( dir ) {
+								node = elem;
+								while ( (node = node[ dir ]) ) {
+									if ( ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1 ) {
+										return false;
+									}
+								}
+								// Reverse direction for :only-* (if we haven't yet done so)
+								start = dir = type === "only" && !start && "nextSibling";
+							}
+							return true;
+						}
+
+						start = [ forward ? parent.firstChild : parent.lastChild ];
+
+						// non-xml :nth-child(...) stores cache data on `parent`
+						if ( forward && useCache ) {
+							// Seek `elem` from a previously-cached index
+							outerCache = parent[ expando ] || (parent[ expando ] = {});
+							cache = outerCache[ type ] || [];
+							nodeIndex = cache[0] === dirruns && cache[1];
+							diff = cache[0] === dirruns && cache[2];
+							node = nodeIndex && parent.childNodes[ nodeIndex ];
+
+							while ( (node = ++nodeIndex && node && node[ dir ] ||
+
+								// Fallback to seeking `elem` from the start
+								(diff = nodeIndex = 0) || start.pop()) ) {
+
+								// When found, cache indexes on `parent` and break
+								if ( node.nodeType === 1 && ++diff && node === elem ) {
+									outerCache[ type ] = [ dirruns, nodeIndex, diff ];
+									break;
+								}
+							}
+
+						// Use previously-cached element index if available
+						} else if ( useCache && (cache = (elem[ expando ] || (elem[ expando ] = {}))[ type ]) && cache[0] === dirruns ) {
+							diff = cache[1];
+
+						// xml :nth-child(...) or :nth-last-child(...) or :nth(-last)?-of-type(...)
+						} else {
+							// Use the same loop as above to seek `elem` from the start
+							while ( (node = ++nodeIndex && node && node[ dir ] ||
+								(diff = nodeIndex = 0) || start.pop()) ) {
+
+								if ( ( ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1 ) && ++diff ) {
+									// Cache the index of each encountered element
+									if ( useCache ) {
+										(node[ expando ] || (node[ expando ] = {}))[ type ] = [ dirruns, diff ];
+									}
+
+									if ( node === elem ) {
+										break;
+									}
+								}
+							}
+						}
+
+						// Incorporate the offset, then check against cycle size
+						diff -= last;
+						return diff === first || ( diff % first === 0 && diff / first >= 0 );
+					}
+				};
+		},
+
+		"PSEUDO": function( pseudo, argument ) {
+			// pseudo-class names are case-insensitive
+			// http://www.w3.org/TR/selectors/#pseudo-classes
+			// Prioritize by case sensitivity in case custom pseudos are added with uppercase letters
+			// Remember that setFilters inherits from pseudos
+			var args,
+				fn = Expr.pseudos[ pseudo ] || Expr.setFilters[ pseudo.toLowerCase() ] ||
+					Sizzle.error( "unsupported pseudo: " + pseudo );
+
+			// The user may use createPseudo to indicate that
+			// arguments are needed to create the filter function
+			// just as Sizzle does
+			if ( fn[ expando ] ) {
+				return fn( argument );
+			}
+
+			// But maintain support for old signatures
+			if ( fn.length > 1 ) {
+				args = [ pseudo, pseudo, "", argument ];
+				return Expr.setFilters.hasOwnProperty( pseudo.toLowerCase() ) ?
+					markFunction(function( seed, matches ) {
+						var idx,
+							matched = fn( seed, argument ),
+							i = matched.length;
+						while ( i-- ) {
+							idx = indexOf( seed, matched[i] );
+							seed[ idx ] = !( matches[ idx ] = matched[i] );
+						}
+					}) :
+					function( elem ) {
+						return fn( elem, 0, args );
+					};
+			}
+
+			return fn;
+		}
+	},
+
+	pseudos: {
+		// Potentially complex pseudos
+		"not": markFunction(function( selector ) {
+			// Trim the selector passed to compile
+			// to avoid treating leading and trailing
+			// spaces as combinators
+			var input = [],
+				results = [],
+				matcher = compile( selector.replace( rtrim, "$1" ) );
+
+			return matcher[ expando ] ?
+				markFunction(function( seed, matches, context, xml ) {
+					var elem,
+						unmatched = matcher( seed, null, xml, [] ),
+						i = seed.length;
+
+					// Match elements unmatched by `matcher`
+					while ( i-- ) {
+						if ( (elem = unmatched[i]) ) {
+							seed[i] = !(matches[i] = elem);
+						}
+					}
+				}) :
+				function( elem, context, xml ) {
+					input[0] = elem;
+					matcher( input, null, xml, results );
+					// Don't keep the element (issue #299)
+					input[0] = null;
+					return !results.pop();
+				};
+		}),
+
+		"has": markFunction(function( selector ) {
+			return function( elem ) {
+				return Sizzle( selector, elem ).length > 0;
+			};
+		}),
+
+		"contains": markFunction(function( text ) {
+			text = text.replace( runescape, funescape );
+			return function( elem ) {
+				return ( elem.textContent || elem.innerText || getText( elem ) ).indexOf( text ) > -1;
+			};
+		}),
+
+		// "Whether an element is represented by a :lang() selector
+		// is based solely on the element's language value
+		// being equal to the identifier C,
+		// or beginning with the identifier C immediately followed by "-".
+		// The matching of C against the element's language value is performed case-insensitively.
+		// The identifier C does not have to be a valid language name."
+		// http://www.w3.org/TR/selectors/#lang-pseudo
+		"lang": markFunction( function( lang ) {
+			// lang value must be a valid identifier
+			if ( !ridentifier.test(lang || "") ) {
+				Sizzle.error( "unsupported lang: " + lang );
+			}
+			lang = lang.replace( runescape, funescape ).toLowerCase();
+			return function( elem ) {
+				var elemLang;
+				do {
+					if ( (elemLang = documentIsHTML ?
+						elem.lang :
+						elem.getAttribute("xml:lang") || elem.getAttribute("lang")) ) {
+
+						elemLang = elemLang.toLowerCase();
+						return elemLang === lang || elemLang.indexOf( lang + "-" ) === 0;
+					}
+				} while ( (elem = elem.parentNode) && elem.nodeType === 1 );
+				return false;
+			};
+		}),
+
+		// Miscellaneous
+		"target": function( elem ) {
+			var hash = window.location && window.location.hash;
+			return hash && hash.slice( 1 ) === elem.id;
+		},
+
+		"root": function( elem ) {
+			return elem === docElem;
+		},
+
+		"focus": function( elem ) {
+			return elem === document.activeElement && (!document.hasFocus || document.hasFocus()) && !!(elem.type || elem.href || ~elem.tabIndex);
+		},
+
+		// Boolean properties
+		"enabled": function( elem ) {
+			return elem.disabled === false;
+		},
+
+		"disabled": function( elem ) {
+			return elem.disabled === true;
+		},
+
+		"checked": function( elem ) {
+			// In CSS3, :checked should return both checked and selected elements
+			// http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked
+			var nodeName = elem.nodeName.toLowerCase();
+			return (nodeName === "input" && !!elem.checked) || (nodeName === "option" && !!elem.selected);
+		},
+
+		"selected": function( elem ) {
+			// Accessing this property makes selected-by-default
+			// options in Safari work properly
+			if ( elem.parentNode ) {
+				elem.parentNode.selectedIndex;
+			}
+
+			return elem.selected === true;
+		},
+
+		// Contents
+		"empty": function( elem ) {
+			// http://www.w3.org/TR/selectors/#empty-pseudo
+			// :empty is negated by element (1) or content nodes (text: 3; cdata: 4; entity ref: 5),
+			//   but not by others (comment: 8; processing instruction: 7; etc.)
+			// nodeType < 6 works because attributes (2) do not appear as children
+			for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) {
+				if ( elem.nodeType < 6 ) {
+					return false;
+				}
+			}
+			return true;
+		},
+
+		"parent": function( elem ) {
+			return !Expr.pseudos["empty"]( elem );
+		},
+
+		// Element/input types
+		"header": function( elem ) {
+			return rheader.test( elem.nodeName );
+		},
+
+		"input": function( elem ) {
+			return rinputs.test( elem.nodeName );
+		},
+
+		"button": function( elem ) {
+			var name = elem.nodeName.toLowerCase();
+			return name === "input" && elem.type === "button" || name === "button";
+		},
+
+		"text": function( elem ) {
+			var attr;
+			return elem.nodeName.toLowerCase() === "input" &&
+				elem.type === "text" &&
+
+				// Support: IE<8
+				// New HTML5 attribute values (e.g., "search") appear with elem.type === "text"
+				( (attr = elem.getAttribute("type")) == null || attr.toLowerCase() === "text" );
+		},
+
+		// Position-in-collection
+		"first": createPositionalPseudo(function() {
+			return [ 0 ];
+		}),
+
+		"last": createPositionalPseudo(function( matchIndexes, length ) {
+			return [ length - 1 ];
+		}),
+
+		"eq": createPositionalPseudo(function( matchIndexes, length, argument ) {
+			return [ argument < 0 ? argument + length : argument ];
+		}),
+
+		"even": createPositionalPseudo(function( matchIndexes, length ) {
+			var i = 0;
+			for ( ; i < length; i += 2 ) {
+				matchIndexes.push( i );
+			}
+			return matchIndexes;
+		}),
+
+		"odd": createPositionalPseudo(function( matchIndexes, length ) {
+			var i = 1;
+			for ( ; i < length; i += 2 ) {
+				matchIndexes.push( i );
+			}
+			return matchIndexes;
+		}),
+
+		"lt": createPositionalPseudo(function( matchIndexes, length, argument ) {
+			var i = argument < 0 ? argument + length : argument;
+			for ( ; --i >= 0; ) {
+				matchIndexes.push( i );
+			}
+			return matchIndexes;
+		}),
+
+		"gt": createPositionalPseudo(function( matchIndexes, length, argument ) {
+			var i = argument < 0 ? argument + length : argument;
+			for ( ; ++i < length; ) {
+				matchIndexes.push( i );
+			}
+			return matchIndexes;
+		})
+	}
+};
+
+Expr.pseudos["nth"] = Expr.pseudos["eq"];
+
+// Add button/input type pseudos
+for ( i in { radio: true, checkbox: true, file: true, password: true, image: true } ) {
+	Expr.pseudos[ i ] = createInputPseudo( i );
+}
+for ( i in { submit: true, reset: true } ) {
+	Expr.pseudos[ i ] = createButtonPseudo( i );
+}
+
+// Easy API for creating new setFilters
+function setFilters() {}
+setFilters.prototype = Expr.filters = Expr.pseudos;
+Expr.setFilters = new setFilters();
+
+tokenize = Sizzle.tokenize = function( selector, parseOnly ) {
+	var matched, match, tokens, type,
+		soFar, groups, preFilters,
+		cached = tokenCache[ selector + " " ];
+
+	if ( cached ) {
+		return parseOnly ? 0 : cached.slice( 0 );
+	}
+
+	soFar = selector;
+	groups = [];
+	preFilters = Expr.preFilter;
+
+	while ( soFar ) {
+
+		// Comma and first run
+		if ( !matched || (match = rcomma.exec( soFar )) ) {
+			if ( match ) {
+				// Don't consume trailing commas as valid
+				soFar = soFar.slice( match[0].length ) || soFar;
+			}
+			groups.push( (tokens = []) );
+		}
+
+		matched = false;
+
+		// Combinators
+		if ( (match = rcombinators.exec( soFar )) ) {
+			matched = match.shift();
+			tokens.push({
+				value: matched,
+				// Cast descendant combinators to space
+				type: match[0].replace( rtrim, " " )
+			});
+			soFar = soFar.slice( matched.length );
+		}
+
+		// Filters
+		for ( type in Expr.filter ) {
+			if ( (match = matchExpr[ type ].exec( soFar )) && (!preFilters[ type ] ||
+				(match = preFilters[ type ]( match ))) ) {
+				matched = match.shift();
+				tokens.push({
+					value: matched,
+					type: type,
+					matches: match
+				});
+				soFar = soFar.slice( matched.length );
+			}
+		}
+
+		if ( !matched ) {
+			break;
+		}
+	}
+
+	// Return the length of the invalid excess
+	// if we're just parsing
+	// Otherwise, throw an error or return tokens
+	return parseOnly ?
+		soFar.length :
+		soFar ?
+			Sizzle.error( selector ) :
+			// Cache the tokens
+			tokenCache( selector, groups ).slice( 0 );
+};
+
+function toSelector( tokens ) {
+	var i = 0,
+		len = tokens.length,
+		selector = "";
+	for ( ; i < len; i++ ) {
+		selector += tokens[i].value;
+	}
+	return selector;
+}
+
+function addCombinator( matcher, combinator, base ) {
+	var dir = combinator.dir,
+		checkNonElements = base && dir === "parentNode",
+		doneName = done++;
+
+	return combinator.first ?
+		// Check against closest ancestor/preceding element
+		function( elem, context, xml ) {
+			while ( (elem = elem[ dir ]) ) {
+				if ( elem.nodeType === 1 || checkNonElements ) {
+					return matcher( elem, context, xml );
+				}
+			}
+		} :
+
+		// Check against all ancestor/preceding elements
+		function( elem, context, xml ) {
+			var oldCache, outerCache,
+				newCache = [ dirruns, doneName ];
+
+			// We can't set arbitrary data on XML nodes, so they don't benefit from dir caching
+			if ( xml ) {
+				while ( (elem = elem[ dir ]) ) {
+					if ( elem.nodeType === 1 || checkNonElements ) {
+						if ( matcher( elem, context, xml ) ) {
+							return true;
+						}
+					}
+				}
+			} else {
+				while ( (elem = elem[ dir ]) ) {
+					if ( elem.nodeType === 1 || checkNonElements ) {
+						outerCache = elem[ expando ] || (elem[ expando ] = {});
+						if ( (oldCache = outerCache[ dir ]) &&
+							oldCache[ 0 ] === dirruns && oldCache[ 1 ] === doneName ) {
+
+							// Assign to newCache so results back-propagate to previous elements
+							return (newCache[ 2 ] = oldCache[ 2 ]);
+						} else {
+							// Reuse newcache so results back-propagate to previous elements
+							outerCache[ dir ] = newCache;
+
+							// A match means we're done; a fail means we have to keep checking
+							if ( (newCache[ 2 ] = matcher( elem, context, xml )) ) {
+								return true;
+							}
+						}
+					}
+				}
+			}
+		};
+}
+
+function elementMatcher( matchers ) {
+	return matchers.length > 1 ?
+		function( elem, context, xml ) {
+			var i = matchers.length;
+			while ( i-- ) {
+				if ( !matchers[i]( elem, context, xml ) ) {
+					return false;
+				}
+			}
+			return true;
+		} :
+		matchers[0];
+}
+
+function multipleContexts( selector, contexts, results ) {
+	var i = 0,
+		len = contexts.length;
+	for ( ; i < len; i++ ) {
+		Sizzle( selector, contexts[i], results );
+	}
+	return results;
+}
+
+function condense( unmatched, map, filter, context, xml ) {
+	var elem,
+		newUnmatched = [],
+		i = 0,
+		len = unmatched.length,
+		mapped = map != null;
+
+	for ( ; i < len; i++ ) {
+		if ( (elem = unmatched[i]) ) {
+			if ( !filter || filter( elem, context, xml ) ) {
+				newUnmatched.push( elem );
+				if ( mapped ) {
+					map.push( i );
+				}
+			}
+		}
+	}
+
+	return newUnmatched;
+}
+
+function setMatcher( preFilter, selector, matcher, postFilter, postFinder, postSelector ) {
+	if ( postFilter && !postFilter[ expando ] ) {
+		postFilter = setMatcher( postFilter );
+	}
+	if ( postFinder && !postFinder[ expando ] ) {
+		postFinder = setMatcher( postFinder, postSelector );
+	}
+	return markFunction(function( seed, results, context, xml ) {
+		var temp, i, elem,
+			preMap = [],
+			postMap = [],
+			preexisting = results.length,
+
+			// Get initial elements from seed or context
+			elems = seed || multipleContexts( selector || "*", context.nodeType ? [ context ] : context, [] ),
+
+			// Prefilter to get matcher input, preserving a map for seed-results synchronization
+			matcherIn = preFilter && ( seed || !selector ) ?
+				condense( elems, preMap, preFilter, context, xml ) :
+				elems,
+
+			matcherOut = matcher ?
+				// If we have a postFinder, or filtered seed, or non-seed postFilter or preexisting results,
+				postFinder || ( seed ? preFilter : preexisting || postFilter ) ?
+
+					// ...intermediate processing is necessary
+					[] :
+
+					// ...otherwise use results directly
+					results :
+				matcherIn;
+
+		// Find primary matches
+		if ( matcher ) {
+			matcher( matcherIn, matcherOut, context, xml );
+		}
+
+		// Apply postFilter
+		if ( postFilter ) {
+			temp = condense( matcherOut, postMap );
+			postFilter( temp, [], context, xml );
+
+			// Un-match failing elements by moving them back to matcherIn
+			i = temp.length;
+			while ( i-- ) {
+				if ( (elem = temp[i]) ) {
+					matcherOut[ postMap[i] ] = !(matcherIn[ postMap[i] ] = elem);
+				}
+			}
+		}
+
+		if ( seed ) {
+			if ( postFinder || preFilter ) {
+				if ( postFinder ) {
+					// Get the final matcherOut by condensing this intermediate into postFinder contexts
+					temp = [];
+					i = matcherOut.length;
+					while ( i-- ) {
+						if ( (elem = matcherOut[i]) ) {
+							// Restore matcherIn since elem is not yet a final match
+							temp.push( (matcherIn[i] = elem) );
+						}
+					}
+					postFinder( null, (matcherOut = []), temp, xml );
+				}
+
+				// Move matched elements from seed to results to keep them synchronized
+				i = matcherOut.length;
+				while ( i-- ) {
+					if ( (elem = matcherOut[i]) &&
+						(temp = postFinder ? indexOf( seed, elem ) : preMap[i]) > -1 ) {
+
+						seed[temp] = !(results[temp] = elem);
+					}
+				}
+			}
+
+		// Add elements to results, through postFinder if defined
+		} else {
+			matcherOut = condense(
+				matcherOut === results ?
+					matcherOut.splice( preexisting, matcherOut.length ) :
+					matcherOut
+			);
+			if ( postFinder ) {
+				postFinder( null, results, matcherOut, xml );
+			} else {
+				push.apply( results, matcherOut );
+			}
+		}
+	});
+}
+
+function matcherFromTokens( tokens ) {
+	var checkContext, matcher, j,
+		len = tokens.length,
+		leadingRelative = Expr.relative[ tokens[0].type ],
+		implicitRelative = leadingRelative || Expr.relative[" "],
+		i = leadingRelative ? 1 : 0,
+
+		// The foundational matcher ensures that elements are reachable from top-level context(s)
+		matchContext = addCombinator( function( elem ) {
+			return elem === checkContext;
+		}, implicitRelative, true ),
+		matchAnyContext = addCombinator( function( elem ) {
+			return indexOf( checkContext, elem ) > -1;
+		}, implicitRelative, true ),
+		matchers = [ function( elem, context, xml ) {
+			var ret = ( !leadingRelative && ( xml || context !== outermostContext ) ) || (
+				(checkContext = context).nodeType ?
+					matchContext( elem, context, xml ) :
+					matchAnyContext( elem, context, xml ) );
+			// Avoid hanging onto element (issue #299)
+			checkContext = null;
+			return ret;
+		} ];
+
+	for ( ; i < len; i++ ) {
+		if ( (matcher = Expr.relative[ tokens[i].type ]) ) {
+			matchers = [ addCombinator(elementMatcher( matchers ), matcher) ];
+		} else {
+			matcher = Expr.filter[ tokens[i].type ].apply( null, tokens[i].matches );
+
+			// Return special upon seeing a positional matcher
+			if ( matcher[ expando ] ) {
+				// Find the next relative operator (if any) for proper handling
+				j = ++i;
+				for ( ; j < len; j++ ) {
+					if ( Expr.relative[ tokens[j].type ] ) {
+						break;
+					}
+				}
+				return setMatcher(
+					i > 1 && elementMatcher( matchers ),
+					i > 1 && toSelector(
+						// If the preceding token was a descendant combinator, insert an implicit any-element `*`
+						tokens.slice( 0, i - 1 ).concat({ value: tokens[ i - 2 ].type === " " ? "*" : "" })
+					).replace( rtrim, "$1" ),
+					matcher,
+					i < j && matcherFromTokens( tokens.slice( i, j ) ),
+					j < len && matcherFromTokens( (tokens = tokens.slice( j )) ),
+					j < len && toSelector( tokens )
+				);
+			}
+			matchers.push( matcher );
+		}
+	}
+
+	return elementMatcher( matchers );
+}
+
+function matcherFromGroupMatchers( elementMatchers, setMatchers ) {
+	var bySet = setMatchers.length > 0,
+		byElement = elementMatchers.length > 0,
+		superMatcher = function( seed, context, xml, results, outermost ) {
+			var elem, j, matcher,
+				matchedCount = 0,
+				i = "0",
+				unmatched = seed && [],
+				setMatched = [],
+				contextBackup = outermostContext,
+				// We must always have either seed elements or outermost context
+				elems = seed || byElement && Expr.find["TAG"]( "*", outermost ),
+				// Use integer dirruns iff this is the outermost matcher
+				dirrunsUnique = (dirruns += contextBackup == null ? 1 : Math.random() || 0.1),
+				len = elems.length;
+
+			if ( outermost ) {
+				outermostContext = context !== document && context;
+			}
+
+			// Add elements passing elementMatchers directly to results
+			// Keep `i` a string if there are no elements so `matchedCount` will be "00" below
+			// Support: IE<9, Safari
+			// Tolerate NodeList properties (IE: "length"; Safari: <number>) matching elements by id
+			for ( ; i !== len && (elem = elems[i]) != null; i++ ) {
+				if ( byElement && elem ) {
+					j = 0;
+					while ( (matcher = elementMatchers[j++]) ) {
+						if ( matcher( elem, context, xml ) ) {
+							results.push( elem );
+							break;
+						}
+					}
+					if ( outermost ) {
+						dirruns = dirrunsUnique;
+					}
+				}
+
+				// Track unmatched elements for set filters
+				if ( bySet ) {
+					// They will have gone through all possible matchers
+					if ( (elem = !matcher && elem) ) {
+						matchedCount--;
+					}
+
+					// Lengthen the array for every element, matched or not
+					if ( seed ) {
+						unmatched.push( elem );
+					}
+				}
+			}
+
+			// Apply set filters to unmatched elements
+			matchedCount += i;
+			if ( bySet && i !== matchedCount ) {
+				j = 0;
+				while ( (matcher = setMatchers[j++]) ) {
+					matcher( unmatched, setMatched, context, xml );
+				}
+
+				if ( seed ) {
+					// Reintegrate element matches to eliminate the need for sorting
+					if ( matchedCount > 0 ) {
+						while ( i-- ) {
+							if ( !(unmatched[i] || setMatched[i]) ) {
+								setMatched[i] = pop.call( results );
+							}
+						}
+					}
+
+					// Discard index placeholder values to get only actual matches
+					setMatched = condense( setMatched );
+				}
+
+				// Add matches to results
+				push.apply( results, setMatched );
+
+				// Seedless set matches succeeding multiple successful matchers stipulate sorting
+				if ( outermost && !seed && setMatched.length > 0 &&
+					( matchedCount + setMatchers.length ) > 1 ) {
+
+					Sizzle.uniqueSort( results );
+				}
+			}
+
+			// Override manipulation of globals by nested matchers
+			if ( outermost ) {
+				dirruns = dirrunsUnique;
+				outermostContext = contextBackup;
+			}
+
+			return unmatched;
+		};
+
+	return bySet ?
+		markFunction( superMatcher ) :
+		superMatcher;
+}
+
+compile = Sizzle.compile = function( selector, match /* Internal Use Only */ ) {
+	var i,
+		setMatchers = [],
+		elementMatchers = [],
+		cached = compilerCache[ selector + " " ];
+
+	if ( !cached ) {
+		// Generate a function of recursive functions that can be used to check each element
+		if ( !match ) {
+			match = tokenize( selector );
+		}
+		i = match.length;
+		while ( i-- ) {
+			cached = matcherFromTokens( match[i] );
+			if ( cached[ expando ] ) {
+				setMatchers.push( cached );
+			} else {
+				elementMatchers.push( cached );
+			}
+		}
+
+		// Cache the compiled function
+		cached = compilerCache( selector, matcherFromGroupMatchers( elementMatchers, setMatchers ) );
+
+		// Save selector and tokenization
+		cached.selector = selector;
+	}
+	return cached;
+};
+
+/**
+ * A low-level selection function that works with Sizzle's compiled
+ *  selector functions
+ * @param {String|Function} selector A selector or a pre-compiled
+ *  selector function built with Sizzle.compile
+ * @param {Element} context
+ * @param {Array} [results]
+ * @param {Array} [seed] A set of elements to match against
+ */
+select = Sizzle.select = function( selector, context, results, seed ) {
+	var i, tokens, token, type, find,
+		compiled = typeof selector === "function" && selector,
+		match = !seed && tokenize( (selector = compiled.selector || selector) );
+
+	results = results || [];
+
+	// Try to minimize operations if there is no seed and only one group
+	if ( match.length === 1 ) {
+
+		// Take a shortcut and set the context if the root selector is an ID
+		tokens = match[0] = match[0].slice( 0 );
+		if ( tokens.length > 2 && (token = tokens[0]).type === "ID" &&
+				support.getById && context.nodeType === 9 && documentIsHTML &&
+				Expr.relative[ tokens[1].type ] ) {
+
+			context = ( Expr.find["ID"]( token.matches[0].replace(runescape, funescape), context ) || [] )[0];
+			if ( !context ) {
+				return results;
+
+			// Precompiled matchers will still verify ancestry, so step up a level
+			} else if ( compiled ) {
+				context = context.parentNode;
+			}
+
+			selector = selector.slice( tokens.shift().value.length );
+		}
+
+		// Fetch a seed set for right-to-left matching
+		i = matchExpr["needsContext"].test( selector ) ? 0 : tokens.length;
+		while ( i-- ) {
+			token = tokens[i];
+
+			// Abort if we hit a combinator
+			if ( Expr.relative[ (type = token.type) ] ) {
+				break;
+			}
+			if ( (find = Expr.find[ type ]) ) {
+				// Search, expanding context for leading sibling combinators
+				if ( (seed = find(
+					token.matches[0].replace( runescape, funescape ),
+					rsibling.test( tokens[0].type ) && testContext( context.parentNode ) || context
+				)) ) {
+
+					// If seed is empty or no tokens remain, we can return early
+					tokens.splice( i, 1 );
+					selector = seed.length && toSelector( tokens );
+					if ( !selector ) {
+						push.apply( results, seed );
+						return results;
+					}
+
+					break;
+				}
+			}
+		}
+	}
+
+	// Compile and execute a filtering function if one is not provided
+	// Provide `match` to avoid retokenization if we modified the selector above
+	( compiled || compile( selector, match ) )(
+		seed,
+		context,
+		!documentIsHTML,
+		results,
+		rsibling.test( selector ) && testContext( context.parentNode ) || context
+	);
+	return results;
+};
+
+// One-time assignments
+
+// Sort stability
+support.sortStable = expando.split("").sort( sortOrder ).join("") === expando;
+
+// Support: Chrome 14-35+
+// Always assume duplicates if they aren't passed to the comparison function
+support.detectDuplicates = !!hasDuplicate;
+
+// Initialize against the default document
+setDocument();
+
+// Support: Webkit<537.32 - Safari 6.0.3/Chrome 25 (fixed in Chrome 27)
+// Detached nodes confoundingly follow *each other*
+support.sortDetached = assert(function( div1 ) {
+	// Should return 1, but returns 4 (following)
+	return div1.compareDocumentPosition( document.createElement("div") ) & 1;
+});
+
+// Support: IE<8
+// Prevent attribute/property "interpolation"
+// http://msdn.microsoft.com/en-us/library/ms536429%28VS.85%29.aspx
+if ( !assert(function( div ) {
+	div.innerHTML = "<a href='#'></a>";
+	return div.firstChild.getAttribute("href") === "#" ;
+}) ) {
+	addHandle( "type|href|height|width", function( elem, name, isXML ) {
+		if ( !isXML ) {
+			return elem.getAttribute( name, name.toLowerCase() === "type" ? 1 : 2 );
+		}
+	});
+}
+
+// Support: IE<9
+// Use defaultValue in place of getAttribute("value")
+if ( !support.attributes || !assert(function( div ) {
+	div.innerHTML = "<input/>";
+	div.firstChild.setAttribute( "value", "" );
+	return div.firstChild.getAttribute( "value" ) === "";
+}) ) {
+	addHandle( "value", function( elem, name, isXML ) {
+		if ( !isXML && elem.nodeName.toLowerCase() === "input" ) {
+			return elem.defaultValue;
+		}
+	});
+}
+
+// Support: IE<9
+// Use getAttributeNode to fetch booleans when getAttribute lies
+if ( !assert(function( div ) {
+	return div.getAttribute("disabled") == null;
+}) ) {
+	addHandle( booleans, function( elem, name, isXML ) {
+		var val;
+		if ( !isXML ) {
+			return elem[ name ] === true ? name.toLowerCase() :
+					(val = elem.getAttributeNode( name )) && val.specified ?
+					val.value :
+				null;
+		}
+	});
+}
+
+return Sizzle;
+
+})( window );
+
+
+
+jQuery.find = Sizzle;
+jQuery.expr = Sizzle.selectors;
+jQuery.expr[":"] = jQuery.expr.pseudos;
+jQuery.unique = Sizzle.uniqueSort;
+jQuery.text = Sizzle.getText;
+jQuery.isXMLDoc = Sizzle.isXML;
+jQuery.contains = Sizzle.contains;
+
+
+
+var rneedsContext = jQuery.expr.match.needsContext;
+
+var rsingleTag = (/^<(\w+)\s*\/?>(?:<\/\1>|)$/);
+
+
+
+var risSimple = /^.[^:#\[\.,]*$/;
+
+// Implement the identical functionality for filter and not
+function winnow( elements, qualifier, not ) {
+	if ( jQuery.isFunction( qualifier ) ) {
+		return jQuery.grep( elements, function( elem, i ) {
+			/* jshint -W018 */
+			return !!qualifier.call( elem, i, elem ) !== not;
+		});
+
+	}
+
+	if ( qualifier.nodeType ) {
+		return jQuery.grep( elements, function( elem ) {
+			return ( elem === qualifier ) !== not;
+		});
+
+	}
+
+	if ( typeof qualifier === "string" ) {
+		if ( risSimple.test( qualifier ) ) {
+			return jQuery.filter( qualifier, elements, not );
+		}
+
+		qualifier = jQuery.filter( qualifier, elements );
+	}
+
+	return jQuery.grep( elements, function( elem ) {
+		return ( jQuery.inArray( elem, qualifier ) >= 0 ) !== not;
+	});
+}
+
+jQuery.filter = function( expr, elems, not ) {
+	var elem = elems[ 0 ];
+
+	if ( not ) {
+		expr = ":not(" + expr + ")";
+	}
+
+	return elems.length === 1 && elem.nodeType === 1 ?
+		jQuery.find.matchesSelector( elem, expr ) ? [ elem ] : [] :
+		jQuery.find.matches( expr, jQuery.grep( elems, function( elem ) {
+			return elem.nodeType === 1;
+		}));
+};
+
+jQuery.fn.extend({
+	find: function( selector ) {
+		var i,
+			ret = [],
+			self = this,
+			len = self.length;
+
+		if ( typeof selector !== "string" ) {
+			return this.pushStack( jQuery( selector ).filter(function() {
+				for ( i = 0; i < len; i++ ) {
+					if ( jQuery.contains( self[ i ], this ) ) {
+						return true;
+					}
+				}
+			}) );
+		}
+
+		for ( i = 0; i < len; i++ ) {
+			jQuery.find( selector, self[ i ], ret );
+		}
+
+		// Needed because $( selector, context ) becomes $( context ).find( selector )
+		ret = this.pushStack( len > 1 ? jQuery.unique( ret ) : ret );
+		ret.selector = this.selector ? this.selector + " " + selector : selector;
+		return ret;
+	},
+	filter: function( selector ) {
+		return this.pushStack( winnow(this, selector || [], false) );
+	},
+	not: function( selector ) {
+		return this.pushStack( winnow(this, selector || [], true) );
+	},
+	is: function( selector ) {
+		return !!winnow(
+			this,
+
+			// If this is a positional/relative selector, check membership in the returned set
+			// so $("p:first").is("p:last") won't return true for a doc with two "p".
+			typeof selector === "string" && rneedsContext.test( selector ) ?
+				jQuery( selector ) :
+				selector || [],
+			false
+		).length;
+	}
+});
+
+
+// Initialize a jQuery object
+
+
+// A central reference to the root jQuery(document)
+var rootjQuery,
+
+	// Use the correct document accordingly with window argument (sandbox)
+	document = window.document,
+
+	// A simple way to check for HTML strings
+	// Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
+	// Strict HTML recognition (#11290: must start with <)
+	rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,
+
+	init = jQuery.fn.init = function( selector, context ) {
+		var match, elem;
+
+		// HANDLE: $(""), $(null), $(undefined), $(false)
+		if ( !selector ) {
+			return this;
+		}
+
+		// Handle HTML strings
+		if ( typeof selector === "string" ) {
+			if ( selector.charAt(0) === "<" && selector.charAt( selector.length - 1 ) === ">" && selector.length >= 3 ) {
+				// Assume that strings that start and end with <> are HTML and skip the regex check
+				match = [ null, selector, null ];
+
+			} else {
+				match = rquickExpr.exec( selector );
+			}
+
+			// Match html or make sure no context is specified for #id
+			if ( match && (match[1] || !context) ) {
+
+				// HANDLE: $(html) -> $(array)
+				if ( match[1] ) {
+					context = context instanceof jQuery ? context[0] : context;
+
+					// scripts is true for back-compat
+					// Intentionally let the error be thrown if parseHTML is not present
+					jQuery.merge( this, jQuery.parseHTML(
+						match[1],
+						context && context.nodeType ? context.ownerDocument || context : document,
+						true
+					) );
+
+					// HANDLE: $(html, props)
+					if ( rsingleTag.test( match[1] ) && jQuery.isPlainObject( context ) ) {
+						for ( match in context ) {
+							// Properties of context are called as methods if possible
+							if ( jQuery.isFunction( this[ match ] ) ) {
+								this[ match ]( context[ match ] );
+
+							// ...and otherwise set as attributes
+							} else {
+								this.attr( match, context[ match ] );
+							}
+						}
+					}
+
+					return this;
+
+				// HANDLE: $(#id)
+				} else {
+					elem = document.getElementById( match[2] );
+
+					// Check parentNode to catch when Blackberry 4.6 returns
+					// nodes that are no longer in the document #6963
+					if ( elem && elem.parentNode ) {
+						// Handle the case where IE and Opera return items
+						// by name instead of ID
+						if ( elem.id !== match[2] ) {
+							return rootjQuery.find( selector );
+						}
+
+						// Otherwise, we inject the element directly into the jQuery object
+						this.length = 1;
+						this[0] = elem;
+					}
+
+					this.context = document;
+					this.selector = selector;
+					return this;
+				}
+
+			// HANDLE: $(expr, $(...))
+			} else if ( !context || context.jquery ) {
+				return ( context || rootjQuery ).find( selector );
+
+			// HANDLE: $(expr, context)
+			// (which is just equivalent to: $(context).find(expr)
+			} else {
+				return this.constructor( context ).find( selector );
+			}
+
+		// HANDLE: $(DOMElement)
+		} else if ( selector.nodeType ) {
+			this.context = this[0] = selector;
+			this.length = 1;
+			return this;
+
+		// HANDLE: $(function)
+		// Shortcut for document ready
+		} else if ( jQuery.isFunction( selector ) ) {
+			return typeof rootjQuery.ready !== "undefined" ?
+				rootjQuery.ready( selector ) :
+				// Execute immediately if ready is not present
+				selector( jQuery );
+		}
+
+		if ( selector.selector !== undefined ) {
+			this.selector = selector.selector;
+			this.context = selector.context;
+		}
+
+		return jQuery.makeArray( selector, this );
+	};
+
+// Give the init function the jQuery prototype for later instantiation
+init.prototype = jQuery.fn;
+
+// Initialize central reference
+rootjQuery = jQuery( document );
+
+
+var rparentsprev = /^(?:parents|prev(?:Until|All))/,
+	// methods guaranteed to produce a unique set when starting from a unique set
+	guaranteedUnique = {
+		children: true,
+		contents: true,
+		next: true,
+		prev: true
+	};
+
+jQuery.extend({
+	dir: function( elem, dir, until ) {
+		var matched = [],
+			cur = elem[ dir ];
+
+		while ( cur && cur.nodeType !== 9 && (until === undefined || cur.nodeType !== 1 || !jQuery( cur ).is( until )) ) {
+			if ( cur.nodeType === 1 ) {
+				matched.push( cur );
+			}
+			cur = cur[dir];
+		}
+		return matched;
+	},
+
+	sibling: function( n, elem ) {
+		var r = [];
+
+		for ( ; n; n = n.nextSibling ) {
+			if ( n.nodeType === 1 && n !== elem ) {
+				r.push( n );
+			}
+		}
+
+		return r;
+	}
+});
+
+jQuery.fn.extend({
+	has: function( target ) {
+		var i,
+			targets = jQuery( target, this ),
+			len = targets.length;
+
+		return this.filter(function() {
+			for ( i = 0; i < len; i++ ) {
+				if ( jQuery.contains( this, targets[i] ) ) {
+					return true;
+				}
+			}
+		});
+	},
+
+	closest: function( selectors, context ) {
+		var cur,
+			i = 0,
+			l = this.length,
+			matched = [],
+			pos = rneedsContext.test( selectors ) || typeof selectors !== "string" ?
+				jQuery( selectors, context || this.context ) :
+				0;
+
+		for ( ; i < l; i++ ) {
+			for ( cur = this[i]; cur && cur !== context; cur = cur.parentNode ) {
+				// Always skip document fragments
+				if ( cur.nodeType < 11 && (pos ?
+					pos.index(cur) > -1 :
+
+					// Don't pass non-elements to Sizzle
+					cur.nodeType === 1 &&
+						jQuery.find.matchesSelector(cur, selectors)) ) {
+
+					matched.push( cur );
+					break;
+				}
+			}
+		}
+
+		return this.pushStack( matched.length > 1 ? jQuery.unique( matched ) : matched );
+	},
+
+	// Determine the position of an element within
+	// the matched set of elements
+	index: function( elem ) {
+
+		// No argument, return index in parent
+		if ( !elem ) {
+			return ( this[0] && this[0].parentNode ) ? this.first().prevAll().length : -1;
+		}
+
+		// index in selector
+		if ( typeof elem === "string" ) {
+			return jQuery.inArray( this[0], jQuery( elem ) );
+		}
+
+		// Locate the position of the desired element
+		return jQuery.inArray(
+			// If it receives a jQuery object, the first element is used
+			elem.jquery ? elem[0] : elem, this );
+	},
+
+	add: function( selector, context ) {
+		return this.pushStack(
+			jQuery.unique(
+				jQuery.merge( this.get(), jQuery( selector, context ) )
+			)
+		);
+	},
+
+	addBack: function( selector ) {
+		return this.add( selector == null ?
+			this.prevObject : this.prevObject.filter(selector)
+		);
+	}
+});
+
+function sibling( cur, dir ) {
+	do {
+		cur = cur[ dir ];
+	} while ( cur && cur.nodeType !== 1 );
+
+	return cur;
+}
+
+jQuery.each({
+	parent: function( elem ) {
+		var parent = elem.parentNode;
+		return parent && parent.nodeType !== 11 ? parent : null;
+	},
+	parents: function( elem ) {
+		return jQuery.dir( elem, "parentNode" );
+	},
+	parentsUntil: function( elem, i, until ) {
+		return jQuery.dir( elem, "parentNode", until );
+	},
+	next: function( elem ) {
+		return sibling( elem, "nextSibling" );
+	},
+	prev: function( elem ) {
+		return sibling( elem, "previousSibling" );
+	},
+	nextAll: function( elem ) {
+		return jQuery.dir( elem, "nextSibling" );
+	},
+	prevAll: function( elem ) {
+		return jQuery.dir( elem, "previousSibling" );
+	},
+	nextUntil: function( elem, i, until ) {
+		return jQuery.dir( elem, "nextSibling", until );
+	},
+	prevUntil: function( elem, i, until ) {
+		return jQuery.dir( elem, "previousSibling", until );
+	},
+	siblings: function( elem ) {
+		return jQuery.sibling( ( elem.parentNode || {} ).firstChild, elem );
+	},
+	children: function( elem ) {
+		return jQuery.sibling( elem.firstChild );
+	},
+	contents: function( elem ) {
+		return jQuery.nodeName( elem, "iframe" ) ?
+			elem.contentDocument || elem.contentWindow.document :
+			jQuery.merge( [], elem.childNodes );
+	}
+}, function( name, fn ) {
+	jQuery.fn[ name ] = function( until, selector ) {
+		var ret = jQuery.map( this, fn, until );
+
+		if ( name.slice( -5 ) !== "Until" ) {
+			selector = until;
+		}
+
+		if ( selector && typeof selector === "string" ) {
+			ret = jQuery.filter( selector, ret );
+		}
+
+		if ( this.length > 1 ) {
+			// Remove duplicates
+			if ( !guaranteedUnique[ name ] ) {
+				ret = jQuery.unique( ret );
+			}
+
+			// Reverse order for parents* and prev-derivatives
+			if ( rparentsprev.test( name ) ) {
+				ret = ret.reverse();
+			}
+		}
+
+		return this.pushStack( ret );
+	};
+});
+var rnotwhite = (/\S+/g);
+
+
+
+// String to Object options format cache
+var optionsCache = {};
+
+// Convert String-formatted options into Object-formatted ones and store in cache
+function createOptions( options ) {
+	var object = optionsCache[ options ] = {};
+	jQuery.each( options.match( rnotwhite ) || [], function( _, flag ) {
+		object[ flag ] = true;
+	});
+	return object;
+}
+
+/*
+ * Create a callback list using the following parameters:
+ *
+ *	options: an optional list of space-separated options that will change how
+ *			the callback list behaves or a more traditional option object
+ *
+ * By default a callback list will act like an event callback list and can be
+ * "fired" multiple times.
+ *
+ * Possible options:
+ *
+ *	once:			will ensure the callback list can only be fired once (like a Deferred)
+ *
+ *	memory:			will keep track of previous values and will call any callback added
+ *					after the list has been fired right away with the latest "memorized"
+ *					values (like a Deferred)
+ *
+ *	unique:			will ensure a callback can only be added once (no duplicate in the list)
+ *
+ *	stopOnFalse:	interrupt callings when a callback returns false
+ *
+ */
+jQuery.Callbacks = function( options ) {
+
+	// Convert options from String-formatted to Object-formatted if needed
+	// (we check in cache first)
+	options = typeof options === "string" ?
+		( optionsCache[ options ] || createOptions( options ) ) :
+		jQuery.extend( {}, options );
+
+	var // Flag to know if list is currently firing
+		firing,
+		// Last fire value (for non-forgettable lists)
+		memory,
+		// Flag to know if list was already fired
+		fired,
+		// End of the loop when firing
+		firingLength,
+		// Index of currently firing callback (modified by remove if needed)
+		firingIndex,
+		// First callback to fire (used internally by add and fireWith)
+		firingStart,
+		// Actual callback list
+		list = [],
+		// Stack of fire calls for repeatable lists
+		stack = !options.once && [],
+		// Fire callbacks
+		fire = function( data ) {
+			memory = options.memory && data;
+			fired = true;
+			firingIndex = firingStart || 0;
+			firingStart = 0;
+			firingLength = list.length;
+			firing = true;
+			for ( ; list && firingIndex < firingLength; firingIndex++ ) {
+				if ( list[ firingIndex ].apply( data[ 0 ], data[ 1 ] ) === false && options.stopOnFalse ) {
+					memory = false; // To prevent further calls using add
+					break;
+				}
+			}
+			firing = false;
+			if ( list ) {
+				if ( stack ) {
+					if ( stack.length ) {
+						fire( stack.shift() );
+					}
+				} else if ( memory ) {
+					list = [];
+				} else {
+					self.disable();
+				}
+			}
+		},
+		// Actual Callbacks object
+		self = {
+			// Add a callback or a collection of callbacks to the list
+			add: function() {
+				if ( list ) {
+					// First, we save the current length
+					var start = list.length;
+					(function add( args ) {
+						jQuery.each( args, function( _, arg ) {
+							var type = jQuery.type( arg );
+							if ( type === "function" ) {
+								if ( !options.unique || !self.has( arg ) ) {
+									list.push( arg );
+								}
+							} else if ( arg && arg.length && type !== "string" ) {
+								// Inspect recursively
+								add( arg );
+							}
+						});
+					})( arguments );
+					// Do we need to add the callbacks to the
+					// current firing batch?
+					if ( firing ) {
+						firingLength = list.length;
+					// With memory, if we're not firing then
+					// we should call right away
+					} else if ( memory ) {
+						firingStart = start;
+						fire( memory );
+					}
+				}
+				return this;
+			},
+			// Remove a callback from the list
+			remove: function() {
+				if ( list ) {
+					jQuery.each( arguments, function( _, arg ) {
+						var index;
+						while ( ( index = jQuery.inArray( arg, list, index ) ) > -1 ) {
+							list.splice( index, 1 );
+							// Handle firing indexes
+							if ( firing ) {
+								if ( index <= firingLength ) {
+									firingLength--;
+								}
+								if ( index <= firingIndex ) {
+									firingIndex--;
+								}
+							}
+						}
+					});
+				}
+				return this;
+			},
+			// Check if a given callback is in the list.
+			// If no argument is given, return whether or not list has callbacks attached.
+			has: function( fn ) {
+				return fn ? jQuery.inArray( fn, list ) > -1 : !!( list && list.length );
+			},
+			// Remove all callbacks from the list
+			empty: function() {
+				list = [];
+				firingLength = 0;
+				return this;
+			},
+			// Have the list do nothing anymore
+			disable: function() {
+				list = stack = memory = undefined;
+				return this;
+			},
+			// Is it disabled?
+			disabled: function() {
+				return !list;
+			},
+			// Lock the list in its current state
+			lock: function() {
+				stack = undefined;
+				if ( !memory ) {
+					self.disable();
+				}
+				return this;
+			},
+			// Is it locked?
+			locked: function() {
+				return !stack;
+			},
+			// Call all callbacks with the given context and arguments
+			fireWith: function( context, args ) {
+				if ( list && ( !fired || stack ) ) {
+					args = args || [];
+					args = [ context, args.slice ? args.slice() : args ];
+					if ( firing ) {
+						stack.push( args );
+					} else {
+						fire( args );
+					}
+				}
+				return this;
+			},
+			// Call all the callbacks with the given arguments
+			fire: function() {
+				self.fireWith( this, arguments );
+				return this;
+			},
+			// To know if the callbacks have already been called at least once
+			fired: function() {
+				return !!fired;
+			}
+		};
+
+	return self;
+};
+
+
+jQuery.extend({
+
+	Deferred: function( func ) {
+		var tuples = [
+				// action, add listener, listener list, final state
+				[ "resolve", "done", jQuery.Callbacks("once memory"), "resolved" ],
+				[ "reject", "fail", jQuery.Callbacks("once memory"), "rejected" ],
+				[ "notify", "progress", jQuery.Callbacks("memory") ]
+			],
+			state = "pending",
+			promise = {
+				state: function() {
+					return state;
+				},
+				always: function() {
+					deferred.done( arguments ).fail( arguments );
+					return this;
+				},
+				then: function( /* fnDone, fnFail, fnProgress */ ) {
+					var fns = arguments;
+					return jQuery.Deferred(function( newDefer ) {
+						jQuery.each( tuples, function( i, tuple ) {
+							var fn = jQuery.isFunction( fns[ i ] ) && fns[ i ];
+							// deferred[ done | fail | progress ] for forwarding actions to newDefer
+							deferred[ tuple[1] ](function() {
+								var returned = fn && fn.apply( this, arguments );
+								if ( returned && jQuery.isFunction( returned.promise ) ) {
+									returned.promise()
+										.done( newDefer.resolve )
+										.fail( newDefer.reject )
+										.progress( newDefer.notify );
+								} else {
+									newDefer[ tuple[ 0 ] + "With" ]( this === promise ? newDefer.promise() : this, fn ? [ returned ] : arguments );
+								}
+							});
+						});
+						fns = null;
+					}).promise();
+				},
+				// Get a promise for this deferred
+				// If obj is provided, the promise aspect is added to the object
+				promise: function( obj ) {
+					return obj != null ? jQuery.extend( obj, promise ) : promise;
+				}
+			},
+			deferred = {};
+
+		// Keep pipe for back-compat
+		promise.pipe = promise.then;
+
+		// Add list-specific methods
+		jQuery.each( tuples, function( i, tuple ) {
+			var list = tuple[ 2 ],
+				stateString = tuple[ 3 ];
+
+			// promise[ done | fail | progress ] = list.add
+			promise[ tuple[1] ] = list.add;
+
+			// Handle state
+			if ( stateString ) {
+				list.add(function() {
+					// state = [ resolved | rejected ]
+					state = stateString;
+
+				// [ reject_list | resolve_list ].disable; progress_list.lock
+				}, tuples[ i ^ 1 ][ 2 ].disable, tuples[ 2 ][ 2 ].lock );
+			}
+
+			// deferred[ resolve | reject | notify ]
+			deferred[ tuple[0] ] = function() {
+				deferred[ tuple[0] + "With" ]( this === deferred ? promise : this, arguments );
+				return this;
+			};
+			deferred[ tuple[0] + "With" ] = list.fireWith;
+		});
+
+		// Make the deferred a promise
+		promise.promise( deferred );
+
+		// Call given func if any
+		if ( func ) {
+			func.call( deferred, deferred );
+		}
+
+		// All done!
+		return deferred;
+	},
+
+	// Deferred helper
+	when: function( subordinate /* , ..., subordinateN */ ) {
+		var i = 0,
+			resolveValues = slice.call( arguments ),
+			length = resolveValues.length,
+
+			// the count of uncompleted subordinates
+			remaining = length !== 1 || ( subordinate && jQuery.isFunction( subordinate.promise ) ) ? length : 0,
+
+			// the master Deferred. If resolveValues consist of only a single Deferred, just use that.
+			deferred = remaining === 1 ? subordinate : jQuery.Deferred(),
+
+			// Update function for both resolve and progress values
+			updateFunc = function( i, contexts, values ) {
+				return function( value ) {
+					contexts[ i ] = this;
+					values[ i ] = arguments.length > 1 ? slice.call( arguments ) : value;
+					if ( values === progressValues ) {
+						deferred.notifyWith( contexts, values );
+
+					} else if ( !(--remaining) ) {
+						deferred.resolveWith( contexts, values );
+					}
+				};
+			},
+
+			progressValues, progressContexts, resolveContexts;
+
+		// add listeners to Deferred subordinates; treat others as resolved
+		if ( length > 1 ) {
+			progressValues = new Array( length );
+			progressContexts = new Array( length );
+			resolveContexts = new Array( length );
+			for ( ; i < length; i++ ) {
+				if ( resolveValues[ i ] && jQuery.isFunction( resolveValues[ i ].promise ) ) {
+					resolveValues[ i ].promise()
+						.done( updateFunc( i, resolveContexts, resolveValues ) )
+						.fail( deferred.reject )
+						.progress( updateFunc( i, progressContexts, progressValues ) );
+				} else {
+					--remaining;
+				}
+			}
+		}
+
+		// if we're not waiting on anything, resolve the master
+		if ( !remaining ) {
+			deferred.resolveWith( resolveContexts, resolveValues );
+		}
+
+		return deferred.promise();
+	}
+});
+
+
+// The deferred used on DOM ready
+var readyList;
+
+jQuery.fn.ready = function( fn ) {
+	// Add the callback
+	jQuery.ready.promise().done( fn );
+
+	return this;
+};
+
+jQuery.extend({
+	// Is the DOM ready to be used? Set to true once it occurs.
+	isReady: false,
+
+	// A counter to track how many items to wait for before
+	// the ready event fires. See #6781
+	readyWait: 1,
+
+	// Hold (or release) the ready event
+	holdReady: function( hold ) {
+		if ( hold ) {
+			jQuery.readyWait++;
+		} else {
+			jQuery.ready( true );
+		}
+	},
+
+	// Handle when the DOM is ready
+	ready: function( wait ) {
+
+		// Abort if there are pending holds or we're already ready
+		if ( wait === true ? --jQuery.readyWait : jQuery.isReady ) {
+			return;
+		}
+
+		// Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
+		if ( !document.body ) {
+			return setTimeout( jQuery.ready );
+		}
+
+		// Remember that the DOM is ready
+		jQuery.isReady = true;
+
+		// If a normal DOM Ready event fired, decrement, and wait if need be
+		if ( wait !== true && --jQuery.readyWait > 0 ) {
+			return;
+		}
+
+		// If there are functions bound, to execute
+		readyList.resolveWith( document, [ jQuery ] );
+
+		// Trigger any bound ready events
+		if ( jQuery.fn.triggerHandler ) {
+			jQuery( document ).triggerHandler( "ready" );
+			jQuery( document ).off( "ready" );
+		}
+	}
+});
+
+/**
+ * Clean-up method for dom ready events
+ */
+function detach() {
+	if ( document.addEventListener ) {
+		document.removeEventListener( "DOMContentLoaded", completed, false );
+		window.removeEventListener( "load", completed, false );
+
+	} else {
+		document.detachEvent( "onreadystatechange", completed );
+		window.detachEvent( "onload", completed );
+	}
+}
+
+/**
+ * The ready event handler and self cleanup method
+ */
+function completed() {
+	// readyState === "complete" is good enough for us to call the dom ready in oldIE
+	if ( document.addEventListener || event.type === "load" || document.readyState === "complete" ) {
+		detach();
+		jQuery.ready();
+	}
+}
+
+jQuery.ready.promise = function( obj ) {
+	if ( !readyList ) {
+
+		readyList = jQuery.Deferred();
+
+		// Catch cases where $(document).ready() is called after the browser event has already occurred.
+		// we once tried to use readyState "interactive" here, but it caused issues like the one
+		// discovered by ChrisS here: http://bugs.jquery.com/ticket/12282#comment:15
+		if ( document.readyState === "complete" ) {
+			// Handle it asynchronously to allow scripts the opportunity to delay ready
+			setTimeout( jQuery.ready );
+
+		// Standards-based browsers support DOMContentLoaded
+		} else if ( document.addEventListener ) {
+			// Use the handy event callback
+			document.addEventListener( "DOMContentLoaded", completed, false );
+
+			// A fallback to window.onload, that will always work
+			window.addEventListener( "load", completed, false );
+
+		// If IE event model is used
+		} else {
+			// Ensure firing before onload, maybe late but safe also for iframes
+			document.attachEvent( "onreadystatechange", completed );
+
+			// A fallback to window.onload, that will always work
+			window.attachEvent( "onload", completed );
+
+			// If IE and not a frame
+			// continually check to see if the document is ready
+			var top = false;
+
+			try {
+				top = window.frameElement == null && document.documentElement;
+			} catch(e) {}
+
+			if ( top && top.doScroll ) {
+				(function doScrollCheck() {
+					if ( !jQuery.isReady ) {
+
+						try {
+							// Use the trick by Diego Perini
+							// http://javascript.nwbox.com/IEContentLoaded/
+							top.doScroll("left");
+						} catch(e) {
+							return setTimeout( doScrollCheck, 50 );
+						}
+
+						// detach all dom ready events
+						detach();
+
+						// and execute any waiting functions
+						jQuery.ready();
+					}
+				})();
+			}
+		}
+	}
+	return readyList.promise( obj );
+};
+
+
+var strundefined = typeof undefined;
+
+
+
+// Support: IE<9
+// Iteration over object's inherited properties before its own
+var i;
+for ( i in jQuery( support ) ) {
+	break;
+}
+support.ownLast = i !== "0";
+
+// Note: most support tests are defined in their respective modules.
+// false until the test is run
+support.inlineBlockNeedsLayout = false;
+
+// Execute ASAP in case we need to set body.style.zoom
+jQuery(function() {
+	// Minified: var a,b,c,d
+	var val, div, body, container;
+
+	body = document.getElementsByTagName( "body" )[ 0 ];
+	if ( !body || !body.style ) {
+		// Return for frameset docs that don't have a body
+		return;
+	}
+
+	// Setup
+	div = document.createElement( "div" );
+	container = document.createElement( "div" );
+	container.style.cssText = "position:absolute;border:0;width:0;height:0;top:0;left:-9999px";
+	body.appendChild( container ).appendChild( div );
+
+	if ( typeof div.style.zoom !== strundefined ) {
+		// Support: IE<8
+		// Check if natively block-level elements act like inline-block
+		// elements when setting their display to 'inline' and giving
+		// them layout
+		div.style.cssText = "display:inline;margin:0;border:0;padding:1px;width:1px;zoom:1";
+
+		support.inlineBlockNeedsLayout = val = div.offsetWidth === 3;
+		if ( val ) {
+			// Prevent IE 6 from affecting layout for positioned elements #11048
+			// Prevent IE from shrinking the body in IE 7 mode #12869
+			// Support: IE<8
+			body.style.zoom = 1;
+		}
+	}
+
+	body.removeChild( container );
+});
+
+
+
+
+(function() {
+	var div = document.createElement( "div" );
+
+	// Execute the test only if not already executed in another module.
+	if (support.deleteExpando == null) {
+		// Support: IE<9
+		support.deleteExpando = true;
+		try {
+			delete div.test;
+		} catch( e ) {
+			support.deleteExpando = false;
+		}
+	}
+
+	// Null elements to avoid leaks in IE.
+	div = null;
+})();
+
+
+/**
+ * Determines whether an object can have data
+ */
+jQuery.acceptData = function( elem ) {
+	var noData = jQuery.noData[ (elem.nodeName + " ").toLowerCase() ],
+		nodeType = +elem.nodeType || 1;
+
+	// Do not set data on non-element DOM nodes because it will not be cleared (#8335).
+	return nodeType !== 1 && nodeType !== 9 ?
+		false :
+
+		// Nodes accept data unless otherwise specified; rejection can be conditional
+		!noData || noData !== true && elem.getAttribute("classid") === noData;
+};
+
+
+var rbrace = /^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,
+	rmultiDash = /([A-Z])/g;
+
+function dataAttr( elem, key, data ) {
+	// If nothing was found internally, try to fetch any
+	// data from the HTML5 data-* attribute
+	if ( data === undefined && elem.nodeType === 1 ) {
+
+		var name = "data-" + key.replace( rmultiDash, "-$1" ).toLowerCase();
+
+		data = elem.getAttribute( name );
+
+		if ( typeof data === "string" ) {
+			try {
+				data = data === "true" ? true :
+					data === "false" ? false :
+					data === "null" ? null :
+					// Only convert to a number if it doesn't change the string
+					+data + "" === data ? +data :
+					rbrace.test( data ) ? jQuery.parseJSON( data ) :
+					data;
+			} catch( e ) {}
+
+			// Make sure we set the data so it isn't changed later
+			jQuery.data( elem, key, data );
+
+		} else {
+			data = undefined;
+		}
+	}
+
+	return data;
+}
+
+// checks a cache object for emptiness
+function isEmptyDataObject( obj ) {
+	var name;
+	for ( name in obj ) {
+
+		// if the public data object is empty, the private is still empty
+		if ( name === "data" && jQuery.isEmptyObject( obj[name] ) ) {
+			continue;
+		}
+		if ( name !== "toJSON" ) {
+			return false;
+		}
+	}
+
+	return true;
+}
+
+function internalData( elem, name, data, pvt /* Internal Use Only */ ) {
+	if ( !jQuery.acceptData( elem ) ) {
+		return;
+	}
+
+	var ret, thisCache,
+		internalKey = jQuery.expando,
+
+		// We have to handle DOM nodes and JS objects differently because IE6-7
+		// can't GC object references properly across the DOM-JS boundary
+		isNode = elem.nodeType,
+
+		// Only DOM nodes need the global jQuery cache; JS object data is
+		// attached directly to the object so GC can occur automatically
+		cache = isNode ? jQuery.cache : elem,
+
+		// Only defining an ID for JS objects if its cache already exists allows
+		// the code to shortcut on the same path as a DOM node with no cache
+		id = isNode ? elem[ internalKey ] : elem[ internalKey ] && internalKey;
+
+	// Avoid doing any more work than we need to when trying to get data on an
+	// object that has no data at all
+	if ( (!id || !cache[id] || (!pvt && !cache[id].data)) && data === undefined && typeof name === "string" ) {
+		return;
+	}
+
+	if ( !id ) {
+		// Only DOM nodes need a new unique ID for each element since their data
+		// ends up in the global cache
+		if ( isNode ) {
+			id = elem[ internalKey ] = deletedIds.pop() || jQuery.guid++;
+		} else {
+			id = internalKey;
+		}
+	}
+
+	if ( !cache[ id ] ) {
+		// Avoid exposing jQuery metadata on plain JS objects when the object
+		// is serialized using JSON.stringify
+		cache[ id ] = isNode ? {} : { toJSON: jQuery.noop };
+	}
+
+	// An object can be passed to jQuery.data instead of a key/value pair; this gets
+	// shallow copied over onto the existing cache
+	if ( typeof name === "object" || typeof name === "function" ) {
+		if ( pvt ) {
+			cache[ id ] = jQuery.extend( cache[ id ], name );
+		} else {
+			cache[ id ].data = jQuery.extend( cache[ id ].data, name );
+		}
+	}
+
+	thisCache = cache[ id ];
+
+	// jQuery data() is stored in a separate object inside the object's internal data
+	// cache in order to avoid key collisions between internal data and user-defined
+	// data.
+	if ( !pvt ) {
+		if ( !thisCache.data ) {
+			thisCache.data = {};
+		}
+
+		thisCache = thisCache.data;
+	}
+
+	if ( data !== undefined ) {
+		thisCache[ jQuery.camelCase( name ) ] = data;
+	}
+
+	// Check for both converted-to-camel and non-converted data property names
+	// If a data property was specified
+	if ( typeof name === "string" ) {
+
+		// First Try to find as-is property data
+		ret = thisCache[ name ];
+
+		// Test for null|undefined property data
+		if ( ret == null ) {
+
+			// Try to find the camelCased property
+			ret = thisCache[ jQuery.camelCase( name ) ];
+		}
+	} else {
+		ret = thisCache;
+	}
+
+	return ret;
+}
+
+function internalRemoveData( elem, name, pvt ) {
+	if ( !jQuery.acceptData( elem ) ) {
+		return;
+	}
+
+	var thisCache, i,
+		isNode = elem.nodeType,
+
+		// See jQuery.data for more information
+		cache = isNode ? jQuery.cache : elem,
+		id = isNode ? elem[ jQuery.expando ] : jQuery.expando;
+
+	// If there is already no cache entry for this object, there is no
+	// purpose in continuing
+	if ( !cache[ id ] ) {
+		return;
+	}
+
+	if ( name ) {
+
+		thisCache = pvt ? cache[ id ] : cache[ id ].data;
+
+		if ( thisCache ) {
+
+			// Support array or space separated string names for data keys
+			if ( !jQuery.isArray( name ) ) {
+
+				// try the string as a key before any manipulation
+				if ( name in thisCache ) {
+					name = [ name ];
+				} else {
+
+					// split the camel cased version by spaces unless a key with the spaces exists
+					name = jQuery.camelCase( name );
+					if ( name in thisCache ) {
+						name = [ name ];
+					} else {
+						name = name.split(" ");
+					}
+				}
+			} else {
+				// If "name" is an array of keys...
+				// When data is initially created, via ("key", "val") signature,
+				// keys will be converted to camelCase.
+				// Since there is no way to tell _how_ a key was added, remove
+				// both plain key and camelCase key. #12786
+				// This will only penalize the array argument path.
+				name = name.concat( jQuery.map( name, jQuery.camelCase ) );
+			}
+
+			i = name.length;
+			while ( i-- ) {
+				delete thisCache[ name[i] ];
+			}
+
+			// If there is no data left in the cache, we want to continue
+			// and let the cache object itself get destroyed
+			if ( pvt ? !isEmptyDataObject(thisCache) : !jQuery.isEmptyObject(thisCache) ) {
+				return;
+			}
+		}
+	}
+
+	// See jQuery.data for more information
+	if ( !pvt ) {
+		delete cache[ id ].data;
+
+		// Don't destroy the parent cache unless the internal data object
+		// had been the only thing left in it
+		if ( !isEmptyDataObject( cache[ id ] ) ) {
+			return;
+		}
+	}
+
+	// Destroy the cache
+	if ( isNode ) {
+		jQuery.cleanData( [ elem ], true );
+
+	// Use delete when supported for expandos or `cache` is not a window per isWindow (#10080)
+	/* jshint eqeqeq: false */
+	} else if ( support.deleteExpando || cache != cache.window ) {
+		/* jshint eqeqeq: true */
+		delete cache[ id ];
+
+	// When all else fails, null
+	} else {
+		cache[ id ] = null;
+	}
+}
+
+jQuery.extend({
+	cache: {},
+
+	// The following elements (space-suffixed to avoid Object.prototype collisions)
+	// throw uncatchable exceptions if you attempt to set expando properties
+	noData: {
+		"applet ": true,
+		"embed ": true,
+		// ...but Flash objects (which have this classid) *can* handle expandos
+		"object ": "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
+	},
+
+	hasData: function( elem ) {
+		elem = elem.nodeType ? jQuery.cache[ elem[jQuery.expando] ] : elem[ jQuery.expando ];
+		return !!elem && !isEmptyDataObject( elem );
+	},
+
+	data: function( elem, name, data ) {
+		return internalData( elem, name, data );
+	},
+
+	removeData: function( elem, name ) {
+		return internalRemoveData( elem, name );
+	},
+
+	// For internal use only.
+	_data: function( elem, name, data ) {
+		return internalData( elem, name, data, true );
+	},
+
+	_removeData: function( elem, name ) {
+		return internalRemoveData( elem, name, true );
+	}
+});
+
+jQuery.fn.extend({
+	data: function( key, value ) {
+		var i, name, data,
+			elem = this[0],
+			attrs = elem && elem.attributes;
+
+		// Special expections of .data basically thwart jQuery.access,
+		// so implement the relevant behavior ourselves
+
+		// Gets all values
+		if ( key === undefined ) {
+			if ( this.length ) {
+				data = jQuery.data( elem );
+
+				if ( elem.nodeType === 1 && !jQuery._data( elem, "parsedAttrs" ) ) {
+					i = attrs.length;
+					while ( i-- ) {
+
+						// Support: IE11+
+						// The attrs elements can be null (#14894)
+						if ( attrs[ i ] ) {
+							name = attrs[ i ].name;
+							if ( name.indexOf( "data-" ) === 0 ) {
+								name = jQuery.camelCase( name.slice(5) );
+								dataAttr( elem, name, data[ name ] );
+							}
+						}
+					}
+					jQuery._data( elem, "parsedAttrs", true );
+				}
+			}
+
+			return data;
+		}
+
+		// Sets multiple values
+		if ( typeof key === "object" ) {
+			return this.each(function() {
+				jQuery.data( this, key );
+			});
+		}
+
+		return arguments.length > 1 ?
+
+			// Sets one value
+			this.each(function() {
+				jQuery.data( this, key, value );
+			}) :
+
+			// Gets one value
+			// Try to fetch any internally stored data first
+			elem ? dataAttr( elem, key, jQuery.data( elem, key ) ) : undefined;
+	},
+
+	removeData: function( key ) {
+		return this.each(function() {
+			jQuery.removeData( this, key );
+		});
+	}
+});
+
+
+jQuery.extend({
+	queue: function( elem, type, data ) {
+		var queue;
+
+		if ( elem ) {
+			type = ( type || "fx" ) + "queue";
+			queue = jQuery._data( elem, type );
+
+			// Speed up dequeue by getting out quickly if this is just a lookup
+			if ( data ) {
+				if ( !queue || jQuery.isArray(data) ) {
+					queue = jQuery._data( elem, type, jQuery.makeArray(data) );
+				} else {
+					queue.push( data );
+				}
+			}
+			return queue || [];
+		}
+	},
+
+	dequeue: function( elem, type ) {
+		type = type || "fx";
+
+		var queue = jQuery.queue( elem, type ),
+			startLength = queue.length,
+			fn = queue.shift(),
+			hooks = jQuery._queueHooks( elem, type ),
+			next = function() {
+				jQuery.dequeue( elem, type );
+			};
+
+		// If the fx queue is dequeued, always remove the progress sentinel
+		if ( fn === "inprogress" ) {
+			fn = queue.shift();
+			startLength--;
+		}
+
+		if ( fn ) {
+
+			// Add a progress sentinel to prevent the fx queue from being
+			// automatically dequeued
+			if ( type === "fx" ) {
+				queue.unshift( "inprogress" );
+			}
+
+			// clear up the last queue stop function
+			delete hooks.stop;
+			fn.call( elem, next, hooks );
+		}
+
+		if ( !startLength && hooks ) {
+			hooks.empty.fire();
+		}
+	},
+
+	// not intended for public consumption - generates a queueHooks object, or returns the current one
+	_queueHooks: function( elem, type ) {
+		var key = type + "queueHooks";
+		return jQuery._data( elem, key ) || jQuery._data( elem, key, {
+			empty: jQuery.Callbacks("once memory").add(function() {
+				jQuery._removeData( elem, type + "queue" );
+				jQuery._removeData( elem, key );
+			})
+		});
+	}
+});
+
+jQuery.fn.extend({
+	queue: function( type, data ) {
+		var setter = 2;
+
+		if ( typeof type !== "string" ) {
+			data = type;
+			type = "fx";
+			setter--;
+		}
+
+		if ( arguments.length < setter ) {
+			return jQuery.queue( this[0], type );
+		}
+
+		return data === undefined ?
+			this :
+			this.each(function() {
+				var queue = jQuery.queue( this, type, data );
+
+				// ensure a hooks for this queue
+				jQuery._queueHooks( this, type );
+
+				if ( type === "fx" && queue[0] !== "inprogress" ) {
+					jQuery.dequeue( this, type );
+				}
+			});
+	},
+	dequeue: function( type ) {
+		return this.each(function() {
+			jQuery.dequeue( this, type );
+		});
+	},
+	clearQueue: function( type ) {
+		return this.queue( type || "fx", [] );
+	},
+	// Get a promise resolved when queues of a certain type
+	// are emptied (fx is the type by default)
+	promise: function( type, obj ) {
+		var tmp,
+			count = 1,
+			defer = jQuery.Deferred(),
+			elements = this,
+			i = this.length,
+			resolve = function() {
+				if ( !( --count ) ) {
+					defer.resolveWith( elements, [ elements ] );
+				}
+			};
+
+		if ( typeof type !== "string" ) {
+			obj = type;
+			type = undefined;
+		}
+		type = type || "fx";
+
+		while ( i-- ) {
+			tmp = jQuery._data( elements[ i ], type + "queueHooks" );
+			if ( tmp && tmp.empty ) {
+				count++;
+				tmp.empty.add( resolve );
+			}
+		}
+		resolve();
+		return defer.promise( obj );
+	}
+});
+var pnum = (/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/).source;
+
+var cssExpand = [ "Top", "Right", "Bottom", "Left" ];
+
+var isHidden = function( elem, el ) {
+		// isHidden might be called from jQuery#filter function;
+		// in that case, element will be second argument
+		elem = el || elem;
+		return jQuery.css( elem, "display" ) === "none" || !jQuery.contains( elem.ownerDocument, elem );
+	};
+
+
+
+// Multifunctional method to get and set values of a collection
+// The value/s can optionally be executed if it's a function
+var access = jQuery.access = function( elems, fn, key, value, chainable, emptyGet, raw ) {
+	var i = 0,
+		length = elems.length,
+		bulk = key == null;
+
+	// Sets many values
+	if ( jQuery.type( key ) === "object" ) {
+		chainable = true;
+		for ( i in key ) {
+			jQuery.access( elems, fn, i, key[i], true, emptyGet, raw );
+		}
+
+	// Sets one value
+	} else if ( value !== undefined ) {
+		chainable = true;
+
+		if ( !jQuery.isFunction( value ) ) {
+			raw = true;
+		}
+
+		if ( bulk ) {
+			// Bulk operations run against the entire set
+			if ( raw ) {
+				fn.call( elems, value );
+				fn = null;
+
+			// ...except when executing function values
+			} else {
+				bulk = fn;
+				fn = function( elem, key, value ) {
+					return bulk.call( jQuery( elem ), value );
+				};
+			}
+		}
+
+		if ( fn ) {
+			for ( ; i < length; i++ ) {
+				fn( elems[i], key, raw ? value : value.call( elems[i], i, fn( elems[i], key ) ) );
+			}
+		}
+	}
+
+	return chainable ?
+		elems :
+
+		// Gets
+		bulk ?
+			fn.call( elems ) :
+			length ? fn( elems[0], key ) : emptyGet;
+};
+var rcheckableType = (/^(?:checkbox|radio)$/i);
+
+
+
+(function() {
+	// Minified: var a,b,c
+	var input = document.createElement( "input" ),
+		div = document.createElement( "div" ),
+		fragment = document.createDocumentFragment();
+
+	// Setup
+	div.innerHTML = "  <link/><table></table><a href='/a'>a</a><input type='checkbox'/>";
+
+	// IE strips leading whitespace when .innerHTML is used
+	support.leadingWhitespace = div.firstChild.nodeType === 3;
+
+	// Make sure that tbody elements aren't automatically inserted
+	// IE will insert them into empty tables
+	support.tbody = !div.getElementsByTagName( "tbody" ).length;
+
+	// Make sure that link elements get serialized correctly by innerHTML
+	// This requires a wrapper element in IE
+	support.htmlSerialize = !!div.getElementsByTagName( "link" ).length;
+
+	// Makes sure cloning an html5 element does not cause problems
+	// Where outerHTML is undefined, this still works
+	support.html5Clone =
+		document.createElement( "nav" ).cloneNode( true ).outerHTML !== "<:nav></:nav>";
+
+	// Check if a disconnected checkbox will retain its checked
+	// value of true after appended to the DOM (IE6/7)
+	input.type = "checkbox";
+	input.checked = true;
+	fragment.appendChild( input );
+	support.appendChecked = input.checked;
+
+	// Make sure textarea (and checkbox) defaultValue is properly cloned
+	// Support: IE6-IE11+
+	div.innerHTML = "<textarea>x</textarea>";
+	support.noCloneChecked = !!div.cloneNode( true ).lastChild.defaultValue;
+
+	// #11217 - WebKit loses check when the name is after the checked attribute
+	fragment.appendChild( div );
+	div.innerHTML = "<input type='radio' checked='checked' name='t'/>";
+
+	// Support: Safari 5.1, iOS 5.1, Android 4.x, Android 2.3
+	// old WebKit doesn't clone checked state correctly in fragments
+	support.checkClone = div.cloneNode( true ).cloneNode( true ).lastChild.checked;
+
+	// Support: IE<9
+	// Opera does not clone events (and typeof div.attachEvent === undefined).
+	// IE9-10 clones events bound via attachEvent, but they don't trigger with .click()
+	support.noCloneEvent = true;
+	if ( div.attachEvent ) {
+		div.attachEvent( "onclick", function() {
+			support.noCloneEvent = false;
+		});
+
+		div.cloneNode( true ).click();
+	}
+
+	// Execute the test only if not already executed in another module.
+	if (support.deleteExpando == null) {
+		// Support: IE<9
+		support.deleteExpando = true;
+		try {
+			delete div.test;
+		} catch( e ) {
+			support.deleteExpando = false;
+		}
+	}
+})();
+
+
+(function() {
+	var i, eventName,
+		div = document.createElement( "div" );
+
+	// Support: IE<9 (lack submit/change bubble), Firefox 23+ (lack focusin event)
+	for ( i in { submit: true, change: true, focusin: true }) {
+		eventName = "on" + i;
+
+		if ( !(support[ i + "Bubbles" ] = eventName in window) ) {
+			// Beware of CSP restrictions (https://developer.mozilla.org/en/Security/CSP)
+			div.setAttribute( eventName, "t" );
+			support[ i + "Bubbles" ] = div.attributes[ eventName ].expando === false;
+		}
+	}
+
+	// Null elements to avoid leaks in IE.
+	div = null;
+})();
+
+
+var rformElems = /^(?:input|select|textarea)$/i,
+	rkeyEvent = /^key/,
+	rmouseEvent = /^(?:mouse|pointer|contextmenu)|click/,
+	rfocusMorph = /^(?:focusinfocus|focusoutblur)$/,
+	rtypenamespace = /^([^.]*)(?:\.(.+)|)$/;
+
+function returnTrue() {
+	return true;
+}
+
+function returnFalse() {
+	return false;
+}
+
+function safeActiveElement() {
+	try {
+		return document.activeElement;
+	} catch ( err ) { }
+}
+
+/*
+ * Helper functions for managing events -- not part of the public interface.
+ * Props to Dean Edwards' addEvent library for many of the ideas.
+ */
+jQuery.event = {
+
+	global: {},
+
+	add: function( elem, types, handler, data, selector ) {
+		var tmp, events, t, handleObjIn,
+			special, eventHandle, handleObj,
+			handlers, type, namespaces, origType,
+			elemData = jQuery._data( elem );
+
+		// Don't attach events to noData or text/comment nodes (but allow plain objects)
+		if ( !elemData ) {
+			return;
+		}
+
+		// Caller can pass in an object of custom data in lieu of the handler
+		if ( handler.handler ) {
+			handleObjIn = handler;
+			handler = handleObjIn.handler;
+			selector = handleObjIn.selector;
+		}
+
+		// Make sure that the handler has a unique ID, used to find/remove it later
+		if ( !handler.guid ) {
+			handler.guid = jQuery.guid++;
+		}
+
+		// Init the element's event structure and main handler, if this is the first
+		if ( !(events = elemData.events) ) {
+			events = elemData.events = {};
+		}
+		if ( !(eventHandle = elemData.handle) ) {
+			eventHandle = elemData.handle = function( e ) {
+				// Discard the second event of a jQuery.event.trigger() and
+				// when an event is called after a page has unloaded
+				return typeof jQuery !== strundefined && (!e || jQuery.event.triggered !== e.type) ?
+					jQuery.event.dispatch.apply( eventHandle.elem, arguments ) :
+					undefined;
+			};
+			// Add elem as a property of the handle fn to prevent a memory leak with IE non-native events
+			eventHandle.elem = elem;
+		}
+
+		// Handle multiple events separated by a space
+		types = ( types || "" ).match( rnotwhite ) || [ "" ];
+		t = types.length;
+		while ( t-- ) {
+			tmp = rtypenamespace.exec( types[t] ) || [];
+			type = origType = tmp[1];
+			namespaces = ( tmp[2] || "" ).split( "." ).sort();
+
+			// There *must* be a type, no attaching namespace-only handlers
+			if ( !type ) {
+				continue;
+			}
+
+			// If event changes its type, use the special event handlers for the changed type
+			special = jQuery.event.special[ type ] || {};
+
+			// If selector defined, determine special event api type, otherwise given type
+			type = ( selector ? special.delegateType : special.bindType ) || type;
+
+			// Update special based on newly reset type
+			special = jQuery.event.special[ type ] || {};
+
+			// handleObj is passed to all event handlers
+			handleObj = jQuery.extend({
+				type: type,
+				origType: origType,
+				data: data,
+				handler: handler,
+				guid: handler.guid,
+				selector: selector,
+				needsContext: selector && jQuery.expr.match.needsContext.test( selector ),
+				namespace: namespaces.join(".")
+			}, handleObjIn );
+
+			// Init the event handler queue if we're the first
+			if ( !(handlers = events[ type ]) ) {
+				handlers = events[ type ] = [];
+				handlers.delegateCount = 0;
+
+				// Only use addEventListener/attachEvent if the special events handler returns false
+				if ( !special.setup || special.setup.call( elem, data, namespaces, eventHandle ) === false ) {
+					// Bind the global event handler to the element
+					if ( elem.addEventListener ) {
+						elem.addEventListener( type, eventHandle, false );
+
+					} else if ( elem.attachEvent ) {
+						elem.attachEvent( "on" + type, eventHandle );
+					}
+				}
+			}
+
+			if ( special.add ) {
+				special.add.call( elem, handleObj );
+
+				if ( !handleObj.handler.guid ) {
+					handleObj.handler.guid = handler.guid;
+				}
+			}
+
+			// Add to the element's handler list, delegates in front
+			if ( selector ) {
+				handlers.splice( handlers.delegateCount++, 0, handleObj );
+			} else {
+				handlers.push( handleObj );
+			}
+
+			// Keep track of which events have ever been used, for event optimization
+			jQuery.event.global[ type ] = true;
+		}
+
+		// Nullify elem to prevent memory leaks in IE
+		elem = null;
+	},
+
+	// Detach an event or set of events from an element
+	remove: function( elem, types, handler, selector, mappedTypes ) {
+		var j, handleObj, tmp,
+			origCount, t, events,
+			special, handlers, type,
+			namespaces, origType,
+			elemData = jQuery.hasData( elem ) && jQuery._data( elem );
+
+		if ( !elemData || !(events = elemData.events) ) {
+			return;
+		}
+
+		// Once for each type.namespace in types; type may be omitted
+		types = ( types || "" ).match( rnotwhite ) || [ "" ];
+		t = types.length;
+		while ( t-- ) {
+			tmp = rtypenamespace.exec( types[t] ) || [];
+			type = origType = tmp[1];
+			namespaces = ( tmp[2] || "" ).split( "." ).sort();
+
+			// Unbind all events (on this namespace, if provided) for the element
+			if ( !type ) {
+				for ( type in events ) {
+					jQuery.event.remove( elem, type + types[ t ], handler, selector, true );
+				}
+				continue;
+			}
+
+			special = jQuery.event.special[ type ] || {};
+			type = ( selector ? special.delegateType : special.bindType ) || type;
+			handlers = events[ type ] || [];
+			tmp = tmp[2] && new RegExp( "(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)" );
+
+			// Remove matching events
+			origCount = j = handlers.length;
+			while ( j-- ) {
+				handleObj = handlers[ j ];
+
+				if ( ( mappedTypes || origType === handleObj.origType ) &&
+					( !handler || handler.guid === handleObj.guid ) &&
+					( !tmp || tmp.test( handleObj.namespace ) ) &&
+					( !selector || selector === handleObj.selector || selector === "**" && handleObj.selector ) ) {
+					handlers.splice( j, 1 );
+
+					if ( handleObj.selector ) {
+						handlers.delegateCount--;
+					}
+					if ( special.remove ) {
+						special.remove.call( elem, handleObj );
+					}
+				}
+			}
+
+			// Remove generic event handler if we removed something and no more handlers exist
+			// (avoids potential for endless recursion during removal of special event handlers)
+			if ( origCount && !handlers.length ) {
+				if ( !special.teardown || special.teardown.call( elem, namespaces, elemData.handle ) === false ) {
+					jQuery.removeEvent( elem, type, elemData.handle );
+				}
+
+				delete events[ type ];
+			}
+		}
+
+		// Remove the expando if it's no longer used
+		if ( jQuery.isEmptyObject( events ) ) {
+			delete elemData.handle;
+
+			// removeData also checks for emptiness and clears the expando if empty
+			// so use it instead of delete
+			jQuery._removeData( elem, "events" );
+		}
+	},
+
+	trigger: function( event, data, elem, onlyHandlers ) {
+		var handle, ontype, cur,
+			bubbleType, special, tmp, i,
+			eventPath = [ elem || document ],
+			type = hasOwn.call( event, "type" ) ? event.type : event,
+			namespaces = hasOwn.call( event, "namespace" ) ? event.namespace.split(".") : [];
+
+		cur = tmp = elem = elem || document;
+
+		// Don't do events on text and comment nodes
+		if ( elem.nodeType === 3 || elem.nodeType === 8 ) {
+			return;
+		}
+
+		// focus/blur morphs to focusin/out; ensure we're not firing them right now
+		if ( rfocusMorph.test( type + jQuery.event.triggered ) ) {
+			return;
+		}
+
+		if ( type.indexOf(".") >= 0 ) {
+			// Namespaced trigger; create a regexp to match event type in handle()
+			namespaces = type.split(".");
+			type = namespaces.shift();
+			namespaces.sort();
+		}
+		ontype = type.indexOf(":") < 0 && "on" + type;
+
+		// Caller can pass in a jQuery.Event object, Object, or just an event type string
+		event = event[ jQuery.expando ] ?
+			event :
+			new jQuery.Event( type, typeof event === "object" && event );
+
+		// Trigger bitmask: & 1 for native handlers; & 2 for jQuery (always true)
+		event.isTrigger = onlyHandlers ? 2 : 3;
+		event.namespace = namespaces.join(".");
+		event.namespace_re = event.namespace ?
+			new RegExp( "(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)" ) :
+			null;
+
+		// Clean up the event in case it is being reused
+		event.result = undefined;
+		if ( !event.target ) {
+			event.target = elem;
+		}
+
+		// Clone any incoming data and prepend the event, creating the handler arg list
+		data = data == null ?
+			[ event ] :
+			jQuery.makeArray( data, [ event ] );
+
+		// Allow special events to draw outside the lines
+		special = jQuery.event.special[ type ] || {};
+		if ( !onlyHandlers && special.trigger && special.trigger.apply( elem, data ) === false ) {
+			return;
+		}
+
+		// Determine event propagation path in advance, per W3C events spec (#9951)
+		// Bubble up to document, then to window; watch for a global ownerDocument var (#9724)
+		if ( !onlyHandlers && !special.noBubble && !jQuery.isWindow( elem ) ) {
+
+			bubbleType = special.delegateType || type;
+			if ( !rfocusMorph.test( bubbleType + type ) ) {
+				cur = cur.parentNode;
+			}
+			for ( ; cur; cur = cur.parentNode ) {
+				eventPath.push( cur );
+				tmp = cur;
+			}
+
+			// Only add window if we got to document (e.g., not plain obj or detached DOM)
+			if ( tmp === (elem.ownerDocument || document) ) {
+				eventPath.push( tmp.defaultView || tmp.parentWindow || window );
+			}
+		}
+
+		// Fire handlers on the event path
+		i = 0;
+		while ( (cur = eventPath[i++]) && !event.isPropagationStopped() ) {
+
+			event.type = i > 1 ?
+				bubbleType :
+				special.bindType || type;
+
+			// jQuery handler
+			handle = ( jQuery._data( cur, "events" ) || {} )[ event.type ] && jQuery._data( cur, "handle" );
+			if ( handle ) {
+				handle.apply( cur, data );
+			}
+
+			// Native handler
+			handle = ontype && cur[ ontype ];
+			if ( handle && handle.apply && jQuery.acceptData( cur ) ) {
+				event.result = handle.apply( cur, data );
+				if ( event.result === false ) {
+					event.preventDefault();
+				}
+			}
+		}
+		event.type = type;
+
+		// If nobody prevented the default action, do it now
+		if ( !onlyHandlers && !event.isDefaultPrevented() ) {
+
+			if ( (!special._default || special._default.apply( eventPath.pop(), data ) === false) &&
+				jQuery.acceptData( elem ) ) {
+
+				// Call a native DOM method on the target with the same name name as the event.
+				// Can't use an .isFunction() check here because IE6/7 fails that test.
+				// Don't do default actions on window, that's where global variables be (#6170)
+				if ( ontype && elem[ type ] && !jQuery.isWindow( elem ) ) {
+
+					// Don't re-trigger an onFOO event when we call its FOO() method
+					tmp = elem[ ontype ];
+
+					if ( tmp ) {
+						elem[ ontype ] = null;
+					}
+
+					// Prevent re-triggering of the same event, since we already bubbled it above
+					jQuery.event.triggered = type;
+					try {
+						elem[ type ]();
+					} catch ( e ) {
+						// IE<9 dies on focus/blur to hidden element (#1486,#12518)
+						// only reproducible on winXP IE8 native, not IE9 in IE8 mode
+					}
+					jQuery.event.triggered = undefined;
+
+					if ( tmp ) {
+						elem[ ontype ] = tmp;
+					}
+				}
+			}
+		}
+
+		return event.result;
+	},
+
+	dispatch: function( event ) {
+
+		// Make a writable jQuery.Event from the native event object
+		event = jQuery.event.fix( event );
+
+		var i, ret, handleObj, matched, j,
+			handlerQueue = [],
+			args = slice.call( arguments ),
+			handlers = ( jQuery._data( this, "events" ) || {} )[ event.type ] || [],
+			special = jQuery.event.special[ event.type ] || {};
+
+		// Use the fix-ed jQuery.Event rather than the (read-only) native event
+		args[0] = event;
+		event.delegateTarget = this;
+
+		// Call the preDispatch hook for the mapped type, and let it bail if desired
+		if ( special.preDispatch && special.preDispatch.call( this, event ) === false ) {
+			return;
+		}
+
+		// Determine handlers
+		handlerQueue = jQuery.event.handlers.call( this, event, handlers );
+
+		// Run delegates first; they may want to stop propagation beneath us
+		i = 0;
+		while ( (matched = handlerQueue[ i++ ]) && !event.isPropagationStopped() ) {
+			event.currentTarget = matched.elem;
+
+			j = 0;
+			while ( (handleObj = matched.handlers[ j++ ]) && !event.isImmediatePropagationStopped() ) {
+
+				// Triggered event must either 1) have no namespace, or
+				// 2) have namespace(s) a subset or equal to those in the bound event (both can have no namespace).
+				if ( !event.namespace_re || event.namespace_re.test( handleObj.namespace ) ) {
+
+					event.handleObj = handleObj;
+					event.data = handleObj.data;
+
+					ret = ( (jQuery.event.special[ handleObj.origType ] || {}).handle || handleObj.handler )
+							.apply( matched.elem, args );
+
+					if ( ret !== undefined ) {
+						if ( (event.result = ret) === false ) {
+							event.preventDefault();
+							event.stopPropagation();
+						}
+					}
+				}
+			}
+		}
+
+		// Call the postDispatch hook for the mapped type
+		if ( special.postDispatch ) {
+			special.postDispatch.call( this, event );
+		}
+
+		return event.result;
+	},
+
+	handlers: function( event, handlers ) {
+		var sel, handleObj, matches, i,
+			handlerQueue = [],
+			delegateCount = handlers.delegateCount,
+			cur = event.target;
+
+		// Find delegate handlers
+		// Black-hole SVG <use> instance trees (#13180)
+		// Avoid non-left-click bubbling in Firefox (#3861)
+		if ( delegateCount && cur.nodeType && (!event.button || event.type !== "click") ) {
+
+			/* jshint eqeqeq: false */
+			for ( ; cur != this; cur = cur.parentNode || this ) {
+				/* jshint eqeqeq: true */
+
+				// Don't check non-elements (#13208)
+				// Don't process clicks on disabled elements (#6911, #8165, #11382, #11764)
+				if ( cur.nodeType === 1 && (cur.disabled !== true || event.type !== "click") ) {
+					matches = [];
+					for ( i = 0; i < delegateCount; i++ ) {
+						handleObj = handlers[ i ];
+
+						// Don't conflict with Object.prototype properties (#13203)
+						sel = handleObj.selector + " ";
+
+						if ( matches[ sel ] === undefined ) {
+							matches[ sel ] = handleObj.needsContext ?
+								jQuery( sel, this ).index( cur ) >= 0 :
+								jQuery.find( sel, this, null, [ cur ] ).length;
+						}
+						if ( matches[ sel ] ) {
+							matches.push( handleObj );
+						}
+					}
+					if ( matches.length ) {
+						handlerQueue.push({ elem: cur, handlers: matches });
+					}
+				}
+			}
+		}
+
+		// Add the remaining (directly-bound) handlers
+		if ( delegateCount < handlers.length ) {
+			handlerQueue.push({ elem: this, handlers: handlers.slice( delegateCount ) });
+		}
+
+		return handlerQueue;
+	},
+
+	fix: function( event ) {
+		if ( event[ jQuery.expando ] ) {
+			return event;
+		}
+
+		// Create a writable copy of the event object and normalize some properties
+		var i, prop, copy,
+			type = event.type,
+			originalEvent = event,
+			fixHook = this.fixHooks[ type ];
+
+		if ( !fixHook ) {
+			this.fixHooks[ type ] = fixHook =
+				rmouseEvent.test( type ) ? this.mouseHooks :
+				rkeyEvent.test( type ) ? this.keyHooks :
+				{};
+		}
+		copy = fixHook.props ? this.props.concat( fixHook.props ) : this.props;
+
+		event = new jQuery.Event( originalEvent );
+
+		i = copy.length;
+		while ( i-- ) {
+			prop = copy[ i ];
+			event[ prop ] = originalEvent[ prop ];
+		}
+
+		// Support: IE<9
+		// Fix target property (#1925)
+		if ( !event.target ) {
+			event.target = originalEvent.srcElement || document;
+		}
+
+		// Support: Chrome 23+, Safari?
+		// Target should not be a text node (#504, #13143)
+		if ( event.target.nodeType === 3 ) {
+			event.target = event.target.parentNode;
+		}
+
+		// Support: IE<9
+		// For mouse/key events, metaKey==false if it's undefined (#3368, #11328)
+		event.metaKey = !!event.metaKey;
+
+		return fixHook.filter ? fixHook.filter( event, originalEvent ) : event;
+	},
+
+	// Includes some event props shared by KeyEvent and MouseEvent
+	props: "altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),
+
+	fixHooks: {},
+
+	keyHooks: {
+		props: "char charCode key keyCode".split(" "),
+		filter: function( event, original ) {
+
+			// Add which for key events
+			if ( event.which == null ) {
+				event.which = original.charCode != null ? original.charCode : original.keyCode;
+			}
+
+			return event;
+		}
+	},
+
+	mouseHooks: {
+		props: "button buttons clientX clientY fromElement offsetX offsetY pageX pageY screenX screenY toElement".split(" "),
+		filter: function( event, original ) {
+			var body, eventDoc, doc,
+				button = original.button,
+				fromElement = original.fromElement;
+
+			// Calculate pageX/Y if missing and clientX/Y available
+			if ( event.pageX == null && original.clientX != null ) {
+				eventDoc = event.target.ownerDocument || document;
+				doc = eventDoc.documentElement;
+				body = eventDoc.body;
+
+				event.pageX = original.clientX + ( doc && doc.scrollLeft || body && body.scrollLeft || 0 ) - ( doc && doc.clientLeft || body && body.clientLeft || 0 );
+				event.pageY = original.clientY + ( doc && doc.scrollTop  || body && body.scrollTop  || 0 ) - ( doc && doc.clientTop  || body && body.clientTop  || 0 );
+			}
+
+			// Add relatedTarget, if necessary
+			if ( !event.relatedTarget && fromElement ) {
+				event.relatedTarget = fromElement === event.target ? original.toElement : fromElement;
+			}
+
+			// Add which for click: 1 === left; 2 === middle; 3 === right
+			// Note: button is not normalized, so don't use it
+			if ( !event.which && button !== undefined ) {
+				event.which = ( button & 1 ? 1 : ( button & 2 ? 3 : ( button & 4 ? 2 : 0 ) ) );
+			}
+
+			return event;
+		}
+	},
+
+	special: {
+		load: {
+			// Prevent triggered image.load events from bubbling to window.load
+			noBubble: true
+		},
+		focus: {
+			// Fire native event if possible so blur/focus sequence is correct
+			trigger: function() {
+				if ( this !== safeActiveElement() && this.focus ) {
+					try {
+						this.focus();
+						return false;
+					} catch ( e ) {
+						// Support: IE<9
+						// If we error on focus to hidden element (#1486, #12518),
+						// let .trigger() run the handlers
+					}
+				}
+			},
+			delegateType: "focusin"
+		},
+		blur: {
+			trigger: function() {
+				if ( this === safeActiveElement() && this.blur ) {
+					this.blur();
+					return false;
+				}
+			},
+			delegateType: "focusout"
+		},
+		click: {
+			// For checkbox, fire native event so checked state will be right
+			trigger: function() {
+				if ( jQuery.nodeName( this, "input" ) && this.type === "checkbox" && this.click ) {
+					this.click();
+					return false;
+				}
+			},
+
+			// For cross-browser consistency, don't fire native .click() on links
+			_default: function( event ) {
+				return jQuery.nodeName( event.target, "a" );
+			}
+		},
+
+		beforeunload: {
+			postDispatch: function( event ) {
+
+				// Support: Firefox 20+
+				// Firefox doesn't alert if the returnValue field is not set.
+				if ( event.result !== undefined && event.originalEvent ) {
+					event.originalEvent.returnValue = event.result;
+				}
+			}
+		}
+	},
+
+	simulate: function( type, elem, event, bubble ) {
+		// Piggyback on a donor event to simulate a different one.
+		// Fake originalEvent to avoid donor's stopPropagation, but if the
+		// simulated event prevents default then we do the same on the donor.
+		var e = jQuery.extend(
+			new jQuery.Event(),
+			event,
+			{
+				type: type,
+				isSimulated: true,
+				originalEvent: {}
+			}
+		);
+		if ( bubble ) {
+			jQuery.event.trigger( e, null, elem );
+		} else {
+			jQuery.event.dispatch.call( elem, e );
+		}
+		if ( e.isDefaultPrevented() ) {
+			event.preventDefault();
+		}
+	}
+};
+
+jQuery.removeEvent = document.removeEventListener ?
+	function( elem, type, handle ) {
+		if ( elem.removeEventListener ) {
+			elem.removeEventListener( type, handle, false );
+		}
+	} :
+	function( elem, type, handle ) {
+		var name = "on" + type;
+
+		if ( elem.detachEvent ) {
+
+			// #8545, #7054, preventing memory leaks for custom events in IE6-8
+			// detachEvent needed property on element, by name of that event, to properly expose it to GC
+			if ( typeof elem[ name ] === strundefined ) {
+				elem[ name ] = null;
+			}
+
+			elem.detachEvent( name, handle );
+		}
+	};
+
+jQuery.Event = function( src, props ) {
+	// Allow instantiation without the 'new' keyword
+	if ( !(this instanceof jQuery.Event) ) {
+		return new jQuery.Event( src, props );
+	}
+
+	// Event object
+	if ( src && src.type ) {
+		this.originalEvent = src;
+		this.type = src.type;
+
+		// Events bubbling up the document may have been marked as prevented
+		// by a handler lower down the tree; reflect the correct value.
+		this.isDefaultPrevented = src.defaultPrevented ||
+				src.defaultPrevented === undefined &&
+				// Support: IE < 9, Android < 4.0
+				src.returnValue === false ?
+			returnTrue :
+			returnFalse;
+
+	// Event type
+	} else {
+		this.type = src;
+	}
+
+	// Put explicitly provided properties onto the event object
+	if ( props ) {
+		jQuery.extend( this, props );
+	}
+
+	// Create a timestamp if incoming event doesn't have one
+	this.timeStamp = src && src.timeStamp || jQuery.now();
+
+	// Mark it as fixed
+	this[ jQuery.expando ] = true;
+};
+
+// jQuery.Event is based on DOM3 Events as specified by the ECMAScript Language Binding
+// http://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.html
+jQuery.Event.prototype = {
+	isDefaultPrevented: returnFalse,
+	isPropagationStopped: returnFalse,
+	isImmediatePropagationStopped: returnFalse,
+
+	preventDefault: function() {
+		var e = this.originalEvent;
+
+		this.isDefaultPrevented = returnTrue;
+		if ( !e ) {
+			return;
+		}
+
+		// If preventDefault exists, run it on the original event
+		if ( e.preventDefault ) {
+			e.preventDefault();
+
+		// Support: IE
+		// Otherwise set the returnValue property of the original event to false
+		} else {
+			e.returnValue = false;
+		}
+	},
+	stopPropagation: function() {
+		var e = this.originalEvent;
+
+		this.isPropagationStopped = returnTrue;
+		if ( !e ) {
+			return;
+		}
+		// If stopPropagation exists, run it on the original event
+		if ( e.stopPropagation ) {
+			e.stopPropagation();
+		}
+
+		// Support: IE
+		// Set the cancelBubble property of the original event to true
+		e.cancelBubble = true;
+	},
+	stopImmediatePropagation: function() {
+		var e = this.originalEvent;
+
+		this.isImmediatePropagationStopped = returnTrue;
+
+		if ( e && e.stopImmediatePropagation ) {
+			e.stopImmediatePropagation();
+		}
+
+		this.stopPropagation();
+	}
+};
+
+// Create mouseenter/leave events using mouseover/out and event-time checks
+jQuery.each({
+	mouseenter: "mouseover",
+	mouseleave: "mouseout",
+	pointerenter: "pointerover",
+	pointerleave: "pointerout"
+}, function( orig, fix ) {
+	jQuery.event.special[ orig ] = {
+		delegateType: fix,
+		bindType: fix,
+
+		handle: function( event ) {
+			var ret,
+				target = this,
+				related = event.relatedTarget,
+				handleObj = event.handleObj;
+
+			// For mousenter/leave call the handler if related is outside the target.
+			// NB: No relatedTarget if the mouse left/entered the browser window
+			if ( !related || (related !== target && !jQuery.contains( target, related )) ) {
+				event.type = handleObj.origType;
+				ret = handleObj.handler.apply( this, arguments );
+				event.type = fix;
+			}
+			return ret;
+		}
+	};
+});
+
+// IE submit delegation
+if ( !support.submitBubbles ) {
+
+	jQuery.event.special.submit = {
+		setup: function() {
+			// Only need this for delegated form submit events
+			if ( jQuery.nodeName( this, "form" ) ) {
+				return false;
+			}
+
+			// Lazy-add a submit handler when a descendant form may potentially be submitted
+			jQuery.event.add( this, "click._submit keypress._submit", function( e ) {
+				// Node name check avoids a VML-related crash in IE (#9807)
+				var elem = e.target,
+					form = jQuery.nodeName( elem, "input" ) || jQuery.nodeName( elem, "button" ) ? elem.form : undefined;
+				if ( form && !jQuery._data( form, "submitBubbles" ) ) {
+					jQuery.event.add( form, "submit._submit", function( event ) {
+						event._submit_bubble = true;
+					});
+					jQuery._data( form, "submitBubbles", true );
+				}
+			});
+			// return undefined since we don't need an event listener
+		},
+
+		postDispatch: function( event ) {
+			// If form was submitted by the user, bubble the event up the tree
+			if ( event._submit_bubble ) {
+				delete event._submit_bubble;
+				if ( this.parentNode && !event.isTrigger ) {
+					jQuery.event.simulate( "submit", this.parentNode, event, true );
+				}
+			}
+		},
+
+		teardown: function() {
+			// Only need this for delegated form submit events
+			if ( jQuery.nodeName( this, "form" ) ) {
+				return false;
+			}
+
+			// Remove delegated handlers; cleanData eventually reaps submit handlers attached above
+			jQuery.event.remove( this, "._submit" );
+		}
+	};
+}
+
+// IE change delegation and checkbox/radio fix
+if ( !support.changeBubbles ) {
+
+	jQuery.event.special.change = {
+
+		setup: function() {
+
+			if ( rformElems.test( this.nodeName ) ) {
+				// IE doesn't fire change on a check/radio until blur; trigger it on click
+				// after a propertychange. Eat the blur-change in special.change.handle.
+				// This still fires onchange a second time for check/radio after blur.
+				if ( this.type === "checkbox" || this.type === "radio" ) {
+					jQuery.event.add( this, "propertychange._change", function( event ) {
+						if ( event.originalEvent.propertyName === "checked" ) {
+							this._just_changed = true;
+						}
+					});
+					jQuery.event.add( this, "click._change", function( event ) {
+						if ( this._just_changed && !event.isTrigger ) {
+							this._just_changed = false;
+						}
+						// Allow triggered, simulated change events (#11500)
+						jQuery.event.simulate( "change", this, event, true );
+					});
+				}
+				return false;
+			}
+			// Delegated event; lazy-add a change handler on descendant inputs
+			jQuery.event.add( this, "beforeactivate._change", function( e ) {
+				var elem = e.target;
+
+				if ( rformElems.test( elem.nodeName ) && !jQuery._data( elem, "changeBubbles" ) ) {
+					jQuery.event.add( elem, "change._change", function( event ) {
+						if ( this.parentNode && !event.isSimulated && !event.isTrigger ) {
+							jQuery.event.simulate( "change", this.parentNode, event, true );
+						}
+					});
+					jQuery._data( elem, "changeBubbles", true );
+				}
+			});
+		},
+
+		handle: function( event ) {
+			var elem = event.target;
+
+			// Swallow native change events from checkbox/radio, we already triggered them above
+			if ( this !== elem || event.isSimulated || event.isTrigger || (elem.type !== "radio" && elem.type !== "checkbox") ) {
+				return event.handleObj.handler.apply( this, arguments );
+			}
+		},
+
+		teardown: function() {
+			jQuery.event.remove( this, "._change" );
+
+			return !rformElems.test( this.nodeName );
+		}
+	};
+}
+
+// Create "bubbling" focus and blur events
+if ( !support.focusinBubbles ) {
+	jQuery.each({ focus: "focusin", blur: "focusout" }, function( orig, fix ) {
+
+		// Attach a single capturing handler on the document while someone wants focusin/focusout
+		var handler = function( event ) {
+				jQuery.event.simulate( fix, event.target, jQuery.event.fix( event ), true );
+			};
+
+		jQuery.event.special[ fix ] = {
+			setup: function() {
+				var doc = this.ownerDocument || this,
+					attaches = jQuery._data( doc, fix );
+
+				if ( !attaches ) {
+					doc.addEventListener( orig, handler, true );
+				}
+				jQuery._data( doc, fix, ( attaches || 0 ) + 1 );
+			},
+			teardown: function() {
+				var doc = this.ownerDocument || this,
+					attaches = jQuery._data( doc, fix ) - 1;
+
+				if ( !attaches ) {
+					doc.removeEventListener( orig, handler, true );
+					jQuery._removeData( doc, fix );
+				} else {
+					jQuery._data( doc, fix, attaches );
+				}
+			}
+		};
+	});
+}
+
+jQuery.fn.extend({
+
+	on: function( types, selector, data, fn, /*INTERNAL*/ one ) {
+		var type, origFn;
+
+		// Types can be a map of types/handlers
+		if ( typeof types === "object" ) {
+			// ( types-Object, selector, data )
+			if ( typeof selector !== "string" ) {
+				// ( types-Object, data )
+				data = data || selector;
+				selector = undefined;
+			}
+			for ( type in types ) {
+				this.on( type, selector, data, types[ type ], one );
+			}
+			return this;
+		}
+
+		if ( data == null && fn == null ) {
+			// ( types, fn )
+			fn = selector;
+			data = selector = undefined;
+		} else if ( fn == null ) {
+			if ( typeof selector === "string" ) {
+				// ( types, selector, fn )
+				fn = data;
+				data = undefined;
+			} else {
+				// ( types, data, fn )
+				fn = data;
+				data = selector;
+				selector = undefined;
+			}
+		}
+		if ( fn === false ) {
+			fn = returnFalse;
+		} else if ( !fn ) {
+			return this;
+		}
+
+		if ( one === 1 ) {
+			origFn = fn;
+			fn = function( event ) {
+				// Can use an empty set, since event contains the info
+				jQuery().off( event );
+				return origFn.apply( this, arguments );
+			};
+			// Use same guid so caller can remove using origFn
+			fn.guid = origFn.guid || ( origFn.guid = jQuery.guid++ );
+		}
+		return this.each( function() {
+			jQuery.event.add( this, types, fn, data, selector );
+		});
+	},
+	one: function( types, selector, data, fn ) {
+		return this.on( types, selector, data, fn, 1 );
+	},
+	off: function( types, selector, fn ) {
+		var handleObj, type;
+		if ( types && types.preventDefault && types.handleObj ) {
+			// ( event )  dispatched jQuery.Event
+			handleObj = types.handleObj;
+			jQuery( types.delegateTarget ).off(
+				handleObj.namespace ? handleObj.origType + "." + handleObj.namespace : handleObj.origType,
+				handleObj.selector,
+				handleObj.handler
+			);
+			return this;
+		}
+		if ( typeof types === "object" ) {
+			// ( types-object [, selector] )
+			for ( type in types ) {
+				this.off( type, selector, types[ type ] );
+			}
+			return this;
+		}
+		if ( selector === false || typeof selector === "function" ) {
+			// ( types [, fn] )
+			fn = selector;
+			selector = undefined;
+		}
+		if ( fn === false ) {
+			fn = returnFalse;
+		}
+		return this.each(function() {
+			jQuery.event.remove( this, types, fn, selector );
+		});
+	},
+
+	trigger: function( type, data ) {
+		return this.each(function() {
+			jQuery.event.trigger( type, data, this );
+		});
+	},
+	triggerHandler: function( type, data ) {
+		var elem = this[0];
+		if ( elem ) {
+			return jQuery.event.trigger( type, data, elem, true );
+		}
+	}
+});
+
+
+function createSafeFragment( document ) {
+	var list = nodeNames.split( "|" ),
+		safeFrag = document.createDocumentFragment();
+
+	if ( safeFrag.createElement ) {
+		while ( list.length ) {
+			safeFrag.createElement(
+				list.pop()
+			);
+		}
+	}
+	return safeFrag;
+}
+
+var nodeNames = "abbr|article|aside|audio|bdi|canvas|data|datalist|details|figcaption|figure|footer|" +
+		"header|hgroup|mark|meter|nav|output|progress|section|summary|time|video",
+	rinlinejQuery = / jQuery\d+="(?:null|\d+)"/g,
+	rnoshimcache = new RegExp("<(?:" + nodeNames + ")[\\s/>]", "i"),
+	rleadingWhitespace = /^\s+/,
+	rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,
+	rtagName = /<([\w:]+)/,
+	rtbody = /<tbody/i,
+	rhtml = /<|&#?\w+;/,
+	rnoInnerhtml = /<(?:script|style|link)/i,
+	// checked="checked" or checked
+	rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i,
+	rscriptType = /^$|\/(?:java|ecma)script/i,
+	rscriptTypeMasked = /^true\/(.*)/,
+	rcleanScript = /^\s*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*$/g,
+
+	// We have to close these tags to support XHTML (#13200)
+	wrapMap = {
+		option: [ 1, "<select multiple='multiple'>", "</select>" ],
+		legend: [ 1, "<fieldset>", "</fieldset>" ],
+		area: [ 1, "<map>", "</map>" ],
+		param: [ 1, "<object>", "</object>" ],
+		thead: [ 1, "<table>", "</table>" ],
+		tr: [ 2, "<table><tbody>", "</tbody></table>" ],
+		col: [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ],
+		td: [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ],
+
+		// IE6-8 can't serialize link, script, style, or any html5 (NoScope) tags,
+		// unless wrapped in a div with non-breaking characters in front of it.
+		_default: support.htmlSerialize ? [ 0, "", "" ] : [ 1, "X<div>", "</div>"  ]
+	},
+	safeFragment = createSafeFragment( document ),
+	fragmentDiv = safeFragment.appendChild( document.createElement("div") );
+
+wrapMap.optgroup = wrapMap.option;
+wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead;
+wrapMap.th = wrapMap.td;
+
+function getAll( context, tag ) {
+	var elems, elem,
+		i = 0,
+		found = typeof context.getElementsByTagName !== strundefined ? context.getElementsByTagName( tag || "*" ) :
+			typeof context.querySelectorAll !== strundefined ? context.querySelectorAll( tag || "*" ) :
+			undefined;
+
+	if ( !found ) {
+		for ( found = [], elems = context.childNodes || context; (elem = elems[i]) != null; i++ ) {
+			if ( !tag || jQuery.nodeName( elem, tag ) ) {
+				found.push( elem );
+			} else {
+				jQuery.merge( found, getAll( elem, tag ) );
+			}
+		}
+	}
+
+	return tag === undefined || tag && jQuery.nodeName( context, tag ) ?
+		jQuery.merge( [ context ], found ) :
+		found;
+}
+
+// Used in buildFragment, fixes the defaultChecked property
+function fixDefaultChecked( elem ) {
+	if ( rcheckableType.test( elem.type ) ) {
+		elem.defaultChecked = elem.checked;
+	}
+}
+
+// Support: IE<8
+// Manipulating tables requires a tbody
+function manipulationTarget( elem, content ) {
+	return jQuery.nodeName( elem, "table" ) &&
+		jQuery.nodeName( content.nodeType !== 11 ? content : content.firstChild, "tr" ) ?
+
+		elem.getElementsByTagName("tbody")[0] ||
+			elem.appendChild( elem.ownerDocument.createElement("tbody") ) :
+		elem;
+}
+
+// Replace/restore the type attribute of script elements for safe DOM manipulation
+function disableScript( elem ) {
+	elem.type = (jQuery.find.attr( elem, "type" ) !== null) + "/" + elem.type;
+	return elem;
+}
+function restoreScript( elem ) {
+	var match = rscriptTypeMasked.exec( elem.type );
+	if ( match ) {
+		elem.type = match[1];
+	} else {
+		elem.removeAttribute("type");
+	}
+	return elem;
+}
+
+// Mark scripts as having already been evaluated
+function setGlobalEval( elems, refElements ) {
+	var elem,
+		i = 0;
+	for ( ; (elem = elems[i]) != null; i++ ) {
+		jQuery._data( elem, "globalEval", !refElements || jQuery._data( refElements[i], "globalEval" ) );
+	}
+}
+
+function cloneCopyEvent( src, dest ) {
+
+	if ( dest.nodeType !== 1 || !jQuery.hasData( src ) ) {
+		return;
+	}
+
+	var type, i, l,
+		oldData = jQuery._data( src ),
+		curData = jQuery._data( dest, oldData ),
+		events = oldData.events;
+
+	if ( events ) {
+		delete curData.handle;
+		curData.events = {};
+
+		for ( type in events ) {
+			for ( i = 0, l = events[ type ].length; i < l; i++ ) {
+				jQuery.event.add( dest, type, events[ type ][ i ] );
+			}
+		}
+	}
+
+	// make the cloned public data object a copy from the original
+	if ( curData.data ) {
+		curData.data = jQuery.extend( {}, curData.data );
+	}
+}
+
+function fixCloneNodeIssues( src, dest ) {
+	var nodeName, e, data;
+
+	// We do not need to do anything for non-Elements
+	if ( dest.nodeType !== 1 ) {
+		return;
+	}
+
+	nodeName = dest.nodeName.toLowerCase();
+
+	// IE6-8 copies events bound via attachEvent when using cloneNode.
+	if ( !support.noCloneEvent && dest[ jQuery.expando ] ) {
+		data = jQuery._data( dest );
+
+		for ( e in data.events ) {
+			jQuery.removeEvent( dest, e, data.handle );
+		}
+
+		// Event data gets referenced instead of copied if the expando gets copied too
+		dest.removeAttribute( jQuery.expando );
+	}
+
+	// IE blanks contents when cloning scripts, and tries to evaluate newly-set text
+	if ( nodeName === "script" && dest.text !== src.text ) {
+		disableScript( dest ).text = src.text;
+		restoreScript( dest );
+
+	// IE6-10 improperly clones children of object elements using classid.
+	// IE10 throws NoModificationAllowedError if parent is null, #12132.
+	} else if ( nodeName === "object" ) {
+		if ( dest.parentNode ) {
+			dest.outerHTML = src.outerHTML;
+		}
+
+		// This path appears unavoidable for IE9. When cloning an object
+		// element in IE9, the outerHTML strategy above is not sufficient.
+		// If the src has innerHTML and the destination does not,
+		// copy the src.innerHTML into the dest.innerHTML. #10324
+		if ( support.html5Clone && ( src.innerHTML && !jQuery.trim(dest.innerHTML) ) ) {
+			dest.innerHTML = src.innerHTML;
+		}
+
+	} else if ( nodeName === "input" && rcheckableType.test( src.type ) ) {
+		// IE6-8 fails to persist the checked state of a cloned checkbox
+		// or radio button. Worse, IE6-7 fail to give the cloned element
+		// a checked appearance if the defaultChecked value isn't also set
+
+		dest.defaultChecked = dest.checked = src.checked;
+
+		// IE6-7 get confused and end up setting the value of a cloned
+		// checkbox/radio button to an empty string instead of "on"
+		if ( dest.value !== src.value ) {
+			dest.value = src.value;
+		}
+
+	// IE6-8 fails to return the selected option to the default selected
+	// state when cloning options
+	} else if ( nodeName === "option" ) {
+		dest.defaultSelected = dest.selected = src.defaultSelected;
+
+	// IE6-8 fails to set the defaultValue to the correct value when
+	// cloning other types of input fields
+	} else if ( nodeName === "input" || nodeName === "textarea" ) {
+		dest.defaultValue = src.defaultValue;
+	}
+}
+
+jQuery.extend({
+	clone: function( elem, dataAndEvents, deepDataAndEvents ) {
+		var destElements, node, clone, i, srcElements,
+			inPage = jQuery.contains( elem.ownerDocument, elem );
+
+		if ( support.html5Clone || jQuery.isXMLDoc(elem) || !rnoshimcache.test( "<" + elem.nodeName + ">" ) ) {
+			clone = elem.cloneNode( true );
+
+		// IE<=8 does not properly clone detached, unknown element nodes
+		} else {
+			fragmentDiv.innerHTML = elem.outerHTML;
+			fragmentDiv.removeChild( clone = fragmentDiv.firstChild );
+		}
+
+		if ( (!support.noCloneEvent || !support.noCloneChecked) &&
+				(elem.nodeType === 1 || elem.nodeType === 11) && !jQuery.isXMLDoc(elem) ) {
+
+			// We eschew Sizzle here for performance reasons: http://jsperf.com/getall-vs-sizzle/2
+			destElements = getAll( clone );
+			srcElements = getAll( elem );
+
+			// Fix all IE cloning issues
+			for ( i = 0; (node = srcElements[i]) != null; ++i ) {
+				// Ensure that the destination node is not null; Fixes #9587
+				if ( destElements[i] ) {
+					fixCloneNodeIssues( node, destElements[i] );
+				}
+			}
+		}
+
+		// Copy the events from the original to the clone
+		if ( dataAndEvents ) {
+			if ( deepDataAndEvents ) {
+				srcElements = srcElements || getAll( elem );
+				destElements = destElements || getAll( clone );
+
+				for ( i = 0; (node = srcElements[i]) != null; i++ ) {
+					cloneCopyEvent( node, destElements[i] );
+				}
+			} else {
+				cloneCopyEvent( elem, clone );
+			}
+		}
+
+		// Preserve script evaluation history
+		destElements = getAll( clone, "script" );
+		if ( destElements.length > 0 ) {
+			setGlobalEval( destElements, !inPage && getAll( elem, "script" ) );
+		}
+
+		destElements = srcElements = node = null;
+
+		// Return the cloned set
+		return clone;
+	},
+
+	buildFragment: function( elems, context, scripts, selection ) {
+		var j, elem, contains,
+			tmp, tag, tbody, wrap,
+			l = elems.length,
+
+			// Ensure a safe fragment
+			safe = createSafeFragment( context ),
+
+			nodes = [],
+			i = 0;
+
+		for ( ; i < l; i++ ) {
+			elem = elems[ i ];
+
+			if ( elem || elem === 0 ) {
+
+				// Add nodes directly
+				if ( jQuery.type( elem ) === "object" ) {
+					jQuery.merge( nodes, elem.nodeType ? [ elem ] : elem );
+
+				// Convert non-html into a text node
+				} else if ( !rhtml.test( elem ) ) {
+					nodes.push( context.createTextNode( elem ) );
+
+				// Convert html into DOM nodes
+				} else {
+					tmp = tmp || safe.appendChild( context.createElement("div") );
+
+					// Deserialize a standard representation
+					tag = (rtagName.exec( elem ) || [ "", "" ])[ 1 ].toLowerCase();
+					wrap = wrapMap[ tag ] || wrapMap._default;
+
+					tmp.innerHTML = wrap[1] + elem.replace( rxhtmlTag, "<$1></$2>" ) + wrap[2];
+
+					// Descend through wrappers to the right content
+					j = wrap[0];
+					while ( j-- ) {
+						tmp = tmp.lastChild;
+					}
+
+					// Manually add leading whitespace removed by IE
+					if ( !support.leadingWhitespace && rleadingWhitespace.test( elem ) ) {
+						nodes.push( context.createTextNode( rleadingWhitespace.exec( elem )[0] ) );
+					}
+
+					// Remove IE's autoinserted <tbody> from table fragments
+					if ( !support.tbody ) {
+
+						// String was a <table>, *may* have spurious <tbody>
+						elem = tag === "table" && !rtbody.test( elem ) ?
+							tmp.firstChild :
+
+							// String was a bare <thead> or <tfoot>
+							wrap[1] === "<table>" && !rtbody.test( elem ) ?
+								tmp :
+								0;
+
+						j = elem && elem.childNodes.length;
+						while ( j-- ) {
+							if ( jQuery.nodeName( (tbody = elem.childNodes[j]), "tbody" ) && !tbody.childNodes.length ) {
+								elem.removeChild( tbody );
+							}
+						}
+					}
+
+					jQuery.merge( nodes, tmp.childNodes );
+
+					// Fix #12392 for WebKit and IE > 9
+					tmp.textContent = "";
+
+					// Fix #12392 for oldIE
+					while ( tmp.firstChild ) {
+						tmp.removeChild( tmp.firstChild );
+					}
+
+					// Remember the top-level container for proper cleanup
+					tmp = safe.lastChild;
+				}
+			}
+		}
+
+		// Fix #11356: Clear elements from fragment
+		if ( tmp ) {
+			safe.removeChild( tmp );
+		}
+
+		// Reset defaultChecked for any radios and checkboxes
+		// about to be appended to the DOM in IE 6/7 (#8060)
+		if ( !support.appendChecked ) {
+			jQuery.grep( getAll( nodes, "input" ), fixDefaultChecked );
+		}
+
+		i = 0;
+		while ( (elem = nodes[ i++ ]) ) {
+
+			// #4087 - If origin and destination elements are the same, and this is
+			// that element, do not do anything
+			if ( selection && jQuery.inArray( elem, selection ) !== -1 ) {
+				continue;
+			}
+
+			contains = jQuery.contains( elem.ownerDocument, elem );
+
+			// Append to fragment
+			tmp = getAll( safe.appendChild( elem ), "script" );
+
+			// Preserve script evaluation history
+			if ( contains ) {
+				setGlobalEval( tmp );
+			}
+
+			// Capture executables
+			if ( scripts ) {
+				j = 0;
+				while ( (elem = tmp[ j++ ]) ) {
+					if ( rscriptType.test( elem.type || "" ) ) {
+						scripts.push( elem );
+					}
+				}
+			}
+		}
+
+		tmp = null;
+
+		return safe;
+	},
+
+	cleanData: function( elems, /* internal */ acceptData ) {
+		var elem, type, id, data,
+			i = 0,
+			internalKey = jQuery.expando,
+			cache = jQuery.cache,
+			deleteExpando = support.deleteExpando,
+			special = jQuery.event.special;
+
+		for ( ; (elem = elems[i]) != null; i++ ) {
+			if ( acceptData || jQuery.acceptData( elem ) ) {
+
+				id = elem[ internalKey ];
+				data = id && cache[ id ];
+
+				if ( data ) {
+					if ( data.events ) {
+						for ( type in data.events ) {
+							if ( special[ type ] ) {
+								jQuery.event.remove( elem, type );
+
+							// This is a shortcut to avoid jQuery.event.remove's overhead
+							} else {
+								jQuery.removeEvent( elem, type, data.handle );
+							}
+						}
+					}
+
+					// Remove cache only if it was not already removed by jQuery.event.remove
+					if ( cache[ id ] ) {
+
+						delete cache[ id ];
+
+						// IE does not allow us to delete expando properties from nodes,
+						// nor does it have a removeAttribute function on Document nodes;
+						// we must handle all of these cases
+						if ( deleteExpando ) {
+							delete elem[ internalKey ];
+
+						} else if ( typeof elem.removeAttribute !== strundefined ) {
+							elem.removeAttribute( internalKey );
+
+						} else {
+							elem[ internalKey ] = null;
+						}
+
+						deletedIds.push( id );
+					}
+				}
+			}
+		}
+	}
+});
+
+jQuery.fn.extend({
+	text: function( value ) {
+		return access( this, function( value ) {
+			return value === undefined ?
+				jQuery.text( this ) :
+				this.empty().append( ( this[0] && this[0].ownerDocument || document ).createTextNode( value ) );
+		}, null, value, arguments.length );
+	},
+
+	append: function() {
+		return this.domManip( arguments, function( elem ) {
+			if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
+				var target = manipulationTarget( this, elem );
+				target.appendChild( elem );
+			}
+		});
+	},
+
+	prepend: function() {
+		return this.domManip( arguments, function( elem ) {
+			if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
+				var target = manipulationTarget( this, elem );
+				target.insertBefore( elem, target.firstChild );
+			}
+		});
+	},
+
+	before: function() {
+		return this.domManip( arguments, function( elem ) {
+			if ( this.parentNode ) {
+				this.parentNode.insertBefore( elem, this );
+			}
+		});
+	},
+
+	after: function() {
+		return this.domManip( arguments, function( elem ) {
+			if ( this.parentNode ) {
+				this.parentNode.insertBefore( elem, this.nextSibling );
+			}
+		});
+	},
+
+	remove: function( selector, keepData /* Internal Use Only */ ) {
+		var elem,
+			elems = selector ? jQuery.filter( selector, this ) : this,
+			i = 0;
+
+		for ( ; (elem = elems[i]) != null; i++ ) {
+
+			if ( !keepData && elem.nodeType === 1 ) {
+				jQuery.cleanData( getAll( elem ) );
+			}
+
+			if ( elem.parentNode ) {
+				if ( keepData && jQuery.contains( elem.ownerDocument, elem ) ) {
+					setGlobalEval( getAll( elem, "script" ) );
+				}
+				elem.parentNode.removeChild( elem );
+			}
+		}
+
+		return this;
+	},
+
+	empty: function() {
+		var elem,
+			i = 0;
+
+		for ( ; (elem = this[i]) != null; i++ ) {
+			// Remove element nodes and prevent memory leaks
+			if ( elem.nodeType === 1 ) {
+				jQuery.cleanData( getAll( elem, false ) );
+			}
+
+			// Remove any remaining nodes
+			while ( elem.firstChild ) {
+				elem.removeChild( elem.firstChild );
+			}
+
+			// If this is a select, ensure that it displays empty (#12336)
+			// Support: IE<9
+			if ( elem.options && jQuery.nodeName( elem, "select" ) ) {
+				elem.options.length = 0;
+			}
+		}
+
+		return this;
+	},
+
+	clone: function( dataAndEvents, deepDataAndEvents ) {
+		dataAndEvents = dataAndEvents == null ? false : dataAndEvents;
+		deepDataAndEvents = deepDataAndEvents == null ? dataAndEvents : deepDataAndEvents;
+
+		return this.map(function() {
+			return jQuery.clone( this, dataAndEvents, deepDataAndEvents );
+		});
+	},
+
+	html: function( value ) {
+		return access( this, function( value ) {
+			var elem = this[ 0 ] || {},
+				i = 0,
+				l = this.length;
+
+			if ( value === undefined ) {
+				return elem.nodeType === 1 ?
+					elem.innerHTML.replace( rinlinejQuery, "" ) :
+					undefined;
+			}
+
+			// See if we can take a shortcut and just use innerHTML
+			if ( typeof value === "string" && !rnoInnerhtml.test( value ) &&
+				( support.htmlSerialize || !rnoshimcache.test( value )  ) &&
+				( support.leadingWhitespace || !rleadingWhitespace.test( value ) ) &&
+				!wrapMap[ (rtagName.exec( value ) || [ "", "" ])[ 1 ].toLowerCase() ] ) {
+
+				value = value.replace( rxhtmlTag, "<$1></$2>" );
+
+				try {
+					for (; i < l; i++ ) {
+						// Remove element nodes and prevent memory leaks
+						elem = this[i] || {};
+						if ( elem.nodeType === 1 ) {
+							jQuery.cleanData( getAll( elem, false ) );
+							elem.innerHTML = value;
+						}
+					}
+
+					elem = 0;
+
+				// If using innerHTML throws an exception, use the fallback method
+				} catch(e) {}
+			}
+
+			if ( elem ) {
+				this.empty().append( value );
+			}
+		}, null, value, arguments.length );
+	},
+
+	replaceWith: function() {
+		var arg = arguments[ 0 ];
+
+		// Make the changes, replacing each context element with the new content
+		this.domManip( arguments, function( elem ) {
+			arg = this.parentNode;
+
+			jQuery.cleanData( getAll( this ) );
+
+			if ( arg ) {
+				arg.replaceChild( elem, this );
+			}
+		});
+
+		// Force removal if there was no new content (e.g., from empty arguments)
+		return arg && (arg.length || arg.nodeType) ? this : this.remove();
+	},
+
+	detach: function( selector ) {
+		return this.remove( selector, true );
+	},
+
+	domManip: function( args, callback ) {
+
+		// Flatten any nested arrays
+		args = concat.apply( [], args );
+
+		var first, node, hasScripts,
+			scripts, doc, fragment,
+			i = 0,
+			l = this.length,
+			set = this,
+			iNoClone = l - 1,
+			value = args[0],
+			isFunction = jQuery.isFunction( value );
+
+		// We can't cloneNode fragments that contain checked, in WebKit
+		if ( isFunction ||
+				( l > 1 && typeof value === "string" &&
+					!support.checkClone && rchecked.test( value ) ) ) {
+			return this.each(function( index ) {
+				var self = set.eq( index );
+				if ( isFunction ) {
+					args[0] = value.call( this, index, self.html() );
+				}
+				self.domManip( args, callback );
+			});
+		}
+
+		if ( l ) {
+			fragment = jQuery.buildFragment( args, this[ 0 ].ownerDocument, false, this );
+			first = fragment.firstChild;
+
+			if ( fragment.childNodes.length === 1 ) {
+				fragment = first;
+			}
+
+			if ( first ) {
+				scripts = jQuery.map( getAll( fragment, "script" ), disableScript );
+				hasScripts = scripts.length;
+
+				// Use the original fragment for the last item instead of the first because it can end up
+				// being emptied incorrectly in certain situations (#8070).
+				for ( ; i < l; i++ ) {
+					node = fragment;
+
+					if ( i !== iNoClone ) {
+						node = jQuery.clone( node, true, true );
+
+						// Keep references to cloned scripts for later restoration
+						if ( hasScripts ) {
+							jQuery.merge( scripts, getAll( node, "script" ) );
+						}
+					}
+
+					callback.call( this[i], node, i );
+				}
+
+				if ( hasScripts ) {
+					doc = scripts[ scripts.length - 1 ].ownerDocument;
+
+					// Reenable scripts
+					jQuery.map( scripts, restoreScript );
+
+					// Evaluate executable scripts on first document insertion
+					for ( i = 0; i < hasScripts; i++ ) {
+						node = scripts[ i ];
+						if ( rscriptType.test( node.type || "" ) &&
+							!jQuery._data( node, "globalEval" ) && jQuery.contains( doc, node ) ) {
+
+							if ( node.src ) {
+								// Optional AJAX dependency, but won't run scripts if not present
+								if ( jQuery._evalUrl ) {
+									jQuery._evalUrl( node.src );
+								}
+							} else {
+								jQuery.globalEval( ( node.text || node.textContent || node.innerHTML || "" ).replace( rcleanScript, "" ) );
+							}
+						}
+					}
+				}
+
+				// Fix #11809: Avoid leaking memory
+				fragment = first = null;
+			}
+		}
+
+		return this;
+	}
+});
+
+jQuery.each({
+	appendTo: "append",
+	prependTo: "prepend",
+	insertBefore: "before",
+	insertAfter: "after",
+	replaceAll: "replaceWith"
+}, function( name, original ) {
+	jQuery.fn[ name ] = function( selector ) {
+		var elems,
+			i = 0,
+			ret = [],
+			insert = jQuery( selector ),
+			last = insert.length - 1;
+
+		for ( ; i <= last; i++ ) {
+			elems = i === last ? this : this.clone(true);
+			jQuery( insert[i] )[ original ]( elems );
+
+			// Modern browsers can apply jQuery collections as arrays, but oldIE needs a .get()
+			push.apply( ret, elems.get() );
+		}
+
+		return this.pushStack( ret );
+	};
+});
+
+
+var iframe,
+	elemdisplay = {};
+
+/**
+ * Retrieve the actual display of a element
+ * @param {String} name nodeName of the element
+ * @param {Object} doc Document object
+ */
+// Called only from within defaultDisplay
+function actualDisplay( name, doc ) {
+	var style,
+		elem = jQuery( doc.createElement( name ) ).appendTo( doc.body ),
+
+		// getDefaultComputedStyle might be reliably used only on attached element
+		display = window.getDefaultComputedStyle && ( style = window.getDefaultComputedStyle( elem[ 0 ] ) ) ?
+
+			// Use of this method is a temporary fix (more like optmization) until something better comes along,
+			// since it was removed from specification and supported only in FF
+			style.display : jQuery.css( elem[ 0 ], "display" );
+
+	// We don't have any data stored on the element,
+	// so use "detach" method as fast way to get rid of the element
+	elem.detach();
+
+	return display;
+}
+
+/**
+ * Try to determine the default display value of an element
+ * @param {String} nodeName
+ */
+function defaultDisplay( nodeName ) {
+	var doc = document,
+		display = elemdisplay[ nodeName ];
+
+	if ( !display ) {
+		display = actualDisplay( nodeName, doc );
+
+		// If the simple way fails, read from inside an iframe
+		if ( display === "none" || !display ) {
+
+			// Use the already-created iframe if possible
+			iframe = (iframe || jQuery( "<iframe frameborder='0' width='0' height='0'/>" )).appendTo( doc.documentElement );
+
+			// Always write a new HTML skeleton so Webkit and Firefox don't choke on reuse
+			doc = ( iframe[ 0 ].contentWindow || iframe[ 0 ].contentDocument ).document;
+
+			// Support: IE
+			doc.write();
+			doc.close();
+
+			display = actualDisplay( nodeName, doc );
+			iframe.detach();
+		}
+
+		// Store the correct default display
+		elemdisplay[ nodeName ] = display;
+	}
+
+	return display;
+}
+
+
+(function() {
+	var shrinkWrapBlocksVal;
+
+	support.shrinkWrapBlocks = function() {
+		if ( shrinkWrapBlocksVal != null ) {
+			return shrinkWrapBlocksVal;
+		}
+
+		// Will be changed later if needed.
+		shrinkWrapBlocksVal = false;
+
+		// Minified: var b,c,d
+		var div, body, container;
+
+		body = document.getElementsByTagName( "body" )[ 0 ];
+		if ( !body || !body.style ) {
+			// Test fired too early or in an unsupported environment, exit.
+			return;
+		}
+
+		// Setup
+		div = document.createElement( "div" );
+		container = document.createElement( "div" );
+		container.style.cssText = "position:absolute;border:0;width:0;height:0;top:0;left:-9999px";
+		body.appendChild( container ).appendChild( div );
+
+		// Support: IE6
+		// Check if elements with layout shrink-wrap their children
+		if ( typeof div.style.zoom !== strundefined ) {
+			// Reset CSS: box-sizing; display; margin; border
+			div.style.cssText =
+				// Support: Firefox<29, Android 2.3
+				// Vendor-prefix box-sizing
+				"-webkit-box-sizing:content-box;-moz-box-sizing:content-box;" +
+				"box-sizing:content-box;display:block;margin:0;border:0;" +
+				"padding:1px;width:1px;zoom:1";
+			div.appendChild( document.createElement( "div" ) ).style.width = "5px";
+			shrinkWrapBlocksVal = div.offsetWidth !== 3;
+		}
+
+		body.removeChild( container );
+
+		return shrinkWrapBlocksVal;
+	};
+
+})();
+var rmargin = (/^margin/);
+
+var rnumnonpx = new RegExp( "^(" + pnum + ")(?!px)[a-z%]+$", "i" );
+
+
+
+var getStyles, curCSS,
+	rposition = /^(top|right|bottom|left)$/;
+
+if ( window.getComputedStyle ) {
+	getStyles = function( elem ) {
+		// Support: IE<=11+, Firefox<=30+ (#15098, #14150)
+		// IE throws on elements created in popups
+		// FF meanwhile throws on frame elements through "defaultView.getComputedStyle"
+		if ( elem.ownerDocument.defaultView.opener ) {
+			return elem.ownerDocument.defaultView.getComputedStyle( elem, null );
+		}
+
+		return window.getComputedStyle( elem, null );
+	};
+
+	curCSS = function( elem, name, computed ) {
+		var width, minWidth, maxWidth, ret,
+			style = elem.style;
+
+		computed = computed || getStyles( elem );
+
+		// getPropertyValue is only needed for .css('filter') in IE9, see #12537
+		ret = computed ? computed.getPropertyValue( name ) || computed[ name ] : undefined;
+
+		if ( computed ) {
+
+			if ( ret === "" && !jQuery.contains( elem.ownerDocument, elem ) ) {
+				ret = jQuery.style( elem, name );
+			}
+
+			// A tribute to the "awesome hack by Dean Edwards"
+			// Chrome < 17 and Safari 5.0 uses "computed value" instead of "used value" for margin-right
+			// Safari 5.1.7 (at least) returns percentage for a larger set of values, but width seems to be reliably pixels
+			// this is against the CSSOM draft spec: http://dev.w3.org/csswg/cssom/#resolved-values
+			if ( rnumnonpx.test( ret ) && rmargin.test( name ) ) {
+
+				// Remember the original values
+				width = style.width;
+				minWidth = style.minWidth;
+				maxWidth = style.maxWidth;
+
+				// Put in the new values to get a computed value out
+				style.minWidth = style.maxWidth = style.width = ret;
+				ret = computed.width;
+
+				// Revert the changed values
+				style.width = width;
+				style.minWidth = minWidth;
+				style.maxWidth = maxWidth;
+			}
+		}
+
+		// Support: IE
+		// IE returns zIndex value as an integer.
+		return ret === undefined ?
+			ret :
+			ret + "";
+	};
+} else if ( document.documentElement.currentStyle ) {
+	getStyles = function( elem ) {
+		return elem.currentStyle;
+	};
+
+	curCSS = function( elem, name, computed ) {
+		var left, rs, rsLeft, ret,
+			style = elem.style;
+
+		computed = computed || getStyles( elem );
+		ret = computed ? computed[ name ] : undefined;
+
+		// Avoid setting ret to empty string here
+		// so we don't default to auto
+		if ( ret == null && style && style[ name ] ) {
+			ret = style[ name ];
+		}
+
+		// From the awesome hack by Dean Edwards
+		// http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
+
+		// If we're not dealing with a regular pixel number
+		// but a number that has a weird ending, we need to convert it to pixels
+		// but not position css attributes, as those are proportional to the parent element instead
+		// and we can't measure the parent instead because it might trigger a "stacking dolls" problem
+		if ( rnumnonpx.test( ret ) && !rposition.test( name ) ) {
+
+			// Remember the original values
+			left = style.left;
+			rs = elem.runtimeStyle;
+			rsLeft = rs && rs.left;
+
+			// Put in the new values to get a computed value out
+			if ( rsLeft ) {
+				rs.left = elem.currentStyle.left;
+			}
+			style.left = name === "fontSize" ? "1em" : ret;
+			ret = style.pixelLeft + "px";
+
+			// Revert the changed values
+			style.left = left;
+			if ( rsLeft ) {
+				rs.left = rsLeft;
+			}
+		}
+
+		// Support: IE
+		// IE returns zIndex value as an integer.
+		return ret === undefined ?
+			ret :
+			ret + "" || "auto";
+	};
+}
+
+
+
+
+function addGetHookIf( conditionFn, hookFn ) {
+	// Define the hook, we'll check on the first run if it's really needed.
+	return {
+		get: function() {
+			var condition = conditionFn();
+
+			if ( condition == null ) {
+				// The test was not ready at this point; screw the hook this time
+				// but check again when needed next time.
+				return;
+			}
+
+			if ( condition ) {
+				// Hook not needed (or it's not possible to use it due to missing dependency),
+				// remove it.
+				// Since there are no other hooks for marginRight, remove the whole object.
+				delete this.get;
+				return;
+			}
+
+			// Hook needed; redefine it so that the support test is not executed again.
+
+			return (this.get = hookFn).apply( this, arguments );
+		}
+	};
+}
+
+
+(function() {
+	// Minified: var b,c,d,e,f,g, h,i
+	var div, style, a, pixelPositionVal, boxSizingReliableVal,
+		reliableHiddenOffsetsVal, reliableMarginRightVal;
+
+	// Setup
+	div = document.createElement( "div" );
+	div.innerHTML = "  <link/><table></table><a href='/a'>a</a><input type='checkbox'/>";
+	a = div.getElementsByTagName( "a" )[ 0 ];
+	style = a && a.style;
+
+	// Finish early in limited (non-browser) environments
+	if ( !style ) {
+		return;
+	}
+
+	style.cssText = "float:left;opacity:.5";
+
+	// Support: IE<9
+	// Make sure that element opacity exists (as opposed to filter)
+	support.opacity = style.opacity === "0.5";
+
+	// Verify style float existence
+	// (IE uses styleFloat instead of cssFloat)
+	support.cssFloat = !!style.cssFloat;
+
+	div.style.backgroundClip = "content-box";
+	div.cloneNode( true ).style.backgroundClip = "";
+	support.clearCloneStyle = div.style.backgroundClip === "content-box";
+
+	// Support: Firefox<29, Android 2.3
+	// Vendor-prefix box-sizing
+	support.boxSizing = style.boxSizing === "" || style.MozBoxSizing === "" ||
+		style.WebkitBoxSizing === "";
+
+	jQuery.extend(support, {
+		reliableHiddenOffsets: function() {
+			if ( reliableHiddenOffsetsVal == null ) {
+				computeStyleTests();
+			}
+			return reliableHiddenOffsetsVal;
+		},
+
+		boxSizingReliable: function() {
+			if ( boxSizingReliableVal == null ) {
+				computeStyleTests();
+			}
+			return boxSizingReliableVal;
+		},
+
+		pixelPosition: function() {
+			if ( pixelPositionVal == null ) {
+				computeStyleTests();
+			}
+			return pixelPositionVal;
+		},
+
+		// Support: Android 2.3
+		reliableMarginRight: function() {
+			if ( reliableMarginRightVal == null ) {
+				computeStyleTests();
+			}
+			return reliableMarginRightVal;
+		}
+	});
+
+	function computeStyleTests() {
+		// Minified: var b,c,d,j
+		var div, body, container, contents;
+
+		body = document.getElementsByTagName( "body" )[ 0 ];
+		if ( !body || !body.style ) {
+			// Test fired too early or in an unsupported environment, exit.
+			return;
+		}
+
+		// Setup
+		div = document.createElement( "div" );
+		container = document.createElement( "div" );
+		container.style.cssText = "position:absolute;border:0;width:0;height:0;top:0;left:-9999px";
+		body.appendChild( container ).appendChild( div );
+
+		div.style.cssText =
+			// Support: Firefox<29, Android 2.3
+			// Vendor-prefix box-sizing
+			"-webkit-box-sizing:border-box;-moz-box-sizing:border-box;" +
+			"box-sizing:border-box;display:block;margin-top:1%;top:1%;" +
+			"border:1px;padding:1px;width:4px;position:absolute";
+
+		// Support: IE<9
+		// Assume reasonable values in the absence of getComputedStyle
+		pixelPositionVal = boxSizingReliableVal = false;
+		reliableMarginRightVal = true;
+
+		// Check for getComputedStyle so that this code is not run in IE<9.
+		if ( window.getComputedStyle ) {
+			pixelPositionVal = ( window.getComputedStyle( div, null ) || {} ).top !== "1%";
+			boxSizingReliableVal =
+				( window.getComputedStyle( div, null ) || { width: "4px" } ).width === "4px";
+
+			// Support: Android 2.3
+			// Div with explicit width and no margin-right incorrectly
+			// gets computed margin-right based on width of container (#3333)
+			// WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
+			contents = div.appendChild( document.createElement( "div" ) );
+
+			// Reset CSS: box-sizing; display; margin; border; padding
+			contents.style.cssText = div.style.cssText =
+				// Support: Firefox<29, Android 2.3
+				// Vendor-prefix box-sizing
+				"-webkit-box-sizing:content-box;-moz-box-sizing:content-box;" +
+				"box-sizing:content-box;display:block;margin:0;border:0;padding:0";
+			contents.style.marginRight = contents.style.width = "0";
+			div.style.width = "1px";
+
+			reliableMarginRightVal =
+				!parseFloat( ( window.getComputedStyle( contents, null ) || {} ).marginRight );
+
+			div.removeChild( contents );
+		}
+
+		// Support: IE8
+		// Check if table cells still have offsetWidth/Height when they are set
+		// to display:none and there are still other visible table cells in a
+		// table row; if so, offsetWidth/Height are not reliable for use when
+		// determining if an element has been hidden directly using
+		// display:none (it is still safe to use offsets if a parent element is
+		// hidden; don safety goggles and see bug #4512 for more information).
+		div.innerHTML = "<table><tr><td></td><td>t</td></tr></table>";
+		contents = div.getElementsByTagName( "td" );
+		contents[ 0 ].style.cssText = "margin:0;border:0;padding:0;display:none";
+		reliableHiddenOffsetsVal = contents[ 0 ].offsetHeight === 0;
+		if ( reliableHiddenOffsetsVal ) {
+			contents[ 0 ].style.display = "";
+			contents[ 1 ].style.display = "none";
+			reliableHiddenOffsetsVal = contents[ 0 ].offsetHeight === 0;
+		}
+
+		body.removeChild( container );
+	}
+
+})();
+
+
+// A method for quickly swapping in/out CSS properties to get correct calculations.
+jQuery.swap = function( elem, options, callback, args ) {
+	var ret, name,
+		old = {};
+
+	// Remember the old values, and insert the new ones
+	for ( name in options ) {
+		old[ name ] = elem.style[ name ];
+		elem.style[ name ] = options[ name ];
+	}
+
+	ret = callback.apply( elem, args || [] );
+
+	// Revert the old values
+	for ( name in options ) {
+		elem.style[ name ] = old[ name ];
+	}
+
+	return ret;
+};
+
+
+var
+		ralpha = /alpha\([^)]*\)/i,
+	ropacity = /opacity\s*=\s*([^)]*)/,
+
+	// swappable if display is none or starts with table except "table", "table-cell", or "table-caption"
+	// see here for display values: https://developer.mozilla.org/en-US/docs/CSS/display
+	rdisplayswap = /^(none|table(?!-c[ea]).+)/,
+	rnumsplit = new RegExp( "^(" + pnum + ")(.*)$", "i" ),
+	rrelNum = new RegExp( "^([+-])=(" + pnum + ")", "i" ),
+
+	cssShow = { position: "absolute", visibility: "hidden", display: "block" },
+	cssNormalTransform = {
+		letterSpacing: "0",
+		fontWeight: "400"
+	},
+
+	cssPrefixes = [ "Webkit", "O", "Moz", "ms" ];
+
+
+// return a css property mapped to a potentially vendor prefixed property
+function vendorPropName( style, name ) {
+
+	// shortcut for names that are not vendor prefixed
+	if ( name in style ) {
+		return name;
+	}
+
+	// check for vendor prefixed names
+	var capName = name.charAt(0).toUpperCase() + name.slice(1),
+		origName = name,
+		i = cssPrefixes.length;
+
+	while ( i-- ) {
+		name = cssPrefixes[ i ] + capName;
+		if ( name in style ) {
+			return name;
+		}
+	}
+
+	return origName;
+}
+
+function showHide( elements, show ) {
+	var display, elem, hidden,
+		values = [],
+		index = 0,
+		length = elements.length;
+
+	for ( ; index < length; index++ ) {
+		elem = elements[ index ];
+		if ( !elem.style ) {
+			continue;
+		}
+
+		values[ index ] = jQuery._data( elem, "olddisplay" );
+		display = elem.style.display;
+		if ( show ) {
+			// Reset the inline display of this element to learn if it is
+			// being hidden by cascaded rules or not
+			if ( !values[ index ] && display === "none" ) {
+				elem.style.display = "";
+			}
+
+			// Set elements which have been overridden with display: none
+			// in a stylesheet to whatever the default browser style is
+			// for such an element
+			if ( elem.style.display === "" && isHidden( elem ) ) {
+				values[ index ] = jQuery._data( elem, "olddisplay", defaultDisplay(elem.nodeName) );
+			}
+		} else {
+			hidden = isHidden( elem );
+
+			if ( display && display !== "none" || !hidden ) {
+				jQuery._data( elem, "olddisplay", hidden ? display : jQuery.css( elem, "display" ) );
+			}
+		}
+	}
+
+	// Set the display of most of the elements in a second loop
+	// to avoid the constant reflow
+	for ( index = 0; index < length; index++ ) {
+		elem = elements[ index ];
+		if ( !elem.style ) {
+			continue;
+		}
+		if ( !show || elem.style.display === "none" || elem.style.display === "" ) {
+			elem.style.display = show ? values[ index ] || "" : "none";
+		}
+	}
+
+	return elements;
+}
+
+function setPositiveNumber( elem, value, subtract ) {
+	var matches = rnumsplit.exec( value );
+	return matches ?
+		// Guard against undefined "subtract", e.g., when used as in cssHooks
+		Math.max( 0, matches[ 1 ] - ( subtract || 0 ) ) + ( matches[ 2 ] || "px" ) :
+		value;
+}
+
+function augmentWidthOrHeight( elem, name, extra, isBorderBox, styles ) {
+	var i = extra === ( isBorderBox ? "border" : "content" ) ?
+		// If we already have the right measurement, avoid augmentation
+		4 :
+		// Otherwise initialize for horizontal or vertical properties
+		name === "width" ? 1 : 0,
+
+		val = 0;
+
+	for ( ; i < 4; i += 2 ) {
+		// both box models exclude margin, so add it if we want it
+		if ( extra === "margin" ) {
+			val += jQuery.css( elem, extra + cssExpand[ i ], true, styles );
+		}
+
+		if ( isBorderBox ) {
+			// border-box includes padding, so remove it if we want content
+			if ( extra === "content" ) {
+				val -= jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
+			}
+
+			// at this point, extra isn't border nor margin, so remove border
+			if ( extra !== "margin" ) {
+				val -= jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
+			}
+		} else {
+			// at this point, extra isn't content, so add padding
+			val += jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
+
+			// at this point, extra isn't content nor padding, so add border
+			if ( extra !== "padding" ) {
+				val += jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
+			}
+		}
+	}
+
+	return val;
+}
+
+function getWidthOrHeight( elem, name, extra ) {
+
+	// Start with offset property, which is equivalent to the border-box value
+	var valueIsBorderBox = true,
+		val = name === "width" ? elem.offsetWidth : elem.offsetHeight,
+		styles = getStyles( elem ),
+		isBorderBox = support.boxSizing && jQuery.css( elem, "boxSizing", false, styles ) === "border-box";
+
+	// some non-html elements return undefined for offsetWidth, so check for null/undefined
+	// svg - https://bugzilla.mozilla.org/show_bug.cgi?id=649285
+	// MathML - https://bugzilla.mozilla.org/show_bug.cgi?id=491668
+	if ( val <= 0 || val == null ) {
+		// Fall back to computed then uncomputed css if necessary
+		val = curCSS( elem, name, styles );
+		if ( val < 0 || val == null ) {
+			val = elem.style[ name ];
+		}
+
+		// Computed unit is not pixels. Stop here and return.
+		if ( rnumnonpx.test(val) ) {
+			return val;
+		}
+
+		// we need the check for style in case a browser which returns unreliable values
+		// for getComputedStyle silently falls back to the reliable elem.style
+		valueIsBorderBox = isBorderBox && ( support.boxSizingReliable() || val === elem.style[ name ] );
+
+		// Normalize "", auto, and prepare for extra
+		val = parseFloat( val ) || 0;
+	}
+
+	// use the active box-sizing model to add/subtract irrelevant styles
+	return ( val +
+		augmentWidthOrHeight(
+			elem,
+			name,
+			extra || ( isBorderBox ? "border" : "content" ),
+			valueIsBorderBox,
+			styles
+		)
+	) + "px";
+}
+
+jQuery.extend({
+	// Add in style property hooks for overriding the default
+	// behavior of getting and setting a style property
+	cssHooks: {
+		opacity: {
+			get: function( elem, computed ) {
+				if ( computed ) {
+					// We should always get a number back from opacity
+					var ret = curCSS( elem, "opacity" );
+					return ret === "" ? "1" : ret;
+				}
+			}
+		}
+	},
+
+	// Don't automatically add "px" to these possibly-unitless properties
+	cssNumber: {
+		"columnCount": true,
+		"fillOpacity": true,
+		"flexGrow": true,
+		"flexShrink": true,
+		"fontWeight": true,
+		"lineHeight": true,
+		"opacity": true,
+		"order": true,
+		"orphans": true,
+		"widows": true,
+		"zIndex": true,
+		"zoom": true
+	},
+
+	// Add in properties whose names you wish to fix before
+	// setting or getting the value
+	cssProps: {
+		// normalize float css property
+		"float": support.cssFloat ? "cssFloat" : "styleFloat"
+	},
+
+	// Get and set the style property on a DOM Node
+	style: function( elem, name, value, extra ) {
+		// Don't set styles on text and comment nodes
+		if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style ) {
+			return;
+		}
+
+		// Make sure that we're working with the right name
+		var ret, type, hooks,
+			origName = jQuery.camelCase( name ),
+			style = elem.style;
+
+		name = jQuery.cssProps[ origName ] || ( jQuery.cssProps[ origName ] = vendorPropName( style, origName ) );
+
+		// gets hook for the prefixed version
+		// followed by the unprefixed version
+		hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
+
+		// Check if we're setting a value
+		if ( value !== undefined ) {
+			type = typeof value;
+
+			// convert relative number strings (+= or -=) to relative numbers. #7345
+			if ( type === "string" && (ret = rrelNum.exec( value )) ) {
+				value = ( ret[1] + 1 ) * ret[2] + parseFloat( jQuery.css( elem, name ) );
+				// Fixes bug #9237
+				type = "number";
+			}
+
+			// Make sure that null and NaN values aren't set. See: #7116
+			if ( value == null || value !== value ) {
+				return;
+			}
+
+			// If a number was passed in, add 'px' to the (except for certain CSS properties)
+			if ( type === "number" && !jQuery.cssNumber[ origName ] ) {
+				value += "px";
+			}
+
+			// Fixes #8908, it can be done more correctly by specifing setters in cssHooks,
+			// but it would mean to define eight (for every problematic property) identical functions
+			if ( !support.clearCloneStyle && value === "" && name.indexOf("background") === 0 ) {
+				style[ name ] = "inherit";
+			}
+
+			// If a hook was provided, use that value, otherwise just set the specified value
+			if ( !hooks || !("set" in hooks) || (value = hooks.set( elem, value, extra )) !== undefined ) {
+
+				// Support: IE
+				// Swallow errors from 'invalid' CSS values (#5509)
+				try {
+					style[ name ] = value;
+				} catch(e) {}
+			}
+
+		} else {
+			// If a hook was provided get the non-computed value from there
+			if ( hooks && "get" in hooks && (ret = hooks.get( elem, false, extra )) !== undefined ) {
+				return ret;
+			}
+
+			// Otherwise just get the value from the style object
+			return style[ name ];
+		}
+	},
+
+	css: function( elem, name, extra, styles ) {
+		var num, val, hooks,
+			origName = jQuery.camelCase( name );
+
+		// Make sure that we're working with the right name
+		name = jQuery.cssProps[ origName ] || ( jQuery.cssProps[ origName ] = vendorPropName( elem.style, origName ) );
+
+		// gets hook for the prefixed version
+		// followed by the unprefixed version
+		hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
+
+		// If a hook was provided get the computed value from there
+		if ( hooks && "get" in hooks ) {
+			val = hooks.get( elem, true, extra );
+		}
+
+		// Otherwise, if a way to get the computed value exists, use that
+		if ( val === undefined ) {
+			val = curCSS( elem, name, styles );
+		}
+
+		//convert "normal" to computed value
+		if ( val === "normal" && name in cssNormalTransform ) {
+			val = cssNormalTransform[ name ];
+		}
+
+		// Return, converting to number if forced or a qualifier was provided and val looks numeric
+		if ( extra === "" || extra ) {
+			num = parseFloat( val );
+			return extra === true || jQuery.isNumeric( num ) ? num || 0 : val;
+		}
+		return val;
+	}
+});
+
+jQuery.each([ "height", "width" ], function( i, name ) {
+	jQuery.cssHooks[ name ] = {
+		get: function( elem, computed, extra ) {
+			if ( computed ) {
+				// certain elements can have dimension info if we invisibly show them
+				// however, it must have a current display style that would benefit from this
+				return rdisplayswap.test( jQuery.css( elem, "display" ) ) && elem.offsetWidth === 0 ?
+					jQuery.swap( elem, cssShow, function() {
+						return getWidthOrHeight( elem, name, extra );
+					}) :
+					getWidthOrHeight( elem, name, extra );
+			}
+		},
+
+		set: function( elem, value, extra ) {
+			var styles = extra && getStyles( elem );
+			return setPositiveNumber( elem, value, extra ?
+				augmentWidthOrHeight(
+					elem,
+					name,
+					extra,
+					support.boxSizing && jQuery.css( elem, "boxSizing", false, styles ) === "border-box",
+					styles
+				) : 0
+			);
+		}
+	};
+});
+
+if ( !support.opacity ) {
+	jQuery.cssHooks.opacity = {
+		get: function( elem, computed ) {
+			// IE uses filters for opacity
+			return ropacity.test( (computed && elem.currentStyle ? elem.currentStyle.filter : elem.style.filter) || "" ) ?
+				( 0.01 * parseFloat( RegExp.$1 ) ) + "" :
+				computed ? "1" : "";
+		},
+
+		set: function( elem, value ) {
+			var style = elem.style,
+				currentStyle = elem.currentStyle,
+				opacity = jQuery.isNumeric( value ) ? "alpha(opacity=" + value * 100 + ")" : "",
+				filter = currentStyle && currentStyle.filter || style.filter || "";
+
+			// IE has trouble with opacity if it does not have layout
+			// Force it by setting the zoom level
+			style.zoom = 1;
+
+			// if setting opacity to 1, and no other filters exist - attempt to remove filter attribute #6652
+			// if value === "", then remove inline opacity #12685
+			if ( ( value >= 1 || value === "" ) &&
+					jQuery.trim( filter.replace( ralpha, "" ) ) === "" &&
+					style.removeAttribute ) {
+
+				// Setting style.filter to null, "" & " " still leave "filter:" in the cssText
+				// if "filter:" is present at all, clearType is disabled, we want to avoid this
+				// style.removeAttribute is IE Only, but so apparently is this code path...
+				style.removeAttribute( "filter" );
+
+				// if there is no filter style applied in a css rule or unset inline opacity, we are done
+				if ( value === "" || currentStyle && !currentStyle.filter ) {
+					return;
+				}
+			}
+
+			// otherwise, set new filter values
+			style.filter = ralpha.test( filter ) ?
+				filter.replace( ralpha, opacity ) :
+				filter + " " + opacity;
+		}
+	};
+}
+
+jQuery.cssHooks.marginRight = addGetHookIf( support.reliableMarginRight,
+	function( elem, computed ) {
+		if ( computed ) {
+			// WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
+			// Work around by temporarily setting element display to inline-block
+			return jQuery.swap( elem, { "display": "inline-block" },
+				curCSS, [ elem, "marginRight" ] );
+		}
+	}
+);
+
+// These hooks are used by animate to expand properties
+jQuery.each({
+	margin: "",
+	padding: "",
+	border: "Width"
+}, function( prefix, suffix ) {
+	jQuery.cssHooks[ prefix + suffix ] = {
+		expand: function( value ) {
+			var i = 0,
+				expanded = {},
+
+				// assumes a single number if not a string
+				parts = typeof value === "string" ? value.split(" ") : [ value ];
+
+			for ( ; i < 4; i++ ) {
+				expanded[ prefix + cssExpand[ i ] + suffix ] =
+					parts[ i ] || parts[ i - 2 ] || parts[ 0 ];
+			}
+
+			return expanded;
+		}
+	};
+
+	if ( !rmargin.test( prefix ) ) {
+		jQuery.cssHooks[ prefix + suffix ].set = setPositiveNumber;
+	}
+});
+
+jQuery.fn.extend({
+	css: function( name, value ) {
+		return access( this, function( elem, name, value ) {
+			var styles, len,
+				map = {},
+				i = 0;
+
+			if ( jQuery.isArray( name ) ) {
+				styles = getStyles( elem );
+				len = name.length;
+
+				for ( ; i < len; i++ ) {
+					map[ name[ i ] ] = jQuery.css( elem, name[ i ], false, styles );
+				}
+
+				return map;
+			}
+
+			return value !== undefined ?
+				jQuery.style( elem, name, value ) :
+				jQuery.css( elem, name );
+		}, name, value, arguments.length > 1 );
+	},
+	show: function() {
+		return showHide( this, true );
+	},
+	hide: function() {
+		return showHide( this );
+	},
+	toggle: function( state ) {
+		if ( typeof state === "boolean" ) {
+			return state ? this.show() : this.hide();
+		}
+
+		return this.each(function() {
+			if ( isHidden( this ) ) {
+				jQuery( this ).show();
+			} else {
+				jQuery( this ).hide();
+			}
+		});
+	}
+});
+
+
+function Tween( elem, options, prop, end, easing ) {
+	return new Tween.prototype.init( elem, options, prop, end, easing );
+}
+jQuery.Tween = Tween;
+
+Tween.prototype = {
+	constructor: Tween,
+	init: function( elem, options, prop, end, easing, unit ) {
+		this.elem = elem;
+		this.prop = prop;
+		this.easing = easing || "swing";
+		this.options = options;
+		this.start = this.now = this.cur();
+		this.end = end;
+		this.unit = unit || ( jQuery.cssNumber[ prop ] ? "" : "px" );
+	},
+	cur: function() {
+		var hooks = Tween.propHooks[ this.prop ];
+
+		return hooks && hooks.get ?
+			hooks.get( this ) :
+			Tween.propHooks._default.get( this );
+	},
+	run: function( percent ) {
+		var eased,
+			hooks = Tween.propHooks[ this.prop ];
+
+		if ( this.options.duration ) {
+			this.pos = eased = jQuery.easing[ this.easing ](
+				percent, this.options.duration * percent, 0, 1, this.options.duration
+			);
+		} else {
+			this.pos = eased = percent;
+		}
+		this.now = ( this.end - this.start ) * eased + this.start;
+
+		if ( this.options.step ) {
+			this.options.step.call( this.elem, this.now, this );
+		}
+
+		if ( hooks && hooks.set ) {
+			hooks.set( this );
+		} else {
+			Tween.propHooks._default.set( this );
+		}
+		return this;
+	}
+};
+
+Tween.prototype.init.prototype = Tween.prototype;
+
+Tween.propHooks = {
+	_default: {
+		get: function( tween ) {
+			var result;
+
+			if ( tween.elem[ tween.prop ] != null &&
+				(!tween.elem.style || tween.elem.style[ tween.prop ] == null) ) {
+				return tween.elem[ tween.prop ];
+			}
+
+			// passing an empty string as a 3rd parameter to .css will automatically
+			// attempt a parseFloat and fallback to a string if the parse fails
+			// so, simple values such as "10px" are parsed to Float.
+			// complex values such as "rotate(1rad)" are returned as is.
+			result = jQuery.css( tween.elem, tween.prop, "" );
+			// Empty strings, null, undefined and "auto" are converted to 0.
+			return !result || result === "auto" ? 0 : result;
+		},
+		set: function( tween ) {
+			// use step hook for back compat - use cssHook if its there - use .style if its
+			// available and use plain properties where available
+			if ( jQuery.fx.step[ tween.prop ] ) {
+				jQuery.fx.step[ tween.prop ]( tween );
+			} else if ( tween.elem.style && ( tween.elem.style[ jQuery.cssProps[ tween.prop ] ] != null || jQuery.cssHooks[ tween.prop ] ) ) {
+				jQuery.style( tween.elem, tween.prop, tween.now + tween.unit );
+			} else {
+				tween.elem[ tween.prop ] = tween.now;
+			}
+		}
+	}
+};
+
+// Support: IE <=9
+// Panic based approach to setting things on disconnected nodes
+
+Tween.propHooks.scrollTop = Tween.propHooks.scrollLeft = {
+	set: function( tween ) {
+		if ( tween.elem.nodeType && tween.elem.parentNode ) {
+			tween.elem[ tween.prop ] = tween.now;
+		}
+	}
+};
+
+jQuery.easing = {
+	linear: function( p ) {
+		return p;
+	},
+	swing: function( p ) {
+		return 0.5 - Math.cos( p * Math.PI ) / 2;
+	}
+};
+
+jQuery.fx = Tween.prototype.init;
+
+// Back Compat <1.8 extension point
+jQuery.fx.step = {};
+
+
+
+
+var
+	fxNow, timerId,
+	rfxtypes = /^(?:toggle|show|hide)$/,
+	rfxnum = new RegExp( "^(?:([+-])=|)(" + pnum + ")([a-z%]*)$", "i" ),
+	rrun = /queueHooks$/,
+	animationPrefilters = [ defaultPrefilter ],
+	tweeners = {
+		"*": [ function( prop, value ) {
+			var tween = this.createTween( prop, value ),
+				target = tween.cur(),
+				parts = rfxnum.exec( value ),
+				unit = parts && parts[ 3 ] || ( jQuery.cssNumber[ prop ] ? "" : "px" ),
+
+				// Starting value computation is required for potential unit mismatches
+				start = ( jQuery.cssNumber[ prop ] || unit !== "px" && +target ) &&
+					rfxnum.exec( jQuery.css( tween.elem, prop ) ),
+				scale = 1,
+				maxIterations = 20;
+
+			if ( start && start[ 3 ] !== unit ) {
+				// Trust units reported by jQuery.css
+				unit = unit || start[ 3 ];
+
+				// Make sure we update the tween properties later on
+				parts = parts || [];
+
+				// Iteratively approximate from a nonzero starting point
+				start = +target || 1;
+
+				do {
+					// If previous iteration zeroed out, double until we get *something*
+					// Use a string for doubling factor so we don't accidentally see scale as unchanged below
+					scale = scale || ".5";
+
+					// Adjust and apply
+					start = start / scale;
+					jQuery.style( tween.elem, prop, start + unit );
+
+				// Update scale, tolerating zero or NaN from tween.cur()
+				// And breaking the loop if scale is unchanged or perfect, or if we've just had enough
+				} while ( scale !== (scale = tween.cur() / target) && scale !== 1 && --maxIterations );
+			}
+
+			// Update tween properties
+			if ( parts ) {
+				start = tween.start = +start || +target || 0;
+				tween.unit = unit;
+				// If a +=/-= token was provided, we're doing a relative animation
+				tween.end = parts[ 1 ] ?
+					start + ( parts[ 1 ] + 1 ) * parts[ 2 ] :
+					+parts[ 2 ];
+			}
+
+			return tween;
+		} ]
+	};
+
+// Animations created synchronously will run synchronously
+function createFxNow() {
+	setTimeout(function() {
+		fxNow = undefined;
+	});
+	return ( fxNow = jQuery.now() );
+}
+
+// Generate parameters to create a standard animation
+function genFx( type, includeWidth ) {
+	var which,
+		attrs = { height: type },
+		i = 0;
+
+	// if we include width, step value is 1 to do all cssExpand values,
+	// if we don't include width, step value is 2 to skip over Left and Right
+	includeWidth = includeWidth ? 1 : 0;
+	for ( ; i < 4 ; i += 2 - includeWidth ) {
+		which = cssExpand[ i ];
+		attrs[ "margin" + which ] = attrs[ "padding" + which ] = type;
+	}
+
+	if ( includeWidth ) {
+		attrs.opacity = attrs.width = type;
+	}
+
+	return attrs;
+}
+
+function createTween( value, prop, animation ) {
+	var tween,
+		collection = ( tweeners[ prop ] || [] ).concat( tweeners[ "*" ] ),
+		index = 0,
+		length = collection.length;
+	for ( ; index < length; index++ ) {
+		if ( (tween = collection[ index ].call( animation, prop, value )) ) {
+
+			// we're done with this property
+			return tween;
+		}
+	}
+}
+
+function defaultPrefilter( elem, props, opts ) {
+	/* jshint validthis: true */
+	var prop, value, toggle, tween, hooks, oldfire, display, checkDisplay,
+		anim = this,
+		orig = {},
+		style = elem.style,
+		hidden = elem.nodeType && isHidden( elem ),
+		dataShow = jQuery._data( elem, "fxshow" );
+
+	// handle queue: false promises
+	if ( !opts.queue ) {
+		hooks = jQuery._queueHooks( elem, "fx" );
+		if ( hooks.unqueued == null ) {
+			hooks.unqueued = 0;
+			oldfire = hooks.empty.fire;
+			hooks.empty.fire = function() {
+				if ( !hooks.unqueued ) {
+					oldfire();
+				}
+			};
+		}
+		hooks.unqueued++;
+
+		anim.always(function() {
+			// doing this makes sure that the complete handler will be called
+			// before this completes
+			anim.always(function() {
+				hooks.unqueued--;
+				if ( !jQuery.queue( elem, "fx" ).length ) {
+					hooks.empty.fire();
+				}
+			});
+		});
+	}
+
+	// height/width overflow pass
+	if ( elem.nodeType === 1 && ( "height" in props || "width" in props ) ) {
+		// Make sure that nothing sneaks out
+		// Record all 3 overflow attributes because IE does not
+		// change the overflow attribute when overflowX and
+		// overflowY are set to the same value
+		opts.overflow = [ style.overflow, style.overflowX, style.overflowY ];
+
+		// Set display property to inline-block for height/width
+		// animations on inline elements that are having width/height animated
+		display = jQuery.css( elem, "display" );
+
+		// Test default display if display is currently "none"
+		checkDisplay = display === "none" ?
+			jQuery._data( elem, "olddisplay" ) || defaultDisplay( elem.nodeName ) : display;
+
+		if ( checkDisplay === "inline" && jQuery.css( elem, "float" ) === "none" ) {
+
+			// inline-level elements accept inline-block;
+			// block-level elements need to be inline with layout
+			if ( !support.inlineBlockNeedsLayout || defaultDisplay( elem.nodeName ) === "inline" ) {
+				style.display = "inline-block";
+			} else {
+				style.zoom = 1;
+			}
+		}
+	}
+
+	if ( opts.overflow ) {
+		style.overflow = "hidden";
+		if ( !support.shrinkWrapBlocks() ) {
+			anim.always(function() {
+				style.overflow = opts.overflow[ 0 ];
+				style.overflowX = opts.overflow[ 1 ];
+				style.overflowY = opts.overflow[ 2 ];
+			});
+		}
+	}
+
+	// show/hide pass
+	for ( prop in props ) {
+		value = props[ prop ];
+		if ( rfxtypes.exec( value ) ) {
+			delete props[ prop ];
+			toggle = toggle || value === "toggle";
+			if ( value === ( hidden ? "hide" : "show" ) ) {
+
+				// If there is dataShow left over from a stopped hide or show and we are going to proceed with show, we should pretend to be hidden
+				if ( value === "show" && dataShow && dataShow[ prop ] !== undefined ) {
+					hidden = true;
+				} else {
+					continue;
+				}
+			}
+			orig[ prop ] = dataShow && dataShow[ prop ] || jQuery.style( elem, prop );
+
+		// Any non-fx value stops us from restoring the original display value
+		} else {
+			display = undefined;
+		}
+	}
+
+	if ( !jQuery.isEmptyObject( orig ) ) {
+		if ( dataShow ) {
+			if ( "hidden" in dataShow ) {
+				hidden = dataShow.hidden;
+			}
+		} else {
+			dataShow = jQuery._data( elem, "fxshow", {} );
+		}
+
+		// store state if its toggle - enables .stop().toggle() to "reverse"
+		if ( toggle ) {
+			dataShow.hidden = !hidden;
+		}
+		if ( hidden ) {
+			jQuery( elem ).show();
+		} else {
+			anim.done(function() {
+				jQuery( elem ).hide();
+			});
+		}
+		anim.done(function() {
+			var prop;
+			jQuery._removeData( elem, "fxshow" );
+			for ( prop in orig ) {
+				jQuery.style( elem, prop, orig[ prop ] );
+			}
+		});
+		for ( prop in orig ) {
+			tween = createTween( hidden ? dataShow[ prop ] : 0, prop, anim );
+
+			if ( !( prop in dataShow ) ) {
+				dataShow[ prop ] = tween.start;
+				if ( hidden ) {
+					tween.end = tween.start;
+					tween.start = prop === "width" || prop === "height" ? 1 : 0;
+				}
+			}
+		}
+
+	// If this is a noop like .hide().hide(), restore an overwritten display value
+	} else if ( (display === "none" ? defaultDisplay( elem.nodeName ) : display) === "inline" ) {
+		style.display = display;
+	}
+}
+
+function propFilter( props, specialEasing ) {
+	var index, name, easing, value, hooks;
+
+	// camelCase, specialEasing and expand cssHook pass
+	for ( index in props ) {
+		name = jQuery.camelCase( index );
+		easing = specialEasing[ name ];
+		value = props[ index ];
+		if ( jQuery.isArray( value ) ) {
+			easing = value[ 1 ];
+			value = props[ index ] = value[ 0 ];
+		}
+
+		if ( index !== name ) {
+			props[ name ] = value;
+			delete props[ index ];
+		}
+
+		hooks = jQuery.cssHooks[ name ];
+		if ( hooks && "expand" in hooks ) {
+			value = hooks.expand( value );
+			delete props[ name ];
+
+			// not quite $.extend, this wont overwrite keys already present.
+			// also - reusing 'index' from above because we have the correct "name"
+			for ( index in value ) {
+				if ( !( index in props ) ) {
+					props[ index ] = value[ index ];
+					specialEasing[ index ] = easing;
+				}
+			}
+		} else {
+			specialEasing[ name ] = easing;
+		}
+	}
+}
+
+function Animation( elem, properties, options ) {
+	var result,
+		stopped,
+		index = 0,
+		length = animationPrefilters.length,
+		deferred = jQuery.Deferred().always( function() {
+			// don't match elem in the :animated selector
+			delete tick.elem;
+		}),
+		tick = function() {
+			if ( stopped ) {
+				return false;
+			}
+			var currentTime = fxNow || createFxNow(),
+				remaining = Math.max( 0, animation.startTime + animation.duration - currentTime ),
+				// archaic crash bug won't allow us to use 1 - ( 0.5 || 0 ) (#12497)
+				temp = remaining / animation.duration || 0,
+				percent = 1 - temp,
+				index = 0,
+				length = animation.tweens.length;
+
+			for ( ; index < length ; index++ ) {
+				animation.tweens[ index ].run( percent );
+			}
+
+			deferred.notifyWith( elem, [ animation, percent, remaining ]);
+
+			if ( percent < 1 && length ) {
+				return remaining;
+			} else {
+				deferred.resolveWith( elem, [ animation ] );
+				return false;
+			}
+		},
+		animation = deferred.promise({
+			elem: elem,
+			props: jQuery.extend( {}, properties ),
+			opts: jQuery.extend( true, { specialEasing: {} }, options ),
+			originalProperties: properties,
+			originalOptions: options,
+			startTime: fxNow || createFxNow(),
+			duration: options.duration,
+			tweens: [],
+			createTween: function( prop, end ) {
+				var tween = jQuery.Tween( elem, animation.opts, prop, end,
+						animation.opts.specialEasing[ prop ] || animation.opts.easing );
+				animation.tweens.push( tween );
+				return tween;
+			},
+			stop: function( gotoEnd ) {
+				var index = 0,
+					// if we are going to the end, we want to run all the tweens
+					// otherwise we skip this part
+					length = gotoEnd ? animation.tweens.length : 0;
+				if ( stopped ) {
+					return this;
+				}
+				stopped = true;
+				for ( ; index < length ; index++ ) {
+					animation.tweens[ index ].run( 1 );
+				}
+
+				// resolve when we played the last frame
+				// otherwise, reject
+				if ( gotoEnd ) {
+					deferred.resolveWith( elem, [ animation, gotoEnd ] );
+				} else {
+					deferred.rejectWith( elem, [ animation, gotoEnd ] );
+				}
+				return this;
+			}
+		}),
+		props = animation.props;
+
+	propFilter( props, animation.opts.specialEasing );
+
+	for ( ; index < length ; index++ ) {
+		result = animationPrefilters[ index ].call( animation, elem, props, animation.opts );
+		if ( result ) {
+			return result;
+		}
+	}
+
+	jQuery.map( props, createTween, animation );
+
+	if ( jQuery.isFunction( animation.opts.start ) ) {
+		animation.opts.start.call( elem, animation );
+	}
+
+	jQuery.fx.timer(
+		jQuery.extend( tick, {
+			elem: elem,
+			anim: animation,
+			queue: animation.opts.queue
+		})
+	);
+
+	// attach callbacks from options
+	return animation.progress( animation.opts.progress )
+		.done( animation.opts.done, animation.opts.complete )
+		.fail( animation.opts.fail )
+		.always( animation.opts.always );
+}
+
+jQuery.Animation = jQuery.extend( Animation, {
+	tweener: function( props, callback ) {
+		if ( jQuery.isFunction( props ) ) {
+			callback = props;
+			props = [ "*" ];
+		} else {
+			props = props.split(" ");
+		}
+
+		var prop,
+			index = 0,
+			length = props.length;
+
+		for ( ; index < length ; index++ ) {
+			prop = props[ index ];
+			tweeners[ prop ] = tweeners[ prop ] || [];
+			tweeners[ prop ].unshift( callback );
+		}
+	},
+
+	prefilter: function( callback, prepend ) {
+		if ( prepend ) {
+			animationPrefilters.unshift( callback );
+		} else {
+			animationPrefilters.push( callback );
+		}
+	}
+});
+
+jQuery.speed = function( speed, easing, fn ) {
+	var opt = speed && typeof speed === "object" ? jQuery.extend( {}, speed ) : {
+		complete: fn || !fn && easing ||
+			jQuery.isFunction( speed ) && speed,
+		duration: speed,
+		easing: fn && easing || easing && !jQuery.isFunction( easing ) && easing
+	};
+
+	opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
+		opt.duration in jQuery.fx.speeds ? jQuery.fx.speeds[ opt.duration ] : jQuery.fx.speeds._default;
+
+	// normalize opt.queue - true/undefined/null -> "fx"
+	if ( opt.queue == null || opt.queue === true ) {
+		opt.queue = "fx";
+	}
+
+	// Queueing
+	opt.old = opt.complete;
+
+	opt.complete = function() {
+		if ( jQuery.isFunction( opt.old ) ) {
+			opt.old.call( this );
+		}
+
+		if ( opt.queue ) {
+			jQuery.dequeue( this, opt.queue );
+		}
+	};
+
+	return opt;
+};
+
+jQuery.fn.extend({
+	fadeTo: function( speed, to, easing, callback ) {
+
+		// show any hidden elements after setting opacity to 0
+		return this.filter( isHidden ).css( "opacity", 0 ).show()
+
+			// animate to the value specified
+			.end().animate({ opacity: to }, speed, easing, callback );
+	},
+	animate: function( prop, speed, easing, callback ) {
+		var empty = jQuery.isEmptyObject( prop ),
+			optall = jQuery.speed( speed, easing, callback ),
+			doAnimation = function() {
+				// Operate on a copy of prop so per-property easing won't be lost
+				var anim = Animation( this, jQuery.extend( {}, prop ), optall );
+
+				// Empty animations, or finishing resolves immediately
+				if ( empty || jQuery._data( this, "finish" ) ) {
+					anim.stop( true );
+				}
+			};
+			doAnimation.finish = doAnimation;
+
+		return empty || optall.queue === false ?
+			this.each( doAnimation ) :
+			this.queue( optall.queue, doAnimation );
+	},
+	stop: function( type, clearQueue, gotoEnd ) {
+		var stopQueue = function( hooks ) {
+			var stop = hooks.stop;
+			delete hooks.stop;
+			stop( gotoEnd );
+		};
+
+		if ( typeof type !== "string" ) {
+			gotoEnd = clearQueue;
+			clearQueue = type;
+			type = undefined;
+		}
+		if ( clearQueue && type !== false ) {
+			this.queue( type || "fx", [] );
+		}
+
+		return this.each(function() {
+			var dequeue = true,
+				index = type != null && type + "queueHooks",
+				timers = jQuery.timers,
+				data = jQuery._data( this );
+
+			if ( index ) {
+				if ( data[ index ] && data[ index ].stop ) {
+					stopQueue( data[ index ] );
+				}
+			} else {
+				for ( index in data ) {
+					if ( data[ index ] && data[ index ].stop && rrun.test( index ) ) {
+						stopQueue( data[ index ] );
+					}
+				}
+			}
+
+			for ( index = timers.length; index--; ) {
+				if ( timers[ index ].elem === this && (type == null || timers[ index ].queue === type) ) {
+					timers[ index ].anim.stop( gotoEnd );
+					dequeue = false;
+					timers.splice( index, 1 );
+				}
+			}
+
+			// start the next in the queue if the last step wasn't forced
+			// timers currently will call their complete callbacks, which will dequeue
+			// but only if they were gotoEnd
+			if ( dequeue || !gotoEnd ) {
+				jQuery.dequeue( this, type );
+			}
+		});
+	},
+	finish: function( type ) {
+		if ( type !== false ) {
+			type = type || "fx";
+		}
+		return this.each(function() {
+			var index,
+				data = jQuery._data( this ),
+				queue = data[ type + "queue" ],
+				hooks = data[ type + "queueHooks" ],
+				timers = jQuery.timers,
+				length = queue ? queue.length : 0;
+
+			// enable finishing flag on private data
+			data.finish = true;
+
+			// empty the queue first
+			jQuery.queue( this, type, [] );
+
+			if ( hooks && hooks.stop ) {
+				hooks.stop.call( this, true );
+			}
+
+			// look for any active animations, and finish them
+			for ( index = timers.length; index--; ) {
+				if ( timers[ index ].elem === this && timers[ index ].queue === type ) {
+					timers[ index ].anim.stop( true );
+					timers.splice( index, 1 );
+				}
+			}
+
+			// look for any animations in the old queue and finish them
+			for ( index = 0; index < length; index++ ) {
+				if ( queue[ index ] && queue[ index ].finish ) {
+					queue[ index ].finish.call( this );
+				}
+			}
+
+			// turn off finishing flag
+			delete data.finish;
+		});
+	}
+});
+
+jQuery.each([ "toggle", "show", "hide" ], function( i, name ) {
+	var cssFn = jQuery.fn[ name ];
+	jQuery.fn[ name ] = function( speed, easing, callback ) {
+		return speed == null || typeof speed === "boolean" ?
+			cssFn.apply( this, arguments ) :
+			this.animate( genFx( name, true ), speed, easing, callback );
+	};
+});
+
+// Generate shortcuts for custom animations
+jQuery.each({
+	slideDown: genFx("show"),
+	slideUp: genFx("hide"),
+	slideToggle: genFx("toggle"),
+	fadeIn: { opacity: "show" },
+	fadeOut: { opacity: "hide" },
+	fadeToggle: { opacity: "toggle" }
+}, function( name, props ) {
+	jQuery.fn[ name ] = function( speed, easing, callback ) {
+		return this.animate( props, speed, easing, callback );
+	};
+});
+
+jQuery.timers = [];
+jQuery.fx.tick = function() {
+	var timer,
+		timers = jQuery.timers,
+		i = 0;
+
+	fxNow = jQuery.now();
+
+	for ( ; i < timers.length; i++ ) {
+		timer = timers[ i ];
+		// Checks the timer has not already been removed
+		if ( !timer() && timers[ i ] === timer ) {
+			timers.splice( i--, 1 );
+		}
+	}
+
+	if ( !timers.length ) {
+		jQuery.fx.stop();
+	}
+	fxNow = undefined;
+};
+
+jQuery.fx.timer = function( timer ) {
+	jQuery.timers.push( timer );
+	if ( timer() ) {
+		jQuery.fx.start();
+	} else {
+		jQuery.timers.pop();
+	}
+};
+
+jQuery.fx.interval = 13;
+
+jQuery.fx.start = function() {
+	if ( !timerId ) {
+		timerId = setInterval( jQuery.fx.tick, jQuery.fx.interval );
+	}
+};
+
+jQuery.fx.stop = function() {
+	clearInterval( timerId );
+	timerId = null;
+};
+
+jQuery.fx.speeds = {
+	slow: 600,
+	fast: 200,
+	// Default speed
+	_default: 400
+};
+
+
+// Based off of the plugin by Clint Helfers, with permission.
+// http://blindsignals.com/index.php/2009/07/jquery-delay/
+jQuery.fn.delay = function( time, type ) {
+	time = jQuery.fx ? jQuery.fx.speeds[ time ] || time : time;
+	type = type || "fx";
+
+	return this.queue( type, function( next, hooks ) {
+		var timeout = setTimeout( next, time );
+		hooks.stop = function() {
+			clearTimeout( timeout );
+		};
+	});
+};
+
+
+(function() {
+	// Minified: var a,b,c,d,e
+	var input, div, select, a, opt;
+
+	// Setup
+	div = document.createElement( "div" );
+	div.setAttribute( "className", "t" );
+	div.innerHTML = "  <link/><table></table><a href='/a'>a</a><input type='checkbox'/>";
+	a = div.getElementsByTagName("a")[ 0 ];
+
+	// First batch of tests.
+	select = document.createElement("select");
+	opt = select.appendChild( document.createElement("option") );
+	input = div.getElementsByTagName("input")[ 0 ];
+
+	a.style.cssText = "top:1px";
+
+	// Test setAttribute on camelCase class. If it works, we need attrFixes when doing get/setAttribute (ie6/7)
+	support.getSetAttribute = div.className !== "t";
+
+	// Get the style information from getAttribute
+	// (IE uses .cssText instead)
+	support.style = /top/.test( a.getAttribute("style") );
+
+	// Make sure that URLs aren't manipulated
+	// (IE normalizes it by default)
+	support.hrefNormalized = a.getAttribute("href") === "/a";
+
+	// Check the default checkbox/radio value ("" on WebKit; "on" elsewhere)
+	support.checkOn = !!input.value;
+
+	// Make sure that a selected-by-default option has a working selected property.
+	// (WebKit defaults to false instead of true, IE too, if it's in an optgroup)
+	support.optSelected = opt.selected;
+
+	// Tests for enctype support on a form (#6743)
+	support.enctype = !!document.createElement("form").enctype;
+
+	// Make sure that the options inside disabled selects aren't marked as disabled
+	// (WebKit marks them as disabled)
+	select.disabled = true;
+	support.optDisabled = !opt.disabled;
+
+	// Support: IE8 only
+	// Check if we can trust getAttribute("value")
+	input = document.createElement( "input" );
+	input.setAttribute( "value", "" );
+	support.input = input.getAttribute( "value" ) === "";
+
+	// Check if an input maintains its value after becoming a radio
+	input.value = "t";
+	input.setAttribute( "type", "radio" );
+	support.radioValue = input.value === "t";
+})();
+
+
+var rreturn = /\r/g;
+
+jQuery.fn.extend({
+	val: function( value ) {
+		var hooks, ret, isFunction,
+			elem = this[0];
+
+		if ( !arguments.length ) {
+			if ( elem ) {
+				hooks = jQuery.valHooks[ elem.type ] || jQuery.valHooks[ elem.nodeName.toLowerCase() ];
+
+				if ( hooks && "get" in hooks && (ret = hooks.get( elem, "value" )) !== undefined ) {
+					return ret;
+				}
+
+				ret = elem.value;
+
+				return typeof ret === "string" ?
+					// handle most common string cases
+					ret.replace(rreturn, "") :
+					// handle cases where value is null/undef or number
+					ret == null ? "" : ret;
+			}
+
+			return;
+		}
+
+		isFunction = jQuery.isFunction( value );
+
+		return this.each(function( i ) {
+			var val;
+
+			if ( this.nodeType !== 1 ) {
+				return;
+			}
+
+			if ( isFunction ) {
+				val = value.call( this, i, jQuery( this ).val() );
+			} else {
+				val = value;
+			}
+
+			// Treat null/undefined as ""; convert numbers to string
+			if ( val == null ) {
+				val = "";
+			} else if ( typeof val === "number" ) {
+				val += "";
+			} else if ( jQuery.isArray( val ) ) {
+				val = jQuery.map( val, function( value ) {
+					return value == null ? "" : value + "";
+				});
+			}
+
+			hooks = jQuery.valHooks[ this.type ] || jQuery.valHooks[ this.nodeName.toLowerCase() ];
+
+			// If set returns undefined, fall back to normal setting
+			if ( !hooks || !("set" in hooks) || hooks.set( this, val, "value" ) === undefined ) {
+				this.value = val;
+			}
+		});
+	}
+});
+
+jQuery.extend({
+	valHooks: {
+		option: {
+			get: function( elem ) {
+				var val = jQuery.find.attr( elem, "value" );
+				return val != null ?
+					val :
+					// Support: IE10-11+
+					// option.text throws exceptions (#14686, #14858)
+					jQuery.trim( jQuery.text( elem ) );
+			}
+		},
+		select: {
+			get: function( elem ) {
+				var value, option,
+					options = elem.options,
+					index = elem.selectedIndex,
+					one = elem.type === "select-one" || index < 0,
+					values = one ? null : [],
+					max = one ? index + 1 : options.length,
+					i = index < 0 ?
+						max :
+						one ? index : 0;
+
+				// Loop through all the selected options
+				for ( ; i < max; i++ ) {
+					option = options[ i ];
+
+					// oldIE doesn't update selected after form reset (#2551)
+					if ( ( option.selected || i === index ) &&
+							// Don't return options that are disabled or in a disabled optgroup
+							( support.optDisabled ? !option.disabled : option.getAttribute("disabled") === null ) &&
+							( !option.parentNode.disabled || !jQuery.nodeName( option.parentNode, "optgroup" ) ) ) {
+
+						// Get the specific value for the option
+						value = jQuery( option ).val();
+
+						// We don't need an array for one selects
+						if ( one ) {
+							return value;
+						}
+
+						// Multi-Selects return an array
+						values.push( value );
+					}
+				}
+
+				return values;
+			},
+
+			set: function( elem, value ) {
+				var optionSet, option,
+					options = elem.options,
+					values = jQuery.makeArray( value ),
+					i = options.length;
+
+				while ( i-- ) {
+					option = options[ i ];
+
+					if ( jQuery.inArray( jQuery.valHooks.option.get( option ), values ) >= 0 ) {
+
+						// Support: IE6
+						// When new option element is added to select box we need to
+						// force reflow of newly added node in order to workaround delay
+						// of initialization properties
+						try {
+							option.selected = optionSet = true;
+
+						} catch ( _ ) {
+
+							// Will be executed only in IE6
+							option.scrollHeight;
+						}
+
+					} else {
+						option.selected = false;
+					}
+				}
+
+				// Force browsers to behave consistently when non-matching value is set
+				if ( !optionSet ) {
+					elem.selectedIndex = -1;
+				}
+
+				return options;
+			}
+		}
+	}
+});
+
+// Radios and checkboxes getter/setter
+jQuery.each([ "radio", "checkbox" ], function() {
+	jQuery.valHooks[ this ] = {
+		set: function( elem, value ) {
+			if ( jQuery.isArray( value ) ) {
+				return ( elem.checked = jQuery.inArray( jQuery(elem).val(), value ) >= 0 );
+			}
+		}
+	};
+	if ( !support.checkOn ) {
+		jQuery.valHooks[ this ].get = function( elem ) {
+			// Support: Webkit
+			// "" is returned instead of "on" if a value isn't specified
+			return elem.getAttribute("value") === null ? "on" : elem.value;
+		};
+	}
+});
+
+
+
+
+var nodeHook, boolHook,
+	attrHandle = jQuery.expr.attrHandle,
+	ruseDefault = /^(?:checked|selected)$/i,
+	getSetAttribute = support.getSetAttribute,
+	getSetInput = support.input;
+
+jQuery.fn.extend({
+	attr: function( name, value ) {
+		return access( this, jQuery.attr, name, value, arguments.length > 1 );
+	},
+
+	removeAttr: function( name ) {
+		return this.each(function() {
+			jQuery.removeAttr( this, name );
+		});
+	}
+});
+
+jQuery.extend({
+	attr: function( elem, name, value ) {
+		var hooks, ret,
+			nType = elem.nodeType;
+
+		// don't get/set attributes on text, comment and attribute nodes
+		if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
+			return;
+		}
+
+		// Fallback to prop when attributes are not supported
+		if ( typeof elem.getAttribute === strundefined ) {
+			return jQuery.prop( elem, name, value );
+		}
+
+		// All attributes are lowercase
+		// Grab necessary hook if one is defined
+		if ( nType !== 1 || !jQuery.isXMLDoc( elem ) ) {
+			name = name.toLowerCase();
+			hooks = jQuery.attrHooks[ name ] ||
+				( jQuery.expr.match.bool.test( name ) ? boolHook : nodeHook );
+		}
+
+		if ( value !== undefined ) {
+
+			if ( value === null ) {
+				jQuery.removeAttr( elem, name );
+
+			} else if ( hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ) {
+				return ret;
+
+			} else {
+				elem.setAttribute( name, value + "" );
+				return value;
+			}
+
+		} else if ( hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ) {
+			return ret;
+
+		} else {
+			ret = jQuery.find.attr( elem, name );
+
+			// Non-existent attributes return null, we normalize to undefined
+			return ret == null ?
+				undefined :
+				ret;
+		}
+	},
+
+	removeAttr: function( elem, value ) {
+		var name, propName,
+			i = 0,
+			attrNames = value && value.match( rnotwhite );
+
+		if ( attrNames && elem.nodeType === 1 ) {
+			while ( (name = attrNames[i++]) ) {
+				propName = jQuery.propFix[ name ] || name;
+
+				// Boolean attributes get special treatment (#10870)
+				if ( jQuery.expr.match.bool.test( name ) ) {
+					// Set corresponding property to false
+					if ( getSetInput && getSetAttribute || !ruseDefault.test( name ) ) {
+						elem[ propName ] = false;
+					// Support: IE<9
+					// Also clear defaultChecked/defaultSelected (if appropriate)
+					} else {
+						elem[ jQuery.camelCase( "default-" + name ) ] =
+							elem[ propName ] = false;
+					}
+
+				// See #9699 for explanation of this approach (setting first, then removal)
+				} else {
+					jQuery.attr( elem, name, "" );
+				}
+
+				elem.removeAttribute( getSetAttribute ? name : propName );
+			}
+		}
+	},
+
+	attrHooks: {
+		type: {
+			set: function( elem, value ) {
+				if ( !support.radioValue && value === "radio" && jQuery.nodeName(elem, "input") ) {
+					// Setting the type on a radio button after the value resets the value in IE6-9
+					// Reset value to default in case type is set after value during creation
+					var val = elem.value;
+					elem.setAttribute( "type", value );
+					if ( val ) {
+						elem.value = val;
+					}
+					return value;
+				}
+			}
+		}
+	}
+});
+
+// Hook for boolean attributes
+boolHook = {
+	set: function( elem, value, name ) {
+		if ( value === false ) {
+			// Remove boolean attributes when set to false
+			jQuery.removeAttr( elem, name );
+		} else if ( getSetInput && getSetAttribute || !ruseDefault.test( name ) ) {
+			// IE<8 needs the *property* name
+			elem.setAttribute( !getSetAttribute && jQuery.propFix[ name ] || name, name );
+
+		// Use defaultChecked and defaultSelected for oldIE
+		} else {
+			elem[ jQuery.camelCase( "default-" + name ) ] = elem[ name ] = true;
+		}
+
+		return name;
+	}
+};
+
+// Retrieve booleans specially
+jQuery.each( jQuery.expr.match.bool.source.match( /\w+/g ), function( i, name ) {
+
+	var getter = attrHandle[ name ] || jQuery.find.attr;
+
+	attrHandle[ name ] = getSetInput && getSetAttribute || !ruseDefault.test( name ) ?
+		function( elem, name, isXML ) {
+			var ret, handle;
+			if ( !isXML ) {
+				// Avoid an infinite loop by temporarily removing this function from the getter
+				handle = attrHandle[ name ];
+				attrHandle[ name ] = ret;
+				ret = getter( elem, name, isXML ) != null ?
+					name.toLowerCase() :
+					null;
+				attrHandle[ name ] = handle;
+			}
+			return ret;
+		} :
+		function( elem, name, isXML ) {
+			if ( !isXML ) {
+				return elem[ jQuery.camelCase( "default-" + name ) ] ?
+					name.toLowerCase() :
+					null;
+			}
+		};
+});
+
+// fix oldIE attroperties
+if ( !getSetInput || !getSetAttribute ) {
+	jQuery.attrHooks.value = {
+		set: function( elem, value, name ) {
+			if ( jQuery.nodeName( elem, "input" ) ) {
+				// Does not return so that setAttribute is also used
+				elem.defaultValue = value;
+			} else {
+				// Use nodeHook if defined (#1954); otherwise setAttribute is fine
+				return nodeHook && nodeHook.set( elem, value, name );
+			}
+		}
+	};
+}
+
+// IE6/7 do not support getting/setting some attributes with get/setAttribute
+if ( !getSetAttribute ) {
+
+	// Use this for any attribute in IE6/7
+	// This fixes almost every IE6/7 issue
+	nodeHook = {
+		set: function( elem, value, name ) {
+			// Set the existing or create a new attribute node
+			var ret = elem.getAttributeNode( name );
+			if ( !ret ) {
+				elem.setAttributeNode(
+					(ret = elem.ownerDocument.createAttribute( name ))
+				);
+			}
+
+			ret.value = value += "";
+
+			// Break association with cloned elements by also using setAttribute (#9646)
+			if ( name === "value" || value === elem.getAttribute( name ) ) {
+				return value;
+			}
+		}
+	};
+
+	// Some attributes are constructed with empty-string values when not defined
+	attrHandle.id = attrHandle.name = attrHandle.coords =
+		function( elem, name, isXML ) {
+			var ret;
+			if ( !isXML ) {
+				return (ret = elem.getAttributeNode( name )) && ret.value !== "" ?
+					ret.value :
+					null;
+			}
+		};
+
+	// Fixing value retrieval on a button requires this module
+	jQuery.valHooks.button = {
+		get: function( elem, name ) {
+			var ret = elem.getAttributeNode( name );
+			if ( ret && ret.specified ) {
+				return ret.value;
+			}
+		},
+		set: nodeHook.set
+	};
+
+	// Set contenteditable to false on removals(#10429)
+	// Setting to empty string throws an error as an invalid value
+	jQuery.attrHooks.contenteditable = {
+		set: function( elem, value, name ) {
+			nodeHook.set( elem, value === "" ? false : value, name );
+		}
+	};
+
+	// Set width and height to auto instead of 0 on empty string( Bug #8150 )
+	// This is for removals
+	jQuery.each([ "width", "height" ], function( i, name ) {
+		jQuery.attrHooks[ name ] = {
+			set: function( elem, value ) {
+				if ( value === "" ) {
+					elem.setAttribute( name, "auto" );
+					return value;
+				}
+			}
+		};
+	});
+}
+
+if ( !support.style ) {
+	jQuery.attrHooks.style = {
+		get: function( elem ) {
+			// Return undefined in the case of empty string
+			// Note: IE uppercases css property names, but if we were to .toLowerCase()
+			// .cssText, that would destroy case senstitivity in URL's, like in "background"
+			return elem.style.cssText || undefined;
+		},
+		set: function( elem, value ) {
+			return ( elem.style.cssText = value + "" );
+		}
+	};
+}
+
+
+
+
+var rfocusable = /^(?:input|select|textarea|button|object)$/i,
+	rclickable = /^(?:a|area)$/i;
+
+jQuery.fn.extend({
+	prop: function( name, value ) {
+		return access( this, jQuery.prop, name, value, arguments.length > 1 );
+	},
+
+	removeProp: function( name ) {
+		name = jQuery.propFix[ name ] || name;
+		return this.each(function() {
+			// try/catch handles cases where IE balks (such as removing a property on window)
+			try {
+				this[ name ] = undefined;
+				delete this[ name ];
+			} catch( e ) {}
+		});
+	}
+});
+
+jQuery.extend({
+	propFix: {
+		"for": "htmlFor",
+		"class": "className"
+	},
+
+	prop: function( elem, name, value ) {
+		var ret, hooks, notxml,
+			nType = elem.nodeType;
+
+		// don't get/set properties on text, comment and attribute nodes
+		if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
+			return;
+		}
+
+		notxml = nType !== 1 || !jQuery.isXMLDoc( elem );
+
+		if ( notxml ) {
+			// Fix name and attach hooks
+			name = jQuery.propFix[ name ] || name;
+			hooks = jQuery.propHooks[ name ];
+		}
+
+		if ( value !== undefined ) {
+			return hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ?
+				ret :
+				( elem[ name ] = value );
+
+		} else {
+			return hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ?
+				ret :
+				elem[ name ];
+		}
+	},
+
+	propHooks: {
+		tabIndex: {
+			get: function( elem ) {
+				// elem.tabIndex doesn't always return the correct value when it hasn't been explicitly set
+				// http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/
+				// Use proper attribute retrieval(#12072)
+				var tabindex = jQuery.find.attr( elem, "tabindex" );
+
+				return tabindex ?
+					parseInt( tabindex, 10 ) :
+					rfocusable.test( elem.nodeName ) || rclickable.test( elem.nodeName ) && elem.href ?
+						0 :
+						-1;
+			}
+		}
+	}
+});
+
+// Some attributes require a special call on IE
+// http://msdn.microsoft.com/en-us/library/ms536429%28VS.85%29.aspx
+if ( !support.hrefNormalized ) {
+	// href/src property should get the full normalized URL (#10299/#12915)
+	jQuery.each([ "href", "src" ], function( i, name ) {
+		jQuery.propHooks[ name ] = {
+			get: function( elem ) {
+				return elem.getAttribute( name, 4 );
+			}
+		};
+	});
+}
+
+// Support: Safari, IE9+
+// mis-reports the default selected property of an option
+// Accessing the parent's selectedIndex property fixes it
+if ( !support.optSelected ) {
+	jQuery.propHooks.selected = {
+		get: function( elem ) {
+			var parent = elem.parentNode;
+
+			if ( parent ) {
+				parent.selectedIndex;
+
+				// Make sure that it also works with optgroups, see #5701
+				if ( parent.parentNode ) {
+					parent.parentNode.selectedIndex;
+				}
+			}
+			return null;
+		}
+	};
+}
+
+jQuery.each([
+	"tabIndex",
+	"readOnly",
+	"maxLength",
+	"cellSpacing",
+	"cellPadding",
+	"rowSpan",
+	"colSpan",
+	"useMap",
+	"frameBorder",
+	"contentEditable"
+], function() {
+	jQuery.propFix[ this.toLowerCase() ] = this;
+});
+
+// IE6/7 call enctype encoding
+if ( !support.enctype ) {
+	jQuery.propFix.enctype = "encoding";
+}
+
+
+
+
+var rclass = /[\t\r\n\f]/g;
+
+jQuery.fn.extend({
+	addClass: function( value ) {
+		var classes, elem, cur, clazz, j, finalValue,
+			i = 0,
+			len = this.length,
+			proceed = typeof value === "string" && value;
+
+		if ( jQuery.isFunction( value ) ) {
+			return this.each(function( j ) {
+				jQuery( this ).addClass( value.call( this, j, this.className ) );
+			});
+		}
+
+		if ( proceed ) {
+			// The disjunction here is for better compressibility (see removeClass)
+			classes = ( value || "" ).match( rnotwhite ) || [];
+
+			for ( ; i < len; i++ ) {
+				elem = this[ i ];
+				cur = elem.nodeType === 1 && ( elem.className ?
+					( " " + elem.className + " " ).replace( rclass, " " ) :
+					" "
+				);
+
+				if ( cur ) {
+					j = 0;
+					while ( (clazz = classes[j++]) ) {
+						if ( cur.indexOf( " " + clazz + " " ) < 0 ) {
+							cur += clazz + " ";
+						}
+					}
+
+					// only assign if different to avoid unneeded rendering.
+					finalValue = jQuery.trim( cur );
+					if ( elem.className !== finalValue ) {
+						elem.className = finalValue;
+					}
+				}
+			}
+		}
+
+		return this;
+	},
+
+	removeClass: function( value ) {
+		var classes, elem, cur, clazz, j, finalValue,
+			i = 0,
+			len = this.length,
+			proceed = arguments.length === 0 || typeof value === "string" && value;
+
+		if ( jQuery.isFunction( value ) ) {
+			return this.each(function( j ) {
+				jQuery( this ).removeClass( value.call( this, j, this.className ) );
+			});
+		}
+		if ( proceed ) {
+			classes = ( value || "" ).match( rnotwhite ) || [];
+
+			for ( ; i < len; i++ ) {
+				elem = this[ i ];
+				// This expression is here for better compressibility (see addClass)
+				cur = elem.nodeType === 1 && ( elem.className ?
+					( " " + elem.className + " " ).replace( rclass, " " ) :
+					""
+				);
+
+				if ( cur ) {
+					j = 0;
+					while ( (clazz = classes[j++]) ) {
+						// Remove *all* instances
+						while ( cur.indexOf( " " + clazz + " " ) >= 0 ) {
+							cur = cur.replace( " " + clazz + " ", " " );
+						}
+					}
+
+					// only assign if different to avoid unneeded rendering.
+					finalValue = value ? jQuery.trim( cur ) : "";
+					if ( elem.className !== finalValue ) {
+						elem.className = finalValue;
+					}
+				}
+			}
+		}
+
+		return this;
+	},
+
+	toggleClass: function( value, stateVal ) {
+		var type = typeof value;
+
+		if ( typeof stateVal === "boolean" && type === "string" ) {
+			return stateVal ? this.addClass( value ) : this.removeClass( value );
+		}
+
+		if ( jQuery.isFunction( value ) ) {
+			return this.each(function( i ) {
+				jQuery( this ).toggleClass( value.call(this, i, this.className, stateVal), stateVal );
+			});
+		}
+
+		return this.each(function() {
+			if ( type === "string" ) {
+				// toggle individual class names
+				var className,
+					i = 0,
+					self = jQuery( this ),
+					classNames = value.match( rnotwhite ) || [];
+
+				while ( (className = classNames[ i++ ]) ) {
+					// check each className given, space separated list
+					if ( self.hasClass( className ) ) {
+						self.removeClass( className );
+					} else {
+						self.addClass( className );
+					}
+				}
+
+			// Toggle whole class name
+			} else if ( type === strundefined || type === "boolean" ) {
+				if ( this.className ) {
+					// store className if set
+					jQuery._data( this, "__className__", this.className );
+				}
+
+				// If the element has a class name or if we're passed "false",
+				// then remove the whole classname (if there was one, the above saved it).
+				// Otherwise bring back whatever was previously saved (if anything),
+				// falling back to the empty string if nothing was stored.
+				this.className = this.className || value === false ? "" : jQuery._data( this, "__className__" ) || "";
+			}
+		});
+	},
+
+	hasClass: function( selector ) {
+		var className = " " + selector + " ",
+			i = 0,
+			l = this.length;
+		for ( ; i < l; i++ ) {
+			if ( this[i].nodeType === 1 && (" " + this[i].className + " ").replace(rclass, " ").indexOf( className ) >= 0 ) {
+				return true;
+			}
+		}
+
+		return false;
+	}
+});
+
+
+
+
+// Return jQuery for attributes-only inclusion
+
+
+jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblclick " +
+	"mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " +
+	"change select submit keydown keypress keyup error contextmenu").split(" "), function( i, name ) {
+
+	// Handle event binding
+	jQuery.fn[ name ] = function( data, fn ) {
+		return arguments.length > 0 ?
+			this.on( name, null, data, fn ) :
+			this.trigger( name );
+	};
+});
+
+jQuery.fn.extend({
+	hover: function( fnOver, fnOut ) {
+		return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver );
+	},
+
+	bind: function( types, data, fn ) {
+		return this.on( types, null, data, fn );
+	},
+	unbind: function( types, fn ) {
+		return this.off( types, null, fn );
+	},
+
+	delegate: function( selector, types, data, fn ) {
+		return this.on( types, selector, data, fn );
+	},
+	undelegate: function( selector, types, fn ) {
+		// ( namespace ) or ( selector, types [, fn] )
+		return arguments.length === 1 ? this.off( selector, "**" ) : this.off( types, selector || "**", fn );
+	}
+});
+
+
+var nonce = jQuery.now();
+
+var rquery = (/\?/);
+
+
+
+var rvalidtokens = /(,)|(\[|{)|(}|])|"(?:[^"\\\r\n]|\\["\\\/bfnrt]|\\u[\da-fA-F]{4})*"\s*:?|true|false|null|-?(?!0\d)\d+(?:\.\d+|)(?:[eE][+-]?\d+|)/g;
+
+jQuery.parseJSON = function( data ) {
+	// Attempt to parse using the native JSON parser first
+	if ( window.JSON && window.JSON.parse ) {
+		// Support: Android 2.3
+		// Workaround failure to string-cast null input
+		return window.JSON.parse( data + "" );
+	}
+
+	var requireNonComma,
+		depth = null,
+		str = jQuery.trim( data + "" );
+
+	// Guard against invalid (and possibly dangerous) input by ensuring that nothing remains
+	// after removing valid tokens
+	return str && !jQuery.trim( str.replace( rvalidtokens, function( token, comma, open, close ) {
+
+		// Force termination if we see a misplaced comma
+		if ( requireNonComma && comma ) {
+			depth = 0;
+		}
+
+		// Perform no more replacements after returning to outermost depth
+		if ( depth === 0 ) {
+			return token;
+		}
+
+		// Commas must not follow "[", "{", or ","
+		requireNonComma = open || comma;
+
+		// Determine new depth
+		// array/object open ("[" or "{"): depth += true - false (increment)
+		// array/object close ("]" or "}"): depth += false - true (decrement)
+		// other cases ("," or primitive): depth += true - true (numeric cast)
+		depth += !close - !open;
+
+		// Remove this token
+		return "";
+	}) ) ?
+		( Function( "return " + str ) )() :
+		jQuery.error( "Invalid JSON: " + data );
+};
+
+
+// Cross-browser xml parsing
+jQuery.parseXML = function( data ) {
+	var xml, tmp;
+	if ( !data || typeof data !== "string" ) {
+		return null;
+	}
+	try {
+		if ( window.DOMParser ) { // Standard
+			tmp = new DOMParser();
+			xml = tmp.parseFromString( data, "text/xml" );
+		} else { // IE
+			xml = new ActiveXObject( "Microsoft.XMLDOM" );
+			xml.async = "false";
+			xml.loadXML( data );
+		}
+	} catch( e ) {
+		xml = undefined;
+	}
+	if ( !xml || !xml.documentElement || xml.getElementsByTagName( "parsererror" ).length ) {
+		jQuery.error( "Invalid XML: " + data );
+	}
+	return xml;
+};
+
+
+var
+	// Document location
+	ajaxLocParts,
+	ajaxLocation,
+
+	rhash = /#.*$/,
+	rts = /([?&])_=[^&]*/,
+	rheaders = /^(.*?):[ \t]*([^\r\n]*)\r?$/mg, // IE leaves an \r character at EOL
+	// #7653, #8125, #8152: local protocol detection
+	rlocalProtocol = /^(?:about|app|app-storage|.+-extension|file|res|widget):$/,
+	rnoContent = /^(?:GET|HEAD)$/,
+	rprotocol = /^\/\//,
+	rurl = /^([\w.+-]+:)(?:\/\/(?:[^\/?#]*@|)([^\/?#:]*)(?::(\d+)|)|)/,
+
+	/* Prefilters
+	 * 1) They are useful to introduce custom dataTypes (see ajax/jsonp.js for an example)
+	 * 2) These are called:
+	 *    - BEFORE asking for a transport
+	 *    - AFTER param serialization (s.data is a string if s.processData is true)
+	 * 3) key is the dataType
+	 * 4) the catchall symbol "*" can be used
+	 * 5) execution will start with transport dataType and THEN continue down to "*" if needed
+	 */
+	prefilters = {},
+
+	/* Transports bindings
+	 * 1) key is the dataType
+	 * 2) the catchall symbol "*" can be used
+	 * 3) selection will start with transport dataType and THEN go to "*" if needed
+	 */
+	transports = {},
+
+	// Avoid comment-prolog char sequence (#10098); must appease lint and evade compression
+	allTypes = "*/".concat("*");
+
+// #8138, IE may throw an exception when accessing
+// a field from window.location if document.domain has been set
+try {
+	ajaxLocation = location.href;
+} catch( e ) {
+	// Use the href attribute of an A element
+	// since IE will modify it given document.location
+	ajaxLocation = document.createElement( "a" );
+	ajaxLocation.href = "";
+	ajaxLocation = ajaxLocation.href;
+}
+
+// Segment location into parts
+ajaxLocParts = rurl.exec( ajaxLocation.toLowerCase() ) || [];
+
+// Base "constructor" for jQuery.ajaxPrefilter and jQuery.ajaxTransport
+function addToPrefiltersOrTransports( structure ) {
+
+	// dataTypeExpression is optional and defaults to "*"
+	return function( dataTypeExpression, func ) {
+
+		if ( typeof dataTypeExpression !== "string" ) {
+			func = dataTypeExpression;
+			dataTypeExpression = "*";
+		}
+
+		var dataType,
+			i = 0,
+			dataTypes = dataTypeExpression.toLowerCase().match( rnotwhite ) || [];
+
+		if ( jQuery.isFunction( func ) ) {
+			// For each dataType in the dataTypeExpression
+			while ( (dataType = dataTypes[i++]) ) {
+				// Prepend if requested
+				if ( dataType.charAt( 0 ) === "+" ) {
+					dataType = dataType.slice( 1 ) || "*";
+					(structure[ dataType ] = structure[ dataType ] || []).unshift( func );
+
+				// Otherwise append
+				} else {
+					(structure[ dataType ] = structure[ dataType ] || []).push( func );
+				}
+			}
+		}
+	};
+}
+
+// Base inspection function for prefilters and transports
+function inspectPrefiltersOrTransports( structure, options, originalOptions, jqXHR ) {
+
+	var inspected = {},
+		seekingTransport = ( structure === transports );
+
+	function inspect( dataType ) {
+		var selected;
+		inspected[ dataType ] = true;
+		jQuery.each( structure[ dataType ] || [], function( _, prefilterOrFactory ) {
+			var dataTypeOrTransport = prefilterOrFactory( options, originalOptions, jqXHR );
+			if ( typeof dataTypeOrTransport === "string" && !seekingTransport && !inspected[ dataTypeOrTransport ] ) {
+				options.dataTypes.unshift( dataTypeOrTransport );
+				inspect( dataTypeOrTransport );
+				return false;
+			} else if ( seekingTransport ) {
+				return !( selected = dataTypeOrTransport );
+			}
+		});
+		return selected;
+	}
+
+	return inspect( options.dataTypes[ 0 ] ) || !inspected[ "*" ] && inspect( "*" );
+}
+
+// A special extend for ajax options
+// that takes "flat" options (not to be deep extended)
+// Fixes #9887
+function ajaxExtend( target, src ) {
+	var deep, key,
+		flatOptions = jQuery.ajaxSettings.flatOptions || {};
+
+	for ( key in src ) {
+		if ( src[ key ] !== undefined ) {
+			( flatOptions[ key ] ? target : ( deep || (deep = {}) ) )[ key ] = src[ key ];
+		}
+	}
+	if ( deep ) {
+		jQuery.extend( true, target, deep );
+	}
+
+	return target;
+}
+
+/* Handles responses to an ajax request:
+ * - finds the right dataType (mediates between content-type and expected dataType)
+ * - returns the corresponding response
+ */
+function ajaxHandleResponses( s, jqXHR, responses ) {
+	var firstDataType, ct, finalDataType, type,
+		contents = s.contents,
+		dataTypes = s.dataTypes;
+
+	// Remove auto dataType and get content-type in the process
+	while ( dataTypes[ 0 ] === "*" ) {
+		dataTypes.shift();
+		if ( ct === undefined ) {
+			ct = s.mimeType || jqXHR.getResponseHeader("Content-Type");
+		}
+	}
+
+	// Check if we're dealing with a known content-type
+	if ( ct ) {
+		for ( type in contents ) {
+			if ( contents[ type ] && contents[ type ].test( ct ) ) {
+				dataTypes.unshift( type );
+				break;
+			}
+		}
+	}
+
+	// Check to see if we have a response for the expected dataType
+	if ( dataTypes[ 0 ] in responses ) {
+		finalDataType = dataTypes[ 0 ];
+	} else {
+		// Try convertible dataTypes
+		for ( type in responses ) {
+			if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[0] ] ) {
+				finalDataType = type;
+				break;
+			}
+			if ( !firstDataType ) {
+				firstDataType = type;
+			}
+		}
+		// Or just use first one
+		finalDataType = finalDataType || firstDataType;
+	}
+
+	// If we found a dataType
+	// We add the dataType to the list if needed
+	// and return the corresponding response
+	if ( finalDataType ) {
+		if ( finalDataType !== dataTypes[ 0 ] ) {
+			dataTypes.unshift( finalDataType );
+		}
+		return responses[ finalDataType ];
+	}
+}
+
+/* Chain conversions given the request and the original response
+ * Also sets the responseXXX fields on the jqXHR instance
+ */
+function ajaxConvert( s, response, jqXHR, isSuccess ) {
+	var conv2, current, conv, tmp, prev,
+		converters = {},
+		// Work with a copy of dataTypes in case we need to modify it for conversion
+		dataTypes = s.dataTypes.slice();
+
+	// Create converters map with lowercased keys
+	if ( dataTypes[ 1 ] ) {
+		for ( conv in s.converters ) {
+			converters[ conv.toLowerCase() ] = s.converters[ conv ];
+		}
+	}
+
+	current = dataTypes.shift();
+
+	// Convert to each sequential dataType
+	while ( current ) {
+
+		if ( s.responseFields[ current ] ) {
+			jqXHR[ s.responseFields[ current ] ] = response;
+		}
+
+		// Apply the dataFilter if provided
+		if ( !prev && isSuccess && s.dataFilter ) {
+			response = s.dataFilter( response, s.dataType );
+		}
+
+		prev = current;
+		current = dataTypes.shift();
+
+		if ( current ) {
+
+			// There's only work to do if current dataType is non-auto
+			if ( current === "*" ) {
+
+				current = prev;
+
+			// Convert response if prev dataType is non-auto and differs from current
+			} else if ( prev !== "*" && prev !== current ) {
+
+				// Seek a direct converter
+				conv = converters[ prev + " " + current ] || converters[ "* " + current ];
+
+				// If none found, seek a pair
+				if ( !conv ) {
+					for ( conv2 in converters ) {
+
+						// If conv2 outputs current
+						tmp = conv2.split( " " );
+						if ( tmp[ 1 ] === current ) {
+
+							// If prev can be converted to accepted input
+							conv = converters[ prev + " " + tmp[ 0 ] ] ||
+								converters[ "* " + tmp[ 0 ] ];
+							if ( conv ) {
+								// Condense equivalence converters
+								if ( conv === true ) {
+									conv = converters[ conv2 ];
+
+								// Otherwise, insert the intermediate dataType
+								} else if ( converters[ conv2 ] !== true ) {
+									current = tmp[ 0 ];
+									dataTypes.unshift( tmp[ 1 ] );
+								}
+								break;
+							}
+						}
+					}
+				}
+
+				// Apply converter (if not an equivalence)
+				if ( conv !== true ) {
+
+					// Unless errors are allowed to bubble, catch and return them
+					if ( conv && s[ "throws" ] ) {
+						response = conv( response );
+					} else {
+						try {
+							response = conv( response );
+						} catch ( e ) {
+							return { state: "parsererror", error: conv ? e : "No conversion from " + prev + " to " + current };
+						}
+					}
+				}
+			}
+		}
+	}
+
+	return { state: "success", data: response };
+}
+
+jQuery.extend({
+
+	// Counter for holding the number of active queries
+	active: 0,
+
+	// Last-Modified header cache for next request
+	lastModified: {},
+	etag: {},
+
+	ajaxSettings: {
+		url: ajaxLocation,
+		type: "GET",
+		isLocal: rlocalProtocol.test( ajaxLocParts[ 1 ] ),
+		global: true,
+		processData: true,
+		async: true,
+		contentType: "application/x-www-form-urlencoded; charset=UTF-8",
+		/*
+		timeout: 0,
+		data: null,
+		dataType: null,
+		username: null,
+		password: null,
+		cache: null,
+		throws: false,
+		traditional: false,
+		headers: {},
+		*/
+
+		accepts: {
+			"*": allTypes,
+			text: "text/plain",
+			html: "text/html",
+			xml: "application/xml, text/xml",
+			json: "application/json, text/javascript"
+		},
+
+		contents: {
+			xml: /xml/,
+			html: /html/,
+			json: /json/
+		},
+
+		responseFields: {
+			xml: "responseXML",
+			text: "responseText",
+			json: "responseJSON"
+		},
+
+		// Data converters
+		// Keys separate source (or catchall "*") and destination types with a single space
+		converters: {
+
+			// Convert anything to text
+			"* text": String,
+
+			// Text to html (true = no transformation)
+			"text html": true,
+
+			// Evaluate text as a json expression
+			"text json": jQuery.parseJSON,
+
+			// Parse text as xml
+			"text xml": jQuery.parseXML
+		},
+
+		// For options that shouldn't be deep extended:
+		// you can add your own custom options here if
+		// and when you create one that shouldn't be
+		// deep extended (see ajaxExtend)
+		flatOptions: {
+			url: true,
+			context: true
+		}
+	},
+
+	// Creates a full fledged settings object into target
+	// with both ajaxSettings and settings fields.
+	// If target is omitted, writes into ajaxSettings.
+	ajaxSetup: function( target, settings ) {
+		return settings ?
+
+			// Building a settings object
+			ajaxExtend( ajaxExtend( target, jQuery.ajaxSettings ), settings ) :
+
+			// Extending ajaxSettings
+			ajaxExtend( jQuery.ajaxSettings, target );
+	},
+
+	ajaxPrefilter: addToPrefiltersOrTransports( prefilters ),
+	ajaxTransport: addToPrefiltersOrTransports( transports ),
+
+	// Main method
+	ajax: function( url, options ) {
+
+		// If url is an object, simulate pre-1.5 signature
+		if ( typeof url === "object" ) {
+			options = url;
+			url = undefined;
+		}
+
+		// Force options to be an object
+		options = options || {};
+
+		var // Cross-domain detection vars
+			parts,
+			// Loop variable
+			i,
+			// URL without anti-cache param
+			cacheURL,
+			// Response headers as string
+			responseHeadersString,
+			// timeout handle
+			timeoutTimer,
+
+			// To know if global events are to be dispatched
+			fireGlobals,
+
+			transport,
+			// Response headers
+			responseHeaders,
+			// Create the final options object
+			s = jQuery.ajaxSetup( {}, options ),
+			// Callbacks context
+			callbackContext = s.context || s,
+			// Context for global events is callbackContext if it is a DOM node or jQuery collection
+			globalEventContext = s.context && ( callbackContext.nodeType || callbackContext.jquery ) ?
+				jQuery( callbackContext ) :
+				jQuery.event,
+			// Deferreds
+			deferred = jQuery.Deferred(),
+			completeDeferred = jQuery.Callbacks("once memory"),
+			// Status-dependent callbacks
+			statusCode = s.statusCode || {},
+			// Headers (they are sent all at once)
+			requestHeaders = {},
+			requestHeadersNames = {},
+			// The jqXHR state
+			state = 0,
+			// Default abort message
+			strAbort = "canceled",
+			// Fake xhr
+			jqXHR = {
+				readyState: 0,
+
+				// Builds headers hashtable if needed
+				getResponseHeader: function( key ) {
+					var match;
+					if ( state === 2 ) {
+						if ( !responseHeaders ) {
+							responseHeaders = {};
+							while ( (match = rheaders.exec( responseHeadersString )) ) {
+								responseHeaders[ match[1].toLowerCase() ] = match[ 2 ];
+							}
+						}
+						match = responseHeaders[ key.toLowerCase() ];
+					}
+					return match == null ? null : match;
+				},
+
+				// Raw string
+				getAllResponseHeaders: function() {
+					return state === 2 ? responseHeadersString : null;
+				},
+
+				// Caches the header
+				setRequestHeader: function( name, value ) {
+					var lname = name.toLowerCase();
+					if ( !state ) {
+						name = requestHeadersNames[ lname ] = requestHeadersNames[ lname ] || name;
+						requestHeaders[ name ] = value;
+					}
+					return this;
+				},
+
+				// Overrides response content-type header
+				overrideMimeType: function( type ) {
+					if ( !state ) {
+						s.mimeType = type;
+					}
+					return this;
+				},
+
+				// Status-dependent callbacks
+				statusCode: function( map ) {
+					var code;
+					if ( map ) {
+						if ( state < 2 ) {
+							for ( code in map ) {
+								// Lazy-add the new callback in a way that preserves old ones
+								statusCode[ code ] = [ statusCode[ code ], map[ code ] ];
+							}
+						} else {
+							// Execute the appropriate callbacks
+							jqXHR.always( map[ jqXHR.status ] );
+						}
+					}
+					return this;
+				},
+
+				// Cancel the request
+				abort: function( statusText ) {
+					var finalText = statusText || strAbort;
+					if ( transport ) {
+						transport.abort( finalText );
+					}
+					done( 0, finalText );
+					return this;
+				}
+			};
+
+		// Attach deferreds
+		deferred.promise( jqXHR ).complete = completeDeferred.add;
+		jqXHR.success = jqXHR.done;
+		jqXHR.error = jqXHR.fail;
+
+		// Remove hash character (#7531: and string promotion)
+		// Add protocol if not provided (#5866: IE7 issue with protocol-less urls)
+		// Handle falsy url in the settings object (#10093: consistency with old signature)
+		// We also use the url parameter if available
+		s.url = ( ( url || s.url || ajaxLocation ) + "" ).replace( rhash, "" ).replace( rprotocol, ajaxLocParts[ 1 ] + "//" );
+
+		// Alias method option to type as per ticket #12004
+		s.type = options.method || options.type || s.method || s.type;
+
+		// Extract dataTypes list
+		s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().match( rnotwhite ) || [ "" ];
+
+		// A cross-domain request is in order when we have a protocol:host:port mismatch
+		if ( s.crossDomain == null ) {
+			parts = rurl.exec( s.url.toLowerCase() );
+			s.crossDomain = !!( parts &&
+				( parts[ 1 ] !== ajaxLocParts[ 1 ] || parts[ 2 ] !== ajaxLocParts[ 2 ] ||
+					( parts[ 3 ] || ( parts[ 1 ] === "http:" ? "80" : "443" ) ) !==
+						( ajaxLocParts[ 3 ] || ( ajaxLocParts[ 1 ] === "http:" ? "80" : "443" ) ) )
+			);
+		}
+
+		// Convert data if not already a string
+		if ( s.data && s.processData && typeof s.data !== "string" ) {
+			s.data = jQuery.param( s.data, s.traditional );
+		}
+
+		// Apply prefilters
+		inspectPrefiltersOrTransports( prefilters, s, options, jqXHR );
+
+		// If request was aborted inside a prefilter, stop there
+		if ( state === 2 ) {
+			return jqXHR;
+		}
+
+		// We can fire global events as of now if asked to
+		// Don't fire events if jQuery.event is undefined in an AMD-usage scenario (#15118)
+		fireGlobals = jQuery.event && s.global;
+
+		// Watch for a new set of requests
+		if ( fireGlobals && jQuery.active++ === 0 ) {
+			jQuery.event.trigger("ajaxStart");
+		}
+
+		// Uppercase the type
+		s.type = s.type.toUpperCase();
+
+		// Determine if request has content
+		s.hasContent = !rnoContent.test( s.type );
+
+		// Save the URL in case we're toying with the If-Modified-Since
+		// and/or If-None-Match header later on
+		cacheURL = s.url;
+
+		// More options handling for requests with no content
+		if ( !s.hasContent ) {
+
+			// If data is available, append data to url
+			if ( s.data ) {
+				cacheURL = ( s.url += ( rquery.test( cacheURL ) ? "&" : "?" ) + s.data );
+				// #9682: remove data so that it's not used in an eventual retry
+				delete s.data;
+			}
+
+			// Add anti-cache in url if needed
+			if ( s.cache === false ) {
+				s.url = rts.test( cacheURL ) ?
+
+					// If there is already a '_' parameter, set its value
+					cacheURL.replace( rts, "$1_=" + nonce++ ) :
+
+					// Otherwise add one to the end
+					cacheURL + ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + nonce++;
+			}
+		}
+
+		// Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
+		if ( s.ifModified ) {
+			if ( jQuery.lastModified[ cacheURL ] ) {
+				jqXHR.setRequestHeader( "If-Modified-Since", jQuery.lastModified[ cacheURL ] );
+			}
+			if ( jQuery.etag[ cacheURL ] ) {
+				jqXHR.setRequestHeader( "If-None-Match", jQuery.etag[ cacheURL ] );
+			}
+		}
+
+		// Set the correct header, if data is being sent
+		if ( s.data && s.hasContent && s.contentType !== false || options.contentType ) {
+			jqXHR.setRequestHeader( "Content-Type", s.contentType );
+		}
+
+		// Set the Accepts header for the server, depending on the dataType
+		jqXHR.setRequestHeader(
+			"Accept",
+			s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[0] ] ?
+				s.accepts[ s.dataTypes[0] ] + ( s.dataTypes[ 0 ] !== "*" ? ", " + allTypes + "; q=0.01" : "" ) :
+				s.accepts[ "*" ]
+		);
+
+		// Check for headers option
+		for ( i in s.headers ) {
+			jqXHR.setRequestHeader( i, s.headers[ i ] );
+		}
+
+		// Allow custom headers/mimetypes and early abort
+		if ( s.beforeSend && ( s.beforeSend.call( callbackContext, jqXHR, s ) === false || state === 2 ) ) {
+			// Abort if not done already and return
+			return jqXHR.abort();
+		}
+
+		// aborting is no longer a cancellation
+		strAbort = "abort";
+
+		// Install callbacks on deferreds
+		for ( i in { success: 1, error: 1, complete: 1 } ) {
+			jqXHR[ i ]( s[ i ] );
+		}
+
+		// Get transport
+		transport = inspectPrefiltersOrTransports( transports, s, options, jqXHR );
+
+		// If no transport, we auto-abort
+		if ( !transport ) {
+			done( -1, "No Transport" );
+		} else {
+			jqXHR.readyState = 1;
+
+			// Send global event
+			if ( fireGlobals ) {
+				globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
+			}
+			// Timeout
+			if ( s.async && s.timeout > 0 ) {
+				timeoutTimer = setTimeout(function() {
+					jqXHR.abort("timeout");
+				}, s.timeout );
+			}
+
+			try {
+				state = 1;
+				transport.send( requestHeaders, done );
+			} catch ( e ) {
+				// Propagate exception as error if not done
+				if ( state < 2 ) {
+					done( -1, e );
+				// Simply rethrow otherwise
+				} else {
+					throw e;
+				}
+			}
+		}
+
+		// Callback for when everything is done
+		function done( status, nativeStatusText, responses, headers ) {
+			var isSuccess, success, error, response, modified,
+				statusText = nativeStatusText;
+
+			// Called once
+			if ( state === 2 ) {
+				return;
+			}
+
+			// State is "done" now
+			state = 2;
+
+			// Clear timeout if it exists
+			if ( timeoutTimer ) {
+				clearTimeout( timeoutTimer );
+			}
+
+			// Dereference transport for early garbage collection
+			// (no matter how long the jqXHR object will be used)
+			transport = undefined;
+
+			// Cache response headers
+			responseHeadersString = headers || "";
+
+			// Set readyState
+			jqXHR.readyState = status > 0 ? 4 : 0;
+
+			// Determine if successful
+			isSuccess = status >= 200 && status < 300 || status === 304;
+
+			// Get response data
+			if ( responses ) {
+				response = ajaxHandleResponses( s, jqXHR, responses );
+			}
+
+			// Convert no matter what (that way responseXXX fields are always set)
+			response = ajaxConvert( s, response, jqXHR, isSuccess );
+
+			// If successful, handle type chaining
+			if ( isSuccess ) {
+
+				// Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
+				if ( s.ifModified ) {
+					modified = jqXHR.getResponseHeader("Last-Modified");
+					if ( modified ) {
+						jQuery.lastModified[ cacheURL ] = modified;
+					}
+					modified = jqXHR.getResponseHeader("etag");
+					if ( modified ) {
+						jQuery.etag[ cacheURL ] = modified;
+					}
+				}
+
+				// if no content
+				if ( status === 204 || s.type === "HEAD" ) {
+					statusText = "nocontent";
+
+				// if not modified
+				} else if ( status === 304 ) {
+					statusText = "notmodified";
+
+				// If we have data, let's convert it
+				} else {
+					statusText = response.state;
+					success = response.data;
+					error = response.error;
+					isSuccess = !error;
+				}
+			} else {
+				// We extract error from statusText
+				// then normalize statusText and status for non-aborts
+				error = statusText;
+				if ( status || !statusText ) {
+					statusText = "error";
+					if ( status < 0 ) {
+						status = 0;
+					}
+				}
+			}
+
+			// Set data for the fake xhr object
+			jqXHR.status = status;
+			jqXHR.statusText = ( nativeStatusText || statusText ) + "";
+
+			// Success/Error
+			if ( isSuccess ) {
+				deferred.resolveWith( callbackContext, [ success, statusText, jqXHR ] );
+			} else {
+				deferred.rejectWith( callbackContext, [ jqXHR, statusText, error ] );
+			}
+
+			// Status-dependent callbacks
+			jqXHR.statusCode( statusCode );
+			statusCode = undefined;
+
+			if ( fireGlobals ) {
+				globalEventContext.trigger( isSuccess ? "ajaxSuccess" : "ajaxError",
+					[ jqXHR, s, isSuccess ? success : error ] );
+			}
+
+			// Complete
+			completeDeferred.fireWith( callbackContext, [ jqXHR, statusText ] );
+
+			if ( fireGlobals ) {
+				globalEventContext.trigger( "ajaxComplete", [ jqXHR, s ] );
+				// Handle the global AJAX counter
+				if ( !( --jQuery.active ) ) {
+					jQuery.event.trigger("ajaxStop");
+				}
+			}
+		}
+
+		return jqXHR;
+	},
+
+	getJSON: function( url, data, callback ) {
+		return jQuery.get( url, data, callback, "json" );
+	},
+
+	getScript: function( url, callback ) {
+		return jQuery.get( url, undefined, callback, "script" );
+	}
+});
+
+jQuery.each( [ "get", "post" ], function( i, method ) {
+	jQuery[ method ] = function( url, data, callback, type ) {
+		// shift arguments if data argument was omitted
+		if ( jQuery.isFunction( data ) ) {
+			type = type || callback;
+			callback = data;
+			data = undefined;
+		}
+
+		return jQuery.ajax({
+			url: url,
+			type: method,
+			dataType: type,
+			data: data,
+			success: callback
+		});
+	};
+});
+
+
+jQuery._evalUrl = function( url ) {
+	return jQuery.ajax({
+		url: url,
+		type: "GET",
+		dataType: "script",
+		async: false,
+		global: false,
+		"throws": true
+	});
+};
+
+
+jQuery.fn.extend({
+	wrapAll: function( html ) {
+		if ( jQuery.isFunction( html ) ) {
+			return this.each(function(i) {
+				jQuery(this).wrapAll( html.call(this, i) );
+			});
+		}
+
+		if ( this[0] ) {
+			// The elements to wrap the target around
+			var wrap = jQuery( html, this[0].ownerDocument ).eq(0).clone(true);
+
+			if ( this[0].parentNode ) {
+				wrap.insertBefore( this[0] );
+			}
+
+			wrap.map(function() {
+				var elem = this;
+
+				while ( elem.firstChild && elem.firstChild.nodeType === 1 ) {
+					elem = elem.firstChild;
+				}
+
+				return elem;
+			}).append( this );
+		}
+
+		return this;
+	},
+
+	wrapInner: function( html ) {
+		if ( jQuery.isFunction( html ) ) {
+			return this.each(function(i) {
+				jQuery(this).wrapInner( html.call(this, i) );
+			});
+		}
+
+		return this.each(function() {
+			var self = jQuery( this ),
+				contents = self.contents();
+
+			if ( contents.length ) {
+				contents.wrapAll( html );
+
+			} else {
+				self.append( html );
+			}
+		});
+	},
+
+	wrap: function( html ) {
+		var isFunction = jQuery.isFunction( html );
+
+		return this.each(function(i) {
+			jQuery( this ).wrapAll( isFunction ? html.call(this, i) : html );
+		});
+	},
+
+	unwrap: function() {
+		return this.parent().each(function() {
+			if ( !jQuery.nodeName( this, "body" ) ) {
+				jQuery( this ).replaceWith( this.childNodes );
+			}
+		}).end();
+	}
+});
+
+
+jQuery.expr.filters.hidden = function( elem ) {
+	// Support: Opera <= 12.12
+	// Opera reports offsetWidths and offsetHeights less than zero on some elements
+	return elem.offsetWidth <= 0 && elem.offsetHeight <= 0 ||
+		(!support.reliableHiddenOffsets() &&
+			((elem.style && elem.style.display) || jQuery.css( elem, "display" )) === "none");
+};
+
+jQuery.expr.filters.visible = function( elem ) {
+	return !jQuery.expr.filters.hidden( elem );
+};
+
+
+
+
+var r20 = /%20/g,
+	rbracket = /\[\]$/,
+	rCRLF = /\r?\n/g,
+	rsubmitterTypes = /^(?:submit|button|image|reset|file)$/i,
+	rsubmittable = /^(?:input|select|textarea|keygen)/i;
+
+function buildParams( prefix, obj, traditional, add ) {
+	var name;
+
+	if ( jQuery.isArray( obj ) ) {
+		// Serialize array item.
+		jQuery.each( obj, function( i, v ) {
+			if ( traditional || rbracket.test( prefix ) ) {
+				// Treat each array item as a scalar.
+				add( prefix, v );
+
+			} else {
+				// Item is non-scalar (array or object), encode its numeric index.
+				buildParams( prefix + "[" + ( typeof v === "object" ? i : "" ) + "]", v, traditional, add );
+			}
+		});
+
+	} else if ( !traditional && jQuery.type( obj ) === "object" ) {
+		// Serialize object item.
+		for ( name in obj ) {
+			buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
+		}
+
+	} else {
+		// Serialize scalar item.
+		add( prefix, obj );
+	}
+}
+
+// Serialize an array of form elements or a set of
+// key/values into a query string
+jQuery.param = function( a, traditional ) {
+	var prefix,
+		s = [],
+		add = function( key, value ) {
+			// If value is a function, invoke it and return its value
+			value = jQuery.isFunction( value ) ? value() : ( value == null ? "" : value );
+			s[ s.length ] = encodeURIComponent( key ) + "=" + encodeURIComponent( value );
+		};
+
+	// Set traditional to true for jQuery <= 1.3.2 behavior.
+	if ( traditional === undefined ) {
+		traditional = jQuery.ajaxSettings && jQuery.ajaxSettings.traditional;
+	}
+
+	// If an array was passed in, assume that it is an array of form elements.
+	if ( jQuery.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) {
+		// Serialize the form elements
+		jQuery.each( a, function() {
+			add( this.name, this.value );
+		});
+
+	} else {
+		// If traditional, encode the "old" way (the way 1.3.2 or older
+		// did it), otherwise encode params recursively.
+		for ( prefix in a ) {
+			buildParams( prefix, a[ prefix ], traditional, add );
+		}
+	}
+
+	// Return the resulting serialization
+	return s.join( "&" ).replace( r20, "+" );
+};
+
+jQuery.fn.extend({
+	serialize: function() {
+		return jQuery.param( this.serializeArray() );
+	},
+	serializeArray: function() {
+		return this.map(function() {
+			// Can add propHook for "elements" to filter or add form elements
+			var elements = jQuery.prop( this, "elements" );
+			return elements ? jQuery.makeArray( elements ) : this;
+		})
+		.filter(function() {
+			var type = this.type;
+			// Use .is(":disabled") so that fieldset[disabled] works
+			return this.name && !jQuery( this ).is( ":disabled" ) &&
+				rsubmittable.test( this.nodeName ) && !rsubmitterTypes.test( type ) &&
+				( this.checked || !rcheckableType.test( type ) );
+		})
+		.map(function( i, elem ) {
+			var val = jQuery( this ).val();
+
+			return val == null ?
+				null :
+				jQuery.isArray( val ) ?
+					jQuery.map( val, function( val ) {
+						return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
+					}) :
+					{ name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
+		}).get();
+	}
+});
+
+
+// Create the request object
+// (This is still attached to ajaxSettings for backward compatibility)
+jQuery.ajaxSettings.xhr = window.ActiveXObject !== undefined ?
+	// Support: IE6+
+	function() {
+
+		// XHR cannot access local files, always use ActiveX for that case
+		return !this.isLocal &&
+
+			// Support: IE7-8
+			// oldIE XHR does not support non-RFC2616 methods (#13240)
+			// See http://msdn.microsoft.com/en-us/library/ie/ms536648(v=vs.85).aspx
+			// and http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9
+			// Although this check for six methods instead of eight
+			// since IE also does not support "trace" and "connect"
+			/^(get|post|head|put|delete|options)$/i.test( this.type ) &&
+
+			createStandardXHR() || createActiveXHR();
+	} :
+	// For all other browsers, use the standard XMLHttpRequest object
+	createStandardXHR;
+
+var xhrId = 0,
+	xhrCallbacks = {},
+	xhrSupported = jQuery.ajaxSettings.xhr();
+
+// Support: IE<10
+// Open requests must be manually aborted on unload (#5280)
+// See https://support.microsoft.com/kb/2856746 for more info
+if ( window.attachEvent ) {
+	window.attachEvent( "onunload", function() {
+		for ( var key in xhrCallbacks ) {
+			xhrCallbacks[ key ]( undefined, true );
+		}
+	});
+}
+
+// Determine support properties
+support.cors = !!xhrSupported && ( "withCredentials" in xhrSupported );
+xhrSupported = support.ajax = !!xhrSupported;
+
+// Create transport if the browser can provide an xhr
+if ( xhrSupported ) {
+
+	jQuery.ajaxTransport(function( options ) {
+		// Cross domain only allowed if supported through XMLHttpRequest
+		if ( !options.crossDomain || support.cors ) {
+
+			var callback;
+
+			return {
+				send: function( headers, complete ) {
+					var i,
+						xhr = options.xhr(),
+						id = ++xhrId;
+
+					// Open the socket
+					xhr.open( options.type, options.url, options.async, options.username, options.password );
+
+					// Apply custom fields if provided
+					if ( options.xhrFields ) {
+						for ( i in options.xhrFields ) {
+							xhr[ i ] = options.xhrFields[ i ];
+						}
+					}
+
+					// Override mime type if needed
+					if ( options.mimeType && xhr.overrideMimeType ) {
+						xhr.overrideMimeType( options.mimeType );
+					}
+
+					// X-Requested-With header
+					// For cross-domain requests, seeing as conditions for a preflight are
+					// akin to a jigsaw puzzle, we simply never set it to be sure.
+					// (it can always be set on a per-request basis or even using ajaxSetup)
+					// For same-domain requests, won't change header if already provided.
+					if ( !options.crossDomain && !headers["X-Requested-With"] ) {
+						headers["X-Requested-With"] = "XMLHttpRequest";
+					}
+
+					// Set headers
+					for ( i in headers ) {
+						// Support: IE<9
+						// IE's ActiveXObject throws a 'Type Mismatch' exception when setting
+						// request header to a null-value.
+						//
+						// To keep consistent with other XHR implementations, cast the value
+						// to string and ignore `undefined`.
+						if ( headers[ i ] !== undefined ) {
+							xhr.setRequestHeader( i, headers[ i ] + "" );
+						}
+					}
+
+					// Do send the request
+					// This may raise an exception which is actually
+					// handled in jQuery.ajax (so no try/catch here)
+					xhr.send( ( options.hasContent && options.data ) || null );
+
+					// Listener
+					callback = function( _, isAbort ) {
+						var status, statusText, responses;
+
+						// Was never called and is aborted or complete
+						if ( callback && ( isAbort || xhr.readyState === 4 ) ) {
+							// Clean up
+							delete xhrCallbacks[ id ];
+							callback = undefined;
+							xhr.onreadystatechange = jQuery.noop;
+
+							// Abort manually if needed
+							if ( isAbort ) {
+								if ( xhr.readyState !== 4 ) {
+									xhr.abort();
+								}
+							} else {
+								responses = {};
+								status = xhr.status;
+
+								// Support: IE<10
+								// Accessing binary-data responseText throws an exception
+								// (#11426)
+								if ( typeof xhr.responseText === "string" ) {
+									responses.text = xhr.responseText;
+								}
+
+								// Firefox throws an exception when accessing
+								// statusText for faulty cross-domain requests
+								try {
+									statusText = xhr.statusText;
+								} catch( e ) {
+									// We normalize with Webkit giving an empty statusText
+									statusText = "";
+								}
+
+								// Filter status for non standard behaviors
+
+								// If the request is local and we have data: assume a success
+								// (success with no data won't get notified, that's the best we
+								// can do given current implementations)
+								if ( !status && options.isLocal && !options.crossDomain ) {
+									status = responses.text ? 200 : 404;
+								// IE - #1450: sometimes returns 1223 when it should be 204
+								} else if ( status === 1223 ) {
+									status = 204;
+								}
+							}
+						}
+
+						// Call complete if needed
+						if ( responses ) {
+							complete( status, statusText, responses, xhr.getAllResponseHeaders() );
+						}
+					};
+
+					if ( !options.async ) {
+						// if we're in sync mode we fire the callback
+						callback();
+					} else if ( xhr.readyState === 4 ) {
+						// (IE6 & IE7) if it's in cache and has been
+						// retrieved directly we need to fire the callback
+						setTimeout( callback );
+					} else {
+						// Add to the list of active xhr callbacks
+						xhr.onreadystatechange = xhrCallbacks[ id ] = callback;
+					}
+				},
+
+				abort: function() {
+					if ( callback ) {
+						callback( undefined, true );
+					}
+				}
+			};
+		}
+	});
+}
+
+// Functions to create xhrs
+function createStandardXHR() {
+	try {
+		return new window.XMLHttpRequest();
+	} catch( e ) {}
+}
+
+function createActiveXHR() {
+	try {
+		return new window.ActiveXObject( "Microsoft.XMLHTTP" );
+	} catch( e ) {}
+}
+
+
+
+
+// Install script dataType
+jQuery.ajaxSetup({
+	accepts: {
+		script: "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"
+	},
+	contents: {
+		script: /(?:java|ecma)script/
+	},
+	converters: {
+		"text script": function( text ) {
+			jQuery.globalEval( text );
+			return text;
+		}
+	}
+});
+
+// Handle cache's special case and global
+jQuery.ajaxPrefilter( "script", function( s ) {
+	if ( s.cache === undefined ) {
+		s.cache = false;
+	}
+	if ( s.crossDomain ) {
+		s.type = "GET";
+		s.global = false;
+	}
+});
+
+// Bind script tag hack transport
+jQuery.ajaxTransport( "script", function(s) {
+
+	// This transport only deals with cross domain requests
+	if ( s.crossDomain ) {
+
+		var script,
+			head = document.head || jQuery("head")[0] || document.documentElement;
+
+		return {
+
+			send: function( _, callback ) {
+
+				script = document.createElement("script");
+
+				script.async = true;
+
+				if ( s.scriptCharset ) {
+					script.charset = s.scriptCharset;
+				}
+
+				script.src = s.url;
+
+				// Attach handlers for all browsers
+				script.onload = script.onreadystatechange = function( _, isAbort ) {
+
+					if ( isAbort || !script.readyState || /loaded|complete/.test( script.readyState ) ) {
+
+						// Handle memory leak in IE
+						script.onload = script.onreadystatechange = null;
+
+						// Remove the script
+						if ( script.parentNode ) {
+							script.parentNode.removeChild( script );
+						}
+
+						// Dereference the script
+						script = null;
+
+						// Callback if not abort
+						if ( !isAbort ) {
+							callback( 200, "success" );
+						}
+					}
+				};
+
+				// Circumvent IE6 bugs with base elements (#2709 and #4378) by prepending
+				// Use native DOM manipulation to avoid our domManip AJAX trickery
+				head.insertBefore( script, head.firstChild );
+			},
+
+			abort: function() {
+				if ( script ) {
+					script.onload( undefined, true );
+				}
+			}
+		};
+	}
+});
+
+
+
+
+var oldCallbacks = [],
+	rjsonp = /(=)\?(?=&|$)|\?\?/;
+
+// Default jsonp settings
+jQuery.ajaxSetup({
+	jsonp: "callback",
+	jsonpCallback: function() {
+		var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( nonce++ ) );
+		this[ callback ] = true;
+		return callback;
+	}
+});
+
+// Detect, normalize options and install callbacks for jsonp requests
+jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
+
+	var callbackName, overwritten, responseContainer,
+		jsonProp = s.jsonp !== false && ( rjsonp.test( s.url ) ?
+			"url" :
+			typeof s.data === "string" && !( s.contentType || "" ).indexOf("application/x-www-form-urlencoded") && rjsonp.test( s.data ) && "data"
+		);
+
+	// Handle iff the expected data type is "jsonp" or we have a parameter to set
+	if ( jsonProp || s.dataTypes[ 0 ] === "jsonp" ) {
+
+		// Get callback name, remembering preexisting value associated with it
+		callbackName = s.jsonpCallback = jQuery.isFunction( s.jsonpCallback ) ?
+			s.jsonpCallback() :
+			s.jsonpCallback;
+
+		// Insert callback into url or form data
+		if ( jsonProp ) {
+			s[ jsonProp ] = s[ jsonProp ].replace( rjsonp, "$1" + callbackName );
+		} else if ( s.jsonp !== false ) {
+			s.url += ( rquery.test( s.url ) ? "&" : "?" ) + s.jsonp + "=" + callbackName;
+		}
+
+		// Use data converter to retrieve json after script execution
+		s.converters["script json"] = function() {
+			if ( !responseContainer ) {
+				jQuery.error( callbackName + " was not called" );
+			}
+			return responseContainer[ 0 ];
+		};
+
+		// force json dataType
+		s.dataTypes[ 0 ] = "json";
+
+		// Install callback
+		overwritten = window[ callbackName ];
+		window[ callbackName ] = function() {
+			responseContainer = arguments;
+		};
+
+		// Clean-up function (fires after converters)
+		jqXHR.always(function() {
+			// Restore preexisting value
+			window[ callbackName ] = overwritten;
+
+			// Save back as free
+			if ( s[ callbackName ] ) {
+				// make sure that re-using the options doesn't screw things around
+				s.jsonpCallback = originalSettings.jsonpCallback;
+
+				// save the callback name for future use
+				oldCallbacks.push( callbackName );
+			}
+
+			// Call if it was a function and we have a response
+			if ( responseContainer && jQuery.isFunction( overwritten ) ) {
+				overwritten( responseContainer[ 0 ] );
+			}
+
+			responseContainer = overwritten = undefined;
+		});
+
+		// Delegate to script
+		return "script";
+	}
+});
+
+
+
+
+// data: string of html
+// context (optional): If specified, the fragment will be created in this context, defaults to document
+// keepScripts (optional): If true, will include scripts passed in the html string
+jQuery.parseHTML = function( data, context, keepScripts ) {
+	if ( !data || typeof data !== "string" ) {
+		return null;
+	}
+	if ( typeof context === "boolean" ) {
+		keepScripts = context;
+		context = false;
+	}
+	context = context || document;
+
+	var parsed = rsingleTag.exec( data ),
+		scripts = !keepScripts && [];
+
+	// Single tag
+	if ( parsed ) {
+		return [ context.createElement( parsed[1] ) ];
+	}
+
+	parsed = jQuery.buildFragment( [ data ], context, scripts );
+
+	if ( scripts && scripts.length ) {
+		jQuery( scripts ).remove();
+	}
+
+	return jQuery.merge( [], parsed.childNodes );
+};
+
+
+// Keep a copy of the old load method
+var _load = jQuery.fn.load;
+
+/**
+ * Load a url into a page
+ */
+jQuery.fn.load = function( url, params, callback ) {
+	if ( typeof url !== "string" && _load ) {
+		return _load.apply( this, arguments );
+	}
+
+	var selector, response, type,
+		self = this,
+		off = url.indexOf(" ");
+
+	if ( off >= 0 ) {
+		selector = jQuery.trim( url.slice( off, url.length ) );
+		url = url.slice( 0, off );
+	}
+
+	// If it's a function
+	if ( jQuery.isFunction( params ) ) {
+
+		// We assume that it's the callback
+		callback = params;
+		params = undefined;
+
+	// Otherwise, build a param string
+	} else if ( params && typeof params === "object" ) {
+		type = "POST";
+	}
+
+	// If we have elements to modify, make the request
+	if ( self.length > 0 ) {
+		jQuery.ajax({
+			url: url,
+
+			// if "type" variable is undefined, then "GET" method will be used
+			type: type,
+			dataType: "html",
+			data: params
+		}).done(function( responseText ) {
+
+			// Save response for use in complete callback
+			response = arguments;
+
+			self.html( selector ?
+
+				// If a selector was specified, locate the right elements in a dummy div
+				// Exclude scripts to avoid IE 'Permission Denied' errors
+				jQuery("<div>").append( jQuery.parseHTML( responseText ) ).find( selector ) :
+
+				// Otherwise use the full result
+				responseText );
+
+		}).complete( callback && function( jqXHR, status ) {
+			self.each( callback, response || [ jqXHR.responseText, status, jqXHR ] );
+		});
+	}
+
+	return this;
+};
+
+
+
+
+// Attach a bunch of functions for handling common AJAX events
+jQuery.each( [ "ajaxStart", "ajaxStop", "ajaxComplete", "ajaxError", "ajaxSuccess", "ajaxSend" ], function( i, type ) {
+	jQuery.fn[ type ] = function( fn ) {
+		return this.on( type, fn );
+	};
+});
+
+
+
+
+jQuery.expr.filters.animated = function( elem ) {
+	return jQuery.grep(jQuery.timers, function( fn ) {
+		return elem === fn.elem;
+	}).length;
+};
+
+
+
+
+
+var docElem = window.document.documentElement;
+
+/**
+ * Gets a window from an element
+ */
+function getWindow( elem ) {
+	return jQuery.isWindow( elem ) ?
+		elem :
+		elem.nodeType === 9 ?
+			elem.defaultView || elem.parentWindow :
+			false;
+}
+
+jQuery.offset = {
+	setOffset: function( elem, options, i ) {
+		var curPosition, curLeft, curCSSTop, curTop, curOffset, curCSSLeft, calculatePosition,
+			position = jQuery.css( elem, "position" ),
+			curElem = jQuery( elem ),
+			props = {};
+
+		// set position first, in-case top/left are set even on static elem
+		if ( position === "static" ) {
+			elem.style.position = "relative";
+		}
+
+		curOffset = curElem.offset();
+		curCSSTop = jQuery.css( elem, "top" );
+		curCSSLeft = jQuery.css( elem, "left" );
+		calculatePosition = ( position === "absolute" || position === "fixed" ) &&
+			jQuery.inArray("auto", [ curCSSTop, curCSSLeft ] ) > -1;
+
+		// need to be able to calculate position if either top or left is auto and position is either absolute or fixed
+		if ( calculatePosition ) {
+			curPosition = curElem.position();
+			curTop = curPosition.top;
+			curLeft = curPosition.left;
+		} else {
+			curTop = parseFloat( curCSSTop ) || 0;
+			curLeft = parseFloat( curCSSLeft ) || 0;
+		}
+
+		if ( jQuery.isFunction( options ) ) {
+			options = options.call( elem, i, curOffset );
+		}
+
+		if ( options.top != null ) {
+			props.top = ( options.top - curOffset.top ) + curTop;
+		}
+		if ( options.left != null ) {
+			props.left = ( options.left - curOffset.left ) + curLeft;
+		}
+
+		if ( "using" in options ) {
+			options.using.call( elem, props );
+		} else {
+			curElem.css( props );
+		}
+	}
+};
+
+jQuery.fn.extend({
+	offset: function( options ) {
+		if ( arguments.length ) {
+			return options === undefined ?
+				this :
+				this.each(function( i ) {
+					jQuery.offset.setOffset( this, options, i );
+				});
+		}
+
+		var docElem, win,
+			box = { top: 0, left: 0 },
+			elem = this[ 0 ],
+			doc = elem && elem.ownerDocument;
+
+		if ( !doc ) {
+			return;
+		}
+
+		docElem = doc.documentElement;
+
+		// Make sure it's not a disconnected DOM node
+		if ( !jQuery.contains( docElem, elem ) ) {
+			return box;
+		}
+
+		// If we don't have gBCR, just use 0,0 rather than error
+		// BlackBerry 5, iOS 3 (original iPhone)
+		if ( typeof elem.getBoundingClientRect !== strundefined ) {
+			box = elem.getBoundingClientRect();
+		}
+		win = getWindow( doc );
+		return {
+			top: box.top  + ( win.pageYOffset || docElem.scrollTop )  - ( docElem.clientTop  || 0 ),
+			left: box.left + ( win.pageXOffset || docElem.scrollLeft ) - ( docElem.clientLeft || 0 )
+		};
+	},
+
+	position: function() {
+		if ( !this[ 0 ] ) {
+			return;
+		}
+
+		var offsetParent, offset,
+			parentOffset = { top: 0, left: 0 },
+			elem = this[ 0 ];
+
+		// fixed elements are offset from window (parentOffset = {top:0, left: 0}, because it is its only offset parent
+		if ( jQuery.css( elem, "position" ) === "fixed" ) {
+			// we assume that getBoundingClientRect is available when computed position is fixed
+			offset = elem.getBoundingClientRect();
+		} else {
+			// Get *real* offsetParent
+			offsetParent = this.offsetParent();
+
+			// Get correct offsets
+			offset = this.offset();
+			if ( !jQuery.nodeName( offsetParent[ 0 ], "html" ) ) {
+				parentOffset = offsetParent.offset();
+			}
+
+			// Add offsetParent borders
+			parentOffset.top  += jQuery.css( offsetParent[ 0 ], "borderTopWidth", true );
+			parentOffset.left += jQuery.css( offsetParent[ 0 ], "borderLeftWidth", true );
+		}
+
+		// Subtract parent offsets and element margins
+		// note: when an element has margin: auto the offsetLeft and marginLeft
+		// are the same in Safari causing offset.left to incorrectly be 0
+		return {
+			top:  offset.top  - parentOffset.top - jQuery.css( elem, "marginTop", true ),
+			left: offset.left - parentOffset.left - jQuery.css( elem, "marginLeft", true)
+		};
+	},
+
+	offsetParent: function() {
+		return this.map(function() {
+			var offsetParent = this.offsetParent || docElem;
+
+			while ( offsetParent && ( !jQuery.nodeName( offsetParent, "html" ) && jQuery.css( offsetParent, "position" ) === "static" ) ) {
+				offsetParent = offsetParent.offsetParent;
+			}
+			return offsetParent || docElem;
+		});
+	}
+});
+
+// Create scrollLeft and scrollTop methods
+jQuery.each( { scrollLeft: "pageXOffset", scrollTop: "pageYOffset" }, function( method, prop ) {
+	var top = /Y/.test( prop );
+
+	jQuery.fn[ method ] = function( val ) {
+		return access( this, function( elem, method, val ) {
+			var win = getWindow( elem );
+
+			if ( val === undefined ) {
+				return win ? (prop in win) ? win[ prop ] :
+					win.document.documentElement[ method ] :
+					elem[ method ];
+			}
+
+			if ( win ) {
+				win.scrollTo(
+					!top ? val : jQuery( win ).scrollLeft(),
+					top ? val : jQuery( win ).scrollTop()
+				);
+
+			} else {
+				elem[ method ] = val;
+			}
+		}, method, val, arguments.length, null );
+	};
+});
+
+// Add the top/left cssHooks using jQuery.fn.position
+// Webkit bug: https://bugs.webkit.org/show_bug.cgi?id=29084
+// getComputedStyle returns percent when specified for top/left/bottom/right
+// rather than make the css module depend on the offset module, we just check for it here
+jQuery.each( [ "top", "left" ], function( i, prop ) {
+	jQuery.cssHooks[ prop ] = addGetHookIf( support.pixelPosition,
+		function( elem, computed ) {
+			if ( computed ) {
+				computed = curCSS( elem, prop );
+				// if curCSS returns percentage, fallback to offset
+				return rnumnonpx.test( computed ) ?
+					jQuery( elem ).position()[ prop ] + "px" :
+					computed;
+			}
+		}
+	);
+});
+
+
+// Create innerHeight, innerWidth, height, width, outerHeight and outerWidth methods
+jQuery.each( { Height: "height", Width: "width" }, function( name, type ) {
+	jQuery.each( { padding: "inner" + name, content: type, "": "outer" + name }, function( defaultExtra, funcName ) {
+		// margin is only for outerHeight, outerWidth
+		jQuery.fn[ funcName ] = function( margin, value ) {
+			var chainable = arguments.length && ( defaultExtra || typeof margin !== "boolean" ),
+				extra = defaultExtra || ( margin === true || value === true ? "margin" : "border" );
+
+			return access( this, function( elem, type, value ) {
+				var doc;
+
+				if ( jQuery.isWindow( elem ) ) {
+					// As of 5/8/2012 this will yield incorrect results for Mobile Safari, but there
+					// isn't a whole lot we can do. See pull request at this URL for discussion:
+					// https://github.com/jquery/jquery/pull/764
+					return elem.document.documentElement[ "client" + name ];
+				}
+
+				// Get document width or height
+				if ( elem.nodeType === 9 ) {
+					doc = elem.documentElement;
+
+					// Either scroll[Width/Height] or offset[Width/Height] or client[Width/Height], whichever is greatest
+					// unfortunately, this causes bug #3838 in IE6/8 only, but there is currently no good, small way to fix it.
+					return Math.max(
+						elem.body[ "scroll" + name ], doc[ "scroll" + name ],
+						elem.body[ "offset" + name ], doc[ "offset" + name ],
+						doc[ "client" + name ]
+					);
+				}
+
+				return value === undefined ?
+					// Get width or height on the element, requesting but not forcing parseFloat
+					jQuery.css( elem, type, extra ) :
+
+					// Set width or height on the element
+					jQuery.style( elem, type, value, extra );
+			}, type, chainable ? margin : undefined, chainable, null );
+		};
+	});
+});
+
+
+// The number of elements contained in the matched element set
+jQuery.fn.size = function() {
+	return this.length;
+};
+
+jQuery.fn.andSelf = jQuery.fn.addBack;
+
+
+
+
+// Register as a named AMD module, since jQuery can be concatenated with other
+// files that may use define, but not via a proper concatenation script that
+// understands anonymous AMD modules. A named AMD is safest and most robust
+// way to register. Lowercase jquery is used because AMD module names are
+// derived from file names, and jQuery is normally delivered in a lowercase
+// file name. Do this after creating the global so that if an AMD module wants
+// to call noConflict to hide this version of jQuery, it will work.
+
+// Note that for maximum portability, libraries that are not jQuery should
+// declare themselves as anonymous modules, and avoid setting a global if an
+// AMD loader is present. jQuery is a special case. For more information, see
+// https://github.com/jrburke/requirejs/wiki/Updating-existing-libraries#wiki-anon
+
+if ( typeof define === "function" && define.amd ) {
+	define( "jquery", [], function() {
+		return jQuery;
+	});
+}
+
+
+
+
+var
+	// Map over jQuery in case of overwrite
+	_jQuery = window.jQuery,
+
+	// Map over the $ in case of overwrite
+	_$ = window.$;
+
+jQuery.noConflict = function( deep ) {
+	if ( window.$ === jQuery ) {
+		window.$ = _$;
+	}
+
+	if ( deep && window.jQuery === jQuery ) {
+		window.jQuery = _jQuery;
+	}
+
+	return jQuery;
+};
+
+// Expose jQuery and $ identifiers, even in
+// AMD (#7102#comment:10, https://github.com/jquery/jquery/pull/557)
+// and CommonJS for browser emulators (#13566)
+if ( typeof noGlobal === strundefined ) {
+	window.jQuery = window.$ = jQuery;
+}
+
+
+
+
+return jQuery;
+
+
+}));
diff --git a/docs/html/_static/minus.png b/docs/html/_static/minus.png
new file mode 100644
index 00000000..0f22b16b
Binary files /dev/null and b/docs/html/_static/minus.png differ
diff --git a/docs/html/_static/navigation.png b/docs/html/_static/navigation.png
new file mode 100644
index 00000000..1081dc14
Binary files /dev/null and b/docs/html/_static/navigation.png differ
diff --git a/docs/html/_static/plus.png b/docs/html/_static/plus.png
new file mode 100644
index 00000000..0cfe084c
Binary files /dev/null and b/docs/html/_static/plus.png differ
diff --git a/docs/html/_static/pygments.css b/docs/html/_static/pygments.css
new file mode 100644
index 00000000..8213e90b
--- /dev/null
+++ b/docs/html/_static/pygments.css
@@ -0,0 +1,65 @@
+.highlight .hll { background-color: #ffffcc }
+.highlight  { background: #eeffcc; }
+.highlight .c { color: #408090; font-style: italic } /* Comment */
+.highlight .err { border: 1px solid #FF0000 } /* Error */
+.highlight .k { color: #007020; font-weight: bold } /* Keyword */
+.highlight .o { color: #666666 } /* Operator */
+.highlight .ch { color: #408090; font-style: italic } /* Comment.Hashbang */
+.highlight .cm { color: #408090; font-style: italic } /* Comment.Multiline */
+.highlight .cp { color: #007020 } /* Comment.Preproc */
+.highlight .cpf { color: #408090; font-style: italic } /* Comment.PreprocFile */
+.highlight .c1 { color: #408090; font-style: italic } /* Comment.Single */
+.highlight .cs { color: #408090; background-color: #fff0f0 } /* Comment.Special */
+.highlight .gd { color: #A00000 } /* Generic.Deleted */
+.highlight .ge { font-style: italic } /* Generic.Emph */
+.highlight .gr { color: #FF0000 } /* Generic.Error */
+.highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */
+.highlight .gi { color: #00A000 } /* Generic.Inserted */
+.highlight .go { color: #333333 } /* Generic.Output */
+.highlight .gp { color: #c65d09; font-weight: bold } /* Generic.Prompt */
+.highlight .gs { font-weight: bold } /* Generic.Strong */
+.highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
+.highlight .gt { color: #0044DD } /* Generic.Traceback */
+.highlight .kc { color: #007020; font-weight: bold } /* Keyword.Constant */
+.highlight .kd { color: #007020; font-weight: bold } /* Keyword.Declaration */
+.highlight .kn { color: #007020; font-weight: bold } /* Keyword.Namespace */
+.highlight .kp { color: #007020 } /* Keyword.Pseudo */
+.highlight .kr { color: #007020; font-weight: bold } /* Keyword.Reserved */
+.highlight .kt { color: #902000 } /* Keyword.Type */
+.highlight .m { color: #208050 } /* Literal.Number */
+.highlight .s { color: #4070a0 } /* Literal.String */
+.highlight .na { color: #4070a0 } /* Name.Attribute */
+.highlight .nb { color: #007020 } /* Name.Builtin */
+.highlight .nc { color: #0e84b5; font-weight: bold } /* Name.Class */
+.highlight .no { color: #60add5 } /* Name.Constant */
+.highlight .nd { color: #555555; font-weight: bold } /* Name.Decorator */
+.highlight .ni { color: #d55537; font-weight: bold } /* Name.Entity */
+.highlight .ne { color: #007020 } /* Name.Exception */
+.highlight .nf { color: #06287e } /* Name.Function */
+.highlight .nl { color: #002070; font-weight: bold } /* Name.Label */
+.highlight .nn { color: #0e84b5; font-weight: bold } /* Name.Namespace */
+.highlight .nt { color: #062873; font-weight: bold } /* Name.Tag */
+.highlight .nv { color: #bb60d5 } /* Name.Variable */
+.highlight .ow { color: #007020; font-weight: bold } /* Operator.Word */
+.highlight .w { color: #bbbbbb } /* Text.Whitespace */
+.highlight .mb { color: #208050 } /* Literal.Number.Bin */
+.highlight .mf { color: #208050 } /* Literal.Number.Float */
+.highlight .mh { color: #208050 } /* Literal.Number.Hex */
+.highlight .mi { color: #208050 } /* Literal.Number.Integer */
+.highlight .mo { color: #208050 } /* Literal.Number.Oct */
+.highlight .sb { color: #4070a0 } /* Literal.String.Backtick */
+.highlight .sc { color: #4070a0 } /* Literal.String.Char */
+.highlight .sd { color: #4070a0; font-style: italic } /* Literal.String.Doc */
+.highlight .s2 { color: #4070a0 } /* Literal.String.Double */
+.highlight .se { color: #4070a0; font-weight: bold } /* Literal.String.Escape */
+.highlight .sh { color: #4070a0 } /* Literal.String.Heredoc */
+.highlight .si { color: #70a0d0; font-style: italic } /* Literal.String.Interpol */
+.highlight .sx { color: #c65d09 } /* Literal.String.Other */
+.highlight .sr { color: #235388 } /* Literal.String.Regex */
+.highlight .s1 { color: #4070a0 } /* Literal.String.Single */
+.highlight .ss { color: #517918 } /* Literal.String.Symbol */
+.highlight .bp { color: #007020 } /* Name.Builtin.Pseudo */
+.highlight .vc { color: #bb60d5 } /* Name.Variable.Class */
+.highlight .vg { color: #bb60d5 } /* Name.Variable.Global */
+.highlight .vi { color: #bb60d5 } /* Name.Variable.Instance */
+.highlight .il { color: #208050 } /* Literal.Number.Integer.Long */
\ No newline at end of file
diff --git a/docs/html/_static/searchtools.js b/docs/html/_static/searchtools.js
new file mode 100644
index 00000000..cb744672
--- /dev/null
+++ b/docs/html/_static/searchtools.js
@@ -0,0 +1,651 @@
+/*
+ * searchtools.js_t
+ * ~~~~~~~~~~~~~~~~
+ *
+ * Sphinx JavaScript utilties for the full-text search.
+ *
+ * :copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
+ * :license: BSD, see LICENSE for details.
+ *
+ */
+
+
+/* Non-minified version JS is _stemmer.js if file is provided */ 
+/**
+ * Porter Stemmer
+ */
+var Stemmer = function() {
+
+  var step2list = {
+    ational: 'ate',
+    tional: 'tion',
+    enci: 'ence',
+    anci: 'ance',
+    izer: 'ize',
+    bli: 'ble',
+    alli: 'al',
+    entli: 'ent',
+    eli: 'e',
+    ousli: 'ous',
+    ization: 'ize',
+    ation: 'ate',
+    ator: 'ate',
+    alism: 'al',
+    iveness: 'ive',
+    fulness: 'ful',
+    ousness: 'ous',
+    aliti: 'al',
+    iviti: 'ive',
+    biliti: 'ble',
+    logi: 'log'
+  };
+
+  var step3list = {
+    icate: 'ic',
+    ative: '',
+    alize: 'al',
+    iciti: 'ic',
+    ical: 'ic',
+    ful: '',
+    ness: ''
+  };
+
+  var c = "[^aeiou]";          // consonant
+  var v = "[aeiouy]";          // vowel
+  var C = c + "[^aeiouy]*";    // consonant sequence
+  var V = v + "[aeiou]*";      // vowel sequence
+
+  var mgr0 = "^(" + C + ")?" + V + C;                      // [C]VC... is m>0
+  var meq1 = "^(" + C + ")?" + V + C + "(" + V + ")?$";    // [C]VC[V] is m=1
+  var mgr1 = "^(" + C + ")?" + V + C + V + C;              // [C]VCVC... is m>1
+  var s_v   = "^(" + C + ")?" + v;                         // vowel in stem
+
+  this.stemWord = function (w) {
+    var stem;
+    var suffix;
+    var firstch;
+    var origword = w;
+
+    if (w.length < 3)
+      return w;
+
+    var re;
+    var re2;
+    var re3;
+    var re4;
+
+    firstch = w.substr(0,1);
+    if (firstch == "y")
+      w = firstch.toUpperCase() + w.substr(1);
+
+    // Step 1a
+    re = /^(.+?)(ss|i)es$/;
+    re2 = /^(.+?)([^s])s$/;
+
+    if (re.test(w))
+      w = w.replace(re,"$1$2");
+    else if (re2.test(w))
+      w = w.replace(re2,"$1$2");
+
+    // Step 1b
+    re = /^(.+?)eed$/;
+    re2 = /^(.+?)(ed|ing)$/;
+    if (re.test(w)) {
+      var fp = re.exec(w);
+      re = new RegExp(mgr0);
+      if (re.test(fp[1])) {
+        re = /.$/;
+        w = w.replace(re,"");
+      }
+    }
+    else if (re2.test(w)) {
+      var fp = re2.exec(w);
+      stem = fp[1];
+      re2 = new RegExp(s_v);
+      if (re2.test(stem)) {
+        w = stem;
+        re2 = /(at|bl|iz)$/;
+        re3 = new RegExp("([^aeiouylsz])\\1$");
+        re4 = new RegExp("^" + C + v + "[^aeiouwxy]$");
+        if (re2.test(w))
+          w = w + "e";
+        else if (re3.test(w)) {
+          re = /.$/;
+          w = w.replace(re,"");
+        }
+        else if (re4.test(w))
+          w = w + "e";
+      }
+    }
+
+    // Step 1c
+    re = /^(.+?)y$/;
+    if (re.test(w)) {
+      var fp = re.exec(w);
+      stem = fp[1];
+      re = new RegExp(s_v);
+      if (re.test(stem))
+        w = stem + "i";
+    }
+
+    // Step 2
+    re = /^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/;
+    if (re.test(w)) {
+      var fp = re.exec(w);
+      stem = fp[1];
+      suffix = fp[2];
+      re = new RegExp(mgr0);
+      if (re.test(stem))
+        w = stem + step2list[suffix];
+    }
+
+    // Step 3
+    re = /^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/;
+    if (re.test(w)) {
+      var fp = re.exec(w);
+      stem = fp[1];
+      suffix = fp[2];
+      re = new RegExp(mgr0);
+      if (re.test(stem))
+        w = stem + step3list[suffix];
+    }
+
+    // Step 4
+    re = /^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/;
+    re2 = /^(.+?)(s|t)(ion)$/;
+    if (re.test(w)) {
+      var fp = re.exec(w);
+      stem = fp[1];
+      re = new RegExp(mgr1);
+      if (re.test(stem))
+        w = stem;
+    }
+    else if (re2.test(w)) {
+      var fp = re2.exec(w);
+      stem = fp[1] + fp[2];
+      re2 = new RegExp(mgr1);
+      if (re2.test(stem))
+        w = stem;
+    }
+
+    // Step 5
+    re = /^(.+?)e$/;
+    if (re.test(w)) {
+      var fp = re.exec(w);
+      stem = fp[1];
+      re = new RegExp(mgr1);
+      re2 = new RegExp(meq1);
+      re3 = new RegExp("^" + C + v + "[^aeiouwxy]$");
+      if (re.test(stem) || (re2.test(stem) && !(re3.test(stem))))
+        w = stem;
+    }
+    re = /ll$/;
+    re2 = new RegExp(mgr1);
+    if (re.test(w) && re2.test(w)) {
+      re = /.$/;
+      w = w.replace(re,"");
+    }
+
+    // and turn initial Y back to y
+    if (firstch == "y")
+      w = firstch.toLowerCase() + w.substr(1);
+    return w;
+  }
+}
+
+
+
+/**
+ * Simple result scoring code.
+ */
+var Scorer = {
+  // Implement the following function to further tweak the score for each result
+  // The function takes a result array [filename, title, anchor, descr, score]
+  // and returns the new score.
+  /*
+  score: function(result) {
+    return result[4];
+  },
+  */
+
+  // query matches the full name of an object
+  objNameMatch: 11,
+  // or matches in the last dotted part of the object name
+  objPartialMatch: 6,
+  // Additive scores depending on the priority of the object
+  objPrio: {0:  15,   // used to be importantResults
+            1:  5,   // used to be objectResults
+            2: -5},  // used to be unimportantResults
+  //  Used when the priority is not in the mapping.
+  objPrioDefault: 0,
+
+  // query found in title
+  title: 15,
+  // query found in terms
+  term: 5
+};
+
+
+/**
+ * Search Module
+ */
+var Search = {
+
+  _index : null,
+  _queued_query : null,
+  _pulse_status : -1,
+
+  init : function() {
+      var params = $.getQueryParameters();
+      if (params.q) {
+          var query = params.q[0];
+          $('input[name="q"]')[0].value = query;
+          this.performSearch(query);
+      }
+  },
+
+  loadIndex : function(url) {
+    $.ajax({type: "GET", url: url, data: null,
+            dataType: "script", cache: true,
+            complete: function(jqxhr, textstatus) {
+              if (textstatus != "success") {
+                document.getElementById("searchindexloader").src = url;
+              }
+            }});
+  },
+
+  setIndex : function(index) {
+    var q;
+    this._index = index;
+    if ((q = this._queued_query) !== null) {
+      this._queued_query = null;
+      Search.query(q);
+    }
+  },
+
+  hasIndex : function() {
+      return this._index !== null;
+  },
+
+  deferQuery : function(query) {
+      this._queued_query = query;
+  },
+
+  stopPulse : function() {
+      this._pulse_status = 0;
+  },
+
+  startPulse : function() {
+    if (this._pulse_status >= 0)
+        return;
+    function pulse() {
+      var i;
+      Search._pulse_status = (Search._pulse_status + 1) % 4;
+      var dotString = '';
+      for (i = 0; i < Search._pulse_status; i++)
+        dotString += '.';
+      Search.dots.text(dotString);
+      if (Search._pulse_status > -1)
+        window.setTimeout(pulse, 500);
+    }
+    pulse();
+  },
+
+  /**
+   * perform a search for something (or wait until index is loaded)
+   */
+  performSearch : function(query) {
+    // create the required interface elements
+    this.out = $('#search-results');
+    this.title = $('<h2>' + _('Searching') + '</h2>').appendTo(this.out);
+    this.dots = $('<span></span>').appendTo(this.title);
+    this.status = $('<p style="display: none"></p>').appendTo(this.out);
+    this.output = $('<ul class="search"/>').appendTo(this.out);
+
+    $('#search-progress').text(_('Preparing search...'));
+    this.startPulse();
+
+    // index already loaded, the browser was quick!
+    if (this.hasIndex())
+      this.query(query);
+    else
+      this.deferQuery(query);
+  },
+
+  /**
+   * execute search (requires search index to be loaded)
+   */
+  query : function(query) {
+    var i;
+    var stopwords = ["a","and","are","as","at","be","but","by","for","if","in","into","is","it","near","no","not","of","on","or","such","that","the","their","then","there","these","they","this","to","was","will","with"];
+
+    // stem the searchterms and add them to the correct list
+    var stemmer = new Stemmer();
+    var searchterms = [];
+    var excluded = [];
+    var hlterms = [];
+    var tmp = query.split(/\s+/);
+    var objectterms = [];
+    for (i = 0; i < tmp.length; i++) {
+      if (tmp[i] !== "") {
+          objectterms.push(tmp[i].toLowerCase());
+      }
+
+      if ($u.indexOf(stopwords, tmp[i].toLowerCase()) != -1 || tmp[i].match(/^\d+$/) ||
+          tmp[i] === "") {
+        // skip this "word"
+        continue;
+      }
+      // stem the word
+      var word = stemmer.stemWord(tmp[i].toLowerCase());
+      var toAppend;
+      // select the correct list
+      if (word[0] == '-') {
+        toAppend = excluded;
+        word = word.substr(1);
+      }
+      else {
+        toAppend = searchterms;
+        hlterms.push(tmp[i].toLowerCase());
+      }
+      // only add if not already in the list
+      if (!$u.contains(toAppend, word))
+        toAppend.push(word);
+    }
+    var highlightstring = '?highlight=' + $.urlencode(hlterms.join(" "));
+
+    // console.debug('SEARCH: searching for:');
+    // console.info('required: ', searchterms);
+    // console.info('excluded: ', excluded);
+
+    // prepare search
+    var terms = this._index.terms;
+    var titleterms = this._index.titleterms;
+
+    // array of [filename, title, anchor, descr, score]
+    var results = [];
+    $('#search-progress').empty();
+
+    // lookup as object
+    for (i = 0; i < objectterms.length; i++) {
+      var others = [].concat(objectterms.slice(0, i),
+                             objectterms.slice(i+1, objectterms.length));
+      results = results.concat(this.performObjectSearch(objectterms[i], others));
+    }
+
+    // lookup as search terms in fulltext
+    results = results.concat(this.performTermsSearch(searchterms, excluded, terms, titleterms));
+
+    // let the scorer override scores with a custom scoring function
+    if (Scorer.score) {
+      for (i = 0; i < results.length; i++)
+        results[i][4] = Scorer.score(results[i]);
+    }
+
+    // now sort the results by score (in opposite order of appearance, since the
+    // display function below uses pop() to retrieve items) and then
+    // alphabetically
+    results.sort(function(a, b) {
+      var left = a[4];
+      var right = b[4];
+      if (left > right) {
+        return 1;
+      } else if (left < right) {
+        return -1;
+      } else {
+        // same score: sort alphabetically
+        left = a[1].toLowerCase();
+        right = b[1].toLowerCase();
+        return (left > right) ? -1 : ((left < right) ? 1 : 0);
+      }
+    });
+
+    // for debugging
+    //Search.lastresults = results.slice();  // a copy
+    //console.info('search results:', Search.lastresults);
+
+    // print the results
+    var resultCount = results.length;
+    function displayNextItem() {
+      // results left, load the summary and display it
+      if (results.length) {
+        var item = results.pop();
+        var listItem = $('<li style="display:none"></li>');
+        if (DOCUMENTATION_OPTIONS.FILE_SUFFIX === '') {
+          // dirhtml builder
+          var dirname = item[0] + '/';
+          if (dirname.match(/\/index\/$/)) {
+            dirname = dirname.substring(0, dirname.length-6);
+          } else if (dirname == 'index/') {
+            dirname = '';
+          }
+          listItem.append($('<a/>').attr('href',
+            DOCUMENTATION_OPTIONS.URL_ROOT + dirname +
+            highlightstring + item[2]).html(item[1]));
+        } else {
+          // normal html builders
+          listItem.append($('<a/>').attr('href',
+            item[0] + DOCUMENTATION_OPTIONS.FILE_SUFFIX +
+            highlightstring + item[2]).html(item[1]));
+        }
+        if (item[3]) {
+          listItem.append($('<span> (' + item[3] + ')</span>'));
+          Search.output.append(listItem);
+          listItem.slideDown(5, function() {
+            displayNextItem();
+          });
+        } else if (DOCUMENTATION_OPTIONS.HAS_SOURCE) {
+          $.ajax({url: DOCUMENTATION_OPTIONS.URL_ROOT + '_sources/' + item[0] + '.txt',
+                  dataType: "text",
+                  complete: function(jqxhr, textstatus) {
+                    var data = jqxhr.responseText;
+                    if (data !== '' && data !== undefined) {
+                      listItem.append(Search.makeSearchSummary(data, searchterms, hlterms));
+                    }
+                    Search.output.append(listItem);
+                    listItem.slideDown(5, function() {
+                      displayNextItem();
+                    });
+                  }});
+        } else {
+          // no source available, just display title
+          Search.output.append(listItem);
+          listItem.slideDown(5, function() {
+            displayNextItem();
+          });
+        }
+      }
+      // search finished, update title and status message
+      else {
+        Search.stopPulse();
+        Search.title.text(_('Search Results'));
+        if (!resultCount)
+          Search.status.text(_('Your search did not match any documents. Please make sure that all words are spelled correctly and that you\'ve selected enough categories.'));
+        else
+            Search.status.text(_('Search finished, found %s page(s) matching the search query.').replace('%s', resultCount));
+        Search.status.fadeIn(500);
+      }
+    }
+    displayNextItem();
+  },
+
+  /**
+   * search for object names
+   */
+  performObjectSearch : function(object, otherterms) {
+    var filenames = this._index.filenames;
+    var objects = this._index.objects;
+    var objnames = this._index.objnames;
+    var titles = this._index.titles;
+
+    var i;
+    var results = [];
+
+    for (var prefix in objects) {
+      for (var name in objects[prefix]) {
+        var fullname = (prefix ? prefix + '.' : '') + name;
+        if (fullname.toLowerCase().indexOf(object) > -1) {
+          var score = 0;
+          var parts = fullname.split('.');
+          // check for different match types: exact matches of full name or
+          // "last name" (i.e. last dotted part)
+          if (fullname == object || parts[parts.length - 1] == object) {
+            score += Scorer.objNameMatch;
+          // matches in last name
+          } else if (parts[parts.length - 1].indexOf(object) > -1) {
+            score += Scorer.objPartialMatch;
+          }
+          var match = objects[prefix][name];
+          var objname = objnames[match[1]][2];
+          var title = titles[match[0]];
+          // If more than one term searched for, we require other words to be
+          // found in the name/title/description
+          if (otherterms.length > 0) {
+            var haystack = (prefix + ' ' + name + ' ' +
+                            objname + ' ' + title).toLowerCase();
+            var allfound = true;
+            for (i = 0; i < otherterms.length; i++) {
+              if (haystack.indexOf(otherterms[i]) == -1) {
+                allfound = false;
+                break;
+              }
+            }
+            if (!allfound) {
+              continue;
+            }
+          }
+          var descr = objname + _(', in ') + title;
+
+          var anchor = match[3];
+          if (anchor === '')
+            anchor = fullname;
+          else if (anchor == '-')
+            anchor = objnames[match[1]][1] + '-' + fullname;
+          // add custom score for some objects according to scorer
+          if (Scorer.objPrio.hasOwnProperty(match[2])) {
+            score += Scorer.objPrio[match[2]];
+          } else {
+            score += Scorer.objPrioDefault;
+          }
+          results.push([filenames[match[0]], fullname, '#'+anchor, descr, score]);
+        }
+      }
+    }
+
+    return results;
+  },
+
+  /**
+   * search for full-text terms in the index
+   */
+  performTermsSearch : function(searchterms, excluded, terms, titleterms) {
+    var filenames = this._index.filenames;
+    var titles = this._index.titles;
+
+    var i, j, file;
+    var fileMap = {};
+    var scoreMap = {};
+    var results = [];
+
+    // perform the search on the required terms
+    for (i = 0; i < searchterms.length; i++) {
+      var word = searchterms[i];
+      var files = [];
+      var _o = [
+        {files: terms[word], score: Scorer.term},
+        {files: titleterms[word], score: Scorer.title}
+      ];
+
+      // no match but word was a required one
+      if ($u.every(_o, function(o){return o.files === undefined;})) {
+        break;
+      }
+      // found search word in contents
+      $u.each(_o, function(o) {
+        var _files = o.files;
+        if (_files === undefined)
+          return
+
+        if (_files.length === undefined)
+          _files = [_files];
+        files = files.concat(_files);
+
+        // set score for the word in each file to Scorer.term
+        for (j = 0; j < _files.length; j++) {
+          file = _files[j];
+          if (!(file in scoreMap))
+            scoreMap[file] = {}
+          scoreMap[file][word] = o.score;
+        }
+      });
+
+      // create the mapping
+      for (j = 0; j < files.length; j++) {
+        file = files[j];
+        if (file in fileMap)
+          fileMap[file].push(word);
+        else
+          fileMap[file] = [word];
+      }
+    }
+
+    // now check if the files don't contain excluded terms
+    for (file in fileMap) {
+      var valid = true;
+
+      // check if all requirements are matched
+      if (fileMap[file].length != searchterms.length)
+          continue;
+
+      // ensure that none of the excluded terms is in the search result
+      for (i = 0; i < excluded.length; i++) {
+        if (terms[excluded[i]] == file ||
+            titleterms[excluded[i]] == file ||
+            $u.contains(terms[excluded[i]] || [], file) ||
+            $u.contains(titleterms[excluded[i]] || [], file)) {
+          valid = false;
+          break;
+        }
+      }
+
+      // if we have still a valid result we can add it to the result list
+      if (valid) {
+        // select one (max) score for the file.
+        // for better ranking, we should calculate ranking by using words statistics like basic tf-idf...
+        var score = $u.max($u.map(fileMap[file], function(w){return scoreMap[file][w]}));
+        results.push([filenames[file], titles[file], '', null, score]);
+      }
+    }
+    return results;
+  },
+
+  /**
+   * helper function to return a node containing the
+   * search summary for a given text. keywords is a list
+   * of stemmed words, hlwords is the list of normal, unstemmed
+   * words. the first one is used to find the occurance, the
+   * latter for highlighting it.
+   */
+  makeSearchSummary : function(text, keywords, hlwords) {
+    var textLower = text.toLowerCase();
+    var start = 0;
+    $.each(keywords, function() {
+      var i = textLower.indexOf(this.toLowerCase());
+      if (i > -1)
+        start = i;
+    });
+    start = Math.max(start - 120, 0);
+    var excerpt = ((start > 0) ? '...' : '') +
+      $.trim(text.substr(start, 240)) +
+      ((start + 240 - text.length) ? '...' : '');
+    var rv = $('<div class="context"></div>').text(excerpt);
+    $.each(hlwords, function() {
+      rv = rv.highlightText(this, 'highlighted');
+    });
+    return rv;
+  }
+};
+
+$(document).ready(function() {
+  Search.init();
+});
\ No newline at end of file
diff --git a/docs/html/_static/sphinxdoc.css b/docs/html/_static/sphinxdoc.css
new file mode 100644
index 00000000..e35e161b
--- /dev/null
+++ b/docs/html/_static/sphinxdoc.css
@@ -0,0 +1,345 @@
+/*
+ * sphinxdoc.css_t
+ * ~~~~~~~~~~~~~~~
+ *
+ * Sphinx stylesheet -- sphinxdoc theme.  Originally created by
+ * Armin Ronacher for Werkzeug.
+ *
+ * :copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
+ * :license: BSD, see LICENSE for details.
+ *
+ */
+
+@import url("basic.css");
+
+/* -- page layout ----------------------------------------------------------- */
+
+body {
+    font-family: 'Lucida Grande', 'Lucida Sans Unicode', 'Geneva',
+                 'Verdana', sans-serif;
+    font-size: 14px;
+    letter-spacing: -0.01em;
+    line-height: 150%;
+    text-align: center;
+    background-color: #BFD1D4;
+    color: black;
+    padding: 0;
+    border: 1px solid #aaa;
+
+    margin: 0px 80px 0px 80px;
+    min-width: 740px;
+}
+
+div.document {
+    background-color: white;
+    text-align: left;
+    background-image: url(contents.png);
+    background-repeat: repeat-x;
+}
+
+div.bodywrapper {
+    margin: 0 240px 0 0;
+    border-right: 1px solid #ccc;
+}
+
+div.body {
+    margin: 0;
+    padding: 0.5em 20px 20px 20px;
+}
+
+div.related {
+    font-size: 1em;
+}
+
+div.related ul {
+    background-image: url(navigation.png);
+    height: 2em;
+    border-top: 1px solid #ddd;
+    border-bottom: 1px solid #ddd;
+}
+
+div.related ul li {
+    margin: 0;
+    padding: 0;
+    height: 2em;
+    float: left;
+}
+
+div.related ul li.right {
+    float: right;
+    margin-right: 5px;
+}
+
+div.related ul li a {
+    margin: 0;
+    padding: 0 5px 0 5px;
+    line-height: 1.75em;
+    color: #EE9816;
+}
+
+div.related ul li a:hover {
+    color: #3CA8E7;
+}
+
+div.sphinxsidebarwrapper {
+    padding: 0;
+}
+
+div.sphinxsidebar {
+    margin: 0;
+    padding: 0.5em 15px 15px 0;
+    width: 210px;
+    float: right;
+    font-size: 1em;
+    text-align: left;
+}
+
+div.sphinxsidebar h3, div.sphinxsidebar h4 {
+    margin: 1em 0 0.5em 0;
+    font-size: 1em;
+    padding: 0.1em 0 0.1em 0.5em;
+    color: white;
+    border: 1px solid #86989B;
+    background-color: #AFC1C4;
+}
+
+div.sphinxsidebar h3 a {
+    color: white;
+}
+
+div.sphinxsidebar ul {
+    padding-left: 1.5em;
+    margin-top: 7px;
+    padding: 0;
+    line-height: 130%;
+}
+
+div.sphinxsidebar ul ul {
+    margin-left: 20px;
+}
+
+div.footer {
+    background-color: #E3EFF1;
+    color: #86989B;
+    padding: 3px 8px 3px 0;
+    clear: both;
+    font-size: 0.8em;
+    text-align: right;
+}
+
+div.footer a {
+    color: #86989B;
+    text-decoration: underline;
+}
+
+/* -- body styles ----------------------------------------------------------- */
+
+p {    
+    margin: 0.8em 0 0.5em 0;
+}
+
+a {
+    color: #CA7900;
+    text-decoration: none;
+}
+
+a:hover {
+    color: #2491CF;
+}
+
+div.body a {
+    text-decoration: underline;
+}
+
+h1 {
+    margin: 0;
+    padding: 0.7em 0 0.3em 0;
+    font-size: 1.5em;
+    color: #11557C;
+}
+
+h2 {
+    margin: 1.3em 0 0.2em 0;
+    font-size: 1.35em;
+    padding: 0;
+}
+
+h3 {
+    margin: 1em 0 -0.3em 0;
+    font-size: 1.2em;
+}
+
+div.body h1 a, div.body h2 a, div.body h3 a, div.body h4 a, div.body h5 a, div.body h6 a {
+    color: black!important;
+}
+
+h1 a.anchor, h2 a.anchor, h3 a.anchor, h4 a.anchor, h5 a.anchor, h6 a.anchor {
+    display: none;
+    margin: 0 0 0 0.3em;
+    padding: 0 0.2em 0 0.2em;
+    color: #aaa!important;
+}
+
+h1:hover a.anchor, h2:hover a.anchor, h3:hover a.anchor, h4:hover a.anchor,
+h5:hover a.anchor, h6:hover a.anchor {
+    display: inline;
+}
+
+h1 a.anchor:hover, h2 a.anchor:hover, h3 a.anchor:hover, h4 a.anchor:hover,
+h5 a.anchor:hover, h6 a.anchor:hover {
+    color: #777;
+    background-color: #eee;
+}
+
+a.headerlink {
+    color: #c60f0f!important;
+    font-size: 1em;
+    margin-left: 6px;
+    padding: 0 4px 0 4px;
+    text-decoration: none!important;
+}
+
+a.headerlink:hover {
+    background-color: #ccc;
+    color: white!important;
+}
+
+cite, code, code {
+    font-family: 'Consolas', 'Deja Vu Sans Mono',
+                 'Bitstream Vera Sans Mono', monospace;
+    font-size: 0.95em;
+    letter-spacing: 0.01em;
+}
+
+code {
+    background-color: #f2f2f2;
+    border-bottom: 1px solid #ddd;
+    color: #333;
+}
+
+code.descname, code.descclassname, code.xref {
+    border: 0;
+}
+
+hr {
+    border: 1px solid #abc;
+    margin: 2em;
+}
+
+a code {
+    border: 0;
+    color: #CA7900;
+}
+
+a code:hover {
+    color: #2491CF;
+}
+
+pre {
+    font-family: 'Consolas', 'Deja Vu Sans Mono',
+                 'Bitstream Vera Sans Mono', monospace;
+    font-size: 0.95em;
+    letter-spacing: 0.015em;
+    line-height: 120%;
+    padding: 0.5em;
+    border: 1px solid #ccc;
+    background-color: #f8f8f8;
+}
+
+pre a {
+    color: inherit;
+    text-decoration: underline;
+}
+
+td.linenos pre {
+    padding: 0.5em 0;
+}
+
+div.quotebar {
+    background-color: #f8f8f8;
+    max-width: 250px;
+    float: right;
+    padding: 2px 7px;
+    border: 1px solid #ccc;
+}
+
+div.topic {
+    background-color: #f8f8f8;
+}
+
+table {
+    border-collapse: collapse;
+    margin: 0 -0.5em 0 -0.5em;
+}
+
+table td, table th {
+    padding: 0.2em 0.5em 0.2em 0.5em;
+}
+
+div.admonition, div.warning {
+    font-size: 0.9em;
+    margin: 1em 0 1em 0;
+    border: 1px solid #86989B;
+    background-color: #f7f7f7;
+    padding: 0;
+}
+
+div.admonition p, div.warning p {
+    margin: 0.5em 1em 0.5em 1em;
+    padding: 0;
+}
+
+div.admonition pre, div.warning pre {
+    margin: 0.4em 1em 0.4em 1em;
+}
+
+div.admonition p.admonition-title,
+div.warning p.admonition-title {
+    margin: 0;
+    padding: 0.1em 0 0.1em 0.5em;
+    color: white;
+    border-bottom: 1px solid #86989B;
+    font-weight: bold;
+    background-color: #AFC1C4;
+}
+
+div.warning {
+    border: 1px solid #940000;
+}
+
+div.warning p.admonition-title {
+    background-color: #CF0000;
+    border-bottom-color: #940000;
+}
+
+div.admonition ul, div.admonition ol,
+div.warning ul, div.warning ol {
+    margin: 0.1em 0.5em 0.5em 3em;
+    padding: 0;
+}
+
+div.versioninfo {
+    margin: 1em 0 0 0;
+    border: 1px solid #ccc;
+    background-color: #DDEAF0;
+    padding: 8px;
+    line-height: 1.3em;
+    font-size: 0.9em;
+}
+
+.viewcode-back {
+    font-family: 'Lucida Grande', 'Lucida Sans Unicode', 'Geneva',
+                 'Verdana', sans-serif;
+}
+
+div.viewcode-block:target {
+    background-color: #f4debf;
+    border-top: 1px solid #ac9;
+    border-bottom: 1px solid #ac9;
+}
+
+div.code-block-caption {
+    background-color: #ddd;
+    color: #222;
+    border: 1px solid #ccc;
+}
\ No newline at end of file
diff --git a/docs/html/_static/underscore.js b/docs/html/_static/underscore.js
new file mode 100644
index 00000000..b4f49a02
--- /dev/null
+++ b/docs/html/_static/underscore.js
@@ -0,0 +1,1415 @@
+//     Underscore.js 1.7.0
+//     http://underscorejs.org
+//     (c) 2009-2014 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
+//     Underscore may be freely distributed under the MIT license.
+
+(function() {
+
+  // Baseline setup
+  // --------------
+
+  // Establish the root object, `window` in the browser, or `exports` on the server.
+  var root = this;
+
+  // Save the previous value of the `_` variable.
+  var previousUnderscore = root._;
+
+  // Save bytes in the minified (but not gzipped) version:
+  var ArrayProto = Array.prototype, ObjProto = Object.prototype, FuncProto = Function.prototype;
+
+  // Create quick reference variables for speed access to core prototypes.
+  var
+    push             = ArrayProto.push,
+    slice            = ArrayProto.slice,
+    concat           = ArrayProto.concat,
+    toString         = ObjProto.toString,
+    hasOwnProperty   = ObjProto.hasOwnProperty;
+
+  // All **ECMAScript 5** native function implementations that we hope to use
+  // are declared here.
+  var
+    nativeIsArray      = Array.isArray,
+    nativeKeys         = Object.keys,
+    nativeBind         = FuncProto.bind;
+
+  // Create a safe reference to the Underscore object for use below.
+  var _ = function(obj) {
+    if (obj instanceof _) return obj;
+    if (!(this instanceof _)) return new _(obj);
+    this._wrapped = obj;
+  };
+
+  // Export the Underscore object for **Node.js**, with
+  // backwards-compatibility for the old `require()` API. If we're in
+  // the browser, add `_` as a global object.
+  if (typeof exports !== 'undefined') {
+    if (typeof module !== 'undefined' && module.exports) {
+      exports = module.exports = _;
+    }
+    exports._ = _;
+  } else {
+    root._ = _;
+  }
+
+  // Current version.
+  _.VERSION = '1.7.0';
+
+  // Internal function that returns an efficient (for current engines) version
+  // of the passed-in callback, to be repeatedly applied in other Underscore
+  // functions.
+  var createCallback = function(func, context, argCount) {
+    if (context === void 0) return func;
+    switch (argCount == null ? 3 : argCount) {
+      case 1: return function(value) {
+        return func.call(context, value);
+      };
+      case 2: return function(value, other) {
+        return func.call(context, value, other);
+      };
+      case 3: return function(value, index, collection) {
+        return func.call(context, value, index, collection);
+      };
+      case 4: return function(accumulator, value, index, collection) {
+        return func.call(context, accumulator, value, index, collection);
+      };
+    }
+    return function() {
+      return func.apply(context, arguments);
+    };
+  };
+
+  // A mostly-internal function to generate callbacks that can be applied
+  // to each element in a collection, returning the desired result — either
+  // identity, an arbitrary callback, a property matcher, or a property accessor.
+  _.iteratee = function(value, context, argCount) {
+    if (value == null) return _.identity;
+    if (_.isFunction(value)) return createCallback(value, context, argCount);
+    if (_.isObject(value)) return _.matches(value);
+    return _.property(value);
+  };
+
+  // Collection Functions
+  // --------------------
+
+  // The cornerstone, an `each` implementation, aka `forEach`.
+  // Handles raw objects in addition to array-likes. Treats all
+  // sparse array-likes as if they were dense.
+  _.each = _.forEach = function(obj, iteratee, context) {
+    if (obj == null) return obj;
+    iteratee = createCallback(iteratee, context);
+    var i, length = obj.length;
+    if (length === +length) {
+      for (i = 0; i < length; i++) {
+        iteratee(obj[i], i, obj);
+      }
+    } else {
+      var keys = _.keys(obj);
+      for (i = 0, length = keys.length; i < length; i++) {
+        iteratee(obj[keys[i]], keys[i], obj);
+      }
+    }
+    return obj;
+  };
+
+  // Return the results of applying the iteratee to each element.
+  _.map = _.collect = function(obj, iteratee, context) {
+    if (obj == null) return [];
+    iteratee = _.iteratee(iteratee, context);
+    var keys = obj.length !== +obj.length && _.keys(obj),
+        length = (keys || obj).length,
+        results = Array(length),
+        currentKey;
+    for (var index = 0; index < length; index++) {
+      currentKey = keys ? keys[index] : index;
+      results[index] = iteratee(obj[currentKey], currentKey, obj);
+    }
+    return results;
+  };
+
+  var reduceError = 'Reduce of empty array with no initial value';
+
+  // **Reduce** builds up a single result from a list of values, aka `inject`,
+  // or `foldl`.
+  _.reduce = _.foldl = _.inject = function(obj, iteratee, memo, context) {
+    if (obj == null) obj = [];
+    iteratee = createCallback(iteratee, context, 4);
+    var keys = obj.length !== +obj.length && _.keys(obj),
+        length = (keys || obj).length,
+        index = 0, currentKey;
+    if (arguments.length < 3) {
+      if (!length) throw new TypeError(reduceError);
+      memo = obj[keys ? keys[index++] : index++];
+    }
+    for (; index < length; index++) {
+      currentKey = keys ? keys[index] : index;
+      memo = iteratee(memo, obj[currentKey], currentKey, obj);
+    }
+    return memo;
+  };
+
+  // The right-associative version of reduce, also known as `foldr`.
+  _.reduceRight = _.foldr = function(obj, iteratee, memo, context) {
+    if (obj == null) obj = [];
+    iteratee = createCallback(iteratee, context, 4);
+    var keys = obj.length !== + obj.length && _.keys(obj),
+        index = (keys || obj).length,
+        currentKey;
+    if (arguments.length < 3) {
+      if (!index) throw new TypeError(reduceError);
+      memo = obj[keys ? keys[--index] : --index];
+    }
+    while (index--) {
+      currentKey = keys ? keys[index] : index;
+      memo = iteratee(memo, obj[currentKey], currentKey, obj);
+    }
+    return memo;
+  };
+
+  // Return the first value which passes a truth test. Aliased as `detect`.
+  _.find = _.detect = function(obj, predicate, context) {
+    var result;
+    predicate = _.iteratee(predicate, context);
+    _.some(obj, function(value, index, list) {
+      if (predicate(value, index, list)) {
+        result = value;
+        return true;
+      }
+    });
+    return result;
+  };
+
+  // Return all the elements that pass a truth test.
+  // Aliased as `select`.
+  _.filter = _.select = function(obj, predicate, context) {
+    var results = [];
+    if (obj == null) return results;
+    predicate = _.iteratee(predicate, context);
+    _.each(obj, function(value, index, list) {
+      if (predicate(value, index, list)) results.push(value);
+    });
+    return results;
+  };
+
+  // Return all the elements for which a truth test fails.
+  _.reject = function(obj, predicate, context) {
+    return _.filter(obj, _.negate(_.iteratee(predicate)), context);
+  };
+
+  // Determine whether all of the elements match a truth test.
+  // Aliased as `all`.
+  _.every = _.all = function(obj, predicate, context) {
+    if (obj == null) return true;
+    predicate = _.iteratee(predicate, context);
+    var keys = obj.length !== +obj.length && _.keys(obj),
+        length = (keys || obj).length,
+        index, currentKey;
+    for (index = 0; index < length; index++) {
+      currentKey = keys ? keys[index] : index;
+      if (!predicate(obj[currentKey], currentKey, obj)) return false;
+    }
+    return true;
+  };
+
+  // Determine if at least one element in the object matches a truth test.
+  // Aliased as `any`.
+  _.some = _.any = function(obj, predicate, context) {
+    if (obj == null) return false;
+    predicate = _.iteratee(predicate, context);
+    var keys = obj.length !== +obj.length && _.keys(obj),
+        length = (keys || obj).length,
+        index, currentKey;
+    for (index = 0; index < length; index++) {
+      currentKey = keys ? keys[index] : index;
+      if (predicate(obj[currentKey], currentKey, obj)) return true;
+    }
+    return false;
+  };
+
+  // Determine if the array or object contains a given value (using `===`).
+  // Aliased as `include`.
+  _.contains = _.include = function(obj, target) {
+    if (obj == null) return false;
+    if (obj.length !== +obj.length) obj = _.values(obj);
+    return _.indexOf(obj, target) >= 0;
+  };
+
+  // Invoke a method (with arguments) on every item in a collection.
+  _.invoke = function(obj, method) {
+    var args = slice.call(arguments, 2);
+    var isFunc = _.isFunction(method);
+    return _.map(obj, function(value) {
+      return (isFunc ? method : value[method]).apply(value, args);
+    });
+  };
+
+  // Convenience version of a common use case of `map`: fetching a property.
+  _.pluck = function(obj, key) {
+    return _.map(obj, _.property(key));
+  };
+
+  // Convenience version of a common use case of `filter`: selecting only objects
+  // containing specific `key:value` pairs.
+  _.where = function(obj, attrs) {
+    return _.filter(obj, _.matches(attrs));
+  };
+
+  // Convenience version of a common use case of `find`: getting the first object
+  // containing specific `key:value` pairs.
+  _.findWhere = function(obj, attrs) {
+    return _.find(obj, _.matches(attrs));
+  };
+
+  // Return the maximum element (or element-based computation).
+  _.max = function(obj, iteratee, context) {
+    var result = -Infinity, lastComputed = -Infinity,
+        value, computed;
+    if (iteratee == null && obj != null) {
+      obj = obj.length === +obj.length ? obj : _.values(obj);
+      for (var i = 0, length = obj.length; i < length; i++) {
+        value = obj[i];
+        if (value > result) {
+          result = value;
+        }
+      }
+    } else {
+      iteratee = _.iteratee(iteratee, context);
+      _.each(obj, function(value, index, list) {
+        computed = iteratee(value, index, list);
+        if (computed > lastComputed || computed === -Infinity && result === -Infinity) {
+          result = value;
+          lastComputed = computed;
+        }
+      });
+    }
+    return result;
+  };
+
+  // Return the minimum element (or element-based computation).
+  _.min = function(obj, iteratee, context) {
+    var result = Infinity, lastComputed = Infinity,
+        value, computed;
+    if (iteratee == null && obj != null) {
+      obj = obj.length === +obj.length ? obj : _.values(obj);
+      for (var i = 0, length = obj.length; i < length; i++) {
+        value = obj[i];
+        if (value < result) {
+          result = value;
+        }
+      }
+    } else {
+      iteratee = _.iteratee(iteratee, context);
+      _.each(obj, function(value, index, list) {
+        computed = iteratee(value, index, list);
+        if (computed < lastComputed || computed === Infinity && result === Infinity) {
+          result = value;
+          lastComputed = computed;
+        }
+      });
+    }
+    return result;
+  };
+
+  // Shuffle a collection, using the modern version of the
+  // [Fisher-Yates shuffle](http://en.wikipedia.org/wiki/Fisher–Yates_shuffle).
+  _.shuffle = function(obj) {
+    var set = obj && obj.length === +obj.length ? obj : _.values(obj);
+    var length = set.length;
+    var shuffled = Array(length);
+    for (var index = 0, rand; index < length; index++) {
+      rand = _.random(0, index);
+      if (rand !== index) shuffled[index] = shuffled[rand];
+      shuffled[rand] = set[index];
+    }
+    return shuffled;
+  };
+
+  // Sample **n** random values from a collection.
+  // If **n** is not specified, returns a single random element.
+  // The internal `guard` argument allows it to work with `map`.
+  _.sample = function(obj, n, guard) {
+    if (n == null || guard) {
+      if (obj.length !== +obj.length) obj = _.values(obj);
+      return obj[_.random(obj.length - 1)];
+    }
+    return _.shuffle(obj).slice(0, Math.max(0, n));
+  };
+
+  // Sort the object's values by a criterion produced by an iteratee.
+  _.sortBy = function(obj, iteratee, context) {
+    iteratee = _.iteratee(iteratee, context);
+    return _.pluck(_.map(obj, function(value, index, list) {
+      return {
+        value: value,
+        index: index,
+        criteria: iteratee(value, index, list)
+      };
+    }).sort(function(left, right) {
+      var a = left.criteria;
+      var b = right.criteria;
+      if (a !== b) {
+        if (a > b || a === void 0) return 1;
+        if (a < b || b === void 0) return -1;
+      }
+      return left.index - right.index;
+    }), 'value');
+  };
+
+  // An internal function used for aggregate "group by" operations.
+  var group = function(behavior) {
+    return function(obj, iteratee, context) {
+      var result = {};
+      iteratee = _.iteratee(iteratee, context);
+      _.each(obj, function(value, index) {
+        var key = iteratee(value, index, obj);
+        behavior(result, value, key);
+      });
+      return result;
+    };
+  };
+
+  // Groups the object's values by a criterion. Pass either a string attribute
+  // to group by, or a function that returns the criterion.
+  _.groupBy = group(function(result, value, key) {
+    if (_.has(result, key)) result[key].push(value); else result[key] = [value];
+  });
+
+  // Indexes the object's values by a criterion, similar to `groupBy`, but for
+  // when you know that your index values will be unique.
+  _.indexBy = group(function(result, value, key) {
+    result[key] = value;
+  });
+
+  // Counts instances of an object that group by a certain criterion. Pass
+  // either a string attribute to count by, or a function that returns the
+  // criterion.
+  _.countBy = group(function(result, value, key) {
+    if (_.has(result, key)) result[key]++; else result[key] = 1;
+  });
+
+  // Use a comparator function to figure out the smallest index at which
+  // an object should be inserted so as to maintain order. Uses binary search.
+  _.sortedIndex = function(array, obj, iteratee, context) {
+    iteratee = _.iteratee(iteratee, context, 1);
+    var value = iteratee(obj);
+    var low = 0, high = array.length;
+    while (low < high) {
+      var mid = low + high >>> 1;
+      if (iteratee(array[mid]) < value) low = mid + 1; else high = mid;
+    }
+    return low;
+  };
+
+  // Safely create a real, live array from anything iterable.
+  _.toArray = function(obj) {
+    if (!obj) return [];
+    if (_.isArray(obj)) return slice.call(obj);
+    if (obj.length === +obj.length) return _.map(obj, _.identity);
+    return _.values(obj);
+  };
+
+  // Return the number of elements in an object.
+  _.size = function(obj) {
+    if (obj == null) return 0;
+    return obj.length === +obj.length ? obj.length : _.keys(obj).length;
+  };
+
+  // Split a collection into two arrays: one whose elements all satisfy the given
+  // predicate, and one whose elements all do not satisfy the predicate.
+  _.partition = function(obj, predicate, context) {
+    predicate = _.iteratee(predicate, context);
+    var pass = [], fail = [];
+    _.each(obj, function(value, key, obj) {
+      (predicate(value, key, obj) ? pass : fail).push(value);
+    });
+    return [pass, fail];
+  };
+
+  // Array Functions
+  // ---------------
+
+  // Get the first element of an array. Passing **n** will return the first N
+  // values in the array. Aliased as `head` and `take`. The **guard** check
+  // allows it to work with `_.map`.
+  _.first = _.head = _.take = function(array, n, guard) {
+    if (array == null) return void 0;
+    if (n == null || guard) return array[0];
+    if (n < 0) return [];
+    return slice.call(array, 0, n);
+  };
+
+  // Returns everything but the last entry of the array. Especially useful on
+  // the arguments object. Passing **n** will return all the values in
+  // the array, excluding the last N. The **guard** check allows it to work with
+  // `_.map`.
+  _.initial = function(array, n, guard) {
+    return slice.call(array, 0, Math.max(0, array.length - (n == null || guard ? 1 : n)));
+  };
+
+  // Get the last element of an array. Passing **n** will return the last N
+  // values in the array. The **guard** check allows it to work with `_.map`.
+  _.last = function(array, n, guard) {
+    if (array == null) return void 0;
+    if (n == null || guard) return array[array.length - 1];
+    return slice.call(array, Math.max(array.length - n, 0));
+  };
+
+  // Returns everything but the first entry of the array. Aliased as `tail` and `drop`.
+  // Especially useful on the arguments object. Passing an **n** will return
+  // the rest N values in the array. The **guard**
+  // check allows it to work with `_.map`.
+  _.rest = _.tail = _.drop = function(array, n, guard) {
+    return slice.call(array, n == null || guard ? 1 : n);
+  };
+
+  // Trim out all falsy values from an array.
+  _.compact = function(array) {
+    return _.filter(array, _.identity);
+  };
+
+  // Internal implementation of a recursive `flatten` function.
+  var flatten = function(input, shallow, strict, output) {
+    if (shallow && _.every(input, _.isArray)) {
+      return concat.apply(output, input);
+    }
+    for (var i = 0, length = input.length; i < length; i++) {
+      var value = input[i];
+      if (!_.isArray(value) && !_.isArguments(value)) {
+        if (!strict) output.push(value);
+      } else if (shallow) {
+        push.apply(output, value);
+      } else {
+        flatten(value, shallow, strict, output);
+      }
+    }
+    return output;
+  };
+
+  // Flatten out an array, either recursively (by default), or just one level.
+  _.flatten = function(array, shallow) {
+    return flatten(array, shallow, false, []);
+  };
+
+  // Return a version of the array that does not contain the specified value(s).
+  _.without = function(array) {
+    return _.difference(array, slice.call(arguments, 1));
+  };
+
+  // Produce a duplicate-free version of the array. If the array has already
+  // been sorted, you have the option of using a faster algorithm.
+  // Aliased as `unique`.
+  _.uniq = _.unique = function(array, isSorted, iteratee, context) {
+    if (array == null) return [];
+    if (!_.isBoolean(isSorted)) {
+      context = iteratee;
+      iteratee = isSorted;
+      isSorted = false;
+    }
+    if (iteratee != null) iteratee = _.iteratee(iteratee, context);
+    var result = [];
+    var seen = [];
+    for (var i = 0, length = array.length; i < length; i++) {
+      var value = array[i];
+      if (isSorted) {
+        if (!i || seen !== value) result.push(value);
+        seen = value;
+      } else if (iteratee) {
+        var computed = iteratee(value, i, array);
+        if (_.indexOf(seen, computed) < 0) {
+          seen.push(computed);
+          result.push(value);
+        }
+      } else if (_.indexOf(result, value) < 0) {
+        result.push(value);
+      }
+    }
+    return result;
+  };
+
+  // Produce an array that contains the union: each distinct element from all of
+  // the passed-in arrays.
+  _.union = function() {
+    return _.uniq(flatten(arguments, true, true, []));
+  };
+
+  // Produce an array that contains every item shared between all the
+  // passed-in arrays.
+  _.intersection = function(array) {
+    if (array == null) return [];
+    var result = [];
+    var argsLength = arguments.length;
+    for (var i = 0, length = array.length; i < length; i++) {
+      var item = array[i];
+      if (_.contains(result, item)) continue;
+      for (var j = 1; j < argsLength; j++) {
+        if (!_.contains(arguments[j], item)) break;
+      }
+      if (j === argsLength) result.push(item);
+    }
+    return result;
+  };
+
+  // Take the difference between one array and a number of other arrays.
+  // Only the elements present in just the first array will remain.
+  _.difference = function(array) {
+    var rest = flatten(slice.call(arguments, 1), true, true, []);
+    return _.filter(array, function(value){
+      return !_.contains(rest, value);
+    });
+  };
+
+  // Zip together multiple lists into a single array -- elements that share
+  // an index go together.
+  _.zip = function(array) {
+    if (array == null) return [];
+    var length = _.max(arguments, 'length').length;
+    var results = Array(length);
+    for (var i = 0; i < length; i++) {
+      results[i] = _.pluck(arguments, i);
+    }
+    return results;
+  };
+
+  // Converts lists into objects. Pass either a single array of `[key, value]`
+  // pairs, or two parallel arrays of the same length -- one of keys, and one of
+  // the corresponding values.
+  _.object = function(list, values) {
+    if (list == null) return {};
+    var result = {};
+    for (var i = 0, length = list.length; i < length; i++) {
+      if (values) {
+        result[list[i]] = values[i];
+      } else {
+        result[list[i][0]] = list[i][1];
+      }
+    }
+    return result;
+  };
+
+  // Return the position of the first occurrence of an item in an array,
+  // or -1 if the item is not included in the array.
+  // If the array is large and already in sort order, pass `true`
+  // for **isSorted** to use binary search.
+  _.indexOf = function(array, item, isSorted) {
+    if (array == null) return -1;
+    var i = 0, length = array.length;
+    if (isSorted) {
+      if (typeof isSorted == 'number') {
+        i = isSorted < 0 ? Math.max(0, length + isSorted) : isSorted;
+      } else {
+        i = _.sortedIndex(array, item);
+        return array[i] === item ? i : -1;
+      }
+    }
+    for (; i < length; i++) if (array[i] === item) return i;
+    return -1;
+  };
+
+  _.lastIndexOf = function(array, item, from) {
+    if (array == null) return -1;
+    var idx = array.length;
+    if (typeof from == 'number') {
+      idx = from < 0 ? idx + from + 1 : Math.min(idx, from + 1);
+    }
+    while (--idx >= 0) if (array[idx] === item) return idx;
+    return -1;
+  };
+
+  // Generate an integer Array containing an arithmetic progression. A port of
+  // the native Python `range()` function. See
+  // [the Python documentation](http://docs.python.org/library/functions.html#range).
+  _.range = function(start, stop, step) {
+    if (arguments.length <= 1) {
+      stop = start || 0;
+      start = 0;
+    }
+    step = step || 1;
+
+    var length = Math.max(Math.ceil((stop - start) / step), 0);
+    var range = Array(length);
+
+    for (var idx = 0; idx < length; idx++, start += step) {
+      range[idx] = start;
+    }
+
+    return range;
+  };
+
+  // Function (ahem) Functions
+  // ------------------
+
+  // Reusable constructor function for prototype setting.
+  var Ctor = function(){};
+
+  // Create a function bound to a given object (assigning `this`, and arguments,
+  // optionally). Delegates to **ECMAScript 5**'s native `Function.bind` if
+  // available.
+  _.bind = function(func, context) {
+    var args, bound;
+    if (nativeBind && func.bind === nativeBind) return nativeBind.apply(func, slice.call(arguments, 1));
+    if (!_.isFunction(func)) throw new TypeError('Bind must be called on a function');
+    args = slice.call(arguments, 2);
+    bound = function() {
+      if (!(this instanceof bound)) return func.apply(context, args.concat(slice.call(arguments)));
+      Ctor.prototype = func.prototype;
+      var self = new Ctor;
+      Ctor.prototype = null;
+      var result = func.apply(self, args.concat(slice.call(arguments)));
+      if (_.isObject(result)) return result;
+      return self;
+    };
+    return bound;
+  };
+
+  // Partially apply a function by creating a version that has had some of its
+  // arguments pre-filled, without changing its dynamic `this` context. _ acts
+  // as a placeholder, allowing any combination of arguments to be pre-filled.
+  _.partial = function(func) {
+    var boundArgs = slice.call(arguments, 1);
+    return function() {
+      var position = 0;
+      var args = boundArgs.slice();
+      for (var i = 0, length = args.length; i < length; i++) {
+        if (args[i] === _) args[i] = arguments[position++];
+      }
+      while (position < arguments.length) args.push(arguments[position++]);
+      return func.apply(this, args);
+    };
+  };
+
+  // Bind a number of an object's methods to that object. Remaining arguments
+  // are the method names to be bound. Useful for ensuring that all callbacks
+  // defined on an object belong to it.
+  _.bindAll = function(obj) {
+    var i, length = arguments.length, key;
+    if (length <= 1) throw new Error('bindAll must be passed function names');
+    for (i = 1; i < length; i++) {
+      key = arguments[i];
+      obj[key] = _.bind(obj[key], obj);
+    }
+    return obj;
+  };
+
+  // Memoize an expensive function by storing its results.
+  _.memoize = function(func, hasher) {
+    var memoize = function(key) {
+      var cache = memoize.cache;
+      var address = hasher ? hasher.apply(this, arguments) : key;
+      if (!_.has(cache, address)) cache[address] = func.apply(this, arguments);
+      return cache[address];
+    };
+    memoize.cache = {};
+    return memoize;
+  };
+
+  // Delays a function for the given number of milliseconds, and then calls
+  // it with the arguments supplied.
+  _.delay = function(func, wait) {
+    var args = slice.call(arguments, 2);
+    return setTimeout(function(){
+      return func.apply(null, args);
+    }, wait);
+  };
+
+  // Defers a function, scheduling it to run after the current call stack has
+  // cleared.
+  _.defer = function(func) {
+    return _.delay.apply(_, [func, 1].concat(slice.call(arguments, 1)));
+  };
+
+  // Returns a function, that, when invoked, will only be triggered at most once
+  // during a given window of time. Normally, the throttled function will run
+  // as much as it can, without ever going more than once per `wait` duration;
+  // but if you'd like to disable the execution on the leading edge, pass
+  // `{leading: false}`. To disable execution on the trailing edge, ditto.
+  _.throttle = function(func, wait, options) {
+    var context, args, result;
+    var timeout = null;
+    var previous = 0;
+    if (!options) options = {};
+    var later = function() {
+      previous = options.leading === false ? 0 : _.now();
+      timeout = null;
+      result = func.apply(context, args);
+      if (!timeout) context = args = null;
+    };
+    return function() {
+      var now = _.now();
+      if (!previous && options.leading === false) previous = now;
+      var remaining = wait - (now - previous);
+      context = this;
+      args = arguments;
+      if (remaining <= 0 || remaining > wait) {
+        clearTimeout(timeout);
+        timeout = null;
+        previous = now;
+        result = func.apply(context, args);
+        if (!timeout) context = args = null;
+      } else if (!timeout && options.trailing !== false) {
+        timeout = setTimeout(later, remaining);
+      }
+      return result;
+    };
+  };
+
+  // Returns a function, that, as long as it continues to be invoked, will not
+  // be triggered. The function will be called after it stops being called for
+  // N milliseconds. If `immediate` is passed, trigger the function on the
+  // leading edge, instead of the trailing.
+  _.debounce = function(func, wait, immediate) {
+    var timeout, args, context, timestamp, result;
+
+    var later = function() {
+      var last = _.now() - timestamp;
+
+      if (last < wait && last > 0) {
+        timeout = setTimeout(later, wait - last);
+      } else {
+        timeout = null;
+        if (!immediate) {
+          result = func.apply(context, args);
+          if (!timeout) context = args = null;
+        }
+      }
+    };
+
+    return function() {
+      context = this;
+      args = arguments;
+      timestamp = _.now();
+      var callNow = immediate && !timeout;
+      if (!timeout) timeout = setTimeout(later, wait);
+      if (callNow) {
+        result = func.apply(context, args);
+        context = args = null;
+      }
+
+      return result;
+    };
+  };
+
+  // Returns the first function passed as an argument to the second,
+  // allowing you to adjust arguments, run code before and after, and
+  // conditionally execute the original function.
+  _.wrap = function(func, wrapper) {
+    return _.partial(wrapper, func);
+  };
+
+  // Returns a negated version of the passed-in predicate.
+  _.negate = function(predicate) {
+    return function() {
+      return !predicate.apply(this, arguments);
+    };
+  };
+
+  // Returns a function that is the composition of a list of functions, each
+  // consuming the return value of the function that follows.
+  _.compose = function() {
+    var args = arguments;
+    var start = args.length - 1;
+    return function() {
+      var i = start;
+      var result = args[start].apply(this, arguments);
+      while (i--) result = args[i].call(this, result);
+      return result;
+    };
+  };
+
+  // Returns a function that will only be executed after being called N times.
+  _.after = function(times, func) {
+    return function() {
+      if (--times < 1) {
+        return func.apply(this, arguments);
+      }
+    };
+  };
+
+  // Returns a function that will only be executed before being called N times.
+  _.before = function(times, func) {
+    var memo;
+    return function() {
+      if (--times > 0) {
+        memo = func.apply(this, arguments);
+      } else {
+        func = null;
+      }
+      return memo;
+    };
+  };
+
+  // Returns a function that will be executed at most one time, no matter how
+  // often you call it. Useful for lazy initialization.
+  _.once = _.partial(_.before, 2);
+
+  // Object Functions
+  // ----------------
+
+  // Retrieve the names of an object's properties.
+  // Delegates to **ECMAScript 5**'s native `Object.keys`
+  _.keys = function(obj) {
+    if (!_.isObject(obj)) return [];
+    if (nativeKeys) return nativeKeys(obj);
+    var keys = [];
+    for (var key in obj) if (_.has(obj, key)) keys.push(key);
+    return keys;
+  };
+
+  // Retrieve the values of an object's properties.
+  _.values = function(obj) {
+    var keys = _.keys(obj);
+    var length = keys.length;
+    var values = Array(length);
+    for (var i = 0; i < length; i++) {
+      values[i] = obj[keys[i]];
+    }
+    return values;
+  };
+
+  // Convert an object into a list of `[key, value]` pairs.
+  _.pairs = function(obj) {
+    var keys = _.keys(obj);
+    var length = keys.length;
+    var pairs = Array(length);
+    for (var i = 0; i < length; i++) {
+      pairs[i] = [keys[i], obj[keys[i]]];
+    }
+    return pairs;
+  };
+
+  // Invert the keys and values of an object. The values must be serializable.
+  _.invert = function(obj) {
+    var result = {};
+    var keys = _.keys(obj);
+    for (var i = 0, length = keys.length; i < length; i++) {
+      result[obj[keys[i]]] = keys[i];
+    }
+    return result;
+  };
+
+  // Return a sorted list of the function names available on the object.
+  // Aliased as `methods`
+  _.functions = _.methods = function(obj) {
+    var names = [];
+    for (var key in obj) {
+      if (_.isFunction(obj[key])) names.push(key);
+    }
+    return names.sort();
+  };
+
+  // Extend a given object with all the properties in passed-in object(s).
+  _.extend = function(obj) {
+    if (!_.isObject(obj)) return obj;
+    var source, prop;
+    for (var i = 1, length = arguments.length; i < length; i++) {
+      source = arguments[i];
+      for (prop in source) {
+        if (hasOwnProperty.call(source, prop)) {
+            obj[prop] = source[prop];
+        }
+      }
+    }
+    return obj;
+  };
+
+  // Return a copy of the object only containing the whitelisted properties.
+  _.pick = function(obj, iteratee, context) {
+    var result = {}, key;
+    if (obj == null) return result;
+    if (_.isFunction(iteratee)) {
+      iteratee = createCallback(iteratee, context);
+      for (key in obj) {
+        var value = obj[key];
+        if (iteratee(value, key, obj)) result[key] = value;
+      }
+    } else {
+      var keys = concat.apply([], slice.call(arguments, 1));
+      obj = new Object(obj);
+      for (var i = 0, length = keys.length; i < length; i++) {
+        key = keys[i];
+        if (key in obj) result[key] = obj[key];
+      }
+    }
+    return result;
+  };
+
+   // Return a copy of the object without the blacklisted properties.
+  _.omit = function(obj, iteratee, context) {
+    if (_.isFunction(iteratee)) {
+      iteratee = _.negate(iteratee);
+    } else {
+      var keys = _.map(concat.apply([], slice.call(arguments, 1)), String);
+      iteratee = function(value, key) {
+        return !_.contains(keys, key);
+      };
+    }
+    return _.pick(obj, iteratee, context);
+  };
+
+  // Fill in a given object with default properties.
+  _.defaults = function(obj) {
+    if (!_.isObject(obj)) return obj;
+    for (var i = 1, length = arguments.length; i < length; i++) {
+      var source = arguments[i];
+      for (var prop in source) {
+        if (obj[prop] === void 0) obj[prop] = source[prop];
+      }
+    }
+    return obj;
+  };
+
+  // Create a (shallow-cloned) duplicate of an object.
+  _.clone = function(obj) {
+    if (!_.isObject(obj)) return obj;
+    return _.isArray(obj) ? obj.slice() : _.extend({}, obj);
+  };
+
+  // Invokes interceptor with the obj, and then returns obj.
+  // The primary purpose of this method is to "tap into" a method chain, in
+  // order to perform operations on intermediate results within the chain.
+  _.tap = function(obj, interceptor) {
+    interceptor(obj);
+    return obj;
+  };
+
+  // Internal recursive comparison function for `isEqual`.
+  var eq = function(a, b, aStack, bStack) {
+    // Identical objects are equal. `0 === -0`, but they aren't identical.
+    // See the [Harmony `egal` proposal](http://wiki.ecmascript.org/doku.php?id=harmony:egal).
+    if (a === b) return a !== 0 || 1 / a === 1 / b;
+    // A strict comparison is necessary because `null == undefined`.
+    if (a == null || b == null) return a === b;
+    // Unwrap any wrapped objects.
+    if (a instanceof _) a = a._wrapped;
+    if (b instanceof _) b = b._wrapped;
+    // Compare `[[Class]]` names.
+    var className = toString.call(a);
+    if (className !== toString.call(b)) return false;
+    switch (className) {
+      // Strings, numbers, regular expressions, dates, and booleans are compared by value.
+      case '[object RegExp]':
+      // RegExps are coerced to strings for comparison (Note: '' + /a/i === '/a/i')
+      case '[object String]':
+        // Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is
+        // equivalent to `new String("5")`.
+        return '' + a === '' + b;
+      case '[object Number]':
+        // `NaN`s are equivalent, but non-reflexive.
+        // Object(NaN) is equivalent to NaN
+        if (+a !== +a) return +b !== +b;
+        // An `egal` comparison is performed for other numeric values.
+        return +a === 0 ? 1 / +a === 1 / b : +a === +b;
+      case '[object Date]':
+      case '[object Boolean]':
+        // Coerce dates and booleans to numeric primitive values. Dates are compared by their
+        // millisecond representations. Note that invalid dates with millisecond representations
+        // of `NaN` are not equivalent.
+        return +a === +b;
+    }
+    if (typeof a != 'object' || typeof b != 'object') return false;
+    // Assume equality for cyclic structures. The algorithm for detecting cyclic
+    // structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`.
+    var length = aStack.length;
+    while (length--) {
+      // Linear search. Performance is inversely proportional to the number of
+      // unique nested structures.
+      if (aStack[length] === a) return bStack[length] === b;
+    }
+    // Objects with different constructors are not equivalent, but `Object`s
+    // from different frames are.
+    var aCtor = a.constructor, bCtor = b.constructor;
+    if (
+      aCtor !== bCtor &&
+      // Handle Object.create(x) cases
+      'constructor' in a && 'constructor' in b &&
+      !(_.isFunction(aCtor) && aCtor instanceof aCtor &&
+        _.isFunction(bCtor) && bCtor instanceof bCtor)
+    ) {
+      return false;
+    }
+    // Add the first object to the stack of traversed objects.
+    aStack.push(a);
+    bStack.push(b);
+    var size, result;
+    // Recursively compare objects and arrays.
+    if (className === '[object Array]') {
+      // Compare array lengths to determine if a deep comparison is necessary.
+      size = a.length;
+      result = size === b.length;
+      if (result) {
+        // Deep compare the contents, ignoring non-numeric properties.
+        while (size--) {
+          if (!(result = eq(a[size], b[size], aStack, bStack))) break;
+        }
+      }
+    } else {
+      // Deep compare objects.
+      var keys = _.keys(a), key;
+      size = keys.length;
+      // Ensure that both objects contain the same number of properties before comparing deep equality.
+      result = _.keys(b).length === size;
+      if (result) {
+        while (size--) {
+          // Deep compare each member
+          key = keys[size];
+          if (!(result = _.has(b, key) && eq(a[key], b[key], aStack, bStack))) break;
+        }
+      }
+    }
+    // Remove the first object from the stack of traversed objects.
+    aStack.pop();
+    bStack.pop();
+    return result;
+  };
+
+  // Perform a deep comparison to check if two objects are equal.
+  _.isEqual = function(a, b) {
+    return eq(a, b, [], []);
+  };
+
+  // Is a given array, string, or object empty?
+  // An "empty" object has no enumerable own-properties.
+  _.isEmpty = function(obj) {
+    if (obj == null) return true;
+    if (_.isArray(obj) || _.isString(obj) || _.isArguments(obj)) return obj.length === 0;
+    for (var key in obj) if (_.has(obj, key)) return false;
+    return true;
+  };
+
+  // Is a given value a DOM element?
+  _.isElement = function(obj) {
+    return !!(obj && obj.nodeType === 1);
+  };
+
+  // Is a given value an array?
+  // Delegates to ECMA5's native Array.isArray
+  _.isArray = nativeIsArray || function(obj) {
+    return toString.call(obj) === '[object Array]';
+  };
+
+  // Is a given variable an object?
+  _.isObject = function(obj) {
+    var type = typeof obj;
+    return type === 'function' || type === 'object' && !!obj;
+  };
+
+  // Add some isType methods: isArguments, isFunction, isString, isNumber, isDate, isRegExp.
+  _.each(['Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp'], function(name) {
+    _['is' + name] = function(obj) {
+      return toString.call(obj) === '[object ' + name + ']';
+    };
+  });
+
+  // Define a fallback version of the method in browsers (ahem, IE), where
+  // there isn't any inspectable "Arguments" type.
+  if (!_.isArguments(arguments)) {
+    _.isArguments = function(obj) {
+      return _.has(obj, 'callee');
+    };
+  }
+
+  // Optimize `isFunction` if appropriate. Work around an IE 11 bug.
+  if (typeof /./ !== 'function') {
+    _.isFunction = function(obj) {
+      return typeof obj == 'function' || false;
+    };
+  }
+
+  // Is a given object a finite number?
+  _.isFinite = function(obj) {
+    return isFinite(obj) && !isNaN(parseFloat(obj));
+  };
+
+  // Is the given value `NaN`? (NaN is the only number which does not equal itself).
+  _.isNaN = function(obj) {
+    return _.isNumber(obj) && obj !== +obj;
+  };
+
+  // Is a given value a boolean?
+  _.isBoolean = function(obj) {
+    return obj === true || obj === false || toString.call(obj) === '[object Boolean]';
+  };
+
+  // Is a given value equal to null?
+  _.isNull = function(obj) {
+    return obj === null;
+  };
+
+  // Is a given variable undefined?
+  _.isUndefined = function(obj) {
+    return obj === void 0;
+  };
+
+  // Shortcut function for checking if an object has a given property directly
+  // on itself (in other words, not on a prototype).
+  _.has = function(obj, key) {
+    return obj != null && hasOwnProperty.call(obj, key);
+  };
+
+  // Utility Functions
+  // -----------------
+
+  // Run Underscore.js in *noConflict* mode, returning the `_` variable to its
+  // previous owner. Returns a reference to the Underscore object.
+  _.noConflict = function() {
+    root._ = previousUnderscore;
+    return this;
+  };
+
+  // Keep the identity function around for default iteratees.
+  _.identity = function(value) {
+    return value;
+  };
+
+  _.constant = function(value) {
+    return function() {
+      return value;
+    };
+  };
+
+  _.noop = function(){};
+
+  _.property = function(key) {
+    return function(obj) {
+      return obj[key];
+    };
+  };
+
+  // Returns a predicate for checking whether an object has a given set of `key:value` pairs.
+  _.matches = function(attrs) {
+    var pairs = _.pairs(attrs), length = pairs.length;
+    return function(obj) {
+      if (obj == null) return !length;
+      obj = new Object(obj);
+      for (var i = 0; i < length; i++) {
+        var pair = pairs[i], key = pair[0];
+        if (pair[1] !== obj[key] || !(key in obj)) return false;
+      }
+      return true;
+    };
+  };
+
+  // Run a function **n** times.
+  _.times = function(n, iteratee, context) {
+    var accum = Array(Math.max(0, n));
+    iteratee = createCallback(iteratee, context, 1);
+    for (var i = 0; i < n; i++) accum[i] = iteratee(i);
+    return accum;
+  };
+
+  // Return a random integer between min and max (inclusive).
+  _.random = function(min, max) {
+    if (max == null) {
+      max = min;
+      min = 0;
+    }
+    return min + Math.floor(Math.random() * (max - min + 1));
+  };
+
+  // A (possibly faster) way to get the current timestamp as an integer.
+  _.now = Date.now || function() {
+    return new Date().getTime();
+  };
+
+   // List of HTML entities for escaping.
+  var escapeMap = {
+    '&': '&amp;',
+    '<': '&lt;',
+    '>': '&gt;',
+    '"': '&quot;',
+    "'": '&#x27;',
+    '`': '&#x60;'
+  };
+  var unescapeMap = _.invert(escapeMap);
+
+  // Functions for escaping and unescaping strings to/from HTML interpolation.
+  var createEscaper = function(map) {
+    var escaper = function(match) {
+      return map[match];
+    };
+    // Regexes for identifying a key that needs to be escaped
+    var source = '(?:' + _.keys(map).join('|') + ')';
+    var testRegexp = RegExp(source);
+    var replaceRegexp = RegExp(source, 'g');
+    return function(string) {
+      string = string == null ? '' : '' + string;
+      return testRegexp.test(string) ? string.replace(replaceRegexp, escaper) : string;
+    };
+  };
+  _.escape = createEscaper(escapeMap);
+  _.unescape = createEscaper(unescapeMap);
+
+  // If the value of the named `property` is a function then invoke it with the
+  // `object` as context; otherwise, return it.
+  _.result = function(object, property) {
+    if (object == null) return void 0;
+    var value = object[property];
+    return _.isFunction(value) ? object[property]() : value;
+  };
+
+  // Generate a unique integer id (unique within the entire client session).
+  // Useful for temporary DOM ids.
+  var idCounter = 0;
+  _.uniqueId = function(prefix) {
+    var id = ++idCounter + '';
+    return prefix ? prefix + id : id;
+  };
+
+  // By default, Underscore uses ERB-style template delimiters, change the
+  // following template settings to use alternative delimiters.
+  _.templateSettings = {
+    evaluate    : /<%([\s\S]+?)%>/g,
+    interpolate : /<%=([\s\S]+?)%>/g,
+    escape      : /<%-([\s\S]+?)%>/g
+  };
+
+  // When customizing `templateSettings`, if you don't want to define an
+  // interpolation, evaluation or escaping regex, we need one that is
+  // guaranteed not to match.
+  var noMatch = /(.)^/;
+
+  // Certain characters need to be escaped so that they can be put into a
+  // string literal.
+  var escapes = {
+    "'":      "'",
+    '\\':     '\\',
+    '\r':     'r',
+    '\n':     'n',
+    '\u2028': 'u2028',
+    '\u2029': 'u2029'
+  };
+
+  var escaper = /\\|'|\r|\n|\u2028|\u2029/g;
+
+  var escapeChar = function(match) {
+    return '\\' + escapes[match];
+  };
+
+  // JavaScript micro-templating, similar to John Resig's implementation.
+  // Underscore templating handles arbitrary delimiters, preserves whitespace,
+  // and correctly escapes quotes within interpolated code.
+  // NB: `oldSettings` only exists for backwards compatibility.
+  _.template = function(text, settings, oldSettings) {
+    if (!settings && oldSettings) settings = oldSettings;
+    settings = _.defaults({}, settings, _.templateSettings);
+
+    // Combine delimiters into one regular expression via alternation.
+    var matcher = RegExp([
+      (settings.escape || noMatch).source,
+      (settings.interpolate || noMatch).source,
+      (settings.evaluate || noMatch).source
+    ].join('|') + '|$', 'g');
+
+    // Compile the template source, escaping string literals appropriately.
+    var index = 0;
+    var source = "__p+='";
+    text.replace(matcher, function(match, escape, interpolate, evaluate, offset) {
+      source += text.slice(index, offset).replace(escaper, escapeChar);
+      index = offset + match.length;
+
+      if (escape) {
+        source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'";
+      } else if (interpolate) {
+        source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'";
+      } else if (evaluate) {
+        source += "';\n" + evaluate + "\n__p+='";
+      }
+
+      // Adobe VMs need the match returned to produce the correct offest.
+      return match;
+    });
+    source += "';\n";
+
+    // If a variable is not specified, place data values in local scope.
+    if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n';
+
+    source = "var __t,__p='',__j=Array.prototype.join," +
+      "print=function(){__p+=__j.call(arguments,'');};\n" +
+      source + 'return __p;\n';
+
+    try {
+      var render = new Function(settings.variable || 'obj', '_', source);
+    } catch (e) {
+      e.source = source;
+      throw e;
+    }
+
+    var template = function(data) {
+      return render.call(this, data, _);
+    };
+
+    // Provide the compiled source as a convenience for precompilation.
+    var argument = settings.variable || 'obj';
+    template.source = 'function(' + argument + '){\n' + source + '}';
+
+    return template;
+  };
+
+  // Add a "chain" function. Start chaining a wrapped Underscore object.
+  _.chain = function(obj) {
+    var instance = _(obj);
+    instance._chain = true;
+    return instance;
+  };
+
+  // OOP
+  // ---------------
+  // If Underscore is called as a function, it returns a wrapped object that
+  // can be used OO-style. This wrapper holds altered versions of all the
+  // underscore functions. Wrapped objects may be chained.
+
+  // Helper function to continue chaining intermediate results.
+  var result = function(obj) {
+    return this._chain ? _(obj).chain() : obj;
+  };
+
+  // Add your own custom functions to the Underscore object.
+  _.mixin = function(obj) {
+    _.each(_.functions(obj), function(name) {
+      var func = _[name] = obj[name];
+      _.prototype[name] = function() {
+        var args = [this._wrapped];
+        push.apply(args, arguments);
+        return result.call(this, func.apply(_, args));
+      };
+    });
+  };
+
+  // Add all of the Underscore functions to the wrapper object.
+  _.mixin(_);
+
+  // Add all mutator Array functions to the wrapper.
+  _.each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) {
+    var method = ArrayProto[name];
+    _.prototype[name] = function() {
+      var obj = this._wrapped;
+      method.apply(obj, arguments);
+      if ((name === 'shift' || name === 'splice') && obj.length === 0) delete obj[0];
+      return result.call(this, obj);
+    };
+  });
+
+  // Add all accessor Array functions to the wrapper.
+  _.each(['concat', 'join', 'slice'], function(name) {
+    var method = ArrayProto[name];
+    _.prototype[name] = function() {
+      return result.call(this, method.apply(this._wrapped, arguments));
+    };
+  });
+
+  // Extracts the result from a wrapped and chained object.
+  _.prototype.value = function() {
+    return this._wrapped;
+  };
+
+  // AMD registration happens at the end for compatibility with AMD loaders
+  // that may not enforce next-turn semantics on modules. Even though general
+  // practice for AMD registration is to be anonymous, underscore registers
+  // as a named module because, like jQuery, it is a base library that is
+  // popular enough to be bundled in a third party lib, but not be part of
+  // an AMD load request. Those cases could generate an error when an
+  // anonymous define() is called outside of a loader request.
+  if (typeof define === 'function' && define.amd) {
+    define('underscore', [], function() {
+      return _;
+    });
+  }
+}.call(this));
diff --git a/docs/html/_static/up-pressed.png b/docs/html/_static/up-pressed.png
new file mode 100644
index 00000000..99e72109
Binary files /dev/null and b/docs/html/_static/up-pressed.png differ
diff --git a/docs/html/_static/up.png b/docs/html/_static/up.png
new file mode 100644
index 00000000..26de002e
Binary files /dev/null and b/docs/html/_static/up.png differ
diff --git a/docs/html/_static/websupport.js b/docs/html/_static/websupport.js
new file mode 100644
index 00000000..ffd9b2bf
--- /dev/null
+++ b/docs/html/_static/websupport.js
@@ -0,0 +1,808 @@
+/*
+ * websupport.js
+ * ~~~~~~~~~~~~~
+ *
+ * sphinx.websupport utilties for all documentation.
+ *
+ * :copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
+ * :license: BSD, see LICENSE for details.
+ *
+ */
+
+(function($) {
+  $.fn.autogrow = function() {
+    return this.each(function() {
+    var textarea = this;
+
+    $.fn.autogrow.resize(textarea);
+
+    $(textarea)
+      .focus(function() {
+        textarea.interval = setInterval(function() {
+          $.fn.autogrow.resize(textarea);
+        }, 500);
+      })
+      .blur(function() {
+        clearInterval(textarea.interval);
+      });
+    });
+  };
+
+  $.fn.autogrow.resize = function(textarea) {
+    var lineHeight = parseInt($(textarea).css('line-height'), 10);
+    var lines = textarea.value.split('\n');
+    var columns = textarea.cols;
+    var lineCount = 0;
+    $.each(lines, function() {
+      lineCount += Math.ceil(this.length / columns) || 1;
+    });
+    var height = lineHeight * (lineCount + 1);
+    $(textarea).css('height', height);
+  };
+})(jQuery);
+
+(function($) {
+  var comp, by;
+
+  function init() {
+    initEvents();
+    initComparator();
+  }
+
+  function initEvents() {
+    $(document).on("click", 'a.comment-close', function(event) {
+      event.preventDefault();
+      hide($(this).attr('id').substring(2));
+    });
+    $(document).on("click", 'a.vote', function(event) {
+      event.preventDefault();
+      handleVote($(this));
+    });
+    $(document).on("click", 'a.reply', function(event) {
+      event.preventDefault();
+      openReply($(this).attr('id').substring(2));
+    });
+    $(document).on("click", 'a.close-reply', function(event) {
+      event.preventDefault();
+      closeReply($(this).attr('id').substring(2));
+    });
+    $(document).on("click", 'a.sort-option', function(event) {
+      event.preventDefault();
+      handleReSort($(this));
+    });
+    $(document).on("click", 'a.show-proposal', function(event) {
+      event.preventDefault();
+      showProposal($(this).attr('id').substring(2));
+    });
+    $(document).on("click", 'a.hide-proposal', function(event) {
+      event.preventDefault();
+      hideProposal($(this).attr('id').substring(2));
+    });
+    $(document).on("click", 'a.show-propose-change', function(event) {
+      event.preventDefault();
+      showProposeChange($(this).attr('id').substring(2));
+    });
+    $(document).on("click", 'a.hide-propose-change', function(event) {
+      event.preventDefault();
+      hideProposeChange($(this).attr('id').substring(2));
+    });
+    $(document).on("click", 'a.accept-comment', function(event) {
+      event.preventDefault();
+      acceptComment($(this).attr('id').substring(2));
+    });
+    $(document).on("click", 'a.delete-comment', function(event) {
+      event.preventDefault();
+      deleteComment($(this).attr('id').substring(2));
+    });
+    $(document).on("click", 'a.comment-markup', function(event) {
+      event.preventDefault();
+      toggleCommentMarkupBox($(this).attr('id').substring(2));
+    });
+  }
+
+  /**
+   * Set comp, which is a comparator function used for sorting and
+   * inserting comments into the list.
+   */
+  function setComparator() {
+    // If the first three letters are "asc", sort in ascending order
+    // and remove the prefix.
+    if (by.substring(0,3) == 'asc') {
+      var i = by.substring(3);
+      comp = function(a, b) { return a[i] - b[i]; };
+    } else {
+      // Otherwise sort in descending order.
+      comp = function(a, b) { return b[by] - a[by]; };
+    }
+
+    // Reset link styles and format the selected sort option.
+    $('a.sel').attr('href', '#').removeClass('sel');
+    $('a.by' + by).removeAttr('href').addClass('sel');
+  }
+
+  /**
+   * Create a comp function. If the user has preferences stored in
+   * the sortBy cookie, use those, otherwise use the default.
+   */
+  function initComparator() {
+    by = 'rating'; // Default to sort by rating.
+    // If the sortBy cookie is set, use that instead.
+    if (document.cookie.length > 0) {
+      var start = document.cookie.indexOf('sortBy=');
+      if (start != -1) {
+        start = start + 7;
+        var end = document.cookie.indexOf(";", start);
+        if (end == -1) {
+          end = document.cookie.length;
+          by = unescape(document.cookie.substring(start, end));
+        }
+      }
+    }
+    setComparator();
+  }
+
+  /**
+   * Show a comment div.
+   */
+  function show(id) {
+    $('#ao' + id).hide();
+    $('#ah' + id).show();
+    var context = $.extend({id: id}, opts);
+    var popup = $(renderTemplate(popupTemplate, context)).hide();
+    popup.find('textarea[name="proposal"]').hide();
+    popup.find('a.by' + by).addClass('sel');
+    var form = popup.find('#cf' + id);
+    form.submit(function(event) {
+      event.preventDefault();
+      addComment(form);
+    });
+    $('#s' + id).after(popup);
+    popup.slideDown('fast', function() {
+      getComments(id);
+    });
+  }
+
+  /**
+   * Hide a comment div.
+   */
+  function hide(id) {
+    $('#ah' + id).hide();
+    $('#ao' + id).show();
+    var div = $('#sc' + id);
+    div.slideUp('fast', function() {
+      div.remove();
+    });
+  }
+
+  /**
+   * Perform an ajax request to get comments for a node
+   * and insert the comments into the comments tree.
+   */
+  function getComments(id) {
+    $.ajax({
+     type: 'GET',
+     url: opts.getCommentsURL,
+     data: {node: id},
+     success: function(data, textStatus, request) {
+       var ul = $('#cl' + id);
+       var speed = 100;
+       $('#cf' + id)
+         .find('textarea[name="proposal"]')
+         .data('source', data.source);
+
+       if (data.comments.length === 0) {
+         ul.html('<li>No comments yet.</li>');
+         ul.data('empty', true);
+       } else {
+         // If there are comments, sort them and put them in the list.
+         var comments = sortComments(data.comments);
+         speed = data.comments.length * 100;
+         appendComments(comments, ul);
+         ul.data('empty', false);
+       }
+       $('#cn' + id).slideUp(speed + 200);
+       ul.slideDown(speed);
+     },
+     error: function(request, textStatus, error) {
+       showError('Oops, there was a problem retrieving the comments.');
+     },
+     dataType: 'json'
+    });
+  }
+
+  /**
+   * Add a comment via ajax and insert the comment into the comment tree.
+   */
+  function addComment(form) {
+    var node_id = form.find('input[name="node"]').val();
+    var parent_id = form.find('input[name="parent"]').val();
+    var text = form.find('textarea[name="comment"]').val();
+    var proposal = form.find('textarea[name="proposal"]').val();
+
+    if (text == '') {
+      showError('Please enter a comment.');
+      return;
+    }
+
+    // Disable the form that is being submitted.
+    form.find('textarea,input').attr('disabled', 'disabled');
+
+    // Send the comment to the server.
+    $.ajax({
+      type: "POST",
+      url: opts.addCommentURL,
+      dataType: 'json',
+      data: {
+        node: node_id,
+        parent: parent_id,
+        text: text,
+        proposal: proposal
+      },
+      success: function(data, textStatus, error) {
+        // Reset the form.
+        if (node_id) {
+          hideProposeChange(node_id);
+        }
+        form.find('textarea')
+          .val('')
+          .add(form.find('input'))
+          .removeAttr('disabled');
+	var ul = $('#cl' + (node_id || parent_id));
+        if (ul.data('empty')) {
+          $(ul).empty();
+          ul.data('empty', false);
+        }
+        insertComment(data.comment);
+        var ao = $('#ao' + node_id);
+        ao.find('img').attr({'src': opts.commentBrightImage});
+        if (node_id) {
+          // if this was a "root" comment, remove the commenting box
+          // (the user can get it back by reopening the comment popup)
+          $('#ca' + node_id).slideUp();
+        }
+      },
+      error: function(request, textStatus, error) {
+        form.find('textarea,input').removeAttr('disabled');
+        showError('Oops, there was a problem adding the comment.');
+      }
+    });
+  }
+
+  /**
+   * Recursively append comments to the main comment list and children
+   * lists, creating the comment tree.
+   */
+  function appendComments(comments, ul) {
+    $.each(comments, function() {
+      var div = createCommentDiv(this);
+      ul.append($(document.createElement('li')).html(div));
+      appendComments(this.children, div.find('ul.comment-children'));
+      // To avoid stagnating data, don't store the comments children in data.
+      this.children = null;
+      div.data('comment', this);
+    });
+  }
+
+  /**
+   * After adding a new comment, it must be inserted in the correct
+   * location in the comment tree.
+   */
+  function insertComment(comment) {
+    var div = createCommentDiv(comment);
+
+    // To avoid stagnating data, don't store the comments children in data.
+    comment.children = null;
+    div.data('comment', comment);
+
+    var ul = $('#cl' + (comment.node || comment.parent));
+    var siblings = getChildren(ul);
+
+    var li = $(document.createElement('li'));
+    li.hide();
+
+    // Determine where in the parents children list to insert this comment.
+    for(i=0; i < siblings.length; i++) {
+      if (comp(comment, siblings[i]) <= 0) {
+        $('#cd' + siblings[i].id)
+          .parent()
+          .before(li.html(div));
+        li.slideDown('fast');
+        return;
+      }
+    }
+
+    // If we get here, this comment rates lower than all the others,
+    // or it is the only comment in the list.
+    ul.append(li.html(div));
+    li.slideDown('fast');
+  }
+
+  function acceptComment(id) {
+    $.ajax({
+      type: 'POST',
+      url: opts.acceptCommentURL,
+      data: {id: id},
+      success: function(data, textStatus, request) {
+        $('#cm' + id).fadeOut('fast');
+        $('#cd' + id).removeClass('moderate');
+      },
+      error: function(request, textStatus, error) {
+        showError('Oops, there was a problem accepting the comment.');
+      }
+    });
+  }
+
+  function deleteComment(id) {
+    $.ajax({
+      type: 'POST',
+      url: opts.deleteCommentURL,
+      data: {id: id},
+      success: function(data, textStatus, request) {
+        var div = $('#cd' + id);
+        if (data == 'delete') {
+          // Moderator mode: remove the comment and all children immediately
+          div.slideUp('fast', function() {
+            div.remove();
+          });
+          return;
+        }
+        // User mode: only mark the comment as deleted
+        div
+          .find('span.user-id:first')
+          .text('[deleted]').end()
+          .find('div.comment-text:first')
+          .text('[deleted]').end()
+          .find('#cm' + id + ', #dc' + id + ', #ac' + id + ', #rc' + id +
+                ', #sp' + id + ', #hp' + id + ', #cr' + id + ', #rl' + id)
+          .remove();
+        var comment = div.data('comment');
+        comment.username = '[deleted]';
+        comment.text = '[deleted]';
+        div.data('comment', comment);
+      },
+      error: function(request, textStatus, error) {
+        showError('Oops, there was a problem deleting the comment.');
+      }
+    });
+  }
+
+  function showProposal(id) {
+    $('#sp' + id).hide();
+    $('#hp' + id).show();
+    $('#pr' + id).slideDown('fast');
+  }
+
+  function hideProposal(id) {
+    $('#hp' + id).hide();
+    $('#sp' + id).show();
+    $('#pr' + id).slideUp('fast');
+  }
+
+  function showProposeChange(id) {
+    $('#pc' + id).hide();
+    $('#hc' + id).show();
+    var textarea = $('#pt' + id);
+    textarea.val(textarea.data('source'));
+    $.fn.autogrow.resize(textarea[0]);
+    textarea.slideDown('fast');
+  }
+
+  function hideProposeChange(id) {
+    $('#hc' + id).hide();
+    $('#pc' + id).show();
+    var textarea = $('#pt' + id);
+    textarea.val('').removeAttr('disabled');
+    textarea.slideUp('fast');
+  }
+
+  function toggleCommentMarkupBox(id) {
+    $('#mb' + id).toggle();
+  }
+
+  /** Handle when the user clicks on a sort by link. */
+  function handleReSort(link) {
+    var classes = link.attr('class').split(/\s+/);
+    for (var i=0; i<classes.length; i++) {
+      if (classes[i] != 'sort-option') {
+	by = classes[i].substring(2);
+      }
+    }
+    setComparator();
+    // Save/update the sortBy cookie.
+    var expiration = new Date();
+    expiration.setDate(expiration.getDate() + 365);
+    document.cookie= 'sortBy=' + escape(by) +
+                     ';expires=' + expiration.toUTCString();
+    $('ul.comment-ul').each(function(index, ul) {
+      var comments = getChildren($(ul), true);
+      comments = sortComments(comments);
+      appendComments(comments, $(ul).empty());
+    });
+  }
+
+  /**
+   * Function to process a vote when a user clicks an arrow.
+   */
+  function handleVote(link) {
+    if (!opts.voting) {
+      showError("You'll need to login to vote.");
+      return;
+    }
+
+    var id = link.attr('id');
+    if (!id) {
+      // Didn't click on one of the voting arrows.
+      return;
+    }
+    // If it is an unvote, the new vote value is 0,
+    // Otherwise it's 1 for an upvote, or -1 for a downvote.
+    var value = 0;
+    if (id.charAt(1) != 'u') {
+      value = id.charAt(0) == 'u' ? 1 : -1;
+    }
+    // The data to be sent to the server.
+    var d = {
+      comment_id: id.substring(2),
+      value: value
+    };
+
+    // Swap the vote and unvote links.
+    link.hide();
+    $('#' + id.charAt(0) + (id.charAt(1) == 'u' ? 'v' : 'u') + d.comment_id)
+      .show();
+
+    // The div the comment is displayed in.
+    var div = $('div#cd' + d.comment_id);
+    var data = div.data('comment');
+
+    // If this is not an unvote, and the other vote arrow has
+    // already been pressed, unpress it.
+    if ((d.value !== 0) && (data.vote === d.value * -1)) {
+      $('#' + (d.value == 1 ? 'd' : 'u') + 'u' + d.comment_id).hide();
+      $('#' + (d.value == 1 ? 'd' : 'u') + 'v' + d.comment_id).show();
+    }
+
+    // Update the comments rating in the local data.
+    data.rating += (data.vote === 0) ? d.value : (d.value - data.vote);
+    data.vote = d.value;
+    div.data('comment', data);
+
+    // Change the rating text.
+    div.find('.rating:first')
+      .text(data.rating + ' point' + (data.rating == 1 ? '' : 's'));
+
+    // Send the vote information to the server.
+    $.ajax({
+      type: "POST",
+      url: opts.processVoteURL,
+      data: d,
+      error: function(request, textStatus, error) {
+        showError('Oops, there was a problem casting that vote.');
+      }
+    });
+  }
+
+  /**
+   * Open a reply form used to reply to an existing comment.
+   */
+  function openReply(id) {
+    // Swap out the reply link for the hide link
+    $('#rl' + id).hide();
+    $('#cr' + id).show();
+
+    // Add the reply li to the children ul.
+    var div = $(renderTemplate(replyTemplate, {id: id})).hide();
+    $('#cl' + id)
+      .prepend(div)
+      // Setup the submit handler for the reply form.
+      .find('#rf' + id)
+      .submit(function(event) {
+        event.preventDefault();
+        addComment($('#rf' + id));
+        closeReply(id);
+      })
+      .find('input[type=button]')
+      .click(function() {
+        closeReply(id);
+      });
+    div.slideDown('fast', function() {
+      $('#rf' + id).find('textarea').focus();
+    });
+  }
+
+  /**
+   * Close the reply form opened with openReply.
+   */
+  function closeReply(id) {
+    // Remove the reply div from the DOM.
+    $('#rd' + id).slideUp('fast', function() {
+      $(this).remove();
+    });
+
+    // Swap out the hide link for the reply link
+    $('#cr' + id).hide();
+    $('#rl' + id).show();
+  }
+
+  /**
+   * Recursively sort a tree of comments using the comp comparator.
+   */
+  function sortComments(comments) {
+    comments.sort(comp);
+    $.each(comments, function() {
+      this.children = sortComments(this.children);
+    });
+    return comments;
+  }
+
+  /**
+   * Get the children comments from a ul. If recursive is true,
+   * recursively include childrens' children.
+   */
+  function getChildren(ul, recursive) {
+    var children = [];
+    ul.children().children("[id^='cd']")
+      .each(function() {
+        var comment = $(this).data('comment');
+        if (recursive)
+          comment.children = getChildren($(this).find('#cl' + comment.id), true);
+        children.push(comment);
+      });
+    return children;
+  }
+
+  /** Create a div to display a comment in. */
+  function createCommentDiv(comment) {
+    if (!comment.displayed && !opts.moderator) {
+      return $('<div class="moderate">Thank you!  Your comment will show up '
+               + 'once it is has been approved by a moderator.</div>');
+    }
+    // Prettify the comment rating.
+    comment.pretty_rating = comment.rating + ' point' +
+      (comment.rating == 1 ? '' : 's');
+    // Make a class (for displaying not yet moderated comments differently)
+    comment.css_class = comment.displayed ? '' : ' moderate';
+    // Create a div for this comment.
+    var context = $.extend({}, opts, comment);
+    var div = $(renderTemplate(commentTemplate, context));
+
+    // If the user has voted on this comment, highlight the correct arrow.
+    if (comment.vote) {
+      var direction = (comment.vote == 1) ? 'u' : 'd';
+      div.find('#' + direction + 'v' + comment.id).hide();
+      div.find('#' + direction + 'u' + comment.id).show();
+    }
+
+    if (opts.moderator || comment.text != '[deleted]') {
+      div.find('a.reply').show();
+      if (comment.proposal_diff)
+        div.find('#sp' + comment.id).show();
+      if (opts.moderator && !comment.displayed)
+        div.find('#cm' + comment.id).show();
+      if (opts.moderator || (opts.username == comment.username))
+        div.find('#dc' + comment.id).show();
+    }
+    return div;
+  }
+
+  /**
+   * A simple template renderer. Placeholders such as <%id%> are replaced
+   * by context['id'] with items being escaped. Placeholders such as <#id#>
+   * are not escaped.
+   */
+  function renderTemplate(template, context) {
+    var esc = $(document.createElement('div'));
+
+    function handle(ph, escape) {
+      var cur = context;
+      $.each(ph.split('.'), function() {
+        cur = cur[this];
+      });
+      return escape ? esc.text(cur || "").html() : cur;
+    }
+
+    return template.replace(/<([%#])([\w\.]*)\1>/g, function() {
+      return handle(arguments[2], arguments[1] == '%' ? true : false);
+    });
+  }
+
+  /** Flash an error message briefly. */
+  function showError(message) {
+    $(document.createElement('div')).attr({'class': 'popup-error'})
+      .append($(document.createElement('div'))
+               .attr({'class': 'error-message'}).text(message))
+      .appendTo('body')
+      .fadeIn("slow")
+      .delay(2000)
+      .fadeOut("slow");
+  }
+
+  /** Add a link the user uses to open the comments popup. */
+  $.fn.comment = function() {
+    return this.each(function() {
+      var id = $(this).attr('id').substring(1);
+      var count = COMMENT_METADATA[id];
+      var title = count + ' comment' + (count == 1 ? '' : 's');
+      var image = count > 0 ? opts.commentBrightImage : opts.commentImage;
+      var addcls = count == 0 ? ' nocomment' : '';
+      $(this)
+        .append(
+          $(document.createElement('a')).attr({
+            href: '#',
+            'class': 'sphinx-comment-open' + addcls,
+            id: 'ao' + id
+          })
+            .append($(document.createElement('img')).attr({
+              src: image,
+              alt: 'comment',
+              title: title
+            }))
+            .click(function(event) {
+              event.preventDefault();
+              show($(this).attr('id').substring(2));
+            })
+        )
+        .append(
+          $(document.createElement('a')).attr({
+            href: '#',
+            'class': 'sphinx-comment-close hidden',
+            id: 'ah' + id
+          })
+            .append($(document.createElement('img')).attr({
+              src: opts.closeCommentImage,
+              alt: 'close',
+              title: 'close'
+            }))
+            .click(function(event) {
+              event.preventDefault();
+              hide($(this).attr('id').substring(2));
+            })
+        );
+    });
+  };
+
+  var opts = {
+    processVoteURL: '/_process_vote',
+    addCommentURL: '/_add_comment',
+    getCommentsURL: '/_get_comments',
+    acceptCommentURL: '/_accept_comment',
+    deleteCommentURL: '/_delete_comment',
+    commentImage: '/static/_static/comment.png',
+    closeCommentImage: '/static/_static/comment-close.png',
+    loadingImage: '/static/_static/ajax-loader.gif',
+    commentBrightImage: '/static/_static/comment-bright.png',
+    upArrow: '/static/_static/up.png',
+    downArrow: '/static/_static/down.png',
+    upArrowPressed: '/static/_static/up-pressed.png',
+    downArrowPressed: '/static/_static/down-pressed.png',
+    voting: false,
+    moderator: false
+  };
+
+  if (typeof COMMENT_OPTIONS != "undefined") {
+    opts = jQuery.extend(opts, COMMENT_OPTIONS);
+  }
+
+  var popupTemplate = '\
+    <div class="sphinx-comments" id="sc<%id%>">\
+      <p class="sort-options">\
+        Sort by:\
+        <a href="#" class="sort-option byrating">best rated</a>\
+        <a href="#" class="sort-option byascage">newest</a>\
+        <a href="#" class="sort-option byage">oldest</a>\
+      </p>\
+      <div class="comment-header">Comments</div>\
+      <div class="comment-loading" id="cn<%id%>">\
+        loading comments... <img src="<%loadingImage%>" alt="" /></div>\
+      <ul id="cl<%id%>" class="comment-ul"></ul>\
+      <div id="ca<%id%>">\
+      <p class="add-a-comment">Add a comment\
+        (<a href="#" class="comment-markup" id="ab<%id%>">markup</a>):</p>\
+      <div class="comment-markup-box" id="mb<%id%>">\
+        reStructured text markup: <i>*emph*</i>, <b>**strong**</b>, \
+        <code>``code``</code>, \
+        code blocks: <code>::</code> and an indented block after blank line</div>\
+      <form method="post" id="cf<%id%>" class="comment-form" action="">\
+        <textarea name="comment" cols="80"></textarea>\
+        <p class="propose-button">\
+          <a href="#" id="pc<%id%>" class="show-propose-change">\
+            Propose a change &#9657;\
+          </a>\
+          <a href="#" id="hc<%id%>" class="hide-propose-change">\
+            Propose a change &#9663;\
+          </a>\
+        </p>\
+        <textarea name="proposal" id="pt<%id%>" cols="80"\
+                  spellcheck="false"></textarea>\
+        <input type="submit" value="Add comment" />\
+        <input type="hidden" name="node" value="<%id%>" />\
+        <input type="hidden" name="parent" value="" />\
+      </form>\
+      </div>\
+    </div>';
+
+  var commentTemplate = '\
+    <div id="cd<%id%>" class="sphinx-comment<%css_class%>">\
+      <div class="vote">\
+        <div class="arrow">\
+          <a href="#" id="uv<%id%>" class="vote" title="vote up">\
+            <img src="<%upArrow%>" />\
+          </a>\
+          <a href="#" id="uu<%id%>" class="un vote" title="vote up">\
+            <img src="<%upArrowPressed%>" />\
+          </a>\
+        </div>\
+        <div class="arrow">\
+          <a href="#" id="dv<%id%>" class="vote" title="vote down">\
+            <img src="<%downArrow%>" id="da<%id%>" />\
+          </a>\
+          <a href="#" id="du<%id%>" class="un vote" title="vote down">\
+            <img src="<%downArrowPressed%>" />\
+          </a>\
+        </div>\
+      </div>\
+      <div class="comment-content">\
+        <p class="tagline comment">\
+          <span class="user-id"><%username%></span>\
+          <span class="rating"><%pretty_rating%></span>\
+          <span class="delta"><%time.delta%></span>\
+        </p>\
+        <div class="comment-text comment"><#text#></div>\
+        <p class="comment-opts comment">\
+          <a href="#" class="reply hidden" id="rl<%id%>">reply &#9657;</a>\
+          <a href="#" class="close-reply" id="cr<%id%>">reply &#9663;</a>\
+          <a href="#" id="sp<%id%>" class="show-proposal">proposal &#9657;</a>\
+          <a href="#" id="hp<%id%>" class="hide-proposal">proposal &#9663;</a>\
+          <a href="#" id="dc<%id%>" class="delete-comment hidden">delete</a>\
+          <span id="cm<%id%>" class="moderation hidden">\
+            <a href="#" id="ac<%id%>" class="accept-comment">accept</a>\
+          </span>\
+        </p>\
+        <pre class="proposal" id="pr<%id%>">\
+<#proposal_diff#>\
+        </pre>\
+          <ul class="comment-children" id="cl<%id%>"></ul>\
+        </div>\
+        <div class="clearleft"></div>\
+      </div>\
+    </div>';
+
+  var replyTemplate = '\
+    <li>\
+      <div class="reply-div" id="rd<%id%>">\
+        <form id="rf<%id%>">\
+          <textarea name="comment" cols="80"></textarea>\
+          <input type="submit" value="Add reply" />\
+          <input type="button" value="Cancel" />\
+          <input type="hidden" name="parent" value="<%id%>" />\
+          <input type="hidden" name="node" value="" />\
+        </form>\
+      </div>\
+    </li>';
+
+  $(document).ready(function() {
+    init();
+  });
+})(jQuery);
+
+$(document).ready(function() {
+  // add comment anchors for all paragraphs that are commentable
+  $('.sphinx-has-comment').comment();
+
+  // highlight search words in search results
+  $("div.context").each(function() {
+    var params = $.getQueryParameters();
+    var terms = (params.q) ? params.q[0].split(/\s+/) : [];
+    var result = $(this);
+    $.each(terms, function() {
+      result.highlightText(this.toLowerCase(), 'highlighted');
+    });
+  });
+
+  // directly open comment window if requested
+  var anchor = document.location.hash;
+  if (anchor.substring(0, 9) == '#comment-') {
+    $('#ao' + anchor.substring(9)).click();
+    document.location.hash = '#s' + anchor.substring(9);
+  }
+});
diff --git a/docs/html/api/nmb_NBNSProtocol.html b/docs/html/api/nmb_NBNSProtocol.html
new file mode 100644
index 00000000..fdbaa08e
--- /dev/null
+++ b/docs/html/api/nmb_NBNSProtocol.html
@@ -0,0 +1,208 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    
+    <title>NBNSProtocol Class &mdash; pysmb 1.1.25 documentation</title>
+    
+    <link rel="stylesheet" href="../_static/sphinxdoc.css" type="text/css" />
+    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
+    
+    <script type="text/javascript">
+      var DOCUMENTATION_OPTIONS = {
+        URL_ROOT:    '../',
+        VERSION:     '1.1.25',
+        COLLAPSE_INDEX: false,
+        FILE_SUFFIX: '.html',
+        HAS_SOURCE:  true
+      };
+    </script>
+    <script type="text/javascript" src="../_static/jquery.js"></script>
+    <script type="text/javascript" src="../_static/underscore.js"></script>
+    <script type="text/javascript" src="../_static/doctools.js"></script>
+    <link rel="top" title="pysmb 1.1.25 documentation" href="../index.html" />
+    <link rel="next" title="NetBIOS class" href="nmb_NetBIOS.html" />
+    <link rel="prev" title="Welcome to pysmb’s documentation!" href="../index.html" /> 
+  </head>
+  <body role="document">
+    <div class="related" role="navigation" aria-label="related navigation">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="../genindex.html" title="General Index"
+             accesskey="I">index</a></li>
+        <li class="right" >
+          <a href="../py-modindex.html" title="Python Module Index"
+             >modules</a> |</li>
+        <li class="right" >
+          <a href="nmb_NetBIOS.html" title="NetBIOS class"
+             accesskey="N">next</a> |</li>
+        <li class="right" >
+          <a href="../index.html" title="Welcome to pysmb’s documentation!"
+             accesskey="P">previous</a> |</li>
+        <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.1.25 documentation</a> &raquo;</li> 
+      </ul>
+    </div>
+      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
+        <div class="sphinxsidebarwrapper">
+  <h4>Previous topic</h4>
+  <p class="topless"><a href="../index.html"
+                        title="previous chapter">Welcome to pysmb&#8217;s documentation!</a></p>
+  <h4>Next topic</h4>
+  <p class="topless"><a href="nmb_NetBIOS.html"
+                        title="next chapter">NetBIOS class</a></p>
+  <div role="note" aria-label="source link">
+    <h3>This Page</h3>
+    <ul class="this-page-menu">
+      <li><a href="../_sources/api/nmb_NBNSProtocol.txt"
+            rel="nofollow">Show Source</a></li>
+    </ul>
+   </div>
+<div id="searchbox" style="display: none" role="search">
+  <h3>Quick search</h3>
+    <form class="search" action="../search.html" method="get">
+      <input type="text" name="q" />
+      <input type="submit" value="Go" />
+      <input type="hidden" name="check_keywords" value="yes" />
+      <input type="hidden" name="area" value="default" />
+    </form>
+    <p class="searchtip" style="font-size: 90%">
+    Enter search terms or a module, class or function name.
+    </p>
+</div>
+<script type="text/javascript">$('#searchbox').show(0);</script>
+        </div>
+      </div>
+
+    <div class="document">
+      <div class="documentwrapper">
+        <div class="bodywrapper">
+          <div class="body" role="main">
+            
+  <div class="section" id="nbnsprotocol-class">
+<h1>NBNSProtocol Class<a class="headerlink" href="#nbnsprotocol-class" title="Permalink to this headline">¶</a></h1>
+<p>pysmb has a <em>NBNSProtocol</em> implementation for Twisted framework.
+This allows you to perform name query asynchronously without having your application to block and wait for the results.</p>
+<dl class="docutils">
+<dt>In your project,</dt>
+<dd><ol class="first last arabic simple">
+<li>Create a NBNSProtocol instance.</li>
+<li>Just call <em>queryName</em> method which will return a <em>Deferred</em> instance. Add your callback function to the <em>Deferred</em> instance via <em>addCallback</em> method to receive the results of the name query.</li>
+<li>When you are done with the NBNSProtocol instance, call its &lt;NBNSProtocol instance&gt;.transport.stopListening method to remove this instance from the reactor.</li>
+</ol>
+</dd>
+</dl>
+<dl class="class">
+<dt id="nmb.NetBIOSProtocol.NBNSProtocol">
+<em class="property">class </em><code class="descclassname">nmb.NetBIOSProtocol.</code><code class="descname">NBNSProtocol</code><span class="sig-paren">(</span><em>broadcast=True</em>, <em>listen_port=0</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nmb/NetBIOSProtocol.html#NBNSProtocol"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nmb.NetBIOSProtocol.NBNSProtocol" title="Permalink to this definition">¶</a></dt>
+<dd><dl class="method">
+<dt id="nmb.NetBIOSProtocol.NBNSProtocol.__init__">
+<code class="descname">__init__</code><span class="sig-paren">(</span><em>broadcast=True</em>, <em>listen_port=0</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nmb/NetBIOSProtocol.html#NBNSProtocol.__init__"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nmb.NetBIOSProtocol.NBNSProtocol.__init__" title="Permalink to this definition">¶</a></dt>
+<dd><p>Instantiate a NBNSProtocol instance.</p>
+<p>This automatically calls reactor.listenUDP method to start listening for incoming packets, so you <strong>must not</strong> call the listenUDP method again.</p>
+<table class="docutils field-list" frame="void" rules="none">
+<col class="field-name" />
+<col class="field-body" />
+<tbody valign="top">
+<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
+<li><strong>broadcast</strong> (<em>boolean</em>) &#8211; A boolean flag to indicate if we should setup the listening UDP port in broadcast mode</li>
+<li><strong>listen_port</strong> (<em>integer</em>) &#8211; Specifies the UDP port number to bind to for listening. If zero, OS will automatically select a free port number.</li>
+</ul>
+</td>
+</tr>
+</tbody>
+</table>
+</dd></dl>
+
+<dl class="method">
+<dt id="nmb.NetBIOSProtocol.NBNSProtocol.queryIPForName">
+<code class="descname">queryIPForName</code><span class="sig-paren">(</span><em>ip</em>, <em>port=137</em>, <em>timeout=30</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nmb/NetBIOSProtocol.html#NBNSProtocol.queryIPForName"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nmb.NetBIOSProtocol.NBNSProtocol.queryIPForName" title="Permalink to this definition">¶</a></dt>
+<dd><p>Send a query to the machine with <em>ip</em> and hopes that the machine will reply back with its name.</p>
+<p>The implementation of this function is contributed by Jason Anderson.</p>
+<table class="docutils field-list" frame="void" rules="none">
+<col class="field-name" />
+<col class="field-body" />
+<tbody valign="top">
+<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
+<li><strong>ip</strong> (<em>string</em>) &#8211; If the NBNSProtocol instance was instianted with broadcast=True, then this parameter can be an empty string. We will leave it to the OS to determine an appropriate broadcast address.
+If the NBNSProtocol instance was instianted with broadcast=False, then you should provide a target IP to send the query.</li>
+<li><strong>port</strong> (<em>integer</em>) &#8211; The NetBIOS-NS port (IANA standard defines this port to be 137). You should not touch this parameter unless you know what you are doing.</li>
+<li><strong>timeout</strong> (<em>integer/float</em>) &#8211; Number of seconds to wait for a reply, after which the method will return None</li>
+</ul>
+</td>
+</tr>
+<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">A <em>twisted.internet.defer.Deferred</em> instance. The callback function will be called with a list of names of the machine at <em>ip</em>.
+On timeout, the errback function will be called with a Failure instance wrapping around a NetBIOSTimeout exception</p>
+</td>
+</tr>
+</tbody>
+</table>
+</dd></dl>
+
+<dl class="method">
+<dt id="nmb.NetBIOSProtocol.NBNSProtocol.queryName">
+<code class="descname">queryName</code><span class="sig-paren">(</span><em>name</em>, <em>ip=''</em>, <em>port=137</em>, <em>timeout=30</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nmb/NetBIOSProtocol.html#NBNSProtocol.queryName"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nmb.NetBIOSProtocol.NBNSProtocol.queryName" title="Permalink to this definition">¶</a></dt>
+<dd><p>Send a query on the network and hopes that if machine matching the <em>name</em> will reply with its IP address.</p>
+<table class="docutils field-list" frame="void" rules="none">
+<col class="field-name" />
+<col class="field-body" />
+<tbody valign="top">
+<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
+<li><strong>ip</strong> (<em>string</em>) &#8211; If the NBNSProtocol instance was instianted with broadcast=True, then this parameter can be an empty string. We will leave it to the OS to determine an appropriate broadcast address.
+If the NBNSProtocol instance was instianted with broadcast=False, then you should provide a target IP to send the query.</li>
+<li><strong>port</strong> (<em>integer</em>) &#8211; The NetBIOS-NS port (IANA standard defines this port to be 137). You should not touch this parameter unless you know what you are doing.</li>
+<li><strong>timeout</strong> (<em>integer/float</em>) &#8211; Number of seconds to wait for a reply, after which the returned Deferred instance will be called with a NetBIOSTimeout exception.</li>
+</ul>
+</td>
+</tr>
+<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">A <em>twisted.internet.defer.Deferred</em> instance. The callback function will be called with a list of IP addresses in dotted notation (aaa.bbb.ccc.ddd).
+On timeout, the errback function will be called with a Failure instance wrapping around a NetBIOSTimeout exception</p>
+</td>
+</tr>
+</tbody>
+</table>
+</dd></dl>
+
+</dd></dl>
+
+<dl class="class">
+<dt id="nmb.NetBIOSProtocol.NetBIOSTimeout">
+<em class="property">class </em><code class="descclassname">nmb.NetBIOSProtocol.</code><code class="descname">NetBIOSTimeout</code><a class="reference internal" href="../_modules/nmb/NetBIOSProtocol.html#NetBIOSTimeout"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nmb.NetBIOSProtocol.NetBIOSTimeout" title="Permalink to this definition">¶</a></dt>
+<dd><p>Raised in NBNSProtocol via Deferred.errback method when queryName method has timeout waiting for reply</p>
+</dd></dl>
+
+</div>
+
+
+          </div>
+        </div>
+      </div>
+      <div class="clearer"></div>
+    </div>
+    <div class="related" role="navigation" aria-label="related navigation">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="../genindex.html" title="General Index"
+             >index</a></li>
+        <li class="right" >
+          <a href="../py-modindex.html" title="Python Module Index"
+             >modules</a> |</li>
+        <li class="right" >
+          <a href="nmb_NetBIOS.html" title="NetBIOS class"
+             >next</a> |</li>
+        <li class="right" >
+          <a href="../index.html" title="Welcome to pysmb’s documentation!"
+             >previous</a> |</li>
+        <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.1.25 documentation</a> &raquo;</li> 
+      </ul>
+    </div>
+    <div class="footer" role="contentinfo">
+        &copy; Copyright 2001-2018, Michael Teo http://miketeo.net/.
+      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.6.
+    </div>
+  </body>
+</html>
\ No newline at end of file
diff --git a/docs/html/api/nmb_NetBIOS.html b/docs/html/api/nmb_NetBIOS.html
new file mode 100644
index 00000000..165ff63f
--- /dev/null
+++ b/docs/html/api/nmb_NetBIOS.html
@@ -0,0 +1,212 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    
+    <title>NetBIOS class &mdash; pysmb 1.1.25 documentation</title>
+    
+    <link rel="stylesheet" href="../_static/sphinxdoc.css" type="text/css" />
+    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
+    
+    <script type="text/javascript">
+      var DOCUMENTATION_OPTIONS = {
+        URL_ROOT:    '../',
+        VERSION:     '1.1.25',
+        COLLAPSE_INDEX: false,
+        FILE_SUFFIX: '.html',
+        HAS_SOURCE:  true
+      };
+    </script>
+    <script type="text/javascript" src="../_static/jquery.js"></script>
+    <script type="text/javascript" src="../_static/underscore.js"></script>
+    <script type="text/javascript" src="../_static/doctools.js"></script>
+    <link rel="top" title="pysmb 1.1.25 documentation" href="../index.html" />
+    <link rel="next" title="SMBConnection Class" href="smb_SMBConnection.html" />
+    <link rel="prev" title="NBNSProtocol Class" href="nmb_NBNSProtocol.html" /> 
+  </head>
+  <body role="document">
+    <div class="related" role="navigation" aria-label="related navigation">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="../genindex.html" title="General Index"
+             accesskey="I">index</a></li>
+        <li class="right" >
+          <a href="../py-modindex.html" title="Python Module Index"
+             >modules</a> |</li>
+        <li class="right" >
+          <a href="smb_SMBConnection.html" title="SMBConnection Class"
+             accesskey="N">next</a> |</li>
+        <li class="right" >
+          <a href="nmb_NBNSProtocol.html" title="NBNSProtocol Class"
+             accesskey="P">previous</a> |</li>
+        <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.1.25 documentation</a> &raquo;</li> 
+      </ul>
+    </div>
+      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
+        <div class="sphinxsidebarwrapper">
+  <h4>Previous topic</h4>
+  <p class="topless"><a href="nmb_NBNSProtocol.html"
+                        title="previous chapter">NBNSProtocol Class</a></p>
+  <h4>Next topic</h4>
+  <p class="topless"><a href="smb_SMBConnection.html"
+                        title="next chapter">SMBConnection Class</a></p>
+  <div role="note" aria-label="source link">
+    <h3>This Page</h3>
+    <ul class="this-page-menu">
+      <li><a href="../_sources/api/nmb_NetBIOS.txt"
+            rel="nofollow">Show Source</a></li>
+    </ul>
+   </div>
+<div id="searchbox" style="display: none" role="search">
+  <h3>Quick search</h3>
+    <form class="search" action="../search.html" method="get">
+      <input type="text" name="q" />
+      <input type="submit" value="Go" />
+      <input type="hidden" name="check_keywords" value="yes" />
+      <input type="hidden" name="area" value="default" />
+    </form>
+    <p class="searchtip" style="font-size: 90%">
+    Enter search terms or a module, class or function name.
+    </p>
+</div>
+<script type="text/javascript">$('#searchbox').show(0);</script>
+        </div>
+      </div>
+
+    <div class="document">
+      <div class="documentwrapper">
+        <div class="bodywrapper">
+          <div class="body" role="main">
+            
+  <div class="section" id="netbios-class">
+<h1>NetBIOS class<a class="headerlink" href="#netbios-class" title="Permalink to this headline">¶</a></h1>
+<dl class="docutils">
+<dt>To use the NetBIOS class in your application,</dt>
+<dd><ol class="first last arabic simple">
+<li>Create a new NetBIOS instance</li>
+<li>Call <em>queryName</em> method for each name you wish to query. The method will block until a reply is received from the remote SMB/CIFS service, or until timeout.</li>
+<li>When you are done, call <em>close</em> method to release the underlying resources.</li>
+</ol>
+</dd>
+</dl>
+<dl class="class">
+<dt id="nmb.NetBIOS.NetBIOS">
+<em class="property">class </em><code class="descclassname">nmb.NetBIOS.</code><code class="descname">NetBIOS</code><span class="sig-paren">(</span><em>broadcast=True</em>, <em>listen_port=0</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nmb/NetBIOS.html#NetBIOS"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nmb.NetBIOS.NetBIOS" title="Permalink to this definition">¶</a></dt>
+<dd><dl class="method">
+<dt id="nmb.NetBIOS.NetBIOS.__init__">
+<code class="descname">__init__</code><span class="sig-paren">(</span><em>broadcast=True</em>, <em>listen_port=0</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nmb/NetBIOS.html#NetBIOS.__init__"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nmb.NetBIOS.NetBIOS.__init__" title="Permalink to this definition">¶</a></dt>
+<dd><p>Instantiate a NetBIOS instance, and creates a IPv4 UDP socket to listen/send NBNS packets.</p>
+<table class="docutils field-list" frame="void" rules="none">
+<col class="field-name" />
+<col class="field-body" />
+<tbody valign="top">
+<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
+<li><strong>broadcast</strong> (<em>boolean</em>) &#8211; A boolean flag to indicate if we should setup the listening UDP port in broadcast mode</li>
+<li><strong>listen_port</strong> (<em>integer</em>) &#8211; Specifies the UDP port number to bind to for listening. If zero, OS will automatically select a free port number.</li>
+</ul>
+</td>
+</tr>
+</tbody>
+</table>
+</dd></dl>
+
+<dl class="method">
+<dt id="nmb.NetBIOS.NetBIOS.close">
+<code class="descname">close</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nmb/NetBIOS.html#NetBIOS.close"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nmb.NetBIOS.NetBIOS.close" title="Permalink to this definition">¶</a></dt>
+<dd><p>Close the underlying and free resources.</p>
+<p>The NetBIOS instance should not be used to perform any operations after this method returns.</p>
+<table class="docutils field-list" frame="void" rules="none">
+<col class="field-name" />
+<col class="field-body" />
+<tbody valign="top">
+<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">None</td>
+</tr>
+</tbody>
+</table>
+</dd></dl>
+
+<dl class="method">
+<dt id="nmb.NetBIOS.NetBIOS.queryIPForName">
+<code class="descname">queryIPForName</code><span class="sig-paren">(</span><em>ip</em>, <em>port=137</em>, <em>timeout=30</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nmb/NetBIOS.html#NetBIOS.queryIPForName"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nmb.NetBIOS.NetBIOS.queryIPForName" title="Permalink to this definition">¶</a></dt>
+<dd><p>Send a query to the machine with <em>ip</em> and hopes that the machine will reply back with its name.</p>
+<p>The implementation of this function is contributed by Jason Anderson.</p>
+<table class="docutils field-list" frame="void" rules="none">
+<col class="field-name" />
+<col class="field-body" />
+<tbody valign="top">
+<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
+<li><strong>ip</strong> (<em>string</em>) &#8211; If the NBNSProtocol instance was instianted with broadcast=True, then this parameter can be an empty string. We will leave it to the OS to determine an appropriate broadcast address.
+If the NBNSProtocol instance was instianted with broadcast=False, then you should provide a target IP to send the query.</li>
+<li><strong>port</strong> (<em>integer</em>) &#8211; The NetBIOS-NS port (IANA standard defines this port to be 137). You should not touch this parameter unless you know what you are doing.</li>
+<li><strong>timeout</strong> (<em>integer/float</em>) &#8211; Number of seconds to wait for a reply, after which the method will return None</li>
+</ul>
+</td>
+</tr>
+<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">A list of string containing the names of the machine at <em>ip</em>. On timeout, returns None.</p>
+</td>
+</tr>
+</tbody>
+</table>
+</dd></dl>
+
+<dl class="method">
+<dt id="nmb.NetBIOS.NetBIOS.queryName">
+<code class="descname">queryName</code><span class="sig-paren">(</span><em>name</em>, <em>ip=''</em>, <em>port=137</em>, <em>timeout=30</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nmb/NetBIOS.html#NetBIOS.queryName"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nmb.NetBIOS.NetBIOS.queryName" title="Permalink to this definition">¶</a></dt>
+<dd><p>Send a query on the network and hopes that if machine matching the <em>name</em> will reply with its IP address.</p>
+<table class="docutils field-list" frame="void" rules="none">
+<col class="field-name" />
+<col class="field-body" />
+<tbody valign="top">
+<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
+<li><strong>ip</strong> (<em>string</em>) &#8211; If the NBNSProtocol instance was instianted with broadcast=True, then this parameter can be an empty string. We will leave it to the OS to determine an appropriate broadcast address.
+If the NBNSProtocol instance was instianted with broadcast=False, then you should provide a target IP to send the query.</li>
+<li><strong>port</strong> (<em>integer</em>) &#8211; The NetBIOS-NS port (IANA standard defines this port to be 137). You should not touch this parameter unless you know what you are doing.</li>
+<li><strong>timeout</strong> (<em>integer/float</em>) &#8211; Number of seconds to wait for a reply, after which the method will return None</li>
+</ul>
+</td>
+</tr>
+<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">A list of IP addresses in dotted notation (aaa.bbb.ccc.ddd). On timeout, returns None.</p>
+</td>
+</tr>
+</tbody>
+</table>
+</dd></dl>
+
+</dd></dl>
+
+</div>
+
+
+          </div>
+        </div>
+      </div>
+      <div class="clearer"></div>
+    </div>
+    <div class="related" role="navigation" aria-label="related navigation">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="../genindex.html" title="General Index"
+             >index</a></li>
+        <li class="right" >
+          <a href="../py-modindex.html" title="Python Module Index"
+             >modules</a> |</li>
+        <li class="right" >
+          <a href="smb_SMBConnection.html" title="SMBConnection Class"
+             >next</a> |</li>
+        <li class="right" >
+          <a href="nmb_NBNSProtocol.html" title="NBNSProtocol Class"
+             >previous</a> |</li>
+        <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.1.25 documentation</a> &raquo;</li> 
+      </ul>
+    </div>
+    <div class="footer" role="contentinfo">
+        &copy; Copyright 2001-2018, Michael Teo http://miketeo.net/.
+      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.6.
+    </div>
+  </body>
+</html>
\ No newline at end of file
diff --git a/docs/html/api/smb_SMBConnection.html b/docs/html/api/smb_SMBConnection.html
new file mode 100644
index 00000000..38e03ac8
--- /dev/null
+++ b/docs/html/api/smb_SMBConnection.html
@@ -0,0 +1,174 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    
+    <title>SMBConnection Class &mdash; pysmb 1.1.25 documentation</title>
+    
+    <link rel="stylesheet" href="../_static/sphinxdoc.css" type="text/css" />
+    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
+    
+    <script type="text/javascript">
+      var DOCUMENTATION_OPTIONS = {
+        URL_ROOT:    '../',
+        VERSION:     '1.1.25',
+        COLLAPSE_INDEX: false,
+        FILE_SUFFIX: '.html',
+        HAS_SOURCE:  true
+      };
+    </script>
+    <script type="text/javascript" src="../_static/jquery.js"></script>
+    <script type="text/javascript" src="../_static/underscore.js"></script>
+    <script type="text/javascript" src="../_static/doctools.js"></script>
+    <link rel="top" title="pysmb 1.1.25 documentation" href="../index.html" />
+    <link rel="next" title="SMbHandler Class" href="smb_SMBHandler.html" />
+    <link rel="prev" title="NetBIOS class" href="nmb_NetBIOS.html" /> 
+  </head>
+  <body role="document">
+    <div class="related" role="navigation" aria-label="related navigation">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="../genindex.html" title="General Index"
+             accesskey="I">index</a></li>
+        <li class="right" >
+          <a href="../py-modindex.html" title="Python Module Index"
+             >modules</a> |</li>
+        <li class="right" >
+          <a href="smb_SMBHandler.html" title="SMbHandler Class"
+             accesskey="N">next</a> |</li>
+        <li class="right" >
+          <a href="nmb_NetBIOS.html" title="NetBIOS class"
+             accesskey="P">previous</a> |</li>
+        <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.1.25 documentation</a> &raquo;</li> 
+      </ul>
+    </div>
+      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
+        <div class="sphinxsidebarwrapper">
+  <h3><a href="../index.html">Table Of Contents</a></h3>
+  <ul>
+<li><a class="reference internal" href="#">SMBConnection Class</a><ul>
+<li><a class="reference internal" href="#example">Example</a></li>
+<li><a class="reference internal" href="#smb2-support">SMB2 Support</a></li>
+<li><a class="reference internal" href="#caveats">Caveats</a></li>
+</ul>
+</li>
+</ul>
+
+  <h4>Previous topic</h4>
+  <p class="topless"><a href="nmb_NetBIOS.html"
+                        title="previous chapter">NetBIOS class</a></p>
+  <h4>Next topic</h4>
+  <p class="topless"><a href="smb_SMBHandler.html"
+                        title="next chapter">SMbHandler Class</a></p>
+  <div role="note" aria-label="source link">
+    <h3>This Page</h3>
+    <ul class="this-page-menu">
+      <li><a href="../_sources/api/smb_SMBConnection.txt"
+            rel="nofollow">Show Source</a></li>
+    </ul>
+   </div>
+<div id="searchbox" style="display: none" role="search">
+  <h3>Quick search</h3>
+    <form class="search" action="../search.html" method="get">
+      <input type="text" name="q" />
+      <input type="submit" value="Go" />
+      <input type="hidden" name="check_keywords" value="yes" />
+      <input type="hidden" name="area" value="default" />
+    </form>
+    <p class="searchtip" style="font-size: 90%">
+    Enter search terms or a module, class or function name.
+    </p>
+</div>
+<script type="text/javascript">$('#searchbox').show(0);</script>
+        </div>
+      </div>
+
+    <div class="document">
+      <div class="documentwrapper">
+        <div class="bodywrapper">
+          <div class="body" role="main">
+            
+  <div class="section" id="smbconnection-class">
+<h1>SMBConnection Class<a class="headerlink" href="#smbconnection-class" title="Permalink to this headline">¶</a></h1>
+<p>The SMBConnection is suitable for developers who wish to use pysmb to perform file operations with a remote SMB/CIFS server sequentially.</p>
+<p>Each file operation method, when invoked, will block and return after it has completed or has encountered an error.</p>
+<div class="section" id="example">
+<h2>Example<a class="headerlink" href="#example" title="Permalink to this headline">¶</a></h2>
+<p>The following illustrates a simple file retrieving implementation.:</p>
+<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">tempfile</span>
+<span class="kn">from</span> <span class="nn">smb.SMBConnection</span> <span class="kn">import</span> <span class="n">SMBConnection</span>
+
+<span class="c1"># There will be some mechanism to capture userID, password, client_machine_name, server_name and server_ip</span>
+<span class="c1"># client_machine_name can be an arbitary ASCII string</span>
+<span class="c1"># server_name should match the remote machine name, or else the connection will be rejected</span>
+<span class="n">conn</span> <span class="o">=</span> <span class="n">SMBConnection</span><span class="p">(</span><span class="n">userID</span><span class="p">,</span> <span class="n">password</span><span class="p">,</span> <span class="n">client_machine_name</span><span class="p">,</span> <span class="n">server_name</span><span class="p">,</span> <span class="n">use_ntlm_v2</span> <span class="o">=</span> <span class="bp">True</span><span class="p">)</span>
+<span class="k">assert</span> <span class="n">conn</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="n">server_ip</span><span class="p">,</span> <span class="mi">139</span><span class="p">)</span>
+
+<span class="n">file_obj</span> <span class="o">=</span> <span class="n">tempfile</span><span class="o">.</span><span class="n">NamedTemporaryFile</span><span class="p">()</span>
+<span class="n">file_attributes</span><span class="p">,</span> <span class="n">filesize</span> <span class="o">=</span> <span class="n">conn</span><span class="o">.</span><span class="n">retrieveFile</span><span class="p">(</span><span class="s1">&#39;smbtest&#39;</span><span class="p">,</span> <span class="s1">&#39;/rfc1001.txt&#39;</span><span class="p">,</span> <span class="n">file_obj</span><span class="p">)</span>
+
+<span class="c1"># Retrieved file contents are inside file_obj</span>
+<span class="c1"># Do what you need with the file_obj and then close it</span>
+<span class="c1"># Note that the file obj is positioned at the end-of-file,</span>
+<span class="c1"># so you might need to perform a file_obj.seek() if you need</span>
+<span class="c1"># to read from the beginning</span>
+<span class="n">file_obj</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
+</pre></div>
+</div>
+</div>
+<div class="section" id="smb2-support">
+<h2>SMB2 Support<a class="headerlink" href="#smb2-support" title="Permalink to this headline">¶</a></h2>
+<p>Starting from pysmb 1.1.0, pysmb will utilize SMB2 protocol for communication if the remote SMB/CIFS service supports SMB2.
+Otherwise, it will fallback automatically back to using SMB1 protocol.</p>
+<p>To disable SMB2 protocol in pysmb, set the <em>SUPPORT_SMB2</em> flag in the <em>smb_structs</em> module to <em>False</em> before creating the <em>SMBConnection</em> instance.:</p>
+<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">smb</span> <span class="kn">import</span> <span class="n">smb_structs</span>
+<span class="n">smb_structs</span><span class="o">.</span><span class="n">SUPPORT_SMB2</span> <span class="o">=</span> <span class="bp">False</span>
+</pre></div>
+</div>
+</div>
+<div class="section" id="caveats">
+<h2>Caveats<a class="headerlink" href="#caveats" title="Permalink to this headline">¶</a></h2>
+<ul class="simple">
+<li>It is not meant to be used asynchronously.</li>
+<li>A single <em>SMBConnection</em> instance should not be used to perform more than one operation concurrently at the same time.</li>
+<li>Do not keep a <em>SMBConnection</em> instance &#8220;idle&#8221; for too long, i.e. keeping a <em>SMBConnection</em> instance but not using it.
+Most SMB/CIFS servers have some sort of keepalive mechanism and impose a timeout limit.
+If the clients fail to respond within the timeout limit, the SMB/CIFS server may disconnect the client.</li>
+</ul>
+</div>
+</div>
+
+
+          </div>
+        </div>
+      </div>
+      <div class="clearer"></div>
+    </div>
+    <div class="related" role="navigation" aria-label="related navigation">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="../genindex.html" title="General Index"
+             >index</a></li>
+        <li class="right" >
+          <a href="../py-modindex.html" title="Python Module Index"
+             >modules</a> |</li>
+        <li class="right" >
+          <a href="smb_SMBHandler.html" title="SMbHandler Class"
+             >next</a> |</li>
+        <li class="right" >
+          <a href="nmb_NetBIOS.html" title="NetBIOS class"
+             >previous</a> |</li>
+        <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.1.25 documentation</a> &raquo;</li> 
+      </ul>
+    </div>
+    <div class="footer" role="contentinfo">
+        &copy; Copyright 2001-2018, Michael Teo http://miketeo.net/.
+      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.6.
+    </div>
+  </body>
+</html>
\ No newline at end of file
diff --git a/docs/html/api/smb_SMBHandler.html b/docs/html/api/smb_SMBHandler.html
new file mode 100644
index 00000000..ff3e9ac7
--- /dev/null
+++ b/docs/html/api/smb_SMBHandler.html
@@ -0,0 +1,173 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    
+    <title>SMbHandler Class &mdash; pysmb 1.1.25 documentation</title>
+    
+    <link rel="stylesheet" href="../_static/sphinxdoc.css" type="text/css" />
+    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
+    
+    <script type="text/javascript">
+      var DOCUMENTATION_OPTIONS = {
+        URL_ROOT:    '../',
+        VERSION:     '1.1.25',
+        COLLAPSE_INDEX: false,
+        FILE_SUFFIX: '.html',
+        HAS_SOURCE:  true
+      };
+    </script>
+    <script type="text/javascript" src="../_static/jquery.js"></script>
+    <script type="text/javascript" src="../_static/underscore.js"></script>
+    <script type="text/javascript" src="../_static/doctools.js"></script>
+    <link rel="top" title="pysmb 1.1.25 documentation" href="../index.html" />
+    <link rel="next" title="SMBProtocolFactory Class" href="smb_SMBProtocolFactory.html" />
+    <link rel="prev" title="SMBConnection Class" href="smb_SMBConnection.html" /> 
+  </head>
+  <body role="document">
+    <div class="related" role="navigation" aria-label="related navigation">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="../genindex.html" title="General Index"
+             accesskey="I">index</a></li>
+        <li class="right" >
+          <a href="../py-modindex.html" title="Python Module Index"
+             >modules</a> |</li>
+        <li class="right" >
+          <a href="smb_SMBProtocolFactory.html" title="SMBProtocolFactory Class"
+             accesskey="N">next</a> |</li>
+        <li class="right" >
+          <a href="smb_SMBConnection.html" title="SMBConnection Class"
+             accesskey="P">previous</a> |</li>
+        <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.1.25 documentation</a> &raquo;</li> 
+      </ul>
+    </div>
+      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
+        <div class="sphinxsidebarwrapper">
+  <h3><a href="../index.html">Table Of Contents</a></h3>
+  <ul>
+<li><a class="reference internal" href="#">SMbHandler Class</a><ul>
+<li><a class="reference internal" href="#notes">Notes</a></li>
+<li><a class="reference internal" href="#example">Example</a></li>
+</ul>
+</li>
+</ul>
+
+  <h4>Previous topic</h4>
+  <p class="topless"><a href="smb_SMBConnection.html"
+                        title="previous chapter">SMBConnection Class</a></p>
+  <h4>Next topic</h4>
+  <p class="topless"><a href="smb_SMBProtocolFactory.html"
+                        title="next chapter">SMBProtocolFactory Class</a></p>
+  <div role="note" aria-label="source link">
+    <h3>This Page</h3>
+    <ul class="this-page-menu">
+      <li><a href="../_sources/api/smb_SMBHandler.txt"
+            rel="nofollow">Show Source</a></li>
+    </ul>
+   </div>
+<div id="searchbox" style="display: none" role="search">
+  <h3>Quick search</h3>
+    <form class="search" action="../search.html" method="get">
+      <input type="text" name="q" />
+      <input type="submit" value="Go" />
+      <input type="hidden" name="check_keywords" value="yes" />
+      <input type="hidden" name="area" value="default" />
+    </form>
+    <p class="searchtip" style="font-size: 90%">
+    Enter search terms or a module, class or function name.
+    </p>
+</div>
+<script type="text/javascript">$('#searchbox').show(0);</script>
+        </div>
+      </div>
+
+    <div class="document">
+      <div class="documentwrapper">
+        <div class="bodywrapper">
+          <div class="body" role="main">
+            
+  <div class="section" id="smbhandler-class">
+<h1>SMbHandler Class<a class="headerlink" href="#smbhandler-class" title="Permalink to this headline">¶</a></h1>
+<p>The SMBHandler class provides support for &#8220;<a class="reference external" href="smb://">smb://</a>&#8221; URLs in the <a class="reference external" href="http://docs.python.org/library/urllib2.html">urllib2</a> python package.</p>
+<div class="section" id="notes">
+<h2>Notes<a class="headerlink" href="#notes" title="Permalink to this headline">¶</a></h2>
+<ul class="simple">
+<li>Note that you need to pass in a valid hostname or IP address for the host component of the URL.
+Do not use the Windows/NetBIOS machine name for the host component.</li>
+<li>The first component of the path in the URL points to the name of the shared folder.
+Subsequent path components will point to the directory/folder of the file.</li>
+<li>You can retrieve and upload files, but you cannot delete files/folders or create folders.
+In uploads, if the parent folders do not exist, an <em>urllib2.URLError</em> will be raised.</li>
+</ul>
+</div>
+<div class="section" id="example">
+<h2>Example<a class="headerlink" href="#example" title="Permalink to this headline">¶</a></h2>
+<p>The following code snippet illustrates file retrieval.:</p>
+<div class="highlight-python"><div class="highlight"><pre><span class="c1"># -*- coding: utf-8 -*-</span>
+<span class="kn">import</span> <span class="nn">urllib2</span>
+<span class="kn">from</span> <span class="nn">smb.SMBHandler</span> <span class="kn">import</span> <span class="n">SMBHandler</span>
+
+<span class="n">director</span> <span class="o">=</span> <span class="n">urllib2</span><span class="o">.</span><span class="n">build_opener</span><span class="p">(</span><span class="n">SMBHandler</span><span class="p">)</span>
+<span class="n">fh</span> <span class="o">=</span> <span class="n">director</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="s1">&#39;smb://myuserID:mypassword@192.168.1.1/sharedfolder/rfc1001.txt&#39;</span><span class="p">)</span>
+
+<span class="c1"># Process fh like a file-like object and then close it.</span>
+<span class="n">fh</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
+
+<span class="c1"># For paths/files with unicode characters, simply pass in the URL as an unicode string</span>
+<span class="n">fh2</span> <span class="o">=</span> <span class="n">director</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="s1">u&#39;smb://myuserID:mypassword@192.168.1.1/sharedfolder/测试文件夹/垃圾文件.dat&#39;</span><span class="p">)</span>
+
+<span class="c1"># Process fh2 like a file-like object and then close it.</span>
+<span class="n">fh2</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
+</pre></div>
+</div>
+<p>The following code snippet illustrates file upload. You need to provide a file-like object for the <em>data</em> parameter in the <em>open()</em> method:</p>
+<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">urllib2</span>
+<span class="kn">from</span> <span class="nn">smb.SMBHandler</span> <span class="kn">import</span> <span class="n">SMBHandler</span>
+
+<span class="n">file_fh</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="s1">&#39;local_file.dat&#39;</span><span class="p">,</span> <span class="s1">&#39;rb&#39;</span><span class="p">)</span>
+
+<span class="n">director</span> <span class="o">=</span> <span class="n">urllib2</span><span class="o">.</span><span class="n">build_opener</span><span class="p">(</span><span class="n">SMBHandler</span><span class="p">)</span>
+<span class="n">fh</span> <span class="o">=</span> <span class="n">director</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="s1">&#39;smb://myuserID:mypassword@192.168.1.1/sharedfolder/upload_file.dat&#39;</span><span class="p">,</span> <span class="n">data</span> <span class="o">=</span> <span class="n">file_fh</span><span class="p">)</span>
+
+<span class="c1"># Reading from fh will only return an empty string</span>
+<span class="n">fh</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
+</pre></div>
+</div>
+</div>
+</div>
+
+
+          </div>
+        </div>
+      </div>
+      <div class="clearer"></div>
+    </div>
+    <div class="related" role="navigation" aria-label="related navigation">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="../genindex.html" title="General Index"
+             >index</a></li>
+        <li class="right" >
+          <a href="../py-modindex.html" title="Python Module Index"
+             >modules</a> |</li>
+        <li class="right" >
+          <a href="smb_SMBProtocolFactory.html" title="SMBProtocolFactory Class"
+             >next</a> |</li>
+        <li class="right" >
+          <a href="smb_SMBConnection.html" title="SMBConnection Class"
+             >previous</a> |</li>
+        <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.1.25 documentation</a> &raquo;</li> 
+      </ul>
+    </div>
+    <div class="footer" role="contentinfo">
+        &copy; Copyright 2001-2018, Michael Teo http://miketeo.net/.
+      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.6.
+    </div>
+  </body>
+</html>
\ No newline at end of file
diff --git a/docs/html/api/smb_SMBProtocolFactory.html b/docs/html/api/smb_SMBProtocolFactory.html
new file mode 100644
index 00000000..232c75f9
--- /dev/null
+++ b/docs/html/api/smb_SMBProtocolFactory.html
@@ -0,0 +1,211 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    
+    <title>SMBProtocolFactory Class &mdash; pysmb 1.1.25 documentation</title>
+    
+    <link rel="stylesheet" href="../_static/sphinxdoc.css" type="text/css" />
+    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
+    
+    <script type="text/javascript">
+      var DOCUMENTATION_OPTIONS = {
+        URL_ROOT:    '../',
+        VERSION:     '1.1.25',
+        COLLAPSE_INDEX: false,
+        FILE_SUFFIX: '.html',
+        HAS_SOURCE:  true
+      };
+    </script>
+    <script type="text/javascript" src="../_static/jquery.js"></script>
+    <script type="text/javascript" src="../_static/underscore.js"></script>
+    <script type="text/javascript" src="../_static/doctools.js"></script>
+    <link rel="top" title="pysmb 1.1.25 documentation" href="../index.html" />
+    <link rel="next" title="SharedDevice Class" href="smb_SharedDevice.html" />
+    <link rel="prev" title="SMbHandler Class" href="smb_SMBHandler.html" /> 
+  </head>
+  <body role="document">
+    <div class="related" role="navigation" aria-label="related navigation">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="../genindex.html" title="General Index"
+             accesskey="I">index</a></li>
+        <li class="right" >
+          <a href="../py-modindex.html" title="Python Module Index"
+             >modules</a> |</li>
+        <li class="right" >
+          <a href="smb_SharedDevice.html" title="SharedDevice Class"
+             accesskey="N">next</a> |</li>
+        <li class="right" >
+          <a href="smb_SMBHandler.html" title="SMbHandler Class"
+             accesskey="P">previous</a> |</li>
+        <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.1.25 documentation</a> &raquo;</li> 
+      </ul>
+    </div>
+      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
+        <div class="sphinxsidebarwrapper">
+  <h3><a href="../index.html">Table Of Contents</a></h3>
+  <ul>
+<li><a class="reference internal" href="#">SMBProtocolFactory Class</a><ul>
+<li><a class="reference internal" href="#example">Example</a></li>
+<li><a class="reference internal" href="#smb2-support">SMB2 Support</a></li>
+<li><a class="reference internal" href="#caveats">Caveats</a></li>
+</ul>
+</li>
+</ul>
+
+  <h4>Previous topic</h4>
+  <p class="topless"><a href="smb_SMBHandler.html"
+                        title="previous chapter">SMbHandler Class</a></p>
+  <h4>Next topic</h4>
+  <p class="topless"><a href="smb_SharedDevice.html"
+                        title="next chapter">SharedDevice Class</a></p>
+  <div role="note" aria-label="source link">
+    <h3>This Page</h3>
+    <ul class="this-page-menu">
+      <li><a href="../_sources/api/smb_SMBProtocolFactory.txt"
+            rel="nofollow">Show Source</a></li>
+    </ul>
+   </div>
+<div id="searchbox" style="display: none" role="search">
+  <h3>Quick search</h3>
+    <form class="search" action="../search.html" method="get">
+      <input type="text" name="q" />
+      <input type="submit" value="Go" />
+      <input type="hidden" name="check_keywords" value="yes" />
+      <input type="hidden" name="area" value="default" />
+    </form>
+    <p class="searchtip" style="font-size: 90%">
+    Enter search terms or a module, class or function name.
+    </p>
+</div>
+<script type="text/javascript">$('#searchbox').show(0);</script>
+        </div>
+      </div>
+
+    <div class="document">
+      <div class="documentwrapper">
+        <div class="bodywrapper">
+          <div class="body" role="main">
+            
+  <div class="section" id="smbprotocolfactory-class">
+<h1>SMBProtocolFactory Class<a class="headerlink" href="#smbprotocolfactory-class" title="Permalink to this headline">¶</a></h1>
+<p>For those who want to utilize pysmb in Twisted framework, pysmb has a <em>smb.SMBProtocol.SMBProtocol</em> implementation.
+In most cases, you do not need to touch or import the <em>SMBProtocol</em> directly. All the SMB functionalities are exposed in the <em>SMBProtocolFactory</em>.</p>
+<dl class="docutils">
+<dt>In your project,</dt>
+<dd><ol class="first last arabic simple">
+<li>Create a new class and subclass <em>SMBProtocolFactory</em>.</li>
+<li>Override the <em>SMBProtocolFactory.onAuthOK</em> and <em>SMBProtocolFactory.onAuthFailed</em> instance methods to provide your own post-authenthentication handling.
+Once <em>SMBProtocolFactory.onAuthOK</em> has been called by pymsb internals, your application is ready to communicate with the remote SMB/CIFS service through
+the <em>SMBProtocolFactory</em> public methods such as <em>SMBProtocolFactory.storeFile</em>, <em>SMBProtocolFactory.retrieveFile</em>, etc.</li>
+<li>When you want to disconnect from the remote SMB/CIFS server, just call <em>SMBProtocolFactory.closeConnection</em> method.</li>
+</ol>
+</dd>
+</dl>
+<p>All the <em>SMBProtocolFactory</em> public methods that provide file functionlities will return a <em>twisted.internet.defer.Deferred</em> instance.
+A <a class="reference internal" href="smb_exceptions.html"><em>NotReadyError</em></a> exception is raised when the underlying SMB is not authenticated.
+If the underlying SMB connection has been terminated, a <a class="reference internal" href="smb_exceptions.html"><em>NotConnectedError</em></a> exception is raised.</p>
+<p>All the file operation methods in <em>SMBProtocolFactory</em> class accept a <em>timeout</em> parameter. This parameter specifies the time limit where pysmb will wait for the
+entire file operation (except <em>storeFile</em> and <em>retrieveFile</em> methods) to complete. If the file operation fails to complete within the timeout period, the returned
+<em>Deferred</em> instance&#8217;s <em>errback</em> method will be called with a <em>SMBTimeout</em> exception.</p>
+<p>If you are interested in learning the results of the operation or to know when the operation has completed, you should
+add a handling method to the returned <em>Deferred</em> instance via <em>Deferred.addCallback</em>. If the file operation fails, the <em>Deferred.errback</em> function will be called
+with an <a class="reference internal" href="smb_exceptions.html"><em>OperationFailure</em></a>; on timeout, it will be called with a <a class="reference internal" href="smb_exceptions.html"><em>SMBTimeout</em></a>.</p>
+<div class="section" id="example">
+<h2>Example<a class="headerlink" href="#example" title="Permalink to this headline">¶</a></h2>
+<p>The following illustrates a simple file retrieving implementation.:</p>
+<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">tempfile</span>
+<span class="kn">from</span> <span class="nn">twisted.internet</span> <span class="kn">import</span> <span class="n">reactor</span>
+<span class="kn">from</span> <span class="nn">smb.SMBProtocol</span> <span class="kn">import</span> <span class="n">SMBProtocolFactory</span>
+
+<span class="k">class</span> <span class="nc">RetrieveFileFactory</span><span class="p">(</span><span class="n">SMBProtocolFactory</span><span class="p">):</span>
+
+    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
+        <span class="n">SMBProtocolFactory</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
+
+    <span class="k">def</span> <span class="nf">fileRetrieved</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">write_result</span><span class="p">):</span>
+        <span class="n">file_obj</span><span class="p">,</span> <span class="n">file_attributes</span><span class="p">,</span> <span class="n">file_size</span> <span class="o">=</span> <span class="n">write_result</span>
+
+        <span class="c1"># Retrieved file contents are inside file_obj</span>
+        <span class="c1"># Do what you need with the file_obj and then close it</span>
+        <span class="c1"># Note that the file obj is positioned at the end-of-file,</span>
+        <span class="c1"># so you might need to perform a file_obj.seek() to if you</span>
+        <span class="c1"># need to read from the beginning</span>
+        <span class="n">file_obj</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
+
+        <span class="bp">self</span><span class="o">.</span><span class="n">transport</span><span class="o">.</span><span class="n">loseConnection</span><span class="p">()</span>
+
+    <span class="k">def</span> <span class="nf">onAuthOK</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="n">d</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">retrieveFile</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">service</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">path</span><span class="p">,</span> <span class="n">tempfile</span><span class="o">.</span><span class="n">NamedTemporaryFile</span><span class="p">())</span>
+        <span class="n">d</span><span class="o">.</span><span class="n">addCallback</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">fileRetrieved</span><span class="p">)</span>
+        <span class="n">d</span><span class="o">.</span><span class="n">addErrback</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">d</span><span class="o">.</span><span class="n">errback</span><span class="p">)</span>
+
+    <span class="k">def</span> <span class="nf">onAuthFailed</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="k">print</span> <span class="s1">&#39;Auth failed&#39;</span>
+
+<span class="c1"># There will be some mechanism to capture userID, password, client_machine_name, server_name and server_ip</span>
+<span class="c1"># client_machine_name can be an arbitary ASCII string</span>
+<span class="c1"># server_name should match the remote machine name, or else the connection will be rejected</span>
+<span class="n">factory</span> <span class="o">=</span> <span class="n">RetrieveFileFactory</span><span class="p">(</span><span class="n">userID</span><span class="p">,</span> <span class="n">password</span><span class="p">,</span> <span class="n">client_machine_name</span><span class="p">,</span> <span class="n">server_name</span><span class="p">,</span> <span class="n">use_ntlm_v2</span> <span class="o">=</span> <span class="bp">True</span><span class="p">)</span>
+<span class="n">factory</span><span class="o">.</span><span class="n">service</span> <span class="o">=</span> <span class="s1">&#39;smbtest&#39;</span>
+<span class="n">factory</span><span class="o">.</span><span class="n">path</span> <span class="o">=</span> <span class="s1">&#39;/rfc1001.txt&#39;</span>
+<span class="n">reactor</span><span class="o">.</span><span class="n">connectTCP</span><span class="p">(</span><span class="n">server_ip</span><span class="p">,</span> <span class="mi">139</span><span class="p">,</span> <span class="n">factory</span><span class="p">)</span>
+</pre></div>
+</div>
+</div>
+<div class="section" id="smb2-support">
+<h2>SMB2 Support<a class="headerlink" href="#smb2-support" title="Permalink to this headline">¶</a></h2>
+<p>Starting from pysmb 1.1.0, pysmb will utilize SMB2 protocol for communication if the remote SMB/CIFS service supports SMB2.
+Otherwise, it will fallback automatically back to using SMB1 protocol.</p>
+<p>To disable SMB2 protocol in pysmb, set the <em>SUPPORT_SMB2</em> flag in the <em>smb_structs</em> module to <em>False</em> before creating the <em>SMBProtocolFactory</em> instance.:</p>
+<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">smb</span> <span class="kn">import</span> <span class="n">smb_structs</span>
+<span class="n">smb_structs</span><span class="o">.</span><span class="n">SUPPORT_SMB2</span> <span class="o">=</span> <span class="bp">False</span>
+</pre></div>
+</div>
+</div>
+<div class="section" id="caveats">
+<h2>Caveats<a class="headerlink" href="#caveats" title="Permalink to this headline">¶</a></h2>
+<ul class="simple">
+<li>A new factory instance must be created for each SMB connection to the remote SMB/CIFS service. Avoid reusing the same factory instance for more than one SMB connection.</li>
+<li>The remote SMB/CIFS server usually imposes a limit of the number of concurrent file operations for each client. For example, to transfer a thousand files, you may need to setup a queue in your application and call <em>storeFile</em> or <em>retrieveFile</em> in batches.</li>
+<li>The <em>timeout</em> parameter in the file operation methods are not precise; it is accurate to within 1 second interval, i.e. with a timeout of 0.5 sec, pysmb might raise
+<em>SMBTimeout</em> exception after 1.5 sec.</li>
+</ul>
+</div>
+</div>
+
+
+          </div>
+        </div>
+      </div>
+      <div class="clearer"></div>
+    </div>
+    <div class="related" role="navigation" aria-label="related navigation">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="../genindex.html" title="General Index"
+             >index</a></li>
+        <li class="right" >
+          <a href="../py-modindex.html" title="Python Module Index"
+             >modules</a> |</li>
+        <li class="right" >
+          <a href="smb_SharedDevice.html" title="SharedDevice Class"
+             >next</a> |</li>
+        <li class="right" >
+          <a href="smb_SMBHandler.html" title="SMbHandler Class"
+             >previous</a> |</li>
+        <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.1.25 documentation</a> &raquo;</li> 
+      </ul>
+    </div>
+    <div class="footer" role="contentinfo">
+        &copy; Copyright 2001-2018, Michael Teo http://miketeo.net/.
+      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.6.
+    </div>
+  </body>
+</html>
\ No newline at end of file
diff --git a/docs/html/api/smb_SharedDevice.html b/docs/html/api/smb_SharedDevice.html
new file mode 100644
index 00000000..46d17a9e
--- /dev/null
+++ b/docs/html/api/smb_SharedDevice.html
@@ -0,0 +1,118 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    
+    <title>SharedDevice Class &mdash; pysmb 1.1.25 documentation</title>
+    
+    <link rel="stylesheet" href="../_static/sphinxdoc.css" type="text/css" />
+    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
+    
+    <script type="text/javascript">
+      var DOCUMENTATION_OPTIONS = {
+        URL_ROOT:    '../',
+        VERSION:     '1.1.25',
+        COLLAPSE_INDEX: false,
+        FILE_SUFFIX: '.html',
+        HAS_SOURCE:  true
+      };
+    </script>
+    <script type="text/javascript" src="../_static/jquery.js"></script>
+    <script type="text/javascript" src="../_static/underscore.js"></script>
+    <script type="text/javascript" src="../_static/doctools.js"></script>
+    <link rel="top" title="pysmb 1.1.25 documentation" href="../index.html" />
+    <link rel="next" title="SharedFile Class" href="smb_SharedFile.html" />
+    <link rel="prev" title="SMBProtocolFactory Class" href="smb_SMBProtocolFactory.html" /> 
+  </head>
+  <body role="document">
+    <div class="related" role="navigation" aria-label="related navigation">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="../genindex.html" title="General Index"
+             accesskey="I">index</a></li>
+        <li class="right" >
+          <a href="../py-modindex.html" title="Python Module Index"
+             >modules</a> |</li>
+        <li class="right" >
+          <a href="smb_SharedFile.html" title="SharedFile Class"
+             accesskey="N">next</a> |</li>
+        <li class="right" >
+          <a href="smb_SMBProtocolFactory.html" title="SMBProtocolFactory Class"
+             accesskey="P">previous</a> |</li>
+        <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.1.25 documentation</a> &raquo;</li> 
+      </ul>
+    </div>
+      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
+        <div class="sphinxsidebarwrapper">
+  <h4>Previous topic</h4>
+  <p class="topless"><a href="smb_SMBProtocolFactory.html"
+                        title="previous chapter">SMBProtocolFactory Class</a></p>
+  <h4>Next topic</h4>
+  <p class="topless"><a href="smb_SharedFile.html"
+                        title="next chapter">SharedFile Class</a></p>
+  <div role="note" aria-label="source link">
+    <h3>This Page</h3>
+    <ul class="this-page-menu">
+      <li><a href="../_sources/api/smb_SharedDevice.txt"
+            rel="nofollow">Show Source</a></li>
+    </ul>
+   </div>
+<div id="searchbox" style="display: none" role="search">
+  <h3>Quick search</h3>
+    <form class="search" action="../search.html" method="get">
+      <input type="text" name="q" />
+      <input type="submit" value="Go" />
+      <input type="hidden" name="check_keywords" value="yes" />
+      <input type="hidden" name="area" value="default" />
+    </form>
+    <p class="searchtip" style="font-size: 90%">
+    Enter search terms or a module, class or function name.
+    </p>
+</div>
+<script type="text/javascript">$('#searchbox').show(0);</script>
+        </div>
+      </div>
+
+    <div class="document">
+      <div class="documentwrapper">
+        <div class="bodywrapper">
+          <div class="body" role="main">
+            
+  <div class="section" id="shareddevice-class">
+<h1>SharedDevice Class<a class="headerlink" href="#shareddevice-class" title="Permalink to this headline">¶</a></h1>
+</div>
+
+
+          </div>
+        </div>
+      </div>
+      <div class="clearer"></div>
+    </div>
+    <div class="related" role="navigation" aria-label="related navigation">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="../genindex.html" title="General Index"
+             >index</a></li>
+        <li class="right" >
+          <a href="../py-modindex.html" title="Python Module Index"
+             >modules</a> |</li>
+        <li class="right" >
+          <a href="smb_SharedFile.html" title="SharedFile Class"
+             >next</a> |</li>
+        <li class="right" >
+          <a href="smb_SMBProtocolFactory.html" title="SMBProtocolFactory Class"
+             >previous</a> |</li>
+        <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.1.25 documentation</a> &raquo;</li> 
+      </ul>
+    </div>
+    <div class="footer" role="contentinfo">
+        &copy; Copyright 2001-2018, Michael Teo http://miketeo.net/.
+      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.6.
+    </div>
+  </body>
+</html>
\ No newline at end of file
diff --git a/docs/html/api/smb_SharedFile.html b/docs/html/api/smb_SharedFile.html
new file mode 100644
index 00000000..7a708e27
--- /dev/null
+++ b/docs/html/api/smb_SharedFile.html
@@ -0,0 +1,118 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    
+    <title>SharedFile Class &mdash; pysmb 1.1.25 documentation</title>
+    
+    <link rel="stylesheet" href="../_static/sphinxdoc.css" type="text/css" />
+    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
+    
+    <script type="text/javascript">
+      var DOCUMENTATION_OPTIONS = {
+        URL_ROOT:    '../',
+        VERSION:     '1.1.25',
+        COLLAPSE_INDEX: false,
+        FILE_SUFFIX: '.html',
+        HAS_SOURCE:  true
+      };
+    </script>
+    <script type="text/javascript" src="../_static/jquery.js"></script>
+    <script type="text/javascript" src="../_static/underscore.js"></script>
+    <script type="text/javascript" src="../_static/doctools.js"></script>
+    <link rel="top" title="pysmb 1.1.25 documentation" href="../index.html" />
+    <link rel="next" title="SMB Exceptions" href="smb_exceptions.html" />
+    <link rel="prev" title="SharedDevice Class" href="smb_SharedDevice.html" /> 
+  </head>
+  <body role="document">
+    <div class="related" role="navigation" aria-label="related navigation">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="../genindex.html" title="General Index"
+             accesskey="I">index</a></li>
+        <li class="right" >
+          <a href="../py-modindex.html" title="Python Module Index"
+             >modules</a> |</li>
+        <li class="right" >
+          <a href="smb_exceptions.html" title="SMB Exceptions"
+             accesskey="N">next</a> |</li>
+        <li class="right" >
+          <a href="smb_SharedDevice.html" title="SharedDevice Class"
+             accesskey="P">previous</a> |</li>
+        <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.1.25 documentation</a> &raquo;</li> 
+      </ul>
+    </div>
+      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
+        <div class="sphinxsidebarwrapper">
+  <h4>Previous topic</h4>
+  <p class="topless"><a href="smb_SharedDevice.html"
+                        title="previous chapter">SharedDevice Class</a></p>
+  <h4>Next topic</h4>
+  <p class="topless"><a href="smb_exceptions.html"
+                        title="next chapter">SMB Exceptions</a></p>
+  <div role="note" aria-label="source link">
+    <h3>This Page</h3>
+    <ul class="this-page-menu">
+      <li><a href="../_sources/api/smb_SharedFile.txt"
+            rel="nofollow">Show Source</a></li>
+    </ul>
+   </div>
+<div id="searchbox" style="display: none" role="search">
+  <h3>Quick search</h3>
+    <form class="search" action="../search.html" method="get">
+      <input type="text" name="q" />
+      <input type="submit" value="Go" />
+      <input type="hidden" name="check_keywords" value="yes" />
+      <input type="hidden" name="area" value="default" />
+    </form>
+    <p class="searchtip" style="font-size: 90%">
+    Enter search terms or a module, class or function name.
+    </p>
+</div>
+<script type="text/javascript">$('#searchbox').show(0);</script>
+        </div>
+      </div>
+
+    <div class="document">
+      <div class="documentwrapper">
+        <div class="bodywrapper">
+          <div class="body" role="main">
+            
+  <div class="section" id="sharedfile-class">
+<h1>SharedFile Class<a class="headerlink" href="#sharedfile-class" title="Permalink to this headline">¶</a></h1>
+</div>
+
+
+          </div>
+        </div>
+      </div>
+      <div class="clearer"></div>
+    </div>
+    <div class="related" role="navigation" aria-label="related navigation">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="../genindex.html" title="General Index"
+             >index</a></li>
+        <li class="right" >
+          <a href="../py-modindex.html" title="Python Module Index"
+             >modules</a> |</li>
+        <li class="right" >
+          <a href="smb_exceptions.html" title="SMB Exceptions"
+             >next</a> |</li>
+        <li class="right" >
+          <a href="smb_SharedDevice.html" title="SharedDevice Class"
+             >previous</a> |</li>
+        <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.1.25 documentation</a> &raquo;</li> 
+      </ul>
+    </div>
+    <div class="footer" role="contentinfo">
+        &copy; Copyright 2001-2018, Michael Teo http://miketeo.net/.
+      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.6.
+    </div>
+  </body>
+</html>
\ No newline at end of file
diff --git a/docs/html/api/smb_exceptions.html b/docs/html/api/smb_exceptions.html
new file mode 100644
index 00000000..ebc21c79
--- /dev/null
+++ b/docs/html/api/smb_exceptions.html
@@ -0,0 +1,135 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    
+    <title>SMB Exceptions &mdash; pysmb 1.1.25 documentation</title>
+    
+    <link rel="stylesheet" href="../_static/sphinxdoc.css" type="text/css" />
+    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
+    
+    <script type="text/javascript">
+      var DOCUMENTATION_OPTIONS = {
+        URL_ROOT:    '../',
+        VERSION:     '1.1.25',
+        COLLAPSE_INDEX: false,
+        FILE_SUFFIX: '.html',
+        HAS_SOURCE:  true
+      };
+    </script>
+    <script type="text/javascript" src="../_static/jquery.js"></script>
+    <script type="text/javascript" src="../_static/underscore.js"></script>
+    <script type="text/javascript" src="../_static/doctools.js"></script>
+    <link rel="top" title="pysmb 1.1.25 documentation" href="../index.html" />
+    <link rel="next" title="Security Descriptors" href="smb_security_descriptors.html" />
+    <link rel="prev" title="SharedFile Class" href="smb_SharedFile.html" /> 
+  </head>
+  <body role="document">
+    <div class="related" role="navigation" aria-label="related navigation">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="../genindex.html" title="General Index"
+             accesskey="I">index</a></li>
+        <li class="right" >
+          <a href="../py-modindex.html" title="Python Module Index"
+             >modules</a> |</li>
+        <li class="right" >
+          <a href="smb_security_descriptors.html" title="Security Descriptors"
+             accesskey="N">next</a> |</li>
+        <li class="right" >
+          <a href="smb_SharedFile.html" title="SharedFile Class"
+             accesskey="P">previous</a> |</li>
+        <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.1.25 documentation</a> &raquo;</li> 
+      </ul>
+    </div>
+      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
+        <div class="sphinxsidebarwrapper">
+  <h4>Previous topic</h4>
+  <p class="topless"><a href="smb_SharedFile.html"
+                        title="previous chapter">SharedFile Class</a></p>
+  <h4>Next topic</h4>
+  <p class="topless"><a href="smb_security_descriptors.html"
+                        title="next chapter">Security Descriptors</a></p>
+  <div role="note" aria-label="source link">
+    <h3>This Page</h3>
+    <ul class="this-page-menu">
+      <li><a href="../_sources/api/smb_exceptions.txt"
+            rel="nofollow">Show Source</a></li>
+    </ul>
+   </div>
+<div id="searchbox" style="display: none" role="search">
+  <h3>Quick search</h3>
+    <form class="search" action="../search.html" method="get">
+      <input type="text" name="q" />
+      <input type="submit" value="Go" />
+      <input type="hidden" name="check_keywords" value="yes" />
+      <input type="hidden" name="area" value="default" />
+    </form>
+    <p class="searchtip" style="font-size: 90%">
+    Enter search terms or a module, class or function name.
+    </p>
+</div>
+<script type="text/javascript">$('#searchbox').show(0);</script>
+        </div>
+      </div>
+
+    <div class="document">
+      <div class="documentwrapper">
+        <div class="bodywrapper">
+          <div class="body" role="main">
+            
+  <div class="section" id="smb-exceptions">
+<h1>SMB Exceptions<a class="headerlink" href="#smb-exceptions" title="Permalink to this headline">¶</a></h1>
+<dl class="class">
+<dt id="smb.smb_structs.UnsupportedFeature">
+<em class="property">class </em><code class="descclassname">smb.smb_structs.</code><code class="descname">UnsupportedFeature</code><a class="reference internal" href="../_modules/smb/smb_structs.html#UnsupportedFeature"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#smb.smb_structs.UnsupportedFeature" title="Permalink to this definition">¶</a></dt>
+<dd><p>Raised when an supported feature is present/required in the protocol but is not
+currently supported by pysmb</p>
+</dd></dl>
+
+<dl class="class">
+<dt id="smb.smb_structs.ProtocolError">
+<em class="property">class </em><code class="descclassname">smb.smb_structs.</code><code class="descname">ProtocolError</code><span class="sig-paren">(</span><em>message</em>, <em>data_buf=None</em>, <em>smb_message=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/smb/smb_structs.html#ProtocolError"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#smb.smb_structs.ProtocolError" title="Permalink to this definition">¶</a></dt>
+<dd></dd></dl>
+
+<dl class="class">
+<dt id="smb.smb_structs.OperationFailure">
+<em class="property">class </em><code class="descclassname">smb.smb_structs.</code><code class="descname">OperationFailure</code><span class="sig-paren">(</span><em>message</em>, <em>smb_messages</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/smb/smb_structs.html#OperationFailure"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#smb.smb_structs.OperationFailure" title="Permalink to this definition">¶</a></dt>
+<dd></dd></dl>
+
+</div>
+
+
+          </div>
+        </div>
+      </div>
+      <div class="clearer"></div>
+    </div>
+    <div class="related" role="navigation" aria-label="related navigation">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="../genindex.html" title="General Index"
+             >index</a></li>
+        <li class="right" >
+          <a href="../py-modindex.html" title="Python Module Index"
+             >modules</a> |</li>
+        <li class="right" >
+          <a href="smb_security_descriptors.html" title="Security Descriptors"
+             >next</a> |</li>
+        <li class="right" >
+          <a href="smb_SharedFile.html" title="SharedFile Class"
+             >previous</a> |</li>
+        <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.1.25 documentation</a> &raquo;</li> 
+      </ul>
+    </div>
+    <div class="footer" role="contentinfo">
+        &copy; Copyright 2001-2018, Michael Teo http://miketeo.net/.
+      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.6.
+    </div>
+  </body>
+</html>
\ No newline at end of file
diff --git a/docs/html/api/smb_security_descriptors.html b/docs/html/api/smb_security_descriptors.html
new file mode 100644
index 00000000..0d583d53
--- /dev/null
+++ b/docs/html/api/smb_security_descriptors.html
@@ -0,0 +1,263 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    
+    <title>Security Descriptors &mdash; pysmb 1.1.25 documentation</title>
+    
+    <link rel="stylesheet" href="../_static/sphinxdoc.css" type="text/css" />
+    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
+    
+    <script type="text/javascript">
+      var DOCUMENTATION_OPTIONS = {
+        URL_ROOT:    '../',
+        VERSION:     '1.1.25',
+        COLLAPSE_INDEX: false,
+        FILE_SUFFIX: '.html',
+        HAS_SOURCE:  true
+      };
+    </script>
+    <script type="text/javascript" src="../_static/jquery.js"></script>
+    <script type="text/javascript" src="../_static/underscore.js"></script>
+    <script type="text/javascript" src="../_static/doctools.js"></script>
+    <link rel="top" title="pysmb 1.1.25 documentation" href="../index.html" />
+    <link rel="next" title="Extending pysmb For Other Frameworks" href="../extending.html" />
+    <link rel="prev" title="SMB Exceptions" href="smb_exceptions.html" /> 
+  </head>
+  <body role="document">
+    <div class="related" role="navigation" aria-label="related navigation">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="../genindex.html" title="General Index"
+             accesskey="I">index</a></li>
+        <li class="right" >
+          <a href="../py-modindex.html" title="Python Module Index"
+             >modules</a> |</li>
+        <li class="right" >
+          <a href="../extending.html" title="Extending pysmb For Other Frameworks"
+             accesskey="N">next</a> |</li>
+        <li class="right" >
+          <a href="smb_exceptions.html" title="SMB Exceptions"
+             accesskey="P">previous</a> |</li>
+        <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.1.25 documentation</a> &raquo;</li> 
+      </ul>
+    </div>
+      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
+        <div class="sphinxsidebarwrapper">
+  <h4>Previous topic</h4>
+  <p class="topless"><a href="smb_exceptions.html"
+                        title="previous chapter">SMB Exceptions</a></p>
+  <h4>Next topic</h4>
+  <p class="topless"><a href="../extending.html"
+                        title="next chapter">Extending pysmb For Other Frameworks</a></p>
+  <div role="note" aria-label="source link">
+    <h3>This Page</h3>
+    <ul class="this-page-menu">
+      <li><a href="../_sources/api/smb_security_descriptors.txt"
+            rel="nofollow">Show Source</a></li>
+    </ul>
+   </div>
+<div id="searchbox" style="display: none" role="search">
+  <h3>Quick search</h3>
+    <form class="search" action="../search.html" method="get">
+      <input type="text" name="q" />
+      <input type="submit" value="Go" />
+      <input type="hidden" name="check_keywords" value="yes" />
+      <input type="hidden" name="area" value="default" />
+    </form>
+    <p class="searchtip" style="font-size: 90%">
+    Enter search terms or a module, class or function name.
+    </p>
+</div>
+<script type="text/javascript">$('#searchbox').show(0);</script>
+        </div>
+      </div>
+
+    <div class="document">
+      <div class="documentwrapper">
+        <div class="bodywrapper">
+          <div class="body" role="main">
+            
+  <div class="section" id="module-smb.security_descriptors">
+<span id="security-descriptors"></span><h1>Security Descriptors<a class="headerlink" href="#module-smb.security_descriptors" title="Permalink to this headline">¶</a></h1>
+<p>This module implements security descriptors, and associated data
+structures, as specified in <a class="reference external" href="https://msdn.microsoft.com/en-us/library/cc230273.aspx">[MS-DTYP]</a>.</p>
+<dl class="class">
+<dt id="smb.security_descriptors.SID">
+<em class="property">class </em><code class="descclassname">smb.security_descriptors.</code><code class="descname">SID</code><span class="sig-paren">(</span><em>revision</em>, <em>identifier_authority</em>, <em>subauthorities</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/smb/security_descriptors.html#SID"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#smb.security_descriptors.SID" title="Permalink to this definition">¶</a></dt>
+<dd><p>A Windows security identifier. Represents a single principal, such a
+user or a group, as a sequence of numbers consisting of the revision,
+identifier authority, and a variable-length list of subauthorities.</p>
+<p>See [MS-DTYP]: 2.4.2</p>
+<dl class="attribute">
+<dt id="smb.security_descriptors.SID.identifier_authority">
+<code class="descname">identifier_authority</code><em class="property"> = None</em><a class="headerlink" href="#smb.security_descriptors.SID.identifier_authority" title="Permalink to this definition">¶</a></dt>
+<dd><p>An integer representing the identifier authority.</p>
+</dd></dl>
+
+<dl class="attribute">
+<dt id="smb.security_descriptors.SID.revision">
+<code class="descname">revision</code><em class="property"> = None</em><a class="headerlink" href="#smb.security_descriptors.SID.revision" title="Permalink to this definition">¶</a></dt>
+<dd><p>Revision, should always be 1.</p>
+</dd></dl>
+
+<dl class="attribute">
+<dt id="smb.security_descriptors.SID.subauthorities">
+<code class="descname">subauthorities</code><em class="property"> = None</em><a class="headerlink" href="#smb.security_descriptors.SID.subauthorities" title="Permalink to this definition">¶</a></dt>
+<dd><p>A list of integers representing all subauthorities.</p>
+</dd></dl>
+
+</dd></dl>
+
+<dl class="class">
+<dt id="smb.security_descriptors.ACE">
+<em class="property">class </em><code class="descclassname">smb.security_descriptors.</code><code class="descname">ACE</code><span class="sig-paren">(</span><em>type_</em>, <em>flags</em>, <em>mask</em>, <em>sid</em>, <em>additional_data</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/smb/security_descriptors.html#ACE"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#smb.security_descriptors.ACE" title="Permalink to this definition">¶</a></dt>
+<dd><p>Represents a single access control entry.</p>
+<p>See [MS-DTYP]: 2.4.4</p>
+<dl class="attribute">
+<dt id="smb.security_descriptors.ACE.additional_data">
+<code class="descname">additional_data</code><em class="property"> = None</em><a class="headerlink" href="#smb.security_descriptors.ACE.additional_data" title="Permalink to this definition">¶</a></dt>
+<dd><p>A dictionary of additional fields present in the ACE, depending
+on the type. The following fields can be present:</p>
+<ul class="simple">
+<li><code class="docutils literal"><span class="pre">flags</span></code></li>
+<li><code class="docutils literal"><span class="pre">object_type</span></code></li>
+<li><code class="docutils literal"><span class="pre">inherited_object_type</span></code></li>
+<li><code class="docutils literal"><span class="pre">application_data</span></code></li>
+<li><code class="docutils literal"><span class="pre">attribute_data</span></code></li>
+</ul>
+</dd></dl>
+
+<dl class="attribute">
+<dt id="smb.security_descriptors.ACE.flags">
+<code class="descname">flags</code><em class="property"> = None</em><a class="headerlink" href="#smb.security_descriptors.ACE.flags" title="Permalink to this definition">¶</a></dt>
+<dd><p>An integer bitmask with ACE flags, corresponds to the
+<code class="docutils literal"><span class="pre">AceFlags</span></code> field.</p>
+</dd></dl>
+
+<dl class="attribute">
+<dt id="smb.security_descriptors.ACE.isInheritOnly">
+<code class="descname">isInheritOnly</code><a class="headerlink" href="#smb.security_descriptors.ACE.isInheritOnly" title="Permalink to this definition">¶</a></dt>
+<dd><p>Convenience property which indicates if this ACE is inherit
+only, meaning that it doesn&#8217;t apply to the object itself.</p>
+</dd></dl>
+
+<dl class="attribute">
+<dt id="smb.security_descriptors.ACE.mask">
+<code class="descname">mask</code><em class="property"> = None</em><a class="headerlink" href="#smb.security_descriptors.ACE.mask" title="Permalink to this definition">¶</a></dt>
+<dd><p>An integer representing the <code class="docutils literal"><span class="pre">ACCESS_MASK</span></code> as specified in
+[MS-DTYP] 2.4.3.</p>
+</dd></dl>
+
+<dl class="attribute">
+<dt id="smb.security_descriptors.ACE.sid">
+<code class="descname">sid</code><em class="property"> = None</em><a class="headerlink" href="#smb.security_descriptors.ACE.sid" title="Permalink to this definition">¶</a></dt>
+<dd><p>The <a class="reference internal" href="#smb.security_descriptors.SID" title="smb.security_descriptors.SID"><code class="xref py py-class docutils literal"><span class="pre">SID</span></code></a> of a trustee.</p>
+</dd></dl>
+
+<dl class="attribute">
+<dt id="smb.security_descriptors.ACE.type">
+<code class="descname">type</code><em class="property"> = None</em><a class="headerlink" href="#smb.security_descriptors.ACE.type" title="Permalink to this definition">¶</a></dt>
+<dd><p>An integer representing the type of the ACE. One of the
+<code class="docutils literal"><span class="pre">ACE_TYPE_*</span></code> constants. Corresponds to the <code class="docutils literal"><span class="pre">AceType</span></code> field
+from [MS-DTYP] 2.4.4.1.</p>
+</dd></dl>
+
+</dd></dl>
+
+<dl class="class">
+<dt id="smb.security_descriptors.ACL">
+<em class="property">class </em><code class="descclassname">smb.security_descriptors.</code><code class="descname">ACL</code><span class="sig-paren">(</span><em>revision</em>, <em>aces</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/smb/security_descriptors.html#ACL"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#smb.security_descriptors.ACL" title="Permalink to this definition">¶</a></dt>
+<dd><p>Access control list, encapsulating a sequence of access control
+entries.</p>
+<p>See [MS-DTYP]: 2.4.5</p>
+<dl class="attribute">
+<dt id="smb.security_descriptors.ACL.aces">
+<code class="descname">aces</code><em class="property"> = None</em><a class="headerlink" href="#smb.security_descriptors.ACL.aces" title="Permalink to this definition">¶</a></dt>
+<dd><p>List of <a class="reference internal" href="#smb.security_descriptors.ACE" title="smb.security_descriptors.ACE"><code class="xref py py-class docutils literal"><span class="pre">ACE</span></code></a> instances.</p>
+</dd></dl>
+
+<dl class="attribute">
+<dt id="smb.security_descriptors.ACL.revision">
+<code class="descname">revision</code><em class="property"> = None</em><a class="headerlink" href="#smb.security_descriptors.ACL.revision" title="Permalink to this definition">¶</a></dt>
+<dd><p>Integer value of the revision.</p>
+</dd></dl>
+
+</dd></dl>
+
+<dl class="class">
+<dt id="smb.security_descriptors.SecurityDescriptor">
+<em class="property">class </em><code class="descclassname">smb.security_descriptors.</code><code class="descname">SecurityDescriptor</code><span class="sig-paren">(</span><em>flags</em>, <em>owner</em>, <em>group</em>, <em>dacl</em>, <em>sacl</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/smb/security_descriptors.html#SecurityDescriptor"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#smb.security_descriptors.SecurityDescriptor" title="Permalink to this definition">¶</a></dt>
+<dd><p>Represents a security descriptor.</p>
+<p>See [MS-DTYP]: 2.4.6</p>
+<dl class="attribute">
+<dt id="smb.security_descriptors.SecurityDescriptor.dacl">
+<code class="descname">dacl</code><em class="property"> = None</em><a class="headerlink" href="#smb.security_descriptors.SecurityDescriptor.dacl" title="Permalink to this definition">¶</a></dt>
+<dd><p>Instance of <a class="reference internal" href="#smb.security_descriptors.ACL" title="smb.security_descriptors.ACL"><code class="xref py py-class docutils literal"><span class="pre">ACL</span></code></a> representing the discretionary access
+control list, which specifies access restrictions of an object.</p>
+</dd></dl>
+
+<dl class="attribute">
+<dt id="smb.security_descriptors.SecurityDescriptor.flags">
+<code class="descname">flags</code><em class="property"> = None</em><a class="headerlink" href="#smb.security_descriptors.SecurityDescriptor.flags" title="Permalink to this definition">¶</a></dt>
+<dd><p>Integer bitmask of control flags. Corresponds to the
+<code class="docutils literal"><span class="pre">Control</span></code> field in [MS-DTYP] 2.4.6.</p>
+</dd></dl>
+
+<dl class="attribute">
+<dt id="smb.security_descriptors.SecurityDescriptor.group">
+<code class="descname">group</code><em class="property"> = None</em><a class="headerlink" href="#smb.security_descriptors.SecurityDescriptor.group" title="Permalink to this definition">¶</a></dt>
+<dd><p>Instance of <a class="reference internal" href="#smb.security_descriptors.SID" title="smb.security_descriptors.SID"><code class="xref py py-class docutils literal"><span class="pre">SID</span></code></a> representing the owner group.</p>
+</dd></dl>
+
+<dl class="attribute">
+<dt id="smb.security_descriptors.SecurityDescriptor.owner">
+<code class="descname">owner</code><em class="property"> = None</em><a class="headerlink" href="#smb.security_descriptors.SecurityDescriptor.owner" title="Permalink to this definition">¶</a></dt>
+<dd><p>Instance of <a class="reference internal" href="#smb.security_descriptors.SID" title="smb.security_descriptors.SID"><code class="xref py py-class docutils literal"><span class="pre">SID</span></code></a> representing the owner user.</p>
+</dd></dl>
+
+<dl class="attribute">
+<dt id="smb.security_descriptors.SecurityDescriptor.sacl">
+<code class="descname">sacl</code><em class="property"> = None</em><a class="headerlink" href="#smb.security_descriptors.SecurityDescriptor.sacl" title="Permalink to this definition">¶</a></dt>
+<dd><p>Instance of <a class="reference internal" href="#smb.security_descriptors.ACL" title="smb.security_descriptors.ACL"><code class="xref py py-class docutils literal"><span class="pre">ACL</span></code></a> representing the system access control
+list, which specifies audit logging of an object.</p>
+</dd></dl>
+
+</dd></dl>
+
+</div>
+
+
+          </div>
+        </div>
+      </div>
+      <div class="clearer"></div>
+    </div>
+    <div class="related" role="navigation" aria-label="related navigation">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="../genindex.html" title="General Index"
+             >index</a></li>
+        <li class="right" >
+          <a href="../py-modindex.html" title="Python Module Index"
+             >modules</a> |</li>
+        <li class="right" >
+          <a href="../extending.html" title="Extending pysmb For Other Frameworks"
+             >next</a> |</li>
+        <li class="right" >
+          <a href="smb_exceptions.html" title="SMB Exceptions"
+             >previous</a> |</li>
+        <li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.1.25 documentation</a> &raquo;</li> 
+      </ul>
+    </div>
+    <div class="footer" role="contentinfo">
+        &copy; Copyright 2001-2018, Michael Teo http://miketeo.net/.
+      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.6.
+    </div>
+  </body>
+</html>
\ No newline at end of file
diff --git a/docs/html/extending.html b/docs/html/extending.html
new file mode 100644
index 00000000..b7903bd3
--- /dev/null
+++ b/docs/html/extending.html
@@ -0,0 +1,130 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    
+    <title>Extending pysmb For Other Frameworks &mdash; pysmb 1.1.25 documentation</title>
+    
+    <link rel="stylesheet" href="_static/sphinxdoc.css" type="text/css" />
+    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
+    
+    <script type="text/javascript">
+      var DOCUMENTATION_OPTIONS = {
+        URL_ROOT:    './',
+        VERSION:     '1.1.25',
+        COLLAPSE_INDEX: false,
+        FILE_SUFFIX: '.html',
+        HAS_SOURCE:  true
+      };
+    </script>
+    <script type="text/javascript" src="_static/jquery.js"></script>
+    <script type="text/javascript" src="_static/underscore.js"></script>
+    <script type="text/javascript" src="_static/doctools.js"></script>
+    <link rel="top" title="pysmb 1.1.25 documentation" href="index.html" />
+    <link rel="prev" title="Security Descriptors" href="api/smb_security_descriptors.html" /> 
+  </head>
+  <body role="document">
+    <div class="related" role="navigation" aria-label="related navigation">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="genindex.html" title="General Index"
+             accesskey="I">index</a></li>
+        <li class="right" >
+          <a href="py-modindex.html" title="Python Module Index"
+             >modules</a> |</li>
+        <li class="right" >
+          <a href="api/smb_security_descriptors.html" title="Security Descriptors"
+             accesskey="P">previous</a> |</li>
+        <li class="nav-item nav-item-0"><a href="index.html">pysmb 1.1.25 documentation</a> &raquo;</li> 
+      </ul>
+    </div>
+      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
+        <div class="sphinxsidebarwrapper">
+  <h4>Previous topic</h4>
+  <p class="topless"><a href="api/smb_security_descriptors.html"
+                        title="previous chapter">Security Descriptors</a></p>
+  <div role="note" aria-label="source link">
+    <h3>This Page</h3>
+    <ul class="this-page-menu">
+      <li><a href="_sources/extending.txt"
+            rel="nofollow">Show Source</a></li>
+    </ul>
+   </div>
+<div id="searchbox" style="display: none" role="search">
+  <h3>Quick search</h3>
+    <form class="search" action="search.html" method="get">
+      <input type="text" name="q" />
+      <input type="submit" value="Go" />
+      <input type="hidden" name="check_keywords" value="yes" />
+      <input type="hidden" name="area" value="default" />
+    </form>
+    <p class="searchtip" style="font-size: 90%">
+    Enter search terms or a module, class or function name.
+    </p>
+</div>
+<script type="text/javascript">$('#searchbox').show(0);</script>
+        </div>
+      </div>
+
+    <div class="document">
+      <div class="documentwrapper">
+        <div class="bodywrapper">
+          <div class="body" role="main">
+            
+  <div class="section" id="extending-pysmb-for-other-frameworks">
+<h1>Extending pysmb For Other Frameworks<a class="headerlink" href="#extending-pysmb-for-other-frameworks" title="Permalink to this headline">¶</a></h1>
+<p>This page briefly describes the steps involved in extending pysmb for other frameworks.</p>
+<p>In general, you need to take care of the SMB TCP connection setup, i.e. finding the IP address of the remote server and connect to the SMB/CIFS service.
+Then you need to read/write synchronously or asynchronously from and to the SMB socket. And you need to handle post-authentication callback methods, and from these methods,
+initiate file operations with the remote SMB/CIFS server.</p>
+<dl class="docutils">
+<dt>Now the above steps in more technical details:</dt>
+<dd><ol class="first arabic simple">
+<li>Create a new class which subclasses the <em>smb.base.SMB</em> class. Most often, the connection setup will be part of the <em>__init__</em> method.</li>
+<li>Override the <em>write(self, data)</em> method to provide an implementation which will write <em>data</em> to the socket.</li>
+<li>Write your own loop handling method to read data from the socket. Once data have been read, call <em>feedData</em> method with the parameter.
+The <em>feedData</em> method has its own internal buffer, so it can accept incomplete NetBIOS session packet data.</li>
+<li>Override</li>
+</ol>
+<blockquote class="last">
+<div><ul class="simple">
+<li><em>onAuthOK</em> method to include your own operations to perform when authentication is successful. You can initiate file operations in this method.</li>
+<li><em>onAuthFailed</em> method to include your own processing on what to do when authentication fails. You can report this as an error, or to try a different NTLM authentication algorithm (<em>use_ntlm_v2</em> parameter in the constructor).</li>
+<li><em>onNMBSessionFailed</em> method to include your own processing on what to do when pysmb fails to setup the NetBIOS session with the remote server. Usually, this is due to a wrong <em>remote_name</em> parameter in the constructor.</li>
+</ul>
+</div></blockquote>
+</dd>
+</dl>
+</div>
+
+
+          </div>
+        </div>
+      </div>
+      <div class="clearer"></div>
+    </div>
+    <div class="related" role="navigation" aria-label="related navigation">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="genindex.html" title="General Index"
+             >index</a></li>
+        <li class="right" >
+          <a href="py-modindex.html" title="Python Module Index"
+             >modules</a> |</li>
+        <li class="right" >
+          <a href="api/smb_security_descriptors.html" title="Security Descriptors"
+             >previous</a> |</li>
+        <li class="nav-item nav-item-0"><a href="index.html">pysmb 1.1.25 documentation</a> &raquo;</li> 
+      </ul>
+    </div>
+    <div class="footer" role="contentinfo">
+        &copy; Copyright 2001-2018, Michael Teo http://miketeo.net/.
+      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.6.
+    </div>
+  </body>
+</html>
\ No newline at end of file
diff --git a/docs/html/genindex.html b/docs/html/genindex.html
new file mode 100644
index 00000000..585930f6
--- /dev/null
+++ b/docs/html/genindex.html
@@ -0,0 +1,368 @@
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    
+    <title>Index &mdash; pysmb 1.1.25 documentation</title>
+    
+    <link rel="stylesheet" href="_static/sphinxdoc.css" type="text/css" />
+    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
+    
+    <script type="text/javascript">
+      var DOCUMENTATION_OPTIONS = {
+        URL_ROOT:    './',
+        VERSION:     '1.1.25',
+        COLLAPSE_INDEX: false,
+        FILE_SUFFIX: '.html',
+        HAS_SOURCE:  true
+      };
+    </script>
+    <script type="text/javascript" src="_static/jquery.js"></script>
+    <script type="text/javascript" src="_static/underscore.js"></script>
+    <script type="text/javascript" src="_static/doctools.js"></script>
+    <link rel="top" title="pysmb 1.1.25 documentation" href="index.html" /> 
+  </head>
+  <body role="document">
+    <div class="related" role="navigation" aria-label="related navigation">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="#" title="General Index"
+             accesskey="I">index</a></li>
+        <li class="right" >
+          <a href="py-modindex.html" title="Python Module Index"
+             >modules</a> |</li>
+        <li class="nav-item nav-item-0"><a href="index.html">pysmb 1.1.25 documentation</a> &raquo;</li> 
+      </ul>
+    </div>
+      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
+        <div class="sphinxsidebarwrapper">
+
+   
+
+<div id="searchbox" style="display: none" role="search">
+  <h3>Quick search</h3>
+    <form class="search" action="search.html" method="get">
+      <input type="text" name="q" />
+      <input type="submit" value="Go" />
+      <input type="hidden" name="check_keywords" value="yes" />
+      <input type="hidden" name="area" value="default" />
+    </form>
+    <p class="searchtip" style="font-size: 90%">
+    Enter search terms or a module, class or function name.
+    </p>
+</div>
+<script type="text/javascript">$('#searchbox').show(0);</script>
+        </div>
+      </div>
+
+    <div class="document">
+      <div class="documentwrapper">
+        <div class="bodywrapper">
+          <div class="body" role="main">
+            
+
+<h1 id="index">Index</h1>
+
+<div class="genindex-jumpbox">
+ <a href="#_"><strong>_</strong></a>
+ | <a href="#A"><strong>A</strong></a>
+ | <a href="#C"><strong>C</strong></a>
+ | <a href="#D"><strong>D</strong></a>
+ | <a href="#F"><strong>F</strong></a>
+ | <a href="#G"><strong>G</strong></a>
+ | <a href="#I"><strong>I</strong></a>
+ | <a href="#M"><strong>M</strong></a>
+ | <a href="#N"><strong>N</strong></a>
+ | <a href="#O"><strong>O</strong></a>
+ | <a href="#P"><strong>P</strong></a>
+ | <a href="#Q"><strong>Q</strong></a>
+ | <a href="#R"><strong>R</strong></a>
+ | <a href="#S"><strong>S</strong></a>
+ | <a href="#T"><strong>T</strong></a>
+ | <a href="#U"><strong>U</strong></a>
+ 
+</div>
+<h2 id="_">_</h2>
+<table style="width: 100%" class="indextable genindextable"><tr>
+  <td style="width: 33%" valign="top"><dl>
+      
+  <dt><a href="api/nmb_NetBIOS.html#nmb.NetBIOS.NetBIOS.__init__">__init__() (nmb.NetBIOS.NetBIOS method)</a>
+  </dt>
+
+      <dd><dl>
+        
+  <dt><a href="api/nmb_NBNSProtocol.html#nmb.NetBIOSProtocol.NBNSProtocol.__init__">(nmb.NetBIOSProtocol.NBNSProtocol method)</a>
+  </dt>
+
+      </dl></dd>
+  </dl></td>
+</tr></table>
+
+<h2 id="A">A</h2>
+<table style="width: 100%" class="indextable genindextable"><tr>
+  <td style="width: 33%" valign="top"><dl>
+      
+  <dt><a href="api/smb_security_descriptors.html#smb.security_descriptors.ACE">ACE (class in smb.security_descriptors)</a>
+  </dt>
+
+      
+  <dt><a href="api/smb_security_descriptors.html#smb.security_descriptors.ACL.aces">aces (smb.security_descriptors.ACL attribute)</a>
+  </dt>
+
+  </dl></td>
+  <td style="width: 33%" valign="top"><dl>
+      
+  <dt><a href="api/smb_security_descriptors.html#smb.security_descriptors.ACL">ACL (class in smb.security_descriptors)</a>
+  </dt>
+
+      
+  <dt><a href="api/smb_security_descriptors.html#smb.security_descriptors.ACE.additional_data">additional_data (smb.security_descriptors.ACE attribute)</a>
+  </dt>
+
+  </dl></td>
+</tr></table>
+
+<h2 id="C">C</h2>
+<table style="width: 100%" class="indextable genindextable"><tr>
+  <td style="width: 33%" valign="top"><dl>
+      
+  <dt><a href="api/nmb_NetBIOS.html#nmb.NetBIOS.NetBIOS.close">close() (nmb.NetBIOS.NetBIOS method)</a>
+  </dt>
+
+  </dl></td>
+</tr></table>
+
+<h2 id="D">D</h2>
+<table style="width: 100%" class="indextable genindextable"><tr>
+  <td style="width: 33%" valign="top"><dl>
+      
+  <dt><a href="api/smb_security_descriptors.html#smb.security_descriptors.SecurityDescriptor.dacl">dacl (smb.security_descriptors.SecurityDescriptor attribute)</a>
+  </dt>
+
+  </dl></td>
+</tr></table>
+
+<h2 id="F">F</h2>
+<table style="width: 100%" class="indextable genindextable"><tr>
+  <td style="width: 33%" valign="top"><dl>
+      
+  <dt><a href="api/smb_security_descriptors.html#smb.security_descriptors.ACE.flags">flags (smb.security_descriptors.ACE attribute)</a>
+  </dt>
+
+      <dd><dl>
+        
+  <dt><a href="api/smb_security_descriptors.html#smb.security_descriptors.SecurityDescriptor.flags">(smb.security_descriptors.SecurityDescriptor attribute)</a>
+  </dt>
+
+      </dl></dd>
+  </dl></td>
+</tr></table>
+
+<h2 id="G">G</h2>
+<table style="width: 100%" class="indextable genindextable"><tr>
+  <td style="width: 33%" valign="top"><dl>
+      
+  <dt><a href="api/smb_security_descriptors.html#smb.security_descriptors.SecurityDescriptor.group">group (smb.security_descriptors.SecurityDescriptor attribute)</a>
+  </dt>
+
+  </dl></td>
+</tr></table>
+
+<h2 id="I">I</h2>
+<table style="width: 100%" class="indextable genindextable"><tr>
+  <td style="width: 33%" valign="top"><dl>
+      
+  <dt><a href="api/smb_security_descriptors.html#smb.security_descriptors.SID.identifier_authority">identifier_authority (smb.security_descriptors.SID attribute)</a>
+  </dt>
+
+  </dl></td>
+  <td style="width: 33%" valign="top"><dl>
+      
+  <dt><a href="api/smb_security_descriptors.html#smb.security_descriptors.ACE.isInheritOnly">isInheritOnly (smb.security_descriptors.ACE attribute)</a>
+  </dt>
+
+  </dl></td>
+</tr></table>
+
+<h2 id="M">M</h2>
+<table style="width: 100%" class="indextable genindextable"><tr>
+  <td style="width: 33%" valign="top"><dl>
+      
+  <dt><a href="api/smb_security_descriptors.html#smb.security_descriptors.ACE.mask">mask (smb.security_descriptors.ACE attribute)</a>
+  </dt>
+
+  </dl></td>
+</tr></table>
+
+<h2 id="N">N</h2>
+<table style="width: 100%" class="indextable genindextable"><tr>
+  <td style="width: 33%" valign="top"><dl>
+      
+  <dt><a href="api/nmb_NBNSProtocol.html#nmb.NetBIOSProtocol.NBNSProtocol">NBNSProtocol (class in nmb.NetBIOSProtocol)</a>
+  </dt>
+
+      
+  <dt><a href="api/nmb_NetBIOS.html#nmb.NetBIOS.NetBIOS">NetBIOS (class in nmb.NetBIOS)</a>
+  </dt>
+
+  </dl></td>
+  <td style="width: 33%" valign="top"><dl>
+      
+  <dt><a href="api/nmb_NBNSProtocol.html#nmb.NetBIOSProtocol.NetBIOSTimeout">NetBIOSTimeout (class in nmb.NetBIOSProtocol)</a>
+  </dt>
+
+  </dl></td>
+</tr></table>
+
+<h2 id="O">O</h2>
+<table style="width: 100%" class="indextable genindextable"><tr>
+  <td style="width: 33%" valign="top"><dl>
+      
+  <dt><a href="api/smb_exceptions.html#smb.smb_structs.OperationFailure">OperationFailure (class in smb.smb_structs)</a>
+  </dt>
+
+  </dl></td>
+  <td style="width: 33%" valign="top"><dl>
+      
+  <dt><a href="api/smb_security_descriptors.html#smb.security_descriptors.SecurityDescriptor.owner">owner (smb.security_descriptors.SecurityDescriptor attribute)</a>
+  </dt>
+
+  </dl></td>
+</tr></table>
+
+<h2 id="P">P</h2>
+<table style="width: 100%" class="indextable genindextable"><tr>
+  <td style="width: 33%" valign="top"><dl>
+      
+  <dt><a href="api/smb_exceptions.html#smb.smb_structs.ProtocolError">ProtocolError (class in smb.smb_structs)</a>
+  </dt>
+
+  </dl></td>
+</tr></table>
+
+<h2 id="Q">Q</h2>
+<table style="width: 100%" class="indextable genindextable"><tr>
+  <td style="width: 33%" valign="top"><dl>
+      
+  <dt><a href="api/nmb_NetBIOS.html#nmb.NetBIOS.NetBIOS.queryIPForName">queryIPForName() (nmb.NetBIOS.NetBIOS method)</a>
+  </dt>
+
+      <dd><dl>
+        
+  <dt><a href="api/nmb_NBNSProtocol.html#nmb.NetBIOSProtocol.NBNSProtocol.queryIPForName">(nmb.NetBIOSProtocol.NBNSProtocol method)</a>
+  </dt>
+
+      </dl></dd>
+  </dl></td>
+  <td style="width: 33%" valign="top"><dl>
+      
+  <dt><a href="api/nmb_NetBIOS.html#nmb.NetBIOS.NetBIOS.queryName">queryName() (nmb.NetBIOS.NetBIOS method)</a>
+  </dt>
+
+      <dd><dl>
+        
+  <dt><a href="api/nmb_NBNSProtocol.html#nmb.NetBIOSProtocol.NBNSProtocol.queryName">(nmb.NetBIOSProtocol.NBNSProtocol method)</a>
+  </dt>
+
+      </dl></dd>
+  </dl></td>
+</tr></table>
+
+<h2 id="R">R</h2>
+<table style="width: 100%" class="indextable genindextable"><tr>
+  <td style="width: 33%" valign="top"><dl>
+      
+  <dt><a href="api/smb_security_descriptors.html#smb.security_descriptors.ACL.revision">revision (smb.security_descriptors.ACL attribute)</a>
+  </dt>
+
+      <dd><dl>
+        
+  <dt><a href="api/smb_security_descriptors.html#smb.security_descriptors.SID.revision">(smb.security_descriptors.SID attribute)</a>
+  </dt>
+
+      </dl></dd>
+  </dl></td>
+</tr></table>
+
+<h2 id="S">S</h2>
+<table style="width: 100%" class="indextable genindextable"><tr>
+  <td style="width: 33%" valign="top"><dl>
+      
+  <dt><a href="api/smb_security_descriptors.html#smb.security_descriptors.SecurityDescriptor.sacl">sacl (smb.security_descriptors.SecurityDescriptor attribute)</a>
+  </dt>
+
+      
+  <dt><a href="api/smb_security_descriptors.html#smb.security_descriptors.SecurityDescriptor">SecurityDescriptor (class in smb.security_descriptors)</a>
+  </dt>
+
+      
+  <dt><a href="api/smb_security_descriptors.html#smb.security_descriptors.SID">SID (class in smb.security_descriptors)</a>
+  </dt>
+
+  </dl></td>
+  <td style="width: 33%" valign="top"><dl>
+      
+  <dt><a href="api/smb_security_descriptors.html#smb.security_descriptors.ACE.sid">sid (smb.security_descriptors.ACE attribute)</a>
+  </dt>
+
+      
+  <dt><a href="api/smb_security_descriptors.html#module-smb.security_descriptors">smb.security_descriptors (module)</a>
+  </dt>
+
+      
+  <dt><a href="api/smb_security_descriptors.html#smb.security_descriptors.SID.subauthorities">subauthorities (smb.security_descriptors.SID attribute)</a>
+  </dt>
+
+  </dl></td>
+</tr></table>
+
+<h2 id="T">T</h2>
+<table style="width: 100%" class="indextable genindextable"><tr>
+  <td style="width: 33%" valign="top"><dl>
+      
+  <dt><a href="api/smb_security_descriptors.html#smb.security_descriptors.ACE.type">type (smb.security_descriptors.ACE attribute)</a>
+  </dt>
+
+  </dl></td>
+</tr></table>
+
+<h2 id="U">U</h2>
+<table style="width: 100%" class="indextable genindextable"><tr>
+  <td style="width: 33%" valign="top"><dl>
+      
+  <dt><a href="api/smb_exceptions.html#smb.smb_structs.UnsupportedFeature">UnsupportedFeature (class in smb.smb_structs)</a>
+  </dt>
+
+  </dl></td>
+</tr></table>
+
+
+
+          </div>
+        </div>
+      </div>
+      <div class="clearer"></div>
+    </div>
+    <div class="related" role="navigation" aria-label="related navigation">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="#" title="General Index"
+             >index</a></li>
+        <li class="right" >
+          <a href="py-modindex.html" title="Python Module Index"
+             >modules</a> |</li>
+        <li class="nav-item nav-item-0"><a href="index.html">pysmb 1.1.25 documentation</a> &raquo;</li> 
+      </ul>
+    </div>
+    <div class="footer" role="contentinfo">
+        &copy; Copyright 2001-2018, Michael Teo http://miketeo.net/.
+      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.6.
+    </div>
+  </body>
+</html>
\ No newline at end of file
diff --git a/docs/html/index.html b/docs/html/index.html
new file mode 100644
index 00000000..cf745496
--- /dev/null
+++ b/docs/html/index.html
@@ -0,0 +1,229 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    
+    <title>Welcome to pysmb’s documentation! &mdash; pysmb 1.1.25 documentation</title>
+    
+    <link rel="stylesheet" href="_static/sphinxdoc.css" type="text/css" />
+    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
+    
+    <script type="text/javascript">
+      var DOCUMENTATION_OPTIONS = {
+        URL_ROOT:    './',
+        VERSION:     '1.1.25',
+        COLLAPSE_INDEX: false,
+        FILE_SUFFIX: '.html',
+        HAS_SOURCE:  true
+      };
+    </script>
+    <script type="text/javascript" src="_static/jquery.js"></script>
+    <script type="text/javascript" src="_static/underscore.js"></script>
+    <script type="text/javascript" src="_static/doctools.js"></script>
+    <link rel="top" title="pysmb 1.1.25 documentation" href="#" />
+    <link rel="next" title="NBNSProtocol Class" href="api/nmb_NBNSProtocol.html" /> 
+  </head>
+  <body role="document">
+    <div class="related" role="navigation" aria-label="related navigation">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="genindex.html" title="General Index"
+             accesskey="I">index</a></li>
+        <li class="right" >
+          <a href="py-modindex.html" title="Python Module Index"
+             >modules</a> |</li>
+        <li class="right" >
+          <a href="api/nmb_NBNSProtocol.html" title="NBNSProtocol Class"
+             accesskey="N">next</a> |</li>
+        <li class="nav-item nav-item-0"><a href="#">pysmb 1.1.25 documentation</a> &raquo;</li> 
+      </ul>
+    </div>
+      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
+        <div class="sphinxsidebarwrapper">
+  <h3><a href="#">Table Of Contents</a></h3>
+  <ul>
+<li><a class="reference internal" href="#">Welcome to pysmb&#8217;s documentation!</a><ul>
+<li><a class="reference internal" href="#license">License</a></li>
+<li><a class="reference internal" href="#credits">Credits</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#package-contents-and-description">Package Contents and Description</a></li>
+<li><a class="reference internal" href="#using-pysmb">Using pysmb</a></li>
+<li><a class="reference internal" href="#indices-and-tables">Indices and tables</a></li>
+</ul>
+
+  <h4>Next topic</h4>
+  <p class="topless"><a href="api/nmb_NBNSProtocol.html"
+                        title="next chapter">NBNSProtocol Class</a></p>
+  <div role="note" aria-label="source link">
+    <h3>This Page</h3>
+    <ul class="this-page-menu">
+      <li><a href="_sources/index.txt"
+            rel="nofollow">Show Source</a></li>
+    </ul>
+   </div>
+<div id="searchbox" style="display: none" role="search">
+  <h3>Quick search</h3>
+    <form class="search" action="search.html" method="get">
+      <input type="text" name="q" />
+      <input type="submit" value="Go" />
+      <input type="hidden" name="check_keywords" value="yes" />
+      <input type="hidden" name="area" value="default" />
+    </form>
+    <p class="searchtip" style="font-size: 90%">
+    Enter search terms or a module, class or function name.
+    </p>
+</div>
+<script type="text/javascript">$('#searchbox').show(0);</script>
+        </div>
+      </div>
+
+    <div class="document">
+      <div class="documentwrapper">
+        <div class="bodywrapper">
+          <div class="body" role="main">
+            
+  <div class="section" id="welcome-to-pysmb-s-documentation">
+<h1>Welcome to pysmb&#8217;s documentation!<a class="headerlink" href="#welcome-to-pysmb-s-documentation" title="Permalink to this headline">¶</a></h1>
+<p>pysmb is a pure Python implementation of the client-side SMB/CIFS protocol (SMB1 and SMB2) which is the underlying protocol
+that facilitates file sharing and printing between Windows machines, as well as with Linux machines via the Samba server application.
+pysmb is developed in Python 2.4.6, Python 2.7.1 and Python 3.2.3 and has been tested against shared folders on Windows XP SP3, Windows Vista, Windows 7 and Samba 3.x.</p>
+<p>The latest version of pysmb is always available at the pysmb project page at <a class="reference external" href="http://miketeo.net/wp/index.php/projects/pysmb">miketeo.net</a>.</p>
+<div class="section" id="license">
+<h2>License<a class="headerlink" href="#license" title="Permalink to this headline">¶</a></h2>
+<p>pysmb itself is licensed under an opensource license.
+You are free to use pysmb in any applications, including for commercial purposes.
+For more details on the terms of use, please read the LICENSE file that comes with your pysmb source.</p>
+<p>pysmb depends on other 3rd-party modules whose terms of use are not covered by pysmb.
+Use of these modules could possibly conflict with your licensing needs. Please exercise your own discretion to determine their suitabilities.
+I have listed these modules in the following section.</p>
+</div>
+<div class="section" id="credits">
+<h2>Credits<a class="headerlink" href="#credits" title="Permalink to this headline">¶</a></h2>
+<p>pysmb is not alone. It is made possible with support from other modules.</p>
+<ul class="simple">
+<li><strong>pyasn1</strong> : Pure Python implementation of ASN.1 parsing and encoding (not included together with pysmb; needs to be installed separately)</li>
+<li><strong>md4</strong> and <strong>U32</strong> : Pure Python implementation of MD4 hashing algorithm and 32-bit unsigned integer by Dmitry Rozmanov. Licensed under LGPL and included together with pysmb.</li>
+<li><strong>pyDes</strong> : Pure Python implementation of the DES encryption algorithm by Todd Whiteman. Free domain and included together with pysmb.</li>
+<li><strong>sha256</strong> : Pure Python implementation of SHA-256 message digest by Thomas Dixon. Licensed under MIT and included together with pysmb. This module is imported only when
+the Python standard library (usually Python 2.4) does not provide the SHA-256 hash algorithm.</li>
+</ul>
+<p>In various places, there are references to different specifications. Most of these referenced specifications
+can be downloaded from Microsoft web site under Microsoft&#8217;s &#8220;Open Specification Promise&#8221;. If you need to download
+a copy of these specifications, please google for it. For example, google for &#8220;MS-CIFS&#8221; to download the CIFS specification for NT LM dialect.</p>
+</div>
+</div>
+<div class="section" id="package-contents-and-description">
+<h1>Package Contents and Description<a class="headerlink" href="#package-contents-and-description" title="Permalink to this headline">¶</a></h1>
+<p>pysmb is organized into 2 main packages: smb and nmb.
+The smb package contains all the functionalities related to Server Message Block (SMB) implementation.
+As an application developer, you will be importing this module into your application.
+Hence, please take some time to familiarize yourself with the smb package contents.</p>
+<ul class="simple">
+<li><strong>nmb/base.py</strong> :
+Contains the NetBIOSSession and NBNS abstract class which implements NetBIOS session and NetBIOS Name Service communication
+without any network transport specifics.</li>
+<li><strong>nmb/NetBIOS.py</strong>:
+Provides a NBNS implementation to query IP addresses for machine names. All operations are blocking I/O.</li>
+<li><strong>nmb/NetBIOSProtocol.py</strong> :
+Provides the NBNS protocol implementation for use in Twisted framework.</li>
+<li><strong>smb/base.py</strong> :
+Contains the SMB abstract class which implements the SMB communication without any network transport specifics.</li>
+<li><strong>smb/ntlm.py</strong> :
+Contains the NTLMv1 and NTLMv2 authentication routines and the decoding/encoding of NTLM authentication messages within SMB messages.</li>
+<li><strong>smb/securityblob.py</strong> :
+Provides routines to encode/decode the NTLMSSP security blob in the SMB messages.</li>
+<li><strong>smb/smb_constants.py</strong> :
+All the constants used in the smb package for SMB1 protocol</li>
+<li><strong>smb/smb_structs.py</strong> :
+Contains the internal classes used in the SMB package for SMB1 protocol. These classes are usually used to encode/decode the parameter and data blocks of specific SMB1 message.</li>
+<li><strong>smb/smb2_constants.py</strong> :
+All the constants used in the smb package for SMB2 protocol</li>
+<li><strong>smb/smb2_structs.py</strong> :
+Contains the internal classes used in the SMB package for SMB2 protocol. These classes are usually used to encode/decode the parameter and data blocks of specific SMB2 message.</li>
+<li><strong>smb/SMBConnection.py</strong> :
+Contains a SMB protocol implementation. All operations are blocking I/O.</li>
+<li><strong>smb/SMBProtocol.py</strong> :
+Contains the SMB protocol implementation for use in the Twisted framework.</li>
+<li><strong>smb/SMBHandler.py</strong> :
+Provides support for &#8220;<a class="reference external" href="smb://">smb://</a>&#8221; URL in the urllib2 python package.</li>
+</ul>
+</div>
+<div class="section" id="using-pysmb">
+<h1>Using pysmb<a class="headerlink" href="#using-pysmb" title="Permalink to this headline">¶</a></h1>
+<dl class="docutils">
+<dt>As an application developer who is looking to use pysmb to translate NetBIOS names to IP addresses,</dt>
+<dd><ul class="first last simple">
+<li>To use pysmb in applications where you want the file operations to return after they have completed (synchronous style), please read
+<a class="reference internal" href="api/nmb_NetBIOS.html"><em>nmb.NetBIOS.NetBIOS</em></a> documentation.</li>
+<li>To use pysmb in Twisted, please read <a class="reference internal" href="api/nmb_NBNSProtocol.html"><em>nmb.NetBIOSProtocol.NBNSProtocol</em></a> documentation.</li>
+</ul>
+</dd>
+<dt>As an application developer who is looking to use pysmb to implement file transfer or authentication over SMB:</dt>
+<dd><ul class="first last simple">
+<li>To use pysmb in applications where you want the file operations to return after they have completed (synchronous style), please read
+<a class="reference internal" href="api/smb_SMBConnection.html"><em>smb.SMBConnection.SMBConnection</em></a> documentation.</li>
+<li>To use pysmb in Twisted, please read <a class="reference internal" href="api/smb_SMBProtocolFactory.html"><em>smb.SMBProtocol.SMBProtocolFactory</em></a> documentation.</li>
+<li>To support &#8220;<a class="reference external" href="smb://">smb://</a>&#8221; URL in urllib2 python package, read <a class="reference internal" href="api/smb_SMBHandler.html"><em>smb.SMBHandler.SMBHandler</em></a> documentation.</li>
+</ul>
+</dd>
+<dt>As a software developer who is looking to modify pysmb so that you can integrate it to other network frameworks:</dt>
+<dd><ul class="first last simple">
+<li>Read <a class="reference internal" href="extending.html"><em>Extending pysmb For Other Frameworks</em></a></li>
+</ul>
+</dd>
+</dl>
+</div>
+<div class="section" id="indices-and-tables">
+<h1>Indices and tables<a class="headerlink" href="#indices-and-tables" title="Permalink to this headline">¶</a></h1>
+<div class="toctree-wrapper compound">
+<ul>
+<li class="toctree-l1"><a class="reference internal" href="api/nmb_NBNSProtocol.html">NBNSProtocol Class</a></li>
+<li class="toctree-l1"><a class="reference internal" href="api/nmb_NetBIOS.html">NetBIOS class</a></li>
+<li class="toctree-l1"><a class="reference internal" href="api/smb_SMBConnection.html">SMBConnection Class</a></li>
+<li class="toctree-l1"><a class="reference internal" href="api/smb_SMBHandler.html">SMbHandler Class</a></li>
+<li class="toctree-l1"><a class="reference internal" href="api/smb_SMBProtocolFactory.html">SMBProtocolFactory Class</a></li>
+<li class="toctree-l1"><a class="reference internal" href="api/smb_SharedDevice.html">SharedDevice Class</a></li>
+<li class="toctree-l1"><a class="reference internal" href="api/smb_SharedFile.html">SharedFile Class</a></li>
+<li class="toctree-l1"><a class="reference internal" href="api/smb_exceptions.html">SMB Exceptions</a></li>
+<li class="toctree-l1"><a class="reference internal" href="api/smb_security_descriptors.html">Security Descriptors</a></li>
+<li class="toctree-l1"><a class="reference internal" href="extending.html">Extending pysmb For Other Frameworks</a></li>
+</ul>
+</div>
+<ul class="simple">
+<li><a class="reference internal" href="genindex.html"><span>Index</span></a></li>
+<li><a class="reference internal" href="search.html"><span>Search Page</span></a></li>
+</ul>
+</div>
+
+
+          </div>
+        </div>
+      </div>
+      <div class="clearer"></div>
+    </div>
+    <div class="related" role="navigation" aria-label="related navigation">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="genindex.html" title="General Index"
+             >index</a></li>
+        <li class="right" >
+          <a href="py-modindex.html" title="Python Module Index"
+             >modules</a> |</li>
+        <li class="right" >
+          <a href="api/nmb_NBNSProtocol.html" title="NBNSProtocol Class"
+             >next</a> |</li>
+        <li class="nav-item nav-item-0"><a href="#">pysmb 1.1.25 documentation</a> &raquo;</li> 
+      </ul>
+    </div>
+    <div class="footer" role="contentinfo">
+        &copy; Copyright 2001-2018, Michael Teo http://miketeo.net/.
+      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.6.
+    </div>
+  </body>
+</html>
\ No newline at end of file
diff --git a/docs/html/objects.inv b/docs/html/objects.inv
new file mode 100644
index 00000000..50ddef60
--- /dev/null
+++ b/docs/html/objects.inv
@@ -0,0 +1,6 @@
+# Sphinx inventory version 2
+# Project: pysmb
+# Version: 1.1.25
+# The remainder of this file is compressed using zlib.
+xڵ�Qo� ���)��װ��o��H��$R�gt�k���±��~vW�j�iO6��~w'�65_!�U���e���bd7��l�Z��=5�����[?.�����
�ީ��q�wJ�j�paͥ�����Ig��n�:�,�_��)�y�S�v9t�
�D��3v��2M�PeО\�/�8���D'S�5H�Lj��ׇ��:}��A)M�Y0BAO���D�'£�],�ձ�{��ִ�
ğ�Q�Tj=f�.��ڒ�������صpf���ϸ��ƵBK�Qc��c��O�`=xL���ξ�ۃ��Ֆ��o�\�4ŗP����.��a�o��|�x���*
+IR�k��nڤ�S-��}�9����������.�} �Zm>�H��@���o�ht���g�;bB���8qP�&�SDr���`;���`;���Rt
\ No newline at end of file
diff --git a/docs/html/py-modindex.html b/docs/html/py-modindex.html
new file mode 100644
index 00000000..c5dbc0dd
--- /dev/null
+++ b/docs/html/py-modindex.html
@@ -0,0 +1,114 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    
+    <title>Python Module Index &mdash; pysmb 1.1.25 documentation</title>
+    
+    <link rel="stylesheet" href="_static/sphinxdoc.css" type="text/css" />
+    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
+    
+    <script type="text/javascript">
+      var DOCUMENTATION_OPTIONS = {
+        URL_ROOT:    './',
+        VERSION:     '1.1.25',
+        COLLAPSE_INDEX: false,
+        FILE_SUFFIX: '.html',
+        HAS_SOURCE:  true
+      };
+    </script>
+    <script type="text/javascript" src="_static/jquery.js"></script>
+    <script type="text/javascript" src="_static/underscore.js"></script>
+    <script type="text/javascript" src="_static/doctools.js"></script>
+    <link rel="top" title="pysmb 1.1.25 documentation" href="index.html" />
+ 
+
+
+  </head>
+  <body role="document">
+    <div class="related" role="navigation" aria-label="related navigation">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="genindex.html" title="General Index"
+             accesskey="I">index</a></li>
+        <li class="right" >
+          <a href="#" title="Python Module Index"
+             >modules</a> |</li>
+        <li class="nav-item nav-item-0"><a href="index.html">pysmb 1.1.25 documentation</a> &raquo;</li> 
+      </ul>
+    </div>
+      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
+        <div class="sphinxsidebarwrapper">
+<div id="searchbox" style="display: none" role="search">
+  <h3>Quick search</h3>
+    <form class="search" action="search.html" method="get">
+      <input type="text" name="q" />
+      <input type="submit" value="Go" />
+      <input type="hidden" name="check_keywords" value="yes" />
+      <input type="hidden" name="area" value="default" />
+    </form>
+    <p class="searchtip" style="font-size: 90%">
+    Enter search terms or a module, class or function name.
+    </p>
+</div>
+<script type="text/javascript">$('#searchbox').show(0);</script>
+        </div>
+      </div>
+
+    <div class="document">
+      <div class="documentwrapper">
+        <div class="bodywrapper">
+          <div class="body" role="main">
+            
+
+   <h1>Python Module Index</h1>
+
+   <div class="modindex-jumpbox">
+   <a href="#cap-s"><strong>s</strong></a>
+   </div>
+
+   <table class="indextable modindextable" cellspacing="0" cellpadding="2">
+     <tr class="pcap"><td></td><td>&nbsp;</td><td></td></tr>
+     <tr class="cap" id="cap-s"><td></td><td>
+       <strong>s</strong></td><td></td></tr>
+     <tr>
+       <td><img src="_static/minus.png" class="toggler"
+              id="toggle-1" style="display: none" alt="-" /></td>
+       <td>
+       <code class="xref">smb</code></td><td>
+       <em></em></td></tr>
+     <tr class="cg-1">
+       <td></td>
+       <td>&nbsp;&nbsp;&nbsp;
+       <a href="api/smb_security_descriptors.html#module-smb.security_descriptors"><code class="xref">smb.security_descriptors</code></a></td><td>
+       <em>Data structures used in Windows security descriptors.</em></td></tr>
+   </table>
+
+
+          </div>
+        </div>
+      </div>
+      <div class="clearer"></div>
+    </div>
+    <div class="related" role="navigation" aria-label="related navigation">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="genindex.html" title="General Index"
+             >index</a></li>
+        <li class="right" >
+          <a href="#" title="Python Module Index"
+             >modules</a> |</li>
+        <li class="nav-item nav-item-0"><a href="index.html">pysmb 1.1.25 documentation</a> &raquo;</li> 
+      </ul>
+    </div>
+    <div class="footer" role="contentinfo">
+        &copy; Copyright 2001-2018, Michael Teo http://miketeo.net/.
+      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.6.
+    </div>
+  </body>
+</html>
\ No newline at end of file
diff --git a/docs/html/search.html b/docs/html/search.html
new file mode 100644
index 00000000..f85a1c9b
--- /dev/null
+++ b/docs/html/search.html
@@ -0,0 +1,105 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    
+    <title>Search &mdash; pysmb 1.1.25 documentation</title>
+    
+    <link rel="stylesheet" href="_static/sphinxdoc.css" type="text/css" />
+    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
+    
+    <script type="text/javascript">
+      var DOCUMENTATION_OPTIONS = {
+        URL_ROOT:    './',
+        VERSION:     '1.1.25',
+        COLLAPSE_INDEX: false,
+        FILE_SUFFIX: '.html',
+        HAS_SOURCE:  true
+      };
+    </script>
+    <script type="text/javascript" src="_static/jquery.js"></script>
+    <script type="text/javascript" src="_static/underscore.js"></script>
+    <script type="text/javascript" src="_static/doctools.js"></script>
+    <script type="text/javascript" src="_static/searchtools.js"></script>
+    <link rel="top" title="pysmb 1.1.25 documentation" href="index.html" />
+  <script type="text/javascript">
+    jQuery(function() { Search.loadIndex("searchindex.js"); });
+  </script>
+  
+  <script type="text/javascript" id="searchindexloader"></script>
+   
+
+  </head>
+  <body role="document">
+    <div class="related" role="navigation" aria-label="related navigation">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="genindex.html" title="General Index"
+             accesskey="I">index</a></li>
+        <li class="right" >
+          <a href="py-modindex.html" title="Python Module Index"
+             >modules</a> |</li>
+        <li class="nav-item nav-item-0"><a href="index.html">pysmb 1.1.25 documentation</a> &raquo;</li> 
+      </ul>
+    </div>
+      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
+        <div class="sphinxsidebarwrapper">
+        </div>
+      </div>
+
+    <div class="document">
+      <div class="documentwrapper">
+        <div class="bodywrapper">
+          <div class="body" role="main">
+            
+  <h1 id="search-documentation">Search</h1>
+  <div id="fallback" class="admonition warning">
+  <script type="text/javascript">$('#fallback').hide();</script>
+  <p>
+    Please activate JavaScript to enable the search
+    functionality.
+  </p>
+  </div>
+  <p>
+    From here you can search these documents. Enter your search
+    words into the box below and click "search". Note that the search
+    function will automatically search for all of the words. Pages
+    containing fewer words won't appear in the result list.
+  </p>
+  <form action="" method="get">
+    <input type="text" name="q" value="" />
+    <input type="submit" value="search" />
+    <span id="search-progress" style="padding-left: 10px"></span>
+  </form>
+  
+  <div id="search-results">
+  
+  </div>
+
+          </div>
+        </div>
+      </div>
+      <div class="clearer"></div>
+    </div>
+    <div class="related" role="navigation" aria-label="related navigation">
+      <h3>Navigation</h3>
+      <ul>
+        <li class="right" style="margin-right: 10px">
+          <a href="genindex.html" title="General Index"
+             >index</a></li>
+        <li class="right" >
+          <a href="py-modindex.html" title="Python Module Index"
+             >modules</a> |</li>
+        <li class="nav-item nav-item-0"><a href="index.html">pysmb 1.1.25 documentation</a> &raquo;</li> 
+      </ul>
+    </div>
+    <div class="footer" role="contentinfo">
+        &copy; Copyright 2001-2018, Michael Teo http://miketeo.net/.
+      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.6.
+    </div>
+  </body>
+</html>
\ No newline at end of file
diff --git a/docs/html/searchindex.js b/docs/html/searchindex.js
new file mode 100644
index 00000000..d364bb4b
--- /dev/null
+++ b/docs/html/searchindex.js
@@ -0,0 +1 @@
+Search.setIndex({envversion:46,filenames:["api/nmb_NBNSProtocol","api/nmb_NetBIOS","api/smb_SMBConnection","api/smb_SMBHandler","api/smb_SMBProtocolFactory","api/smb_SharedDevice","api/smb_SharedFile","api/smb_exceptions","api/smb_security_descriptors","extending","index"],objects:{"nmb.NetBIOS":{NetBIOS:[1,0,1,""]},"nmb.NetBIOS.NetBIOS":{"__init__":[1,1,1,""],close:[1,1,1,""],queryIPForName:[1,1,1,""],queryName:[1,1,1,""]},"nmb.NetBIOSProtocol":{NBNSProtocol:[0,0,1,""],NetBIOSTimeout:[0,0,1,""]},"nmb.NetBIOSProtocol.NBNSProtocol":{"__init__":[0,1,1,""],queryIPForName:[0,1,1,""],queryName:[0,1,1,""]},"smb.security_descriptors":{ACE:[8,0,1,""],ACL:[8,0,1,""],SID:[8,0,1,""],SecurityDescriptor:[8,0,1,""]},"smb.security_descriptors.ACE":{additional_data:[8,3,1,""],flags:[8,3,1,""],isInheritOnly:[8,3,1,""],mask:[8,3,1,""],sid:[8,3,1,""],type:[8,3,1,""]},"smb.security_descriptors.ACL":{aces:[8,3,1,""],revision:[8,3,1,""]},"smb.security_descriptors.SID":{identifier_authority:[8,3,1,""],revision:[8,3,1,""],subauthorities:[8,3,1,""]},"smb.security_descriptors.SecurityDescriptor":{dacl:[8,3,1,""],flags:[8,3,1,""],group:[8,3,1,""],owner:[8,3,1,""],sacl:[8,3,1,""]},"smb.smb_structs":{OperationFailure:[7,0,1,""],ProtocolError:[7,0,1,""],UnsupportedFeature:[7,0,1,""]},smb:{security_descriptors:[8,2,0,"-"]}},objnames:{"0":["py","class","Python class"],"1":["py","method","Python method"],"2":["py","module","Python module"],"3":["py","attribute","Python attribute"]},objtypes:{"0":"py:class","1":"py:method","2":"py:module","3":"py:attribute"},terms:{"3rd":10,"\u5783\u573e\u6587\u4ef6":3,"\u6d4b\u8bd5\u6587\u4ef6\u5939":3,"__init__":[0,1,4,9],"abstract":10,"boolean":[0,1],"case":4,"float":[0,1],"function":[0,1,4,10],"import":[2,3,4,10],"long":2,"new":[1,4,9],"public":4,"return":[0,1,2,3,4,10],"true":[0,1,2,4],"try":9,aaa:[0,1],abov:9,accept:[4,9],access:8,access_mask:8,accur:4,ace_type_:8,aceflag:8,acetyp:8,acl:8,add:[0,4],addcallback:[0,4],adderrback:4,addit:8,additional_data:8,address:[0,1,3,9,10],after:[0,1,2,4,10],again:0,against:10,algorithm:[9,10],all:[4,8,10],allow:0,alon:10,alwai:[8,10],anderson:[0,1],ani:[1,10],appli:8,applic:[0,1,4,10],application_data:8,appropri:[0,1],arbitari:[2,4],arg:4,around:0,ascii:[2,4],asn:10,assert:2,associ:8,asynchron:[0,2,9],attribute_data:8,audit:8,auth:4,authent:[4,9,10],authenthent:4,author:8,automat:[0,1,2,4],avail:10,avoid:4,back:[0,1,2,4],base:[9,10],batch:4,bbb:[0,1],been:[4,9,10],befor:[2,4],begin:[2,4],between:10,bind:[0,1],bit:10,bitmask:8,blob:10,block:[0,1,2,10],briefli:9,broadcast:[0,1],buffer:9,build_open:3,call:[0,1,4,9],callback:[0,9],can:[0,1,2,3,4,8,9,10],cannot:3,captur:[2,4],care:9,ccc:[0,1],charact:3,cif:[1,2,4,9,10],client:[2,4,10],client_machine_nam:[2,4],close:[1,2,3,4],closeconnect:4,code:3,come:10,commerci:10,commun:[2,4,10],complet:[2,4,10],compon:3,concurr:[2,4],conflict:10,conn:2,connect:[2,4,9],connecttcp:4,consist:8,constant:[8,10],constructor:9,contain:[1,10],content:[2,4],contribut:[0,1],control:8,conveni:8,copi:10,correspond:8,could:10,cover:10,creat:[0,1,2,3,4,9],current:7,dacl:8,dat:3,data:[3,8,9,10],data_buf:7,ddd:[0,1],decod:10,def:4,defer:[0,4],defin:[0,1],delet:3,depend:[8,10],describ:9,detail:[9,10],determin:[0,1,10],develop:[2,10],dialect:10,dictionari:8,differ:[9,10],digest:10,directli:4,director:3,directori:3,disabl:[2,4],disconnect:[2,4],discret:10,discretionari:8,dixon:10,dmitri:10,doe:10,doesn:8,domain:10,done:[0,1],dot:[0,1],download:10,dtyp:8,due:9,each:[1,2,4],els:[2,4],empti:[0,1,3],encapsul:8,encod:10,encount:2,encrypt:10,end:[2,4],entir:4,entri:8,errback:[0,4],error:[2,9],etc:4,except:[0,4],exercis:10,exist:3,expos:4,facilit:10,factori:4,fail:[2,4,9],failur:0,fallback:[2,4],fals:[0,1,2,4],familiar:10,featur:7,feeddata:9,fh2:3,field:8,file:[2,3,4,9,10],file_attribut:[2,4],file_fh:3,file_obj:[2,4],file_s:4,fileretriev:4,files:2,find:9,first:3,flag:[0,1,2,4,8],folder:[3,10],follow:[2,3,4,8,10],framework:[0,4],free:[0,1,10],from:[0,1,2,3,4,8,9,10],functionl:4,gener:9,googl:10,group:8,handl:[4,9],hash:10,have:[0,2,9,10],henc:10,hope:[0,1],host:3,hostnam:3,iana:[0,1],identifi:8,identifier_author:8,idl:2,illustr:[2,3,4],implement:[0,1,2,4,8,9,10],impos:[2,4],includ:[9,10],incom:0,incomplet:9,index:10,indic:[0,1,8],inherit:8,inherited_object_typ:8,initi:9,insid:[2,4],instal:10,instanc:[0,1,2,4,8],instanti:[0,1],instiant:[0,1],integ:[0,1,8,10],integr:10,interest:4,intern:[4,9,10],internet:[0,4],interv:4,invok:2,involv:9,ipv4:1,isinheritonli:8,itself:[8,10],jason:[0,1],just:[0,4],keep:2,keepal:2,know:[0,1,4],kwarg:4,latest:10,learn:4,leav:[0,1],length:8,lgpl:10,librari:10,like:3,limit:[2,4],linux:10,list:[0,1,8,10],listen:[0,1],listen_port:[0,1],listenudp:0,local_fil:3,log:8,look:10,loop:9,loseconnect:4,machin:[0,1,2,3,4,10],made:10,mai:[2,4],main:10,mask:8,match:[0,1,2,4],md4:10,mean:8,meant:2,mechan:[2,4],messag:[7,10],method:[0,1,2,3,4,9],microsoft:10,might:[2,4],miketeo:10,mit:10,mode:[0,1],modifi:10,modul:[2,4,8,10],more:[2,4,9,10],most:[2,4,9,10],must:[0,4],mypassword:3,myuserid:3,name:[0,1,2,3,4,10],namedtemporaryfil:[2,4],nbn:[1,10],need:[2,3,4,9,10],net:10,netbio:0,netbiosprotocol:[0,10],netbiossess:10,netbiostimeout:0,network:[0,1,10],nmb:[0,1,10],none:[0,1,7,8],notat:[0,1],notconnectederror:4,note:2,notreadyerror:4,now:9,ntlm:[9,10],ntlmssp:10,ntlmv1:10,ntlmv2:10,number:[0,1,4,8],obj:[2,4],object:[3,8],object_typ:8,often:9,onauthfail:[4,9],onauthok:[4,9],onc:[4,9],onli:[3,8,10],onnmbsessionfail:9,open:[3,10],opensourc:10,oper:[1,2,4,9,10],operationfailur:[4,7],organ:10,otherwis:[2,4],over:10,overrid:[4,9],own:[4,9,10],owner:8,packag:3,packet:[0,1,9],page:[9,10],paramet:[0,1,3,4,9,10],parent:3,pars:10,part:9,parti:10,pass:3,password:[2,4],path:[3,4],perform:[0,1,2,4,9],period:4,place:10,pleas:10,point:3,port:[0,1],posit:[2,4],possibl:10,post:[4,9],precis:4,present:[7,8],princip:8,print:[4,10],process:[3,9],project:[0,4,10],promis:10,properti:8,protocol:[2,4,7,10],protocolerror:7,provid:[0,1,3,4,9,10],pure:10,purpos:10,pyasn1:10,pyde:10,pymsb:4,pysmb:[0,2,4,7],python:[3,10],queri:[0,1,10],queryipfornam:[0,1],querynam:[0,1],queue:4,rais:[0,3,4,7],reactor:[0,4],read:[2,3,4,9,10],readi:4,receiv:[0,1],refer:10,referenc:10,reject:[2,4],relat:10,releas:1,remot:[1,2,4,9],remote_nam:9,remov:0,repli:[0,1],report:9,repres:8,requir:7,resourc:1,respond:2,restrict:8,result:[0,4],retriev:[2,3,4],retrievefil:[2,4],retrievefilefactori:4,reus:4,revis:8,rfc1001:[2,3,4],routin:10,rozmanov:10,sacl:8,samba:10,same:[2,4],search:10,sec:4,second:[0,1,4],section:10,security_descriptor:8,securityblob:10,securitydescriptor:8,see:8,seek:[2,4],select:[0,1],self:[4,9],send:[0,1],separ:10,sequenc:8,sequenti:2,server:[2,4,9,10],server_ip:[2,4],server_nam:[2,4],servic:[1,2,4,9,10],session:[9,10],set:[2,4],setup:[0,1,4,9],sha256:10,sha:10,share:[3,10],sharedfold:3,should:[0,1,2,4,8],sid:8,side:10,simpl:[2,4],simpli:3,singl:[2,8],site:10,smb1:[2,4,10],smb2_constant:10,smb2_struct:10,smb:[1,2,3,4],smb_constant:10,smb_messag:7,smb_struct:[2,4,7,10],smbprotocol:[4,10],smbtest:[2,4],smbtimeout:4,snippet:3,socket:[1,9],softwar:10,some:[2,4,10],sort:2,sourc:[0,1,7,8,10],sp3:10,specif:10,specifi:[0,1,4,8],standard:[0,1,10],start:[0,2,4],step:9,stoplisten:0,storefil:4,string:[0,1,2,3,4],structur:8,style:10,subauthor:8,subclass:[4,9],subsequ:3,success:9,suitabl:[2,10],support_smb2:[2,4],synchron:[9,10],system:8,take:[9,10],target:[0,1],tcp:9,technic:9,tempfil:[2,4],term:10,termin:4,test:10,than:[2,4],thei:10,thi:[0,1,4,8,9,10],thoma:10,those:4,thousand:4,through:4,time:[2,4,10],timeout:[0,1,2,4],todd:10,togeth:10,too:2,touch:[0,1,4],transfer:[4,10],translat:10,transport:[0,4,10],truste:8,twist:[0,4,10],txt:[2,3,4],type:8,type_:8,u32:10,udp:[0,1],under:10,underli:[1,4,10],unicod:3,unless:[0,1],unsign:10,unsupportedfeatur:7,until:1,upload:3,upload_fil:3,url:[3,10],urlerror:3,urllib2:[3,10],use_ntlm_v2:[2,4,9],user:8,userid:[2,4],usual:[4,9,10],utf:3,util:[2,4],valid:3,valu:8,variabl:8,variou:10,version:10,via:[0,4,10],vista:10,wait:[0,1,4],want:[4,10],web:10,well:10,what:[0,1,2,4,9],when:[0,1,2,4,7,9,10],where:[4,10],which:[0,1,8,9,10],whiteman:10,who:[2,4,10],whose:10,window:[3,8,10],wish:[1,2],within:[2,4,10],without:[0,10],wrap:0,write:9,write_result:4,wrong:9,you:[0,1,2,3,4,9,10],your:[0,1,4,9,10],yourself:10,zero:[0,1]},titles:["NBNSProtocol Class","NetBIOS class","SMBConnection Class","SMbHandler Class","SMBProtocolFactory Class","SharedDevice Class","SharedFile Class","SMB Exceptions","Security Descriptors","Extending pysmb For Other Frameworks","Welcome to pysmb&#8217;s documentation!"],titleterms:{"class":[0,1,2,3,4,5,6],caveat:[2,4],content:10,credit:10,descript:10,descriptor:8,document:10,exampl:[2,3,4],except:7,extend:9,framework:9,indic:10,licens:10,nbnsprotocol:0,netbio:1,note:3,other:9,packag:10,pysmb:[9,10],secur:8,shareddevic:5,sharedfil:6,smb2:[2,4],smb:7,smbconnect:2,smbhandler:3,smbprotocolfactori:4,support:[2,4],tabl:10,welcom:10}})
\ No newline at end of file
diff --git a/python2/nmb/NetBIOS.py b/python2/nmb/NetBIOS.py
new file mode 100644
index 00000000..34058054
--- /dev/null
+++ b/python2/nmb/NetBIOS.py
@@ -0,0 +1,144 @@
+
+import os, logging, random, socket, time, select
+from base import NBNS, NotConnectedError
+from nmb_constants import TYPE_CLIENT, TYPE_SERVER, TYPE_WORKSTATION
+
+class NetBIOS(NBNS):
+
+    log = logging.getLogger('NMB.NetBIOS')
+
+    def __init__(self, broadcast = True, listen_port = 0):
+        """
+        Instantiate a NetBIOS instance, and creates a IPv4 UDP socket to listen/send NBNS packets.
+
+        :param boolean broadcast: A boolean flag to indicate if we should setup the listening UDP port in broadcast mode
+        :param integer listen_port: Specifies the UDP port number to bind to for listening. If zero, OS will automatically select a free port number.
+        """
+        self.broadcast = broadcast
+        self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+        if self.broadcast:
+            self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
+        if listen_port:
+            self.sock.bind(( '', listen_port ))
+
+    def close(self):
+        """
+        Close the underlying and free resources.
+
+        The NetBIOS instance should not be used to perform any operations after this method returns.
+
+        :return: None
+        """
+        self.sock.close()
+        self.sock = None
+
+    def write(self, data, ip, port):
+        assert self.sock, 'Socket is already closed'
+        self.sock.sendto(data, ( ip, port ))
+
+    def queryName(self, name, ip = '', port = 137, timeout = 30):
+        """
+        Send a query on the network and hopes that if machine matching the *name* will reply with its IP address.
+
+        :param string ip: If the NBNSProtocol instance was instianted with broadcast=True, then this parameter can be an empty string. We will leave it to the OS to determine an appropriate broadcast address.
+                          If the NBNSProtocol instance was instianted with broadcast=False, then you should provide a target IP to send the query.
+        :param integer port: The NetBIOS-NS port (IANA standard defines this port to be 137). You should not touch this parameter unless you know what you are doing.
+        :param integer/float timeout: Number of seconds to wait for a reply, after which the method will return None
+        :return: A list of IP addresses in dotted notation (aaa.bbb.ccc.ddd). On timeout, returns None.
+        """
+        assert self.sock, 'Socket is already closed'
+
+        trn_id = random.randint(1, 0xFFFF)
+        data = self.prepareNameQuery(trn_id, name)
+        if self.broadcast and not ip:
+            ip = '<broadcast>'
+        elif not ip:
+            self.log.warning('queryName: ip parameter is empty. OS might not transmit this query to the network')
+
+        self.write(data, ip, port)
+
+        return self._pollForNetBIOSPacket(trn_id, timeout)
+
+    def queryIPForName(self, ip, port = 137, timeout = 30):
+        """
+        Send a query to the machine with *ip* and hopes that the machine will reply back with its name.
+
+        The implementation of this function is contributed by Jason Anderson.
+
+        :param string ip: If the NBNSProtocol instance was instianted with broadcast=True, then this parameter can be an empty string. We will leave it to the OS to determine an appropriate broadcast address.
+                          If the NBNSProtocol instance was instianted with broadcast=False, then you should provide a target IP to send the query.
+        :param integer port: The NetBIOS-NS port (IANA standard defines this port to be 137). You should not touch this parameter unless you know what you are doing.
+        :param integer/float timeout: Number of seconds to wait for a reply, after which the method will return None
+        :return: A list of string containing the names of the machine at *ip*. On timeout, returns None.
+        """
+        assert self.sock, 'Socket is already closed'
+
+        trn_id = random.randint(1, 0xFFFF)
+        data = self.prepareNetNameQuery(trn_id, False)
+        self.write(data, ip, port)
+        ret = self._pollForQueryPacket(trn_id, timeout)
+        if ret:
+            return map(lambda s: s[0], filter(lambda s: s[1] == TYPE_SERVER, ret))
+        else:
+            return None
+
+    #
+    # Protected Methods
+    #
+
+    def _pollForNetBIOSPacket(self, wait_trn_id, timeout):
+        end_time = time.time() + timeout
+        while True:
+            try:
+                _timeout = end_time - time.time()
+                if _timeout <= 0:
+                    return None
+
+                ready, _, _ = select.select([ self.sock.fileno() ], [ ], [ ], _timeout)
+                if not ready:
+                    return None
+
+                data, _ = self.sock.recvfrom(0xFFFF)
+                if len(data) == 0:
+                    raise NotConnectedError
+
+                trn_id, ret = self.decodePacket(data)
+
+                if trn_id == wait_trn_id:
+                    return ret
+            except select.error, ex:
+                if type(ex) is types.TupleType:
+                    if ex[0] != errno.EINTR and ex[0] != errno.EAGAIN:
+                        raise ex
+                else:
+                    raise ex
+
+    #
+    # Contributed by Jason Anderson
+    #
+    def _pollForQueryPacket(self, wait_trn_id, timeout):
+        end_time = time.time() + timeout
+        while True:
+            try:
+                _timeout = end_time - time.time()
+                if _timeout <= 0:
+                    return None
+
+                ready, _, _ = select.select([ self.sock.fileno() ], [ ], [ ], _timeout)
+                if not ready:
+                    return None
+
+                data, _ = self.sock.recvfrom(0xFFFF)
+                if len(data) == 0:
+                    raise NotConnectedError
+
+                trn_id, ret = self.decodeIPQueryPacket(data)
+
+                if trn_id == wait_trn_id:
+                    return ret
+            except select.error, ex:
+                if type(ex) is types.TupleType:
+                    if ex[0] != errno.EINTR and ex[0] != errno.EAGAIN:
+                        raise ex
+                else:
+                    raise ex
diff --git a/python2/nmb/NetBIOSProtocol.py b/python2/nmb/NetBIOSProtocol.py
new file mode 100644
index 00000000..3d9b6b87
--- /dev/null
+++ b/python2/nmb/NetBIOSProtocol.py
@@ -0,0 +1,136 @@
+
+import os, logging, random, socket, time
+from twisted.internet import reactor, defer
+from twisted.internet.protocol import DatagramProtocol
+from nmb_constants import TYPE_SERVER
+from base import NBNS
+
+IP_QUERY, NAME_QUERY = range(2)
+
+class NetBIOSTimeout(Exception):
+    """Raised in NBNSProtocol via Deferred.errback method when queryName method has timeout waiting for reply"""
+    pass
+
+class NBNSProtocol(DatagramProtocol, NBNS):
+
+    log = logging.getLogger('NMB.NBNSProtocol')
+
+    def __init__(self, broadcast = True, listen_port = 0):
+        """
+        Instantiate a NBNSProtocol instance.
+
+        This automatically calls reactor.listenUDP method to start listening for incoming packets, so you **must not** call the listenUDP method again.
+
+        :param boolean broadcast: A boolean flag to indicate if we should setup the listening UDP port in broadcast mode
+        :param integer listen_port: Specifies the UDP port number to bind to for listening. If zero, OS will automatically select a free port number.
+        """
+        self.broadcast = broadcast
+        self.pending_trns = { }  # TRN ID -> ( expiry_time, name, Deferred instance )
+        self.transport = reactor.listenUDP(listen_port, self)
+        if self.broadcast:
+            self.transport.getHandle().setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
+        reactor.callLater(1, self.cleanupPendingTrns)
+
+    def datagramReceived(self, data, from_info):
+        host, port = from_info
+        trn_id, ret = self.decodePacket(data)
+
+        # pending transaction exists for trn_id - handle it and remove from queue
+        if trn_id in self.pending_trns:
+            _, ip, d = self.pending_trns.pop(trn_id)
+            if ip is NAME_QUERY:
+                # decode as query packet
+                trn_id, ret = self.decodeIPQueryPacket(data)
+            d.callback(ret)
+
+    def write(self, data, ip, port):
+        # We don't use the transport.write method directly as it keeps raising DeprecationWarning for ip='<broadcast>'
+        self.transport.getHandle().sendto(data, ( ip, port ))
+
+    def queryName(self, name, ip = '', port = 137, timeout = 30):
+        """
+        Send a query on the network and hopes that if machine matching the *name* will reply with its IP address.
+
+        :param string ip: If the NBNSProtocol instance was instianted with broadcast=True, then this parameter can be an empty string. We will leave it to the OS to determine an appropriate broadcast address.
+                          If the NBNSProtocol instance was instianted with broadcast=False, then you should provide a target IP to send the query.
+        :param integer port: The NetBIOS-NS port (IANA standard defines this port to be 137). You should not touch this parameter unless you know what you are doing.
+        :param integer/float timeout: Number of seconds to wait for a reply, after which the returned Deferred instance will be called with a NetBIOSTimeout exception.
+        :return: A *twisted.internet.defer.Deferred* instance. The callback function will be called with a list of IP addresses in dotted notation (aaa.bbb.ccc.ddd).
+                 On timeout, the errback function will be called with a Failure instance wrapping around a NetBIOSTimeout exception
+        """
+        trn_id = random.randint(1, 0xFFFF)
+        while True:
+            if not self.pending_trns.has_key(trn_id):
+                break
+            else:
+                trn_id = (trn_id + 1) & 0xFFFF
+
+        data = self.prepareNameQuery(trn_id, name)
+        if self.broadcast and not ip:
+            ip = '<broadcast>'
+        elif not ip:
+            self.log.warning('queryName: ip parameter is empty. OS might not transmit this query to the network')
+
+        self.write(data, ip, port)
+
+        d = defer.Deferred()
+        self.pending_trns[trn_id] = ( time.time()+timeout, name, d )
+        return d
+
+    def queryIPForName(self, ip, port = 137, timeout = 30):
+        """
+        Send a query to the machine with *ip* and hopes that the machine will reply back with its name.
+
+        The implementation of this function is contributed by Jason Anderson.
+
+        :param string ip: If the NBNSProtocol instance was instianted with broadcast=True, then this parameter can be an empty string. We will leave it to the OS to determine an appropriate broadcast address.
+                          If the NBNSProtocol instance was instianted with broadcast=False, then you should provide a target IP to send the query.
+        :param integer port: The NetBIOS-NS port (IANA standard defines this port to be 137). You should not touch this parameter unless you know what you are doing.
+        :param integer/float timeout: Number of seconds to wait for a reply, after which the method will return None
+        :return: A *twisted.internet.defer.Deferred* instance. The callback function will be called with a list of names of the machine at *ip*.
+                 On timeout, the errback function will be called with a Failure instance wrapping around a NetBIOSTimeout exception
+        """
+        trn_id = random.randint(1, 0xFFFF)
+        while True:
+            if not self.pending_trns.has_key(trn_id):
+                break
+            else:
+                trn_id = (trn_id + 1) & 0xFFFF
+
+        data = self.prepareNetNameQuery(trn_id)
+        self.write(data, ip, port)
+
+        d = defer.Deferred()
+        d2 = defer.Deferred()
+        d2.addErrback(d.errback)
+
+        def stripCode(ret):
+            if ret is not None: # got valid response. Somehow the callback is also called when there is an error.
+                d.callback(map(lambda s: s[0], filter(lambda s: s[1] == TYPE_SERVER, ret)))
+
+        d2.addCallback(stripCode)
+        self.pending_trns[trn_id] = ( time.time()+timeout, NAME_QUERY, d2 )
+        return d
+
+    def stopProtocol(self):
+        DatagramProtocol.stopProtocol(self)
+
+    def cleanupPendingTrns(self):
+        now = time.time()
+
+        # reply should have been received in the past
+        expired = filter(lambda (trn_id, (expiry_time, name, d)): expiry_time < now, self.pending_trns.iteritems())
+
+        # remove expired items from dict + call errback
+        def expire_item(item):
+            trn_id, (expiry_time, name, d) = item
+
+            del self.pending_trns[trn_id]
+            try:
+                d.errback(NetBIOSTimeout(name))
+            except: pass
+
+        map(expire_item, expired)
+
+        if self.transport:
+            reactor.callLater(1, self.cleanupPendingTrns)
diff --git a/python2/nmb/__init__.py b/python2/nmb/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/python2/nmb/base.py b/python2/nmb/base.py
new file mode 100644
index 00000000..0bbef825
--- /dev/null
+++ b/python2/nmb/base.py
@@ -0,0 +1,181 @@
+
+import struct, logging, random
+from nmb_constants import *
+from nmb_structs import *
+from utils import encode_name
+
+class NMBSession:
+
+    log = logging.getLogger('NMB.NMBSession')
+
+    def __init__(self, my_name, remote_name, host_type = TYPE_SERVER, is_direct_tcp = False):
+        self.my_name = my_name.upper()
+        self.remote_name = remote_name.upper()
+        self.host_type = host_type
+        self.data_buf = ''
+
+        if is_direct_tcp:
+            self.data_nmb = DirectTCPSessionMessage()
+            self.sendNMBPacket = self._sendNMBPacket_DirectTCP
+        else:
+            self.data_nmb = NMBSessionMessage()
+            self.sendNMBPacket = self._sendNMBPacket_NetBIOS
+
+    #
+    # Overridden Methods
+    #
+
+    def write(self, data):
+        raise NotImplementedError
+
+    def onNMBSessionMessage(self, flags, data):
+        pass
+
+    def onNMBSessionOK(self):
+        pass
+
+    def onNMBSessionFailed(self):
+        pass
+
+    #
+    # Public Methods
+    #
+
+    def feedData(self, data):
+        self.data_buf = self.data_buf + data
+
+        offset = 0
+        while True:
+            length = self.data_nmb.decode(self.data_buf, offset)
+            if length == 0:
+                break
+            elif length > 0:
+                offset += length
+                self._processNMBSessionPacket(self.data_nmb)
+            else:
+                raise NMBError
+
+        if offset > 0:
+            self.data_buf = self.data_buf[offset:]
+
+    def sendNMBMessage(self, data):
+        self.sendNMBPacket(SESSION_MESSAGE, data)
+
+    def requestNMBSession(self):
+        my_name_encoded = encode_name(self.my_name, TYPE_WORKSTATION)
+        remote_name_encoded = encode_name(self.remote_name, self.host_type)
+        self.sendNMBPacket(SESSION_REQUEST, remote_name_encoded + my_name_encoded)
+
+    #
+    # Protected Methods
+    #
+
+    def _processNMBSessionPacket(self, packet):
+        if packet.type == SESSION_MESSAGE:
+            self.onNMBSessionMessage(packet.flags, packet.data)
+        elif packet.type == POSITIVE_SESSION_RESPONSE:
+            self.onNMBSessionOK()
+        elif packet.type == NEGATIVE_SESSION_RESPONSE:
+            self.onNMBSessionFailed()
+        elif packet.type == SESSION_KEEPALIVE:
+            # Discard keepalive packets - [RFC1002]: 5.2.2.1
+            pass
+        else:
+            self.log.warning('Unrecognized NMB session type: 0x%02x', packet.type)
+
+    def _sendNMBPacket_NetBIOS(self, packet_type, data):
+        length = len(data)
+        assert length <= 0x01FFFF
+        flags = 0
+        if length > 0xFFFF:
+            flags |= 0x01
+            length &= 0xFFFF
+        self.write(struct.pack('>BBH', packet_type, flags, length) + data)
+
+    def _sendNMBPacket_DirectTCP(self, packet_type, data):
+        length = len(data)
+        assert length <= 0x00FFFFFF
+        self.write(struct.pack('>I', length) + data)
+
+
+class NBNS:
+
+    log = logging.getLogger('NMB.NBNS')
+
+    HEADER_STRUCT_FORMAT = '>HHHHHH'
+    HEADER_STRUCT_SIZE = struct.calcsize(HEADER_STRUCT_FORMAT)
+
+    def write(self, data, ip, port):
+        raise NotImplementedError
+
+    def decodePacket(self, data):
+        if len(data) < self.HEADER_STRUCT_SIZE:
+            raise Exception
+
+        trn_id, code, question_count, answer_count, authority_count, additional_count = struct.unpack(self.HEADER_STRUCT_FORMAT, data[:self.HEADER_STRUCT_SIZE])
+
+        is_response = bool((code >> 15) & 0x01)
+        opcode = (code >> 11) & 0x0F
+        flags = (code >> 4) & 0x7F
+        rcode = code & 0x0F
+
+        if opcode == 0x0000 and is_response:
+            name_len = ord(data[self.HEADER_STRUCT_SIZE])
+            offset = self.HEADER_STRUCT_SIZE+2+name_len+8 # constant 2 for the padding bytes before/after the Name and constant 8 for the Type, Class and TTL fields in the Answer section after the Name
+            record_count = (struct.unpack('>H', data[offset:offset+2])[0]) / 6
+
+            offset += 4  # Constant 4 for the Data Length and Flags field
+            ret = [ ]
+            for i in range(0, record_count):
+                ret.append('%d.%d.%d.%d' % struct.unpack('4B', (data[offset:offset + 4])))
+                offset += 6
+            return trn_id, ret
+        else:
+            return trn_id, None
+
+
+    def prepareNameQuery(self, trn_id, name, is_broadcast = True):
+        header = struct.pack(self.HEADER_STRUCT_FORMAT,
+                             trn_id, (is_broadcast and 0x0110) or 0x0100, 1, 0, 0, 0)
+        payload = encode_name(name, 0x20) + '\x00\x20\x00\x01'
+
+        return header + payload
+
+    #
+    # Contributed by Jason Anderson
+    #
+    def decodeIPQueryPacket(self, data):
+        if len(data) < self.HEADER_STRUCT_SIZE:
+            raise Exception
+
+        trn_id, code, question_count, answer_count, authority_count, additional_count = struct.unpack(self.HEADER_STRUCT_FORMAT, data[:self.HEADER_STRUCT_SIZE])
+
+        is_response = bool((code >> 15) & 0x01)
+        opcode = (code >> 11) & 0x0F
+        flags = (code >> 4) & 0x7F
+        rcode = code & 0x0F
+        numnames = struct.unpack('B', data[self.HEADER_STRUCT_SIZE + 44])[0]
+
+        if numnames > 0:
+            ret = [ ]
+            offset = self.HEADER_STRUCT_SIZE + 45
+
+            for i in range(0, numnames):
+                mynme = data[offset:offset + 15]
+                mynme = mynme.strip()
+                ret.append(( mynme, ord(data[offset+15]) ))
+                offset += 18
+
+            return trn_id, ret
+        else:
+            return trn_id, None
+
+    #
+    # Contributed by Jason Anderson
+    #
+    def prepareNetNameQuery(self, trn_id, is_broadcast = True):
+        header = struct.pack(self.HEADER_STRUCT_FORMAT,
+                             trn_id, (is_broadcast and 0x0010) or 0x0000, 1, 0, 0, 0)
+        payload = encode_name('*', 0) + '\x00\x21\x00\x01'
+
+        return header + payload
diff --git a/python2/nmb/nmb_constants.py b/python2/nmb/nmb_constants.py
new file mode 100644
index 00000000..fcf6007a
--- /dev/null
+++ b/python2/nmb/nmb_constants.py
@@ -0,0 +1,38 @@
+
+# Default port for NetBIOS name service
+NETBIOS_NS_PORT = 137
+
+# Default port for NetBIOS session service
+NETBIOS_SESSION_PORT = 139
+
+# Owner Node Type Constants
+NODE_B = 0x00
+NODE_P = 0x01
+NODE_M = 0x10
+NODE_RESERVED = 0x11
+
+# Name Type Constants
+TYPE_UNKNOWN = 0x01
+TYPE_WORKSTATION = 0x00
+TYPE_CLIENT = 0x03
+TYPE_SERVER = 0x20
+TYPE_DOMAIN_MASTER = 0x1B
+TYPE_MASTER_BROWSER = 0x1D
+TYPE_BROWSER = 0x1E
+
+TYPE_NAMES = { TYPE_UNKNOWN: 'Unknown',
+               TYPE_WORKSTATION: 'Workstation',
+               TYPE_CLIENT: 'Client',
+               TYPE_SERVER: 'Server',
+               TYPE_MASTER_BROWSER: 'Master Browser',
+               TYPE_BROWSER: 'Browser Server',
+               TYPE_DOMAIN_MASTER: 'Domain Master'
+               }
+
+# Values for Session Packet Type field in Session Packets
+SESSION_MESSAGE = 0x00
+SESSION_REQUEST = 0x81
+POSITIVE_SESSION_RESPONSE = 0x82
+NEGATIVE_SESSION_RESPONSE = 0x83
+REGTARGET_SESSION_RESPONSE = 0x84
+SESSION_KEEPALIVE = 0x85
diff --git a/python2/nmb/nmb_structs.py b/python2/nmb/nmb_structs.py
new file mode 100644
index 00000000..71e603c3
--- /dev/null
+++ b/python2/nmb/nmb_structs.py
@@ -0,0 +1,69 @@
+
+import struct
+
+class NMBError(Exception): pass
+
+
+class NotConnectedError(NMBError):
+    """
+    Raisd when the underlying NMB connection has been disconnected or not connected yet
+    """
+    pass
+
+
+class NMBSessionMessage:
+
+    HEADER_STRUCT_FORMAT = '>BBH'
+    HEADER_STRUCT_SIZE = struct.calcsize(HEADER_STRUCT_FORMAT)
+
+    def __init__(self):
+        self.reset()
+
+    def reset(self):
+        self.type = 0
+        self.flags = 0
+        self.data = ''
+
+    def decode(self, data, offset):
+        data_len = len(data)
+
+        if data_len < offset + self.HEADER_STRUCT_SIZE:
+            # Not enough data for decoding
+            return 0
+
+        self.reset()
+        self.type, self.flags, length = struct.unpack(self.HEADER_STRUCT_FORMAT, data[offset:offset+self.HEADER_STRUCT_SIZE])
+
+        if self.flags & 0x01:
+            length |= 0x010000
+
+        if data_len < offset + self.HEADER_STRUCT_SIZE + length:
+            return 0
+
+        self.data = data[offset+self.HEADER_STRUCT_SIZE:offset+self.HEADER_STRUCT_SIZE+length]
+        return self.HEADER_STRUCT_SIZE + length
+
+
+class DirectTCPSessionMessage(NMBSessionMessage):
+
+    HEADER_STRUCT_FORMAT = '>I'
+    HEADER_STRUCT_SIZE = struct.calcsize(HEADER_STRUCT_FORMAT)
+
+    def decode(self, data, offset):
+        data_len = len(data)
+
+        if data_len < offset + self.HEADER_STRUCT_SIZE:
+            # Not enough data for decoding
+            return 0
+
+        self.reset()
+        length = struct.unpack(self.HEADER_STRUCT_FORMAT, data[offset:offset+self.HEADER_STRUCT_SIZE])[0]
+
+        if length >> 24 != 0:
+            raise NMBError("Invalid protocol header for Direct TCP session message")
+
+        if data_len < offset + self.HEADER_STRUCT_SIZE + length:
+            return 0
+
+        self.data = data[offset+self.HEADER_STRUCT_SIZE:offset+self.HEADER_STRUCT_SIZE+length]
+        return self.HEADER_STRUCT_SIZE + length
diff --git a/python2/nmb/utils.py b/python2/nmb/utils.py
new file mode 100644
index 00000000..45d625c2
--- /dev/null
+++ b/python2/nmb/utils.py
@@ -0,0 +1,50 @@
+
+import string, re
+
+
+def encode_name(name, type, scope = None):
+    """
+    Perform first and second level encoding of name as specified in RFC 1001 (Section 4)
+    """
+    if name == '*':
+        name = name + '\0' * 15
+    elif len(name) > 15:
+        name = name[:15] + chr(type)
+    else:
+        name = string.ljust(name, 15) + chr(type)
+
+    def _do_first_level_encoding(m):
+        s = ord(m.group(0))
+        return string.uppercase[s >> 4] + string.uppercase[s & 0x0f]
+
+    encoded_name = chr(len(name) * 2) + re.sub('.', _do_first_level_encoding, name)
+    if scope:
+        encoded_scope = ''
+        for s in string.split(scope, '.'):
+            encoded_scope = encoded_scope + chr(len(s)) + s
+        return encoded_name + encoded_scope + '\0'
+    else:
+        return encoded_name + '\0'
+
+
+def decode_name(name):
+    name_length = ord(name[0])
+    assert name_length == 32
+
+    def _do_first_level_decoding(m):
+        s = m.group(0)
+        return chr(((ord(s[0]) - ord('A')) << 4) | (ord(s[1]) - ord('A')))
+
+    decoded_name = re.sub('..', _do_first_level_decoding, name[1:33])
+    if name[33] == '\0':
+        return 34, decoded_name, ''
+    else:
+        decoded_domain = ''
+        offset = 34
+        while 1:
+            domain_length = ord(name[offset])
+            if domain_length == 0:
+                break
+            decoded_domain = '.' + name[offset:offset + domain_length]
+            offset = offset + domain_length
+        return offset + 1, decoded_name, decoded_domain
diff --git a/python2/pysmb.egg-info/PKG-INFO b/python2/pysmb.egg-info/PKG-INFO
new file mode 100644
index 00000000..9f8779df
--- /dev/null
+++ b/python2/pysmb.egg-info/PKG-INFO
@@ -0,0 +1,23 @@
+Metadata-Version: 1.1
+Name: pysmb
+Version: 1.1.26
+Summary: pysmb is an experimental SMB/CIFS library written in Python to support file sharing between Windows and Linux machines
+Home-page: https://miketeo.net/projects/pysmb
+Author: Michael Teo
+Author-email: miketeo@miketeo.net
+License: zlib/libpng
+Description: pysmb is an experimental SMB/CIFS library written in Python. It implements the client-side SMB/CIFS protocol which allows your Python application to access and transfer files to/from SMB/CIFS shared folders like your Windows file sharing and Samba folders.
+Keywords: windows samba cifs sharing ftp smb linux
+Platform: UNKNOWN
+Classifier: Development Status :: 5 - Production/Stable
+Classifier: Environment :: Win32 (MS Windows)
+Classifier: Environment :: Console
+Classifier: License :: OSI Approved :: zlib/libpng License
+Classifier: Operating System :: Microsoft :: Windows
+Classifier: Operating System :: POSIX
+Classifier: Programming Language :: Python
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3
+Classifier: Topic :: Communications :: File Sharing
+Classifier: Topic :: Software Development :: Libraries :: Python Modules
+Classifier: Topic :: System :: Networking
diff --git a/python2/pysmb.egg-info/SOURCES.txt b/python2/pysmb.egg-info/SOURCES.txt
new file mode 100644
index 00000000..636e6d02
--- /dev/null
+++ b/python2/pysmb.egg-info/SOURCES.txt
@@ -0,0 +1,242 @@
+CHANGELOG
+LICENSE
+MANIFEST.in
+README.txt
+setup.py
+docs/doctrees/environment.pickle
+docs/doctrees/extending.doctree
+docs/doctrees/index.doctree
+docs/doctrees/api/nmb_NBNSProtocol.doctree
+docs/doctrees/api/nmb_NetBIOS.doctree
+docs/doctrees/api/smb_SMBConnection.doctree
+docs/doctrees/api/smb_SMBHandler.doctree
+docs/doctrees/api/smb_SMBProtocolFactory.doctree
+docs/doctrees/api/smb_SharedDevice.doctree
+docs/doctrees/api/smb_SharedFile.doctree
+docs/doctrees/api/smb_exceptions.doctree
+docs/doctrees/api/smb_security_descriptors.doctree
+docs/html/.buildinfo
+docs/html/extending.html
+docs/html/genindex.html
+docs/html/index.html
+docs/html/objects.inv
+docs/html/py-modindex.html
+docs/html/search.html
+docs/html/searchindex.js
+docs/html/_modules/index.html
+docs/html/_modules/nmb/NetBIOS.html
+docs/html/_modules/nmb/NetBIOSProtocol.html
+docs/html/_modules/smb/security_descriptors.html
+docs/html/_modules/smb/smb_structs.html
+docs/html/_sources/extending.txt
+docs/html/_sources/index.txt
+docs/html/_sources/api/nmb_NBNSProtocol.txt
+docs/html/_sources/api/nmb_NetBIOS.txt
+docs/html/_sources/api/smb_SMBConnection.txt
+docs/html/_sources/api/smb_SMBHandler.txt
+docs/html/_sources/api/smb_SMBProtocolFactory.txt
+docs/html/_sources/api/smb_SharedDevice.txt
+docs/html/_sources/api/smb_SharedFile.txt
+docs/html/_sources/api/smb_exceptions.txt
+docs/html/_sources/api/smb_security_descriptors.txt
+docs/html/_static/ajax-loader.gif
+docs/html/_static/basic.css
+docs/html/_static/comment-bright.png
+docs/html/_static/comment-close.png
+docs/html/_static/comment.png
+docs/html/_static/contents.png
+docs/html/_static/doctools.js
+docs/html/_static/down-pressed.png
+docs/html/_static/down.png
+docs/html/_static/file.png
+docs/html/_static/jquery.js
+docs/html/_static/minus.png
+docs/html/_static/navigation.png
+docs/html/_static/plus.png
+docs/html/_static/pygments.css
+docs/html/_static/searchtools.js
+docs/html/_static/sphinxdoc.css
+docs/html/_static/underscore.js
+docs/html/_static/up-pressed.png
+docs/html/_static/up.png
+docs/html/_static/websupport.js
+docs/html/api/nmb_NBNSProtocol.html
+docs/html/api/nmb_NetBIOS.html
+docs/html/api/smb_SMBConnection.html
+docs/html/api/smb_SMBHandler.html
+docs/html/api/smb_SMBProtocolFactory.html
+docs/html/api/smb_SharedDevice.html
+docs/html/api/smb_SharedFile.html
+docs/html/api/smb_exceptions.html
+docs/html/api/smb_security_descriptors.html
+python2/nmb/NetBIOS.py
+python2/nmb/NetBIOSProtocol.py
+python2/nmb/__init__.py
+python2/nmb/base.py
+python2/nmb/nmb_constants.py
+python2/nmb/nmb_structs.py
+python2/nmb/utils.py
+python2/pysmb.egg-info/PKG-INFO
+python2/pysmb.egg-info/SOURCES.txt
+python2/pysmb.egg-info/dependency_links.txt
+python2/pysmb.egg-info/requires.txt
+python2/pysmb.egg-info/top_level.txt
+python2/smb/SMBConnection.py
+python2/smb/SMBHandler.py
+python2/smb/SMBProtocol.py
+python2/smb/__init__.py
+python2/smb/base.py
+python2/smb/ntlm.py
+python2/smb/security_descriptors.py
+python2/smb/securityblob.py
+python2/smb/smb2_constants.py
+python2/smb/smb2_structs.py
+python2/smb/smb_constants.py
+python2/smb/smb_structs.py
+python2/smb/utils/README.txt
+python2/smb/utils/U32.py
+python2/smb/utils/__init__.py
+python2/smb/utils/md4.py
+python2/smb/utils/pyDes.py
+python2/smb/utils/sha256.py
+python2/tests/README_1st.txt
+python2/tests/__init__.py
+python2/tests/connection.ini
+python2/tests/test_ntlm.py
+python2/tests/test_security_descriptors.py
+python2/tests/test_securityblob.py
+python2/tests/DirectSMBConnectionTests/__init__.py
+python2/tests/DirectSMBConnectionTests/test_SMBHandler.py
+python2/tests/DirectSMBConnectionTests/test_auth.py
+python2/tests/DirectSMBConnectionTests/test_createdeletedirectory.py
+python2/tests/DirectSMBConnectionTests/test_echo.py
+python2/tests/DirectSMBConnectionTests/test_listpath.py
+python2/tests/DirectSMBConnectionTests/test_listshares.py
+python2/tests/DirectSMBConnectionTests/test_listsnapshots.py
+python2/tests/DirectSMBConnectionTests/test_rename.py
+python2/tests/DirectSMBConnectionTests/test_retrievefile.py
+python2/tests/DirectSMBConnectionTests/test_storefile.py
+python2/tests/DirectSMBConnectionTests/util.py
+python2/tests/DirectSMBTwistedTests/test_auth.py
+python2/tests/DirectSMBTwistedTests/test_createdeletedirectory.py
+python2/tests/DirectSMBTwistedTests/test_echo.py
+python2/tests/DirectSMBTwistedTests/test_listpath.py
+python2/tests/DirectSMBTwistedTests/test_listshares.py
+python2/tests/DirectSMBTwistedTests/test_listsnapshots.py
+python2/tests/DirectSMBTwistedTests/test_rename.py
+python2/tests/DirectSMBTwistedTests/test_retrievefile.py
+python2/tests/DirectSMBTwistedTests/test_storefile.py
+python2/tests/DirectSMBTwistedTests/util.py
+python2/tests/NetBIOSTests/__init__.py
+python2/tests/NetBIOSTests/test_queryname.py
+python2/tests/NetBIOSTwistedTests/__init__.py
+python2/tests/NetBIOSTwistedTests/test_queryname.py
+python2/tests/SMBConnectionTests/__init__.py
+python2/tests/SMBConnectionTests/test_SMBHandler.py
+python2/tests/SMBConnectionTests/test_auth.py
+python2/tests/SMBConnectionTests/test_createdeletedirectory.py
+python2/tests/SMBConnectionTests/test_deletepattern.py
+python2/tests/SMBConnectionTests/test_echo.py
+python2/tests/SMBConnectionTests/test_getattributes.py
+python2/tests/SMBConnectionTests/test_listpath.py
+python2/tests/SMBConnectionTests/test_listshares.py
+python2/tests/SMBConnectionTests/test_listsnapshots.py
+python2/tests/SMBConnectionTests/test_rename.py
+python2/tests/SMBConnectionTests/test_retrievefile.py
+python2/tests/SMBConnectionTests/test_security.py
+python2/tests/SMBConnectionTests/test_storefile.py
+python2/tests/SMBConnectionTests/test_with_context.py
+python2/tests/SMBConnectionTests/util.py
+python2/tests/SMBTwistedTests/__init__.py
+python2/tests/SMBTwistedTests/test_auth.py
+python2/tests/SMBTwistedTests/test_createdeletedirectory.py
+python2/tests/SMBTwistedTests/test_echo.py
+python2/tests/SMBTwistedTests/test_getattributes.py
+python2/tests/SMBTwistedTests/test_listpath.py
+python2/tests/SMBTwistedTests/test_listshares.py
+python2/tests/SMBTwistedTests/test_listsnapshots.py
+python2/tests/SMBTwistedTests/test_rename.py
+python2/tests/SMBTwistedTests/test_retrievefile.py
+python2/tests/SMBTwistedTests/test_storefile.py
+python2/tests/SMBTwistedTests/util.py
+python2/tests/SupportFiles/binary.dat
+python3/nmb/NetBIOS.py
+python3/nmb/NetBIOSProtocol.py
+python3/nmb/__init__.py
+python3/nmb/base.py
+python3/nmb/nmb_constants.py
+python3/nmb/nmb_structs.py
+python3/nmb/utils.py
+python3/pysmb.egg-info/PKG-INFO
+python3/pysmb.egg-info/SOURCES.txt
+python3/pysmb.egg-info/dependency_links.txt
+python3/pysmb.egg-info/requires.txt
+python3/pysmb.egg-info/top_level.txt
+python3/smb/SMBConnection.py
+python3/smb/SMBHandler.py
+python3/smb/SMBProtocol.py
+python3/smb/__init__.py
+python3/smb/base.py
+python3/smb/ntlm.py
+python3/smb/security_descriptors.py
+python3/smb/securityblob.py
+python3/smb/smb2_constants.py
+python3/smb/smb2_structs.py
+python3/smb/smb_constants.py
+python3/smb/smb_structs.py
+python3/smb/utils/U32.py
+python3/smb/utils/__init__.py
+python3/smb/utils/md4.py
+python3/smb/utils/pyDes.py
+python3/smb/utils/sha256.py
+python3/tests/README_1st.txt
+python3/tests/__init__.py
+python3/tests/connection.ini
+python3/tests/test_ntlm.py
+python3/tests/test_security_descriptors.py
+python3/tests/test_securityblob.py
+python3/tests/DirectSMBConnectionTests/__init__.py
+python3/tests/DirectSMBConnectionTests/test_auth.py
+python3/tests/DirectSMBConnectionTests/test_createdeletedirectory.py
+python3/tests/DirectSMBConnectionTests/test_echo.py
+python3/tests/DirectSMBConnectionTests/test_listpath.py
+python3/tests/DirectSMBConnectionTests/test_listshares.py
+python3/tests/DirectSMBConnectionTests/test_listsnapshots.py
+python3/tests/DirectSMBConnectionTests/test_rename.py
+python3/tests/DirectSMBConnectionTests/test_retrievefile.py
+python3/tests/DirectSMBConnectionTests/test_storefile.py
+python3/tests/DirectSMBConnectionTests/util.py
+python3/tests/NetBIOSTests/__init__.py
+python3/tests/NetBIOSTests/test_queryname.py
+python3/tests/SMBConnectionTests/__init__.py
+python3/tests/SMBConnectionTests/test_SMBHandler.py
+python3/tests/SMBConnectionTests/test_auth.py
+python3/tests/SMBConnectionTests/test_createdeletedirectory.py
+python3/tests/SMBConnectionTests/test_deletepattern.py
+python3/tests/SMBConnectionTests/test_echo.py
+python3/tests/SMBConnectionTests/test_getattributes.py
+python3/tests/SMBConnectionTests/test_listpath.py
+python3/tests/SMBConnectionTests/test_listshares.py
+python3/tests/SMBConnectionTests/test_listsnapshots.py
+python3/tests/SMBConnectionTests/test_rename.py
+python3/tests/SMBConnectionTests/test_retrievefile.py
+python3/tests/SMBConnectionTests/test_security.py
+python3/tests/SMBConnectionTests/test_storefile.py
+python3/tests/SMBConnectionTests/test_with_context.py
+python3/tests/SMBConnectionTests/util.py
+python3/tests/SupportFiles/binary.dat
+sphinx/Makefile
+sphinx/make.bat
+sphinx/requirements.txt
+sphinx/source/conf.py
+sphinx/source/extending.rst
+sphinx/source/index.rst
+sphinx/source/api/nmb_NBNSProtocol.rst
+sphinx/source/api/nmb_NetBIOS.rst
+sphinx/source/api/smb_SMBConnection.rst
+sphinx/source/api/smb_SMBHandler.rst
+sphinx/source/api/smb_SMBProtocolFactory.rst
+sphinx/source/api/smb_SharedDevice.rst
+sphinx/source/api/smb_SharedFile.rst
+sphinx/source/api/smb_exceptions.rst
+sphinx/source/api/smb_security_descriptors.rst
\ No newline at end of file
diff --git a/python2/pysmb.egg-info/dependency_links.txt b/python2/pysmb.egg-info/dependency_links.txt
new file mode 100644
index 00000000..8b137891
--- /dev/null
+++ b/python2/pysmb.egg-info/dependency_links.txt
@@ -0,0 +1 @@
+
diff --git a/python2/pysmb.egg-info/requires.txt b/python2/pysmb.egg-info/requires.txt
new file mode 100644
index 00000000..38fe4145
--- /dev/null
+++ b/python2/pysmb.egg-info/requires.txt
@@ -0,0 +1 @@
+pyasn1
diff --git a/python2/pysmb.egg-info/top_level.txt b/python2/pysmb.egg-info/top_level.txt
new file mode 100644
index 00000000..65ad1103
--- /dev/null
+++ b/python2/pysmb.egg-info/top_level.txt
@@ -0,0 +1,2 @@
+nmb
+smb
diff --git a/python2/smb/SMBConnection.py b/python2/smb/SMBConnection.py
new file mode 100644
index 00000000..8ac23b96
--- /dev/null
+++ b/python2/smb/SMBConnection.py
@@ -0,0 +1,639 @@
+
+import os, logging, select, socket, struct, errno
+from smb_constants import *
+from smb_structs import *
+from base import SMB, NotConnectedError, NotReadyError, SMBTimeout
+
+
+class SMBConnection(SMB):
+
+    log = logging.getLogger('SMB.SMBConnection')
+
+    #: SMB messages will never be signed regardless of remote server's configurations; access errors will occur if the remote server requires signing.
+    SIGN_NEVER = 0
+    #: SMB messages will be signed when remote server supports signing but not requires signing.
+    SIGN_WHEN_SUPPORTED = 1
+    #: SMB messages will only be signed when remote server requires signing.
+    SIGN_WHEN_REQUIRED = 2
+
+    def __init__(self, username, password, my_name, remote_name, domain = '', use_ntlm_v2 = True, sign_options = SIGN_WHEN_REQUIRED, is_direct_tcp = False):
+        """
+        Create a new SMBConnection instance.
+
+        *username* and *password* are the user credentials required to authenticate the underlying SMB connection with the remote server.
+        File operations can only be proceeded after the connection has been authenticated successfully.
+
+        Note that you need to call *connect* method to actually establish the SMB connection to the remote server and perform authentication.
+
+        The default TCP port for most SMB/CIFS servers using NetBIOS over TCP/IP is 139.
+        Some newer server installations might also support Direct hosting of SMB over TCP/IP; for these servers, the default TCP port is 445.
+
+        :param string my_name: The local NetBIOS machine name that will identify where this connection is originating from.
+                               You can freely choose a name as long as it contains a maximum of 15 alphanumeric characters and does not contain spaces and any of ``\/:*?";|+``
+        :param string remote_name: The NetBIOS machine name of the remote server.
+                                   On windows, you can find out the machine name by right-clicking on the "My Computer" and selecting "Properties".
+                                   This parameter must be the same as what has been configured on the remote server, or else the connection will be rejected.
+        :param string domain: The network domain. On windows, it is known as the workgroup. Usually, it is safe to leave this parameter as an empty string.
+        :param boolean use_ntlm_v2: Indicates whether pysmb should be NTLMv1 or NTLMv2 authentication algorithm for authentication.
+                                    The choice of NTLMv1 and NTLMv2 is configured on the remote server, and there is no mechanism to auto-detect which algorithm has been configured.
+                                    Hence, we can only "guess" or try both algorithms.
+                                    On Sambda, Windows Vista and Windows 7, NTLMv2 is enabled by default. On Windows XP, we can use NTLMv1 before NTLMv2.
+        :param int sign_options: Determines whether SMB messages will be signed. Default is *SIGN_WHEN_REQUIRED*.
+                                 If *SIGN_WHEN_REQUIRED* (value=2), SMB messages will only be signed when remote server requires signing.
+                                 If *SIGN_WHEN_SUPPORTED* (value=1), SMB messages will be signed when remote server supports signing but not requires signing.
+                                 If *SIGN_NEVER* (value=0), SMB messages will never be signed regardless of remote server's configurations; access errors will occur if the remote server requires signing.
+        :param boolean is_direct_tcp: Controls whether the NetBIOS over TCP/IP (is_direct_tcp=False) or the newer Direct hosting of SMB over TCP/IP (is_direct_tcp=True) will be used for the communication.
+                                      The default parameter is False which will use NetBIOS over TCP/IP for wider compatibility (TCP port: 139).
+        """
+        SMB.__init__(self, username, password, my_name, remote_name, domain, use_ntlm_v2, sign_options, is_direct_tcp)
+        self.sock = None
+        self.auth_result = None
+        self.is_busy = False
+        self.is_direct_tcp = is_direct_tcp
+
+    #
+    # SMB (and its superclass) Methods
+    #
+
+    def onAuthOK(self):
+        self.auth_result = True
+
+    def onAuthFailed(self):
+        self.auth_result = False
+
+    def write(self, data):
+        assert self.sock
+        data_len = len(data)
+        total_sent = 0
+        while total_sent < data_len:
+            sent = self.sock.send(data[total_sent:])
+            if sent == 0:
+                raise NotConnectedError('Server disconnected')
+            total_sent = total_sent + sent
+
+    #
+    # Support for "with" context
+    #
+    def __enter__(self):
+        return self
+
+    def __exit__(self, *args):
+        self.close()
+
+    #
+    # Misc Properties
+    #
+
+    @property
+    def isUsingSMB2(self):
+        """A convenient property to return True if the underlying SMB connection is using SMB2 protocol."""
+        return self.is_using_smb2
+
+
+    #
+    # Public Methods
+    #
+
+    def connect(self, ip, port = 139, sock_family = socket.AF_INET, timeout = 60):
+        """
+        Establish the SMB connection to the remote SMB/CIFS server.
+
+        You must call this method before attempting any of the file operations with the remote server.
+        This method will block until the SMB connection has attempted at least one authentication.
+
+        :return: A boolean value indicating the result of the authentication atttempt: True if authentication is successful; False, if otherwise.
+        """
+        if self.sock:
+            self.sock.close()
+
+        self.auth_result = None
+        self.sock = socket.socket(sock_family)
+        self.sock.settimeout(timeout)
+        self.sock.connect(( ip, port ))
+
+        self.is_busy = True
+        try:
+            if not self.is_direct_tcp:
+                self.requestNMBSession()
+            else:
+                self.onNMBSessionOK()
+            while self.auth_result is None:
+                self._pollForNetBIOSPacket(timeout)
+        finally:
+            self.is_busy = False
+
+        return self.auth_result
+
+    def close(self):
+        """
+        Terminate the SMB connection (if it has been started) and release any sources held by the underlying socket.
+        """
+        if self.sock:
+            self.sock.close()
+            self.sock = None
+
+    def listShares(self, timeout = 30):
+        """
+        Retrieve a list of shared resources on remote server.
+
+        :return: A list of :doc:`smb.base.SharedDevice<smb_SharedDevice>` instances describing the shared resource
+        """
+        if not self.sock:
+            raise NotConnectedError('Not connected to server')
+
+        results = [ ]
+
+        def cb(entries):
+            self.is_busy = False
+            results.extend(entries)
+
+        def eb(failure):
+            self.is_busy = False
+            raise failure
+
+        self.is_busy = True
+        try:
+            self._listShares(cb, eb, timeout)
+            while self.is_busy:
+                self._pollForNetBIOSPacket(timeout)
+        finally:
+            self.is_busy = False
+
+        return results
+
+    def listPath(self, service_name, path,
+                 search = SMB_FILE_ATTRIBUTE_READONLY | SMB_FILE_ATTRIBUTE_HIDDEN | SMB_FILE_ATTRIBUTE_SYSTEM | SMB_FILE_ATTRIBUTE_DIRECTORY | SMB_FILE_ATTRIBUTE_ARCHIVE | SMB_FILE_ATTRIBUTE_INCL_NORMAL,
+                 pattern = '*', timeout = 30):
+        """
+        Retrieve a directory listing of files/folders at *path*
+
+        For simplicity, pysmb defines a "normal" file as a file entry that is not read-only, not hidden, not system, not archive and not a directory.
+        It ignores other attributes like compression, indexed, sparse, temporary and encryption.
+
+        Note that the default search parameter will query for all read-only (SMB_FILE_ATTRIBUTE_READONLY), hidden (SMB_FILE_ATTRIBUTE_HIDDEN),
+        system (SMB_FILE_ATTRIBUTE_SYSTEM), archive (SMB_FILE_ATTRIBUTE_ARCHIVE), normal (SMB_FILE_ATTRIBUTE_INCL_NORMAL) files
+        and directories (SMB_FILE_ATTRIBUTE_DIRECTORY).
+        If you do not need to include "normal" files in the result, define your own search parameter without the SMB_FILE_ATTRIBUTE_INCL_NORMAL constant.
+        SMB_FILE_ATTRIBUTE_NORMAL should be used by itself and not be used with other bit constants.
+
+        :param string/unicode service_name: the name of the shared folder for the *path*
+        :param string/unicode path: path relative to the *service_name* where we are interested to learn about its files/sub-folders.
+        :param integer search: integer value made up from a bitwise-OR of *SMB_FILE_ATTRIBUTE_xxx* bits (see smb_constants.py).
+        :param string/unicode pattern: the filter to apply to the results before returning to the client.
+        :return: A list of :doc:`smb.base.SharedFile<smb_SharedFile>` instances.
+        """
+        if not self.sock:
+            raise NotConnectedError('Not connected to server')
+
+        results = [ ]
+
+        def cb(entries):
+            self.is_busy = False
+            results.extend(entries)
+
+        def eb(failure):
+            self.is_busy = False
+            raise failure
+
+        self.is_busy = True
+        try:
+            self._listPath(service_name, path, cb, eb, search = search, pattern = pattern, timeout = timeout)
+            while self.is_busy:
+                self._pollForNetBIOSPacket(timeout)
+        finally:
+            self.is_busy = False
+
+        return results
+
+    def listSnapshots(self, service_name, path, timeout = 30):
+        """
+        Retrieve a list of available snapshots (shadow copies) for *path*.
+
+        Note that snapshot features are only supported on Windows Vista Business, Enterprise and Ultimate, and on all Windows 7 editions.
+
+        :param string/unicode service_name: the name of the shared folder for the *path*
+        :param string/unicode path: path relative to the *service_name* where we are interested in the list of available snapshots
+        :return: A list of python *datetime.DateTime* instances in GMT/UTC time zone
+        """
+        if not self.sock:
+            raise NotConnectedError('Not connected to server')
+
+        results = [ ]
+
+        def cb(entries):
+            self.is_busy = False
+            results.extend(entries)
+
+        def eb(failure):
+            self.is_busy = False
+            raise failure
+
+        self.is_busy = True
+        try:
+            self._listSnapshots(service_name, path, cb, eb, timeout = timeout)
+            while self.is_busy:
+                self._pollForNetBIOSPacket(timeout)
+        finally:
+            self.is_busy = False
+
+        return results
+
+    def getAttributes(self, service_name, path, timeout = 30):
+        """
+        Retrieve information about the file at *path* on the *service_name*.
+
+        :param string/unicode service_name: the name of the shared folder for the *path*
+        :param string/unicode path: Path of the file on the remote server. If the file cannot be opened for reading, an :doc:`OperationFailure<smb_exceptions>` will be raised.
+        :return: A :doc:`smb.base.SharedFile<smb_SharedFile>` instance containing the attributes of the file.
+        """
+        if not self.sock:
+            raise NotConnectedError('Not connected to server')
+
+        results = [ ]
+
+        def cb(info):
+            self.is_busy = False
+            results.append(info)
+
+        def eb(failure):
+            self.is_busy = False
+            raise failure
+
+        self.is_busy = True
+        try:
+            self._getAttributes(service_name, path, cb, eb, timeout)
+            while self.is_busy:
+                self._pollForNetBIOSPacket(timeout)
+        finally:
+            self.is_busy = False
+
+        return results[0]
+
+    def getSecurity(self, service_name, path, timeout = 30):
+        """
+        Retrieve the security descriptor of the file at *path* on the *service_name*.
+
+        :param string/unicode service_name: the name of the shared folder for the *path*
+        :param string/unicode path: Path of the file on the remote server. If the file cannot be opened for reading, an :doc:`OperationFailure<smb_exceptions>` will be raised.
+        :return: A :class:`smb.security_descriptors.SecurityDescriptor` instance containing the security information of the file.
+        """
+        if not self.sock:
+            raise NotConnectedError('Not connected to server')
+
+        results = [ ]
+
+        def cb(info):
+            self.is_busy = False
+            results.append(info)
+
+        def eb(failure):
+            self.is_busy = False
+            raise failure
+
+        self.is_busy = True
+        try:
+            self._getSecurity(service_name, path, cb, eb, timeout)
+            while self.is_busy:
+                self._pollForNetBIOSPacket(timeout)
+        finally:
+            self.is_busy = False
+
+        return results[0]
+
+    def retrieveFile(self, service_name, path, file_obj, timeout = 30):
+        """
+        Retrieve the contents of the file at *path* on the *service_name* and write these contents to the provided *file_obj*.
+
+        Use *retrieveFileFromOffset()* method if you wish to specify the offset to read from the remote *path* and/or the number of bytes to write to the *file_obj*.
+
+        :param string/unicode service_name: the name of the shared folder for the *path*
+        :param string/unicode path: Path of the file on the remote server. If the file cannot be opened for reading, an :doc:`OperationFailure<smb_exceptions>` will be raised.
+        :param file_obj: A file-like object that has a *write* method. Data will be written continuously to *file_obj* until EOF is received from the remote service.
+        :return: A 2-element tuple of ( file attributes of the file on server, number of bytes written to *file_obj* ).
+                 The file attributes is an integer value made up from a bitwise-OR of *SMB_FILE_ATTRIBUTE_xxx* bits (see smb_constants.py)
+        """
+        return self.retrieveFileFromOffset(service_name, path, file_obj, 0L, -1L, timeout)
+
+    def retrieveFileFromOffset(self, service_name, path, file_obj, offset = 0L, max_length = -1L, timeout = 30):
+        """
+        Retrieve the contents of the file at *path* on the *service_name* and write these contents to the provided *file_obj*.
+
+        :param string/unicode service_name: the name of the shared folder for the *path*
+        :param string/unicode path: Path of the file on the remote server. If the file cannot be opened for reading, an :doc:`OperationFailure<smb_exceptions>` will be raised.
+        :param file_obj: A file-like object that has a *write* method. Data will be written continuously to *file_obj* up to *max_length* number of bytes.
+        :param integer/long offset: the offset in the remote *path* where the first byte will be read and written to *file_obj*. Must be either zero or a positive integer/long value.
+        :param integer/long max_length: maximum number of bytes to read from the remote *path* and write to the *file_obj*. Specify a negative value to read from *offset* to the EOF.
+                                        If zero, the method returns immediately after the file is opened successfully for reading.
+        :return: A 2-element tuple of ( file attributes of the file on server, number of bytes written to *file_obj* ).
+                 The file attributes is an integer value made up from a bitwise-OR of *SMB_FILE_ATTRIBUTE_xxx* bits (see smb_constants.py)
+        """
+        if not self.sock:
+            raise NotConnectedError('Not connected to server')
+
+        results = [ ]
+
+        def cb(r):
+            self.is_busy = False
+            results.append(r[1:])
+
+        def eb(failure):
+            self.is_busy = False
+            raise failure
+
+        self.is_busy = True
+        try:
+            self._retrieveFileFromOffset(service_name, path, file_obj, cb, eb, offset, max_length, timeout = timeout)
+            while self.is_busy:
+                self._pollForNetBIOSPacket(timeout)
+        finally:
+            self.is_busy = False
+
+        return results[0]
+
+    def storeFile(self, service_name, path, file_obj, timeout = 30):
+        """
+        Store the contents of the *file_obj* at *path* on the *service_name*.
+        If the file already exists on the remote server, it will be truncated and overwritten.
+
+        :param string/unicode service_name: the name of the shared folder for the *path*
+        :param string/unicode path: Path of the file on the remote server. If the file at *path* does not exist, it will be created. Otherwise, it will be overwritten.
+                                    If the *path* refers to a folder or the file cannot be opened for writing, an :doc:`OperationFailure<smb_exceptions>` will be raised.
+        :param file_obj: A file-like object that has a *read* method. Data will read continuously from *file_obj* until EOF.
+        :return: Number of bytes uploaded
+        """
+        return self.storeFileFromOffset(service_name, path, file_obj, 0L, True, timeout)
+
+    def storeFileFromOffset(self, service_name, path, file_obj, offset = 0L, truncate = False, timeout = 30):
+        """
+        Store the contents of the *file_obj* at *path* on the *service_name*.
+
+        :param string/unicode service_name: the name of the shared folder for the *path*
+        :param string/unicode path: Path of the file on the remote server. If the file at *path* does not exist, it will be created.
+                                    If the *path* refers to a folder or the file cannot be opened for writing, an :doc:`OperationFailure<smb_exceptions>` will be raised.
+        :param file_obj: A file-like object that has a *read* method. Data will read continuously from *file_obj* until EOF.
+        :param offset: Long integer value which specifies the offset in the remote server to start writing. First byte of the file is 0.
+        :param truncate: Boolean value. If True and the file exists on the remote server, it will be truncated first before writing. Default is False.
+        :return: the file position where the next byte will be written.
+        """
+        if not self.sock:
+            raise NotConnectedError('Not connected to server')
+
+        results = [ ]
+
+        def cb(r):
+            self.is_busy = False
+            results.append(r[1])
+
+        def eb(failure):
+            self.is_busy = False
+            raise failure
+
+        self.is_busy = True
+        try:
+            self._storeFileFromOffset(service_name, path, file_obj, cb, eb, offset, truncate = truncate, timeout = timeout)
+            while self.is_busy:
+                self._pollForNetBIOSPacket(timeout)
+        finally:
+            self.is_busy = False
+
+        return results[0]
+
+    def deleteFiles(self, service_name, path_file_pattern, timeout = 30):
+        """
+        Delete one or more regular files. It supports the use of wildcards in file names, allowing for deletion of multiple files in a single request.
+
+        :param string/unicode service_name: Contains the name of the shared folder.
+        :param string/unicode path_file_pattern: The pathname of the file(s) to be deleted, relative to the service_name.
+                                                 Wildcards may be used in th filename component of the path.
+                                                 If your path/filename contains non-English characters, you must pass in an unicode string.
+        :return: None
+        """
+        if not self.sock:
+            raise NotConnectedError('Not connected to server')
+
+        def cb(r):
+            self.is_busy = False
+
+        def eb(failure):
+            self.is_busy = False
+            raise failure
+
+        self.is_busy = True
+        try:
+            self._deleteFiles(service_name, path_file_pattern, cb, eb, timeout = timeout)
+            while self.is_busy:
+                self._pollForNetBIOSPacket(timeout)
+        finally:
+            self.is_busy = False
+
+    def resetFileAttributes(self, service_name, path_file_pattern, timeout = 30):
+        """
+        Reset file attributes of one or more regular files or folders.
+        It supports the use of wildcards in file names, allowing for unlocking of multiple files/folders in a single request.
+        This function is very helpful when deleting files/folders that are read-only.
+        Note: this function is currently only implemented for SMB2! Technically, it sets the FILE_ATTRIBUTE_NORMAL flag, therefore clearing all other flags. (See https://msdn.microsoft.com/en-us/library/cc232110.aspx for further information)
+
+        :param string/unicode service_name: Contains the name of the shared folder.
+        :param string/unicode path_file_pattern: The pathname of the file(s) to be deleted, relative to the service_name.
+                                                 Wildcards may be used in the filename component of the path.
+                                                 If your path/filename contains non-English characters, you must pass in an unicode string.
+        :return: None
+        """
+        if not self.sock:
+            raise NotConnectedError('Not connected to server')
+
+        def cb(r):
+            self.is_busy = False
+
+        def eb(failure):
+            self.is_busy = False
+            raise failure
+
+        self.is_busy = True
+        try:
+            self._resetFileAttributes(service_name, path_file_pattern, cb, eb, timeout = timeout)
+            while self.is_busy:
+                self._pollForNetBIOSPacket(timeout)
+        finally:
+            self.is_busy = False
+
+    def createDirectory(self, service_name, path, timeout = 30):
+        """
+        Creates a new directory *path* on the *service_name*.
+
+        :param string/unicode service_name: Contains the name of the shared folder.
+        :param string/unicode path: The path of the new folder (relative to) the shared folder.
+                                    If the path contains non-English characters, an unicode string must be used to pass in the path.
+        :return: None
+        """
+        if not self.sock:
+            raise NotConnectedError('Not connected to server')
+
+        def cb(r):
+            self.is_busy = False
+
+        def eb(failure):
+            self.is_busy = False
+            raise failure
+
+        self.is_busy = True
+        try:
+            self._createDirectory(service_name, path, cb, eb, timeout = timeout)
+            while self.is_busy:
+                self._pollForNetBIOSPacket(timeout)
+        finally:
+            self.is_busy = False
+
+    def deleteDirectory(self, service_name, path, timeout = 30):
+        """
+        Delete the empty folder at *path* on *service_name*
+
+        :param string/unicode service_name: Contains the name of the shared folder.
+        :param string/unicode path: The path of the to-be-deleted folder (relative to) the shared folder.
+                                    If the path contains non-English characters, an unicode string must be used to pass in the path.
+        :return: None
+        """
+        if not self.sock:
+            raise NotConnectedError('Not connected to server')
+
+        def cb(r):
+            self.is_busy = False
+
+        def eb(failure):
+            self.is_busy = False
+            raise failure
+
+        self.is_busy = True
+        try:
+            self._deleteDirectory(service_name, path, cb, eb, timeout = timeout)
+            while self.is_busy:
+                self._pollForNetBIOSPacket(timeout)
+        finally:
+            self.is_busy = False
+
+    def rename(self, service_name, old_path, new_path, timeout = 30):
+        """
+        Rename a file or folder at *old_path* to *new_path* shared at *service_name*. Note that this method cannot be used to rename file/folder across different shared folders
+
+        *old_path* and *new_path* are string/unicode referring to the old and new path of the renamed resources (relative to) the shared folder.
+        If the path contains non-English characters, an unicode string must be used to pass in the path.
+
+        :param string/unicode service_name: Contains the name of the shared folder.
+        :return: None
+        """
+        if not self.sock:
+            raise NotConnectedError('Not connected to server')
+
+        def cb(r):
+            self.is_busy = False
+
+        def eb(failure):
+            self.is_busy = False
+            raise failure
+
+        self.is_busy = True
+        try:
+            self._rename(service_name, old_path, new_path, cb, eb)
+            while self.is_busy:
+                self._pollForNetBIOSPacket(timeout)
+        finally:
+            self.is_busy = False
+
+    def echo(self, data, timeout = 10):
+        """
+        Send an echo command containing *data* to the remote SMB/CIFS server. The remote SMB/CIFS will reply with the same *data*.
+
+        :param bytes data: Data to send to the remote server. Must be a bytes object.
+        :return: The *data* parameter
+        """
+        if not self.sock:
+            raise NotConnectedError('Not connected to server')
+
+        results = [ ]
+
+        def cb(r):
+            self.is_busy = False
+            results.append(r)
+
+        def eb(failure):
+            self.is_busy = False
+            raise failure
+
+        self.is_busy = True
+        try:
+            self._echo(data, cb, eb)
+            while self.is_busy:
+                self._pollForNetBIOSPacket(timeout)
+        finally:
+            self.is_busy = False
+
+        return results[0]
+
+    #
+    # Protected Methods
+    #
+
+    def _pollForNetBIOSPacket(self, timeout):
+        expiry_time = time.time() + timeout
+        read_len = 4
+        data = ''
+
+        while read_len > 0:
+            try:
+                if expiry_time < time.time():
+                    raise SMBTimeout
+
+                ready, _, _ = select.select([ self.sock.fileno() ], [ ], [ ], timeout)
+                if not ready:
+                    raise SMBTimeout
+
+                d = self.sock.recv(read_len)
+                if len(d) == 0:
+                    raise NotConnectedError
+
+                data = data + d
+                read_len -= len(d)
+            except select.error, ex:
+                if isinstance(ex, types.TupleType):
+                    if ex[0] != errno.EINTR and ex[0] != errno.EAGAIN:
+                        raise ex
+                else:
+                    raise ex
+
+        type_, flags, length = struct.unpack('>BBH', data)
+        if type_ == 0x0:
+            # This is a Direct TCP packet
+            # The length is specified in the header from byte 8. (0-indexed)
+            # we read a structure assuming NBT, so to get the real length
+            # combine the length and flag fields together
+            length = length + (flags << 16)
+        else:
+            # This is a NetBIOS over TCP (NBT) packet
+            # The length is specified in the header from byte 16. (0-indexed)
+            if flags & 0x01:
+                length = length | 0x10000
+
+        read_len = length
+        while read_len > 0:
+            try:
+                if expiry_time < time.time():
+                    raise SMBTimeout
+
+                ready, _, _ = select.select([ self.sock.fileno() ], [ ], [ ], timeout)
+                if not ready:
+                    raise SMBTimeout
+
+                d = self.sock.recv(read_len)
+                if len(d) == 0:
+                    raise NotConnectedError
+
+                data = data + d
+                read_len -= len(d)
+            except select.error, ex:
+                if isinstance(ex, types.TupleType):
+                    if ex[0] != errno.EINTR and ex[0] != errno.EAGAIN:
+                        raise ex
+                else:
+                    raise ex
+
+        self.feedData(data)
diff --git a/python2/smb/SMBHandler.py b/python2/smb/SMBHandler.py
new file mode 100644
index 00000000..137e943a
--- /dev/null
+++ b/python2/smb/SMBHandler.py
@@ -0,0 +1,97 @@
+
+import os, sys, socket, urllib2, mimetypes, mimetools, tempfile
+from urllib import (unwrap, unquote, splittype, splithost, quote,
+     addinfourl, splitport, splittag,
+     splitattr, ftpwrapper, splituser, splitpasswd, splitvalue)
+from nmb.NetBIOS import NetBIOS
+from smb.SMBConnection import SMBConnection
+
+try:
+    from cStringIO import StringIO
+except ImportError:
+    from StringIO import StringIO
+
+USE_NTLM = True
+MACHINE_NAME = None
+
+class SMBHandler(urllib2.BaseHandler):
+
+    def smb_open(self, req):
+        global USE_NTLM, MACHINE_NAME
+
+        host = req.get_host()
+        if not host:
+            raise urllib2.URLError('SMB error: no host given')
+        host, port = splitport(host)
+        if port is None:
+            port = 139
+        else:
+            port = int(port)
+
+        # username/password handling
+        user, host = splituser(host)
+        if user:
+            user, passwd = splitpasswd(user)
+        else:
+            passwd = None
+        host = unquote(host)
+        user = user or ''
+
+        domain = ''
+        if ';' in user:
+            domain, user = user.split(';', 1)
+
+        passwd = passwd or ''
+        myname = MACHINE_NAME or self.generateClientMachineName()
+
+        n = NetBIOS()
+        names = n.queryIPForName(host)
+        if names:
+            server_name = names[0]
+        else:
+            raise urllib2.URLError('SMB error: Hostname does not reply back with its machine name')
+
+        path, attrs = splitattr(req.get_selector())
+        if path.startswith('/'):
+            path = path[1:]
+        dirs = path.split('/')
+        dirs = map(unquote, dirs)
+        service, path = dirs[0], '/'.join(dirs[1:])
+
+        try:
+            conn = SMBConnection(user, passwd, myname, server_name, domain=domain, use_ntlm_v2 = USE_NTLM)
+            conn.connect(host, port)
+
+            if req.has_data():
+                data_fp = req.get_data()
+                filelen = conn.storeFile(service, path, data_fp)
+
+                headers = "Content-length: 0\n"
+                fp = StringIO("")
+            else:
+                fp = self.createTempFile()
+                file_attrs, retrlen = conn.retrieveFile(service, path, fp)
+                fp.seek(0)
+
+                headers = ""
+                mtype = mimetypes.guess_type(req.get_full_url())[0]
+                if mtype:
+                    headers += "Content-type: %s\n" % mtype
+                if retrlen is not None and retrlen >= 0:
+                    headers += "Content-length: %d\n" % retrlen
+
+            sf = StringIO(headers)
+            headers = mimetools.Message(sf)
+
+            return addinfourl(fp, headers, req.get_full_url())
+        except Exception, ex:
+            raise urllib2.URLError, ('smb error: %s' % ex), sys.exc_info()[2]
+
+    def createTempFile(self):
+        return tempfile.TemporaryFile()
+
+    def generateClientMachineName(self):
+        hostname = socket.gethostname()
+        if hostname:
+            return hostname.split('.')[0]
+        return 'SMB%d' % os.getpid()
diff --git a/python2/smb/SMBProtocol.py b/python2/smb/SMBProtocol.py
new file mode 100644
index 00000000..1238d637
--- /dev/null
+++ b/python2/smb/SMBProtocol.py
@@ -0,0 +1,409 @@
+
+import os, logging, time
+from twisted.internet import reactor, defer
+from twisted.internet.protocol import ClientFactory, Protocol
+from smb_constants import *
+from smb_structs import *
+from base import SMB, NotConnectedError, NotReadyError, SMBTimeout
+
+
+__all__ = [ 'SMBProtocolFactory', 'NotConnectedError', 'NotReadyError' ]
+
+
+class SMBProtocol(Protocol, SMB):
+
+    log = logging.getLogger('SMB.SMBProtocol')
+
+    #
+    # Protocol Methods
+    #
+
+    def connectionMade(self):
+        self.factory.instance = self
+        if not self.is_direct_tcp:
+            self.requestNMBSession()
+        else:
+            self.onNMBSessionOK()
+
+    def connectionLost(self, reason):
+        if self.factory.instance == self:
+            self.instance = None
+
+    def dataReceived(self, data):
+        self.feedData(data)
+
+    #
+    # SMB (and its superclass) Methods
+    #
+
+    def write(self, data):
+        self.transport.write(data)
+
+    def onAuthOK(self):
+        if self.factory.instance == self:
+            self.factory.onAuthOK()
+            reactor.callLater(1, self._cleanupPendingRequests)
+
+    def onAuthFailed(self):
+        if self.factory.instance == self:
+            self.factory.onAuthFailed()
+
+    def onNMBSessionFailed(self):
+        self.log.error('Cannot establish NetBIOS session. You might have provided a wrong remote_name')
+
+    #
+    # Protected Methods
+    #
+
+    def _cleanupPendingRequests(self):
+        if self.factory.instance == self:
+            now = time.time()
+            to_remove = []
+            for mid, r in self.pending_requests.iteritems():
+                if r.expiry_time < now:
+                    try:
+                        r.errback(SMBTimeout())
+                    except Exception: pass
+                    to_remove.append(mid)
+
+            for mid in to_remove:
+                del self.pending_requests[mid]
+
+            reactor.callLater(1, self._cleanupPendingRequests)
+
+
+class SMBProtocolFactory(ClientFactory):
+
+    protocol = SMBProtocol
+    log = logging.getLogger('SMB.SMBFactory')
+
+    #: SMB messages will never be signed regardless of remote server's configurations; access errors will occur if the remote server requires signing.
+    SIGN_NEVER = 0
+    #: SMB messages will be signed when remote server supports signing but not requires signing.
+    SIGN_WHEN_SUPPORTED = 1
+    #: SMB messages will only be signed when remote server requires signing.
+    SIGN_WHEN_REQUIRED = 2
+
+    def __init__(self, username, password, my_name, remote_name, domain = '', use_ntlm_v2 = True, sign_options = SIGN_WHEN_REQUIRED, is_direct_tcp = False):
+        """
+        Create a new SMBProtocolFactory instance. You will pass this instance to *reactor.connectTCP()* which will then instantiate the TCP connection to the remote SMB/CIFS server.
+        Note that the default TCP port for most SMB/CIFS servers using NetBIOS over TCP/IP is 139.
+        Some newer server installations might also support Direct hosting of SMB over TCP/IP; for these servers, the default TCP port is 445.
+
+        *username* and *password* are the user credentials required to authenticate the underlying SMB connection with the remote server.
+        File operations can only be proceeded after the connection has been authenticated successfully.
+
+        :param string my_name: The local NetBIOS machine name that will identify where this connection is originating from.
+                               You can freely choose a name as long as it contains a maximum of 15 alphanumeric characters and does not contain spaces and any of ``\/:*?";|+``.
+        :param string remote_name: The NetBIOS machine name of the remote server.
+                                   On windows, you can find out the machine name by right-clicking on the "My Computer" and selecting "Properties".
+                                   This parameter must be the same as what has been configured on the remote server, or else the connection will be rejected.
+        :param string domain: The network domain. On windows, it is known as the workgroup. Usually, it is safe to leave this parameter as an empty string.
+        :param boolean use_ntlm_v2: Indicates whether pysmb should be NTLMv1 or NTLMv2 authentication algorithm for authentication.
+                                    The choice of NTLMv1 and NTLMv2 is configured on the remote server, and there is no mechanism to auto-detect which algorithm has been configured.
+                                    Hence, we can only "guess" or try both algorithms.
+                                    On Sambda, Windows Vista and Windows 7, NTLMv2 is enabled by default. On Windows XP, we can use NTLMv1 before NTLMv2.
+        :param int sign_options: Determines whether SMB messages will be signed. Default is *SIGN_WHEN_REQUIRED*.
+                                 If *SIGN_WHEN_REQUIRED* (value=2), SMB messages will only be signed when remote server requires signing.
+                                 If *SIGN_WHEN_SUPPORTED* (value=1), SMB messages will be signed when remote server supports signing but not requires signing.
+                                 If *SIGN_NEVER* (value=0), SMB messages will never be signed regardless of remote server's configurations; access errors will occur if the remote server requires signing.
+        :param boolean is_direct_tcp: Controls whether the NetBIOS over TCP/IP (is_direct_tcp=False) or the newer Direct hosting of SMB over TCP/IP (is_direct_tcp=True) will be used for the communication.
+                                      The default parameter is False which will use NetBIOS over TCP/IP for wider compatibility (TCP port: 139).
+        """
+        self.username = username
+        self.password = password
+        self.my_name = my_name
+        self.remote_name = remote_name
+        self.domain = domain
+        self.use_ntlm_v2 = use_ntlm_v2
+        self.sign_options = sign_options
+        self.is_direct_tcp = is_direct_tcp
+        self.instance = None    #: The single SMBProtocol instance for each SMBProtocolFactory instance. Usually, you should not need to touch this attribute directly.
+
+    #
+    # Public Property
+    #
+
+    @property
+    def isReady(self):
+        """A convenient property to return True if the underlying SMB connection has connected to remote server, has successfully authenticated itself and is ready for file operations."""
+        return bool(self.instance and self.instance.has_authenticated)
+
+    @property
+    def isUsingSMB2(self):
+        """A convenient property to return True if the underlying SMB connection is using SMB2 protocol."""
+        return self.instance and self.instance.is_using_smb2
+
+    #
+    # Public Methods for Callbacks
+    #
+
+    def onAuthOK(self):
+        """
+        Override this method in your *SMBProtocolFactory* subclass to add in post-authentication handling.
+        This method will be called when the server has replied that the SMB connection has been successfully authenticated.
+        File operations can proceed when this method has been called.
+        """
+        pass
+
+    def onAuthFailed(self):
+        """
+        Override this method in your *SMBProtocolFactory* subclass to add in post-authentication handling.
+        This method will be called when the server has replied that the SMB connection has been successfully authenticated.
+
+        If you want to retry authenticating from this method,
+         1. Disconnect the underlying SMB connection (call ``self.instance.transport.loseConnection()``)
+         2. Create a new SMBProtocolFactory subclass instance with different user credientials or different NTLM algorithm flag.
+         3. Call ``reactor.connectTCP`` with the new instance to re-establish the SMB connection
+        """
+        pass
+
+    #
+    # Public Methods
+    #
+
+    def listShares(self, timeout = 30):
+        """
+        Retrieve a list of shared resources on remote server.
+
+        :param integer/float timeout: Number of seconds that pysmb will wait before raising *SMBTimeout* via the returned *Deferred* instance's *errback* method.
+        :return: A *twisted.internet.defer.Deferred* instance. The callback function will be called with a list of :doc:`smb.base.SharedDevice<smb_SharedDevice>` instances.
+        """
+        if not self.instance:
+            raise NotConnectedError('Not connected to server')
+
+        d = defer.Deferred()
+        self.instance._listShares(d.callback, d.errback, timeout)
+        return d
+
+    def listPath(self, service_name, path,
+                 search = SMB_FILE_ATTRIBUTE_READONLY | SMB_FILE_ATTRIBUTE_HIDDEN | SMB_FILE_ATTRIBUTE_SYSTEM | SMB_FILE_ATTRIBUTE_DIRECTORY | SMB_FILE_ATTRIBUTE_ARCHIVE | SMB_FILE_ATTRIBUTE_INCL_NORMAL,
+                 pattern = '*', timeout = 30):
+        """
+        Retrieve a directory listing of files/folders at *path*
+
+        For simplicity, pysmb defines a "normal" file as a file entry that is not read-only, not hidden, not system, not archive and not a directory.
+        It ignores other attributes like compression, indexed, sparse, temporary and encryption.
+
+        Note that the default search parameter will query for all read-only (SMB_FILE_ATTRIBUTE_READONLY), hidden (SMB_FILE_ATTRIBUTE_HIDDEN),
+        system (SMB_FILE_ATTRIBUTE_SYSTEM), archive (SMB_FILE_ATTRIBUTE_ARCHIVE), normal (SMB_FILE_ATTRIBUTE_INCL_NORMAL) files
+        and directories (SMB_FILE_ATTRIBUTE_DIRECTORY).
+        If you do not need to include "normal" files in the result, define your own search parameter without the SMB_FILE_ATTRIBUTE_INCL_NORMAL constant.
+        SMB_FILE_ATTRIBUTE_NORMAL should be used by itself and not be used with other bit constants.
+
+        :param string/unicode service_name: the name of the shared folder for the *path*
+        :param string/unicode path: path relative to the *service_name* where we are interested to learn about its files/sub-folders.
+        :param integer search: integer value made up from a bitwise-OR of *SMB_FILE_ATTRIBUTE_xxx* bits (see smb_constants.py).
+        :param string/unicode pattern: the filter to apply to the results before returning to the client.
+        :param integer/float timeout: Number of seconds that pysmb will wait before raising *SMBTimeout* via the returned *Deferred* instance's *errback* method.
+        :return: A *twisted.internet.defer.Deferred* instance. The callback function will be called with a list of :doc:`smb.base.SharedFile<smb_SharedFile>` instances.
+        """
+        if not self.instance:
+            raise NotConnectedError('Not connected to server')
+
+        d = defer.Deferred()
+        self.instance._listPath(service_name, path, d.callback, d.errback, search = search, pattern = pattern, timeout = timeout)
+        return d
+
+    def listSnapshots(self, service_name, path, timeout = 30):
+        """
+        Retrieve a list of available snapshots (a.k.a. shadow copies) for *path*.
+
+        Note that snapshot features are only supported on Windows Vista Business, Enterprise and Ultimate, and on all Windows 7 editions.
+
+        :param string/unicode service_name: the name of the shared folder for the *path*
+        :param string/unicode path: path relative to the *service_name* where we are interested in the list of available snapshots
+        :return: A *twisted.internet.defer.Deferred* instance. The callback function will be called with a list of python *datetime.DateTime*
+                 instances in GMT/UTC time zone
+        """
+        if not self.instance:
+            raise NotConnectedError('Not connected to server')
+
+        d = defer.Deferred()
+        self.instance._listSnapshots(service_name, path, d.callback, d.errback, timeout = timeout)
+        return d
+
+    def getAttributes(self, service_name, path, timeout = 30):
+        """
+        Retrieve information about the file at *path* on the *service_name*.
+
+        :param string/unicode service_name: the name of the shared folder for the *path*
+        :param string/unicode path: Path of the file on the remote server. If the file cannot be opened for reading, an :doc:`OperationFailure<smb_exceptions>` will be raised.
+        :return: A *twisted.internet.defer.Deferred* instance. The callback function will be called with a :doc:`smb.base.SharedFile<smb_SharedFile>` instance containing the attributes of the file.
+        """
+        if not self.instance:
+            raise NotConnectedError('Not connected to server')
+
+        d = defer.Deferred()
+        self.instance._getAttributes(service_name, path, d.callback, d.errback, timeout = timeout)
+        return d
+
+    def retrieveFile(self, service_name, path, file_obj, timeout = 30):
+        """
+        Retrieve the contents of the file at *path* on the *service_name* and write these contents to the provided *file_obj*.
+
+        Use *retrieveFileFromOffset()* method if you need to specify the offset to read from the remote *path* and/or the maximum number of bytes to write to the *file_obj*.
+
+        The meaning of the *timeout* parameter will be different from other file operation methods. As the downloaded file usually exceeeds the maximum size
+        of each SMB/CIFS data message, it will be packetized into a series of request messages (each message will request about about 60kBytes).
+        The *timeout* parameter is an integer/float value that specifies the timeout interval for these individual SMB/CIFS message to be transmitted and downloaded from the remote SMB/CIFS server.
+
+        :param string/unicode service_name: the name of the shared folder for the *path*
+        :param string/unicode path: Path of the file on the remote server. If the file cannot be opened for reading, an :doc:`OperationFailure<smb_exceptions>` will be called in the returned *Deferred* errback.
+        :param file_obj: A file-like object that has a *write* method. Data will be written continuously to *file_obj* until EOF is received from the remote service.
+        :return: A *twisted.internet.defer.Deferred* instance. The callback function will be called with a 3-element tuple of ( *file_obj*, file attributes of the file on server, number of bytes written to *file_obj* ).
+                 The file attributes is an integer value made up from a bitwise-OR of *SMB_FILE_ATTRIBUTE_xxx* bits (see smb_constants.py)
+        """
+        return self.retrieveFileFromOffset(service_name, path, file_obj, 0L, -1L, timeout)
+
+    def retrieveFileFromOffset(self, service_name, path, file_obj, offset = 0L, max_length = -1L, timeout = 30):
+        """
+        Retrieve the contents of the file at *path* on the *service_name* and write these contents to the provided *file_obj*.
+
+        The meaning of the *timeout* parameter will be different from other file operation methods. As the downloaded file usually exceeeds the maximum size
+        of each SMB/CIFS data message, it will be packetized into a series of request messages (each message will request about about 60kBytes).
+        The *timeout* parameter is an integer/float value that specifies the timeout interval for these individual SMB/CIFS message to be transmitted and downloaded from the remote SMB/CIFS server.
+
+        :param string/unicode service_name: the name of the shared folder for the *path*
+        :param string/unicode path: Path of the file on the remote server. If the file cannot be opened for reading, an :doc:`OperationFailure<smb_exceptions>` will be called in the returned *Deferred* errback.
+        :param file_obj: A file-like object that has a *write* method. Data will be written continuously to *file_obj* until EOF is received from the remote service.
+        :param integer/long offset: the offset in the remote *path* where the first byte will be read and written to *file_obj*. Must be either zero or a positive integer/long value.
+        :param integer/long max_length: maximum number of bytes to read from the remote *path* and write to the *file_obj*. Specify a negative value to read from *offset* to the EOF.
+                                        If zero, the *Deferred* callback is invoked immediately after the file is opened successfully for reading.
+        :return: A *twisted.internet.defer.Deferred* instance. The callback function will be called with a 3-element tuple of ( *file_obj*, file attributes of the file on server, number of bytes written to *file_obj* ).
+                 The file attributes is an integer value made up from a bitwise-OR of *SMB_FILE_ATTRIBUTE_xxx* bits (see smb_constants.py)
+        """
+        if not self.instance:
+            raise NotConnectedError('Not connected to server')
+
+        d = defer.Deferred()
+        self.instance._retrieveFileFromOffset(service_name, path, file_obj, d.callback, d.errback, offset, max_length, timeout = timeout)
+        return d
+
+    def storeFile(self, service_name, path, file_obj, timeout = 30):
+        """
+        Store the contents of the *file_obj* at *path* on the *service_name*.
+
+        The meaning of the *timeout* parameter will be different from other file operation methods. As the uploaded file usually exceeeds the maximum size
+        of each SMB/CIFS data message, it will be packetized into a series of messages (usually about 60kBytes).
+        The *timeout* parameter is an integer/float value that specifies the timeout interval for these individual SMB/CIFS message to be transmitted and acknowledged
+        by the remote SMB/CIFS server.
+
+        :param string/unicode service_name: the name of the shared folder for the *path*
+        :param string/unicode path: Path of the file on the remote server. If the file at *path* does not exist, it will be created. Otherwise, it will be overwritten.
+                                    If the *path* refers to a folder or the file cannot be opened for writing, an :doc:`OperationFailure<smb_exceptions>` will be called in the returned *Deferred* errback.
+        :param file_obj: A file-like object that has a *read* method. Data will read continuously from *file_obj* until EOF.
+        :return: A *twisted.internet.defer.Deferred* instance. The callback function will be called with a 2-element tuple of ( *file_obj*, number of bytes uploaded ).
+        """
+        if not self.instance:
+            raise NotConnectedError('Not connected to server')
+
+        d = defer.Deferred()
+        self.instance._storeFile(service_name, path, file_obj, d.callback, d.errback, timeout = timeout)
+        return d
+
+    def deleteFiles(self, service_name, path_file_pattern, timeout = 30):
+        """
+        Delete one or more regular files. It supports the use of wildcards in file names, allowing for deletion of multiple files in a single request.
+
+        :param string/unicode service_name: Contains the name of the shared folder.
+        :param string/unicode path_file_pattern: The pathname of the file(s) to be deleted, relative to the service_name.
+                                                 Wildcards may be used in th filename component of the path.
+                                                 If your path/filename contains non-English characters, you must pass in an unicode string.
+        :param integer/float timeout: Number of seconds that pysmb will wait before raising *SMBTimeout* via the returned *Deferred* instance's *errback* method.
+        :return: A *twisted.internet.defer.Deferred* instance. The callback function will be called with the *path_file_pattern* parameter.
+        """
+        if not self.instance:
+            raise NotConnectedError('Not connected to server')
+
+        d = defer.Deferred()
+        self.instance._deleteFiles(service_name, path_file_pattern, d.callback, d.errback, timeout = timeout)
+        return d
+
+    def createDirectory(self, service_name, path):
+        """
+        Creates a new directory *path* on the *service_name*.
+
+        :param string/unicode service_name: Contains the name of the shared folder.
+        :param string/unicode path: The path of the new folder (relative to) the shared folder.
+                                    If the path contains non-English characters, an unicode string must be used to pass in the path.
+        :param integer/float timeout: Number of seconds that pysmb will wait before raising *SMBTimeout* via the returned *Deferred* instance's *errback* method.
+        :return: A *twisted.internet.defer.Deferred* instance. The callback function will be called with the *path* parameter.
+        """
+        if not self.instance:
+            raise NotConnectedError('Not connected to server')
+
+        d = defer.Deferred()
+        self.instance._createDirectory(service_name, path, d.callback, d.errback)
+        return d
+
+    def deleteDirectory(self, service_name, path):
+        """
+        Delete the empty folder at *path* on *service_name*
+
+        :param string/unicode service_name: Contains the name of the shared folder.
+        :param string/unicode path: The path of the to-be-deleted folder (relative to) the shared folder.
+                                    If the path contains non-English characters, an unicode string must be used to pass in the path.
+        :param integer/float timeout: Number of seconds that pysmb will wait before raising *SMBTimeout* via the returned *Deferred* instance's *errback* method.
+        :return: A *twisted.internet.defer.Deferred* instance. The callback function will be called with the *path* parameter.
+        """
+        if not self.instance:
+            raise NotConnectedError('Not connected to server')
+
+        d = defer.Deferred()
+        self.instance._deleteDirectory(service_name, path, d.callback, d.errback)
+        return d
+
+    def rename(self, service_name, old_path, new_path):
+        """
+        Rename a file or folder at *old_path* to *new_path* shared at *service_name*. Note that this method cannot be used to rename file/folder across different shared folders
+
+        *old_path* and *new_path* are string/unicode referring to the old and new path of the renamed resources (relative to) the shared folder.
+        If the path contains non-English characters, an unicode string must be used to pass in the path.
+
+        :param string/unicode service_name: Contains the name of the shared folder.
+        :param integer/float timeout: Number of seconds that pysmb will wait before raising *SMBTimeout* via the returned *Deferred* instance's *errback* method.
+        :return: A *twisted.internet.defer.Deferred* instance. The callback function will be called with a 2-element tuple of ( *old_path*, *new_path* ).
+        """
+        if not self.instance:
+            raise NotConnectedError('Not connected to server')
+
+        d = defer.Deferred()
+        self.instance._rename(service_name, old_path, new_path, d.callback, d.errback)
+        return d
+
+    def echo(self, data, timeout = 10):
+        """
+        Send an echo command containing *data* to the remote SMB/CIFS server. The remote SMB/CIFS will reply with the same *data*.
+
+        :param bytes data: Data to send to the remote server. Must be a bytes object.
+        :param integer/float timeout: Number of seconds that pysmb will wait before raising *SMBTimeout* via the returned *Deferred* instance's *errback* method.
+        :return: A *twisted.internet.defer.Deferred* instance. The callback function will be called with the *data* parameter.
+        """
+        if not self.instance:
+            raise NotConnectedError('Not connected to server')
+
+        d = defer.Deferred()
+        self.instance._echo(data, d.callback, d.errback, timeout)
+        return d
+
+    def closeConnection(self):
+        """
+        Disconnect from the remote SMB/CIFS server. The TCP connection will be closed at the earliest opportunity after this method returns.
+
+        :return: None
+        """
+        if not self.instance:
+            raise NotConnectedError('Not connected to server')
+
+        self.instance.transport.loseConnection()
+
+    #
+    # ClientFactory methods
+    # (Do not touch these unless you know what you are doing)
+    #
+
+    def buildProtocol(self, addr):
+        p = self.protocol(self.username, self.password, self.my_name, self.remote_name, self.domain, self.use_ntlm_v2, self.sign_options, self.is_direct_tcp)
+        p.factory = self
+        return p
diff --git a/python2/smb/__init__.py b/python2/smb/__init__.py
new file mode 100644
index 00000000..8b137891
--- /dev/null
+++ b/python2/smb/__init__.py
@@ -0,0 +1 @@
+
diff --git a/python2/smb/base.py b/python2/smb/base.py
new file mode 100644
index 00000000..d2346aaf
--- /dev/null
+++ b/python2/smb/base.py
@@ -0,0 +1,2941 @@
+
+import logging, binascii, time, hmac
+from datetime import datetime
+from smb_constants import *
+from smb2_constants import *
+from smb_structs import *
+from smb2_structs import *
+from .security_descriptors import SecurityDescriptor
+from nmb.base import NMBSession
+from utils import convertFILETIMEtoEpoch
+import ntlm, securityblob
+
+try:
+    import hashlib
+    sha256 = hashlib.sha256
+except ImportError:
+    from utils import sha256
+
+
+class NotReadyError(Exception):
+    """Raised when SMB connection is not ready (i.e. not authenticated or authentication failed)"""
+    pass
+
+class NotConnectedError(Exception):
+    """Raised when underlying SMB connection has been disconnected or not connected yet"""
+    pass
+
+class SMBTimeout(Exception):
+    """Raised when a timeout has occurred while waiting for a response or for a SMB/CIFS operation to complete."""
+    pass
+
+
+def _convert_to_unicode(string):
+    if not isinstance(string, unicode):
+        string = unicode(string, "utf-8")
+    return string
+
+
+class SMB(NMBSession):
+    """
+    This class represents a "connection" to the remote SMB/CIFS server.
+    It is not meant to be used directly in an application as it does not have any network transport implementations.
+
+    For application use, please refer to
+      - L{SMBProtocol.SMBProtocolFactory<smb.SMBProtocol>} if you are using Twisted framework
+
+    In [MS-CIFS], this class will contain attributes of Client, Client.Connection and Client.Session abstract data models.
+
+    References:
+    ===========
+      - [MS-CIFS]: 3.2.1
+    """
+
+    log = logging.getLogger('SMB.SMB')
+
+    SIGN_NEVER = 0
+    SIGN_WHEN_SUPPORTED = 1
+    SIGN_WHEN_REQUIRED = 2
+
+    def __init__(self, username, password, my_name, remote_name, domain = '', use_ntlm_v2 = True, sign_options = SIGN_WHEN_REQUIRED, is_direct_tcp = False):
+        NMBSession.__init__(self, my_name, remote_name, is_direct_tcp = is_direct_tcp)
+        self.username = _convert_to_unicode(username)
+        self.password = _convert_to_unicode(password)
+        self.domain = _convert_to_unicode(domain)
+        self.sign_options = sign_options
+        self.is_direct_tcp = is_direct_tcp
+        self.use_ntlm_v2 = use_ntlm_v2 #: Similar to LMAuthenticationPolicy and NTAuthenticationPolicy as described in [MS-CIFS] 3.2.1.1
+        self.smb_message = SMBMessage(self)
+        self.is_using_smb2 = False   #: Are we communicating using SMB2 protocol? self.smb_message will be a SMB2Message instance if this flag is True
+        self.async_requests = { }    #: AsyncID mapped to _PendingRequest instance
+        self.pending_requests = { }  #: MID mapped to _PendingRequest instance
+        self.connected_trees = { }   #: Share name mapped to TID
+        self.next_rpc_call_id = 1    #: Next RPC callID value. Not used directly in SMB message. Usually encapsulated in sub-commands under SMB_COM_TRANSACTION or SMB_COM_TRANSACTION2 messages
+
+        self.has_negotiated = False
+        self.has_authenticated = False
+        self.is_signing_active = False           #: True if the remote server accepts message signing. All outgoing messages will be signed. Simiar to IsSigningActive as described in [MS-CIFS] 3.2.1.2
+        self.signing_session_key = None          #: Session key for signing packets, if signing is active. Similar to SigningSessionKey as described in [MS-CIFS] 3.2.1.2
+        self.signing_challenge_response = None   #: Contains the challenge response for signing, if signing is active. Similar to SigningChallengeResponse as described in [MS-CIFS] 3.2.1.2
+        self.mid = 0
+        self.uid = 0
+        self.next_signing_id = 2     #: Similar to ClientNextSendSequenceNumber as described in [MS-CIFS] 3.2.1.2
+
+        # SMB1 and SMB2 attributes
+        # Note that the interpretations of the values may differ between SMB1 and SMB2 protocols
+        self.capabilities = 0
+        self.security_mode = 0     #: Initialized from the SecurityMode field of the SMB_COM_NEGOTIATE message
+
+        # SMB1 attributes
+        # Most of the following attributes will be initialized upon receipt of SMB_COM_NEGOTIATE message from server (via self._updateServerInfo_SMB1 method)
+        self.use_plaintext_authentication = False  #: Similar to PlaintextAuthenticationPolicy in in [MS-CIFS] 3.2.1.1
+        self.max_raw_size = 0
+        self.max_buffer_size = 0   #: Similar to MaxBufferSize as described in [MS-CIFS] 3.2.1.1
+        self.max_mpx_count = 0     #: Similar to MaxMpxCount as described in [MS-CIFS] 3.2.1.1
+
+        # SMB2 attributes
+        self.max_read_size = 0      #: Similar to MaxReadSize as described in [MS-SMB2] 2.2.4
+        self.max_write_size = 0     #: Similar to MaxWriteSize as described in [MS-SMB2] 2.2.4
+        self.max_transact_size = 0  #: Similar to MaxTransactSize as described in [MS-SMB2] 2.2.4
+        self.session_id = 0         #: Similar to SessionID as described in [MS-SMB2] 2.2.4. This will be set in _updateState_SMB2 method
+        self.smb2_dialect = 0
+
+
+        # SMB 2.1 attributes
+        self.cap_leasing = False
+        self.cap_multi_credit = False
+        self.credits = 0   # how many credits we're allowed to spend per request
+
+        self._setupSMB1Methods()
+
+        self.log.info('Authentication with remote machine "%s" for user "%s" will be using NTLM %s authentication (%s extended security)',
+                      self.remote_name, self.username,
+                      (self.use_ntlm_v2 and 'v2') or 'v1',
+                      (SUPPORT_EXTENDED_SECURITY and 'with') or 'without')
+
+
+    #
+    # NMBSession Methods
+    #
+
+    def onNMBSessionOK(self):
+        self._sendSMBMessage(SMBMessage(self, ComNegotiateRequest()))
+
+    def onNMBSessionFailed(self):
+        pass
+
+    def onNMBSessionMessage(self, flags, data):
+        while True:
+            try:
+                i = self.smb_message.decode(data)
+            except SMB2ProtocolHeaderError:
+                self.log.info('Now switching over to SMB2 protocol communication')
+                self.is_using_smb2 = True
+                self.mid = 0  # Must reset messageID counter, or else remote SMB2 server will disconnect
+                self._setupSMB2Methods()
+                self.smb_message = self._klassSMBMessage(self)
+                i = self.smb_message.decode(data)
+                self.log.info('SMB2 dialect is 0x%04x', self.smb2_dialect)
+
+            next_message_offset = 0
+            if self.is_using_smb2:
+                next_message_offset = self.smb_message.next_command_offset
+
+                # update how many credits we're allowed to spend on requests
+                self.credits = self.smb_message.credit_response
+
+                # SMB2 CANCEL commands do not consume message IDs
+                if self.smb_message.command != SMB2_COM_CANCEL:
+                    self.log.debug('Received SMB2 packet from server - "%s" (command:0x%02X). Credit charge recv: %s',
+                                   SMB_COMMAND_NAMES.get(self.smb_message.command, '<unknown>'), self.smb_message.command, self.smb_message.credit_charge)
+                    if self.smb_message.credit_charge > 0:
+                        # Let's update the sequenceWindow based on the CreditsCharged
+                        # In the SMB 2.0.2 dialect, this field MUST NOT be used and MUST be reserved.
+                        # The sender MUST set this to 0, and the receiver MUST ignore it.
+                        # In all other dialects, this field indicates the number of credits that this request consumes.
+                        self.log.debug("Updating MID to add credit charge from server...")
+                        self.log.debug("*** Before: " + str(self.mid))
+                        self.mid = self.mid + (self.smb_message.credit_charge - 1)
+                        self.log.debug("*** After: " + str(self.mid))
+
+            if i > 0:
+                if not self.is_using_smb2:
+                    self.log.debug('Received SMB message "%s" (command:0x%2X flags:0x%02X flags2:0x%04X TID:%d UID:%d)',
+                                   SMB_COMMAND_NAMES.get(self.smb_message.command, '<unknown>'),
+                                   self.smb_message.command, self.smb_message.flags, self.smb_message.flags2, self.smb_message.tid, self.smb_message.uid)
+                else:
+                    self.log.debug('Received SMB2 message "%s" (command:0x%04X flags:0x%04x)',
+                                   SMB2_COMMAND_NAMES.get(self.smb_message.command, '<unknown>'),
+                                   self.smb_message.command, self.smb_message.flags)
+                if self._updateState(self.smb_message):
+                    # We need to create a new instance instead of calling reset() because the instance could be captured in the message history.
+                    self.smb_message = self._klassSMBMessage(self)
+
+            if next_message_offset > 0:
+                data = data[next_message_offset:]
+            else:
+                break
+
+    #
+    # Public Methods for Overriding in Subclasses
+    #
+
+    def onAuthOK(self):
+        pass
+
+    def onAuthFailed(self):
+        pass
+
+    #
+    # Protected Methods
+    #
+
+    def _setupSMB1Methods(self):
+        self._klassSMBMessage = SMBMessage
+        self._updateState = self._updateState_SMB1
+        self._updateServerInfo = self._updateServerInfo_SMB1
+        self._handleNegotiateResponse = self._handleNegotiateResponse_SMB1
+        self._sendSMBMessage = self._sendSMBMessage_SMB1
+        self._handleSessionChallenge = self._handleSessionChallenge_SMB1
+        self._listShares = self._listShares_SMB1
+        self._listPath = self._listPath_SMB1
+        self._listSnapshots = self._listSnapshots_SMB1
+        self._getSecurity = self._getSecurity_SMB1
+        self._getAttributes = self._getAttributes_SMB1
+        self._retrieveFile = self._retrieveFile_SMB1
+        self._retrieveFileFromOffset = self._retrieveFileFromOffset_SMB1
+        self._storeFile = self._storeFile_SMB1
+        self._storeFileFromOffset = self._storeFileFromOffset_SMB1
+        self._deleteFiles = self._deleteFiles_SMB1
+        self._resetFileAttributes = self._resetFileAttributes_SMB1
+        self._createDirectory = self._createDirectory_SMB1
+        self._deleteDirectory = self._deleteDirectory_SMB1
+        self._rename = self._rename_SMB1
+        self._echo = self._echo_SMB1
+
+    def _setupSMB2Methods(self):
+        self._klassSMBMessage = SMB2Message
+        self._updateState = self._updateState_SMB2
+        self._updateServerInfo = self._updateServerInfo_SMB2
+        self._handleNegotiateResponse = self._handleNegotiateResponse_SMB2
+        self._sendSMBMessage = self._sendSMBMessage_SMB2
+        self._handleSessionChallenge = self._handleSessionChallenge_SMB2
+        self._listShares = self._listShares_SMB2
+        self._listPath = self._listPath_SMB2
+        self._listSnapshots = self._listSnapshots_SMB2
+        self._getAttributes = self._getAttributes_SMB2
+        self._getSecurity = self._getSecurity_SMB2
+        self._retrieveFile = self._retrieveFile_SMB2
+        self._retrieveFileFromOffset = self._retrieveFileFromOffset_SMB2
+        self._storeFile = self._storeFile_SMB2
+        self._storeFileFromOffset = self._storeFileFromOffset_SMB2
+        self._deleteFiles = self._deleteFiles_SMB2
+        self._resetFileAttributes = self._resetFileAttributes_SMB2
+        self._createDirectory = self._createDirectory_SMB2
+        self._deleteDirectory = self._deleteDirectory_SMB2
+        self._rename = self._rename_SMB2
+        self._echo = self._echo_SMB2
+
+    def _getNextRPCCallID(self):
+        self.next_rpc_call_id += 1
+        return self.next_rpc_call_id
+
+    #
+    # SMB2 Methods Family
+    #
+
+    def _sendSMBMessage_SMB2(self, smb_message):
+        if smb_message.mid == 0:
+            smb_message.mid = self._getNextMID_SMB2()
+
+        if smb_message.command != SMB2_COM_NEGOTIATE:
+            smb_message.session_id = self.session_id
+
+        if self.is_signing_active:
+            smb_message.flags |= SMB2_FLAGS_SIGNED
+            raw_data = smb_message.encode()
+            smb_message.signature = hmac.new(self.signing_session_key, raw_data, sha256).digest()[:16]
+
+            smb_message.raw_data = smb_message.encode()
+            self.log.debug('MID is %d. Signature is %s. Total raw message is %d bytes', smb_message.mid, binascii.hexlify(smb_message.signature), len(smb_message.raw_data))
+        else:
+            smb_message.raw_data = smb_message.encode()
+        self.sendNMBMessage(smb_message.raw_data)
+
+    def _getNextMID_SMB2(self):
+        self.mid += 1
+        return self.mid
+
+    def _updateState_SMB2(self, message):
+        if message.isReply:
+            if message.command == SMB2_COM_NEGOTIATE:
+                if message.status == 0:
+
+                    if self.smb_message.payload.dialect_revision == SMB2_DIALECT_2ALL:
+                        # Dialects from SMB 2.1 must be negotiated in a second negotiate phase
+                        # We send a SMB2 Negotiate Request to accomplish this
+                        self._sendSMBMessage(SMB2Message(self, SMB2NegotiateRequest()))
+                    else:
+                        if self.smb_message.payload.dialect_revision == SMB2_DIALECT_21:
+                            # We negotiated SMB 2.1.
+                            # we must now send credit requests (MUST!)
+                            #self.send_credits_request = True
+                            pass
+
+                        self.has_negotiated = True
+                        self.log.info('SMB2 dialect negotiation successful')
+                        self.dialect = self.smb_message.payload.dialect_revision
+                        self._updateServerInfo(message.payload)
+                        self._handleNegotiateResponse(message)
+                else:
+                    raise ProtocolError('Unknown status value (0x%08X) in SMB2_COM_NEGOTIATE' % message.status,
+                                        message.raw_data, message)
+            elif message.command == SMB2_COM_SESSION_SETUP:
+                if message.status == 0:
+                    self.session_id = message.session_id
+                    try:
+                        result = securityblob.decodeAuthResponseSecurityBlob(message.payload.security_blob)
+                        if result == securityblob.RESULT_ACCEPT_COMPLETED:
+                            self.has_authenticated = True
+                            self.log.info('Authentication (on SMB2) successful!')
+
+                            # [MS-SMB2]: 3.2.5.3.1
+                            # If the security subsystem indicates that the session was established by an anonymous user,
+                            # Session.SigningRequired MUST be set to FALSE.
+                            # If the SMB2_SESSION_FLAG_IS_GUEST bit is set in the SessionFlags field of the
+                            # SMB2 SESSION_SETUP Response and if Session.SigningRequired is TRUE, this indicates a SESSION_SETUP
+                            # failure and the connection MUST be terminated. If the SMB2_SESSION_FLAG_IS_GUEST bit is set in the SessionFlags
+                            # field of the SMB2 SESSION_SETUP Response and if RequireMessageSigning is FALSE, Session.SigningRequired
+                            # MUST be set to FALSE.
+                            if message.payload.isGuestSession or message.payload.isAnonymousSession:
+                                self.is_signing_active = False
+                                self.log.info('Signing disabled because session is guest/anonymous')
+
+                            self.onAuthOK()
+                        else:
+                            raise ProtocolError('SMB2_COM_SESSION_SETUP status is 0 but security blob negResult value is %d' % result, message.raw_data, message)
+                    except securityblob.BadSecurityBlobError, ex:
+                        raise ProtocolError(str(ex), message.raw_data, message)
+                elif message.status == 0xc0000016:  # STATUS_MORE_PROCESSING_REQUIRED
+                    self.session_id = message.session_id
+                    try:
+                        result, ntlm_token = securityblob.decodeChallengeSecurityBlob(message.payload.security_blob)
+                        if result == securityblob.RESULT_ACCEPT_INCOMPLETE:
+                            self._handleSessionChallenge(message, ntlm_token)
+                    except ( securityblob.BadSecurityBlobError, securityblob.UnsupportedSecurityProvider ), ex:
+                        raise ProtocolError(str(ex), message.raw_data, message)
+                elif (message.status == 0xc000006d   # STATUS_LOGON_FAILURE
+                    or message.status == 0xc0000064  # STATUS_NO_SUCH_USER
+                    or message.status == 0xc000006a):# STATUS_WRONG_PASSWORD
+                    self.has_authenticated = False
+                    self.log.info('Authentication (on SMB2) failed. Please check username and password.')
+                    self.onAuthFailed()
+                elif (message.status == 0xc0000193    # STATUS_ACCOUNT_EXPIRED
+                    or message.status == 0xC0000071): # STATUS_PASSWORD_EXPIRED
+                    self.has_authenticated = False
+                    self.log.info('Authentication (on SMB2) failed. Account or password has expired.')
+                    self.onAuthFailed()
+                elif message.status == 0xc0000234: # STATUS_ACCOUNT_LOCKED_OUT
+                    self.has_authenticated = False
+                    self.log.info('Authentication (on SMB2) failed. Account has been locked due to too many invalid logon attempts.')
+                    self.onAuthFailed()
+                elif message.status == 0xc0000072: # STATUS_ACCOUNT_DISABLED
+                    self.has_authenticated = False
+                    self.log.info('Authentication (on SMB2) failed. Account has been disabled.')
+                    self.onAuthFailed()
+                elif (message.status == 0xc000006f    # STATUS_INVALID_LOGON_HOURS
+                    or message.status == 0xc000015b   # STATUS_LOGON_TYPE_NOT_GRANTED
+                    or message.status == 0xc0000070): # STATUS_INVALID_WORKSTATION
+                    self.has_authenticated = False
+                    self.log.info('Authentication (on SMB2) failed. Not allowed.')
+                    self.onAuthFailed()
+                elif message.status == 0xc000018c:  # STATUS_TRUSTED_DOMAIN_FAILURE
+                    self.has_authenticated = False
+                    self.log.info('Authentication (on SMB2) failed. Domain not trusted.')
+                    self.onAuthFailed()
+                elif message.status == 0xc000018d:  # STATUS_TRUSTED_RELATIONSHIP_FAILURE
+                    self.has_authenticated = False
+                    self.log.info('Authentication (on SMB2) failed. Workstation not trusted.')
+                    self.onAuthFailed()
+                else:
+                    raise ProtocolError('Unknown status value (0x%08X) in SMB_COM_SESSION_SETUP_ANDX (with extended security)' % message.status,
+                                        message.raw_data, message)
+
+            if message.isAsync:
+                if message.status == 0x00000103:  # STATUS_PENDING
+                    req = self.pending_requests.pop(message.mid, None)
+                    if req:
+                        self.async_requests[message.async_id] = req
+                else: # All other status including SUCCESS
+                    req = self.async_requests.pop(message.async_id, None)
+                    if req:
+                        req.callback(message, **req.kwargs)
+                        return True
+            else:
+                req = self.pending_requests.pop(message.mid, None)
+                if req:
+                    req.callback(message, **req.kwargs)
+                    return True
+
+
+    def _updateServerInfo_SMB2(self, payload):
+        self.capabilities = payload.capabilities
+        self.security_mode = payload.security_mode
+        self.max_transact_size = payload.max_transact_size
+        self.max_read_size = payload.max_read_size
+        self.max_write_size = payload.max_write_size
+        self.use_plaintext_authentication = False   # SMB2 never allows plaintext authentication
+
+        if (self.capabilities & SMB2_GLOBAL_CAP_LEASING) == SMB2_GLOBAL_CAP_LEASING:
+            self.cap_leasing = True
+
+        if (self.capabilities & SMB2_GLOBAL_CAP_LARGE_MTU) == SMB2_GLOBAL_CAP_LARGE_MTU:
+            self.cap_multi_credit = True
+
+
+    def _handleNegotiateResponse_SMB2(self, message):
+        ntlm_data = ntlm.generateNegotiateMessage()
+        blob = securityblob.generateNegotiateSecurityBlob(ntlm_data)
+        self._sendSMBMessage(SMB2Message(self, SMB2SessionSetupRequest(blob)))
+
+
+    def _handleSessionChallenge_SMB2(self, message, ntlm_token):
+        server_challenge, server_flags, server_info = ntlm.decodeChallengeMessage(ntlm_token)
+
+        self.log.info('Performing NTLMv2 authentication (on SMB2) with server challenge "%s"', binascii.hexlify(server_challenge))
+
+        if self.use_ntlm_v2:
+            self.log.info('Performing NTLMv2 authentication (on SMB2) with server challenge "%s"', binascii.hexlify(server_challenge))
+            nt_challenge_response, lm_challenge_response, session_key = ntlm.generateChallengeResponseV2(self.password,
+                                                                                                         self.username,
+                                                                                                         server_challenge,
+                                                                                                         server_info,
+                                                                                                         self.domain)
+
+        else:
+            self.log.info('Performing NTLMv1 authentication (on SMB2) with server challenge "%s"', binascii.hexlify(server_challenge))
+            nt_challenge_response, lm_challenge_response, session_key = ntlm.generateChallengeResponseV1(self.password, server_challenge, True)
+
+        ntlm_data = ntlm.generateAuthenticateMessage(server_flags,
+                                                     nt_challenge_response,
+                                                     lm_challenge_response,
+                                                     session_key,
+                                                     self.username,
+                                                     self.domain,
+                                                     self.my_name)
+
+        if self.log.isEnabledFor(logging.DEBUG):
+            self.log.debug('NT challenge response is "%s" (%d bytes)', binascii.hexlify(nt_challenge_response), len(nt_challenge_response))
+            self.log.debug('LM challenge response is "%s" (%d bytes)', binascii.hexlify(lm_challenge_response), len(lm_challenge_response))
+
+        blob = securityblob.generateAuthSecurityBlob(ntlm_data)
+        self._sendSMBMessage(SMB2Message(self, SMB2SessionSetupRequest(blob)))
+
+        if self.security_mode & SMB2_NEGOTIATE_SIGNING_REQUIRED:
+            self.log.info('Server requires all SMB messages to be signed')
+            self.is_signing_active = (self.sign_options != SMB.SIGN_NEVER)
+        elif self.security_mode & SMB2_NEGOTIATE_SIGNING_ENABLED:
+            self.log.info('Server supports SMB signing')
+            self.is_signing_active = (self.sign_options == SMB.SIGN_WHEN_SUPPORTED)
+        else:
+            self.is_signing_active = False
+
+        if self.is_signing_active:
+            self.log.info("SMB signing activated. All SMB messages will be signed.")
+            self.signing_session_key = (session_key + '\0'*16)[:16]
+            if self.capabilities & CAP_EXTENDED_SECURITY:
+                self.signing_challenge_response = None
+            else:
+                self.signing_challenge_response = blob
+        else:
+            self.log.info("SMB signing deactivated. SMB messages will NOT be signed.")
+
+
+    def _listShares_SMB2(self, callback, errback, timeout = 30):
+        if not self.has_authenticated:
+            raise NotReadyError('SMB connection not authenticated')
+
+        expiry_time = time.time() + timeout
+        path = 'IPC$'
+        messages_history = [ ]
+
+        def connectSrvSvc(tid):
+            m = SMB2Message(self, SMB2CreateRequest('srvsvc',
+                                              file_attributes = 0,
+                                              access_mask = FILE_READ_DATA | FILE_WRITE_DATA | FILE_APPEND_DATA | FILE_READ_EA | FILE_WRITE_EA | READ_CONTROL | FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES | SYNCHRONIZE,
+                                              share_access = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
+                                              oplock = SMB2_OPLOCK_LEVEL_NONE,
+                                              impersonation = SEC_IMPERSONATE,
+                                              create_options = FILE_NON_DIRECTORY_FILE | FILE_OPEN_NO_RECALL,
+                                              create_disp = FILE_OPEN))
+
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectSrvSvcCB, errback, tid = tid)
+            messages_history.append(m)
+
+        def connectSrvSvcCB(create_message, **kwargs):
+            messages_history.append(create_message)
+            if create_message.status == 0:
+                call_id = self._getNextRPCCallID()
+                # The data_bytes are binding call to Server Service RPC using DCE v1.1 RPC over SMB. See [MS-SRVS] and [C706]
+                # If you wish to understand the meanings of the byte stream, I would suggest you use a recent version of WireShark to packet capture the stream
+                data_bytes = \
+                    binascii.unhexlify("""05 00 0b 03 10 00 00 00 74 00 00 00""".replace(' ', '')) + \
+                    struct.pack('<I', call_id) + \
+                    binascii.unhexlify("""
+b8 10 b8 10 00 00 00 00 02 00 00 00 00 00 01 00
+c8 4f 32 4b 70 16 d3 01 12 78 5a 47 bf 6e e1 88
+03 00 00 00 04 5d 88 8a eb 1c c9 11 9f e8 08 00
+2b 10 48 60 02 00 00 00 01 00 01 00 c8 4f 32 4b
+70 16 d3 01 12 78 5a 47 bf 6e e1 88 03 00 00 00
+2c 1c b7 6c 12 98 40 45 03 00 00 00 00 00 00 00
+01 00 00 00
+""".replace(' ', '').replace('\n', ''))
+                m = SMB2Message(self, SMB2WriteRequest(create_message.payload.fid, data_bytes, 0))
+                m.tid = kwargs['tid']
+                self._sendSMBMessage(m)
+                self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, rpcBindCB, errback, tid = kwargs['tid'], fid = create_message.payload.fid)
+                messages_history.append(m)
+            else:
+                errback(OperationFailure('Failed to list shares: Unable to locate Server Service RPC endpoint', messages_history))
+
+        def rpcBindCB(trans_message, **kwargs):
+            messages_history.append(trans_message)
+            if trans_message.status == 0:
+                m = SMB2Message(self, SMB2ReadRequest(kwargs['fid'], read_len = 1024, read_offset = 0))
+                m.tid = kwargs['tid']
+                self._sendSMBMessage(m)
+                self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, rpcReadCB, errback, tid = kwargs['tid'], fid = kwargs['fid'])
+                messages_history.append(m)
+            else:
+                closeFid(kwargs['tid'], kwargs['fid'], error = 'Failed to list shares: Unable to read from Server Service RPC endpoint')
+
+        def rpcReadCB(read_message, **kwargs):
+            messages_history.append(read_message)
+            if read_message.status == 0:
+                call_id = self._getNextRPCCallID()
+
+                padding = ''
+                remote_name = '\\\\' + self.remote_name
+                server_len = len(remote_name) + 1
+                server_bytes_len = server_len * 2
+                if server_len % 2 != 0:
+                    padding = '\0\0'
+                    server_bytes_len += 2
+
+                # The data bytes are the RPC call to NetrShareEnum (Opnum 15) at Server Service RPC.
+                # If you wish to understand the meanings of the byte stream, I would suggest you use a recent version of WireShark to packet capture the stream
+                data_bytes = \
+                    binascii.unhexlify("""05 00 00 03 10 00 00 00""".replace(' ', '')) + \
+                    struct.pack('<HHI', 72+server_bytes_len, 0, call_id) + \
+                    binascii.unhexlify("""4c 00 00 00 00 00 0f 00 00 00 02 00""".replace(' ', '')) + \
+                    struct.pack('<III', server_len, 0, server_len) + \
+                    (remote_name + '\0').encode('UTF-16LE') + padding + \
+                    binascii.unhexlify("""
+01 00 00 00 01 00 00 00 04 00 02 00 00 00 00 00
+00 00 00 00 ff ff ff ff 08 00 02 00 00 00 00 00
+""".replace(' ', '').replace('\n', ''))
+                m = SMB2Message(self, SMB2IoctlRequest(kwargs['fid'], 0x0011C017, flags = 0x01, max_out_size = 8196, in_data = data_bytes))
+                m.tid = kwargs['tid']
+                self._sendSMBMessage(m)
+                self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, listShareResultsCB, errback, tid = kwargs['tid'], fid = kwargs['fid'])
+                messages_history.append(m)
+            else:
+                closeFid(kwargs['tid'], kwargs['fid'], error = 'Failed to list shares: Unable to bind to Server Service RPC endpoint')
+
+        def listShareResultsCB(result_message, **kwargs):
+            messages_history.append(result_message)
+            if result_message.status == 0:
+                # The payload.data_bytes will contain the results of the RPC call to NetrShareEnum (Opnum 15) at Server Service RPC.
+                data_bytes = result_message.payload.out_data
+
+                if ord(data_bytes[3]) & 0x02 == 0:
+                    sendReadRequest(kwargs['tid'], kwargs['fid'], data_bytes)
+                else:
+                    decodeResults(kwargs['tid'], kwargs['fid'], data_bytes)
+            else:
+                closeFid(kwargs['tid'], kwargs['fid'])
+                errback(OperationFailure('Failed to list shares: Unable to retrieve shared device list', messages_history))
+
+        def decodeResults(tid, fid, data_bytes):
+            shares_count = struct.unpack('<I', data_bytes[36:40])[0]
+            results = [ ]     # A list of SharedDevice instances
+            offset = 36 + 12  # You need to study the byte stream to understand the meaning of these constants
+            for i in range(0, shares_count):
+                results.append(SharedDevice(struct.unpack('<I', data_bytes[offset+4:offset+8])[0], None, None))
+                offset += 12
+
+            for i in range(0, shares_count):
+                max_length, _, length = struct.unpack('<III', data_bytes[offset:offset+12])
+                offset += 12
+                results[i].name = unicode(data_bytes[offset:offset+length*2-2], 'UTF-16LE')
+
+                if length % 2 != 0:
+                    offset += (length * 2 + 2)
+                else:
+                    offset += (length * 2)
+
+                max_length, _, length = struct.unpack('<III', data_bytes[offset:offset+12])
+                offset += 12
+                results[i].comments = unicode(data_bytes[offset:offset+length*2-2], 'UTF-16LE')
+
+                if length % 2 != 0:
+                    offset += (length * 2 + 2)
+                else:
+                    offset += (length * 2)
+
+            closeFid(tid, fid)
+            callback(results)
+
+        def sendReadRequest(tid, fid, data_bytes):
+            read_count = min(4280, self.max_read_size)
+            m = SMB2Message(self, SMB2ReadRequest(fid, 0, read_count))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, readCB, errback,
+                                                           tid = tid, fid = fid, data_bytes = data_bytes)
+
+        def readCB(read_message, **kwargs):
+            messages_history.append(read_message)
+            if read_message.status == 0:
+                data_bytes = read_message.payload.data
+
+                if ord(data_bytes[3]) & 0x02 == 0:
+                    sendReadRequest(kwargs['tid'], kwargs['fid'], kwargs['data_bytes'] + data_bytes[24:])
+                else:
+                    decodeResults(kwargs['tid'], kwargs['fid'], kwargs['data_bytes'] + data_bytes[24:])
+            else:
+                closeFid(kwargs['tid'], kwargs['fid'])
+                errback(OperationFailure('Failed to list shares: Unable to retrieve shared device list', messages_history))
+
+        def closeFid(tid, fid, results = None, error = None):
+            m = SMB2Message(self, SMB2CloseRequest(fid))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, closeCB, errback, results = results, error = error)
+            messages_history.append(m)
+
+        def closeCB(close_message, **kwargs):
+            if kwargs['results'] is not None:
+                callback(kwargs['results'])
+            elif kwargs['error'] is not None:
+                errback(OperationFailure(kwargs['error'], messages_history))
+
+        if not self.connected_trees.has_key(path):
+            def connectCB(connect_message, **kwargs):
+                messages_history.append(connect_message)
+                if connect_message.status == 0:
+                    self.connected_trees[path] = connect_message.tid
+                    connectSrvSvc(connect_message.tid)
+                else:
+                    errback(OperationFailure('Failed to list shares: Unable to connect to IPC$', messages_history))
+
+            m = SMB2Message(self, SMB2TreeConnectRequest(r'\\%s\%s' % ( self.remote_name.upper(), path )))
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectCB, errback, path = path)
+            messages_history.append(m)
+        else:
+            connectSrvSvc(self.connected_trees[path])
+
+    def _listPath_SMB2(self, service_name, path, callback, errback, search, pattern, timeout = 30):
+        if not self.has_authenticated:
+            raise NotReadyError('SMB connection not authenticated')
+
+        expiry_time = time.time() + timeout
+        path = path.replace('/', '\\')
+        if path.startswith('\\'):
+            path = path[1:]
+        if path.endswith('\\'):
+            path = path[:-1]
+        messages_history = [ ]
+        results = [ ]
+
+        def sendCreate(tid):
+            create_context_data = binascii.unhexlify("""
+28 00 00 00 10 00 04 00 00 00 18 00 10 00 00 00
+44 48 6e 51 00 00 00 00 00 00 00 00 00 00 00 00
+00 00 00 00 00 00 00 00 18 00 00 00 10 00 04 00
+00 00 18 00 00 00 00 00 4d 78 41 63 00 00 00 00
+00 00 00 00 10 00 04 00 00 00 18 00 00 00 00 00
+51 46 69 64 00 00 00 00
+""".replace(' ', '').replace('\n', ''))
+            m = SMB2Message(self, SMB2CreateRequest(path,
+                                              file_attributes = 0,
+                                              access_mask = FILE_READ_DATA | FILE_READ_EA | FILE_READ_ATTRIBUTES | SYNCHRONIZE,
+                                              share_access = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
+                                              oplock = SMB2_OPLOCK_LEVEL_NONE,
+                                              impersonation = SEC_IMPERSONATE,
+                                              create_options = FILE_DIRECTORY_FILE,
+                                              create_disp = FILE_OPEN,
+                                              create_context_data = create_context_data))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, createCB, errback, tid = tid)
+            messages_history.append(m)
+
+        def createCB(create_message, **kwargs):
+            messages_history.append(create_message)
+            if create_message.status == 0:
+                sendQuery(kwargs['tid'], create_message.payload.fid, '')
+            else:
+                errback(OperationFailure('Failed to list %s on %s: Unable to open directory' % ( path, service_name ), messages_history))
+
+        def sendQuery(tid, fid, data_buf):
+            if self.smb2_dialect != SMB2_DIALECT_2 and self.cap_multi_credit:
+                output_buf_len = 64 * 1024 * (self.credits - 1)
+            else:
+                output_buf_len = self.max_transact_size
+
+            m = SMB2Message(self, SMB2QueryDirectoryRequest(fid, pattern,
+                                                      info_class = 0x25,   # FileIdBothDirectoryInformation
+                                                      flags = 0,
+                                                      output_buf_len = output_buf_len))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, queryCB, errback, tid = tid, fid = fid, data_buf = data_buf)
+            messages_history.append(m)
+
+        def queryCB(query_message, **kwargs):
+            messages_history.append(query_message)
+            if query_message.status == 0:
+                data_buf = decodeQueryStruct(kwargs['data_buf'] + query_message.payload.data)
+                sendQuery(kwargs['tid'], kwargs['fid'], data_buf)
+            elif query_message.status == 0x80000006L:  # STATUS_NO_MORE_FILES
+                closeFid(kwargs['tid'], kwargs['fid'], results = results)
+            else:
+                closeFid(kwargs['tid'], kwargs['fid'], error = query_message.status)
+
+        def decodeQueryStruct(data_bytes):
+            # FileIdBothDirectoryInformation structure. See [MS-SMB]: 2.2.8.1.3 and [MS-FSCC]: 2.4.17
+            info_format = '<IIQQQQQQIIIBB24sHQ'
+            info_size = struct.calcsize(info_format)
+
+            data_length = len(data_bytes)
+            offset = 0
+            while offset < data_length:
+                if offset + info_size > data_length:
+                    return data_bytes[offset:]
+
+                next_offset, _, \
+                create_time, last_access_time, last_write_time, last_attr_change_time, \
+                file_size, alloc_size, file_attributes, filename_length, ea_size, \
+                short_name_length, _, short_name, _, file_id = struct.unpack(info_format, data_bytes[offset:offset+info_size])
+
+                offset2 = offset + info_size
+                if offset2 + filename_length > data_length:
+                    return data_bytes[offset:]
+
+                filename = data_bytes[offset2:offset2+filename_length].decode('UTF-16LE')
+                short_name = short_name[:short_name_length].decode('UTF-16LE')
+
+                accept_result = False
+                if (file_attributes & 0xff) in ( 0x00, ATTR_NORMAL ): # Only the first 8-bits are compared. We ignore other bits like temp, compressed, encryption, sparse, indexed, etc
+                    accept_result = (search == SMB_FILE_ATTRIBUTE_NORMAL) or (search & SMB_FILE_ATTRIBUTE_INCL_NORMAL)
+                else:
+                    accept_result = (file_attributes & search) > 0
+                if accept_result:
+                    results.append(SharedFile(convertFILETIMEtoEpoch(create_time), convertFILETIMEtoEpoch(last_access_time),
+                                              convertFILETIMEtoEpoch(last_write_time), convertFILETIMEtoEpoch(last_attr_change_time),
+                                              file_size, alloc_size, file_attributes, short_name, filename, file_id))
+
+                if next_offset:
+                    offset += next_offset
+                else:
+                    break
+            return ''
+
+        def closeFid(tid, fid, results = None, error = None):
+            m = SMB2Message(self, SMB2CloseRequest(fid))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, closeCB, errback, results = results, error = error)
+            messages_history.append(m)
+
+        def closeCB(close_message, **kwargs):
+            if kwargs['results'] is not None:
+                callback(kwargs['results'])
+            elif kwargs['error'] is not None:
+                if kwargs['error'] == 0xC000000F:  # [MS-ERREF]: STATUS_NO_SUCH_FILE
+                    # Remote server returns STATUS_NO_SUCH_FILE error so we assume that the search returns no matching files
+                    callback([ ])
+                else:
+                    errback(OperationFailure('Failed to list %s on %s: Query failed with errorcode 0x%08x' % ( path, service_name, kwargs['error'] ), messages_history))
+
+        if not self.connected_trees.has_key(service_name):
+            def connectCB(connect_message, **kwargs):
+                messages_history.append(connect_message)
+                if connect_message.status == 0:
+                    self.connected_trees[service_name] = connect_message.tid
+                    sendCreate(connect_message.tid)
+                else:
+                    errback(OperationFailure('Failed to list %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history))
+
+            m = SMB2Message(self, SMB2TreeConnectRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name )))
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectCB, errback, path = service_name)
+            messages_history.append(m)
+        else:
+            sendCreate(self.connected_trees[service_name])
+
+    def _getAttributes_SMB2(self, service_name, path, callback, errback, timeout = 30):
+        if not self.has_authenticated:
+            raise NotReadyError('SMB connection not authenticated')
+
+        expiry_time = time.time() + timeout
+        path = path.replace('/', '\\')
+        if path.startswith('\\'):
+            path = path[1:]
+        if path.endswith('\\'):
+            path = path[:-1]
+        messages_history = [ ]
+
+        def sendCreate(tid):
+            create_context_data = binascii.unhexlify("""
+28 00 00 00 10 00 04 00 00 00 18 00 10 00 00 00
+44 48 6e 51 00 00 00 00 00 00 00 00 00 00 00 00
+00 00 00 00 00 00 00 00 18 00 00 00 10 00 04 00
+00 00 18 00 00 00 00 00 4d 78 41 63 00 00 00 00
+00 00 00 00 10 00 04 00 00 00 18 00 00 00 00 00
+51 46 69 64 00 00 00 00
+""".replace(' ', '').replace('\n', ''))
+            m = SMB2Message(self, SMB2CreateRequest(path,
+                                              file_attributes = 0,
+                                              access_mask = FILE_READ_DATA | FILE_READ_EA | FILE_READ_ATTRIBUTES | SYNCHRONIZE,
+                                              share_access = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
+                                              oplock = SMB2_OPLOCK_LEVEL_NONE,
+                                              impersonation = SEC_IMPERSONATE,
+                                              create_options = 0,
+                                              create_disp = FILE_OPEN,
+                                              create_context_data = create_context_data))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, createCB, errback, tid = tid)
+            messages_history.append(m)
+
+        def createCB(create_message, **kwargs):
+            messages_history.append(create_message)
+            if create_message.status == 0:
+                p = create_message.payload
+                filename = self._extractLastPathComponent(unicode(path))
+                info = SharedFile(p.create_time, p.lastaccess_time, p.lastwrite_time, p.change_time,
+                                  p.file_size, p.allocation_size, p.file_attributes,
+                                  filename, filename)
+                closeFid(kwargs['tid'], p.fid, info = info)
+            else:
+                errback(OperationFailure('Failed to get attributes for %s on %s: Unable to open remote file object' % ( path, service_name ), messages_history))
+
+        def closeFid(tid, fid, info = None, error = None):
+            m = SMB2Message(self, SMB2CloseRequest(fid))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, closeCB, errback, info = info, error = error)
+            messages_history.append(m)
+
+        def closeCB(close_message, **kwargs):
+            if kwargs['info'] is not None:
+                callback(kwargs['info'])
+            elif kwargs['error'] is not None:
+                errback(OperationFailure('Failed to get attributes for %s on %s: Query failed with errorcode 0x%08x' % ( path, service_name, kwargs['error'] ), messages_history))
+
+        if not self.connected_trees.has_key(service_name):
+            def connectCB(connect_message, **kwargs):
+                messages_history.append(connect_message)
+                if connect_message.status == 0:
+                    self.connected_trees[service_name] = connect_message.tid
+                    sendCreate(connect_message.tid)
+                else:
+                    errback(OperationFailure('Failed to get attributes for %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history))
+
+            m = SMB2Message(self, SMB2TreeConnectRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name )))
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectCB, errback, path = service_name)
+            messages_history.append(m)
+        else:
+            sendCreate(self.connected_trees[service_name])
+
+    def _getSecurity_SMB2(self, service_name, path, callback, errback, timeout = 30):
+        if not self.has_authenticated:
+            raise NotReadyError('SMB connection not authenticated')
+
+        expiry_time = time.time() + timeout
+        path = path.replace('/', '\\')
+        if path.startswith('\\'):
+            path = path[1:]
+        if path.endswith('\\'):
+            path = path[:-1]
+        messages_history = [ ]
+        results = [ ]
+
+        def sendCreate(tid):
+            m = SMB2Message(self, SMB2CreateRequest(path,
+                                              file_attributes = 0,
+                                              access_mask = FILE_READ_DATA | FILE_READ_EA | FILE_READ_ATTRIBUTES | READ_CONTROL | SYNCHRONIZE,
+                                              share_access = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
+                                              oplock = SMB2_OPLOCK_LEVEL_NONE,
+                                              impersonation = SEC_IMPERSONATE,
+                                              create_options = 0,
+                                              create_disp = FILE_OPEN))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, createCB, errback, tid = tid)
+            messages_history.append(m)
+
+        def createCB(create_message, **kwargs):
+            messages_history.append(create_message)
+            if create_message.status == 0:
+                if self.smb2_dialect != SMB2_DIALECT_2 and self.cap_multi_credit:
+                    output_buf_len = 64 * 1024 * (self.credits - 1)
+                else:
+                    output_buf_len = self.max_transact_size
+
+                m = SMB2Message(self, SMB2QueryInfoRequest(create_message.payload.fid,
+                                                     flags = 0,
+                                                     additional_info = OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION,
+                                                     info_type = SMB2_INFO_SECURITY,
+                                                     file_info_class = 0, # [MS-SMB2] 2.2.37, 3.2.4.12
+                                                     input_buf = '',
+                                                     output_buf_len = output_buf_len))
+                m.tid = kwargs['tid']
+                self._sendSMBMessage(m)
+                self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, queryCB, errback, tid = kwargs['tid'], fid = create_message.payload.fid)
+                messages_history.append(m)
+            else:
+                errback(OperationFailure('Failed to get the security descriptor of %s on %s: Unable to open file or directory' % ( path, service_name ), messages_history))
+
+        def queryCB(query_message, **kwargs):
+            messages_history.append(query_message)
+            if query_message.status == 0:
+                security = SecurityDescriptor.from_bytes(query_message.payload.data)
+                closeFid(kwargs['tid'], kwargs['fid'], result = security)
+            else:
+                closeFid(kwargs['tid'], kwargs['fid'], error = query_message.status)
+
+        def closeFid(tid, fid, result = None, error = None):
+            m = SMB2Message(self, SMB2CloseRequest(fid))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, closeCB, errback, result = result, error = error)
+            messages_history.append(m)
+
+        def closeCB(close_message, **kwargs):
+            if kwargs['result'] is not None:
+                callback(kwargs['result'])
+            elif kwargs['error'] is not None:
+                errback(OperationFailure('Failed to get the security descriptor of %s on %s: Query failed with errorcode 0x%08x' % ( path, service_name, kwargs['error'] ), messages_history))
+
+        if not self.connected_trees.has_key(service_name):
+            def connectCB(connect_message, **kwargs):
+                messages_history.append(connect_message)
+                if connect_message.status == 0:
+                    self.connected_trees[service_name] = connect_message.tid
+                    sendCreate(connect_message.tid)
+                else:
+                    errback(OperationFailure('Failed to get the security descriptor of %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history))
+
+            m = SMB2Message(self, SMB2TreeConnectRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name )))
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectCB, errback, path = service_name)
+            messages_history.append(m)
+        else:
+            sendCreate(self.connected_trees[service_name])
+
+    def _retrieveFile_SMB2(self, service_name, path, file_obj, callback, errback, timeout = 30):
+        return self._retrieveFileFromOffset(service_name, path, file_obj, callback, errback, 0L, -1L, timeout)
+
+    def _retrieveFileFromOffset_SMB2(self, service_name, path, file_obj, callback, errback, starting_offset, max_length, timeout = 30):
+        if not self.has_authenticated:
+            raise NotReadyError('SMB connection not authenticated')
+
+        expiry_time = time.time() + timeout
+        path = path.replace('/', '\\')
+        if path.startswith('\\'):
+            path = path[1:]
+        if path.endswith('\\'):
+            path = path[:-1]
+        messages_history = [ ]
+        results = [ ]
+
+        def sendCreate(tid):
+            create_context_data = binascii.unhexlify("""
+28 00 00 00 10 00 04 00 00 00 18 00 10 00 00 00
+44 48 6e 51 00 00 00 00 00 00 00 00 00 00 00 00
+00 00 00 00 00 00 00 00 18 00 00 00 10 00 04 00
+00 00 18 00 00 00 00 00 4d 78 41 63 00 00 00 00
+00 00 00 00 10 00 04 00 00 00 18 00 00 00 00 00
+51 46 69 64 00 00 00 00
+""".replace(' ', '').replace('\n', ''))
+            m = SMB2Message(self, SMB2CreateRequest(path,
+                                              file_attributes = 0,
+                                              access_mask = FILE_READ_DATA | FILE_READ_EA | FILE_READ_ATTRIBUTES | READ_CONTROL | SYNCHRONIZE,
+                                              share_access = FILE_SHARE_READ | FILE_SHARE_WRITE,
+                                              oplock = SMB2_OPLOCK_LEVEL_NONE,
+                                              impersonation = SEC_IMPERSONATE,
+                                              create_options = FILE_SEQUENTIAL_ONLY | FILE_NON_DIRECTORY_FILE,
+                                              create_disp = FILE_OPEN,
+                                              create_context_data = create_context_data))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, createCB, errback, tid = tid)
+            messages_history.append(m)
+
+        def createCB(create_message, **kwargs):
+            messages_history.append(create_message)
+            if create_message.status == 0:
+                m = SMB2Message(self, SMB2QueryInfoRequest(create_message.payload.fid,
+                                                     flags = 0,
+                                                     additional_info = 0,
+                                                     info_type = SMB2_INFO_FILE,
+                                                     file_info_class = 0x16,  # FileStreamInformation [MS-FSCC] 2.4
+                                                     input_buf = '',
+                                                     output_buf_len = 4096))
+                m.tid = kwargs['tid']
+                self._sendSMBMessage(m)
+                self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, infoCB, errback,
+                                                               tid = kwargs['tid'],
+                                                               fid = create_message.payload.fid,
+                                                               file_attributes = create_message.payload.file_attributes)
+                messages_history.append(m)
+            else:
+                errback(OperationFailure('Failed to retrieve %s on %s: Unable to open file' % ( path, service_name ), messages_history))
+
+        def infoCB(info_message, **kwargs):
+            messages_history.append(info_message)
+            if info_message.status == 0:
+                file_len = struct.unpack('<Q', info_message.payload.data[8:16])[0]
+                if max_length == 0 or starting_offset > file_len:
+                    closeFid(info_message.tid, kwargs['fid'])
+                    callback(( file_obj, kwargs['file_attributes'], 0 ))  # Note that this is a tuple of 3-elements
+                else:
+                    remaining_len = max_length
+                    if remaining_len < 0:
+                        remaining_len = file_len
+                    if starting_offset + remaining_len > file_len:
+                        remaining_len = file_len - starting_offset
+                    sendRead(kwargs['tid'], kwargs['fid'], starting_offset, remaining_len, 0, kwargs['file_attributes'])
+            else:
+                errback(OperationFailure('Failed to retrieve %s on %s: Unable to retrieve information on file' % ( path, service_name ), messages_history))
+
+        def sendRead(tid, fid, offset, remaining_len, read_len, file_attributes):
+            read_count = min(self.max_read_size, remaining_len)
+
+            if self.smb2_dialect != SMB2_DIALECT_2 and self.cap_multi_credit:
+                max_read_count = 64 * 1024 * (self.credits -1)
+                read_count = min(read_count, max_read_count)
+
+            m = SMB2Message(self, SMB2ReadRequest(fid, offset, read_count))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, readCB, errback,
+                                                           tid = tid, fid = fid, offset = offset,
+                                                           remaining_len = remaining_len,
+                                                           read_len = read_len,
+                                                           file_attributes = file_attributes)
+
+        def readCB(read_message, **kwargs):
+            # To avoid crazy memory usage when retrieving large files, we do not save every read_message in messages_history.
+            if read_message.status == 0:
+                data_len = read_message.payload.data_length
+                file_obj.write(read_message.payload.data)
+
+                remaining_len = kwargs['remaining_len'] - data_len
+
+                if remaining_len > 0:
+                    sendRead(kwargs['tid'], kwargs['fid'], kwargs['offset'] + data_len, remaining_len, kwargs['read_len'] + data_len, kwargs['file_attributes'])
+                else:
+                    closeFid(kwargs['tid'], kwargs['fid'], ret = ( file_obj, kwargs['file_attributes'], kwargs['read_len'] + data_len ))
+            else:
+                messages_history.append(read_message)
+                closeFid(kwargs['tid'], kwargs['fid'], error = read_message.status)
+
+        def closeFid(tid, fid, ret = None, error = None):
+            m = SMB2Message(self, SMB2CloseRequest(fid))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, closeCB, errback, ret = ret, error = error)
+            messages_history.append(m)
+
+        def closeCB(close_message, **kwargs):
+            if kwargs['ret'] is not None:
+                callback(kwargs['ret'])
+            elif kwargs['error'] is not None:
+                errback(OperationFailure('Failed to retrieve %s on %s: Read failed' % ( path, service_name ), messages_history))
+
+        if not self.connected_trees.has_key(service_name):
+            def connectCB(connect_message, **kwargs):
+                messages_history.append(connect_message)
+                if connect_message.status == 0:
+                    self.connected_trees[service_name] = connect_message.tid
+                    sendCreate(connect_message.tid)
+                else:
+                    errback(OperationFailure('Failed to retrieve %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history))
+
+            m = SMB2Message(self, SMB2TreeConnectRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name )))
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectCB, errback, path = service_name)
+            messages_history.append(m)
+        else:
+            sendCreate(self.connected_trees[service_name])
+
+    def _storeFile_SMB2(self, service_name, path, file_obj, callback, errback, timeout = 30):
+        self._storeFileFromOffset_SMB2(service_name, path, file_obj, callback, errback, 0L, True, timeout)
+
+    def _storeFileFromOffset_SMB2(self, service_name, path, file_obj, callback, errback, starting_offset, truncate = False, timeout = 30):
+        if not self.has_authenticated:
+            raise NotReadyError('SMB connection not authenticated')
+
+        expiry_time = time.time() + timeout
+        path = path.replace('/', '\\')
+        if path.startswith('\\'):
+            path = path[1:]
+        if path.endswith('\\'):
+            path = path[:-1]
+        messages_history = [ ]
+
+        def sendCreate(tid):
+            create_context_data = binascii.unhexlify("""
+28 00 00 00 10 00 04 00 00 00 18 00 10 00 00 00
+44 48 6e 51 00 00 00 00 00 00 00 00 00 00 00 00
+00 00 00 00 00 00 00 00 20 00 00 00 10 00 04 00
+00 00 18 00 08 00 00 00 41 6c 53 69 00 00 00 00
+85 62 00 00 00 00 00 00 18 00 00 00 10 00 04 00
+00 00 18 00 00 00 00 00 4d 78 41 63 00 00 00 00
+00 00 00 00 10 00 04 00 00 00 18 00 00 00 00 00
+51 46 69 64 00 00 00 00
+""".replace(' ', '').replace('\n', ''))
+            m = SMB2Message(self, SMB2CreateRequest(path,
+                                              file_attributes = ATTR_ARCHIVE,
+                                              access_mask = FILE_READ_DATA | FILE_WRITE_DATA | FILE_APPEND_DATA | FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES | FILE_READ_EA | FILE_WRITE_EA | READ_CONTROL | SYNCHRONIZE,
+                                              share_access = 0,
+                                              oplock = SMB2_OPLOCK_LEVEL_NONE,
+                                              impersonation = SEC_IMPERSONATE,
+                                              create_options = FILE_SEQUENTIAL_ONLY | FILE_NON_DIRECTORY_FILE,
+                                              create_disp = FILE_OVERWRITE_IF if truncate else FILE_OPEN_IF,
+                                              create_context_data = create_context_data))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, createCB, errback, tid = tid)
+            messages_history.append(m)
+
+        def createCB(create_message, **kwargs):
+            create_message.tid = kwargs['tid']
+            messages_history.append(create_message)
+            if create_message.status == 0:
+                sendWrite(create_message.tid, create_message.payload.fid, starting_offset)
+            else:
+                errback(OperationFailure('Failed to store %s on %s: Unable to open file' % ( path, service_name ), messages_history))
+
+        def sendWrite(tid, fid, offset):
+            if self.smb2_dialect != SMB2_DIALECT_2 and self.cap_multi_credit:
+                write_count = 64 * 1024 * (self.credits -1)
+            else:
+                write_count = self.max_write_size
+            data = file_obj.read(write_count)
+            data_len = len(data)
+            if data_len > 0:
+                m = SMB2Message(self, SMB2WriteRequest(fid, data, offset))
+                m.tid = tid
+                self._sendSMBMessage(m)
+                self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, writeCB, errback, tid = tid, fid = fid, offset = offset+data_len)
+            else:
+                closeFid(tid, fid, offset = offset)
+
+        def writeCB(write_message, **kwargs):
+            # To avoid crazy memory usage when saving large files, we do not save every write_message in messages_history.
+            if write_message.status == 0:
+                sendWrite(kwargs['tid'], kwargs['fid'], kwargs['offset'])
+            else:
+                messages_history.append(write_message)
+                closeFid(kwargs['tid'], kwargs['fid'])
+                errback(OperationFailure('Failed to store %s on %s: Write failed' % ( path, service_name ), messages_history))
+
+        def closeFid(tid, fid, error = None, offset = None):
+            m = SMB2Message(self, SMB2CloseRequest(fid))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, closeCB, errback, fid = fid, offset = offset, error = error)
+            messages_history.append(m)
+
+        def closeCB(close_message, **kwargs):
+            if kwargs['offset'] is not None:
+                callback(( file_obj, kwargs['offset'] ))  # Note that this is a tuple of 2-elements
+            elif kwargs['error'] is not None:
+                errback(OperationFailure('Failed to store %s on %s: Write failed' % ( path, service_name ), messages_history))
+
+        if not self.connected_trees.has_key(service_name):
+            def connectCB(connect_message, **kwargs):
+                messages_history.append(connect_message)
+                if connect_message.status == 0:
+                    self.connected_trees[service_name] = connect_message.tid
+                    sendCreate(connect_message.tid)
+                else:
+                    errback(OperationFailure('Failed to store %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history))
+
+            m = SMB2Message(self, SMB2TreeConnectRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name )))
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, connectCB, errback, path = service_name)
+            messages_history.append(m)
+        else:
+            sendCreate(self.connected_trees[service_name])
+
+
+    def _deleteFiles_SMB2(self, service_name, path_file_pattern, callback, errback, timeout = 30):
+        if not self.has_authenticated:
+            raise NotReadyError('SMB connection not authenticated')
+
+        expiry_time = time.time() + timeout
+        path = path_file_pattern.replace('/', '\\')
+        if path.startswith('\\'):
+            path = path[1:]
+        if path.endswith('\\'):
+            path = path[:-1]
+        messages_history = [ ]
+
+        def sendCreate(tid):
+            create_context_data = binascii.unhexlify("""
+28 00 00 00 10 00 04 00 00 00 18 00 10 00 00 00
+44 48 6e 51 00 00 00 00 00 00 00 00 00 00 00 00
+00 00 00 00 00 00 00 00 18 00 00 00 10 00 04 00
+00 00 18 00 00 00 00 00 4d 78 41 63 00 00 00 00
+00 00 00 00 10 00 04 00 00 00 18 00 00 00 00 00
+51 46 69 64 00 00 00 00
+""".replace(' ', '').replace('\n', ''))
+            m = SMB2Message(self, SMB2CreateRequest(path,
+                                              file_attributes = 0,
+                                              access_mask = DELETE | FILE_READ_ATTRIBUTES,
+                                              share_access = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
+                                              oplock = SMB2_OPLOCK_LEVEL_NONE,
+                                              impersonation = SEC_IMPERSONATE,
+                                              create_options = FILE_NON_DIRECTORY_FILE,
+                                              create_disp = FILE_OPEN,
+                                              create_context_data = create_context_data))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, createCB, errback, tid = tid)
+            messages_history.append(m)
+
+        def createCB(open_message, **kwargs):
+            open_message.tid = kwargs['tid']
+            messages_history.append(open_message)
+            if open_message.status == 0:
+                sendDelete(open_message.tid, open_message.payload.fid)
+            else:
+                errback(OperationFailure('Failed to delete %s on %s: Unable to open file' % ( path, service_name ), messages_history))
+
+        def sendDelete(tid, fid):
+            m = SMB2Message(self, SMB2SetInfoRequest(fid,
+                                               additional_info = 0,
+                                               info_type = SMB2_INFO_FILE,
+                                               file_info_class = 0x0d,  # SMB2_FILE_DISPOSITION_INFO
+                                               data = '\x01'))
+            # [MS-SMB2]: 2.2.39, [MS-FSCC]: 2.4.11
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, deleteCB, errback, tid = tid, fid = fid)
+            messages_history.append(m)
+
+        def deleteCB(delete_message, **kwargs):
+            messages_history.append(delete_message)
+            if delete_message.status == 0:
+                closeFid(kwargs['tid'], kwargs['fid'], status = 0)
+            else:
+                closeFid(kwargs['tid'], kwargs['fid'], status = delete_message.status)
+
+        def closeFid(tid, fid, status = None):
+            m = SMB2Message(self, SMB2CloseRequest(fid))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, closeCB, errback, status = status)
+            messages_history.append(m)
+
+        def closeCB(close_message, **kwargs):
+            if kwargs['status'] == 0:
+                callback(path_file_pattern)
+            else:
+                errback(OperationFailure('Failed to delete %s on %s: Delete failed' % ( path, service_name ), messages_history))
+
+        if not self.connected_trees.has_key(service_name):
+            def connectCB(connect_message, **kwargs):
+                messages_history.append(connect_message)
+                if connect_message.status == 0:
+                    self.connected_trees[service_name] = connect_message.tid
+                    sendCreate(connect_message.tid)
+                else:
+                    errback(OperationFailure('Failed to delete %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history))
+
+            m = SMB2Message(self, SMB2TreeConnectRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name )))
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectCB, errback, path = service_name)
+            messages_history.append(m)
+        else:
+            sendCreate(self.connected_trees[service_name])
+
+    def _resetFileAttributes_SMB2(self, service_name, path_file_pattern, callback, errback, timeout = 30):
+        if not self.has_authenticated:
+            raise NotReadyError('SMB connection not authenticated')
+
+        expiry_time = time.time() + timeout
+        path = path_file_pattern.replace('/', '\\')
+        if path.startswith('\\'):
+            path = path[1:]
+        if path.endswith('\\'):
+            path = path[:-1]
+        messages_history = [ ]
+
+        def sendCreate(tid):
+            create_context_data = binascii.unhexlify("""
+28 00 00 00 10 00 04 00 00 00 18 00 10 00 00 00
+44 48 6e 51 00 00 00 00 00 00 00 00 00 00 00 00
+00 00 00 00 00 00 00 00 18 00 00 00 10 00 04 00
+00 00 18 00 00 00 00 00 4d 78 41 63 00 00 00 00
+00 00 00 00 10 00 04 00 00 00 18 00 00 00 00 00
+51 46 69 64 00 00 00 00
+""".replace(' ', '').replace('\n', ''))
+
+            m = SMB2Message(self, SMB2CreateRequest(path,
+                                              file_attributes = 0,
+                                              access_mask = FILE_WRITE_ATTRIBUTES,
+                                              share_access = FILE_SHARE_READ | FILE_SHARE_WRITE,
+                                              oplock = SMB2_OPLOCK_LEVEL_NONE,
+                                              impersonation = SEC_IMPERSONATE,
+                                              create_options = 0,
+                                              create_disp = FILE_OPEN,
+                                              create_context_data = create_context_data))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, createCB, errback, tid = tid)
+            messages_history.append(m)
+
+        def createCB(open_message, **kwargs):
+            messages_history.append(open_message)
+            if open_message.status == 0:
+                sendReset(kwargs['tid'], open_message.payload.fid)
+            else:
+                errback(OperationFailure('Failed to reset attributes of %s on %s: Unable to open file' % ( path, service_name ), messages_history))
+
+        def sendReset(tid, fid):
+            m = SMB2Message(self, SMB2SetInfoRequest(fid,
+                                               additional_info = 0,
+                                               info_type = SMB2_INFO_FILE,
+                                               file_info_class = 4,  # FileBasicInformation
+                                               data = struct.pack('qqqqii',0,0,0,0,0x80,0))) # FILE_ATTRIBUTE_NORMAL
+            # [MS-SMB2]: 2.2.39, [MS-FSCC]: 2.4, [MS-FSCC]: 2.4.7, [MS-FSCC]: 2.6
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, resetCB, errback, tid = tid, fid = fid)
+            messages_history.append(m)
+
+        def resetCB(reset_message, **kwargs):
+            messages_history.append(reset_message)
+            if reset_message.status == 0:
+                closeFid(kwargs['tid'], kwargs['fid'], status = 0)
+            else:
+                closeFid(kwargs['tid'], kwargs['fid'], status = reset_message.status)
+
+        def closeFid(tid, fid, status = None):
+            m = SMB2Message(self, SMB2CloseRequest(fid))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, closeCB, errback, status = status)
+            messages_history.append(m)
+
+        def closeCB(close_message, **kwargs):
+            if kwargs['status'] == 0:
+                callback(path_file_pattern)
+            else:
+                errback(OperationFailure('Failed to reset attributes of %s on %s: Reset failed' % ( path, service_name ), messages_history))
+
+        if not self.connected_trees.has_key(service_name):
+            def connectCB(connect_message, **kwargs):
+                messages_history.append(connect_message)
+                if connect_message.status == 0:
+                    self.connected_trees[service_name] = connect_message.tid
+                    sendCreate(connect_message.tid)
+                else:
+                    errback(OperationFailure('Failed to reset attributes of %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history))
+
+            m = SMB2Message(self, SMB2TreeConnectRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name )))
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectCB, errback, path = service_name)
+            messages_history.append(m)
+        else:
+            sendCreate(self.connected_trees[service_name])
+
+    def _createDirectory_SMB2(self, service_name, path, callback, errback, timeout = 30):
+        if not self.has_authenticated:
+            raise NotReadyError('SMB connection not authenticated')
+
+        expiry_time = time.time() + timeout
+        path = path.replace('/', '\\')
+        if path.startswith('\\'):
+            path = path[1:]
+        if path.endswith('\\'):
+            path = path[:-1]
+        messages_history = [ ]
+
+        def sendCreate(tid):
+            create_context_data = binascii.unhexlify("""
+28 00 00 00 10 00 04 00 00 00 18 00 10 00 00 00
+44 48 6e 51 00 00 00 00 00 00 00 00 00 00 00 00
+00 00 00 00 00 00 00 00 18 00 00 00 10 00 04 00
+00 00 18 00 00 00 00 00 4d 78 41 63 00 00 00 00
+00 00 00 00 10 00 04 00 00 00 18 00 00 00 00 00
+51 46 69 64 00 00 00 00
+""".replace(' ', '').replace('\n', ''))
+            m = SMB2Message(self, SMB2CreateRequest(path,
+                                              file_attributes = 0,
+                                              access_mask = FILE_READ_DATA | FILE_WRITE_DATA | FILE_READ_EA | FILE_WRITE_EA | FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES | READ_CONTROL | DELETE | SYNCHRONIZE,
+                                              share_access = 0,
+                                              oplock = SMB2_OPLOCK_LEVEL_NONE,
+                                              impersonation = SEC_IMPERSONATE,
+                                              create_options = FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT,
+                                              create_disp = FILE_CREATE,
+                                              create_context_data = create_context_data))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, createCB, errback, tid = tid)
+            messages_history.append(m)
+
+        def createCB(create_message, **kwargs):
+            messages_history.append(create_message)
+            if create_message.status == 0:
+                closeFid(kwargs['tid'], create_message.payload.fid)
+            else:
+                errback(OperationFailure('Failed to create directory %s on %s: Create failed' % ( path, service_name ), messages_history))
+
+        def closeFid(tid, fid):
+            m = SMB2Message(self, SMB2CloseRequest(fid))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, closeCB, errback)
+            messages_history.append(m)
+
+        def closeCB(close_message, **kwargs):
+            callback(path)
+
+        if not self.connected_trees.has_key(service_name):
+            def connectCB(connect_message, **kwargs):
+                messages_history.append(connect_message)
+                if connect_message.status == 0:
+                    self.connected_trees[service_name] = connect_message.tid
+                    sendCreate(connect_message.tid)
+                else:
+                    errback(OperationFailure('Failed to create directory %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history))
+
+            m = SMB2Message(self, SMB2TreeConnectRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name )))
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectCB, errback, path = service_name)
+            messages_history.append(m)
+        else:
+            sendCreate(self.connected_trees[service_name])
+
+    def _deleteDirectory_SMB2(self, service_name, path, callback, errback, timeout = 30):
+        if not self.has_authenticated:
+            raise NotReadyError('SMB connection not authenticated')
+
+        expiry_time = time.time() + timeout
+        path = path.replace('/', '\\')
+        if path.startswith('\\'):
+            path = path[1:]
+        if path.endswith('\\'):
+            path = path[:-1]
+        messages_history = [ ]
+
+        def sendCreate(tid):
+            create_context_data = binascii.unhexlify("""
+28 00 00 00 10 00 04 00 00 00 18 00 10 00 00 00
+44 48 6e 51 00 00 00 00 00 00 00 00 00 00 00 00
+00 00 00 00 00 00 00 00 18 00 00 00 10 00 04 00
+00 00 18 00 00 00 00 00 4d 78 41 63 00 00 00 00
+00 00 00 00 10 00 04 00 00 00 18 00 00 00 00 00
+51 46 69 64 00 00 00 00
+""".replace(' ', '').replace('\n', ''))
+            m = SMB2Message(self, SMB2CreateRequest(path,
+                                              file_attributes = 0,
+                                              access_mask = DELETE | FILE_READ_ATTRIBUTES,
+                                              share_access = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
+                                              oplock = SMB2_OPLOCK_LEVEL_NONE,
+                                              impersonation = SEC_IMPERSONATE,
+                                              create_options = FILE_DIRECTORY_FILE,
+                                              create_disp = FILE_OPEN,
+                                              create_context_data = create_context_data))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, createCB, errback, tid = tid)
+            messages_history.append(m)
+
+        def createCB(open_message, **kwargs):
+            messages_history.append(open_message)
+            if open_message.status == 0:
+                sendDelete(kwargs['tid'], open_message.payload.fid)
+            else:
+                errback(OperationFailure('Failed to delete %s on %s: Unable to open directory' % ( path, service_name ), messages_history))
+
+        def sendDelete(tid, fid):
+            m = SMB2Message(self, SMB2SetInfoRequest(fid,
+                                               additional_info = 0,
+                                               info_type = SMB2_INFO_FILE,
+                                               file_info_class = 0x0d,  # SMB2_FILE_DISPOSITION_INFO
+                                               data = '\x01'))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, deleteCB, errback, tid = tid, fid = fid)
+            messages_history.append(m)
+
+        def deleteCB(delete_message, **kwargs):
+            messages_history.append(delete_message)
+            if delete_message.status == 0:
+                closeFid(kwargs['tid'], kwargs['fid'], status = 0)
+            else:
+                closeFid(kwargs['tid'], kwargs['fid'], status = delete_message.status)
+
+        def closeFid(tid, fid, status = None):
+            m = SMB2Message(self, SMB2CloseRequest(fid))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, closeCB, errback, status = status)
+            messages_history.append(m)
+
+        def closeCB(close_message, **kwargs):
+            if kwargs['status'] == 0:
+                callback(path)
+            else:
+                errback(OperationFailure('Failed to delete %s on %s: Delete failed' % ( path, service_name ), messages_history))
+
+        if not self.connected_trees.has_key(service_name):
+            def connectCB(connect_message, **kwargs):
+                messages_history.append(connect_message)
+                if connect_message.status == 0:
+                    self.connected_trees[service_name] = connect_message.tid
+                    sendCreate(connect_message.tid)
+                else:
+                    errback(OperationFailure('Failed to delete %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history))
+
+            m = SMB2Message(self, SMB2TreeConnectRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name )))
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectCB, errback, path = service_name)
+            messages_history.append(m)
+        else:
+            sendCreate(self.connected_trees[service_name])
+
+    def _rename_SMB2(self, service_name, old_path, new_path, callback, errback, timeout = 30):
+        if not self.has_authenticated:
+            raise NotReadyError('SMB connection not authenticated')
+
+        expiry_time = time.time() + timeout
+        messages_history = [ ]
+
+        new_path = new_path.replace('/', '\\')
+        if new_path.startswith('\\'):
+            new_path = new_path[1:]
+        if new_path.endswith('\\'):
+            new_path = new_path[:-1]
+
+        old_path = old_path.replace('/', '\\')
+        if old_path.startswith('\\'):
+            old_path = old_path[1:]
+        if old_path.endswith('\\'):
+            old_path = old_path[:-1]
+
+        def sendCreate(tid):
+            create_context_data = binascii.unhexlify("""
+28 00 00 00 10 00 04 00 00 00 18 00 10 00 00 00
+44 48 6e 51 00 00 00 00 00 00 00 00 00 00 00 00
+00 00 00 00 00 00 00 00 18 00 00 00 10 00 04 00
+00 00 18 00 00 00 00 00 4d 78 41 63 00 00 00 00
+00 00 00 00 10 00 04 00 00 00 18 00 00 00 00 00
+51 46 69 64 00 00 00 00
+""".replace(' ', '').replace('\n', ''))
+            m = SMB2Message(self, SMB2CreateRequest(old_path,
+                                              file_attributes = 0,
+                                              access_mask = DELETE | FILE_READ_ATTRIBUTES | SYNCHRONIZE,
+                                              share_access = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
+                                              oplock = SMB2_OPLOCK_LEVEL_NONE,
+                                              impersonation = SEC_IMPERSONATE,
+                                              create_options = FILE_SYNCHRONOUS_IO_NONALERT,
+                                              create_disp = FILE_OPEN,
+                                              create_context_data = create_context_data))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, createCB, errback, tid = tid)
+            messages_history.append(m)
+
+        def createCB(create_message, **kwargs):
+            messages_history.append(create_message)
+            if create_message.status == 0:
+                sendRename(kwargs['tid'], create_message.payload.fid)
+            else:
+                errback(OperationFailure('Failed to rename %s on %s: Unable to open file/directory' % ( old_path, service_name ), messages_history))
+
+        def sendRename(tid, fid):
+            data = '\x00'*16 + struct.pack('<I', len(new_path)*2) + new_path.encode('UTF-16LE')
+            m = SMB2Message(self, SMB2SetInfoRequest(fid,
+                                               additional_info = 0,
+                                               info_type = SMB2_INFO_FILE,
+                                               file_info_class = 0x0a,  # SMB2_FILE_RENAME_INFO
+                                               data = data))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, renameCB, errback, tid = tid, fid = fid)
+            messages_history.append(m)
+
+        def renameCB(rename_message, **kwargs):
+            messages_history.append(rename_message)
+            if rename_message.status == 0:
+                closeFid(kwargs['tid'], kwargs['fid'], status = 0)
+            else:
+                closeFid(kwargs['tid'], kwargs['fid'], status = rename_message.status)
+
+        def closeFid(tid, fid, status = None):
+            m = SMB2Message(self, SMB2CloseRequest(fid))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, closeCB, errback, status = status)
+            messages_history.append(m)
+
+        def closeCB(close_message, **kwargs):
+            if kwargs['status'] == 0:
+                callback(( old_path, new_path ))
+            else:
+                errback(OperationFailure('Failed to rename %s on %s: Rename failed' % ( old_path, service_name ), messages_history))
+
+        if not self.connected_trees.has_key(service_name):
+            def connectCB(connect_message, **kwargs):
+                messages_history.append(connect_message)
+                if connect_message.status == 0:
+                    self.connected_trees[service_name] = connect_message.tid
+                    sendCreate(connect_message.tid)
+                else:
+                    errback(OperationFailure('Failed to rename %s on %s: Unable to connect to shared device' % ( old_path, service_name ), messages_history))
+
+            m = SMB2Message(self, SMB2TreeConnectRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name )))
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectCB, errback, path = service_name)
+            messages_history.append(m)
+        else:
+            sendCreate(self.connected_trees[service_name])
+
+    def _listSnapshots_SMB2(self, service_name, path, callback, errback, timeout = 30):
+        if not self.has_authenticated:
+            raise NotReadyError('SMB connection not authenticated')
+
+        expiry_time = time.time() + timeout
+        path = path.replace('/', '\\')
+        if path.startswith('\\'):
+            path = path[1:]
+        if path.endswith('\\'):
+            path = path[:-1]
+        messages_history = [ ]
+
+        def sendCreate(tid):
+            create_context_data = binascii.unhexlify("""
+28 00 00 00 10 00 04 00 00 00 18 00 10 00 00 00
+44 48 6e 51 00 00 00 00 00 00 00 00 00 00 00 00
+00 00 00 00 00 00 00 00 00 00 00 00 10 00 04 00
+00 00 18 00 00 00 00 00 4d 78 41 63 00 00 00 00
+""".replace(' ', '').replace('\n', ''))
+            m = SMB2Message(self, SMB2CreateRequest(path,
+                                              file_attributes = 0,
+                                              access_mask = FILE_READ_DATA | FILE_READ_ATTRIBUTES | SYNCHRONIZE,
+                                              share_access = FILE_SHARE_READ | FILE_SHARE_WRITE,
+                                              oplock = SMB2_OPLOCK_LEVEL_NONE,
+                                              impersonation = SEC_IMPERSONATE,
+                                              create_options = FILE_SYNCHRONOUS_IO_NONALERT,
+                                              create_disp = FILE_OPEN,
+                                              create_context_data = create_context_data))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, createCB, errback, tid = tid)
+            messages_history.append(m)
+
+        def createCB(create_message, **kwargs):
+            messages_history.append(create_message)
+            if create_message.status == 0:
+                sendEnumSnapshots(kwargs['tid'], create_message.payload.fid)
+            else:
+                errback(OperationFailure('Failed to list snapshots %s on %s: Unable to open file/directory' % ( old_path, service_name ), messages_history))
+
+        def sendEnumSnapshots(tid, fid):
+            m = SMB2Message(self, SMB2IoctlRequest(fid,
+                                             ctlcode = 0x00144064,  # FSCTL_SRV_ENUMERATE_SNAPSHOTS
+                                             flags = 0x0001,
+                                             in_data = ''))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, enumSnapshotsCB, errback, tid = tid, fid = fid)
+            messages_history.append(m)
+
+        def enumSnapshotsCB(enum_message, **kwargs):
+            messages_history.append(enum_message)
+            if enum_message.status == 0:
+                results = [ ]
+                snapshots_count = struct.unpack('<I', enum_message.payload.out_data[4:8])[0]
+                for i in range(0, snapshots_count):
+                    s = enum_message.payload.out_data[12+i*50:12+48+i*50].decode('UTF-16LE')
+                    results.append(datetime(*map(int, ( s[5:9], s[10:12], s[13:15], s[16:18], s[19:21], s[22:24] ))))
+                closeFid(kwargs['tid'], kwargs['fid'], results = results)
+            else:
+                closeFid(kwargs['tid'], kwargs['fid'], status = enum_message.status)
+
+        def closeFid(tid, fid, status = None, results = None):
+            m = SMB2Message(self, SMB2CloseRequest(fid))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, closeCB, errback, status = status, results = results)
+            messages_history.append(m)
+
+        def closeCB(close_message, **kwargs):
+            if kwargs['results'] is not None:
+                callback(kwargs['results'])
+            else:
+                errback(OperationFailure('Failed to list snapshots %s on %s: List failed' % ( path, service_name ), messages_history))
+
+        if not self.connected_trees.has_key(service_name):
+            def connectCB(connect_message, **kwargs):
+                messages_history.append(connect_message)
+                if connect_message.status == 0:
+                    self.connected_trees[service_name] = connect_message.tid
+                    sendCreate(connect_message.tid)
+                else:
+                    errback(OperationFailure('Failed to list snapshots %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history))
+
+            m = SMB2Message(self, SMB2TreeConnectRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name )))
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectCB, errback, path = service_name)
+            messages_history.append(m)
+        else:
+            sendCreate(self.connected_trees[service_name])
+
+    def _echo_SMB2(self, data, callback, errback, timeout = 30):
+        messages_history = [ ]
+
+        def echoCB(echo_message, **kwargs):
+            messages_history.append(echo_message)
+            if echo_message.status == 0:
+                callback(data)
+            else:
+                errback(OperationFailure('Echo failed', messages_history))
+
+        m = SMB2Message(self, SMB2EchoRequest())
+        self._sendSMBMessage(m)
+        self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, echoCB, errback)
+        messages_history.append(m)
+
+
+    #
+    # SMB1 Methods Family
+    #
+
+    def _sendSMBMessage_SMB1(self, smb_message):
+        if smb_message.mid == 0:
+            smb_message.mid = self._getNextMID_SMB1()
+        if not smb_message.uid:
+            smb_message.uid = self.uid
+        if self.is_signing_active:
+            smb_message.flags2 |= SMB_FLAGS2_SMB_SECURITY_SIGNATURE
+
+            # Increment the next_signing_id as described in [MS-CIFS] 3.2.4.1.3
+            smb_message.security = self.next_signing_id
+            self.next_signing_id += 2  # All our defined messages currently have responses, so always increment by 2
+            raw_data = smb_message.encode()
+
+            md = ntlm.MD5(self.signing_session_key)
+            if self.signing_challenge_response:
+                md.update(self.signing_challenge_response)
+            md.update(raw_data)
+            signature = md.digest()[:8]
+
+            self.log.debug('MID is %d. Signing ID is %d. Signature is %s. Total raw message is %d bytes', smb_message.mid, smb_message.security, binascii.hexlify(signature), len(raw_data))
+            smb_message.raw_data = raw_data[:14] + signature + raw_data[22:]
+        else:
+            smb_message.raw_data = smb_message.encode()
+        self.sendNMBMessage(smb_message.raw_data)
+
+    def _getNextMID_SMB1(self):
+        self.mid += 1
+        if self.mid >= 0xFFFF: # MID cannot be 0xFFFF. [MS-CIFS]: 2.2.1.6.2
+            # We don't use MID of 0 as MID can be reused for SMB_COM_TRANSACTION2_SECONDARY messages
+            # where if mid=0, _sendSMBMessage will re-assign new MID values again
+            self.mid = 1
+        return self.mid
+
+    def _updateState_SMB1(self, message):
+        if message.isReply:
+            if message.command == SMB_COM_NEGOTIATE:
+                if not message.status.hasError:
+                    self.has_negotiated = True
+                    self.log.info('SMB dialect negotiation successful (ExtendedSecurity:%s)', message.hasExtendedSecurity)
+                    self._updateServerInfo(message.payload)
+                    self._handleNegotiateResponse(message)
+                else:
+                    raise ProtocolError('Unknown status value (0x%08X) in SMB_COM_NEGOTIATE' % message.status.internal_value,
+                                        message.raw_data, message)
+            elif message.command == SMB_COM_SESSION_SETUP_ANDX:
+                if message.hasExtendedSecurity:
+                    if not message.status.hasError:
+                        try:
+                            result = securityblob.decodeAuthResponseSecurityBlob(message.payload.security_blob)
+                            if result == securityblob.RESULT_ACCEPT_COMPLETED:
+                                self.log.debug('SMB uid is now %d', message.uid)
+                                self.uid = message.uid
+                                self.has_authenticated = True
+                                self.log.info('Authentication (with extended security) successful!')
+                                self.onAuthOK()
+                            else:
+                                raise ProtocolError('SMB_COM_SESSION_SETUP_ANDX status is 0 but security blob negResult value is %d' % result, message.raw_data, message)
+                        except securityblob.BadSecurityBlobError, ex:
+                            raise ProtocolError(str(ex), message.raw_data, message)
+                    elif message.status.internal_value == 0xc0000016:  # STATUS_MORE_PROCESSING_REQUIRED
+                        try:
+                            result, ntlm_token = securityblob.decodeChallengeSecurityBlob(message.payload.security_blob)
+                            if result == securityblob.RESULT_ACCEPT_INCOMPLETE:
+                                self._handleSessionChallenge(message, ntlm_token)
+                        except ( securityblob.BadSecurityBlobError, securityblob.UnsupportedSecurityProvider ), ex:
+                            raise ProtocolError(str(ex), message.raw_data, message)
+                    elif (message.status.internal_value == 0xc000006d    # STATUS_LOGON_FAILURE
+                        or message.status.internal_value == 0xc0000064   # STATUS_NO_SUCH_USER
+                        or message.status.internal_value == 0xc000006a): # STATUS_WRONG_PASSWORD
+                        self.has_authenticated = False
+                        self.log.info('Authentication (with extended security) failed. Please check username and password.')
+                        self.onAuthFailed()
+                    elif (message.status.internal_value == 0xc0000193    # STATUS_ACCOUNT_EXPIRED
+                        or message.status.internal_value == 0xC0000071): # STATUS_PASSWORD_EXPIRED
+                        self.has_authenticated = False
+                        self.log.info('Authentication (with extended security) failed. Account or password has expired.')
+                        self.onAuthFailed()
+                    elif message.status.internal_value == 0xc0000234: # STATUS_ACCOUNT_LOCKED_OUT
+                        self.has_authenticated = False
+                        self.log.info('Authentication (with extended security) failed. Account has been locked due to too many invalid logon attempts.')
+                        self.onAuthFailed()
+                    elif message.status.internal_value == 0xc0000072: # STATUS_ACCOUNT_DISABLED
+                        self.has_authenticated = False
+                        self.log.info('Authentication (with extended security) failed. Account has been disabled.')
+                        self.onAuthFailed()
+                    elif (message.status.internal_value == 0xc000006f    # STATUS_INVALID_LOGON_HOURS
+                        or message.status.internal_value == 0xc000015b   # STATUS_LOGON_TYPE_NOT_GRANTED
+                        or message.status.internal_value == 0xc0000070): # STATUS_INVALID_WORKSTATION
+                        self.has_authenticated = False
+                        self.log.info('Authentication (with extended security) failed. Not allowed.')
+                        self.onAuthFailed()
+                    elif message.status.internal_value == 0xc000018c:  # STATUS_TRUSTED_DOMAIN_FAILURE
+                        self.has_authenticated = False
+                        self.log.info('Authentication (with extended security) failed. Domain not trusted.')
+                        self.onAuthFailed()
+                    elif message.status.internal_value == 0xc000018d:  # STATUS_TRUSTED_RELATIONSHIP_FAILURE
+                        self.has_authenticated = False
+                        self.log.info('Authentication (with extended security) failed. Workstation not trusted.')
+                        self.onAuthFailed()
+                    else:
+                        raise ProtocolError('Unknown status value (0x%08X) in SMB_COM_SESSION_SETUP_ANDX (with extended security)' % message.status.internal_value,
+                                            message.raw_data, message)
+                else:
+                    if message.status.internal_value == 0:
+                        self.log.debug('SMB uid is now %d', message.uid)
+                        self.uid = message.uid
+                        self.has_authenticated = True
+                        self.log.info('Authentication (without extended security) successful!')
+                        self.onAuthOK()
+                    else:
+                        self.has_authenticated = False
+                        self.log.info('Authentication (without extended security) failed. Please check username and password')
+                        self.onAuthFailed()
+            elif message.command == SMB_COM_TREE_CONNECT_ANDX:
+                try:
+                    req = self.pending_requests[message.mid]
+                except KeyError:
+                    pass
+                else:
+                    if not message.status.hasError:
+                        self.connected_trees[req.kwargs['path']] = message.tid
+
+            req = self.pending_requests.pop(message.mid, None)
+            if req:
+                req.callback(message, **req.kwargs)
+                return True
+
+
+    def _updateServerInfo_SMB1(self, payload):
+        self.capabilities = payload.capabilities
+        self.security_mode = payload.security_mode
+        self.max_raw_size = payload.max_raw_size
+        self.max_buffer_size = payload.max_buffer_size
+        self.max_mpx_count = payload.max_mpx_count
+        self.use_plaintext_authentication = not bool(payload.security_mode & NEGOTIATE_ENCRYPT_PASSWORDS)
+
+        if self.use_plaintext_authentication:
+            self.log.warning('Remote server only supports plaintext authentication. Your password can be stolen easily over the network.')
+
+
+    def _handleSessionChallenge_SMB1(self, message, ntlm_token):
+        assert message.hasExtendedSecurity
+
+        if message.uid and not self.uid:
+            self.uid = message.uid
+
+        server_challenge, server_flags, server_info = ntlm.decodeChallengeMessage(ntlm_token)
+        if self.use_ntlm_v2:
+            self.log.info('Performing NTLMv2 authentication (with extended security) with server challenge "%s"', binascii.hexlify(server_challenge))
+            nt_challenge_response, lm_challenge_response, session_key = ntlm.generateChallengeResponseV2(self.password,
+                                                                                                         self.username,
+                                                                                                         server_challenge,
+                                                                                                         server_info,
+                                                                                                         self.domain)
+
+        else:
+            self.log.info('Performing NTLMv1 authentication (with extended security) with server challenge "%s"', binascii.hexlify(server_challenge))
+            nt_challenge_response, lm_challenge_response, session_key = ntlm.generateChallengeResponseV1(self.password, server_challenge, True)
+
+        ntlm_data = ntlm.generateAuthenticateMessage(server_flags,
+                                                     nt_challenge_response,
+                                                     lm_challenge_response,
+                                                     session_key,
+                                                     self.username,
+                                                     self.domain,
+                                                     self.my_name)
+
+        if self.log.isEnabledFor(logging.DEBUG):
+            self.log.debug('NT challenge response is "%s" (%d bytes)', binascii.hexlify(nt_challenge_response), len(nt_challenge_response))
+            self.log.debug('LM challenge response is "%s" (%d bytes)', binascii.hexlify(lm_challenge_response), len(lm_challenge_response))
+
+        blob = securityblob.generateAuthSecurityBlob(ntlm_data)
+        self._sendSMBMessage(SMBMessage(self, ComSessionSetupAndxRequest__WithSecurityExtension(0, blob)))
+
+        if self.security_mode & NEGOTIATE_SECURITY_SIGNATURES_REQUIRE:
+            self.log.info('Server requires all SMB messages to be signed')
+            self.is_signing_active = (self.sign_options != SMB.SIGN_NEVER)
+        elif self.security_mode & NEGOTIATE_SECURITY_SIGNATURES_ENABLE:
+            self.log.info('Server supports SMB signing')
+            self.is_signing_active = (self.sign_options == SMB.SIGN_WHEN_SUPPORTED)
+        else:
+            self.is_signing_active = False
+
+        if self.is_signing_active:
+            self.log.info("SMB signing activated. All SMB messages will be signed.")
+            self.signing_session_key = session_key
+            if self.capabilities & CAP_EXTENDED_SECURITY:
+                self.signing_challenge_response = None
+            else:
+                self.signing_challenge_response = blob
+        else:
+            self.log.info("SMB signing deactivated. SMB messages will NOT be signed.")
+
+
+    def _handleNegotiateResponse_SMB1(self, message):
+        if message.uid and not self.uid:
+            self.uid = message.uid
+
+        if message.hasExtendedSecurity or message.payload.supportsExtendedSecurity:
+            ntlm_data = ntlm.generateNegotiateMessage()
+            blob = securityblob.generateNegotiateSecurityBlob(ntlm_data)
+            self._sendSMBMessage(SMBMessage(self, ComSessionSetupAndxRequest__WithSecurityExtension(message.payload.session_key, blob)))
+        else:
+            nt_password, _, _ = ntlm.generateChallengeResponseV1(self.password, message.payload.challenge, False)
+            self.log.info('Performing NTLMv1 authentication (without extended security) with challenge "%s" and hashed password of "%s"',
+                          binascii.hexlify(message.payload.challenge),
+                          binascii.hexlify(nt_password))
+            self._sendSMBMessage(SMBMessage(self, ComSessionSetupAndxRequest__NoSecurityExtension(message.payload.session_key,
+                                                                                           self.username,
+                                                                                           nt_password,
+                                                                                           True,
+                                                                                           self.domain)))
+
+    def _listShares_SMB1(self, callback, errback, timeout = 30):
+        if not self.has_authenticated:
+            raise NotReadyError('SMB connection not authenticated')
+
+        expiry_time = time.time() + timeout
+        path = 'IPC$'
+        messages_history = [ ]
+
+        def connectSrvSvc(tid):
+            m = SMBMessage(self, ComNTCreateAndxRequest('\\srvsvc',
+                                                  flags = NT_CREATE_REQUEST_EXTENDED_RESPONSE,
+                                                  access_mask = READ_CONTROL | FILE_WRITE_ATTRIBUTES | FILE_READ_ATTRIBUTES | FILE_WRITE_EA | FILE_READ_EA | FILE_APPEND_DATA | FILE_WRITE_DATA | FILE_READ_DATA,
+                                                  share_access = FILE_SHARE_READ | FILE_SHARE_WRITE,
+                                                  create_disp = FILE_OPEN,
+                                                  create_options = FILE_OPEN_NO_RECALL | FILE_NON_DIRECTORY_FILE,
+                                                  impersonation = SEC_IMPERSONATE,
+                                                  security_flags = 0))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectSrvSvcCB, errback)
+            messages_history.append(m)
+
+        def connectSrvSvcCB(create_message, **kwargs):
+            messages_history.append(create_message)
+            if not create_message.status.hasError:
+                call_id = self._getNextRPCCallID()
+                # See [MS-CIFS]: 2.2.5.6.1 for more information on TRANS_TRANSACT_NMPIPE (0x0026) parameters
+                setup_bytes = struct.pack('<HH', 0x0026, create_message.payload.fid)
+                # The data_bytes are binding call to Server Service RPC using DCE v1.1 RPC over SMB. See [MS-SRVS] and [C706]
+                # If you wish to understand the meanings of the byte stream, I would suggest you use a recent version of WireShark to packet capture the stream
+                data_bytes = \
+                    binascii.unhexlify("""05 00 0b 03 10 00 00 00 48 00 00 00""".replace(' ', '')) + \
+                    struct.pack('<I', call_id) + \
+                    binascii.unhexlify("""
+b8 10 b8 10 00 00 00 00 01 00 00 00 00 00 01 00
+c8 4f 32 4b 70 16 d3 01 12 78 5a 47 bf 6e e1 88
+03 00 00 00 04 5d 88 8a eb 1c c9 11 9f e8 08 00
+2b 10 48 60 02 00 00 00""".replace(' ', '').replace('\n', ''))
+                m = SMBMessage(self, ComTransactionRequest(max_params_count = 0,
+                                                     max_data_count = 4280,
+                                                     max_setup_count = 0,
+                                                     data_bytes = data_bytes,
+                                                     setup_bytes = setup_bytes))
+                m.tid = create_message.tid
+                self._sendSMBMessage(m)
+                self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, rpcBindCB, errback, fid = create_message.payload.fid)
+                messages_history.append(m)
+            else:
+                errback(OperationFailure('Failed to list shares: Unable to locate Server Service RPC endpoint', messages_history))
+
+        def rpcBindCB(trans_message, **kwargs):
+            messages_history.append(trans_message)
+            if not trans_message.status.hasError:
+                call_id = self._getNextRPCCallID()
+
+                padding = ''
+                server_len = len(self.remote_name) + 1
+                server_bytes_len = server_len * 2
+                if server_len % 2 != 0:
+                    padding = '\0\0'
+                    server_bytes_len += 2
+
+                # See [MS-CIFS]: 2.2.5.6.1 for more information on TRANS_TRANSACT_NMPIPE (0x0026) parameters
+                setup_bytes = struct.pack('<HH', 0x0026, kwargs['fid'])
+                # The data bytes are the RPC call to NetrShareEnum (Opnum 15) at Server Service RPC.
+                # If you wish to understand the meanings of the byte stream, I would suggest you use a recent version of WireShark to packet capture the stream
+                data_bytes = \
+                    binascii.unhexlify("""05 00 00 03 10 00 00 00""".replace(' ', '')) + \
+                    struct.pack('<HHI', 72+server_bytes_len, 0, call_id) + \
+                    binascii.unhexlify("""4c 00 00 00 00 00 0f 00 00 00 02 00""".replace(' ', '')) + \
+                    struct.pack('<III', server_len, 0, server_len) + \
+                    (self.remote_name + '\0').encode('UTF-16LE') + padding + \
+                    binascii.unhexlify("""
+01 00 00 00 01 00 00 00 04 00 02 00 00 00 00 00
+00 00 00 00 ff ff ff ff 08 00 02 00 00 00 00 00
+""".replace(' ', '').replace('\n', ''))
+                m = SMBMessage(self, ComTransactionRequest(max_params_count = 0,
+                                                     max_data_count = 4280,
+                                                     max_setup_count = 0,
+                                                     data_bytes = data_bytes,
+                                                     setup_bytes = setup_bytes))
+                m.tid = trans_message.tid
+                self._sendSMBMessage(m)
+                self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, listShareResultsCB, errback, fid = kwargs['fid'])
+                messages_history.append(m)
+            else:
+                closeFid(trans_message.tid, kwargs['fid'])
+                errback(OperationFailure('Failed to list shares: Unable to bind to Server Service RPC endpoint', messages_history))
+
+        def listShareResultsCB(result_message, **kwargs):
+            messages_history.append(result_message)
+            if not result_message.status.hasError:
+                # The payload.data_bytes will contain the results of the RPC call to NetrShareEnum (Opnum 15) at Server Service RPC.
+                data_bytes = result_message.payload.data_bytes
+
+                if ord(data_bytes[3]) & 0x02 == 0:
+                    sendReadRequest(result_message.tid, kwargs['fid'], data_bytes)
+                else:
+                    decodeResults(result_message.tid, kwargs['fid'], data_bytes)
+            else:
+                closeFid(result_message.tid, kwargs['fid'])
+                errback(OperationFailure('Failed to list shares: Unable to retrieve shared device list', messages_history))
+
+        def decodeResults(tid, fid, data_bytes):
+            shares_count = struct.unpack('<I', data_bytes[36:40])[0]
+            results = [ ]     # A list of SharedDevice instances
+            offset = 36 + 12  # You need to study the byte stream to understand the meaning of these constants
+            for i in range(0, shares_count):
+                results.append(SharedDevice(struct.unpack('<I', data_bytes[offset+4:offset+8])[0], None, None))
+                offset += 12
+
+            for i in range(0, shares_count):
+                max_length, _, length = struct.unpack('<III', data_bytes[offset:offset+12])
+                offset += 12
+                results[i].name = unicode(data_bytes[offset:offset+length*2-2], 'UTF-16LE')
+
+                if length % 2 != 0:
+                    offset += (length * 2 + 2)
+                else:
+                    offset += (length * 2)
+
+                max_length, _, length = struct.unpack('<III', data_bytes[offset:offset+12])
+                offset += 12
+                results[i].comments = unicode(data_bytes[offset:offset+length*2-2], 'UTF-16LE')
+
+                if length % 2 != 0:
+                    offset += (length * 2 + 2)
+                else:
+                    offset += (length * 2)
+
+            closeFid(tid, fid)
+            callback(results)
+
+        def sendReadRequest(tid, fid, data_bytes):
+            read_count = min(4280, self.max_raw_size - 2)
+            m = SMBMessage(self, ComReadAndxRequest(fid = fid,
+                                              offset = 0,
+                                              max_return_bytes_count = read_count,
+                                              min_return_bytes_count = read_count))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, readCB, errback, fid = fid, data_bytes = data_bytes)
+
+        def readCB(read_message, **kwargs):
+            messages_history.append(read_message)
+            if not read_message.status.hasError:
+                data_bytes = read_message.payload.data
+
+                if ord(data_bytes[3]) & 0x02 == 0:
+                    sendReadRequest(read_message.tid, kwargs['fid'], kwargs['data_bytes'] + data_bytes[24:])
+                else:
+                    decodeResults(read_message.tid, kwargs['fid'], kwargs['data_bytes'] + data_bytes[24:])
+            else:
+                closeFid(read_message.tid, kwargs['fid'])
+                errback(OperationFailure('Failed to list shares: Unable to retrieve shared device list', messages_history))
+
+        def closeFid(tid, fid):
+            m = SMBMessage(self, ComCloseRequest(fid))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            messages_history.append(m)
+
+        def connectCB(connect_message, **kwargs):
+            messages_history.append(connect_message)
+            if not connect_message.status.hasError:
+                self.connected_trees[path] = connect_message.tid
+                connectSrvSvc(connect_message.tid)
+            else:
+                errback(OperationFailure('Failed to list shares: Unable to connect to IPC$', messages_history))
+
+        m = SMBMessage(self, ComTreeConnectAndxRequest(r'\\%s\%s' % ( self.remote_name.upper(), path ), SERVICE_ANY, ''))
+        self._sendSMBMessage(m)
+        self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectCB, errback, path = path)
+        messages_history.append(m)
+
+    def _listPath_SMB1(self, service_name, path, callback, errback, search, pattern, timeout = 30):
+        if not self.has_authenticated:
+            raise NotReadyError('SMB connection not authenticated')
+
+        expiry_time = time.time() + timeout
+        path = path.replace('/', '\\')
+        if not path.endswith('\\'):
+            path += '\\'
+        messages_history = [ ]
+        results = [ ]
+
+        def sendFindFirst(tid, support_dfs=False):
+            setup_bytes = struct.pack('<H', 0x0001)  # TRANS2_FIND_FIRST2 sub-command. See [MS-CIFS]: 2.2.6.2.1
+            params_bytes = \
+                struct.pack('<HHHHI',
+                            search & 0xFFFF, # SearchAttributes (need to restrict the values due to introduction of SMB_FILE_ATTRIBUTE_INCL_NORMAL)
+                            100,    # SearchCount
+                            0x0006, # Flags: SMB_FIND_CLOSE_AT_EOS | SMB_FIND_RETURN_RESUME_KEYS
+                            0x0104, # InfoLevel: SMB_FIND_FILE_BOTH_DIRECTORY_INFO
+                            0x0000) # SearchStorageType (seems to be ignored by Windows)
+            if support_dfs:
+                params_bytes += ("\\" + self.remote_name + "\\" + service_name + path + pattern + '\0').encode('UTF-16LE')
+            else:
+                params_bytes += (path + pattern + '\0').encode('UTF-16LE')
+
+            m = SMBMessage(self, ComTransaction2Request(max_params_count = 10,
+                                                  max_data_count = 16644,
+                                                  max_setup_count = 0,
+                                                  params_bytes = params_bytes,
+                                                  setup_bytes = setup_bytes))
+            m.tid = tid
+            if support_dfs:
+                m.flags2 |= SMB_FLAGS2_DFS
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, findFirstCB, errback, support_dfs=support_dfs)
+            messages_history.append(m)
+
+        def decodeFindStruct(data_bytes):
+            # SMB_FIND_FILE_BOTH_DIRECTORY_INFO structure. See [MS-CIFS]: 2.2.8.1.7 and [MS-SMB]: 2.2.8.1.1
+            info_format = '<IIQQQQQQIIIBB24s'
+            info_size = struct.calcsize(info_format)
+
+            data_length = len(data_bytes)
+            offset = 0
+            while offset < data_length:
+                if offset + info_size > data_length:
+                    return data_bytes[offset:]
+
+                next_offset, _, \
+                create_time, last_access_time, last_write_time, last_attr_change_time, \
+                file_size, alloc_size, file_attributes, filename_length, ea_size, \
+                short_name_length, _, short_name = struct.unpack(info_format, data_bytes[offset:offset+info_size])
+
+                offset2 = offset + info_size
+                if offset2 + filename_length > data_length:
+                    return data_bytes[offset:]
+
+                filename = data_bytes[offset2:offset2+filename_length].decode('UTF-16LE')
+                short_name = short_name.decode('UTF-16LE')
+
+                accept_result = False
+                if (file_attributes & 0xff) in ( 0x00, ATTR_NORMAL ): # Only the first 8-bits are compared. We ignore other bits like temp, compressed, encryption, sparse, indexed, etc
+                    accept_result = (search == SMB_FILE_ATTRIBUTE_NORMAL) or (search & SMB_FILE_ATTRIBUTE_INCL_NORMAL)
+                else:
+                    accept_result = (file_attributes & search) > 0
+                if accept_result:
+                    results.append(SharedFile(convertFILETIMEtoEpoch(create_time), convertFILETIMEtoEpoch(last_access_time),
+                                              convertFILETIMEtoEpoch(last_write_time), convertFILETIMEtoEpoch(last_attr_change_time),
+                                              file_size, alloc_size, file_attributes, short_name, filename))
+
+                if next_offset:
+                    offset += next_offset
+                else:
+                    break
+            return ''
+
+        def findFirstCB(find_message, **kwargs):
+            messages_history.append(find_message)
+            if not find_message.status.hasError:
+                if not kwargs.has_key('total_count'):
+                    # TRANS2_FIND_FIRST2 response. [MS-CIFS]: 2.2.6.2.2
+                    sid, search_count, end_of_search, _, last_name_offset = struct.unpack('<HHHHH', find_message.payload.params_bytes[:10])
+                    kwargs.update({ 'sid': sid, 'end_of_search': end_of_search, 'last_name_offset': last_name_offset, 'data_buf': '' })
+                else:
+                    sid, end_of_search, last_name_offset = kwargs['sid'], kwargs['end_of_search'], kwargs['last_name_offset']
+
+                send_next = True
+                if find_message.payload.data_bytes:
+                    d = decodeFindStruct(kwargs['data_buf'] + find_message.payload.data_bytes)
+                    if not kwargs.has_key('data_count'):
+                        if len(find_message.payload.data_bytes) != find_message.payload.total_data_count:
+                            kwargs.update({ 'data_count': len(find_message.payload.data_bytes),
+                                            'total_count': find_message.payload.total_data_count,
+                                            'data_buf': d,
+                                            })
+                            send_next = False
+                    else:
+                        kwargs['data_count'] += len(find_message.payload.data_bytes)
+                        kwargs['total_count'] = min(find_message.payload.total_data_count, kwargs['total_count'])
+                        kwargs['data_buf'] = d
+                        if kwargs['data_count'] != kwargs['total_count']:
+                            send_next = False
+
+                if not send_next:
+                    self.pending_requests[find_message.mid] = _PendingRequest(find_message.mid, expiry_time, findFirstCB, errback, **kwargs)
+                elif end_of_search:
+                    callback(results)
+                else:
+                    sendFindNext(find_message.tid, sid, 0, results[-1].filename, kwargs.get('support_dfs', False))
+            else:
+                if find_message.status.internal_value == 0xC000000F:  # [MS-ERREF]: STATUS_NO_SUCH_FILE
+                    # Remote server returns STATUS_NO_SUCH_FILE error so we assume that the search returns no matching files
+                    callback([ ])
+                else:
+                    errback(OperationFailure('Failed to list %s on %s: Unable to retrieve file list' % ( path, service_name ), messages_history))
+
+        def sendFindNext(tid, sid, resume_key, resume_file, support_dfs=False):
+            setup_bytes = struct.pack('<H', 0x0002)  # TRANS2_FIND_NEXT2 sub-command. See [MS-CIFS]: 2.2.6.3.1
+            params_bytes = \
+                struct.pack('<HHHIH',
+                            sid,        # SID
+                            100,        # SearchCount
+                            0x0104,     # InfoLevel: SMB_FIND_FILE_BOTH_DIRECTORY_INFO
+                            resume_key, # ResumeKey
+                            0x0006)     # Flags: SMB_FIND_RETURN_RESUME_KEYS | SMB_FIND_CLOSE_AT_EOS
+            params_bytes += (resume_file+'\0').encode('UTF-16LE')
+
+            m = SMBMessage(self, ComTransaction2Request(max_params_count = 10,
+                                                  max_data_count = 16644,
+                                                  max_setup_count = 0,
+                                                  params_bytes = params_bytes,
+                                                  setup_bytes = setup_bytes))
+            m.tid = tid
+            if support_dfs:
+                m.flags2 |= SMB_FLAGS2_DFS
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, findNextCB, errback, sid = sid, support_dfs = support_dfs)
+            messages_history.append(m)
+
+        def findNextCB(find_message, **kwargs):
+            messages_history.append(find_message)
+            if not find_message.status.hasError:
+                if not kwargs.has_key('total_count'):
+                    # TRANS2_FIND_NEXT2 response. [MS-CIFS]: 2.2.6.3.2
+                    search_count, end_of_search, _, last_name_offset = struct.unpack('<HHHH', find_message.payload.params_bytes[:8])
+                    kwargs.update({ 'end_of_search': end_of_search, 'last_name_offset': last_name_offset, 'data_buf': '' })
+                else:
+                    end_of_search, last_name_offset = kwargs['end_of_search'], kwargs['last_name_offset']
+
+                send_next = True
+                if find_message.payload.data_bytes:
+                    d = decodeFindStruct(kwargs['data_buf'] + find_message.payload.data_bytes)
+                    if not kwargs.has_key('data_count'):
+                        if len(find_message.payload.data_bytes) != find_message.payload.total_data_count:
+                            kwargs.update({ 'data_count': len(find_message.payload.data_bytes),
+                                            'total_count': find_message.payload.total_data_count,
+                                            'data_buf': d,
+                                            })
+                            send_next = False
+                    else:
+                        kwargs['data_count'] += len(find_message.payload.data_bytes)
+                        kwargs['total_count'] = min(find_message.payload.total_data_count, kwargs['total_count'])
+                        kwargs['data_buf'] = d
+                        if kwargs['data_count'] != kwargs['total_count']:
+                            send_next = False
+
+                if not send_next:
+                    self.pending_requests[find_message.mid] = _PendingRequest(find_message.mid, expiry_time, findNextCB, errback, **kwargs)
+                elif end_of_search:
+                    callback(results)
+                else:
+                    sendFindNext(find_message.tid, kwargs['sid'], 0, results[-1].filename, kwargs.get('support_dfs', False))
+            else:
+                errback(OperationFailure('Failed to list %s on %s: Unable to retrieve file list' % ( path, service_name ), messages_history))
+
+        def sendDFSReferral(tid):
+            setup_bytes = struct.pack('<H', 0x0010)  # TRANS2_GET_DFS_REFERRAL sub-command. See [MS-CIFS]: 2.2.6.16.1
+            params_bytes = struct.pack('<H', 3)      # Max referral level 3
+            params_bytes += ("\\" + self.remote_name + "\\" + service_name).encode('UTF-16LE')
+
+            m = SMBMessage(self, ComTransaction2Request(max_params_count = 10,
+                                                  max_data_count = 16644,
+                                                  max_setup_count = 0,
+                                                  params_bytes = params_bytes,
+                                                  setup_bytes = setup_bytes))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, dfsReferralCB, errback)
+            messages_history.append(m)
+
+        def dfsReferralCB(dfs_message, **kwargs):
+            sendFindFirst(dfs_message.tid, True)
+
+        if not self.connected_trees.has_key(service_name):
+            def connectCB(connect_message, **kwargs):
+                messages_history.append(connect_message)
+                if not connect_message.status.hasError:
+                    self.connected_trees[service_name] = connect_message.tid
+                    if connect_message.payload.optional_support & SMB_TREE_CONNECTX_SUPPORT_DFS:
+                        sendDFSReferral(connect_message.tid)
+                    else:
+                        sendFindFirst(connect_message.tid, False)
+                else:
+                    errback(OperationFailure('Failed to list %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history))
+
+            m = SMBMessage(self, ComTreeConnectAndxRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name ), SERVICE_ANY, ''))
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectCB, errback, path = service_name)
+            messages_history.append(m)
+        else:
+            sendFindFirst(self.connected_trees[service_name])
+
+    def _getAttributes_SMB1(self, service_name, path, callback, errback, timeout = 30):
+        if not self.has_authenticated:
+            raise NotReadyError('SMB connection not authenticated')
+
+        expiry_time = time.time() + timeout
+        path = path.replace('/', '\\')
+        if path.startswith('\\'):
+            path = path[1:]
+        if path.endswith('\\'):
+            path = path[:-1]
+        messages_history = [ ]
+
+        def sendQuery(tid):
+            setup_bytes = struct.pack('<H', 0x0005)  # TRANS2_QUERY_PATH_INFORMATION sub-command. See [MS-CIFS]: 2.2.6.6.1
+            params_bytes = \
+                struct.pack('<HI',
+                            0x0107, # SMB_QUERY_FILE_ALL_INFO ([MS-CIFS] 2.2.2.3.3)
+                            0x0000) # Reserved
+            params_bytes += (path + '\0').encode('UTF-16LE')
+
+            m = SMBMessage(self, ComTransaction2Request(max_params_count = 2,
+                                                  max_data_count = 65535,
+                                                  max_setup_count = 0,
+                                                  params_bytes = params_bytes,
+                                                  setup_bytes = setup_bytes))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, queryCB, errback)
+            messages_history.append(m)
+
+        def queryCB(query_message, **kwargs):
+            messages_history.append(query_message)
+            if not query_message.status.hasError:
+                info_format = '<QQQQIIQQ'
+                info_size = struct.calcsize(info_format)
+                create_time, last_access_time, last_write_time, last_attr_change_time, \
+                file_attributes, _, alloc_size, file_size = struct.unpack(info_format, query_message.payload.data_bytes[:info_size])
+                filename = self._extractLastPathComponent(unicode(path))
+
+                info = SharedFile(convertFILETIMEtoEpoch(create_time), convertFILETIMEtoEpoch(last_access_time), convertFILETIMEtoEpoch(last_write_time), convertFILETIMEtoEpoch(last_attr_change_time),
+                                  file_size, alloc_size, file_attributes, filename, filename)
+                callback(info)
+            else:
+                errback(OperationFailure('Failed to get attributes for %s on %s: Read failed' % ( path, service_name ), messages_history))
+
+        if not self.connected_trees.has_key(service_name):
+            def connectCB(connect_message, **kwargs):
+                messages_history.append(connect_message)
+                if not connect_message.status.hasError:
+                    self.connected_trees[service_name] = connect_message.tid
+                    sendQuery(connect_message.tid)
+                else:
+                    errback(OperationFailure('Failed to get attributes for %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history))
+
+            m = SMBMessage(self, ComTreeConnectAndxRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name ), SERVICE_ANY, ''))
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectCB, errback, path = service_name)
+            messages_history.append(m)
+        else:
+            sendQuery(self.connected_trees[service_name])
+
+    def _getSecurity_SMB1(self, service_name, path_file_pattern, callback, errback, timeout = 30):
+        raise NotReadyError('getSecurity is not yet implemented for SMB1')
+
+    def _retrieveFile_SMB1(self, service_name, path, file_obj, callback, errback, timeout = 30):
+        return self._retrieveFileFromOffset(service_name, path, file_obj, callback, errback, 0L, -1L, timeout)
+
+    def _retrieveFileFromOffset_SMB1(self, service_name, path, file_obj, callback, errback, starting_offset, max_length, timeout = 30):
+        if not self.has_authenticated:
+            raise NotReadyError('SMB connection not authenticated')
+
+        path = path.replace('/', '\\')
+        messages_history = [ ]
+
+        def sendOpen(tid):
+            m = SMBMessage(self, ComOpenAndxRequest(filename = path,
+                                              access_mode = 0x0040,  # Sharing mode: Deny nothing to others
+                                              open_mode = 0x0001,    # Failed if file does not exist
+                                              search_attributes = SMB_FILE_ATTRIBUTE_HIDDEN | SMB_FILE_ATTRIBUTE_SYSTEM,
+                                              timeout = timeout * 1000))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, openCB, errback)
+            messages_history.append(m)
+
+        def openCB(open_message, **kwargs):
+            messages_history.append(open_message)
+            if not open_message.status.hasError:
+                if max_length == 0:
+                    closeFid(open_message.tid, open_message.payload.fid)
+                    callback(( file_obj, open_message.payload.file_attributes, 0L ))
+                else:
+                    sendRead(open_message.tid, open_message.payload.fid, starting_offset, open_message.payload.file_attributes, 0L, max_length)
+            else:
+                errback(OperationFailure('Failed to retrieve %s on %s: Unable to open file' % ( path, service_name ), messages_history))
+
+        def sendRead(tid, fid, offset, file_attributes, read_len, remaining_len):
+            read_count = self.max_raw_size - 2
+            m = SMBMessage(self, ComReadAndxRequest(fid = fid,
+                                              offset = offset,
+                                              max_return_bytes_count = read_count,
+                                              min_return_bytes_count = min(0xFFFF, read_count)))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, readCB, errback, fid = fid, offset = offset, file_attributes = file_attributes,
+                                                           read_len = read_len, remaining_len = remaining_len)
+
+        def readCB(read_message, **kwargs):
+            # To avoid crazy memory usage when retrieving large files, we do not save every read_message in messages_history.
+            if not read_message.status.hasError:
+                read_len = kwargs['read_len']
+                remaining_len = kwargs['remaining_len']
+                data_len = read_message.payload.data_length
+                if max_length > 0:
+                    if data_len > remaining_len:
+                        file_obj.write(read_message.payload.data[:remaining_len])
+                        read_len += remaining_len
+                        remaining_len = 0
+                    else:
+                        file_obj.write(read_message.payload.data)
+                        remaining_len -= data_len
+                        read_len += data_len
+                else:
+                    file_obj.write(read_message.payload.data)
+                    read_len += data_len
+
+                if (max_length > 0 and remaining_len <= 0) or data_len < (self.max_raw_size - 2):
+                    closeFid(read_message.tid, kwargs['fid'])
+                    callback(( file_obj, kwargs['file_attributes'], read_len ))  # Note that this is a tuple of 3-elements
+                else:
+                    sendRead(read_message.tid, kwargs['fid'], kwargs['offset']+data_len, kwargs['file_attributes'], read_len, remaining_len)
+            else:
+                messages_history.append(read_message)
+                closeFid(read_message.tid, kwargs['fid'])
+                errback(OperationFailure('Failed to retrieve %s on %s: Read failed' % ( path, service_name ), messages_history))
+
+        def closeFid(tid, fid):
+            m = SMBMessage(self, ComCloseRequest(fid))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            messages_history.append(m)
+
+        if not self.connected_trees.has_key(service_name):
+            def connectCB(connect_message, **kwargs):
+                messages_history.append(connect_message)
+                if not connect_message.status.hasError:
+                    self.connected_trees[service_name] = connect_message.tid
+                    sendOpen(connect_message.tid)
+                else:
+                    errback(OperationFailure('Failed to retrieve %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history))
+
+            m = SMBMessage(self, ComTreeConnectAndxRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name ), SERVICE_ANY, ''))
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, connectCB, errback, path = service_name)
+            messages_history.append(m)
+        else:
+            sendOpen(self.connected_trees[service_name])
+
+    def _storeFile_SMB1(self, service_name, path, file_obj, callback, errback, timeout = 30):
+        self._storeFileFromOffset_SMB1(service_name, path, file_obj, callback, errback, 0L, True, timeout)
+
+    def _storeFileFromOffset_SMB1(self, service_name, path, file_obj, callback, errback, starting_offset, truncate = False, timeout = 30):
+        if not self.has_authenticated:
+            raise NotReadyError('SMB connection not authenticated')
+
+        path = path.replace('/', '\\')
+        messages_history = [ ]
+
+        def sendOpen(tid):
+            m = SMBMessage(self, ComOpenAndxRequest(filename = path,
+                                              access_mode = 0x0041,  # Sharing mode: Deny nothing to others + Open for writing
+                                              open_mode = 0x0012 if truncate else 0x0011,    # Create file if file does not exist. Overwrite or append depending on truncate parameter.
+                                              search_attributes = SMB_FILE_ATTRIBUTE_HIDDEN | SMB_FILE_ATTRIBUTE_SYSTEM,
+                                              timeout = timeout * 1000))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, openCB, errback)
+            messages_history.append(m)
+
+        def openCB(open_message, **kwargs):
+            messages_history.append(open_message)
+            if not open_message.status.hasError:
+                sendWrite(open_message.tid, open_message.payload.fid, starting_offset)
+            else:
+                errback(OperationFailure('Failed to store %s on %s: Unable to open file' % ( path, service_name ), messages_history))
+
+        def sendWrite(tid, fid, offset):
+            # For message signing, the total SMB message size must be not exceed the max_buffer_size. Non-message signing does not have this limitation
+            write_count = min((self.is_signing_active and (self.max_buffer_size-64)) or self.max_raw_size, 0xFFFF-1)  # Need to minus 1 byte from 0xFFFF because of the first NULL byte in the ComWriteAndxRequest message data
+            data_bytes = file_obj.read(write_count)
+            data_len = len(data_bytes)
+            if data_len > 0:
+                m = SMBMessage(self, ComWriteAndxRequest(fid = fid, offset = offset, data_bytes = data_bytes))
+                m.tid = tid
+                self._sendSMBMessage(m)
+                self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, writeCB, errback, fid = fid, offset = offset+data_len)
+            else:
+                closeFid(tid, fid)
+                callback(( file_obj, offset ))  # Note that this is a tuple of 2-elements
+
+        def writeCB(write_message, **kwargs):
+            # To avoid crazy memory usage when saving large files, we do not save every write_message in messages_history.
+            if not write_message.status.hasError:
+                sendWrite(write_message.tid, kwargs['fid'], kwargs['offset'])
+            else:
+                messages_history.append(write_message)
+                closeFid(write_message.tid, kwargs['fid'])
+                errback(OperationFailure('Failed to store %s on %s: Write failed' % ( path, service_name ), messages_history))
+
+        def closeFid(tid, fid):
+            m = SMBMessage(self, ComCloseRequest(fid))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            messages_history.append(m)
+
+        if not self.connected_trees.has_key(service_name):
+            def connectCB(connect_message, **kwargs):
+                messages_history.append(connect_message)
+                if not connect_message.status.hasError:
+                    self.connected_trees[service_name] = connect_message.tid
+                    sendOpen(connect_message.tid)
+                else:
+                    errback(OperationFailure('Failed to store %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history))
+
+            m = SMBMessage(self, ComTreeConnectAndxRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name ), SERVICE_ANY, ''))
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, connectCB, errback, path = service_name)
+            messages_history.append(m)
+        else:
+            sendOpen(self.connected_trees[service_name])
+
+    def _deleteFiles_SMB1(self, service_name, path_file_pattern, callback, errback, timeout = 30):
+        if not self.has_authenticated:
+            raise NotReadyError('SMB connection not authenticated')
+
+        path = path_file_pattern.replace('/', '\\')
+        messages_history = [ ]
+
+        def sendDelete(tid):
+            m = SMBMessage(self, ComDeleteRequest(filename_pattern = path,
+                                            search_attributes = SMB_FILE_ATTRIBUTE_HIDDEN | SMB_FILE_ATTRIBUTE_SYSTEM))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, deleteCB, errback)
+            messages_history.append(m)
+
+        def deleteCB(delete_message, **kwargs):
+            messages_history.append(delete_message)
+            if not delete_message.status.hasError:
+                callback(path_file_pattern)
+            else:
+                errback(OperationFailure('Failed to store %s on %s: Delete failed' % ( path, service_name ), messages_history))
+
+        if not self.connected_trees.has_key(service_name):
+            def connectCB(connect_message, **kwargs):
+                messages_history.append(connect_message)
+                if not connect_message.status.hasError:
+                    self.connected_trees[service_name] = connect_message.tid
+                    sendDelete(connect_message.tid)
+                else:
+                    errback(OperationFailure('Failed to delete %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history))
+
+            m = SMBMessage(self, ComTreeConnectAndxRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name ), SERVICE_ANY, ''))
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, connectCB, errback, path = service_name)
+            messages_history.append(m)
+        else:
+            sendDelete(self.connected_trees[service_name])
+
+    def _resetFileAttributes_SMB1(self, service_name, path_file_pattern, callback, errback, timeout = 30):
+        raise NotReadyError('resetFileAttributes is not yet implemented for SMB1')
+
+    def _createDirectory_SMB1(self, service_name, path, callback, errback, timeout = 30):
+        if not self.has_authenticated:
+            raise NotReadyError('SMB connection not authenticated')
+
+        path = path.replace('/', '\\')
+        messages_history = [ ]
+
+        def sendCreate(tid):
+            m = SMBMessage(self, ComCreateDirectoryRequest(path))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, createCB, errback)
+            messages_history.append(m)
+
+        def createCB(create_message, **kwargs):
+            messages_history.append(create_message)
+            if not create_message.status.hasError:
+                callback(path)
+            else:
+                errback(OperationFailure('Failed to create directory %s on %s: Create failed' % ( path, service_name ), messages_history))
+
+        if not self.connected_trees.has_key(service_name):
+            def connectCB(connect_message, **kwargs):
+                messages_history.append(connect_message)
+                if not connect_message.status.hasError:
+                    self.connected_trees[service_name] = connect_message.tid
+                    sendCreate(connect_message.tid)
+                else:
+                    errback(OperationFailure('Failed to create directory %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history))
+
+            m = SMBMessage(self, ComTreeConnectAndxRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name ), SERVICE_ANY, ''))
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, connectCB, errback, path = service_name)
+            messages_history.append(m)
+        else:
+            sendCreate(self.connected_trees[service_name])
+
+    def _deleteDirectory_SMB1(self, service_name, path, callback, errback, timeout = 30):
+        if not self.has_authenticated:
+            raise NotReadyError('SMB connection not authenticated')
+
+        path = path.replace('/', '\\')
+        messages_history = [ ]
+
+        def sendDelete(tid):
+            m = SMBMessage(self, ComDeleteDirectoryRequest(path))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, deleteCB, errback)
+            messages_history.append(m)
+
+        def deleteCB(delete_message, **kwargs):
+            messages_history.append(delete_message)
+            if not delete_message.status.hasError:
+                callback(path)
+            else:
+                errback(OperationFailure('Failed to delete directory %s on %s: Delete failed' % ( path, service_name ), messages_history))
+
+        if not self.connected_trees.has_key(service_name):
+            def connectCB(connect_message, **kwargs):
+                messages_history.append(connect_message)
+                if not connect_message.status.hasError:
+                    self.connected_trees[service_name] = connect_message.tid
+                    sendDelete(connect_message.tid)
+                else:
+                    errback(OperationFailure('Failed to delete %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history))
+
+            m = SMBMessage(self, ComTreeConnectAndxRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name ), SERVICE_ANY, ''))
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, connectCB, errback, path = service_name)
+            messages_history.append(m)
+        else:
+            sendDelete(self.connected_trees[service_name])
+
+    def _rename_SMB1(self, service_name, old_path, new_path, callback, errback, timeout = 30):
+        if not self.has_authenticated:
+            raise NotReadyError('SMB connection not authenticated')
+
+        new_path = new_path.replace('/', '\\')
+        old_path = old_path.replace('/', '\\')
+        messages_history = [ ]
+
+        def sendRename(tid):
+            m = SMBMessage(self, ComRenameRequest(old_path = old_path,
+                                            new_path = new_path,
+                                            search_attributes = SMB_FILE_ATTRIBUTE_HIDDEN | SMB_FILE_ATTRIBUTE_SYSTEM))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, renameCB, errback)
+            messages_history.append(m)
+
+        def renameCB(rename_message, **kwargs):
+            messages_history.append(rename_message)
+            if not rename_message.status.hasError:
+                callback(( old_path, new_path ))  # Note that this is a tuple of 2-elements
+            else:
+                errback(OperationFailure('Failed to rename %s on %s: Rename failed' % ( old_path, service_name ), messages_history))
+
+        if not self.connected_trees.has_key(service_name):
+            def connectCB(connect_message, **kwargs):
+                messages_history.append(connect_message)
+                if not connect_message.status.hasError:
+                    self.connected_trees[service_name] = connect_message.tid
+                    sendRename(connect_message.tid)
+                else:
+                    errback(OperationFailure('Failed to rename %s on %s: Unable to connect to shared device' % ( old_path, service_name ), messages_history))
+
+            m = SMBMessage(self, ComTreeConnectAndxRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name ), SERVICE_ANY, ''))
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, connectCB, errback, path = service_name)
+            messages_history.append(m)
+        else:
+            sendRename(self.connected_trees[service_name])
+
+    def _listSnapshots_SMB1(self, service_name, path, callback, errback, timeout = 30):
+        if not self.has_authenticated:
+            raise NotReadyError('SMB connection not authenticated')
+
+        expiry_time = time.time() + timeout
+        path = path.replace('/', '\\')
+        if not path.endswith('\\'):
+            path += '\\'
+        messages_history = [ ]
+        results = [ ]
+
+        def sendOpen(tid):
+            m = SMBMessage(self, ComOpenAndxRequest(filename = path,
+                                              access_mode = 0x0040,  # Sharing mode: Deny nothing to others
+                                              open_mode = 0x0001,    # Failed if file does not exist
+                                              search_attributes = 0,
+                                              timeout = timeout * 1000))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, openCB, errback)
+            messages_history.append(m)
+
+        def openCB(open_message, **kwargs):
+            messages_history.append(open_message)
+            if not open_message.status.hasError:
+                sendEnumSnapshots(open_message.tid, open_message.payload.fid)
+            else:
+                errback(OperationFailure('Failed to list snapshots %s on %s: Unable to open path' % ( path, service_name ), messages_history))
+
+        def sendEnumSnapshots(tid, fid):
+            # [MS-CIFS]: 2.2.7.2
+            # [MS-SMB]: 2.2.7.2.1
+            setup_bytes = struct.pack('<IHBB',
+                                      0x00144064,  # [MS-SMB]: 2.2.7.2.1
+                                      fid,         # FID
+                                      0x01,        # IsFctl
+                                      0)           # IsFlags
+            m = SMBMessage(self, ComNTTransactRequest(function = 0x0002,  # NT_TRANSACT_IOCTL. [MS-CIFS]: 2.2.7.2.1
+                                                max_params_count = 0,
+                                                max_data_count = 0xFFFF,
+                                                max_setup_count = 0,
+                                                setup_bytes = setup_bytes))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, enumSnapshotsCB, errback, tid = tid, fid = fid)
+            messages_history.append(m)
+
+        def enumSnapshotsCB(enum_message, **kwargs):
+            messages_history.append(enum_message)
+            if not enum_message.status.hasError:
+                results = [ ]
+                snapshots_count = struct.unpack('<I', enum_message.payload.data_bytes[4:8])[0]
+                for i in range(0, snapshots_count):
+                    s = enum_message.payload.data_bytes[12+i*50:12+48+i*50].decode('UTF-16LE')
+                    results.append(datetime(*map(int, ( s[5:9], s[10:12], s[13:15], s[16:18], s[19:21], s[22:24] ))))
+                closeFid(kwargs['tid'], kwargs['fid'])
+                callback(results)
+            else:
+                closeFid(kwargs['tid'], kwargs['fid'])
+                errback(OperationFailure('Failed to list snapshots %s on %s: Unable to list snapshots on path' % ( path, service_name ), messages_history))
+
+        def closeFid(tid, fid):
+            m = SMBMessage(self, ComCloseRequest(fid))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            messages_history.append(m)
+
+        if not self.connected_trees.has_key(service_name):
+            def connectCB(connect_message, **kwargs):
+                messages_history.append(connect_message)
+                if not connect_message.status.hasError:
+                    self.connected_trees[service_name] = connect_message.tid
+                    sendOpen(connect_message.tid)
+                else:
+                    errback(OperationFailure('Failed to list snapshots %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history))
+
+            m = SMBMessage(self, ComTreeConnectAndxRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name ), SERVICE_ANY, ''))
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectCB, errback, path = service_name)
+            messages_history.append(m)
+        else:
+            sendOpen(self.connected_trees[service_name])
+
+    def _echo_SMB1(self, data, callback, errback, timeout = 30):
+        messages_history = [ ]
+
+        if not isinstance(data, type(b'')):
+            raise TypeError('Echo data must be %s not %s' % (type(b'').__name__, type(data).__name__))
+
+        def echoCB(echo_message, **kwargs):
+            messages_history.append(echo_message)
+            if not echo_message.status.hasError:
+                callback(echo_message.payload.data)
+            else:
+                errback(OperationFailure('Echo failed', messages_history))
+
+        m = SMBMessage(self, ComEchoRequest(echo_data = data))
+        self._sendSMBMessage(m)
+        self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, echoCB, errback)
+        messages_history.append(m)
+
+    def _extractLastPathComponent(self, path):
+        return path.replace('\\', '/').split('/')[-1]
+
+
+class SharedDevice:
+    """
+    Contains information about a single shared device on the remote server.
+
+    The following attributes are available:
+
+    * name : An unicode string containing the name of the shared device
+    * comments : An unicode string containing the user description of the shared device
+    """
+
+    # The following constants are taken from [MS-SRVS]: 2.2.2.4
+    # They are used to identify the type of shared resource from the results from the NetrShareEnum in Server Service RPC
+    DISK_TREE   = 0x00
+    PRINT_QUEUE = 0x01
+    COMM_DEVICE = 0x02
+    IPC         = 0x03
+
+    def __init__(self, type, name, comments):
+        self._type = type
+        self.name = name         #: An unicode string containing the name of the shared device
+        self.comments = comments #: An unicode string containing the user description of the shared device
+
+    @property
+    def type(self):
+        """
+        Returns one of the following integral constants.
+         - SharedDevice.DISK_TREE
+         - SharedDevice.PRINT_QUEUE
+         - SharedDevice.COMM_DEVICE
+         - SharedDevice.IPC
+        """
+        return self._type & 0xFFFF
+
+    @property
+    def isSpecial(self):
+        """
+        Returns True if this shared device is a special share reserved for interprocess communication (IPC$)
+        or remote administration of the server (ADMIN$). Can also refer to administrative shares such as
+        C$, D$, E$, and so forth
+        """
+        return bool(self._type & 0x80000000)
+
+    @property
+    def isTemporary(self):
+        """
+        Returns True if this is a temporary share that is not persisted for creation each time the file server initializes.
+        """
+        return bool(self._type & 0x40000000)
+
+    def __unicode__(self):
+        return u'Shared device: %s (type:0x%02x comments:%s)' % (self.name, self.type, self.comments )
+
+
+class SharedFile:
+    """
+    Contain information about a file/folder entry that is shared on the shared device.
+
+    As an application developer, you should not need to instantiate a *SharedFile* instance directly in your application.
+    These *SharedFile* instances are usually returned via a call to *listPath* method in :doc:`smb.SMBProtocol.SMBProtocolFactory<smb_SMBProtocolFactory>`.
+
+    If you encounter *SharedFile* instance where its short_name attribute is empty but the filename attribute contains a short name which does not correspond
+    to any files/folders on your remote shared device, it could be that the original filename on the file/folder entry on the shared device contains
+    one of these prohibited characters: "\/[]:+|<>=;?,* (see [MS-CIFS]: 2.2.1.1.1 for more details).
+
+    The following attributes are available:
+
+    * create_time : Float value in number of seconds since 1970-01-01 00:00:00 to the time of creation of this file resource on the remote server
+    * last_access_time : Float value in number of seconds since 1970-01-01 00:00:00 to the time of last access of this file resource on the remote server
+    * last_write_time : Float value in number of seconds since 1970-01-01 00:00:00 to the time of last modification of this file resource on the remote server
+    * last_attr_change_time : Float value in number of seconds since 1970-01-01 00:00:00 to the time of last attribute change of this file resource on the remote server
+    * file_size : File size in number of bytes
+    * alloc_size : Total number of bytes allocated to store this file
+    * file_attributes : A SMB_EXT_FILE_ATTR integer value. See [MS-CIFS]: 2.2.1.2.3. You can perform bit-wise tests to determine the status of the file using the ATTR_xxx constants in smb_constants.py.
+    * short_name : Unicode string containing the short name of this file (usually in 8.3 notation)
+    * filename : Unicode string containing the long filename of this file. Each OS has a limit to the length of this file name. On Windows, it is 256 characters.
+    * file_id : Long value representing the file reference number for the file. If the remote system does not support this field, this field will be None or 0. See [MS-FSCC]: 2.4.17
+    """
+
+    def __init__(self, create_time, last_access_time, last_write_time, last_attr_change_time, file_size, alloc_size, file_attributes, short_name, filename, file_id=None):
+        self.create_time = create_time  #: Float value in number of seconds since 1970-01-01 00:00:00 to the time of creation of this file resource on the remote server
+        self.last_access_time = last_access_time  #: Float value in number of seconds since 1970-01-01 00:00:00 to the time of last access of this file resource on the remote server
+        self.last_write_time = last_write_time    #: Float value in number of seconds since 1970-01-01 00:00:00 to the time of last modification of this file resource on the remote server
+        self.last_attr_change_time = last_attr_change_time  #: Float value in number of seconds since 1970-01-01 00:00:00 to the time of last attribute change of this file resource on the remote server
+        self.file_size = file_size   #: File size in number of bytes
+        self.alloc_size = alloc_size #: Total number of bytes allocated to store this file
+        self.file_attributes = file_attributes #: A SMB_EXT_FILE_ATTR integer value. See [MS-CIFS]: 2.2.1.2.3. You can perform bit-wise tests to determine the status of the file using the ATTR_xxx constants in smb_constants.py.
+        self.short_name = short_name #: Unicode string containing the short name of this file (usually in 8.3 notation)
+        self.filename = filename     #: Unicode string containing the long filename of this file. Each OS has a limit to the length of this file name. On Windows, it is 256 characters.
+        self.file_id = file_id       #: Long value representing the file reference number for the file. If the remote system does not support this field, this field will be None or 0. See [MS-FSCC]: 2.4.17
+
+    @property
+    def isDirectory(self):
+        """A convenient property to return True if this file resource is a directory on the remote server"""
+        return bool(self.file_attributes & ATTR_DIRECTORY)
+
+    @property
+    def isReadOnly(self):
+        """A convenient property to return True if this file resource is read-only on the remote server"""
+        return bool(self.file_attributes & ATTR_READONLY)
+
+    @property
+    def isNormal(self):
+        """
+        A convenient property to return True if this is a normal file.
+
+        Note that pysmb defines a normal file as a file entry that is not read-only, not hidden, not system, not archive and not a directory.
+        It ignores other attributes like compression, indexed, sparse, temporary and encryption.
+        """
+        return (self.file_attributes==ATTR_NORMAL) or ((self.file_attributes & 0xff)==0)
+
+    def __unicode__(self):
+        return u'Shared file: %s (FileSize:%d bytes, isDirectory:%s)' % ( self.filename, self.file_size, self.isDirectory )
+
+
+class _PendingRequest:
+
+    def __init__(self, mid, expiry_time, callback, errback, **kwargs):
+        self.mid = mid
+        self.expiry_time = expiry_time
+        self.callback = callback
+        self.errback = errback
+        self.kwargs = kwargs
diff --git a/python2/smb/ntlm.py b/python2/smb/ntlm.py
new file mode 100644
index 00000000..ae6fc9e7
--- /dev/null
+++ b/python2/smb/ntlm.py
@@ -0,0 +1,248 @@
+
+import types, hmac, binascii, struct, random
+from utils.pyDes import des
+
+try:
+    import hashlib
+    hashlib.new('md4')
+
+    def MD4(): return hashlib.new('md4')
+except ( ImportError, ValueError ):
+    from utils.md4 import MD4
+
+try:
+    import hashlib
+    def MD5(s): return hashlib.md5(s)
+except ImportError:
+    import md5
+    def MD5(s): return md5.new(s)
+
+################
+# NTLMv2 Methods
+################
+
+# The following constants are defined in accordance to [MS-NLMP]: 2.2.2.5
+
+NTLM_NegotiateUnicode                =  0x00000001
+NTLM_NegotiateOEM                    =  0x00000002
+NTLM_RequestTarget                   =  0x00000004
+NTLM_Unknown9                        =  0x00000008
+NTLM_NegotiateSign                   =  0x00000010
+NTLM_NegotiateSeal                   =  0x00000020
+NTLM_NegotiateDatagram               =  0x00000040
+NTLM_NegotiateLanManagerKey          =  0x00000080
+NTLM_Unknown8                        =  0x00000100
+NTLM_NegotiateNTLM                   =  0x00000200
+NTLM_NegotiateNTOnly                 =  0x00000400
+NTLM_Anonymous                       =  0x00000800
+NTLM_NegotiateOemDomainSupplied      =  0x00001000
+NTLM_NegotiateOemWorkstationSupplied =  0x00002000
+NTLM_Unknown6                        =  0x00004000
+NTLM_NegotiateAlwaysSign             =  0x00008000
+NTLM_TargetTypeDomain                =  0x00010000
+NTLM_TargetTypeServer                =  0x00020000
+NTLM_TargetTypeShare                 =  0x00040000
+NTLM_NegotiateExtendedSecurity       =  0x00080000
+NTLM_NegotiateIdentify               =  0x00100000
+NTLM_Unknown5                        =  0x00200000
+NTLM_RequestNonNTSessionKey          =  0x00400000
+NTLM_NegotiateTargetInfo             =  0x00800000
+NTLM_Unknown4                        =  0x01000000
+NTLM_NegotiateVersion                =  0x02000000
+NTLM_Unknown3                        =  0x04000000
+NTLM_Unknown2                        =  0x08000000
+NTLM_Unknown1                        =  0x10000000
+NTLM_Negotiate128                    =  0x20000000
+NTLM_NegotiateKeyExchange            =  0x40000000
+NTLM_Negotiate56                     =  0x80000000
+
+NTLM_FLAGS = NTLM_NegotiateUnicode | \
+             NTLM_RequestTarget | \
+             NTLM_NegotiateNTLM | \
+             NTLM_NegotiateAlwaysSign | \
+             NTLM_NegotiateExtendedSecurity | \
+             NTLM_NegotiateTargetInfo | \
+             NTLM_NegotiateVersion | \
+             NTLM_Negotiate128 | \
+             NTLM_NegotiateKeyExchange | \
+             NTLM_Negotiate56
+
+def generateNegotiateMessage():
+    """
+    References:
+    ===========
+    - [MS-NLMP]: 2.2.1.1
+    """
+    s = struct.pack('<8sII8s8s8s',
+                    'NTLMSSP\0', 0x01, NTLM_FLAGS,
+                    '\0' * 8,  # Domain
+                    '\0' * 8,  # Workstation
+                    '\x06\x00\x72\x17\x00\x00\x00\x0F')  # Version [MS-NLMP]: 2.2.2.10
+    return s
+
+
+def generateAuthenticateMessage(challenge_flags, nt_response, lm_response, session_key, user, domain = 'WORKGROUP', workstation = 'LOCALHOST'):
+    """
+    References:
+    ===========
+    - [MS-NLMP]: 2.2.1.3
+    """
+    FORMAT = '<8sIHHIHHIHHIHHIHHIHHII'
+    FORMAT_SIZE = struct.calcsize(FORMAT)
+
+    lm_response_length = len(lm_response)
+    lm_response_offset = FORMAT_SIZE
+    nt_response_length = len(nt_response)
+    nt_response_offset = lm_response_offset + lm_response_length
+    domain_unicode = domain.encode('UTF-16LE')
+    domain_length = len(domain_unicode)
+    domain_offset = nt_response_offset + nt_response_length
+
+    padding = ''
+    if domain_offset % 2 != 0:
+        padding = '\0'
+        domain_offset += 1
+
+    user_unicode = user.encode('UTF-16LE')
+    user_length = len(user_unicode)
+    user_offset = domain_offset + domain_length
+    workstation_unicode = workstation.encode('UTF-16LE')
+    workstation_length = len(workstation_unicode)
+    workstation_offset = user_offset + user_length
+    session_key_length = len(session_key)
+    session_key_offset = workstation_offset + workstation_length
+
+    auth_flags = challenge_flags
+    auth_flags &= ~NTLM_NegotiateVersion
+
+    s = struct.pack(FORMAT,
+                    'NTLMSSP\0', 0x03,
+                    lm_response_length, lm_response_length, lm_response_offset,
+                    nt_response_length, nt_response_length, nt_response_offset,
+                    domain_length, domain_length, domain_offset,
+                    user_length, user_length, user_offset,
+                    workstation_length, workstation_length, workstation_offset,
+                    session_key_length, session_key_length, session_key_offset,
+                    auth_flags)
+
+    return s + lm_response + nt_response + padding + domain_unicode + user_unicode + workstation_unicode + session_key
+
+
+def decodeChallengeMessage(ntlm_data):
+    """
+    References:
+    ===========
+    - [MS-NLMP]: 2.2.1.2
+    - [MS-NLMP]: 2.2.2.1 (AV_PAIR)
+    """
+    FORMAT = '<8sIHHII8s8sHHI'
+    FORMAT_SIZE = struct.calcsize(FORMAT)
+
+    signature, message_type, \
+    targetname_len, targetname_maxlen, targetname_offset, \
+    flags, challenge, _, \
+    targetinfo_len, targetinfo_maxlen, targetinfo_offset, \
+        = struct.unpack(FORMAT, ntlm_data[:FORMAT_SIZE])
+
+    assert signature == 'NTLMSSP\0'
+    assert message_type == 0x02
+
+    return challenge, flags, ntlm_data[targetinfo_offset:targetinfo_offset+targetinfo_len]
+
+
+def generateChallengeResponseV2(password, user, server_challenge, server_info, domain = '', client_challenge = None):
+    client_timestamp = '\0' * 8
+
+    if not client_challenge:
+        client_challenge = ''
+        for i in range(0, 8):
+            client_challenge += chr(random.getrandbits(8))
+    assert len(client_challenge) == 8
+
+    d = MD4()
+    d.update(password.encode('UTF-16LE'))
+    ntlm_hash = d.digest()   # The NT password hash
+    response_key = hmac.new(ntlm_hash, (user.upper() + domain).encode('UTF-16LE')).digest()  # The NTLMv2 password hash. In [MS-NLMP], this is the result of NTOWFv2 and LMOWFv2 functions
+    temp = '\x01\x01' + '\0'*6 + client_timestamp + client_challenge + '\0'*4 + server_info
+    ntproofstr = hmac.new(response_key, server_challenge + temp).digest()
+
+    nt_challenge_response = ntproofstr + temp
+    lm_challenge_response = hmac.new(response_key, server_challenge + client_challenge).digest() + client_challenge
+    session_key = hmac.new(response_key, ntproofstr).digest()
+
+    return nt_challenge_response, lm_challenge_response, session_key
+
+
+################
+# NTLMv1 Methods
+################
+
+def expandDesKey(key):
+    """Expand the key from a 7-byte password key into a 8-byte DES key"""
+    s = chr(((ord(key[0]) >> 1) & 0x7f) << 1)
+    s = s + chr(((ord(key[0]) & 0x01) << 6 | ((ord(key[1]) >> 2) & 0x3f)) << 1)
+    s = s + chr(((ord(key[1]) & 0x03) << 5 | ((ord(key[2]) >> 3) & 0x1f)) << 1)
+    s = s + chr(((ord(key[2]) & 0x07) << 4 | ((ord(key[3]) >> 4) & 0x0f)) << 1)
+    s = s + chr(((ord(key[3]) & 0x0f) << 3 | ((ord(key[4]) >> 5) & 0x07)) << 1)
+    s = s + chr(((ord(key[4]) & 0x1f) << 2 | ((ord(key[5]) >> 6) & 0x03)) << 1)
+    s = s + chr(((ord(key[5]) & 0x3f) << 1 | ((ord(key[6]) >> 7) & 0x01)) << 1)
+    s = s + chr((ord(key[6]) & 0x7f) << 1)
+    return s
+
+
+def DESL(K, D):
+    """
+    References:
+    ===========
+    - http://ubiqx.org/cifs/SMB.html (2.8.3.4)
+    - [MS-NLMP]: Section 6
+    """
+    d1 = des(expandDesKey(K[0:7]))
+    d2 = des(expandDesKey(K[7:14]))
+    d3 = des(expandDesKey(K[14:16] + '\0' * 5))
+    return d1.encrypt(D) + d2.encrypt(D) + d3.encrypt(D)
+
+
+def generateChallengeResponseV1(password, server_challenge, has_extended_security = False, client_challenge = None):
+    """
+    Generate a NTLMv1 response
+
+    @param password: User password string
+    @param server_challange: A 8-byte challenge string sent from the server
+    @param has_extended_security: A boolean value indicating whether NTLMSSP_NEGOTIATE_EXTENDED_SESSIONSECURITY flag is enabled in the NTLM negFlag
+    @param client_challenge: A 8-byte string representing client challenge. If None, it will be generated randomly if needed by the response generation
+    @return: a tuple of ( NT challenge response string, LM challenge response string )
+
+    References:
+    ===========
+    - http://ubiqx.org/cifs/SMB.html (2.8.3.3 and 2.8.3.4)
+    - [MS-NLMP]: 3.3.1
+    """
+    _password = (password.upper() + '\0' * 14)[:14]
+    d1 = des(expandDesKey(_password[:7]))
+    d2 = des(expandDesKey(_password[7:]))
+    lm_response_key = d1.encrypt("KGS!@#$%") + d2.encrypt("KGS!@#$%")  # LM password hash. In [MS-NLMP], this is the result of LMOWFv1 function
+
+    d = MD4()
+    d.update(password.encode('UTF-16LE'))
+    nt_response_key = d.digest()   # In [MS-NLMP], this is the result of NTOWFv1 function
+
+    if has_extended_security:
+        if not client_challenge:
+            client_challenge = ''
+            for i in range(0, 8):
+                client_challenge += chr(random.getrandbits(8))
+
+        assert len(client_challenge) == 8
+
+        lm_challenge_response = client_challenge + '\0'*16
+        nt_challenge_response = DESL(nt_response_key, MD5(server_challenge + client_challenge).digest()[0:8])
+    else:
+        nt_challenge_response = DESL(nt_response_key, server_challenge)   # The result after DESL is the NT response
+        lm_challenge_response = DESL(lm_response_key, server_challenge)   # The result after DESL is the LM response
+
+    d = MD4()
+    d.update(nt_response_key)
+    session_key = d.digest()
+
+    return nt_challenge_response, lm_challenge_response, session_key
diff --git a/python2/smb/security_descriptors.py b/python2/smb/security_descriptors.py
new file mode 100644
index 00000000..9e6ebe14
--- /dev/null
+++ b/python2/smb/security_descriptors.py
@@ -0,0 +1,367 @@
+"""
+This module implements security descriptors, and the partial structures
+used in them, as specified in [MS-DTYP].
+"""
+
+import struct
+
+
+# Security descriptor control flags
+# [MS-DTYP]: 2.4.6
+SECURITY_DESCRIPTOR_OWNER_DEFAULTED = 0x0001
+SECURITY_DESCRIPTOR_GROUP_DEFAULTED = 0x0002
+SECURITY_DESCRIPTOR_DACL_PRESENT = 0x0004
+SECURITY_DESCRIPTOR_DACL_DEFAULTED = 0x0008
+SECURITY_DESCRIPTOR_SACL_PRESENT = 0x0010
+SECURITY_DESCRIPTOR_SACL_DEFAULTED = 0x0020
+SECURITY_DESCRIPTOR_SERVER_SECURITY = 0x0040
+SECURITY_DESCRIPTOR_DACL_TRUSTED = 0x0080
+SECURITY_DESCRIPTOR_DACL_COMPUTED_INHERITANCE_REQUIRED = 0x0100
+SECURITY_DESCRIPTOR_SACL_COMPUTED_INHERITANCE_REQUIRED = 0x0200
+SECURITY_DESCRIPTOR_DACL_AUTO_INHERITED = 0x0400
+SECURITY_DESCRIPTOR_SACL_AUTO_INHERITED = 0x0800
+SECURITY_DESCRIPTOR_DACL_PROTECTED = 0x1000
+SECURITY_DESCRIPTOR_SACL_PROTECTED = 0x2000
+SECURITY_DESCRIPTOR_RM_CONTROL_VALID = 0x4000
+SECURITY_DESCRIPTOR_SELF_RELATIVE = 0x8000
+
+# ACE types
+# [MS-DTYP]: 2.4.4.1
+ACE_TYPE_ACCESS_ALLOWED = 0x00
+ACE_TYPE_ACCESS_DENIED = 0x01
+ACE_TYPE_SYSTEM_AUDIT = 0x02
+ACE_TYPE_SYSTEM_ALARM = 0x03
+ACE_TYPE_ACCESS_ALLOWED_COMPOUND = 0x04
+ACE_TYPE_ACCESS_ALLOWED_OBJECT = 0x05
+ACE_TYPE_ACCESS_DENIED_OBJECT = 0x06
+ACE_TYPE_SYSTEM_AUDIT_OBJECT = 0x07
+ACE_TYPE_SYSTEM_ALARM_OBJECT = 0x08
+ACE_TYPE_ACCESS_ALLOWED_CALLBACK = 0x09
+ACE_TYPE_ACCESS_DENIED_CALLBACK = 0x0A
+ACE_TYPE_ACCESS_ALLOWED_CALLBACK_OBJECT = 0x0B
+ACE_TYPE_ACCESS_DENIED_CALLBACK_OBJECT = 0x0C
+ACE_TYPE_SYSTEM_AUDIT_CALLBACK = 0x0D
+ACE_TYPE_SYSTEM_ALARM_CALLBACK = 0x0E
+ACE_TYPE_SYSTEM_AUDIT_CALLBACK_OBJECT = 0x0F
+ACE_TYPE_SYSTEM_ALARM_CALLBACK_OBJECT = 0x10
+ACE_TYPE_SYSTEM_MANDATORY_LABEL = 0x11
+ACE_TYPE_SYSTEM_RESOURCE_ATTRIBUTE = 0x12
+ACE_TYPE_SYSTEM_SCOPED_POLICY_ID = 0x13
+
+# ACE flags
+# [MS-DTYP]: 2.4.4.1
+ACE_FLAG_OBJECT_INHERIT = 0x01
+ACE_FLAG_CONTAINER_INHERIT = 0x02
+ACE_FLAG_NO_PROPAGATE_INHERIT = 0x04
+ACE_FLAG_INHERIT_ONLY = 0x08
+ACE_FLAG_INHERITED = 0x10
+ACE_FLAG_SUCCESSFUL_ACCESS = 0x40
+ACE_FLAG_FAILED_ACCESS = 0x80
+
+# Pre-defined well-known SIDs
+# [MS-DTYP]: 2.4.2.4
+SID_NULL = "S-1-0-0"
+SID_EVERYONE = "S-1-1-0"
+SID_LOCAL = "S-1-2-0"
+SID_CONSOLE_LOGON = "S-1-2-1"
+SID_CREATOR_OWNER = "S-1-3-0"
+SID_CREATOR_GROUP = "S-1-3-1"
+SID_OWNER_SERVER = "S-1-3-2"
+SID_GROUP_SERVER = "S-1-3-3"
+SID_OWNER_RIGHTS = "S-1-3-4"
+SID_NT_AUTHORITY = "S-1-5"
+SID_DIALUP = "S-1-5-1"
+SID_NETWORK = "S-1-5-2"
+SID_BATCH = "S-1-5-3"
+SID_INTERACTIVE = "S-1-5-4"
+SID_SERVICE = "S-1-5-6"
+SID_ANONYMOUS = "S-1-5-7"
+SID_PROXY = "S-1-5-8"
+SID_ENTERPRISE_DOMAIN_CONTROLLERS = "S-1-5-9"
+SID_PRINCIPAL_SELF = "S-1-5-10"
+SID_AUTHENTICATED_USERS = "S-1-5-11"
+SID_RESTRICTED_CODE = "S-1-5-12"
+SID_TERMINAL_SERVER_USER = "S-1-5-13"
+SID_REMOTE_INTERACTIVE_LOGON = "S-1-5-14"
+SID_THIS_ORGANIZATION = "S-1-5-15"
+SID_IUSR = "S-1-5-17"
+SID_LOCAL_SYSTEM = "S-1-5-18"
+SID_LOCAL_SERVICE = "S-1-5-19"
+SID_NETWORK_SERVICE = "S-1-5-20"
+SID_COMPOUNDED_AUTHENTICATION = "S-1-5-21-0-0-0-496"
+SID_CLAIMS_VALID = "S-1-5-21-0-0-0-497"
+SID_BUILTIN_ADMINISTRATORS = "S-1-5-32-544"
+SID_BUILTIN_USERS = "S-1-5-32-545"
+SID_BUILTIN_GUESTS = "S-1-5-32-546"
+SID_POWER_USERS = "S-1-5-32-547"
+SID_ACCOUNT_OPERATORS = "S-1-5-32-548"
+SID_SERVER_OPERATORS = "S-1-5-32-549"
+SID_PRINTER_OPERATORS = "S-1-5-32-550"
+SID_BACKUP_OPERATORS = "S-1-5-32-551"
+SID_REPLICATOR = "S-1-5-32-552"
+SID_ALIAS_PREW2KCOMPACC = "S-1-5-32-554"
+SID_REMOTE_DESKTOP = "S-1-5-32-555"
+SID_NETWORK_CONFIGURATION_OPS = "S-1-5-32-556"
+SID_INCOMING_FOREST_TRUST_BUILDERS = "S-1-5-32-557"
+SID_PERFMON_USERS = "S-1-5-32-558"
+SID_PERFLOG_USERS = "S-1-5-32-559"
+SID_WINDOWS_AUTHORIZATION_ACCESS_GROUP = "S-1-5-32-560"
+SID_TERMINAL_SERVER_LICENSE_SERVERS = "S-1-5-32-561"
+SID_DISTRIBUTED_COM_USERS = "S-1-5-32-562"
+SID_IIS_IUSRS = "S-1-5-32-568"
+SID_CRYPTOGRAPHIC_OPERATORS = "S-1-5-32-569"
+SID_EVENT_LOG_READERS = "S-1-5-32-573"
+SID_CERTIFICATE_SERVICE_DCOM_ACCESS = "S-1-5-32-574"
+SID_RDS_REMOTE_ACCESS_SERVERS = "S-1-5-32-575"
+SID_RDS_ENDPOINT_SERVERS = "S-1-5-32-576"
+SID_RDS_MANAGEMENT_SERVERS = "S-1-5-32-577"
+SID_HYPER_V_ADMINS = "S-1-5-32-578"
+SID_ACCESS_CONTROL_ASSISTANCE_OPS = "S-1-5-32-579"
+SID_REMOTE_MANAGEMENT_USERS = "S-1-5-32-580"
+SID_WRITE_RESTRICTED_CODE = "S-1-5-33"
+SID_NTLM_AUTHENTICATION = "S-1-5-64-10"
+SID_SCHANNEL_AUTHENTICATION = "S-1-5-64-14"
+SID_DIGEST_AUTHENTICATION = "S-1-5-64-21"
+SID_THIS_ORGANIZATION_CERTIFICATE = "S-1-5-65-1"
+SID_NT_SERVICE = "S-1-5-80"
+SID_USER_MODE_DRIVERS = "S-1-5-84-0-0-0-0-0"
+SID_LOCAL_ACCOUNT = "S-1-5-113"
+SID_LOCAL_ACCOUNT_AND_MEMBER_OF_ADMINISTRATORS_GROUP = "S-1-5-114"
+SID_OTHER_ORGANIZATION = "S-1-5-1000"
+SID_ALL_APP_PACKAGES = "S-1-15-2-1"
+SID_ML_UNTRUSTED = "S-1-16-0"
+SID_ML_LOW = "S-1-16-4096"
+SID_ML_MEDIUM = "S-1-16-8192"
+SID_ML_MEDIUM_PLUS = "S-1-16-8448"
+SID_ML_HIGH = "S-1-16-12288"
+SID_ML_SYSTEM = "S-1-16-16384"
+SID_ML_PROTECTED_PROCESS = "S-1-16-20480"
+SID_AUTHENTICATION_AUTHORITY_ASSERTED_IDENTITY = "S-1-18-1"
+SID_SERVICE_ASSERTED_IDENTITY = "S-1-18-2"
+SID_FRESH_PUBLIC_KEY_IDENTITY = "S-1-18-3"
+SID_KEY_TRUST_IDENTITY = "S-1-18-4"
+SID_KEY_PROPERTY_MFA = "S-1-18-5"
+SID_KEY_PROPERTY_ATTESTATION = "S-1-18-6"
+
+
+class SID(object):
+    """
+    A Windows security identifier. Represents a single principal, such a
+    user or a group, as a sequence of numbers consisting of the revision,
+    identifier authority, and a variable-length list of subauthorities.
+
+    See [MS-DTYP]: 2.4.2
+    """
+    def __init__(self, revision, identifier_authority, subauthorities):
+        #: Revision, should always be 1.
+        self.revision = revision
+        #: An integer representing the identifier authority.
+        self.identifier_authority = identifier_authority
+        #: A list of integers representing all subauthorities.
+        self.subauthorities = subauthorities
+
+    def __str__(self):
+        """
+        String representation, as specified in [MS-DTYP]: 2.4.2.1
+        """
+        if self.identifier_authority >= 2**32:
+            id_auth = '%#x' % (self.identifier_authority,)
+        else:
+            id_auth = self.identifier_authority
+        auths = [self.revision, id_auth] + self.subauthorities
+        return 'S-' + '-'.join(str(subauth) for subauth in auths)
+
+    def __repr__(self):
+        return 'SID(%r)' % (str(self),)
+
+    @classmethod
+    def from_bytes(cls, data, return_tail=False):
+        revision, subauth_count = struct.unpack('<BB', data[:2])
+        identifier_authority = struct.unpack('>Q', '\x00\x00' + data[2:8])[0]
+        subauth_data = data[8:]
+        subauthorities = [struct.unpack('<L', subauth_data[4 * i : 4 * (i+1)])[0]
+                          for i in range(subauth_count)]
+        sid = cls(revision, identifier_authority, subauthorities)
+        if return_tail:
+            return sid, subauth_data[4 * subauth_count :]
+        return sid
+
+
+class ACE(object):
+    """
+    Represents a single access control entry.
+
+    See [MS-DTYP]: 2.4.4
+    """
+    HEADER_FORMAT = '<BBH'
+
+    def __init__(self, type_, flags, mask, sid, additional_data):
+        #: An integer representing the type of the ACE. One of the
+        #: ``ACE_TYPE_*`` constants. Corresponds to the ``AceType`` field
+        #: from [MS-DTYP] 2.4.4.1.
+        self.type = type_
+        #: An integer bitmask with ACE flags, corresponds to the
+        #: ``AceFlags`` field.
+        self.flags = flags
+        #: An integer representing the ``ACCESS_MASK`` as specified in
+        #: [MS-DTYP] 2.4.3.
+        self.mask = mask
+        #: The :class:`SID` of a trustee.
+        self.sid = sid
+        #: A dictionary of additional fields present in the ACE, depending
+        #: on the type. The following fields can be present:
+        #:
+        #: * ``flags``
+        #: * ``object_type``
+        #: * ``inherited_object_type``
+        #: * ``application_data``
+        #: * ``attribute_data``
+        self.additional_data = additional_data
+
+    def __repr__(self):
+        return "ACE(type=%#04x, flags=%#04x, mask=%#010x, sid=%s)" % (
+            self.type, self.flags, self.mask, self.sid,
+        )
+
+    @property
+    def isInheritOnly(self):
+        """Convenience property which indicates if this ACE is inherit
+        only, meaning that it doesn't apply to the object itself."""
+        return bool(self.flags & ACE_FLAG_INHERIT_ONLY)
+
+    @classmethod
+    def from_bytes(cls, data):
+        header_size = struct.calcsize(cls.HEADER_FORMAT)
+        header = data[:header_size]
+        type_, flags, size = struct.unpack(cls.HEADER_FORMAT, header)
+
+        assert len(data) >= size
+
+        body = data[header_size:size]
+        additional_data = {}
+
+        # In all ACE types, the mask immediately follows the header.
+        mask = struct.unpack('<I', body[:4])[0]
+        body = body[4:]
+
+        # All OBJECT-type ACEs contain additional flags, and two GUIDs as
+        # the following fields.
+        if type_ in (ACE_TYPE_ACCESS_ALLOWED_OBJECT,
+                     ACE_TYPE_ACCESS_DENIED_OBJECT,
+                     ACE_TYPE_ACCESS_ALLOWED_CALLBACK_OBJECT,
+                     ACE_TYPE_ACCESS_DENIED_CALLBACK_OBJECT,
+                     ACE_TYPE_SYSTEM_AUDIT_OBJECT,
+                     ACE_TYPE_SYSTEM_AUDIT_CALLBACK_OBJECT):
+            additional_data['flags'] = struct.unpack('<I', body[:4])[0]
+            additional_data['object_type'] = body[4:20]
+            additional_data['inherited_object_type'] = body[20:36]
+            body = body[36:]
+
+        # Then the SID in all types.
+        sid, body = SID.from_bytes(body, return_tail=True)
+
+        # CALLBACK-type ACEs (and for some obscure reason,
+        # SYSTEM_AUDIT_OBJECT) have a final tail of application data.
+        if type_ in (ACE_TYPE_ACCESS_ALLOWED_CALLBACK,
+                     ACE_TYPE_ACCESS_DENIED_CALLBACK,
+                     ACE_TYPE_ACCESS_ALLOWED_CALLBACK_OBJECT,
+                     ACE_TYPE_ACCESS_DENIED_CALLBACK_OBJECT,
+                     ACE_TYPE_SYSTEM_AUDIT_OBJECT,
+                     ACE_TYPE_SYSTEM_AUDIT_CALLBACK,
+                     ACE_TYPE_SYSTEM_AUDIT_CALLBACK_OBJECT):
+            additional_data['application_data'] = body
+
+        # SYSTEM_RESOURCE_ATTRIBUTE ACEs have a tail of attribute data.
+        if type_ == ACE_TYPE_SYSTEM_RESOURCE_ATTRIBUTE:
+            additional_data['attribute_data'] = body
+
+        return cls(type_, flags, mask, sid, additional_data)
+
+
+class ACL(object):
+    """
+    Access control list, encapsulating a sequence of access control
+    entries.
+
+    See [MS-DTYP]: 2.4.5
+    """
+    HEADER_FORMAT = '<BBHHH'
+
+    def __init__(self, revision, aces):
+        #: Integer value of the revision.
+        self.revision = revision
+        #: List of :class:`ACE` instances.
+        self.aces = aces
+
+    def __repr__(self):
+        return "ACL(%r)" % (self.aces,)
+
+    @classmethod
+    def from_bytes(cls, data):
+        revision = None
+        aces = []
+
+        header_size = struct.calcsize(cls.HEADER_FORMAT)
+        header, remaining = data[:header_size], data[header_size:]
+        revision, sbz1, size, count, sbz2 = struct.unpack(cls.HEADER_FORMAT, header)
+
+        assert len(data) >= size
+
+        for i in range(count):
+            ace_size = struct.unpack('<H', remaining[2:4])[0]
+            ace_data, remaining = remaining[:ace_size], remaining[ace_size:]
+            aces.append(ACE.from_bytes(ace_data))
+
+        return cls(revision, aces)
+
+
+class SecurityDescriptor(object):
+    """
+    Represents a security descriptor.
+
+    See [MS-DTYP]: 2.4.6
+    """
+
+    HEADER_FORMAT = '<BBHIIII'
+
+    def __init__(self, flags, owner, group, dacl, sacl):
+        #: Integer bitmask of control flags. Corresponds to the
+        #: ``Control`` field in [MS-DTYP] 2.4.6.
+        self.flags = flags
+        #: Instance of :class:`SID` representing the owner user.
+        self.owner = owner
+        #: Instance of :class:`SID` representing the owner group.
+        self.group = group
+        #: Instance of :class:`ACL` representing the discretionary access
+        #: control list, which specifies access restrictions of an object.
+        self.dacl = dacl
+        #: Instance of :class:`ACL` representing the system access control
+        #: list, which specifies audit logging of an object.
+        self.sacl = sacl
+
+    @classmethod
+    def from_bytes(cls, data):
+        owner = None
+        group = None
+        dacl = None
+        sacl = None
+
+        header = data[:struct.calcsize(cls.HEADER_FORMAT)]
+        (revision, sbz1, flags, owner_offset, group_offset, sacl_offset,
+         dacl_offset) = struct.unpack(cls.HEADER_FORMAT, header)
+
+        assert revision == 1
+        assert flags & SECURITY_DESCRIPTOR_SELF_RELATIVE
+        for offset in (owner_offset, group_offset, sacl_offset, dacl_offset):
+            assert 0 <= offset < len(data)
+
+        if owner_offset:
+            owner = SID.from_bytes(data[owner_offset:])
+        if group_offset:
+            group = SID.from_bytes(data[group_offset:])
+        if dacl_offset:
+            dacl = ACL.from_bytes(data[dacl_offset:])
+        if sacl_offset:
+            sacl = ACL.from_bytes(data[sacl_offset:])
+
+        return cls(flags, owner, group, dacl, sacl)
diff --git a/python2/smb/securityblob.py b/python2/smb/securityblob.py
new file mode 100644
index 00000000..38af11ec
--- /dev/null
+++ b/python2/smb/securityblob.py
@@ -0,0 +1,136 @@
+
+from pyasn1.type import tag, univ, namedtype, namedval, constraint
+from pyasn1.codec.der import encoder, decoder
+
+__all__ = [ 'generateNegotiateSecurityBlob', 'generateAuthSecurityBlob', 'decodeChallengeSecurityBlob', 'decodeAuthResponseSecurityBlob' ]
+
+
+class UnsupportedSecurityProvider(Exception): pass
+class BadSecurityBlobError(Exception): pass
+
+
+def generateNegotiateSecurityBlob(ntlm_data):
+    mech_token = univ.OctetString(ntlm_data).subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2))
+    mech_types = MechTypeList().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0))
+    mech_types.setComponentByPosition(0, univ.ObjectIdentifier('1.3.6.1.4.1.311.2.2.10'))
+
+    n = NegTokenInit().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0))
+    n.setComponentByName('mechTypes', mech_types)
+    n.setComponentByName('mechToken', mech_token)
+
+    nt = NegotiationToken()
+    nt.setComponentByName('negTokenInit', n)
+
+    ct = ContextToken()
+    ct.setComponentByName('thisMech', univ.ObjectIdentifier('1.3.6.1.5.5.2'))
+    ct.setComponentByName('innerContextToken', nt)
+
+    return encoder.encode(ct)
+
+
+def generateAuthSecurityBlob(ntlm_data):
+    response_token = univ.OctetString(ntlm_data).subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2))
+
+    n = NegTokenTarg().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1))
+    n.setComponentByName('responseToken', response_token)
+
+    nt = NegotiationToken()
+    nt.setComponentByName('negTokenTarg', n)
+
+    return encoder.encode(nt)
+
+
+def decodeChallengeSecurityBlob(data):
+    try:
+        d, _ = decoder.decode(data, asn1Spec = NegotiationToken())
+        nt = d.getComponentByName('negTokenTarg')
+
+        token = nt.getComponentByName('responseToken')
+        if not token:
+            raise BadSecurityBlobError('NTLMSSP_CHALLENGE security blob does not contain responseToken field')
+
+        provider_oid = nt.getComponentByName('supportedMech')
+        if provider_oid and str(provider_oid) != '1.3.6.1.4.1.311.2.2.10':  # This OID is defined in [MS-NLMP]: 1.9
+            raise UnsupportedSecurityProvider('Security provider "%s" is not supported by pysmb' % str(provider_oid))
+
+        result = nt.getComponentByName('negResult')
+        return int(result), str(token)
+    except Exception, ex:
+        raise BadSecurityBlobError(str(ex))
+
+
+def decodeAuthResponseSecurityBlob(data):
+    try:
+        d, _ = decoder.decode(data, asn1Spec = NegotiationToken())
+        nt = d.getComponentByName('negTokenTarg')
+
+        result = nt.getComponentByName('negResult')
+        return int(result)
+    except Exception, ex:
+        raise BadSecurityBlobError(str(ex))
+
+
+#
+# GSS-API ASN.1 (RFC2478 section 3.2.1)
+#
+
+RESULT_ACCEPT_COMPLETED = 0
+RESULT_ACCEPT_INCOMPLETE = 1
+RESULT_REJECT = 2
+
+class NegResultEnumerated(univ.Enumerated):
+    namedValues = namedval.NamedValues(
+        ( 'accept_completed', 0 ),
+        ( 'accept_incomplete', 1 ),
+        ( 'reject', 2 )
+    )
+    subtypeSpec = univ.Enumerated.subtypeSpec + constraint.SingleValueConstraint(0, 1, 2)
+
+
+class MechTypeList(univ.SequenceOf):
+    componentType = univ.ObjectIdentifier()
+
+
+class ContextFlags(univ.BitString):
+    namedValues = namedval.NamedValues(
+        ( 'delegFlag', 0 ),
+        ( 'mutualFlag', 1 ),
+        ( 'replayFlag', 2 ),
+        ( 'sequenceFlag', 3 ),
+        ( 'anonFlag', 4 ),
+        ( 'confFlag', 5 ),
+        ( 'integFlag', 6 )
+    )
+
+
+class NegTokenInit(univ.Sequence):
+    componentType = namedtype.NamedTypes(
+        namedtype.OptionalNamedType('mechTypes', MechTypeList().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0))),
+        namedtype.OptionalNamedType('reqFlags', ContextFlags().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1))),
+        namedtype.OptionalNamedType('mechToken', univ.OctetString().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 2))),
+        namedtype.OptionalNamedType('mechListMIC', univ.OctetString().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 3)))
+    )
+
+
+class NegTokenTarg(univ.Sequence):
+    componentType = namedtype.NamedTypes(
+        namedtype.OptionalNamedType('negResult', NegResultEnumerated().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0))),
+        namedtype.OptionalNamedType('supportedMech', univ.ObjectIdentifier().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1))),
+        namedtype.OptionalNamedType('responseToken', univ.OctetString().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 2))),
+        namedtype.OptionalNamedType('mechListMIC', univ.OctetString().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 3)))
+    )
+
+
+class NegotiationToken(univ.Choice):
+    componentType = namedtype.NamedTypes(
+        namedtype.NamedType('negTokenInit', NegTokenInit().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0))),
+        namedtype.NamedType('negTokenTarg', NegTokenTarg().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1)))
+    )
+
+
+class ContextToken(univ.Sequence):
+    tagSet = univ.Sequence.tagSet.tagImplicitly(tag.Tag(tag.tagClassApplication, tag.tagFormatConstructed, 0))
+    componentType = namedtype.NamedTypes(
+        namedtype.NamedType('thisMech', univ.ObjectIdentifier()),
+        namedtype.NamedType('innerContextToken', NegotiationToken())
+    )
diff --git a/python2/smb/smb2_constants.py b/python2/smb/smb2_constants.py
new file mode 100644
index 00000000..024ed2c4
--- /dev/null
+++ b/python2/smb/smb2_constants.py
@@ -0,0 +1,115 @@
+
+# Bitmask for Flags field in SMB2 message header
+SMB2_FLAGS_SERVER_TO_REDIR = 0x01
+SMB2_FLAGS_ASYNC_COMMAND = 0x02
+SMB2_FLAGS_RELATED_OPERATIONS = 0x04
+SMB2_FLAGS_SIGNED = 0x08
+SMB2_FLAGS_DFS_OPERATIONS = 0x10000000
+
+# Values for Command field in SMB2 message header
+SMB2_COM_NEGOTIATE = 0x0000
+SMB2_COM_SESSION_SETUP = 0x0001
+SMB2_COM_LOGOFF = 0x0002
+SMB2_COM_TREE_CONNECT = 0x0003
+SMB2_COM_TREE_DISCONNECT = 0x0004
+SMB2_COM_CREATE = 0x0005
+SMB2_COM_CLOSE = 0x0006
+SMB2_COM_FLUSH = 0x0007
+SMB2_COM_READ = 0x0008
+SMB2_COM_WRITE = 0x0009
+SMB2_COM_LOCK = 0x000A
+SMB2_COM_IOCTL = 0x000B
+SMB2_COM_CANCEL = 0x000C
+SMB2_COM_ECHO = 0x000D
+SMB2_COM_QUERY_DIRECTORY = 0x000E
+SMB2_COM_CHANGE_NOTIFY = 0x000F
+SMB2_COM_QUERY_INFO = 0x0010
+SMB2_COM_SET_INFO = 0x0011
+SMB2_COM_OPLOCK_BREAK = 0x0012
+
+SMB2_COMMAND_NAMES = {
+    0x0000: 'SMB2_COM_NEGOTIATE',
+    0x0001: 'SMB2_COM_SESSION_SETUP',
+    0x0002: 'SMB2_COM_LOGOFF',
+    0x0003: 'SMB2_COM_TREE_CONNECT',
+    0x0004: 'SMB2_COM_TREE_DISCONNECT',
+    0x0005: 'SMB2_COM_CREATE',
+    0x0006: 'SMB2_COM_CLOSE',
+    0x0007: 'SMB2_COM_FLUSH',
+    0x0008: 'SMB2_COM_READ',
+    0x0009: 'SMB2_COM_WRITE',
+    0x000A: 'SMB2_COM_LOCK',
+    0x000B: 'SMB2_COM_IOCTL',
+    0x000C: 'SMB2_COM_CANCEL',
+    0x000D: 'SMB2_COM_ECHO',
+    0x000E: 'SMB2_COM_QUERY_DIRECTORY',
+    0x000F: 'SMB2_COM_CHANGE_NOTIFY',
+    0x0010: 'SMB2_COM_QUERY_INFO',
+    0x0011: 'SMB2_COM_SET_INFO',
+    0x0012: 'SMB2_COM_OPLOCK_BREAK',
+}
+
+# Values for dialect_revision field in SMB2NegotiateResponse class
+SMB2_DIALECT_2 = 0x0202  # 2.0.2 - First SMB2 version
+SMB2_DIALECT_21 = 0x0210  # 2.1 - Windows 7
+SMB2_DIALET_30 = 0x0300  # 3.0 - Windows 8
+SMB2_DIALECT_302 = 0x0302  # 3.0.2 - Windows 8.1
+SMB2_DIALECT_311 = 0x0311  # 3.1.1 - Windows 10
+SMB2_DIALECT_2ALL = 0x02FF  # Wildcard (for negotiation only)
+
+# Bit mask for SecurityMode field in SMB2NegotiateResponse class
+SMB2_NEGOTIATE_SIGNING_ENABLED = 0x0001
+SMB2_NEGOTIATE_SIGNING_REQUIRED = 0x0002
+
+# Values for ShareType field in SMB2TreeConnectResponse class
+SMB2_SHARE_TYPE_DISK = 0x01
+SMB2_SHARE_TYPE_PIPE = 0x02
+SMB2_SHARE_TYPE_PRINTER = 0x03
+
+# Bitmask for Capabilities in SMB2TreeConnectResponse class
+SMB2_SHARE_CAP_DFS = 0x0008
+
+
+# SMB 2.1 / 3 Capabilities flags
+SMB2_GLOBAL_CAP_DFS = 0x01
+SMB2_GLOBAL_CAP_LEASING = 0x02
+SMB2_GLOBAL_CAP_LARGE_MTU = 0x04
+SMB2_GLOBAL_CAP_MULTI_CHANNEL = 0x08
+SMB2_GLOBAL_CAP_PERSISTENT_HANDLES = 0x10
+SMB2_GLOBAL_CAP_DIRECTORY_LEASING = 0x20
+SMB2_GLOBAL_CAP_ENCRYPTION = 0x40
+
+
+# Values for OpLockLevel field in SMB2CreateRequest class
+SMB2_OPLOCK_LEVEL_NONE = 0x00
+SMB2_OPLOCK_LEVEL_II = 0x01
+SMB2_OPLOCK_LEVEL_EXCLUSIVE = 0x08
+SMB2_OPLOCK_LEVEL_BATCH = 0x09
+SMB2_OPLOCK_LEVEL_LEASE = 0xFF
+
+# Values for FileAttributes field in SMB2CreateRequest class
+# The values are defined in [MS-FSCC] 2.6
+SMB2_FILE_ATTRIBUTE_ARCHIVE = 0x0020
+SMB2_FILE_ATTRIBUTE_COMPRESSED = 0x0800
+SMB2_FILE_ATTRIBUTE_DIRECTORY = 0x0010
+SMB2_FILE_ATTRIBUTE_ENCRYPTED = 0x4000
+SMB2_FILE_ATTRIBUTE_HIDDEN = 0x0002
+SMB2_FILE_ATTRIBUTE_NORMAL = 0x0080
+SMB2_FILE_ATTRIBUTE_NOTINDEXED = 0x2000
+SMB2_FILE_ATTRIBUTE_OFFLINE = 0x1000
+SMB2_FILE_ATTRIBUTE_READONLY = 0x0001
+SMB2_FILE_ATTRIBUTE_SPARSE = 0x0200
+SMB2_FILE_ATTRIBUTE_SYSTEM = 0x0004
+SMB2_FILE_ATTRIBUTE_TEMPORARY = 0x0100
+
+# Values for CreateAction field in SMB2CreateResponse class
+SMB2_FILE_SUPERCEDED = 0x00
+SMB2_FILE_OPENED = 0x01
+SMB2_FILE_CREATED = 0x02
+SMB2_FILE_OVERWRITTEN = 0x03
+
+# Values for InfoType field in SMB2QueryInfoRequest class
+SMB2_INFO_FILE = 0x01
+SMB2_INFO_FILESYSTEM = 0x02
+SMB2_INFO_SECURITY = 0x03
+SMB2_INFO_QUOTA = 0x04
diff --git a/python2/smb/smb2_structs.py b/python2/smb/smb2_structs.py
new file mode 100644
index 00000000..2e13b491
--- /dev/null
+++ b/python2/smb/smb2_structs.py
@@ -0,0 +1,1001 @@
+
+import os, sys, struct, types, logging, binascii, time, uuid
+from StringIO import StringIO
+from smb_structs import ProtocolError
+from smb_constants import *
+from smb2_constants import *
+from utils import convertFILETIMEtoEpoch
+
+
+class SMB2Message:
+
+    HEADER_STRUCT_FORMAT = "<4sHHIHHI"  # This refers to the common header part that is shared by both sync and async SMB2 header
+    HEADER_STRUCT_SIZE = struct.calcsize(HEADER_STRUCT_FORMAT)
+
+    ASYNC_HEADER_STRUCT_FORMAT = "<IQQQ16s"
+    ASYNC_HEADER_STRUCT_SIZE = struct.calcsize(ASYNC_HEADER_STRUCT_FORMAT)
+
+    SYNC_HEADER_STRUCT_FORMAT = "<IQIIQ16s"
+    SYNC_HEADER_STRUCT_SIZE = struct.calcsize(SYNC_HEADER_STRUCT_FORMAT)
+
+    HEADER_SIZE = 64
+
+    log = logging.getLogger('SMB.SMB2Message')
+    protocol = 2
+
+
+    def __init__(self, conn = None, payload = None):
+        """
+        Initialise a new SMB2 Message.
+        conn - reference to the connection, the SMB class
+        payload - the message payload, if any
+        """
+        self.reset()
+        self.conn = conn
+        if payload:
+            self.payload = payload
+            self.payload.initMessage(self)
+
+    def __str__(self):
+        b = StringIO()
+        b.write('Command: 0x%02X (%s) %s' % ( self.command, SMB2_COMMAND_NAMES.get(self.command, '<unknown>'), os.linesep ))
+        b.write('Status: 0x%08X %s' % ( self.status, os.linesep ))
+        b.write('Flags: 0x%02X %s' % ( self.flags, os.linesep ))
+        b.write('PID: %d %s' % ( self.pid, os.linesep ))
+        b.write('MID: %d %s' % ( self.mid, os.linesep ))
+        b.write('TID: %d %s' % ( self.tid, os.linesep ))
+        b.write('Data: %d bytes %s%s %s' % ( len(self.data), os.linesep, binascii.hexlify(self.data), os.linesep ))
+        return b.getvalue()
+
+    def reset(self):
+        self.raw_data = ''
+        self.command = 0
+        self.status = 0
+        self.flags = 0
+
+        self.next_command_offset = 0
+        self.mid = 0
+        self.session_id = 0
+        self.signature = '\0'*16
+        self.payload = None
+        self.data = ''
+
+        # For async SMB2 message
+        self.async_id = 0
+
+        # For sync SMB2 message
+        self.pid = 0
+        self.tid = 0
+
+        # credit related
+        self.credit_charge = 0
+        self.credit_request = 1
+
+        # Not used in this class. Maintained for compatibility with SMBMessage class
+        self.flags2 = 0
+        self.uid = 0
+        self.security = 0L
+        self.parameters_data = ''
+
+    def encode(self):
+        """
+        Encode this SMB2 message into a series of bytes suitable to be embedded with a NetBIOS session message.
+        AssertionError will be raised if this SMB message has not been initialized with an SMB instance
+        AssertionError will be raised if this SMB message has not been initialized with a Payload instance
+
+        The header format is:
+        - Protocol ID
+        - Structure Size
+        - Credit Charge
+        - Status / Channel Sequence
+        - Command
+        - Credit Request / Credit Response
+        - Flags
+        - Next Compound
+        - MessageId
+        - Reserved
+        - TreeId
+        - Session ID
+        - Signature
+
+        @return: a string containing the encoded SMB2 message
+        """
+        assert self.payload
+        assert self.conn
+
+        self.pid = os.getpid()
+        self.payload.prepare(self)
+
+        # If Connection.Dialect is not "2.0.2" and if Connection.SupportsMultiCredit is TRUE, the
+        # CreditCharge field in the SMB2 header MUST be set to ( 1 + (OutputBufferLength - 1) / 65536 )
+        # This only applies to SMB2ReadRequest, SMB2WriteRequest, SMB2IoctlRequest and SMB2QueryDirectory
+        # See: MS-SMB2 3.2.4.1.5: For all other requests, the client MUST set CreditCharge to 1, even if the
+        # payload size of a request or the anticipated response is greater than 65536.
+        if self.conn.smb2_dialect != SMB2_DIALECT_2:
+            if self.conn.cap_multi_credit:
+                # self.credit_charge will be set by some commands if necessary (Read/Write/Ioctl/QueryDirectory)
+                # If not set, but dialect is SMB 2.1 or above, we must set it to 1
+                if self.credit_charge is 0:
+                    self.credit_charge = 1
+            else:
+                # If >= SMB 2.1, but server does not support multi credit operations we must set to 1
+                self.credit_charge = 1
+
+        if self.mid > 3:
+            self.credit_request = 127
+
+        headers_data = struct.pack(self.HEADER_STRUCT_FORMAT,
+                                   '\xFESMB',  # Protocol ID
+                                   self.HEADER_SIZE,  # Structure Size
+                                   self.credit_charge,  # Credit Charge
+                                   self.status,  # Status / Channel Sequence
+                                   self.command,  # Command
+                                   self.credit_request,  # Credit Request / Credit Response
+                                   self.flags, # Flags
+                                   ) + \
+                       struct.pack(self.SYNC_HEADER_STRUCT_FORMAT,
+                                    self.next_command_offset, # Next Compound
+                                    self.mid,  # Message ID
+                                    self.pid,  # Process ID
+                                    self.tid,  # Tree ID
+                                    self.session_id,  # Session ID
+                                    self.signature)  # Signature
+        return headers_data + self.data
+
+    def decode(self, buf):
+        """
+        Decodes the SMB message in buf.
+        All fields of the SMB2Message object will be reset to default values before decoding.
+        On errors, do not assume that the fields will be reinstated back to what they are before
+        this method is invoked.
+
+        References
+        ==========
+        - [MS-SMB2]: 2.2.1
+
+        @param buf: data containing one complete SMB2 message
+        @type buf: string
+        @return: a positive integer indicating the number of bytes used in buf to decode this SMB message
+        @raise ProtocolError: raised when decoding fails
+        """
+        buf_len = len(buf)
+        if buf_len < 64:  # All SMB2 headers must be at least 64 bytes. [MS-SMB2]: 2.2.1.1, 2.2.1.2
+            raise ProtocolError('Not enough data to decode SMB2 header', buf)
+
+        self.reset()
+
+        protocol, struct_size, self.credit_charge, self.status, \
+            self.command, self.credit_response, \
+            self.flags = struct.unpack(self.HEADER_STRUCT_FORMAT, buf[:self.HEADER_STRUCT_SIZE])
+
+        if protocol != '\xFESMB':
+            raise ProtocolError('Invalid 4-byte SMB2 protocol field', buf)
+
+        if struct_size != self.HEADER_SIZE:
+            raise ProtocolError('Invalid SMB2 header structure size')
+
+        if self.isAsync:
+            if buf_len < self.HEADER_STRUCT_SIZE+self.ASYNC_HEADER_STRUCT_SIZE:
+                raise ProtocolError('Not enough data to decode SMB2 header', buf)
+
+            self.next_command_offset, self.mid, self.async_id, self.session_id, \
+                self.signature = struct.unpack(self.ASYNC_HEADER_STRUCT_FORMAT,
+                                               buf[self.HEADER_STRUCT_SIZE:self.HEADER_STRUCT_SIZE+self.ASYNC_HEADER_STRUCT_SIZE])
+        else:
+            if buf_len < self.HEADER_STRUCT_SIZE+self.SYNC_HEADER_STRUCT_SIZE:
+                raise ProtocolError('Not enough data to decode SMB2 header', buf)
+
+            self.next_command_offset, self.mid, self.pid, self.tid, self.session_id, \
+                self.signature = struct.unpack(self.SYNC_HEADER_STRUCT_FORMAT,
+                                               buf[self.HEADER_STRUCT_SIZE:self.HEADER_STRUCT_SIZE+self.SYNC_HEADER_STRUCT_SIZE])
+
+        if self.next_command_offset > 0:
+            self.raw_data = buf[:self.next_command_offset]
+            self.data = buf[self.HEADER_SIZE:self.next_command_offset]
+        else:
+            self.raw_data = buf
+            self.data = buf[self.HEADER_SIZE:]
+
+        self._decodeCommand()
+        if self.payload:
+            self.payload.decode(self)
+
+        return len(self.raw_data)
+
+    def _decodeCommand(self):
+        if self.command == SMB2_COM_READ:
+            self.payload = SMB2ReadResponse()
+        elif self.command == SMB2_COM_WRITE:
+            self.payload = SMB2WriteResponse()
+        elif self.command == SMB2_COM_QUERY_DIRECTORY:
+            self.payload = SMB2QueryDirectoryResponse()
+        elif self.command == SMB2_COM_CREATE:
+            self.payload = SMB2CreateResponse()
+        elif self.command == SMB2_COM_CLOSE:
+            self.payload = SMB2CloseResponse()
+        elif self.command == SMB2_COM_QUERY_INFO:
+            self.payload = SMB2QueryInfoResponse()
+        elif self.command == SMB2_COM_SET_INFO:
+            self.payload = SMB2SetInfoResponse()
+        elif self.command == SMB2_COM_IOCTL:
+            self.payload = SMB2IoctlResponse()
+        elif self.command == SMB2_COM_TREE_CONNECT:
+            self.payload = SMB2TreeConnectResponse()
+        elif self.command == SMB2_COM_SESSION_SETUP:
+            self.payload = SMB2SessionSetupResponse()
+        elif self.command == SMB2_COM_NEGOTIATE:
+            self.payload = SMB2NegotiateResponse()
+        elif self.command == SMB2_COM_ECHO:
+            self.payload = SMB2EchoResponse()
+
+    @property
+    def isAsync(self):
+        return bool(self.flags & SMB2_FLAGS_ASYNC_COMMAND)
+
+    @property
+    def isReply(self):
+        return bool(self.flags & SMB2_FLAGS_SERVER_TO_REDIR)
+
+
+class Structure:
+
+    def initMessage(self, message):
+        pass
+
+    def prepare(self, message):
+        raise NotImplementedError
+
+    def decode(self, message):
+        raise NotImplementedError
+
+
+class SMB2NegotiateRequest(Structure):
+    """
+    2.2.3 SMB2 NEGOTIATE Request
+    The SMB2 NEGOTIATE Request packet is used by the client to notify the server what dialects of the SMB 2 Protocol
+    the client understands. This request is composed of an SMB2 header, as specified in section 2.2.1,
+    followed by this request structure:
+
+    SMB2 Negotiate Request Packet structure:
+        StructureSize (2 bytes)
+        DialectCount (2 bytes)
+        SecurityMode (2 bytes)
+        Reserved (2 bytes)
+        Capabilities (4 bytes)
+        ClientGuid (16 bytes)
+        ClientStartTime (8 bytes):
+        ClientStartTime (8 bytes):
+        Dialects (variable): An array of one or more 16-bit integers
+
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.3
+
+    """
+
+
+    STRUCTURE_FORMAT = "<HHHHI16sQHH"
+    STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT)
+
+    def initMessage(self, message):
+        Structure.initMessage(self, message)
+        message.command = SMB2_COM_NEGOTIATE
+
+    def prepare(self, message):
+        # TODO! Do we need to save the GUID and present it later in other requests?
+        # The SMB docs don't exactly explain what the guid is for
+        message.data = struct.pack(self.STRUCTURE_FORMAT,
+                                   36,           # Structure size. Must be 36 as mandated by [MS-SMB2] 2.2.3
+                                   2,            # DialectCount
+                                   0x01,         # Security mode
+                                   0,            # Reserved
+                                   0x00,         # Capabilities
+                                   uuid.uuid4().bytes, # Client GUID
+                                   0,            # Client start time
+                                   SMB2_DIALECT_2,
+                                   SMB2_DIALECT_21)
+
+
+class SMB2NegotiateResponse(Structure):
+    """
+    Contains information on the SMB2_NEGOTIATE response from server
+
+    After calling the decode method, each instance will contain the following attributes,
+    - security_mode (integer)
+    - dialect_revision (integer)
+    - server_guid (string)
+    - max_transact_size (integer)
+    - max_read_size (integer)
+    - max_write_size (integer)
+    - system_time (long)
+    - server_start_time (long)
+    - security_blob (string)
+
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.4
+    """
+
+    STRUCTURE_FORMAT = "<HHHH16sIIIIQQHHI"
+    STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT)
+
+    def decode(self, message):
+        assert message.command == SMB2_COM_NEGOTIATE
+
+        if message.status == 0:
+            struct_size, self.security_mode, self.dialect_revision, _, self.server_guid, self.capabilities, \
+            self.max_transact_size, self.max_read_size, self.max_write_size, self.system_time, self.server_start_time, \
+            security_buf_offset, security_buf_len, _ = struct.unpack(self.STRUCTURE_FORMAT, message.raw_data[SMB2Message.HEADER_SIZE:SMB2Message.HEADER_SIZE+self.STRUCTURE_SIZE])
+
+            self.server_start_time = convertFILETIMEtoEpoch(self.server_start_time)
+            self.system_time = convertFILETIMEtoEpoch(self.system_time)
+            self.security_blob = message.raw_data[security_buf_offset:security_buf_offset+security_buf_len]
+            message.conn.smb2_dialect = self.dialect_revision
+
+
+class SMB2SessionSetupRequest(Structure):
+    """
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.5
+    """
+
+    STRUCTURE_FORMAT = "<HBBIIHHQ"
+    STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT)
+
+    def __init__(self, security_blob):
+        self.security_blob = security_blob
+
+    def initMessage(self, message):
+        Structure.initMessage(self, message)
+        message.command = SMB2_COM_SESSION_SETUP
+
+    def prepare(self, message):
+        message.data = struct.pack(self.STRUCTURE_FORMAT,
+                                   25,   # Structure size. Must be 25 as mandated by [MS-SMB2] 2.2.5
+                                   0,    # VcNumber
+                                   0x01, # Security mode
+                                   0x00, # Capabilities
+                                   0,    # Channel
+                                   SMB2Message.HEADER_SIZE + self.STRUCTURE_SIZE,
+                                   len(self.security_blob),
+                                   0) + self.security_blob
+
+
+class SMB2SessionSetupResponse(Structure):
+    """
+    Contains information about the SMB2_COM_SESSION_SETUP response from the server.
+
+    If the message has no errors, each instance contains the following attributes:
+    - session_flags (integer)
+    - security_blob (string)
+
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.6
+    """
+
+    STRUCTURE_FORMAT = "<HHHH"
+    STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT)
+
+    @property
+    def isGuestSession(self):
+        return (self.session_flags & 0x0001) > 0   # SMB2_SESSION_FLAG_IS_GUEST
+
+    @property
+    def isAnonymousSession(self):
+        return (self.session_flags & 0x0002) > 0   # SMB2_SESSION_FLAG_IS_NULL
+
+    def decode(self, message):
+        assert message.command == SMB2_COM_SESSION_SETUP
+
+        struct_size, self.session_flags, security_blob_offset, security_blob_len \
+            = struct.unpack(self.STRUCTURE_FORMAT, message.raw_data[SMB2Message.HEADER_SIZE:SMB2Message.HEADER_SIZE+self.STRUCTURE_SIZE])
+
+        self.security_blob = message.raw_data[security_blob_offset:security_blob_offset+security_blob_len]
+
+
+class SMB2TreeConnectRequest(Structure):
+    """
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.9
+    """
+
+    STRUCTURE_FORMAT = "<HHHH"
+    STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT)
+
+    def __init__(self, path):
+        self.path = path
+
+    def initMessage(self, message):
+        Structure.initMessage(self, message)
+        message.command = SMB2_COM_TREE_CONNECT
+
+    def prepare(self, message):
+        message.data = struct.pack(self.STRUCTURE_FORMAT,
+                                   9,  # Structure size. Must be 9 as mandated by [MS-SMB2] 2.2.9
+                                   0,  # Reserved
+                                   SMB2Message.HEADER_SIZE + self.STRUCTURE_SIZE,
+                                   len(self.path)*2) + self.path.encode('UTF-16LE')
+
+
+class SMB2TreeConnectResponse(Structure):
+    """
+    Contains information about the SMB2_COM_TREE_CONNECT response from the server.
+
+    If the message has no errors, each instance contains the following attributes:
+    - share_type (integer): one of the SMB2_SHARE_TYPE_xxx constants
+    - share_flags (integer)
+    - capabilities (integer): bitmask of SMB2_SHARE_CAP_xxx
+    - maximal_access (integer)
+
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.10
+    """
+
+    STRUCTURE_FORMAT = "<HBBIII"
+    STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT)
+
+    def decode(self, message):
+        assert message.command == SMB2_COM_TREE_CONNECT
+
+        if message.status == 0:
+            struct_size, self.share_type, _, \
+                self.share_flags, self.capabilities, self.maximal_access \
+                = struct.unpack(self.STRUCTURE_FORMAT, message.raw_data[SMB2Message.HEADER_SIZE:SMB2Message.HEADER_SIZE+self.STRUCTURE_SIZE])
+
+
+class SMB2CreateRequest(Structure):
+    """
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.13
+    """
+
+    STRUCTURE_FORMAT = "<HBBIQQIIIIIHHII"
+    STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT)
+
+    def __init__(self, filename, file_attributes = 0,
+                 access_mask = 0, share_access = 0, create_disp = 0, create_options = 0,
+                 impersonation = SEC_ANONYMOUS,
+                 oplock = SMB2_OPLOCK_LEVEL_NONE,
+                 create_context_data = ''):
+        self.filename = filename
+        self.file_attributes = file_attributes
+        self.access_mask = access_mask
+        self.share_access = share_access
+        self.create_disp = create_disp
+        self.create_options = create_options
+        self.oplock = oplock
+        self.impersonation = impersonation
+        self.create_context_data = create_context_data or ''
+
+    def initMessage(self, message):
+        Structure.initMessage(self, message)
+        message.command = SMB2_COM_CREATE
+
+    def prepare(self, message):
+        buf = self.filename.encode('UTF-16LE')
+        if self.create_context_data:
+            n = SMB2Message.HEADER_SIZE + self.STRUCTURE_SIZE + len(buf)
+            if n % 8 != 0:
+                buf += '\0'*(8-n%8)
+                create_context_offset = SMB2Message.HEADER_SIZE + self.STRUCTURE_SIZE + len(buf)
+            else:
+                create_context_offset = n
+            buf += self.create_context_data
+        else:
+            create_context_offset = 0
+        if not buf:
+            buf = '\0'
+
+        assert create_context_offset % 8 == 0
+        message.data = struct.pack(self.STRUCTURE_FORMAT,
+                                   57,   # Structure size. Must be 57 as mandated by [MS-SMB2] 2.2.13
+                                   0,    # SecurityFlag. Must be 0
+                                   self.oplock,
+                                   self.impersonation,
+                                   0,    # SmbCreateFlags. Must be 0
+                                   0,    # Reserved. Must be 0
+                                   self.access_mask,  # DesiredAccess. [MS-SMB2] 2.2.13.1
+                                   self.file_attributes,
+                                   self.share_access,
+                                   self.create_disp,
+                                   self.create_options,
+                                   SMB2Message.HEADER_SIZE + self.STRUCTURE_SIZE,  # NameOffset
+                                   len(self.filename)*2,    # NameLength in bytes
+                                   create_context_offset,   # CreateContextOffset
+                                   len(self.create_context_data)   # CreateContextLength
+                                  ) + buf
+
+class SMB2CreateResponse(Structure):
+    """
+    Contains information about the SMB2_COM_CREATE response from the server.
+
+    If the message has no errors, each instance contains the following attributes:
+    - oplock (integer): one of SMB2_OPLOCK_LEVEL_xxx constants
+    - create_action (integer): one of SMB2_FILE_xxx constants
+    - allocation_size (long)
+    - file_size (long)
+    - file_attributes (integer)
+    - fid (16-bytes string)
+    - create_time, lastaccess_time, lastwrite_time, change_time (float)
+
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.14
+    """
+
+    STRUCTURE_FORMAT = "<HBBIQQQQQQII16sII"
+    STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT)
+
+    def decode(self, message):
+        assert message.command == SMB2_COM_CREATE
+
+        if message.status == 0:
+            struct_size, self.oplock, _, self.create_action, \
+            create_time, lastaccess_time, lastwrite_time, change_time, \
+            self.allocation_size, self.file_size, self.file_attributes, \
+            _, self.fid, _, _ = struct.unpack(self.STRUCTURE_FORMAT, message.raw_data[SMB2Message.HEADER_SIZE:SMB2Message.HEADER_SIZE+self.STRUCTURE_SIZE])
+
+            self.create_time = convertFILETIMEtoEpoch(create_time)
+            self.lastaccess_time = convertFILETIMEtoEpoch(lastaccess_time)
+            self.lastwrite_time = convertFILETIMEtoEpoch(lastwrite_time)
+            self.change_time = convertFILETIMEtoEpoch(change_time)
+
+
+class SMB2WriteRequest(Structure):
+    """
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.21
+    """
+
+    STRUCTURE_FORMAT = "<HHIQ16sIIHHI"
+    STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT)
+
+    def __init__(self, fid, data, offset, remaining_len = 0, flags = 0):
+        assert len(fid) == 16
+        self.fid = fid
+        self.data = data
+        self.offset = offset
+        self.remaining_len = remaining_len
+        self.flags = flags
+
+    def initMessage(self, message):
+        Structure.initMessage(self, message)
+        message.command = SMB2_COM_WRITE
+
+    def prepare(self, message):
+        message.data = struct.pack(self.STRUCTURE_FORMAT,
+                                   49,  # Structure size. Must be 49 as mandated by [MS-SMB2] 2.2.21
+                                   SMB2Message.HEADER_SIZE + self.STRUCTURE_SIZE,  # DataOffset
+                                   len(self.data),
+                                   self.offset,
+                                   self.fid,
+                                   0,  # Channel. Must be 0
+                                   self.remaining_len,  # RemainingBytes
+                                   0,  # WriteChannelInfoOffset,
+                                   0,  # WriteChannelInfoLength
+                                   self.flags) + self.data
+
+        # MS-SMB2 3.2.4.7
+        # If a client requests writing to a file, Connection.Dialect is not "2.0.2", and if
+        # Connection.SupportsMultiCredit is TRUE, the CreditCharge field in the SMB2 header MUST be set
+        # to ( 1 + (Length - 1) / 65536 )
+        if message.conn.smb2_dialect != SMB2_DIALECT_2 and message.conn.cap_multi_credit:
+            message.credit_charge = int(1 + (len(self.data) -1) / 65536)
+
+
+class SMB2WriteResponse(Structure):
+    """
+    Contains information about the SMB2_WRITE response from the server.
+
+    If the message has no errors, each instance contains the following attributes:
+    - count (integer)
+
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.22
+    """
+
+    STRUCTURE_FORMAT = "<HHIIHH"
+    STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT)
+
+    def decode(self, message):
+        assert message.command == SMB2_COM_WRITE
+        if message.status == 0:
+            struct_size, _, self.count, _, _, _ = struct.unpack(self.STRUCTURE_FORMAT, message.raw_data[SMB2Message.HEADER_SIZE:SMB2Message.HEADER_SIZE+self.STRUCTURE_SIZE])
+
+
+
+class SMB2ReadRequest(Structure):
+    """
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.19
+    """
+
+    STRUCTURE_FORMAT = "<HBBIQ16sIIIHH"
+    STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT)
+
+    def __init__(self, fid, read_offset, read_len, min_read_len = 0):
+        self.fid = fid
+        self.read_offset = read_offset
+        self.read_len = read_len
+        self.min_read_len = min_read_len
+
+    def initMessage(self, message):
+        Structure.initMessage(self, message)
+        message.command = SMB2_COM_READ
+
+    def prepare(self, message):
+        message.data = struct.pack(self.STRUCTURE_FORMAT,
+                                   49,   # Structure size. Must be 49 as mandated by [MS-SMB2] 2.2.19
+                                   0,    # Padding
+                                   0,    # Reserved
+                                   self.read_len,
+                                   self.read_offset,
+                                   self.fid,
+                                   self.min_read_len,
+                                   0,    # Channel
+                                   0,    # RemainingBytes
+                                   0,    # ReadChannelInfoOffset
+                                   0     # ReadChannelInfoLength
+                                  ) + '\0'
+
+        # MS-SMB2 3.2.4.6
+        # If a client requests reading from a file, Connection.Dialect is not "2.0.2", and if
+        # Connection.SupportsMultiCredit is TRUE, the CreditCharge field in the SMB2 header MUST be set
+        # to ( 1 + (Length - 1) / 65536 )
+        if message.conn.smb2_dialect != SMB2_DIALECT_2 and message.conn.cap_multi_credit:
+            message.credit_charge = int(1 + (self.read_len -1) / 65536)
+
+
+class SMB2ReadResponse(Structure):
+    """
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.20
+    """
+
+    STRUCTURE_FORMAT = "<HBBIII"
+    STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT)
+
+    def decode(self, message):
+        assert message.command == SMB2_COM_READ
+
+        if message.status == 0:
+            struct_size, data_offset, _, self.data_length, _, _ = struct.unpack(self.STRUCTURE_FORMAT, message.raw_data[SMB2Message.HEADER_SIZE:SMB2Message.HEADER_SIZE+self.STRUCTURE_SIZE])
+            self.data = message.raw_data[data_offset:data_offset+self.data_length]
+
+
+class SMB2IoctlRequest(Structure):
+    """
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.31
+    """
+
+    STRUCTURE_FORMAT = "<HHI16sIIIIIIII"
+    STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT)
+
+    def __init__(self, fid, ctlcode, flags, in_data, max_out_size = 65536):
+        self.ctlcode = ctlcode
+        self.fid = fid
+        self.flags = flags
+        self.in_data = in_data
+        self.max_out_size = max_out_size
+
+    def initMessage(self, message):
+        Structure.initMessage(self, message)
+        message.command = SMB2_COM_IOCTL
+
+    def prepare(self, message):
+        message.data = struct.pack(self.STRUCTURE_FORMAT,
+                                   57,   # Structure size. Must be 57 as mandated by [MS-SMB2] 2.2.31
+                                   0,    # Reserved
+                                   self.ctlcode,  # CtlCode
+                                   self.fid,
+                                   SMB2Message.HEADER_SIZE + self.STRUCTURE_SIZE,  # InputOffset
+                                   len(self.in_data),  # InputCount
+                                   0,   # MaxInputResponse
+                                   0,   # OutputOffset
+                                   0,   # OutputCount
+                                   self.max_out_size,   # MaxOutputResponse
+                                   self.flags,   # Flags
+                                   0    # Reserved
+                                  ) + self.in_data
+
+        # If Connection.SupportsMultiCredit is TRUE, the CreditCharge field in the SMB2 header
+        # SHOULD be set to (max(InputCount, MaxOutputResponse) - 1) / 65536 + 1
+        if message.conn.smb2_dialect != SMB2_DIALECT_2 and message.conn.cap_multi_credit:
+            message.credit_charge = int((max(len(self.in_data), self.max_out_size) - 1) / 65536 + 1)
+
+
+class SMB2IoctlResponse(Structure):
+    """
+    Contains information about the SMB2_IOCTL response from the server.
+
+    If the message has no errors, each instance contains the following attributes:
+    - ctlcode (integer)
+    - fid (16-bytes string)
+    - flags (integer)
+    - in_data (string)
+    - out_data (string)
+
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.32
+    """
+
+    STRUCTURE_FORMAT = "<HHI16sIIIIII"
+    STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT)
+
+    def decode(self, message):
+        assert message.command == SMB2_COM_IOCTL
+
+        if message.status == 0:
+            struct_size, _, self.ctlcode, self.fid, \
+            input_offset, input_len, output_offset, output_len, \
+            self.flags, _ = struct.unpack(self.STRUCTURE_FORMAT, message.raw_data[SMB2Message.HEADER_SIZE:SMB2Message.HEADER_SIZE+self.STRUCTURE_SIZE])
+
+            if input_len > 0:
+                self.in_data = message.raw_data[input_offset:input_offset+input_len]
+            else:
+                self.in_data = ''
+
+            if output_len > 0:
+                self.out_data = message.raw_data[output_offset:output_offset+output_len]
+            else:
+                self.out_data = ''
+
+
+class SMB2CloseRequest(Structure):
+    """
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.15
+    """
+
+    STRUCTURE_FORMAT = "<HHI16s"
+    STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT)
+
+    def __init__(self, fid, flags = 0):
+        self.fid = fid
+        self.flags = flags
+
+    def initMessage(self, message):
+        Structure.initMessage(self, message)
+        message.command = SMB2_COM_CLOSE
+
+    def prepare(self, message):
+        message.data = struct.pack(self.STRUCTURE_FORMAT,
+                                   24,  # Structure size. Must be 24 as mandated by [MS-SMB2]: 2.2.15
+                                   self.flags,
+                                   0,   # Reserved. Must be 0
+                                   self.fid)
+
+
+class SMB2CloseResponse(Structure):
+    """
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.16
+    """
+
+    def decode(self, message):
+        assert message.command == SMB2_COM_CLOSE
+
+
+class SMB2QueryDirectoryRequest(Structure):
+    """
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.33
+    """
+
+    STRUCTURE_FORMAT = "<HBBI16sHHI"
+    STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT)
+
+    def __init__(self, fid, filename, info_class, flags, output_buf_len):
+        self.fid = fid
+        self.filename = filename
+        self.info_class = info_class
+        self.flags = flags
+        self.output_buf_len = output_buf_len
+
+    def initMessage(self, message):
+        Structure.initMessage(self, message)
+        message.command = SMB2_COM_QUERY_DIRECTORY
+
+    def prepare(self, message):
+        message.data = struct.pack(self.STRUCTURE_FORMAT,
+                                   33,   # Structure size. Must be 33 as mandated by [MS-SMB2] 2.2.33
+                                   self.info_class,   # FileInformationClass
+                                   self.flags,        # Flags
+                                   0,                 # FileIndex
+                                   self.fid,          # FileID
+                                   SMB2Message.HEADER_SIZE + self.STRUCTURE_SIZE,  # FileNameOffset
+                                   len(self.filename)*2,
+                                   self.output_buf_len) + self.filename.encode('UTF-16LE')
+
+        # MS-SMB2 3.2.4.17
+        # If Connection.Dialect is not "2.0.2" and if Connection.SupportsMultiCredit is TRUE, the
+        # CreditCharge field in the SMB2 header MUST be set to ( 1 + (OutputBufferLength - 1) / 65536 )
+        if message.conn.smb2_dialect != SMB2_DIALECT_2 and message.conn.cap_multi_credit:
+            message.credit_charge = int(1 + (self.output_buf_len -1) / 65536)
+
+
+class SMB2QueryDirectoryResponse(Structure):
+    """
+    Contains information about the SMB2_COM_QUERY_DIRECTORY response from the server.
+
+    If the message has no errors, each instance contains the following attributes:
+    - data_length (integer)
+    - data (string)
+
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.34
+    """
+
+    STRUCTURE_FORMAT = "<HHI"
+    STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT)
+
+    def decode(self, message):
+        assert message.command == SMB2_COM_QUERY_DIRECTORY
+
+        if message.status == 0:
+            struct_size, offset, self.data_length = struct.unpack(self.STRUCTURE_FORMAT, message.raw_data[SMB2Message.HEADER_SIZE:SMB2Message.HEADER_SIZE+self.STRUCTURE_SIZE])
+            self.data = message.raw_data[offset:offset+self.data_length]
+
+
+class SMB2QueryInfoRequest(Structure):
+    """
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.37
+    """
+
+    STRUCTURE_FORMAT = "<HBBIHHIII16s"
+    STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT)
+
+    def __init__(self, fid, flags, additional_info, info_type, file_info_class, input_buf, output_buf_len):
+        self.fid = fid
+        self.flags = flags
+        self.additional_info = additional_info
+        self.info_type = info_type
+        self.file_info_class = file_info_class
+        self.output_buf_len = output_buf_len
+        self.input_buf = input_buf or ''
+
+    def initMessage(self, message):
+        Structure.initMessage(self, message)
+        message.command = SMB2_COM_QUERY_INFO
+
+    def prepare(self, message):
+        message.data = struct.pack(self.STRUCTURE_FORMAT,
+                                   41,  # Structure size. Must be 41 as mandated by [MS-SMB2] 2.2.37
+                                   self.info_type,         # InfoType
+                                   self.file_info_class,   # FileInfoClass
+                                   self.output_buf_len,    # OutputBufferLength
+                                   SMB2Message.HEADER_SIZE + self.STRUCTURE_SIZE,  # InputBufferOffset
+                                   0,   # Reserved
+                                   len(self.input_buf),    # InputBufferLength
+                                   self.additional_info,   # AdditionalInformation
+                                   self.flags,             # Flags
+                                   self.fid                # FileId
+                                  ) + self.input_buf
+
+        # MS-SMB2 3.2.4.17
+        # If Connection.Dialect is not "2.0.2" and if Connection.SupportsMultiCredit is TRUE, the
+        # CreditCharge field in the SMB2 header MUST be set to ( 1 + (OutputBufferLength - 1) / 65536 )
+        if message.conn.smb2_dialect != SMB2_DIALECT_2 and message.conn.cap_multi_credit:
+            message.credit_charge = int(1 + ((self.output_buf_len + len(self.input_buf)) -1) / 65536)
+
+
+class SMB2QueryInfoResponse(Structure):
+    """
+    Contains information about the SMB2_COM_QUERY_INFO response from the server.
+
+    If the message has no errors, each instance contains the following attributes:
+    - data_length (integer)
+    - data (string)
+
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.38
+    """
+
+    STRUCTURE_FORMAT = "<HHI"
+    STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT)
+
+    def decode(self, message):
+        assert message.command == SMB2_COM_QUERY_INFO
+
+        if message.status == 0:
+            struct_size, buf_offset, self.data_length = struct.unpack(self.STRUCTURE_FORMAT, message.raw_data[SMB2Message.HEADER_SIZE:SMB2Message.HEADER_SIZE+self.STRUCTURE_SIZE])
+            self.data = message.raw_data[buf_offset:buf_offset+self.data_length]
+
+
+class SMB2SetInfoRequest(Structure):
+    """
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.39
+    """
+
+    STRUCTURE_FORMAT = "<HBBIHHI16s"
+    STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT)
+
+    def __init__(self, fid, additional_info, info_type, file_info_class, data):
+        self.fid = fid
+        self.additional_info = additional_info
+        self.info_type = info_type
+        self.file_info_class = file_info_class
+        self.data = data or ''
+
+    def initMessage(self, message):
+        Structure.initMessage(self, message)
+        message.command = SMB2_COM_SET_INFO
+
+    def prepare(self, message):
+        message.data = struct.pack(self.STRUCTURE_FORMAT,
+                                   33,   # StructureSize. Must be 33 as mandated by [MS-SMB2] 2.2.39
+                                   self.info_type,        # InfoType
+                                   self.file_info_class,  # FileInfoClass
+                                   len(self.data),        # BufferLength
+                                   SMB2Message.HEADER_SIZE + self.STRUCTURE_SIZE,  # BufferOffset
+                                   0,   # Reserved
+                                   self.additional_info,  # AdditionalInformation
+                                   self.fid               # FileId
+                                  ) + self.data
+
+        # MS-SMB2 3.2.4.17
+        # If Connection.Dialect is not "2.0.2" and if Connection.SupportsMultiCredit is TRUE, the
+        # CreditCharge field in the SMB2 header MUST be set to ( 1 + (OutputBufferLength - 1) / 65536 )
+        if message.conn.smb2_dialect != SMB2_DIALECT_2 and message.conn.cap_multi_credit:
+            message.credit_charge = int(1 + (len(self.data) -1) / 65536)
+
+class SMB2SetInfoResponse(Structure):
+    """
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.40
+    """
+
+    def decode(self, message):
+        pass
+
+
+class SMB2EchoRequest(Structure):
+    """
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.28
+    """
+
+    STRUCTURE_FORMAT = '<HH'
+    STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT)
+
+    def initMessage(self, message):
+        Structure.initMessage(self, message)
+        message.command = SMB2_COM_ECHO
+
+    def prepare(self, message):
+        message.data = struct.pack(self.STRUCTURE_FORMAT,
+                                   4,   # StructureSize. Must be 4 as mandated by [MS-SMB2] 2.2.29
+                                   0)   # Reserved
+
+class SMB2EchoResponse(Structure):
+    """
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.29
+    """
+
+    def decode(self, message):
+        pass
diff --git a/python2/smb/smb_constants.py b/python2/smb/smb_constants.py
new file mode 100644
index 00000000..99476802
--- /dev/null
+++ b/python2/smb/smb_constants.py
@@ -0,0 +1,257 @@
+
+# Values for Command field in SMB message header
+SMB_COM_CREATE_DIRECTORY = 0x00
+SMB_COM_DELETE_DIRECTORY = 0x01
+SMB_COM_CLOSE = 0x04
+SMB_COM_DELETE = 0x06
+SMB_COM_RENAME = 0x07
+SMB_COM_TRANSACTION = 0x25
+SMB_COM_ECHO = 0x2B
+SMB_COM_OPEN_ANDX = 0x2D
+SMB_COM_READ_ANDX = 0x2E
+SMB_COM_WRITE_ANDX = 0x2F
+SMB_COM_TRANSACTION2 = 0x32
+SMB_COM_NEGOTIATE = 0x72
+SMB_COM_SESSION_SETUP_ANDX = 0x73
+SMB_COM_TREE_CONNECT_ANDX = 0x75
+SMB_COM_NT_TRANSACT = 0xA0
+SMB_COM_NT_CREATE_ANDX = 0xA2
+
+SMB_COMMAND_NAMES = {
+    0x00: 'SMB_COM_CREATE_DIRECTORY',
+    0x01: 'SMB_COM_DELETE_DIRECTORY',
+    0x04: 'SMB_COM_CLOSE',
+    0x06: 'SMB_COM_DELETE',
+    0x25: 'SMB_COM_TRANSACTION',
+    0x2B: 'SMB_COM_ECHO',
+    0x2D: 'SMB_COM_OPEN_ANDX',
+    0x2E: 'SMB_COM_READ_ANDX',
+    0x2F: 'SMB_COM_WRITE_ANDX',
+    0x32: 'SMB_COM_TRANSACTION2',
+    0x72: 'SMB_COM_NEGOTIATE',
+    0x73: 'SMB_COM_SESSION_SETUP_ANDX',
+    0x75: 'SMB_COM_TREE_CONNECT_ANDX',
+    0xA0: 'SMB_COM_NT_TRANSACT',
+    0xA2: 'SMB_COM_NT_CREATE_ANDX',
+}
+
+# Bitmask for Flags field in SMB message header
+SMB_FLAGS_LOCK_AND_READ_OK = 0x01       # LANMAN1.0
+SMB_FLAGS_BUF_AVAIL = 0x02              # LANMAN1.0, Obsolete
+SMB_FLAGS_CASE_INSENSITIVE = 0x08       # LANMAN1.0, Obsolete
+SMB_FLAGS_CANONICALIZED_PATHS = 0x10    # LANMAN1.0, Obsolete
+SMB_FLAGS_OPLOCK = 0x20                 # LANMAN1.0, Obsolete
+SMB_FLAGS_OPBATCH = 0x40                # LANMAN1.0, Obsolete
+SMB_FLAGS_REPLY = 0x80                  # LANMAN1.0
+
+# Bitmask for Flags2 field in SMB message header
+SMB_FLAGS2_LONG_NAMES = 0x0001              # LANMAN2.0
+SMB_FLAGS2_EAS = 0x0002                     # LANMAN1.2
+SMB_FLAGS2_SMB_SECURITY_SIGNATURE = 0x0004  # NT LANMAN
+SMB_FLAGS2_IS_LONG_NAME = 0x0040            # NT LANMAN
+SMB_FLAGS2_DFS = 0x1000                     # NT LANMAN
+SMB_FLAGS2_REPARSE_PATH = 0x0400            #
+SMB_FLAGS2_EXTENDED_SECURITY = 0x0800       #
+SMB_FLAGS2_PAGING_IO = 0x2000               # NT LANMAN
+SMB_FLAGS2_NT_STATUS = 0x4000               # NT LANMAN
+SMB_FLAGS2_UNICODE = 0x8000                 # NT LANMAN
+
+# Bitmask for Capabilities field in SMB_COM_SESSION_SETUP_ANDX response
+# [MS-SMB]: 2.2.4.5.2.1 (Capabilities field)
+CAP_RAW_MODE = 0x01
+CAP_MPX_MODE = 0x02
+CAP_UNICODE = 0x04
+CAP_LARGE_FILES = 0x08
+CAP_NT_SMBS = 0x10
+CAP_RPC_REMOTE_APIS = 0x20
+CAP_STATUS32 = 0x40
+CAP_LEVEL_II_OPLOCKS = 0x80
+CAP_LOCK_AND_READ = 0x0100
+CAP_NT_FIND = 0x0200
+CAP_DFS = 0x1000
+CAP_INFOLEVEL_PASSTHRU = 0x2000
+CAP_LARGE_READX = 0x4000
+CAP_LARGE_WRITEX = 0x8000
+CAP_LWIO = 0x010000
+CAP_UNIX = 0x800000
+CAP_COMPRESSED = 0x02000000
+CAP_DYNAMIC_REAUTH = 0x20000000
+CAP_PERSISTENT_HANDLES = 0x40000000
+CAP_EXTENDED_SECURITY = 0x80000000
+
+# Value for Action field in SMB_COM_SESSION_SETUP_ANDX response
+SMB_SETUP_GUEST = 0x0001
+SMB_SETUP_USE_LANMAN_KEY = 0X0002
+
+# Bitmask for SecurityMode field in SMB_COM_NEGOTIATE response
+NEGOTIATE_USER_SECURITY = 0x01
+NEGOTIATE_ENCRYPT_PASSWORDS = 0x02
+NEGOTIATE_SECURITY_SIGNATURES_ENABLE = 0x04
+NEGOTIATE_SECURITY_SIGNATURES_REQUIRE = 0x08
+
+# Available constants for Service field in SMB_COM_TREE_CONNECT_ANDX request
+# [MS-CIFS]: 2.2.4.55.1 (Service field)
+SERVICE_PRINTER = 'LPT1:'
+SERVICE_NAMED_PIPE = 'IPC'
+SERVICE_COMM = 'COMM'
+SERVICE_ANY = '?????'
+
+# Bitmask for Flags field in SMB_COM_NT_CREATE_ANDX request
+# [MS-CIFS]: 2.2.4.64.1
+# [MS-SMB]: 2.2.4.9.1
+NT_CREATE_REQUEST_OPLOCK = 0x02
+NT_CREATE_REQUEST_OPBATCH = 0x04
+NT_CREATE_OPEN_TARGET_DIR = 0x08
+NT_CREATE_REQUEST_EXTENDED_RESPONSE = 0x10  # Defined in [MS-SMB]: 2.2.4.9.1
+
+# Bitmask for DesiredAccess field in SMB_COM_NT_CREATE_ANDX request
+# and SMB2CreateRequest class
+# Also used for MaximalAccess field in SMB2TreeConnectResponse class
+# [MS-CIFS]: 2.2.4.64.1
+# [MS-SMB2]: 2.2.13.1.1
+FILE_READ_DATA = 0x01
+FILE_WRITE_DATA = 0X02
+FILE_APPEND_DATA = 0x04
+FILE_READ_EA = 0x08
+FILE_WRITE_EA = 0x10
+FILE_EXECUTE = 0x20
+FILE_DELETE_CHILD = 0x40
+FILE_READ_ATTRIBUTES = 0x80
+FILE_WRITE_ATTRIBUTES = 0x0100
+DELETE = 0x010000
+READ_CONTROL = 0x020000
+WRITE_DAC = 0x040000
+WRITE_OWNER = 0x080000
+SYNCHRONIZE = 0x100000
+ACCESS_SYSTEM_SECURITY = 0x01000000
+MAXIMUM_ALLOWED = 0x02000000
+GENERIC_ALL = 0x10000000
+GENERIC_EXECUTE = 0x20000000
+GENERIC_WRITE = 0x40000000
+GENERIC_READ = 0x80000000L
+
+# SMB_EXT_FILE_ATTR bitmask ([MS-CIFS]: 2.2.1.2.3)
+# Includes extensions defined in [MS-SMB] 2.2.1.2.1
+# Bitmask for FileAttributes field in SMB_COM_NT_CREATE_ANDX request ([MS-CIFS]: 2.2.4.64.1)
+# Also used for FileAttributes field in SMB2CreateRequest class ([MS-SMB2]: 2.2.13)
+ATTR_READONLY = 0x01
+ATTR_HIDDEN = 0x02
+ATTR_SYSTEM = 0x04
+ATTR_DIRECTORY = 0x10
+ATTR_ARCHIVE = 0x20
+ATTR_NORMAL = 0x80
+ATTR_TEMPORARY = 0x0100
+ATTR_SPARSE = 0x0200
+ATTR_REPARSE_POINT = 0x0400
+ATTR_COMPRESSED = 0x0800
+ATTR_OFFLINE = 0x1000
+ATTR_NOT_CONTENT_INDEXED = 0x2000
+ATTR_ENCRYPTED = 0x4000
+POSIX_SEMANTICS = 0x01000000
+BACKUP_SEMANTICS = 0x02000000
+DELETE_ON_CLOSE = 0x04000000
+SEQUENTIAL_SCAN = 0x08000000
+RANDOM_ACCESS = 0x10000000
+NO_BUFFERING = 0x20000000
+WRITE_THROUGH = 0x80000000
+
+# Bitmask for ShareAccess field in SMB_COM_NT_CREATE_ANDX request
+# and SMB2CreateRequest class
+# [MS-CIFS]: 2.2.4.64.1
+# [MS-SMB2]: 2.2.13
+FILE_SHARE_NONE = 0x00
+FILE_SHARE_READ = 0x01
+FILE_SHARE_WRITE = 0x02
+FILE_SHARE_DELETE = 0x04
+
+# Values for CreateDisposition field in SMB_COM_NT_CREATE_ANDX request
+# and SMB2CreateRequest class
+# [MS-CIFS]: 2.2.4.64.1
+# [MS-SMB2]: 2.2.13
+FILE_SUPERSEDE = 0x00
+FILE_OPEN = 0x01
+FILE_CREATE = 0x02
+FILE_OPEN_IF = 0x03
+FILE_OVERWRITE = 0x04
+FILE_OVERWRITE_IF = 0x05
+
+# Bitmask for CreateOptions field in SMB_COM_NT_CREATE_ANDX request
+# and SMB2CreateRequest class
+# [MS-CIFS]: 2.2.4.64.1
+# [MS-SMB2]: 2.2.13
+FILE_DIRECTORY_FILE = 0x01
+FILE_WRITE_THROUGH = 0x02
+FILE_SEQUENTIAL_ONLY = 0x04
+FILE_NO_INTERMEDIATE_BUFFERING = 0x08
+FILE_SYNCHRONOUS_IO_ALERT = 0x10
+FILE_SYNCHRONOUS_IO_NONALERT = 0x20
+FILE_NON_DIRECTORY_FILE = 0x40
+FILE_CREATE_TREE_CONNECTION = 0x80
+FILE_COMPLETE_IF_OPLOCKED = 0x0100
+FILE_NO_EA_KNOWLEDGE = 0x0200
+FILE_OPEN_FOR_RECOVERY = 0x0400
+FILE_RANDOM_ACCESS = 0x0800
+FILE_DELETE_ON_CLOSE = 0x1000
+FILE_OPEN_BY_FILE_ID = 0x2000
+FILE_OPEN_FOR_BACKUP_INTENT = 0x4000
+FILE_NO_COMPRESSION = 0x8000
+FILE_RESERVE_OPFILTER = 0x100000
+FILE_OPEN_NO_RECALL = 0x400000
+FILE_OPEN_FOR_FREE_SPACE_QUERY = 0x800000
+
+# Values for ImpersonationLevel field in SMB_COM_NT_CREATE_ANDX request
+# and SMB2CreateRequest class
+# For interpretations about these values, refer to [MS-WSO] and [MSDN-IMPERS]
+# [MS-CIFS]: 2.2.4.64.1
+# [MS-SMB]: 2.2.4.9.1
+# [MS-SMB2]: 2.2.13
+SEC_ANONYMOUS = 0x00
+SEC_IDENTIFY = 0x01
+SEC_IMPERSONATE = 0x02
+SEC_DELEGATION = 0x03   # Defined in [MS-SMB]: 2.2.4.9.1
+
+# Values for SecurityFlags field in SMB_COM_NT_CREATE_ANDX request
+# [MS-CIFS]: 2.2.4.64.1
+SMB_SECURITY_CONTEXT_TRACKING = 0x01
+SMB_SECURITY_EFFECTIVE_ONLY = 0x02
+
+# Bitmask for Flags field in SMB_COM_TRANSACTION2 request
+# [MS-CIFS]: 2.2.4.46.1
+DISCONNECT_TID = 0x01
+NO_RESPONSE = 0x02
+
+# Bitmask for basic file attributes
+# [MS-CIFS]: 2.2.1.2.4
+SMB_FILE_ATTRIBUTE_NORMAL = 0x00
+SMB_FILE_ATTRIBUTE_READONLY = 0x01
+SMB_FILE_ATTRIBUTE_HIDDEN = 0x02
+SMB_FILE_ATTRIBUTE_SYSTEM = 0x04
+SMB_FILE_ATTRIBUTE_VOLUME = 0x08  # Unsupported for listPath() operations
+SMB_FILE_ATTRIBUTE_DIRECTORY = 0x10
+SMB_FILE_ATTRIBUTE_ARCHIVE = 0x20
+# SMB_FILE_ATTRIBUTE_INCL_NORMAL is a special placeholder to include normal files for
+# with other search attributes for listPath() operations. It is not defined in the MS-CIFS specs.
+SMB_FILE_ATTRIBUTE_INCL_NORMAL = 0x10000
+# Do not use the following values for listPath() operations as they are not supported for SMB2
+SMB_SEARCH_ATTRIBUTE_READONLY = 0x0100
+SMB_SEARCH_ATTRIBUTE_HIDDEN = 0x0200
+SMB_SEARCH_ATTRIBUTE_SYSTEM = 0x0400
+SMB_SEARCH_ATTRIBUTE_DIRECTORY = 0x1000
+SMB_SEARCH_ATTRIBUTE_ARCHIVE = 0x2000
+
+# Bitmask for OptionalSupport field in SMB_COM_TREE_CONNECT_ANDX response
+SMB_TREE_CONNECTX_SUPPORT_SEARCH = 0x0001
+SMB_TREE_CONNECTX_SUPPORT_DFS = 0x0002
+
+# Bitmask for security information fields, specified as
+# AdditionalInformation in SMB2
+# [MS-SMB]: 2.2.7.4
+# [MS-SMB2]: 2.2.37
+OWNER_SECURITY_INFORMATION = 0x00000001
+GROUP_SECURITY_INFORMATION = 0x00000002
+DACL_SECURITY_INFORMATION = 0x00000004
+SACL_SECURITY_INFORMATION = 0x00000008
+LABEL_SECURITY_INFORMATION = 0x00000010
+ATTRIBUTE_SECURITY_INFORMATION = 0x00000020
+SCOPE_SECURITY_INFORMATION = 0x00000040
+BACKUP_SECURITY_INFORMATION = 0x00010000
diff --git a/python2/smb/smb_structs.py b/python2/smb/smb_structs.py
new file mode 100644
index 00000000..aa81ac9c
--- /dev/null
+++ b/python2/smb/smb_structs.py
@@ -0,0 +1,1421 @@
+
+import os, sys, struct, types, logging, binascii, time
+from StringIO import StringIO
+from smb_constants import *
+
+
+# Set to True if you want to enable support for extended security. Required for Windows Vista and later
+SUPPORT_EXTENDED_SECURITY = True
+
+# Set to True if you want to enable SMB2 protocol.
+SUPPORT_SMB2 = True
+
+# Set to True if you want to enable SMB2.1 and above protocol.
+SUPPORT_SMB2x = True
+
+# Supported dialects
+NT_LAN_MANAGER_DIALECT = 0  # 'NT LM 0.12' is always the first element in the dialect list and must always be included (MS-SMB 2.2.4.5.1)
+
+# Return the list of support SMB dialects based on the SUPPORT_x constants
+def init_dialects_list():
+    dialects = [ 'NT LM 0.12' ]
+    if SUPPORT_SMB2:
+        dialects.append('SMB 2.002')
+    if SUPPORT_SMB2x:
+        dialects.append('SMB 2.???')
+    return dialects
+
+class UnsupportedFeature(Exception):
+    """
+    Raised when an supported feature is present/required in the protocol but is not
+    currently supported by pysmb
+    """
+    pass
+
+
+class ProtocolError(Exception):
+
+    def __init__(self, message, data_buf = None, smb_message = None):
+        self.message = message
+        self.data_buf = data_buf
+        self.smb_message = smb_message
+
+    def __str__(self):
+        b = StringIO()
+        b.write(self.message + os.linesep)
+        if self.smb_message:
+            b.write('=' * 20 + ' SMB Message ' + '=' * 20 + os.linesep)
+            b.write(str(self.smb_message))
+
+        if self.data_buf:
+            b.write('=' * 20 + ' SMB Data Packet (hex) ' + '=' * 20 + os.linesep)
+            b.write(binascii.hexlify(self.data_buf))
+            b.write(os.linesep)
+
+        return b.getvalue()
+
+class SMB2ProtocolHeaderError(ProtocolError):
+
+    def __init__(self):
+        ProtocolError.__init__(self, "Packet header belongs to SMB2")
+
+class OperationFailure(Exception):
+
+    def __init__(self, message, smb_messages):
+        self.args = [ message ]
+        self.message = message
+        self.smb_messages = smb_messages
+
+    def __str__(self):
+        b = StringIO()
+        b.write(self.message + os.linesep)
+
+        for idx, m in enumerate(self.smb_messages):
+            b.write('=' * 20 + ' SMB Message %d ' % idx + '=' * 20 + os.linesep)
+            b.write('SMB Header:' + os.linesep)
+            b.write('-----------' + os.linesep)
+            b.write(str(m))
+            b.write('SMB Data Packet (hex):' + os.linesep)
+            b.write('----------------------' + os.linesep)
+            b.write(binascii.hexlify(m.raw_data))
+            b.write(os.linesep)
+
+        return b.getvalue()
+
+
+class SMBError:
+
+    def __init__(self):
+        self.reset()
+
+    def reset(self):
+        self.internal_value = 0L
+        self.is_ntstatus = True
+
+    def __str__(self):
+        if self.is_ntstatus:
+            return 'NTSTATUS=0x%08X' % self.internal_value
+        else:
+            return 'ErrorClass=0x%02X ErrorCode=0x%04X' % ( self.internal_value >> 24, self.internal_value & 0xFFFF )
+
+    @property
+    def hasError(self):
+        return self.internal_value != 0
+
+
+class SMBMessage:
+
+    HEADER_STRUCT_FORMAT = "<4sBIBHHQxxHHHHB"
+    HEADER_STRUCT_SIZE = struct.calcsize(HEADER_STRUCT_FORMAT)
+
+    log = logging.getLogger('SMB.SMBMessage')
+    protocol = 1
+
+    def __init__(self, conn, payload = None):
+        self.reset()
+        self.conn = conn
+        if payload:
+            self.payload = payload
+            self.payload.initMessage(self)
+
+    def __str__(self):
+        b = StringIO()
+        b.write('Command: 0x%02X (%s) %s' % ( self.command, SMB_COMMAND_NAMES.get(self.command, '<unknown>'), os.linesep ))
+        b.write('Status: %s %s' % ( str(self.status), os.linesep ))
+        b.write('Flags: 0x%02X %s' % ( self.flags, os.linesep ))
+        b.write('Flags2: 0x%04X %s' % ( self.flags2, os.linesep ))
+        b.write('PID: %d %s' % ( self.pid, os.linesep ))
+        b.write('UID: %d %s' % ( self.uid, os.linesep ))
+        b.write('MID: %d %s' % ( self.mid, os.linesep ))
+        b.write('TID: %d %s' % ( self.tid, os.linesep ))
+        b.write('Security: 0x%016X %s' % ( self.security, os.linesep ))
+        b.write('Parameters: %d bytes %s%s %s' % ( len(self.parameters_data), os.linesep, binascii.hexlify(self.parameters_data), os.linesep ))
+        b.write('Data: %d bytes %s%s %s' % ( len(self.data), os.linesep, binascii.hexlify(self.data), os.linesep ))
+        return b.getvalue()
+
+    def reset(self):
+        self.raw_data = ''
+        self.command = 0
+        self.status = SMBError()
+        self.flags = 0
+        self.flags2 = 0
+        self.pid = 0
+        self.tid = 0
+        self.uid = 0
+        self.mid = 0
+        self.security = 0L
+        self.parameters_data = ''
+        self.data = ''
+        self.payload = None
+
+    @property
+    def isReply(self):
+        return bool(self.flags & SMB_FLAGS_REPLY)
+
+    @property
+    def hasExtendedSecurity(self):
+        return bool(self.flags2 & SMB_FLAGS2_EXTENDED_SECURITY)
+
+    def encode(self):
+        """
+        Encode this SMB message into a series of bytes suitable to be embedded with a NetBIOS session message.
+        AssertionError will be raised if this SMB message has not been initialized with a Payload instance
+
+        @return: a string containing the encoded SMB message
+        """
+        assert self.payload
+
+        self.pid = os.getpid()
+        self.payload.prepare(self)
+
+        parameters_len = len(self.parameters_data)
+        assert parameters_len % 2 == 0
+
+        headers_data = struct.pack(self.HEADER_STRUCT_FORMAT,
+                                   '\xFFSMB', self.command, self.status.internal_value, self.flags,
+                                   self.flags2, (self.pid >> 16) & 0xFFFF, self.security, self.tid,
+                                   self.pid & 0xFFFF, self.uid, self.mid, int(parameters_len / 2))
+        return headers_data + self.parameters_data + struct.pack('<H', len(self.data)) + self.data
+
+    def decode(self, buf):
+        """
+        Decodes the SMB message in buf.
+        All fields of the SMBMessage object will be reset to default values before decoding.
+        On errors, do not assume that the fields will be reinstated back to what they are before
+        this method is invoked.
+
+        @param buf: data containing one complete SMB message
+        @type buf: string
+        @return: a positive integer indicating the number of bytes used in buf to decode this SMB message
+        @raise ProtocolError: raised when decoding fails
+        """
+        buf_len = len(buf)
+        if buf_len < self.HEADER_STRUCT_SIZE:
+            # We need at least 32 bytes (header) + 1 byte (parameter count)
+            raise ProtocolError('Not enough data to decode SMB header', buf)
+
+        self.reset()
+
+        protocol, self.command, status, self.flags, \
+        self.flags2, pid_high, self.security, self.tid, \
+        pid_low, self.uid, self.mid, params_count = struct.unpack(self.HEADER_STRUCT_FORMAT, buf[:self.HEADER_STRUCT_SIZE])
+
+        if protocol == '\xFESMB':
+            raise SMB2ProtocolHeaderError()
+        if protocol != '\xFFSMB':
+            raise ProtocolError('Invalid 4-byte protocol field', buf)
+
+        self.pid = (pid_high << 16) | pid_low
+        self.status.internal_value = status
+        self.status.is_ntstatus = bool(self.flags2 & SMB_FLAGS2_NT_STATUS)
+
+        offset = self.HEADER_STRUCT_SIZE
+        if buf_len < params_count * 2 + 2:
+            # Not enough data in buf to decode up to body length
+            raise ProtocolError('Not enough data. Parameters list decoding failed', buf)
+
+        datalen_offset = offset + params_count*2
+        body_len = struct.unpack('<H', buf[datalen_offset:datalen_offset+2])[0]
+        if body_len > 0 and buf_len < (datalen_offset + 2 + body_len):
+            # Not enough data in buf to decode body
+            raise ProtocolError('Not enough data. Body decoding failed', buf)
+
+        self.parameters_data = buf[offset:datalen_offset]
+
+        if body_len > 0:
+            self.data = buf[datalen_offset+2:datalen_offset+2+body_len]
+
+        self.raw_data = buf
+        self._decodePayload()
+
+        return self.HEADER_STRUCT_SIZE + params_count * 2 + 2 + body_len
+
+    def _decodePayload(self):
+        if self.command == SMB_COM_READ_ANDX:
+            self.payload = ComReadAndxResponse()
+        elif self.command == SMB_COM_WRITE_ANDX:
+            self.payload = ComWriteAndxResponse()
+        elif self.command == SMB_COM_TRANSACTION:
+            self.payload = ComTransactionResponse()
+        elif self.command == SMB_COM_TRANSACTION2:
+            self.payload = ComTransaction2Response()
+        elif self.command == SMB_COM_OPEN_ANDX:
+            self.payload = ComOpenAndxResponse()
+        elif self.command == SMB_COM_NT_CREATE_ANDX:
+            self.payload = ComNTCreateAndxResponse()
+        elif self.command == SMB_COM_TREE_CONNECT_ANDX:
+            self.payload = ComTreeConnectAndxResponse()
+        elif self.command == SMB_COM_ECHO:
+            self.payload = ComEchoResponse()
+        elif self.command == SMB_COM_SESSION_SETUP_ANDX:
+            self.payload = ComSessionSetupAndxResponse()
+        elif self.command == SMB_COM_NEGOTIATE:
+            self.payload = ComNegotiateResponse()
+
+        if self.payload:
+            self.payload.decode(self)
+
+
+class Payload:
+
+    DEFAULT_ANDX_PARAM_HEADER = '\xFF\x00\x00\x00'
+    DEFAULT_ANDX_PARAM_SIZE = 4
+
+    def initMessage(self, message):
+        # SMB_FLAGS2_UNICODE must always be enabled. Without this, almost all the Payload subclasses will need to be
+        # rewritten to check for OEM/Unicode strings which will be tedious. Fortunately, almost all tested CIFS services
+        # support SMB_FLAGS2_UNICODE by default.
+        assert message.payload == self
+        message.flags =  SMB_FLAGS_CASE_INSENSITIVE | SMB_FLAGS_CANONICALIZED_PATHS
+        message.flags2 = SMB_FLAGS2_UNICODE | SMB_FLAGS2_NT_STATUS | SMB_FLAGS2_LONG_NAMES | SMB_FLAGS2_EAS
+
+        if SUPPORT_EXTENDED_SECURITY:
+            message.flags2 |= SMB_FLAGS2_EXTENDED_SECURITY | SMB_FLAGS2_SMB_SECURITY_SIGNATURE
+
+    def prepare(self, message):
+        raise NotImplementedError
+
+    def decode(self, message):
+        raise NotImplementedError
+
+
+class ComNegotiateRequest(Payload):
+    """
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.52.1
+    - [MS-SMB]: 2.2.4.5.1
+    """
+
+    def initMessage(self, message):
+        Payload.initMessage(self, message)
+        message.command = SMB_COM_NEGOTIATE
+
+    def prepare(self, message):
+        assert message.payload == self
+        message.parameters_data = ''
+        message.data = ''.join(map(lambda s: '\x02'+s+'\x00', init_dialects_list()))
+
+
+class ComNegotiateResponse(Payload):
+    """
+    Contains information on the SMB_COM_NEGOTIATE response from server
+
+    After calling the decode method, each instance will contain the following attributes,
+    - security_mode (integer)
+    - max_mpx_count (integer)
+    - max_number_vcs (integer)
+    - max_buffer_size (long)
+    - max_raw_size (long)
+    - session_key (long)
+    - capabilities (long)
+    - system_time (long)
+    - server_time_zone (integer)
+    - challenge_length (integer)
+
+    If the underlying SMB message's flag2 does not have SMB_FLAGS2_EXTENDED_SECURITY bit enabled,
+    then the instance will have the following additional attributes,
+    - challenge (string)
+    - domain (unicode)
+
+    If the underlying SMB message's flags2 has SMB_FLAGS2_EXTENDED_SECURITY bit enabled,
+    then the instance will have the following additional attributes,
+    - server_guid (string)
+    - security_blob (string)
+
+    References:
+    ===========
+    - [MS-SMB]: 2.2.4.5.2.1
+    - [MS-CIFS]: 2.2.4.52.2
+    """
+
+    PAYLOAD_STRUCT_FORMAT = '<HBHHIIIIQHB'
+    PAYLOAD_STRUCT_SIZE = struct.calcsize(PAYLOAD_STRUCT_FORMAT)
+
+    def decode(self, message):
+        assert message.command == SMB_COM_NEGOTIATE
+
+        if not message.isReply:
+            raise ProtocolError('Not a SMB_COM_NEGOTIATE reply', message.raw_data, message)
+
+        self.security_mode, self.max_mpx_count, self.max_number_vcs, self.max_buffer_size, \
+        self.max_raw_size, self.session_key, self.capabilities, self.system_time, self.server_time_zone, \
+        self.challenge_length = ( 0, ) * 10
+
+        data_len = len(message.parameters_data)
+        if data_len < 2:
+            raise ProtocolError('Not enough data to decode SMB_COM_NEGOTIATE dialect_index field', message.raw_data, message)
+
+        self.dialect_index = struct.unpack('<H', message.parameters_data[:2])[0]
+        if self.dialect_index == NT_LAN_MANAGER_DIALECT:
+            if data_len != (0x11 * 2):
+                raise ProtocolError('NT LAN Manager dialect selected in SMB_COM_NEGOTIATE but parameters bytes count (%d) does not meet specs' % data_len,
+                                    message.raw_data, message)
+            else:
+                _, self.security_mode, self.max_mpx_count, self.max_number_vcs, self.max_buffer_size, \
+                self.max_raw_size, self.session_key, self.capabilities, self.system_time, self.server_time_zone, \
+                self.challenge_length = struct.unpack(self.PAYLOAD_STRUCT_FORMAT, message.parameters_data[:self.PAYLOAD_STRUCT_SIZE])
+        elif self.dialect_index == 0xFFFF:
+            raise ProtocolError('Server does not support any of the pysmb dialects. Please email pysmb to add in support for your OS',
+                                message.raw_data, message)
+        else:
+            raise ProtocolError('Unknown dialect index (0x%04X)' % self.dialect_index, message.raw_data, message)
+
+        data_len = len(message.data)
+        if not message.hasExtendedSecurity:
+            self.challenge, self.domain = '', ''
+            if self.challenge_length > 0:
+                if data_len >= self.challenge_length:
+                    self.challenge = message.data[:self.challenge_length]
+
+                    s = ''
+                    offset = self.challenge_length
+                    while offset < data_len:
+                        _s = message.data[offset:offset+2]
+                        if _s == '\0\0':
+                            self.domain = s.decode('UTF-16LE')
+                            break
+                        else:
+                            s += _s
+                            offset += 2
+                else:
+                    raise ProtocolError('Not enough data to decode SMB_COM_NEGOTIATE (without security extensions) Challenge field', message.raw_data, message)
+        else:
+            if data_len < 16:
+                raise ProtocolError('Not enough data to decode SMB_COM_NEGOTIATE (with security extensions) ServerGUID field', message.raw_data, message)
+
+            self.server_guid = message.data[:16]
+            self.security_blob = message.data[16:]
+
+    @property
+    def supportsExtendedSecurity(self):
+        return bool(self.capabilities & CAP_EXTENDED_SECURITY)
+
+
+class ComSessionSetupAndxRequest__WithSecurityExtension(Payload):
+    """
+    References:
+    ===========
+    - [MS-SMB]: 2.2.4.6.1
+    """
+
+    PAYLOAD_STRUCT_FORMAT = '<HHHIHII'
+
+    def __init__(self, session_key, security_blob):
+        self.session_key = session_key
+        self.security_blob = security_blob
+
+    def initMessage(self, message):
+        Payload.initMessage(self, message)
+        message.command = SMB_COM_SESSION_SETUP_ANDX
+
+    def prepare(self, message):
+        assert message.hasExtendedSecurity
+
+        message.flags2 |= SMB_FLAGS2_UNICODE
+
+        cap = CAP_UNICODE | CAP_STATUS32 | CAP_EXTENDED_SECURITY | CAP_NT_SMBS
+
+        message.parameters_data = \
+            self.DEFAULT_ANDX_PARAM_HEADER + \
+            struct.pack(self.PAYLOAD_STRUCT_FORMAT,
+                        16644, 10, 1, self.session_key, len(self.security_blob), 0, cap)
+
+        message.data = self.security_blob
+        if (SMBMessage.HEADER_STRUCT_SIZE + len(message.parameters_data) + len(message.data)) % 2 != 0:
+            message.data = message.data + '\0'
+        message.data = message.data + '\0' * 4
+
+
+class ComSessionSetupAndxRequest__NoSecurityExtension(Payload):
+    """
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.53.1
+    """
+
+    PAYLOAD_STRUCT_FORMAT = '<HHHIHHII'
+
+    def __init__(self, session_key, username, password, is_unicode, domain):
+        self.username = username
+        self.session_key = session_key
+        self.password = password
+        self.is_unicode = is_unicode
+        self.domain = domain
+
+    def initMessage(self, message):
+        Payload.initMessage(self, message)
+        message.command = SMB_COM_SESSION_SETUP_ANDX
+
+    def prepare(self, message):
+        if self.is_unicode:
+            message.flags2 |= SMB_FLAGS2_UNICODE
+        else:
+            message.flags2 &= (~SMB_FLAGS2_UNICODE & 0xFFFF)
+
+        password_len = len(self.password)
+        message.parameters_data = \
+            self.DEFAULT_ANDX_PARAM_HEADER + \
+            struct.pack(self.PAYLOAD_STRUCT_FORMAT,
+                        16644, 10, 0, self.session_key,
+                        (not self.is_unicode and password_len) or 0,
+                        (self.is_unicode and password_len) or 0,
+                        0,
+                        CAP_UNICODE | CAP_LARGE_FILES | CAP_STATUS32)
+
+        est_offset = SMBMessage.HEADER_STRUCT_SIZE + len(message.parameters_data)  # To check if data until SMB paramaters are aligned to a 16-bit boundary
+
+        message.data = self.password
+        if (est_offset + len(message.data)) % 2 != 0 and message.flags2 & SMB_FLAGS2_UNICODE:
+            message.data = message.data + '\0'
+
+        if message.flags2 & SMB_FLAGS2_UNICODE:
+            message.data = message.data + self.username.encode('UTF-16LE') + '\0'
+        else:
+            message.data = message.data + str(self.username) + '\0'
+
+        if (est_offset + len(message.data)) % 2 != 0 and message.flags2 & SMB_FLAGS2_UNICODE:
+            message.data = message.data + '\0'
+
+        if message.flags2 & SMB_FLAGS2_UNICODE:
+            message.data = message.data + self.domain.encode('UTF-16LE') + '\0\0' + 'pysmb'.encode('UTF-16LE') + '\0\0'
+        else:
+            message.data = message.data + self.domain + '\0pysmb\0'
+
+
+class ComSessionSetupAndxResponse(Payload):
+    """
+    Contains information on the SMB_COM_SESSION_SETUP_ANDX response from server
+
+    If the underlying SMB message's flags2 does not have SMB_FLAGS2_EXTENDED_SECURITY bit enabled,
+    then the instance will have the following attributes,
+    - action
+
+    If the underlying SMB message's flags2 has SMB_FLAGS2_EXTENDED_SECURITY bit enabled
+    and the message status is STATUS_MORE_PROCESSING_REQUIRED or equals to 0x00 (no error),
+    then the instance will have the following attributes,
+    - action
+    - securityblob
+
+    If the underlying SMB message's flags2 has SMB_FLAGS2_EXTENDED_SECURITY bit enabled but
+    the message status is not STATUS_MORE_PROCESSING_REQUIRED
+
+    References:
+    ===========
+    - [MS-SMB]: 2.2.4.6.2
+    - [MS-CIFS]: 2.2.4.53.2
+    """
+
+    NOSECURE_PARAMETER_STRUCT_FORMAT = '<BBHH'
+    NOSECURE_PARAMETER_STRUCT_SIZE = struct.calcsize(NOSECURE_PARAMETER_STRUCT_FORMAT)
+
+    SECURE_PARAMETER_STRUCT_FORMAT = '<BBHHH'
+    SECURE_PARAMETER_STRUCT_SIZE = struct.calcsize(SECURE_PARAMETER_STRUCT_FORMAT)
+
+    def decode(self, message):
+        assert message.command == SMB_COM_SESSION_SETUP_ANDX
+        if not message.hasExtendedSecurity:
+            if not message.status.hasError:
+                if len(message.parameters_data) < self.NOSECURE_PARAMETER_STRUCT_SIZE:
+                    raise ProtocolError('Not enough data to decode SMB_COM_SESSION_SETUP_ANDX (no security extensions) parameters', message.raw_data, message)
+
+                _, _, _, self.action = struct.unpack(self.NOSECURE_PARAMETER_STRUCT_FORMAT, message.parameters_data[:self.NOSECURE_PARAMETER_STRUCT_SIZE])
+        else:
+            if not message.status.hasError or message.status.internal_value == 0xc0000016:   # STATUS_MORE_PROCESSING_REQUIRED
+                if len(message.parameters_data) < self.SECURE_PARAMETER_STRUCT_SIZE:
+                    raise ProtocolError('Not enough data to decode SMB_COM_SESSION_SETUP_ANDX (with security extensions) parameters', message.raw_data, message)
+
+                _, _, _, self.action, blob_length = struct.unpack(self.SECURE_PARAMETER_STRUCT_FORMAT, message.parameters_data[:self.SECURE_PARAMETER_STRUCT_SIZE])
+                if len(message.data) < blob_length:
+                    raise ProtocolError('Not enough data to decode SMB_COM_SESSION_SETUP_ANDX (with security extensions) security blob', message.raw_data, message)
+
+                self.security_blob = message.data[:blob_length]
+
+
+class ComTreeConnectAndxRequest(Payload):
+    """
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.55.1
+    - [MS-SMB]: 2.2.4.7.1
+    """
+
+    PAYLOAD_STRUCT_FORMAT = '<HH'
+    PAYLOAD_STRUCT_SIZE = struct.calcsize(PAYLOAD_STRUCT_FORMAT)
+
+    def __init__(self, path, service, password = ''):
+        self.path = path
+        self.service = service
+        self.password = password + '\0'
+
+    def initMessage(self, message):
+        Payload.initMessage(self, message)
+        message.command = SMB_COM_TREE_CONNECT_ANDX
+
+    def prepare(self, message):
+        password_len = len(self.password)
+        message.parameters_data = \
+            self.DEFAULT_ANDX_PARAM_HEADER + \
+            struct.pack(self.PAYLOAD_STRUCT_FORMAT,
+                        0x08 | \
+                            ((message.hasExtendedSecurity and 0x0004) or 0x00) | \
+                            ((message.tid and message.tid != 0xFFFF and 0x0001) or 0x00),  # Disconnect tid, if message.tid must be non-zero
+                        password_len)
+
+        padding = ''
+        if password_len % 2 == 0:
+            padding = '\0'
+
+        # Note that service field is never encoded in UTF-16LE. [MS-CIFS]: 2.2.1.1
+        message.data = self.password + padding + self.path.encode('UTF-16LE') + '\0\0' + self.service + '\0'
+
+
+class ComTreeConnectAndxResponse(Payload):
+    """
+    Contains information about the SMB_COM_TREE_CONNECT_ANDX response from the server.
+
+    If the message has no errors, each instance contains the following attributes:
+    - optional_support
+
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.55.2
+    """
+
+    PAYLOAD_STRUCT_FORMAT = '<BBHH'
+    PAYLOAD_STRUCT_SIZE = struct.calcsize(PAYLOAD_STRUCT_FORMAT)
+
+    def decode(self, message):
+        assert message.command == SMB_COM_TREE_CONNECT_ANDX
+
+        if not message.status.hasError:
+            if len(message.parameters_data) < self.PAYLOAD_STRUCT_SIZE:
+                raise ProtocolError('Not enough data to decode SMB_COM_TREE_CONNECT_ANDX parameters', message.raw_data, message)
+
+            _, _, _, self.optional_support = struct.unpack(self.PAYLOAD_STRUCT_FORMAT, message.parameters_data[:self.PAYLOAD_STRUCT_SIZE])
+
+
+class ComNTCreateAndxRequest(Payload):
+    """
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.64.1
+    - [MS-SMB]: 2.2.4.9.1
+    """
+
+    PAYLOAD_STRUCT_FORMAT = '<BHIIIQIIIIIB'
+    PAYLOAD_STRUCT_SIZE = struct.calcsize(PAYLOAD_STRUCT_FORMAT)
+
+    def __init__(self, filename, flags = 0, root_fid = 0, access_mask = 0, allocation_size = 0L, ext_attr = 0,
+                 share_access = 0, create_disp = 0, create_options = 0, impersonation = 0, security_flags = 0):
+        self.filename = (filename + '\0').encode('UTF-16LE')
+        self.flags = flags
+        self.root_fid = root_fid
+        self.access_mask = access_mask
+        self.allocation_size = allocation_size
+        self.ext_attr = ext_attr
+        self.share_access = share_access
+        self.create_disp = create_disp
+        self.create_options = create_options
+        self.impersonation = impersonation
+        self.security_flags = security_flags
+
+    def initMessage(self, message):
+        Payload.initMessage(self, message)
+        message.command = SMB_COM_NT_CREATE_ANDX
+
+    def prepare(self, message):
+        filename_len = len(self.filename)
+
+        message.parameters_data = \
+            self.DEFAULT_ANDX_PARAM_HEADER + \
+            struct.pack(self.PAYLOAD_STRUCT_FORMAT,
+                        0x00,                  # reserved
+                        filename_len,          # NameLength
+                        self.flags,            # Flags
+                        self.root_fid,         # RootDirectoryFID
+                        self.access_mask,      # DesiredAccess
+                        self.allocation_size,  # AllocationSize
+                        self.ext_attr,         # ExtFileAttributes
+                        self.share_access,     # ShareAccess
+                        self.create_disp,      # CreateDisposition
+                        self.create_options,   # CreateOptions
+                        self.impersonation,    # ImpersonationLevel
+                        self.security_flags)   # SecurityFlags
+
+        padding = ''
+        if (message.HEADER_STRUCT_SIZE + len(message.parameters_data)) % 2 != 0:
+            padding = '\0'
+
+        message.data = padding + self.filename
+
+
+class ComNTCreateAndxResponse(Payload):
+    """
+    Contains (partial) information about the SMB_COM_NT_CREATE_ANDX response from the server.
+
+    Each instance contains the following attributes after decoding:
+    - oplock_level
+    - fid
+
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.64.2
+    """
+    PAYLOAD_STRUCT_FORMAT = '<BBHBH'
+    PAYLOAD_STRUCT_SIZE = struct.calcsize(PAYLOAD_STRUCT_FORMAT)
+
+    def decode(self, message):
+        assert message.command == SMB_COM_NT_CREATE_ANDX
+
+        if not message.status.hasError:
+            if len(message.parameters_data) < self.PAYLOAD_STRUCT_SIZE:
+                raise ProtocolError('Not enough data to decode SMB_COM_NT_CREATE_ANDX parameters', message.raw_data, message)
+
+            _, _, _, self.oplock_level, self.fid = struct.unpack(self.PAYLOAD_STRUCT_FORMAT, message.parameters_data[:self.PAYLOAD_STRUCT_SIZE])
+
+
+class ComTransactionRequest(Payload):
+    """
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.33.1
+    """
+
+    PAYLOAD_STRUCT_FORMAT = '<HHHHBBHIHHHHHH'
+    PAYLOAD_STRUCT_SIZE = struct.calcsize(PAYLOAD_STRUCT_FORMAT)
+
+    def __init__(self, max_params_count, max_data_count, max_setup_count,
+                 total_params_count = 0, total_data_count = 0,
+                 params_bytes = '', data_bytes = '', setup_bytes = '',
+                 flags = 0, timeout = 0, name = "\\PIPE\\"):
+        self.total_params_count = total_params_count or len(params_bytes)
+        self.total_data_count = total_data_count or len(data_bytes)
+        self.max_params_count = max_params_count
+        self.max_data_count = max_data_count
+        self.max_setup_count = max_setup_count
+        self.flags = flags
+        self.timeout = timeout
+        self.params_bytes = params_bytes
+        self.data_bytes = data_bytes
+        self.setup_bytes = setup_bytes
+        self.name = name
+
+    def initMessage(self, message):
+        Payload.initMessage(self, message)
+        message.command = SMB_COM_TRANSACTION
+
+    def prepare(self, message):
+        name = (self.name + '\0').encode('UTF-16LE')
+        name_len = len(name)
+        setup_bytes_len = len(self.setup_bytes)
+        params_bytes_len = len(self.params_bytes)
+        data_bytes_len = len(self.data_bytes)
+
+        padding0 = ''
+        offset = message.HEADER_STRUCT_SIZE + self.PAYLOAD_STRUCT_SIZE + setup_bytes_len + 2 # constant 2 is for the ByteCount field in the SMB header (i.e. field which indicates number of data bytes after the SMB parameters)
+        if offset % 2 != 0:
+            padding0 = '\0'
+            offset += 1
+
+        offset += name_len  # For the name field
+        padding1 = ''
+        if offset % 4 != 0:
+            padding1 = '\0'*(4-offset%4)
+            offset += (4-offset%4)
+
+        if params_bytes_len > 0:
+            params_bytes_offset = offset
+            offset += params_bytes_len
+        else:
+            params_bytes_offset = 0
+
+        padding2 = ''
+        if offset % 4 != 0:
+            padding2 = '\0'*(4-offset%4)
+            offset += (4-offset%4)
+
+        if data_bytes_len > 0:
+            data_bytes_offset = offset
+        else:
+            data_bytes_offset = 0
+
+        message.parameters_data = \
+            struct.pack(self.PAYLOAD_STRUCT_FORMAT,
+                        self.total_params_count,
+                        self.total_data_count,
+                        self.max_params_count,
+                        self.max_data_count,
+                        self.max_setup_count,
+                        0x00,           # Reserved1. Must be 0x00
+                        self.flags,
+                        self.timeout,
+                        0x0000,         # Reserved2. Must be 0x0000
+                        params_bytes_len,
+                        params_bytes_offset,
+                        data_bytes_len,
+                        data_bytes_offset,
+                        int(setup_bytes_len / 2)) + \
+            self.setup_bytes
+
+        message.data = padding0 + name + padding1 + self.params_bytes + padding2 + self.data_bytes
+
+
+class ComTransactionResponse(Payload):
+    """
+    Contains information about a SMB_COM_TRANSACTION response from the server
+
+    After decoding, each instance contains the following attributes:
+    - total_params_count (integer)
+    - total_data_count (integer)
+    - setup_bytes (string)
+    - data_bytes (string)
+    - params_bytes (string)
+
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.33.2
+    """
+
+    PAYLOAD_STRUCT_FORMAT = '<HHHHHHHHHH'
+    PAYLOAD_STRUCT_SIZE = struct.calcsize(PAYLOAD_STRUCT_FORMAT)
+
+    def decode(self, message):
+        assert message.command == SMB_COM_TRANSACTION
+
+        if not message.status.hasError:
+            if len(message.parameters_data) < self.PAYLOAD_STRUCT_SIZE:
+                raise ProtocolError('Not enough data to decode SMB_COM_TRANSACTION parameters', message.raw_data, message)
+
+            self.total_params_count, self.total_data_count, _, \
+            params_bytes_len, params_bytes_offset, params_bytes_displ, \
+            data_bytes_len, data_bytes_offset, data_bytes_displ, \
+            setup_count = struct.unpack(self.PAYLOAD_STRUCT_FORMAT, message.parameters_data[:self.PAYLOAD_STRUCT_SIZE])
+
+            if setup_count > 0:
+                setup_bytes_len = setup_count * 2
+
+                if len(message.parameters_data) < self.PAYLOAD_STRUCT_SIZE + setup_bytes_len:
+                    raise ProtocolError('Not enough data to decode SMB_COM_TRANSACTION parameters', message.raw_data, message)
+
+                self.setup_bytes = message.parameters_data[self.PAYLOAD_STRUCT_SIZE:self.PAYLOAD_STRUCT_SIZE+setup_bytes_len]
+            else:
+                self.setup_bytes = ''
+
+            offset = message.HEADER_STRUCT_SIZE + self.PAYLOAD_STRUCT_SIZE + setup_count * 2 + 2 # constant 2 is for the ByteCount field in the SMB header (i.e. field which indicates number of data bytes after the SMB parameters)
+
+            if params_bytes_len > 0:
+                self.params_bytes = message.data[params_bytes_offset-offset:params_bytes_offset-offset+params_bytes_len]
+            else:
+                self.params_bytes = ''
+
+            if data_bytes_len > 0:
+                self.data_bytes = message.data[data_bytes_offset-offset:data_bytes_offset-offset+data_bytes_len]
+            else:
+                self.data_bytes = ''
+
+
+class ComTransaction2Request(Payload):
+    """
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.46.1
+    """
+
+    PAYLOAD_STRUCT_FORMAT = 'HHHHBBHIHHHHHH'
+    PAYLOAD_STRUCT_SIZE = struct.calcsize(PAYLOAD_STRUCT_FORMAT)
+
+    def __init__(self, max_params_count, max_data_count, max_setup_count,
+                 total_params_count = 0, total_data_count = 0,
+                 params_bytes = '', data_bytes = '', setup_bytes = '',
+                 flags = 0, timeout = 0):
+        self.total_params_count = total_params_count or len(params_bytes)
+        self.total_data_count = total_data_count or len(data_bytes)
+        self.max_params_count = max_params_count
+        self.max_data_count = max_data_count
+        self.max_setup_count = max_setup_count
+        self.flags = flags
+        self.timeout = timeout
+        self.params_bytes = params_bytes
+        self.data_bytes = data_bytes
+        self.setup_bytes = setup_bytes
+
+    def initMessage(self, message):
+        Payload.initMessage(self, message)
+        message.command = SMB_COM_TRANSACTION2
+
+    def prepare(self, message):
+        setup_bytes_len = len(self.setup_bytes)
+        params_bytes_len = len(self.params_bytes)
+        data_bytes_len = len(self.data_bytes)
+        name = '\0\0'
+
+        padding0 = ''
+        offset = message.HEADER_STRUCT_SIZE + self.PAYLOAD_STRUCT_SIZE + setup_bytes_len + 2 # constant 2 is for the ByteCount field in the SMB header (i.e. field which indicates number of data bytes after the SMB parameters)
+        if offset % 2 != 0:
+            padding0 = '\0'
+            offset += 1
+
+        offset += 2  # For the name field
+        padding1 = ''
+        if offset % 4 != 0:
+            padding1 = '\0'*(4-offset%4)
+
+        if params_bytes_len > 0:
+            params_bytes_offset = offset
+            offset += params_bytes_len
+        else:
+            params_bytes_offset = 0
+
+        padding2 = ''
+        if offset % 4 != 0:
+            padding2 = '\0'*(4-offset%4)
+
+        if data_bytes_len > 0:
+            data_bytes_offset = offset
+        else:
+            data_bytes_offset = 0
+
+        message.parameters_data = \
+            struct.pack(self.PAYLOAD_STRUCT_FORMAT,
+                        self.total_params_count,
+                        self.total_data_count,
+                        self.max_params_count,
+                        self.max_data_count,
+                        self.max_setup_count,
+                        0x00,           # Reserved1. Must be 0x00
+                        self.flags,
+                        self.timeout,
+                        0x0000,         # Reserved2. Must be 0x0000
+                        params_bytes_len,
+                        params_bytes_offset,
+                        data_bytes_len,
+                        data_bytes_offset,
+                        int(setup_bytes_len / 2)) + \
+            self.setup_bytes
+
+        message.data = padding0 + name + padding1 + self.params_bytes + padding2 + self.data_bytes
+
+
+class ComTransaction2Response(Payload):
+    """
+    Contains information about a SMB_COM_TRANSACTION2 response from the server
+
+    After decoding, each instance contains the following attributes:
+    - total_params_count (integer)
+    - total_data_count (integer)
+    - setup_bytes (string)
+    - data_bytes (string)
+    - params_bytes (string)
+
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.46.2
+    """
+
+    PAYLOAD_STRUCT_FORMAT = '<HHHHHHHHHBB'
+    PAYLOAD_STRUCT_SIZE = struct.calcsize(PAYLOAD_STRUCT_FORMAT)
+
+    def decode(self, message):
+        assert message.command == SMB_COM_TRANSACTION2
+
+        if not message.status.hasError:
+            if len(message.parameters_data) < self.PAYLOAD_STRUCT_SIZE:
+                raise ProtocolError('Not enough data to decode SMB_COM_TRANSACTION2 parameters', message.raw_data, message)
+
+            self.total_params_count, self.total_data_count, _, \
+            params_bytes_len, params_bytes_offset, params_bytes_displ, \
+            data_bytes_len, data_bytes_offset, data_bytes_displ, \
+            setup_count, _ = struct.unpack(self.PAYLOAD_STRUCT_FORMAT, message.parameters_data[:self.PAYLOAD_STRUCT_SIZE])
+
+            if setup_count > 0:
+                setup_bytes_len = setup_count * 2
+
+                if len(message.parameters_data) < self.PAYLOAD_STRUCT_SIZE + setup_bytes_len:
+                    raise ProtocolError('Not enough data to decode SMB_COM_TRANSACTION parameters', message.raw_data, message)
+
+                self.setup_bytes = message.parameters_data[self.PAYLOAD_STRUCT_SIZE:self.PAYLOAD_STRUCT_SIZE+setup_bytes_len]
+            else:
+                self.setup_bytes = ''
+
+            offset = message.HEADER_STRUCT_SIZE + self.PAYLOAD_STRUCT_SIZE + setup_count * 2 + 2 # constant 2 is for the ByteCount field in the SMB header (i.e. field which indicates number of data bytes after the SMB parameters)
+
+            if params_bytes_len > 0:
+                self.params_bytes = message.data[params_bytes_offset-offset:params_bytes_offset-offset+params_bytes_len]
+            else:
+                self.params_bytes = ''
+
+            if data_bytes_len > 0:
+                self.data_bytes = message.data[data_bytes_offset-offset:data_bytes_offset-offset+data_bytes_len]
+            else:
+                self.data_bytes = ''
+
+
+class ComCloseRequest(Payload):
+    """
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.5.1
+    """
+
+    PAYLOAD_STRUCT_FORMAT = '<HI'
+    PAYLOAD_STRUCT_SIZE = struct.calcsize(PAYLOAD_STRUCT_FORMAT)
+
+    def __init__(self, fid, last_modified_time = 0xFFFFFFFF):
+        self.fid = fid
+        self.last_modified_time = last_modified_time
+
+    def initMessage(self, message):
+        Payload.initMessage(self, message)
+        message.command = SMB_COM_CLOSE
+
+    def prepare(self, message):
+        message.parameters_data = struct.pack(self.PAYLOAD_STRUCT_FORMAT, self.fid, self.last_modified_time)
+        message.data = ''
+
+
+class ComOpenAndxRequest(Payload):
+    """
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.41.1
+    """
+
+    PAYLOAD_STRUCT_FORMAT = '<HHHHIHIII'
+    PAYLOAD_STRUCT_SIZE = struct.calcsize(PAYLOAD_STRUCT_FORMAT)
+
+    def __init__(self, filename, access_mode, open_mode, flags = 0x0000, search_attributes = 0, file_attributes = 0, create_time = 0, timeout = 0):
+        """
+        @param create_time: Epoch time value to indicate the time of creation for this file. If zero, we will automatically assign the current time
+        @type create_time: int
+        @param timeout: Number of milliseconds to wait for blocked open request before failing
+        @type timeout: int
+        """
+        self.filename = filename
+        self.access_mode = access_mode
+        self.open_mode = open_mode
+        self.flags = flags
+        self.search_attributes = search_attributes
+        self.file_attributes = file_attributes
+        self.create_time = create_time or int(time.time())
+        self.timeout = timeout
+
+    def initMessage(self, message):
+        Payload.initMessage(self, message)
+        message.command = SMB_COM_OPEN_ANDX
+
+    def prepare(self, message):
+        message.parameters_data = \
+            self.DEFAULT_ANDX_PARAM_HEADER + \
+            struct.pack(self.PAYLOAD_STRUCT_FORMAT,
+                        self.flags,
+                        self.access_mode,
+                        self.search_attributes,
+                        self.file_attributes,
+                        self.create_time,
+                        self.open_mode,
+                        0,  # AllocationSize
+                        0,  # Timeout (in milli-secs)
+                        0)  # Reserved
+
+        message.data = '\0' + self.filename.encode('UTF-16LE') + '\0\0'
+
+
+class ComOpenAndxResponse(Payload):
+    """
+    Contains information about a SMB_COM_OPEN_ANDX response from the server
+
+    After decoding, each instance will contain the following attributes:
+    - fid (integer)
+    - file_attributes (integer)
+    - last_write_time (long)
+    - access_rights (integer)
+    - resource_type (integer)
+    - open_results (integer)
+
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.41.2
+    - [MS-SMB]: 2.2.4.1.2
+    """
+
+    PAYLOAD_STRUCT_FORMAT = '<BBHHHIIHHHHHHH'
+    PAYLOAD_STRUCT_SIZE = struct.calcsize(PAYLOAD_STRUCT_FORMAT)
+
+    def decode(self, message):
+        assert message.command == SMB_COM_OPEN_ANDX
+
+        if not message.status.hasError:
+            if len(message.parameters_data) < self.PAYLOAD_STRUCT_SIZE:
+                raise ProtocolError('Not enough data to decode SMB_COM_OPEN_ANDX parameters', message.raw_data, message)
+
+            _, _, _, self.fid, self.file_attributes, self.last_write_time, _, \
+            self.access_rights, self.resource_type, _, self.open_results, _, _, _ = struct.unpack(self.PAYLOAD_STRUCT_FORMAT,
+                                                                                                  message.parameters_data[:self.PAYLOAD_STRUCT_SIZE])
+
+
+class ComWriteAndxRequest(Payload):
+    """
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.43.1
+    - [MS-SMB]: 2.2.4.3.1
+    """
+
+    PAYLOAD_STRUCT_FORMAT = '<HIIHHHHHI'
+    PAYLOAD_STRUCT_SIZE = struct.calcsize(PAYLOAD_STRUCT_FORMAT)
+
+    def __init__(self, fid, data_bytes, offset, write_mode = 0, timeout = 0):
+        """
+        @param timeout: Number of milliseconds to wait for blocked write request before failing. Must be zero for writing to regular file
+        @type timeout: int
+        """
+        self.fid = fid
+        self.offset = offset
+        self.data_bytes = data_bytes
+        self.timeout = timeout
+        self.write_mode = write_mode
+
+    def initMessage(self, message):
+        Payload.initMessage(self, message)
+        message.command = SMB_COM_WRITE_ANDX
+
+    def prepare(self, message):
+        # constant 1 is to account for the pad byte in the message.data
+        # constant 2 is for the ByteCount field in the SMB header (i.e. field which indicates number of data bytes after the SMB parameters)
+        data_offset = message.HEADER_STRUCT_SIZE + self.DEFAULT_ANDX_PARAM_SIZE + self.PAYLOAD_STRUCT_SIZE + 1 + 2
+        data_len = len(self.data_bytes)
+
+        message.parameters_data = \
+            self.DEFAULT_ANDX_PARAM_HEADER + \
+            struct.pack(self.PAYLOAD_STRUCT_FORMAT,
+                        self.fid,
+                        self.offset & 0xFFFFFFFF,
+                        self.timeout,
+                        self.write_mode,
+                        data_len,   # Remaining
+                        0x0000,     # Reserved
+                        len(self.data_bytes),  # DataLength
+                        data_offset,           # DataOffset
+                        self.offset >> 32)     # OffsetHigh field defined in [MS-SMB]: 2.2.4.3.1
+
+        message.data = '\0' + self.data_bytes
+
+
+class ComWriteAndxResponse(Payload):
+    """
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.43.2
+    - [MS-SMB]: 2.2.4.3.2
+    """
+
+    PAYLOAD_STRUCT_FORMAT = '<BBHHHHH'  # We follow the SMB_COM_WRITEX_ANDX server extensions in [MS-SMB]: 2.2.4.3.2
+    PAYLOAD_STRUCT_SIZE = struct.calcsize(PAYLOAD_STRUCT_FORMAT)
+
+    def decode(self, message):
+        assert message.command == SMB_COM_WRITE_ANDX
+
+        if not message.status.hasError:
+            if len(message.parameters_data) < self.PAYLOAD_STRUCT_SIZE:
+                raise ProtocolError('Not enough data to decode SMB_COM_WRITE_ANDX parameters', message.raw_data, message)
+
+            _, _, _, count, self.available, high_count, _ = struct.unpack(self.PAYLOAD_STRUCT_FORMAT, message.parameters_data[:self.PAYLOAD_STRUCT_SIZE])
+            self.count = (count & 0xFFFF) | (high_count << 16)
+
+
+class ComReadAndxRequest(Payload):
+    """
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.42.1
+    - [MS-SMB]: 2.2.4.2.1
+    """
+
+    PAYLOAD_STRUCT_FORMAT = '<HIHHIHI'
+    PAYLOAD_STRUCT_SIZE = struct.calcsize(PAYLOAD_STRUCT_FORMAT)
+
+    def __init__(self, fid, offset, max_return_bytes_count, min_return_bytes_count, timeout = 0, remaining = 0):
+        """
+        @param timeout: If reading from a regular file, this parameter must be 0.
+        @type timeout: int
+        """
+        self.fid = fid
+        self.remaining = remaining
+        self.max_return_bytes_count = max_return_bytes_count
+        self.min_return_bytes_count = min_return_bytes_count
+        self.offset = offset
+        self.timeout = timeout
+
+    def initMessage(self, message):
+        Payload.initMessage(self, message)
+        message.command = SMB_COM_READ_ANDX
+
+    def prepare(self, message):
+        message.parameters_data = \
+            self.DEFAULT_ANDX_PARAM_HEADER + \
+            struct.pack(self.PAYLOAD_STRUCT_FORMAT,
+                        self.fid,
+                        self.offset & 0xFFFFFFFF,
+                        self.max_return_bytes_count,
+                        self.min_return_bytes_count,
+                        self.timeout or (self.max_return_bytes_count >> 32),  # Note that in [MS-SMB]: 2.2.4.2.1, this field can also act as MaxCountHigh field
+                        self.remaining, # In [MS-CIFS]: 2.2.4.42.1, this field must be set to 0x0000
+                        self.offset >> 32)
+
+        message.data = ''
+
+
+class ComReadAndxResponse(Payload):
+    """
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.42.2
+    - [MS-SMB]: 2.2.4.2.2
+    """
+
+    PAYLOAD_STRUCT_FORMAT = '<BBHHHHHHHHHHH'
+    PAYLOAD_STRUCT_SIZE = struct.calcsize(PAYLOAD_STRUCT_FORMAT)
+
+    def decode(self, message):
+        assert message.command == SMB_COM_READ_ANDX
+
+        if not message.status.hasError:
+            if len(message.parameters_data) < self.PAYLOAD_STRUCT_SIZE:
+                raise ProtocolError('Not enough data to decode SMB_COM_READ_ANDX parameters', message.raw_data, message)
+
+            _, _, _, _, _, _, self.data_length, data_offset, _, _, _, _, _ = struct.unpack(self.PAYLOAD_STRUCT_FORMAT,
+                                                                                           message.parameters_data[:self.PAYLOAD_STRUCT_SIZE])
+
+            offset = data_offset - message.HEADER_STRUCT_SIZE - self.PAYLOAD_STRUCT_SIZE - 2  # constant 2 is for the ByteCount field in the SMB header (i.e. field which indicates number of data bytes after the SMB parameters)
+            self.data = message.data[offset:offset+self.data_length]
+            assert len(self.data) == self.data_length
+
+
+class ComDeleteRequest(Payload):
+    """
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.7.1
+    """
+
+    def __init__(self, filename_pattern, search_attributes = 0):
+        self.filename_pattern = filename_pattern
+        self.search_attributes = search_attributes
+
+    def initMessage(self, message):
+        Payload.initMessage(self, message)
+        message.command = SMB_COM_DELETE
+
+    def prepare(self, message):
+        message.parameters_data = struct.pack('<H', self.search_attributes)
+        message.data = '\x04' + self.filename_pattern.encode('UTF-16LE') + '\0\0'
+
+
+class ComCreateDirectoryRequest(Payload):
+    """
+    Although this command has been marked deprecated in [MS-CIFS], we continue to use it for its simplicity
+    as compared to its replacement TRANS2_CREATE_DIRECTORY sub-command [MS-CIFS]: 2.2.6.14
+
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.1.1
+    """
+
+    def __init__(self, path):
+        self.path = path
+
+    def initMessage(self, message):
+        Payload.initMessage(self, message)
+        message.command = SMB_COM_CREATE_DIRECTORY
+
+    def prepare(self, message):
+        message.parameters_data = ''
+        message.data = '\x04' + self.path.encode('UTF-16LE') + '\0\0'
+
+
+class ComDeleteDirectoryRequest(Payload):
+    """
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.2.1
+    """
+
+    def __init__(self, path):
+        self.path = path
+
+    def initMessage(self, message):
+        Payload.initMessage(self, message)
+        message.command = SMB_COM_DELETE_DIRECTORY
+
+    def prepare(self, message):
+        message.parameters_data = ''
+        message.data = '\x04' + self.path.encode('UTF-16LE') + '\0\0'
+
+
+class ComRenameRequest(Payload):
+    """
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.8.1
+    """
+
+    def __init__(self, old_path, new_path, search_attributes = 0):
+        self.old_path = old_path
+        self.new_path = new_path
+        self.search_attributes = search_attributes
+
+    def initMessage(self, message):
+        Payload.initMessage(self, message)
+        message.command = SMB_COM_RENAME
+
+    def prepare(self, message):
+        message.parameters_data = struct.pack('<H', self.search_attributes)
+        message.data = '\x04' + self.old_path.encode('UTF-16LE') + '\x00\x00\x04\x00' + self.new_path.encode('UTF-16LE') + '\x00\x00'
+
+
+class ComEchoRequest(Payload):
+    """
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.39.1
+    """
+
+    def __init__(self, echo_data = b'', echo_count = 1):
+        self.echo_count = echo_count
+        self.echo_data = echo_data
+
+    def initMessage(self, message):
+        Payload.initMessage(self, message)
+        message.command = SMB_COM_ECHO
+        message.tid = 0xFFFF
+
+    def prepare(self, message):
+        message.parameters_data = struct.pack('<H', self.echo_count)
+        message.data = self.echo_data
+
+
+class ComEchoResponse(Payload):
+    """
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.39.2
+    """
+
+    def decode(self, message):
+        self.sequence_number = struct.unpack('<H', message.parameters_data[:2])[0]
+        self.data = message.data
+
+
+class ComNTTransactRequest(Payload):
+    """
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.62.1
+    """
+    PAYLOAD_STRUCT_FORMAT = '<BHIIIIIIIIBH'
+    PAYLOAD_STRUCT_SIZE = struct.calcsize(PAYLOAD_STRUCT_FORMAT)
+
+    def __init__(self, function, max_params_count, max_data_count, max_setup_count,
+                 total_params_count = 0, total_data_count = 0,
+                 params_bytes = '', setup_bytes = '', data_bytes = ''):
+        self.function = function
+        self.total_params_count = total_params_count or len(params_bytes)
+        self.total_data_count = total_data_count or len(data_bytes)
+        self.max_params_count = max_params_count
+        self.max_data_count = max_data_count
+        self.max_setup_count = max_setup_count
+        self.params_bytes = params_bytes
+        self.setup_bytes = setup_bytes
+        self.data_bytes = data_bytes
+
+    def initMessage(self, message):
+        Payload.initMessage(self, message)
+        message.command = SMB_COM_NT_TRANSACT
+
+    def prepare(self, message):
+        setup_bytes_len = len(self.setup_bytes)
+        params_bytes_len = len(self.params_bytes)
+        data_bytes_len = len(self.data_bytes)
+
+        padding0 = ''
+        offset = message.HEADER_STRUCT_SIZE + self.PAYLOAD_STRUCT_SIZE + setup_bytes_len + 2 # constant 2 is for the ByteCount field in the SMB header (i.e. field which indicates number of data bytes after the SMB parameters)
+        if offset % 4 != 0:
+            padding0 = '\0'*(4-offset%4)
+            offset += (4-offset%4)
+
+        if params_bytes_len > 0:
+            params_bytes_offset = offset
+        else:
+            params_bytes_offset = 0
+
+        offset += params_bytes_len
+        padding1 = ''
+        if offset % 4 != 0:
+            padding1 = '\0'*(4-offset%4)
+            offset += (4-offset%4)
+
+        if data_bytes_len > 0:
+            data_bytes_offset = offset
+        else:
+            data_bytes_offset = 0
+
+        message.parameters_data = \
+            struct.pack(self.PAYLOAD_STRUCT_FORMAT,
+                        self.max_setup_count,
+                        0x00,           # Reserved1. Must be 0x00
+                        self.total_params_count,
+                        self.total_data_count,
+                        self.max_params_count,
+                        self.max_data_count,
+                        params_bytes_len,
+                        params_bytes_offset,
+                        data_bytes_len,
+                        data_bytes_offset,
+                        int(setup_bytes_len / 2),
+                        self.function) + \
+            self.setup_bytes
+
+        message.data = padding0 + self.params_bytes + padding1 + self.data_bytes
+
+
+class ComNTTransactResponse(Payload):
+    """
+    Contains information about a SMB_COM_NT_TRANSACT response from the server
+
+    After decoding, each instance contains the following attributes:
+    - total_params_count (integer)
+    - total_data_count (integer)
+    - setup_bytes (string)
+    - data_bytes (string)
+    - params_bytes (string)
+
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.62.2
+    """
+    PAYLOAD_STRUCT_FORMAT = '<3sIIIIIIIIBH'
+    PAYLOAD_STRUCT_SIZE = struct.calcsize(PAYLOAD_STRUCT_FORMAT)
+
+    def decode(self, message):
+        assert message.command == SMB_COM_NT_TRANSACT
+
+        if not message.status.hasError:
+            _, self.total_params_count, self.total_data_count, \
+            params_count, params_offset, params_displ, \
+            data_count, data_offset, data_displ, setup_count = struct.unpack(self.PAYLOAD_STRUCT_FORMAT,
+                                                                             message.parameters_data[:self.PAYLOAD_STRUCT_SIZE])
+
+            self.setup_bytes = message.parameters_data[self.PAYLOAD_STRUCT_SIZE:self.PAYLOAD_STRUCT_SIZE+setup_count*2]
+
+            if params_count > 0:
+                params_offset -= message.HEADER_STRUCT_SIZE + self.PAYLOAD_STRUCT_SIZE + setup_count*2 + 2
+                self.params_bytes = message.data[params_offset:params_offset+params_count]
+            else:
+                self.params_bytes = ''
+
+            if data_count > 0:
+                data_offset -= message.HEADER_STRUCT_SIZE + self.PAYLOAD_STRUCT_SIZE + setup_count*2 + 2
+                self.data_bytes = message.data[data_offset:data_offset+data_count]
+            else:
+                self.data_bytes = ''
diff --git a/python2/smb/utils/README.txt b/python2/smb/utils/README.txt
new file mode 100644
index 00000000..c17e6721
--- /dev/null
+++ b/python2/smb/utils/README.txt
@@ -0,0 +1,12 @@
+
+md4.py and U32.py
+Both modules downloaded from http://www.oocities.org/rozmanov/python/md4.html.
+Licensed under LGPL
+
+pyDes.py 2.0.0
+Downloaded from http://twhiteman.netfirms.com/des.html
+Licensed under public domain
+
+sha256.py
+Downloaded from http://xbmc-addons.googlecode.com/svn-history/r1686/trunk/scripts/OpenSubtitles_OSD/resources/lib/sha256.py
+Licensed under MIT
diff --git a/python2/smb/utils/U32.py b/python2/smb/utils/U32.py
new file mode 100644
index 00000000..e65428f0
--- /dev/null
+++ b/python2/smb/utils/U32.py
@@ -0,0 +1,148 @@
+#    U32.py implements 32-bit unsigned int class for Python
+#    Version 1.0
+#    Copyright (C) 2001-2002  Dmitry Rozmanov
+#
+#    This library is free software; you can redistribute it and/or
+#    modify it under the terms of the GNU Lesser General Public
+#    License as published by the Free Software Foundation; either
+#    version 2.1 of the License, or (at your option) any later version.
+#
+#    This library is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#    Lesser General Public License for more details.
+#
+#    You should have received a copy of the GNU Lesser General Public
+#    License along with this library; if not, write to the Free Software
+#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#
+#    e-mail: dima@xenon.spb.ru
+#
+#====================================================================
+
+C = 0x1000000000L
+
+#--------------------------------------------------------------------
+def norm(n):
+    return n & 0xFFFFFFFFL
+
+#====================================================================
+class U32:
+    v = 0L
+
+    #--------------------------------------------------------------------
+    def __init__(self, value = 0):
+        self.v = C + norm(abs(long(value)))
+
+    #--------------------------------------------------------------------
+    def set(self, value = 0):
+        self.v = C + norm(abs(long(value)))
+
+    #--------------------------------------------------------------------
+    def __repr__(self):
+        return hex(norm(self.v))
+
+    #--------------------------------------------------------------------
+    def __long__(self): return long(norm(self.v))
+
+    #--------------------------------------------------------------------
+    def __int__(self): return int(norm(self.v))
+
+    #--------------------------------------------------------------------
+    def __chr__(self): return chr(norm(self.v))
+
+    #--------------------------------------------------------------------
+    def __add__(self, b):
+        r = U32()
+        r.v = C + norm(self.v + b.v)
+        return r
+
+    #--------------------------------------------------------------------
+    def __sub__(self, b):
+        r = U32()
+        if self.v < b.v:
+            r.v = C + norm(0x100000000L - (b.v - self.v))
+        else: r.v = C + norm(self.v - b.v)
+        return r
+
+    #--------------------------------------------------------------------
+    def __mul__(self, b):
+        r = U32()
+        r.v = C + norm(self.v * b.v)
+        return r
+
+    #--------------------------------------------------------------------
+    def __div__(self, b):
+        r = U32()
+        r.v = C + (norm(self.v) / norm(b.v))
+        return r
+
+    #--------------------------------------------------------------------
+    def __mod__(self, b):
+        r = U32()
+        r.v = C + (norm(self.v) % norm(b.v))
+        return r
+
+    #--------------------------------------------------------------------
+    def __neg__(self): return U32(self.v)
+
+    #--------------------------------------------------------------------
+    def __pos__(self): return U32(self.v)
+
+    #--------------------------------------------------------------------
+    def __abs__(self): return U32(self.v)
+
+    #--------------------------------------------------------------------
+    def __invert__(self):
+        r = U32()
+        r.v = C + norm(~self.v)
+        return r
+
+    #--------------------------------------------------------------------
+    def __lshift__(self, b):
+        r = U32()
+        r.v = C + norm(self.v << b)
+        return r
+
+    #--------------------------------------------------------------------
+    def __rshift__(self, b):
+        r = U32()
+        r.v = C + (norm(self.v) >> b)
+        return r
+
+    #--------------------------------------------------------------------
+    def __and__(self, b):
+        r = U32()
+        r.v = C + norm(self.v & b.v)
+        return r
+
+    #--------------------------------------------------------------------
+    def __or__(self, b):
+        r = U32()
+        r.v = C + norm(self.v | b.v)
+        return r
+
+    #--------------------------------------------------------------------
+    def __xor__(self, b):
+        r = U32()
+        r.v = C + norm(self.v ^ b.v)
+        return r
+
+    #--------------------------------------------------------------------
+    def __not__(self):
+        return U32(not norm(self.v))
+
+    #--------------------------------------------------------------------
+    def truth(self):
+        return norm(self.v)
+
+    #--------------------------------------------------------------------
+    def __cmp__(self, b):
+        if norm(self.v) > norm(b.v): return 1
+        elif norm(self.v) < norm(b.v): return -1
+        else: return 0
+
+    #--------------------------------------------------------------------
+    def __nonzero__(self):
+        return norm(self.v)
+        
diff --git a/python2/smb/utils/__init__.py b/python2/smb/utils/__init__.py
new file mode 100644
index 00000000..bce9d86c
--- /dev/null
+++ b/python2/smb/utils/__init__.py
@@ -0,0 +1,3 @@
+
+def convertFILETIMEtoEpoch(t):
+    return (t - 116444736000000000L) / 10000000.0;
diff --git a/python2/smb/utils/md4.py b/python2/smb/utils/md4.py
new file mode 100644
index 00000000..2f107556
--- /dev/null
+++ b/python2/smb/utils/md4.py
@@ -0,0 +1,254 @@
+#    md4.py implements md4 hash class for Python
+#    Version 1.0
+#    Copyright (C) 2001-2002  Dmitry Rozmanov
+#
+#    based on md4.c from "the Python Cryptography Toolkit, version 1.0.0
+#    Copyright (C) 1995, A.M. Kuchling"
+#
+#    This library is free software; you can redistribute it and/or
+#    modify it under the terms of the GNU Lesser General Public
+#    License as published by the Free Software Foundation; either
+#    version 2.1 of the License, or (at your option) any later version.
+#
+#    This library is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#    Lesser General Public License for more details.
+#
+#    You should have received a copy of the GNU Lesser General Public
+#    License along with this library; if not, write to the Free Software
+#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#
+#    e-mail: dima@xenon.spb.ru
+#
+#====================================================================
+
+# MD4 validation data
+
+md4_test= [
+      ('', 0x31d6cfe0d16ae931b73c59d7e0c089c0L),
+      ("a",   0xbde52cb31de33e46245e05fbdbd6fb24L),
+      ("abc",   0xa448017aaf21d8525fc10ae87aa6729dL),
+      ("message digest",   0xd9130a8164549fe818874806e1c7014bL),
+      ("abcdefghijklmnopqrstuvwxyz",   0xd79e1c308aa5bbcdeea8ed63df412da9L),
+      ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
+       0x043f8582f241db351ce627e153e7f0e4L),
+      ("12345678901234567890123456789012345678901234567890123456789012345678901234567890",
+      0xe33b4ddc9c38f2199c3e7b164fcc0536L),
+     ]
+
+#====================================================================
+from U32 import U32
+
+#--------------------------------------------------------------------
+class MD4:
+    A = None
+    B = None
+    C = None
+    D = None
+    count, len1, len2 = None, None, None
+    buf = []
+
+    #-----------------------------------------------------
+    def __init__(self):
+
+
+        self.A = U32(0x67452301L)
+        self.B = U32(0xefcdab89L)
+        self.C = U32(0x98badcfeL)
+        self.D = U32(0x10325476L)
+        self.count, self.len1, self.len2 = U32(0L), U32(0L), U32(0L)
+        self.buf = [0x00] * 64
+
+    #-----------------------------------------------------
+    def __repr__(self):
+        r = 'A = %s, \nB = %s, \nC = %s, \nD = %s.\n' % (self.A.__repr__(), self.B.__repr__(), self.C.__repr__(), self.D.__repr__())
+        r = r + 'count = %s, \nlen1 = %s, \nlen2 = %s.\n' % (self.count.__repr__(), self.len1.__repr__(), self.len2.__repr__())
+        for i in range(4):
+            for j in range(16):
+                r = r + '%4s ' % hex(self.buf[i+j])
+            r = r + '\n'
+
+        return r
+    #-----------------------------------------------------
+    def make_copy(self):
+
+        dest = new()
+
+        dest.len1 = self.len1
+        dest.len2 = self.len2
+        dest.A = self.A
+        dest.B = self.B
+        dest.C = self.C
+        dest.D = self.D
+        dest.count = self.count
+        for i in range(self.count):
+            dest.buf[i] = self.buf[i]
+
+        return dest
+
+    #-----------------------------------------------------
+    def update(self, str):
+
+        buf = []
+        for i in str: buf.append(ord(i))
+        ilen = U32(len(buf))
+
+        # check if the first length is out of range
+        # as the length is measured in bits then multiplay it by 8
+        if (long(self.len1 + (ilen << 3)) < long(self.len1)):
+            self.len2 = self.len2 + U32(1)
+
+        self.len1 = self.len1 + (ilen << 3)
+        self.len2 = self.len2 + (ilen >> 29)
+
+        L = U32(0)
+        bufpos = 0
+        while (long(ilen) > 0):
+            if (64 - long(self.count)) < long(ilen): L = U32(64 - long(self.count))
+            else: L = ilen
+            for i in range(int(L)): self.buf[i + int(self.count)] = buf[i + bufpos]
+            self.count = self.count + L
+            ilen = ilen - L
+            bufpos = bufpos + int(L)
+
+            if (long(self.count) == 64L):
+                self.count = U32(0L)
+                X = []
+                i = 0
+                for j in range(16):
+                    X.append(U32(self.buf[i]) + (U32(self.buf[i+1]) << 8)  + \
+                    (U32(self.buf[i+2]) << 16) + (U32(self.buf[i+3]) << 24))
+                    i = i + 4
+
+                A = self.A
+                B = self.B
+                C = self.C
+                D = self.D
+
+                A = f1(A,B,C,D, 0, 3, X)
+                D = f1(D,A,B,C, 1, 7, X)
+                C = f1(C,D,A,B, 2,11, X)
+                B = f1(B,C,D,A, 3,19, X)
+                A = f1(A,B,C,D, 4, 3, X)
+                D = f1(D,A,B,C, 5, 7, X)
+                C = f1(C,D,A,B, 6,11, X)
+                B = f1(B,C,D,A, 7,19, X)
+                A = f1(A,B,C,D, 8, 3, X)
+                D = f1(D,A,B,C, 9, 7, X)
+                C = f1(C,D,A,B,10,11, X)
+                B = f1(B,C,D,A,11,19, X)
+                A = f1(A,B,C,D,12, 3, X)
+                D = f1(D,A,B,C,13, 7, X)
+                C = f1(C,D,A,B,14,11, X)
+                B = f1(B,C,D,A,15,19, X)
+
+                A = f2(A,B,C,D, 0, 3, X)
+                D = f2(D,A,B,C, 4, 5, X)
+                C = f2(C,D,A,B, 8, 9, X)
+                B = f2(B,C,D,A,12,13, X)
+                A = f2(A,B,C,D, 1, 3, X)
+                D = f2(D,A,B,C, 5, 5, X)
+                C = f2(C,D,A,B, 9, 9, X)
+                B = f2(B,C,D,A,13,13, X)
+                A = f2(A,B,C,D, 2, 3, X)
+                D = f2(D,A,B,C, 6, 5, X)
+                C = f2(C,D,A,B,10, 9, X)
+                B = f2(B,C,D,A,14,13, X)
+                A = f2(A,B,C,D, 3, 3, X)
+                D = f2(D,A,B,C, 7, 5, X)
+                C = f2(C,D,A,B,11, 9, X)
+                B = f2(B,C,D,A,15,13, X)
+
+                A = f3(A,B,C,D, 0, 3, X)
+                D = f3(D,A,B,C, 8, 9, X)
+                C = f3(C,D,A,B, 4,11, X)
+                B = f3(B,C,D,A,12,15, X)
+                A = f3(A,B,C,D, 2, 3, X)
+                D = f3(D,A,B,C,10, 9, X)
+                C = f3(C,D,A,B, 6,11, X)
+                B = f3(B,C,D,A,14,15, X)
+                A = f3(A,B,C,D, 1, 3, X)
+                D = f3(D,A,B,C, 9, 9, X)
+                C = f3(C,D,A,B, 5,11, X)
+                B = f3(B,C,D,A,13,15, X)
+                A = f3(A,B,C,D, 3, 3, X)
+                D = f3(D,A,B,C,11, 9, X)
+                C = f3(C,D,A,B, 7,11, X)
+                B = f3(B,C,D,A,15,15, X)
+
+                self.A = self.A + A
+                self.B = self.B + B
+                self.C = self.C + C
+                self.D = self.D + D
+
+    #-----------------------------------------------------
+    def digest(self):
+
+        res = [0x00] * 16
+        s = [0x00] * 8
+        padding = [0x00] * 64
+        padding[0] = 0x80
+        padlen, oldlen1, oldlen2 = U32(0), U32(0), U32(0)
+
+        temp = self.make_copy()
+
+        oldlen1 = temp.len1
+        oldlen2 = temp.len2
+        if (56 <= long(self.count)): padlen = U32(56 - long(self.count) + 64)
+        else: padlen = U32(56 - long(self.count))
+
+        temp.update(int_array2str(padding[:int(padlen)]))
+
+        s[0]= (oldlen1)        & U32(0xFF)
+        s[1]=((oldlen1) >>  8) & U32(0xFF)
+        s[2]=((oldlen1) >> 16) & U32(0xFF)
+        s[3]=((oldlen1) >> 24) & U32(0xFF)
+        s[4]= (oldlen2)        & U32(0xFF)
+        s[5]=((oldlen2) >>  8) & U32(0xFF)
+        s[6]=((oldlen2) >> 16) & U32(0xFF)
+        s[7]=((oldlen2) >> 24) & U32(0xFF)
+        temp.update(int_array2str(s))
+
+        res[ 0]= temp.A        & U32(0xFF)
+        res[ 1]=(temp.A >>  8) & U32(0xFF)
+        res[ 2]=(temp.A >> 16) & U32(0xFF)
+        res[ 3]=(temp.A >> 24) & U32(0xFF)
+        res[ 4]= temp.B        & U32(0xFF)
+        res[ 5]=(temp.B >>  8) & U32(0xFF)
+        res[ 6]=(temp.B >> 16) & U32(0xFF)
+        res[ 7]=(temp.B >> 24) & U32(0xFF)
+        res[ 8]= temp.C        & U32(0xFF)
+        res[ 9]=(temp.C >>  8) & U32(0xFF)
+        res[10]=(temp.C >> 16) & U32(0xFF)
+        res[11]=(temp.C >> 24) & U32(0xFF)
+        res[12]= temp.D        & U32(0xFF)
+        res[13]=(temp.D >>  8) & U32(0xFF)
+        res[14]=(temp.D >> 16) & U32(0xFF)
+        res[15]=(temp.D >> 24) & U32(0xFF)
+
+        return int_array2str(res)
+
+#====================================================================
+# helpers
+def F(x, y, z): return (((x) & (y)) | ((~x) & (z)))
+def G(x, y, z): return (((x) & (y)) | ((x) & (z)) | ((y) & (z)))
+def H(x, y, z): return ((x) ^ (y) ^ (z))
+
+def ROL(x, n): return (((x) << n) | ((x) >> (32-n)))
+
+def f1(a, b, c, d, k, s, X): return ROL(a + F(b, c, d) + X[k], s)
+def f2(a, b, c, d, k, s, X): return ROL(a + G(b, c, d) + X[k] + U32(0x5a827999L), s)
+def f3(a, b, c, d, k, s, X): return ROL(a + H(b, c, d) + X[k] + U32(0x6ed9eba1L), s)
+
+#--------------------------------------------------------------------
+# helper function
+def int_array2str(array):
+        str = ''
+        for i in array:
+            str = str + chr(i)
+        return str
+
+#--------------------------------------------------------------------
+# To be able to use md4.new() instead of md4.MD4()
+new = MD4
diff --git a/python2/smb/utils/pyDes.py b/python2/smb/utils/pyDes.py
new file mode 100644
index 00000000..6160e2a4
--- /dev/null
+++ b/python2/smb/utils/pyDes.py
@@ -0,0 +1,852 @@
+#############################################################################
+# 				Documentation				    #
+#############################################################################
+
+# Author:   Todd Whiteman
+# Date:     16th March, 2009
+# Verion:   2.0.0
+# License:  Public Domain - free to do as you wish
+# Homepage: http://twhiteman.netfirms.com/des.html
+#
+# This is a pure python implementation of the DES encryption algorithm.
+# It's pure python to avoid portability issues, since most DES 
+# implementations are programmed in C (for performance reasons).
+#
+# Triple DES class is also implemented, utilising the DES base. Triple DES
+# is either DES-EDE3 with a 24 byte key, or DES-EDE2 with a 16 byte key.
+#
+# See the README.txt that should come with this python module for the
+# implementation methods used.
+#
+# Thanks to:
+#  * David Broadwell for ideas, comments and suggestions.
+#  * Mario Wolff for pointing out and debugging some triple des CBC errors.
+#  * Santiago Palladino for providing the PKCS5 padding technique.
+#  * Shaya for correcting the PAD_PKCS5 triple des CBC errors.
+#
+"""A pure python implementation of the DES and TRIPLE DES encryption algorithms.
+
+Class initialization
+--------------------
+pyDes.des(key, [mode], [IV], [pad], [padmode])
+pyDes.triple_des(key, [mode], [IV], [pad], [padmode])
+
+key     -> Bytes containing the encryption key. 8 bytes for DES, 16 or 24 bytes
+	   for Triple DES
+mode    -> Optional argument for encryption type, can be either
+	   pyDes.ECB (Electronic Code Book) or pyDes.CBC (Cypher Block Chaining)
+IV      -> Optional Initial Value bytes, must be supplied if using CBC mode.
+	   Length must be 8 bytes.
+pad     -> Optional argument, set the pad character (PAD_NORMAL) to use during
+	   all encrypt/decrpt operations done with this instance.
+padmode -> Optional argument, set the padding mode (PAD_NORMAL or PAD_PKCS5)
+	   to use during all encrypt/decrpt operations done with this instance.
+
+I recommend to use PAD_PKCS5 padding, as then you never need to worry about any
+padding issues, as the padding can be removed unambiguously upon decrypting
+data that was encrypted using PAD_PKCS5 padmode.
+
+Common methods
+--------------
+encrypt(data, [pad], [padmode])
+decrypt(data, [pad], [padmode])
+
+data    -> Bytes to be encrypted/decrypted
+pad     -> Optional argument. Only when using padmode of PAD_NORMAL. For
+	   encryption, adds this characters to the end of the data block when
+	   data is not a multiple of 8 bytes. For decryption, will remove the
+	   trailing characters that match this pad character from the last 8
+	   bytes of the unencrypted data block.
+padmode -> Optional argument, set the padding mode, must be one of PAD_NORMAL
+	   or PAD_PKCS5). Defaults to PAD_NORMAL.
+	  
+
+Example
+-------
+from pyDes import *
+
+data = "Please encrypt my data"
+k = des("DESCRYPT", CBC, "\0\0\0\0\0\0\0\0", pad=None, padmode=PAD_PKCS5)
+# For Python3, you'll need to use bytes, i.e.:
+#   data = b"Please encrypt my data"
+#   k = des(b"DESCRYPT", CBC, b"\0\0\0\0\0\0\0\0", pad=None, padmode=PAD_PKCS5)
+d = k.encrypt(data)
+print "Encrypted: %r" % d
+print "Decrypted: %r" % k.decrypt(d)
+assert k.decrypt(d, padmode=PAD_PKCS5) == data
+
+
+See the module source (pyDes.py) for more examples of use.
+You can also run the pyDes.py file without and arguments to see a simple test.
+
+Note: This code was not written for high-end systems needing a fast
+      implementation, but rather a handy portable solution with small usage.
+
+"""
+
+import sys
+
+# _pythonMajorVersion is used to handle Python2 and Python3 differences.
+_pythonMajorVersion = sys.version_info[0]
+
+# Modes of crypting / cyphering
+ECB =	0
+CBC =	1
+
+# Modes of padding
+PAD_NORMAL = 1
+PAD_PKCS5 = 2
+
+# PAD_PKCS5: is a method that will unambiguously remove all padding
+#            characters after decryption, when originally encrypted with
+#            this padding mode.
+# For a good description of the PKCS5 padding technique, see:
+# http://www.faqs.org/rfcs/rfc1423.html
+
+# The base class shared by des and triple des.
+class _baseDes(object):
+	def __init__(self, mode=ECB, IV=None, pad=None, padmode=PAD_NORMAL):
+		if IV:
+			IV = self._guardAgainstUnicode(IV)
+		if pad:
+			pad = self._guardAgainstUnicode(pad)
+		self.block_size = 8
+		# Sanity checking of arguments.
+		if pad and padmode == PAD_PKCS5:
+			raise ValueError("Cannot use a pad character with PAD_PKCS5")
+		if IV and len(IV) != self.block_size:
+			raise ValueError("Invalid Initial Value (IV), must be a multiple of " + str(self.block_size) + " bytes")
+
+		# Set the passed in variables
+		self._mode = mode
+		self._iv = IV
+		self._padding = pad
+		self._padmode = padmode
+
+	def getKey(self):
+		"""getKey() -> bytes"""
+		return self.__key
+
+	def setKey(self, key):
+		"""Will set the crypting key for this object."""
+		key = self._guardAgainstUnicode(key)
+		self.__key = key
+
+	def getMode(self):
+		"""getMode() -> pyDes.ECB or pyDes.CBC"""
+		return self._mode
+
+	def setMode(self, mode):
+		"""Sets the type of crypting mode, pyDes.ECB or pyDes.CBC"""
+		self._mode = mode
+
+	def getPadding(self):
+		"""getPadding() -> bytes of length 1. Padding character."""
+		return self._padding
+
+	def setPadding(self, pad):
+		"""setPadding() -> bytes of length 1. Padding character."""
+		if pad is not None:
+			pad = self._guardAgainstUnicode(pad)
+		self._padding = pad
+
+	def getPadMode(self):
+		"""getPadMode() -> pyDes.PAD_NORMAL or pyDes.PAD_PKCS5"""
+		return self._padmode
+		
+	def setPadMode(self, mode):
+		"""Sets the type of padding mode, pyDes.PAD_NORMAL or pyDes.PAD_PKCS5"""
+		self._padmode = mode
+
+	def getIV(self):
+		"""getIV() -> bytes"""
+		return self._iv
+
+	def setIV(self, IV):
+		"""Will set the Initial Value, used in conjunction with CBC mode"""
+		if not IV or len(IV) != self.block_size:
+			raise ValueError("Invalid Initial Value (IV), must be a multiple of " + str(self.block_size) + " bytes")
+		IV = self._guardAgainstUnicode(IV)
+		self._iv = IV
+
+	def _padData(self, data, pad, padmode):
+		# Pad data depending on the mode
+		if padmode is None:
+			# Get the default padding mode.
+			padmode = self.getPadMode()
+		if pad and padmode == PAD_PKCS5:
+			raise ValueError("Cannot use a pad character with PAD_PKCS5")
+
+		if padmode == PAD_NORMAL:
+			if len(data) % self.block_size == 0:
+				# No padding required.
+				return data
+
+			if not pad:
+				# Get the default padding.
+				pad = self.getPadding()
+			if not pad:
+				raise ValueError("Data must be a multiple of " + str(self.block_size) + " bytes in length. Use padmode=PAD_PKCS5 or set the pad character.")
+			data += (self.block_size - (len(data) % self.block_size)) * pad
+		
+		elif padmode == PAD_PKCS5:
+			pad_len = 8 - (len(data) % self.block_size)
+			if _pythonMajorVersion < 3:
+				data += pad_len * chr(pad_len)
+			else:
+				data += bytes([pad_len] * pad_len)
+
+		return data
+
+	def _unpadData(self, data, pad, padmode):
+		# Unpad data depending on the mode.
+		if not data:
+			return data
+		if pad and padmode == PAD_PKCS5:
+			raise ValueError("Cannot use a pad character with PAD_PKCS5")
+		if padmode is None:
+			# Get the default padding mode.
+			padmode = self.getPadMode()
+
+		if padmode == PAD_NORMAL:
+			if not pad:
+				# Get the default padding.
+				pad = self.getPadding()
+			if pad:
+				data = data[:-self.block_size] + \
+				       data[-self.block_size:].rstrip(pad)
+
+		elif padmode == PAD_PKCS5:
+			if _pythonMajorVersion < 3:
+				pad_len = ord(data[-1])
+			else:
+				pad_len = data[-1]
+			data = data[:-pad_len]
+
+		return data
+
+	def _guardAgainstUnicode(self, data):
+		# Only accept byte strings or ascii unicode values, otherwise
+		# there is no way to correctly decode the data into bytes.
+		if _pythonMajorVersion < 3:
+			if isinstance(data, unicode):
+				raise ValueError("pyDes can only work with bytes, not Unicode strings.")
+		else:
+			if isinstance(data, str):
+				# Only accept ascii unicode values.
+				try:
+					return data.encode('ascii')
+				except UnicodeEncodeError:
+					pass
+				raise ValueError("pyDes can only work with encoded strings, not Unicode.")
+		return data
+
+#############################################################################
+# 				    DES					    #
+#############################################################################
+class des(_baseDes):
+	"""DES encryption/decrytpion class
+
+	Supports ECB (Electronic Code Book) and CBC (Cypher Block Chaining) modes.
+
+	pyDes.des(key,[mode], [IV])
+
+	key  -> Bytes containing the encryption key, must be exactly 8 bytes
+	mode -> Optional argument for encryption type, can be either pyDes.ECB
+		(Electronic Code Book), pyDes.CBC (Cypher Block Chaining)
+	IV   -> Optional Initial Value bytes, must be supplied if using CBC mode.
+		Must be 8 bytes in length.
+	pad  -> Optional argument, set the pad character (PAD_NORMAL) to use
+		during all encrypt/decrpt operations done with this instance.
+	padmode -> Optional argument, set the padding mode (PAD_NORMAL or
+		PAD_PKCS5) to use during all encrypt/decrpt operations done
+		with this instance.
+	"""
+
+
+	# Permutation and translation tables for DES
+	__pc1 = [56, 48, 40, 32, 24, 16,  8,
+		  0, 57, 49, 41, 33, 25, 17,
+		  9,  1, 58, 50, 42, 34, 26,
+		 18, 10,  2, 59, 51, 43, 35,
+		 62, 54, 46, 38, 30, 22, 14,
+		  6, 61, 53, 45, 37, 29, 21,
+		 13,  5, 60, 52, 44, 36, 28,
+		 20, 12,  4, 27, 19, 11,  3
+	]
+
+	# number left rotations of pc1
+	__left_rotations = [
+		1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1
+	]
+
+	# permuted choice key (table 2)
+	__pc2 = [
+		13, 16, 10, 23,  0,  4,
+		 2, 27, 14,  5, 20,  9,
+		22, 18, 11,  3, 25,  7,
+		15,  6, 26, 19, 12,  1,
+		40, 51, 30, 36, 46, 54,
+		29, 39, 50, 44, 32, 47,
+		43, 48, 38, 55, 33, 52,
+		45, 41, 49, 35, 28, 31
+	]
+
+	# initial permutation IP
+	__ip = [57, 49, 41, 33, 25, 17, 9,  1,
+		59, 51, 43, 35, 27, 19, 11, 3,
+		61, 53, 45, 37, 29, 21, 13, 5,
+		63, 55, 47, 39, 31, 23, 15, 7,
+		56, 48, 40, 32, 24, 16, 8,  0,
+		58, 50, 42, 34, 26, 18, 10, 2,
+		60, 52, 44, 36, 28, 20, 12, 4,
+		62, 54, 46, 38, 30, 22, 14, 6
+	]
+
+	# Expansion table for turning 32 bit blocks into 48 bits
+	__expansion_table = [
+		31,  0,  1,  2,  3,  4,
+		 3,  4,  5,  6,  7,  8,
+		 7,  8,  9, 10, 11, 12,
+		11, 12, 13, 14, 15, 16,
+		15, 16, 17, 18, 19, 20,
+		19, 20, 21, 22, 23, 24,
+		23, 24, 25, 26, 27, 28,
+		27, 28, 29, 30, 31,  0
+	]
+
+	# The (in)famous S-boxes
+	__sbox = [
+		# S1
+		[14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7,
+		 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8,
+		 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0,
+		 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13],
+
+		# S2
+		[15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10,
+		 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5,
+		 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15,
+		 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9],
+
+		# S3
+		[10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8,
+		 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1,
+		 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7,
+		 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12],
+
+		# S4
+		[7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15,
+		 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9,
+		 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4,
+		 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14],
+
+		# S5
+		[2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9,
+		 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6,
+		 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14,
+		 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3],
+
+		# S6
+		[12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11,
+		 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8,
+		 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6,
+		 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13],
+
+		# S7
+		[4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1,
+		 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6,
+		 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2,
+		 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12],
+
+		# S8
+		[13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7,
+		 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2,
+		 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8,
+		 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11],
+	]
+
+
+	# 32-bit permutation function P used on the output of the S-boxes
+	__p = [
+		15, 6, 19, 20, 28, 11,
+		27, 16, 0, 14, 22, 25,
+		4, 17, 30, 9, 1, 7,
+		23,13, 31, 26, 2, 8,
+		18, 12, 29, 5, 21, 10,
+		3, 24
+	]
+
+	# final permutation IP^-1
+	__fp = [
+		39,  7, 47, 15, 55, 23, 63, 31,
+		38,  6, 46, 14, 54, 22, 62, 30,
+		37,  5, 45, 13, 53, 21, 61, 29,
+		36,  4, 44, 12, 52, 20, 60, 28,
+		35,  3, 43, 11, 51, 19, 59, 27,
+		34,  2, 42, 10, 50, 18, 58, 26,
+		33,  1, 41,  9, 49, 17, 57, 25,
+		32,  0, 40,  8, 48, 16, 56, 24
+	]
+
+	# Type of crypting being done
+	ENCRYPT =	0x00
+	DECRYPT =	0x01
+
+	# Initialisation
+	def __init__(self, key, mode=ECB, IV=None, pad=None, padmode=PAD_NORMAL):
+		# Sanity checking of arguments.
+		if len(key) != 8:
+			raise ValueError("Invalid DES key size. Key must be exactly 8 bytes long.")
+		_baseDes.__init__(self, mode, IV, pad, padmode)
+		self.key_size = 8
+
+		self.L = []
+		self.R = []
+		self.Kn = [ [0] * 48 ] * 16	# 16 48-bit keys (K1 - K16)
+		self.final = []
+
+		self.setKey(key)
+
+	def setKey(self, key):
+		"""Will set the crypting key for this object. Must be 8 bytes."""
+		_baseDes.setKey(self, key)
+		self.__create_sub_keys()
+
+	def __String_to_BitList(self, data):
+		"""Turn the string data, into a list of bits (1, 0)'s"""
+		if _pythonMajorVersion < 3:
+			# Turn the strings into integers. Python 3 uses a bytes
+			# class, which already has this behaviour.
+			data = [ord(c) for c in data]
+		l = len(data) * 8
+		result = [0] * l
+		pos = 0
+		for ch in data:
+			i = 7
+			while i >= 0:
+				if ch & (1 << i) != 0:
+					result[pos] = 1
+				else:
+					result[pos] = 0
+				pos += 1
+				i -= 1
+
+		return result
+
+	def __BitList_to_String(self, data):
+		"""Turn the list of bits -> data, into a string"""
+		result = []
+		pos = 0
+		c = 0
+		while pos < len(data):
+			c += data[pos] << (7 - (pos % 8))
+			if (pos % 8) == 7:
+				result.append(c)
+				c = 0
+			pos += 1
+
+		if _pythonMajorVersion < 3:
+			return ''.join([ chr(c) for c in result ])
+		else:
+			return bytes(result)
+
+	def __permutate(self, table, block):
+		"""Permutate this block with the specified table"""
+		return list(map(lambda x: block[x], table))
+	
+	# Transform the secret key, so that it is ready for data processing
+	# Create the 16 subkeys, K[1] - K[16]
+	def __create_sub_keys(self):
+		"""Create the 16 subkeys K[1] to K[16] from the given key"""
+		key = self.__permutate(des.__pc1, self.__String_to_BitList(self.getKey()))
+		i = 0
+		# Split into Left and Right sections
+		self.L = key[:28]
+		self.R = key[28:]
+		while i < 16:
+			j = 0
+			# Perform circular left shifts
+			while j < des.__left_rotations[i]:
+				self.L.append(self.L[0])
+				del self.L[0]
+
+				self.R.append(self.R[0])
+				del self.R[0]
+
+				j += 1
+
+			# Create one of the 16 subkeys through pc2 permutation
+			self.Kn[i] = self.__permutate(des.__pc2, self.L + self.R)
+
+			i += 1
+
+	# Main part of the encryption algorithm, the number cruncher :)
+	def __des_crypt(self, block, crypt_type):
+		"""Crypt the block of data through DES bit-manipulation"""
+		block = self.__permutate(des.__ip, block)
+		self.L = block[:32]
+		self.R = block[32:]
+
+		# Encryption starts from Kn[1] through to Kn[16]
+		if crypt_type == des.ENCRYPT:
+			iteration = 0
+			iteration_adjustment = 1
+		# Decryption starts from Kn[16] down to Kn[1]
+		else:
+			iteration = 15
+			iteration_adjustment = -1
+
+		i = 0
+		while i < 16:
+			# Make a copy of R[i-1], this will later become L[i]
+			tempR = self.R[:]
+
+			# Permutate R[i - 1] to start creating R[i]
+			self.R = self.__permutate(des.__expansion_table, self.R)
+
+			# Exclusive or R[i - 1] with K[i], create B[1] to B[8] whilst here
+			self.R = list(map(lambda x, y: x ^ y, self.R, self.Kn[iteration]))
+			B = [self.R[:6], self.R[6:12], self.R[12:18], self.R[18:24], self.R[24:30], self.R[30:36], self.R[36:42], self.R[42:]]
+			# Optimization: Replaced below commented code with above
+			#j = 0
+			#B = []
+			#while j < len(self.R):
+			#	self.R[j] = self.R[j] ^ self.Kn[iteration][j]
+			#	j += 1
+			#	if j % 6 == 0:
+			#		B.append(self.R[j-6:j])
+
+			# Permutate B[1] to B[8] using the S-Boxes
+			j = 0
+			Bn = [0] * 32
+			pos = 0
+			while j < 8:
+				# Work out the offsets
+				m = (B[j][0] << 1) + B[j][5]
+				n = (B[j][1] << 3) + (B[j][2] << 2) + (B[j][3] << 1) + B[j][4]
+
+				# Find the permutation value
+				v = des.__sbox[j][(m << 4) + n]
+
+				# Turn value into bits, add it to result: Bn
+				Bn[pos] = (v & 8) >> 3
+				Bn[pos + 1] = (v & 4) >> 2
+				Bn[pos + 2] = (v & 2) >> 1
+				Bn[pos + 3] = v & 1
+
+				pos += 4
+				j += 1
+
+			# Permutate the concatination of B[1] to B[8] (Bn)
+			self.R = self.__permutate(des.__p, Bn)
+
+			# Xor with L[i - 1]
+			self.R = list(map(lambda x, y: x ^ y, self.R, self.L))
+			# Optimization: This now replaces the below commented code
+			#j = 0
+			#while j < len(self.R):
+			#	self.R[j] = self.R[j] ^ self.L[j]
+			#	j += 1
+
+			# L[i] becomes R[i - 1]
+			self.L = tempR
+
+			i += 1
+			iteration += iteration_adjustment
+		
+		# Final permutation of R[16]L[16]
+		self.final = self.__permutate(des.__fp, self.R + self.L)
+		return self.final
+
+
+	# Data to be encrypted/decrypted
+	def crypt(self, data, crypt_type):
+		"""Crypt the data in blocks, running it through des_crypt()"""
+
+		# Error check the data
+		if not data:
+			return ''
+		if len(data) % self.block_size != 0:
+			if crypt_type == des.DECRYPT: # Decryption must work on 8 byte blocks
+				raise ValueError("Invalid data length, data must be a multiple of " + str(self.block_size) + " bytes\n.")
+			if not self.getPadding():
+				raise ValueError("Invalid data length, data must be a multiple of " + str(self.block_size) + " bytes\n. Try setting the optional padding character")
+			else:
+				data += (self.block_size - (len(data) % self.block_size)) * self.getPadding()
+			# print "Len of data: %f" % (len(data) / self.block_size)
+
+		if self.getMode() == CBC:
+			if self.getIV():
+				iv = self.__String_to_BitList(self.getIV())
+			else:
+				raise ValueError("For CBC mode, you must supply the Initial Value (IV) for ciphering")
+
+		# Split the data into blocks, crypting each one seperately
+		i = 0
+		dict = {}
+		result = []
+		#cached = 0
+		#lines = 0
+		while i < len(data):
+			# Test code for caching encryption results
+			#lines += 1
+			#if dict.has_key(data[i:i+8]):
+				#print "Cached result for: %s" % data[i:i+8]
+			#	cached += 1
+			#	result.append(dict[data[i:i+8]])
+			#	i += 8
+			#	continue
+				
+			block = self.__String_to_BitList(data[i:i+8])
+
+			# Xor with IV if using CBC mode
+			if self.getMode() == CBC:
+				if crypt_type == des.ENCRYPT:
+					block = list(map(lambda x, y: x ^ y, block, iv))
+					#j = 0
+					#while j < len(block):
+					#	block[j] = block[j] ^ iv[j]
+					#	j += 1
+
+				processed_block = self.__des_crypt(block, crypt_type)
+
+				if crypt_type == des.DECRYPT:
+					processed_block = list(map(lambda x, y: x ^ y, processed_block, iv))
+					#j = 0
+					#while j < len(processed_block):
+					#	processed_block[j] = processed_block[j] ^ iv[j]
+					#	j += 1
+					iv = block
+				else:
+					iv = processed_block
+			else:
+				processed_block = self.__des_crypt(block, crypt_type)
+
+
+			# Add the resulting crypted block to our list
+			#d = self.__BitList_to_String(processed_block)
+			#result.append(d)
+			result.append(self.__BitList_to_String(processed_block))
+			#dict[data[i:i+8]] = d
+			i += 8
+
+		# print "Lines: %d, cached: %d" % (lines, cached)
+
+		# Return the full crypted string
+		if _pythonMajorVersion < 3:
+			return ''.join(result)
+		else:
+			return bytes.fromhex('').join(result)
+
+	def encrypt(self, data, pad=None, padmode=None):
+		"""encrypt(data, [pad], [padmode]) -> bytes
+
+		data : Bytes to be encrypted
+		pad  : Optional argument for encryption padding. Must only be one byte
+		padmode : Optional argument for overriding the padding mode.
+
+		The data must be a multiple of 8 bytes and will be encrypted
+		with the already specified key. Data does not have to be a
+		multiple of 8 bytes if the padding character is supplied, or
+		the padmode is set to PAD_PKCS5, as bytes will then added to
+		ensure the be padded data is a multiple of 8 bytes.
+		"""
+		data = self._guardAgainstUnicode(data)
+		if pad is not None:
+			pad = self._guardAgainstUnicode(pad)
+		data = self._padData(data, pad, padmode)
+		return self.crypt(data, des.ENCRYPT)
+
+	def decrypt(self, data, pad=None, padmode=None):
+		"""decrypt(data, [pad], [padmode]) -> bytes
+
+		data : Bytes to be encrypted
+		pad  : Optional argument for decryption padding. Must only be one byte
+		padmode : Optional argument for overriding the padding mode.
+
+		The data must be a multiple of 8 bytes and will be decrypted
+		with the already specified key. In PAD_NORMAL mode, if the
+		optional padding character is supplied, then the un-encrypted
+		data will have the padding characters removed from the end of
+		the bytes. This pad removal only occurs on the last 8 bytes of
+		the data (last data block). In PAD_PKCS5 mode, the special
+		padding end markers will be removed from the data after decrypting.
+		"""
+		data = self._guardAgainstUnicode(data)
+		if pad is not None:
+			pad = self._guardAgainstUnicode(pad)
+		data = self.crypt(data, des.DECRYPT)
+		return self._unpadData(data, pad, padmode)
+
+
+
+#############################################################################
+# 				Triple DES				    #
+#############################################################################
+class triple_des(_baseDes):
+	"""Triple DES encryption/decrytpion class
+
+	This algorithm uses the DES-EDE3 (when a 24 byte key is supplied) or
+	the DES-EDE2 (when a 16 byte key is supplied) encryption methods.
+	Supports ECB (Electronic Code Book) and CBC (Cypher Block Chaining) modes.
+
+	pyDes.des(key, [mode], [IV])
+
+	key  -> Bytes containing the encryption key, must be either 16 or
+	        24 bytes long
+	mode -> Optional argument for encryption type, can be either pyDes.ECB
+		(Electronic Code Book), pyDes.CBC (Cypher Block Chaining)
+	IV   -> Optional Initial Value bytes, must be supplied if using CBC mode.
+		Must be 8 bytes in length.
+	pad  -> Optional argument, set the pad character (PAD_NORMAL) to use
+		during all encrypt/decrpt operations done with this instance.
+	padmode -> Optional argument, set the padding mode (PAD_NORMAL or
+		PAD_PKCS5) to use during all encrypt/decrpt operations done
+		with this instance.
+	"""
+	def __init__(self, key, mode=ECB, IV=None, pad=None, padmode=PAD_NORMAL):
+		_baseDes.__init__(self, mode, IV, pad, padmode)
+		self.setKey(key)
+
+	def setKey(self, key):
+		"""Will set the crypting key for this object. Either 16 or 24 bytes long."""
+		self.key_size = 24  # Use DES-EDE3 mode
+		if len(key) != self.key_size:
+			if len(key) == 16: # Use DES-EDE2 mode
+				self.key_size = 16
+			else:
+				raise ValueError("Invalid triple DES key size. Key must be either 16 or 24 bytes long")
+		if self.getMode() == CBC:
+			if not self.getIV():
+				# Use the first 8 bytes of the key
+				self._iv = key[:self.block_size]
+			if len(self.getIV()) != self.block_size:
+				raise ValueError("Invalid IV, must be 8 bytes in length")
+		self.__key1 = des(key[:8], self._mode, self._iv,
+				  self._padding, self._padmode)
+		self.__key2 = des(key[8:16], self._mode, self._iv,
+				  self._padding, self._padmode)
+		if self.key_size == 16:
+			self.__key3 = self.__key1
+		else:
+			self.__key3 = des(key[16:], self._mode, self._iv,
+					  self._padding, self._padmode)
+		_baseDes.setKey(self, key)
+
+	# Override setter methods to work on all 3 keys.
+
+	def setMode(self, mode):
+		"""Sets the type of crypting mode, pyDes.ECB or pyDes.CBC"""
+		_baseDes.setMode(self, mode)
+		for key in (self.__key1, self.__key2, self.__key3):
+			key.setMode(mode)
+
+	def setPadding(self, pad):
+		"""setPadding() -> bytes of length 1. Padding character."""
+		_baseDes.setPadding(self, pad)
+		for key in (self.__key1, self.__key2, self.__key3):
+			key.setPadding(pad)
+
+	def setPadMode(self, mode):
+		"""Sets the type of padding mode, pyDes.PAD_NORMAL or pyDes.PAD_PKCS5"""
+		_baseDes.setPadMode(self, mode)
+		for key in (self.__key1, self.__key2, self.__key3):
+			key.setPadMode(mode)
+
+	def setIV(self, IV):
+		"""Will set the Initial Value, used in conjunction with CBC mode"""
+		_baseDes.setIV(self, IV)
+		for key in (self.__key1, self.__key2, self.__key3):
+			key.setIV(IV)
+
+	def encrypt(self, data, pad=None, padmode=None):
+		"""encrypt(data, [pad], [padmode]) -> bytes
+
+		data : bytes to be encrypted
+		pad  : Optional argument for encryption padding. Must only be one byte
+		padmode : Optional argument for overriding the padding mode.
+
+		The data must be a multiple of 8 bytes and will be encrypted
+		with the already specified key. Data does not have to be a
+		multiple of 8 bytes if the padding character is supplied, or
+		the padmode is set to PAD_PKCS5, as bytes will then added to
+		ensure the be padded data is a multiple of 8 bytes.
+		"""
+		ENCRYPT = des.ENCRYPT
+		DECRYPT = des.DECRYPT
+		data = self._guardAgainstUnicode(data)
+		if pad is not None:
+			pad = self._guardAgainstUnicode(pad)
+		# Pad the data accordingly.
+		data = self._padData(data, pad, padmode)
+		if self.getMode() == CBC:
+			self.__key1.setIV(self.getIV())
+			self.__key2.setIV(self.getIV())
+			self.__key3.setIV(self.getIV())
+			i = 0
+			result = []
+			while i < len(data):
+				block = self.__key1.crypt(data[i:i+8], ENCRYPT)
+				block = self.__key2.crypt(block, DECRYPT)
+				block = self.__key3.crypt(block, ENCRYPT)
+				self.__key1.setIV(block)
+				self.__key2.setIV(block)
+				self.__key3.setIV(block)
+				result.append(block)
+				i += 8
+			if _pythonMajorVersion < 3:
+				return ''.join(result)
+			else:
+				return bytes.fromhex('').join(result)
+		else:
+			data = self.__key1.crypt(data, ENCRYPT)
+			data = self.__key2.crypt(data, DECRYPT)
+			return self.__key3.crypt(data, ENCRYPT)
+
+	def decrypt(self, data, pad=None, padmode=None):
+		"""decrypt(data, [pad], [padmode]) -> bytes
+
+		data : bytes to be encrypted
+		pad  : Optional argument for decryption padding. Must only be one byte
+		padmode : Optional argument for overriding the padding mode.
+
+		The data must be a multiple of 8 bytes and will be decrypted
+		with the already specified key. In PAD_NORMAL mode, if the
+		optional padding character is supplied, then the un-encrypted
+		data will have the padding characters removed from the end of
+		the bytes. This pad removal only occurs on the last 8 bytes of
+		the data (last data block). In PAD_PKCS5 mode, the special
+		padding end markers will be removed from the data after
+		decrypting, no pad character is required for PAD_PKCS5.
+		"""
+		ENCRYPT = des.ENCRYPT
+		DECRYPT = des.DECRYPT
+		data = self._guardAgainstUnicode(data)
+		if pad is not None:
+			pad = self._guardAgainstUnicode(pad)
+		if self.getMode() == CBC:
+			self.__key1.setIV(self.getIV())
+			self.__key2.setIV(self.getIV())
+			self.__key3.setIV(self.getIV())
+			i = 0
+			result = []
+			while i < len(data):
+				iv = data[i:i+8]
+				block = self.__key3.crypt(iv,    DECRYPT)
+				block = self.__key2.crypt(block, ENCRYPT)
+				block = self.__key1.crypt(block, DECRYPT)
+				self.__key1.setIV(iv)
+				self.__key2.setIV(iv)
+				self.__key3.setIV(iv)
+				result.append(block)
+				i += 8
+			if _pythonMajorVersion < 3:
+				data = ''.join(result)
+			else:
+				data = bytes.fromhex('').join(result)
+		else:
+			data = self.__key3.crypt(data, DECRYPT)
+			data = self.__key2.crypt(data, ENCRYPT)
+			data = self.__key1.crypt(data, DECRYPT)
+		return self._unpadData(data, pad, padmode)
diff --git a/python2/smb/utils/sha256.py b/python2/smb/utils/sha256.py
new file mode 100644
index 00000000..a13d6bf3
--- /dev/null
+++ b/python2/smb/utils/sha256.py
@@ -0,0 +1,110 @@
+#!/usr/bin/python
+__author__ = 'Thomas Dixon'
+__license__ = 'MIT'
+
+import copy, struct, sys
+
+digest_size = 32
+blocksize = 1
+
+def new(m=None):
+    return sha256(m)
+
+class sha256(object):
+    _k = (0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
+          0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
+          0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
+          0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
+          0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
+          0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
+          0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
+          0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
+          0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
+          0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
+          0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
+          0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
+          0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
+          0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
+          0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
+          0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2)
+    _h = (0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
+          0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19)
+    _output_size = 8
+
+    blocksize = 1
+    block_size = 64
+    digest_size = 32
+
+    def __init__(self, m=None):
+        self._buffer = ''
+        self._counter = 0
+
+        if m is not None:
+            if type(m) is not str:
+                raise TypeError, '%s() argument 1 must be string, not %s' % (self.__class__.__name__, type(m).__name__)
+            self.update(m)
+
+    def _rotr(self, x, y):
+        return ((x >> y) | (x << (32-y))) & 0xFFFFFFFF
+
+    def _sha256_process(self, c):
+        w = [0]*64
+        w[0:15] = struct.unpack('!16L', c)
+
+        for i in range(16, 64):
+            s0 = self._rotr(w[i-15], 7) ^ self._rotr(w[i-15], 18) ^ (w[i-15] >> 3)
+            s1 = self._rotr(w[i-2], 17) ^ self._rotr(w[i-2], 19) ^ (w[i-2] >> 10)
+            w[i] = (w[i-16] + s0 + w[i-7] + s1) & 0xFFFFFFFF
+
+        a,b,c,d,e,f,g,h = self._h
+
+        for i in range(64):
+            s0 = self._rotr(a, 2) ^ self._rotr(a, 13) ^ self._rotr(a, 22)
+            maj = (a & b) ^ (a & c) ^ (b & c)
+            t2 = s0 + maj
+            s1 = self._rotr(e, 6) ^ self._rotr(e, 11) ^ self._rotr(e, 25)
+            ch = (e & f) ^ ((~e) & g)
+            t1 = h + s1 + ch + self._k[i] + w[i]
+
+            h = g
+            g = f
+            f = e
+            e = (d + t1) & 0xFFFFFFFF
+            d = c
+            c = b
+            b = a
+            a = (t1 + t2) & 0xFFFFFFFF
+
+        self._h = [(x+y) & 0xFFFFFFFF for x,y in zip(self._h, [a,b,c,d,e,f,g,h])]
+
+    def update(self, m):
+        if not m:
+            return
+        if type(m) is not str:
+            raise TypeError, '%s() argument 1 must be string, not %s' % (sys._getframe().f_code.co_name, type(m).__name__)
+
+        self._buffer += m
+        self._counter += len(m)
+
+        while len(self._buffer) >= 64:
+            self._sha256_process(self._buffer[:64])
+            self._buffer = self._buffer[64:]
+
+    def digest(self):
+        mdi = self._counter & 0x3F
+        length = struct.pack('!Q', self._counter<<3)
+
+        if mdi < 56:
+            padlen = 55-mdi
+        else:
+            padlen = 119-mdi
+
+        r = self.copy()
+        r.update('\x80'+('\x00'*padlen)+length)
+        return ''.join([struct.pack('!L', i) for i in r._h[:self._output_size]])
+
+    def hexdigest(self):
+        return self.digest().encode('hex')
+
+    def copy(self):
+        return copy.deepcopy(self)
diff --git a/python2/tests/DirectSMBConnectionTests/__init__.py b/python2/tests/DirectSMBConnectionTests/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/python2/tests/DirectSMBConnectionTests/test_SMBHandler.py b/python2/tests/DirectSMBConnectionTests/test_SMBHandler.py
new file mode 100644
index 00000000..d868a38f
--- /dev/null
+++ b/python2/tests/DirectSMBConnectionTests/test_SMBHandler.py
@@ -0,0 +1,94 @@
+# -*- coding: utf-8 -*-
+
+import os, urllib, urllib2, time, random
+from StringIO import StringIO
+from smb.SMBHandler import SMBHandler
+import util
+
+
+try:
+    import hashlib
+    def MD5(): return hashlib.md5()
+except ImportError:
+    import md5
+    def MD5(): return md5.new()
+
+
+
+def test_basic():
+    # Basic test for smb URLs
+    director = urllib2.build_opener(SMBHandler)
+    fh = director.open('smb://%(user)s:%(password)s@%(server_ip)s/smbtest/rfc1001.txt' % util.getConnectionInfo())
+
+    s = fh.read()
+    md = MD5()
+    md.update(s)
+    assert md.hexdigest() == '5367c2bbf97f521059c78eab65309ad3'
+    assert len(s) == 158437
+
+    fh.close()
+
+
+def test_unicode():
+    # Test smb URLs with unicode paths
+    director = urllib2.build_opener(SMBHandler)
+    fh = director.open(u'smb://%(user)s:%(password)s@%(server_ip)s/smbtest/测试文件夹/垃圾文件.dat' % util.getConnectionInfo())
+
+    s = fh.read()
+    md = MD5()
+    md.update(s)
+    assert md.hexdigest() == '8a44c1e80d55e91c92350955cdf83442'
+    assert len(s) == 256000
+
+    fh.close()
+
+
+
+TEST_FILENAME = os.path.join(os.path.dirname(__file__), os.pardir, 'SupportFiles', 'binary.dat')
+TEST_FILESIZE = 256000
+TEST_DIGEST = 'bb6303f76e29f354b6fdf6ef58587e48'
+
+def test_upload():
+    info = util.getConnectionInfo()
+    info['filename'] = os.sep + 'StoreTest-%d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+
+    director = urllib2.build_opener(SMBHandler)
+    upload_fh = director.open('smb://%(user)s:%(password)s@%(server_ip)s/smbtest/%(filename)s' % info, data = open(TEST_FILENAME, 'rb'))
+
+    retr_fh = director.open('smb://%(user)s:%(password)s@%(server_ip)s/smbtest/%(filename)s' % info)
+
+    s = retr_fh.read()
+    md = MD5()
+    md.update(s)
+
+    assert md.hexdigest() == TEST_DIGEST
+    assert len(s) == TEST_FILESIZE
+
+
+def test_overwrite():
+    info = util.getConnectionInfo()
+    info['filename'] = os.sep + 'StoreTest-%d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+
+    test_s = 'test1234'
+    test_md = MD5()
+    test_md.update(test_s)
+
+    director = urllib2.build_opener(SMBHandler)
+    upload_fh = director.open('smb://%(user)s:%(password)s@%(server_ip)s/smbtest/%(filename)s' % info, data = StringIO(test_s))
+
+    retr_fh = director.open('smb://%(user)s:%(password)s@%(server_ip)s/smbtest/%(filename)s' % info)
+
+    s = retr_fh.read()
+    md = MD5()
+    md.update(s)
+
+    assert md.hexdigest() == test_md.hexdigest()
+    assert len(s) == len(test_s)
+
+    upload_fh = director.open('smb://%(user)s:%(password)s@%(server_ip)s/smbtest/%(filename)s' % info, data = open(TEST_FILENAME, 'rb'))
+
+    retr_fh = director.open('smb://%(user)s:%(password)s@%(server_ip)s/smbtest/%(filename)s' % info)
+
+    s = retr_fh.read()
+    md = MD5()
+    md.update(s)
diff --git a/python2/tests/DirectSMBConnectionTests/test_auth.py b/python2/tests/DirectSMBConnectionTests/test_auth.py
new file mode 100644
index 00000000..a213dc50
--- /dev/null
+++ b/python2/tests/DirectSMBConnectionTests/test_auth.py
@@ -0,0 +1,72 @@
+
+from smb.SMBConnection import SMBConnection
+from util import getConnectionInfo
+from nose.tools import with_setup
+from smb import smb_structs
+
+conn, conn2, conn3 = None, None, None
+
+def teardown_func():
+    global conn, conn2, conn3
+    if conn:
+        conn.close()
+    if conn2:
+        conn2.close()
+    if conn3:
+        conn3.close();
+
+@with_setup(teardown = teardown_func)
+def test_NTLMv1_auth_SMB1():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = False
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], domain = info['domain'], use_ntlm_v2 = False, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+    conn2 = SMBConnection(info['user'], 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = False, is_direct_tcp = True)
+    assert not conn2.connect(info['server_ip'], info['server_port'])
+
+    conn3 = SMBConnection('INVALIDUSER', 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = False, is_direct_tcp = True)
+    assert not conn3.connect(info['server_ip'], info['server_port'])
+
+@with_setup(teardown = teardown_func)
+def test_NTLMv2_auth_SMB1():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = False
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], domain = info['domain'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+    conn2 = SMBConnection(info['user'], 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert not conn2.connect(info['server_ip'], info['server_port'])
+
+    conn3 = SMBConnection('INVALIDUSER', 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert not conn3.connect(info['server_ip'], info['server_port'])
+
+@with_setup(teardown = teardown_func)
+def test_NTLMv1_auth_SMB2():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = True
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], domain = info['domain'], use_ntlm_v2 = False)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+    conn2 = SMBConnection(info['user'], 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = False)
+    assert not conn2.connect(info['server_ip'], info['server_port'])
+
+    conn3 = SMBConnection('INVALIDUSER', 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = False)
+    assert not conn3.connect(info['server_ip'], info['server_port'])
+
+@with_setup(teardown = teardown_func)
+def test_NTLMv2_auth_SMB2():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = True
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], domain = info['domain'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+    conn2 = SMBConnection(info['user'], 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert not conn2.connect(info['server_ip'], info['server_port'])
+
+    conn3 = SMBConnection('INVALIDUSER', 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert not conn3.connect(info['server_ip'], info['server_port'])
diff --git a/python2/tests/DirectSMBConnectionTests/test_createdeletedirectory.py b/python2/tests/DirectSMBConnectionTests/test_createdeletedirectory.py
new file mode 100644
index 00000000..38862b71
--- /dev/null
+++ b/python2/tests/DirectSMBConnectionTests/test_createdeletedirectory.py
@@ -0,0 +1,145 @@
+# -*- coding: utf-8 -*-
+
+import os, time, random
+from smb.SMBConnection import SMBConnection
+from smb.smb2_constants import SMB2_DIALECT_2
+from util import getConnectionInfo
+from nose.tools import with_setup
+from smb import smb_structs
+
+conn = None
+
+def setup_func_SMB1():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = False
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2():
+    global conn
+    smb_structs.SUPPORT_SMB2 = True
+    smb_structs.SUPPORT_SMB2x = False
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2x():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = True
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def teardown_func():
+    global conn
+    conn.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_english_directory_SMB1():
+    global conn
+
+    path = os.sep + 'TestDir %d-%d' % ( time.time(), random.randint(0, 1000) )
+    conn.createDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) in names
+
+    conn.deleteDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) not in names
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_english_directory_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    path = os.sep + 'TestDir %d-%d' % ( time.time(), random.randint(0, 1000) )
+    conn.createDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) in names
+
+    conn.deleteDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) not in names
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_english_directory_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    path = os.sep + 'TestDir %d-%d' % ( time.time(), random.randint(0, 1000) )
+    conn.createDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) in names
+
+    conn.deleteDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) not in names
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_unicode_directory_SMB1():
+    global conn
+
+    path = os.sep + u'文件夹创建 %d-%d' % ( time.time(), random.randint(0, 1000) )
+    conn.createDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) in names
+
+    conn.deleteDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) not in names
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_unicode_directory_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    path = os.sep + u'文件夹创建 %d-%d' % ( time.time(), random.randint(0, 1000) )
+    conn.createDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) in names
+
+    conn.deleteDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) not in names
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_unicode_directory_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    path = os.sep + u'文件夹创建 %d-%d' % ( time.time(), random.randint(0, 1000) )
+    conn.createDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) in names
+
+    conn.deleteDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) not in names
diff --git a/python2/tests/DirectSMBConnectionTests/test_echo.py b/python2/tests/DirectSMBConnectionTests/test_echo.py
new file mode 100644
index 00000000..f86f8ccf
--- /dev/null
+++ b/python2/tests/DirectSMBConnectionTests/test_echo.py
@@ -0,0 +1,24 @@
+
+import random
+from smb.SMBConnection import SMBConnection
+from util import getConnectionInfo
+from nose.tools import with_setup
+
+conn = None
+
+def setup_func():
+    global conn
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def teardown_func():
+    global conn
+    conn.close()
+
+@with_setup(setup_func, teardown_func)
+def test_echo():
+    global conn
+
+    data = '%d' % random.randint(1000, 9999)
+    assert conn.echo(data) == data
diff --git a/python2/tests/DirectSMBConnectionTests/test_listpath.py b/python2/tests/DirectSMBConnectionTests/test_listpath.py
new file mode 100644
index 00000000..bbc38e8e
--- /dev/null
+++ b/python2/tests/DirectSMBConnectionTests/test_listpath.py
@@ -0,0 +1,190 @@
+# -*- coding: utf-8 -*-
+
+from smb.SMBConnection import SMBConnection
+from smb.smb_constants import *
+from smb.smb2_constants import SMB2_DIALECT_2
+from util import getConnectionInfo
+from nose.tools import with_setup
+from smb import smb_structs
+
+conn = None
+
+def setup_func_SMB1():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = False
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2():
+    global conn
+    smb_structs.SUPPORT_SMB2 = True
+    smb_structs.SUPPORT_SMB2x = False
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2x():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = True
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def teardown_func():
+    global conn
+    conn.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_listPath_SMB1():
+    global conn
+    results = conn.listPath('smbtest', '/')
+    filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+    assert ( u'\u6d4b\u8bd5\u6587\u4ef6\u5939', True ) in filenames  # Test non-English folder names
+    assert ( u'Test Folder with Long Name', True ) in filenames      # Test long English folder names
+    assert ( u'TestDir1', True ) in filenames                        # Test short English folder names
+    assert ( u'Implementing CIFS - SMB.html', False ) in filenames   # Test long English file names
+    assert ( u'rfc1001.txt', False ) in filenames                    # Test short English file names
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_listSubPath_SMB1():
+    global conn
+    results = conn.listPath('smbtest', '/Test Folder with Long Name/')
+    filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+    assert ( u'Test File.txt', False ) in filenames
+    assert ( u'Test Folder', True ) in filenames
+    assert ( u'子文件夹', True ) in filenames
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_listPathWithManyFiles_SMB1():
+    global conn
+    results = conn.listPath('smbtest', '/RFC Archive/')
+    filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+    assert len(filenames)==999
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_listPath_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+    results = conn.listPath('smbtest', '/')
+    filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+    assert ( u'\u6d4b\u8bd5\u6587\u4ef6\u5939', True ) in filenames  # Test non-English folder names
+    assert ( u'Test Folder with Long Name', True ) in filenames      # Test long English folder names
+    assert ( u'TestDir1', True ) in filenames                        # Test short English folder names
+    assert ( u'Implementing CIFS - SMB.html', False ) in filenames   # Test long English file names
+    assert ( u'rfc1001.txt', False ) in filenames                    # Test short English file names
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_listPath_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+    results = conn.listPath('smbtest', '/')
+    filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+    assert ( u'\u6d4b\u8bd5\u6587\u4ef6\u5939', True ) in filenames  # Test non-English folder names
+    assert ( u'Test Folder with Long Name', True ) in filenames      # Test long English folder names
+    assert ( u'TestDir1', True ) in filenames                        # Test short English folder names
+    assert ( u'Implementing CIFS - SMB.html', False ) in filenames   # Test long English file names
+    assert ( u'rfc1001.txt', False ) in filenames                    # Test short English file names
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_listSubPath_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+    results = conn.listPath('smbtest', '/Test Folder with Long Name/')
+    filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+    assert ( u'Test File.txt', False ) in filenames
+    assert ( u'Test Folder', True ) in filenames
+    assert ( u'子文件夹', True ) in filenames
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_listSubPath_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+    results = conn.listPath('smbtest', '/Test Folder with Long Name/')
+    filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+    assert ( u'Test File.txt', False ) in filenames
+    assert ( u'Test Folder', True ) in filenames
+    assert ( u'子文件夹', True ) in filenames
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_listPathWithManyFiles_SMB2():
+    global conn
+    results = conn.listPath('smbtest', '/RFC Archive/')
+    filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+    assert len(filenames)==999
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_listPathFilterForDirectory_SMB1():
+    global conn
+    results = conn.listPath('smbtest', '/Test Folder with Long Name', search = SMB_FILE_ATTRIBUTE_DIRECTORY)
+    filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+    assert len(filenames) > 0
+    for f, isDirectory in filenames:
+        assert isDirectory
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_listPathFilterForDirectory_SMB2():
+    global conn
+    results = conn.listPath('smbtest', '/Test Folder with Long Name', search = SMB_FILE_ATTRIBUTE_DIRECTORY)
+    filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+    assert len(filenames) > 0
+    for f, isDirectory in filenames:
+        assert isDirectory
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_listPathFilterForFiles_SMB1():
+    global conn
+    results = conn.listPath('smbtest', '/Test Folder with Long Name', search = SMB_FILE_ATTRIBUTE_READONLY | SMB_FILE_ATTRIBUTE_HIDDEN | SMB_FILE_ATTRIBUTE_SYSTEM | SMB_FILE_ATTRIBUTE_ARCHIVE | SMB_FILE_ATTRIBUTE_INCL_NORMAL)
+    filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+    assert len(filenames) > 0
+    for f, isDirectory in filenames:
+        assert not isDirectory
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_listPathFilterForFiles_SMB2():
+    global conn
+    results = conn.listPath('smbtest', '/Test Folder with Long Name', search = SMB_FILE_ATTRIBUTE_READONLY | SMB_FILE_ATTRIBUTE_HIDDEN | SMB_FILE_ATTRIBUTE_SYSTEM | SMB_FILE_ATTRIBUTE_ARCHIVE | SMB_FILE_ATTRIBUTE_INCL_NORMAL)
+    filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+    assert len(filenames) > 0
+    for f, isDirectory in filenames:
+        assert not isDirectory
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_listPathFilterPattern_SMB1():
+    global conn
+    results = conn.listPath('smbtest', '/Test Folder with Long Name', pattern = 'Test*')
+    filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+    assert len(filenames) == 2
+    assert ( u'Test File.txt', False ) in filenames
+    assert ( u'Test Folder', True ) in filenames
+    assert ( u'子文件夹', True ) not in filenames
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_listPathFilterPattern_SMB2():
+    global conn
+    results = conn.listPath('smbtest', '/Test Folder with Long Name', pattern = 'Test*')
+    filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+    assert len(filenames) == 2
+    assert ( u'Test File.txt', False ) in filenames
+    assert ( u'Test Folder', True ) in filenames
+    assert ( u'子文件夹', True ) not in filenames
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_listPathFilterUnicodePattern_SMB1():
+    global conn
+    results = conn.listPath('smbtest', '/Test Folder with Long Name', pattern = u'*件夹')
+    filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+    assert len(filenames) == 1
+    assert ( u'Test File.txt', False ) not in filenames
+    assert ( u'Test Folder', True ) not in filenames
+    assert ( u'子文件夹', True ) in filenames
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_listPathFilterUnicodePattern_SMB2():
+    global conn
+    results = conn.listPath('smbtest', '/Test Folder with Long Name', pattern = u'*件夹')
+    filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+    assert len(filenames) == 1
+    assert ( u'Test File.txt', False ) not in filenames
+    assert ( u'Test Folder', True ) not in filenames
+    assert ( u'子文件夹', True ) in filenames
diff --git a/python2/tests/DirectSMBConnectionTests/test_listshares.py b/python2/tests/DirectSMBConnectionTests/test_listshares.py
new file mode 100644
index 00000000..f5ee1e65
--- /dev/null
+++ b/python2/tests/DirectSMBConnectionTests/test_listshares.py
@@ -0,0 +1,54 @@
+
+from smb.SMBConnection import SMBConnection
+from smb.smb2_constants import SMB2_DIALECT_2
+from util import getConnectionInfo
+from nose.tools import with_setup
+from smb import smb_structs
+
+conn = None
+
+def setup_func_SMB1():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = False
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2():
+    global conn
+    smb_structs.SUPPORT_SMB2 = True
+    smb_structs.SUPPORT_SMB2x = False
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2x():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = True
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def teardown_func():
+    global conn
+    conn.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_listshares_SMB1():
+    global conn
+    results = conn.listShares()
+    assert 'smbtest' in map(lambda r: r.name.lower(), results)
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_listshares_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+    results = conn.listShares()
+    assert 'smbtest' in map(lambda r: r.name.lower(), results)
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_listshares_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+    results = conn.listShares()
+    assert 'smbtest' in map(lambda r: r.name.lower(), results)
diff --git a/python2/tests/DirectSMBConnectionTests/test_listsnapshots.py b/python2/tests/DirectSMBConnectionTests/test_listsnapshots.py
new file mode 100644
index 00000000..ba1890e0
--- /dev/null
+++ b/python2/tests/DirectSMBConnectionTests/test_listsnapshots.py
@@ -0,0 +1,37 @@
+
+from smb.SMBConnection import SMBConnection
+from util import getConnectionInfo
+from nose.tools import with_setup
+from smb import smb_structs
+
+conn = None
+
+def setup_func_SMB1():
+    global conn
+    smb_structs.SUPPORT_SMB2 = False
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2():
+    global conn
+    smb_structs.SUPPORT_SMB2 = True
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def teardown_func():
+    global conn
+    conn.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_listsnapshots_SMB1():
+    global conn
+    results = conn.listSnapshots('smbtest', '/rfc1001.txt')
+    assert len(results) > 0
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_listsnapshots_SMB2():
+    global conn
+    results = conn.listSnapshots('smbtest', '/rfc1001.txt')
+    assert len(results) > 0
diff --git a/python2/tests/DirectSMBConnectionTests/test_rename.py b/python2/tests/DirectSMBConnectionTests/test_rename.py
new file mode 100644
index 00000000..677600ec
--- /dev/null
+++ b/python2/tests/DirectSMBConnectionTests/test_rename.py
@@ -0,0 +1,321 @@
+# -*- coding: utf-8 -*-
+
+import os, time, random
+from StringIO import StringIO
+from smb.SMBConnection import SMBConnection
+from smb.smb2_constants import SMB2_DIALECT_2
+from util import getConnectionInfo
+from nose.tools import with_setup
+from smb import smb_structs
+
+conn = None
+
+def setup_func_SMB1():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = False
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2():
+    global conn
+    smb_structs.SUPPORT_SMB2 = True
+    smb_structs.SUPPORT_SMB2x = False
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2x():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = True
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def teardown_func():
+    global conn
+    conn.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_rename_english_file_SMB1():
+    global conn
+
+    old_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    new_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.storeFile('smbtest', old_path, StringIO('Rename file test'))
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteFiles('smbtest', new_path)
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_rename_english_file_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    old_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    new_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.storeFile('smbtest', old_path, StringIO('Rename file test'))
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteFiles('smbtest', new_path)
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_rename_english_file_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    old_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    new_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.storeFile('smbtest', old_path, StringIO('Rename file test'))
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteFiles('smbtest', new_path)
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_rename_unicode_file_SMB1():
+    global conn
+
+    old_path = u'/改名测试 %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    new_path = u'/改名测试 %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.storeFile('smbtest', old_path, StringIO('Rename file test'))
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteFiles('smbtest', new_path)
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_rename_unicode_file_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    old_path = u'/改名测试 %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    new_path = u'/改名测试 %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.storeFile('smbtest', old_path, StringIO('Rename file test'))
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteFiles('smbtest', new_path)
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_rename_unicode_file_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    old_path = u'/改名测试 %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    new_path = u'/改名测试 %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.storeFile('smbtest', old_path, StringIO('Rename file test'))
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteFiles('smbtest', new_path)
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_rename_english_directory_SMB1():
+    global conn
+
+    old_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    new_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.createDirectory('smbtest', old_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteDirectory('smbtest', new_path)
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_rename_english_directory_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    old_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    new_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.createDirectory('smbtest', old_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteDirectory('smbtest', new_path)
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_rename_english_directory_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    old_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    new_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.createDirectory('smbtest', old_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteDirectory('smbtest', new_path)
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_rename_unicode_directory_SMB1():
+    global conn
+
+    old_path = u'/改名测试 %d-%d' % ( time.time(), random.randint(1000, 9999) )
+    new_path = u'/改名测试 %d-%d' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.createDirectory('smbtest', old_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteDirectory('smbtest', new_path)
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_rename_unicode_directory_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    old_path = u'/改名测试 %d-%d' % ( time.time(), random.randint(1000, 9999) )
+    new_path = u'/改名测试 %d-%d' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.createDirectory('smbtest', old_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteDirectory('smbtest', new_path)
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_rename_unicode_directory_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    old_path = u'/改名测试 %d-%d' % ( time.time(), random.randint(1000, 9999) )
+    new_path = u'/改名测试 %d-%d' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.createDirectory('smbtest', old_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteDirectory('smbtest', new_path)
diff --git a/python2/tests/DirectSMBConnectionTests/test_retrievefile.py b/python2/tests/DirectSMBConnectionTests/test_retrievefile.py
new file mode 100644
index 00000000..138d2950
--- /dev/null
+++ b/python2/tests/DirectSMBConnectionTests/test_retrievefile.py
@@ -0,0 +1,369 @@
+# -*- coding: utf-8 -*-
+
+import os, tempfile
+from StringIO import StringIO
+from smb.SMBConnection import SMBConnection
+from smb.smb2_constants import SMB2_DIALECT_2
+from util import getConnectionInfo
+from nose.tools import with_setup
+from smb import smb_structs
+
+try:
+    import hashlib
+    def MD5(): return hashlib.md5()
+except ImportError:
+    import md5
+    def MD5(): return md5.new()
+
+conn = None
+
+def setup_func_SMB1():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = False
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2():
+    global conn
+    smb_structs.SUPPORT_SMB2 = True
+    smb_structs.SUPPORT_SMB2x = False
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2x():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = True
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def teardown_func():
+    global conn
+    conn.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_retr_multiplereads_SMB1():
+    # Test file retrieval using multiple ReadAndx calls (assuming each call will not reach more than 65534 bytes)
+    global conn
+    temp_fh = StringIO()
+    file_attributes, filesize = conn.retrieveFile('smbtest', '/rfc1001.txt', temp_fh)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '5367c2bbf97f521059c78eab65309ad3'
+    assert filesize == 158437
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_retr_multiplereads_SMB2():
+    # Test file retrieval using multiple ReadAndx calls (assuming each call will not reach more than 65534 bytes)
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    temp_fh = StringIO()
+    file_attributes, filesize = conn.retrieveFile('smbtest', '/rfc1001.txt', temp_fh)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '5367c2bbf97f521059c78eab65309ad3'
+    assert filesize == 158437
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_retr_multiplereads_SMB2x():
+    # Test file retrieval using multiple ReadAndx calls (assuming each call will not reach more than 65534 bytes)
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    temp_fh = StringIO()
+    file_attributes, filesize = conn.retrieveFile('smbtest', '/rfc1001.txt', temp_fh)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '5367c2bbf97f521059c78eab65309ad3'
+    assert filesize == 158437
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_retr_longfilename_SMB1():
+    # Test file retrieval that has a long English filename
+    global conn
+    temp_fh = StringIO()
+    file_attributes, filesize = conn.retrieveFile('smbtest', '/Implementing CIFS - SMB.html', temp_fh)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '671c5700d279fcbbf958c1bba3c2639e'
+    assert filesize == 421269
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_retr_longfilename_SMB2():
+    # Test file retrieval that has a long English filename
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    temp_fh = StringIO()
+    file_attributes, filesize = conn.retrieveFile('smbtest', '/Implementing CIFS - SMB.html', temp_fh)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '671c5700d279fcbbf958c1bba3c2639e'
+    assert filesize == 421269
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_retr_longfilename_SMB2x():
+    # Test file retrieval that has a long English filename
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    temp_fh = StringIO()
+    file_attributes, filesize = conn.retrieveFile('smbtest', '/Implementing CIFS - SMB.html', temp_fh)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '671c5700d279fcbbf958c1bba3c2639e'
+    assert filesize == 421269
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_retr_unicodefilename_SMB1():
+    # Test file retrieval that has a long non-English filename inside a folder with a non-English name
+    global conn
+    temp_fh = StringIO()
+    file_attributes, filesize = conn.retrieveFile('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '8a44c1e80d55e91c92350955cdf83442'
+    assert filesize == 256000
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_retr_unicodefilename_SMB2():
+    # Test file retrieval that has a long non-English filename inside a folder with a non-English name
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    temp_fh = StringIO()
+    file_attributes, filesize = conn.retrieveFile('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '8a44c1e80d55e91c92350955cdf83442'
+    assert filesize == 256000
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_retr_unicodefilename_SMB2x():
+    # Test file retrieval that has a long non-English filename inside a folder with a non-English name
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    temp_fh = StringIO()
+    file_attributes, filesize = conn.retrieveFile('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '8a44c1e80d55e91c92350955cdf83442'
+    assert filesize == 256000
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_retr_offset_SMB1():
+    # Test file retrieval from offset to EOF
+    global conn
+    temp_fh = StringIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == 'a141bd8024571ce7cb5c67f2b0d8ea0b'
+    assert filesize == 156000
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_retr_offset_SMB2():
+    # Test file retrieval from offset to EOF
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    temp_fh = StringIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == 'a141bd8024571ce7cb5c67f2b0d8ea0b'
+    assert filesize == 156000
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_retr_offset_SMB2x():
+    # Test file retrieval from offset to EOF
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    temp_fh = StringIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == 'a141bd8024571ce7cb5c67f2b0d8ea0b'
+    assert filesize == 156000
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_retr_offset_and_biglimit_SMB1():
+    # Test file retrieval from offset with a big max_length
+    global conn
+    temp_fh = StringIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000, max_length = 100000)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '83b7afd7c92cdece3975338b5ca0b1c5'
+    assert filesize == 100000
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_retr_offset_and_biglimit_SMB2():
+    # Test file retrieval from offset with a big max_length
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    temp_fh = StringIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000, max_length = 100000)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '83b7afd7c92cdece3975338b5ca0b1c5'
+    assert filesize == 100000
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_retr_offset_and_biglimit_SMB2x():
+    # Test file retrieval from offset with a big max_length
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    temp_fh = StringIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000, max_length = 100000)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '83b7afd7c92cdece3975338b5ca0b1c5'
+    assert filesize == 100000
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_retr_offset_and_smalllimit_SMB1():
+    # Test file retrieval from offset with a small max_length
+    global conn
+    temp_fh = StringIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000, max_length = 10)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '746f60a96b39b712a7b6e17ddde19986'
+    assert filesize == 10
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_retr_offset_and_smalllimit_SMB2():
+    # Test file retrieval from offset with a small max_length
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    temp_fh = StringIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000, max_length = 10)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '746f60a96b39b712a7b6e17ddde19986'
+    assert filesize == 10
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_retr_offset_and_smalllimit_SMB2x():
+    # Test file retrieval from offset with a small max_length
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    temp_fh = StringIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000, max_length = 10)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '746f60a96b39b712a7b6e17ddde19986'
+    assert filesize == 10
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_retr_offset_and_zerolimit_SMB1():
+    # Test file retrieval from offset to EOF with max_length=0
+    global conn
+    temp_fh = StringIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000, max_length = 0)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == 'd41d8cd98f00b204e9800998ecf8427e'
+    assert filesize == 0
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_retr_offset_and_zerolimit_SMB2():
+    # Test file retrieval from offset to EOF with max_length=0
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    temp_fh = StringIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000, max_length = 0)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == 'd41d8cd98f00b204e9800998ecf8427e'
+    assert filesize == 0
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_retr_offset_and_zerolimit_SMB2x():
+    # Test file retrieval from offset to EOF with max_length=0
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    temp_fh = StringIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000, max_length = 0)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == 'd41d8cd98f00b204e9800998ecf8427e'
+    assert filesize == 0
+
+    temp_fh.close()
diff --git a/python2/tests/DirectSMBConnectionTests/test_storefile.py b/python2/tests/DirectSMBConnectionTests/test_storefile.py
new file mode 100644
index 00000000..34b58b03
--- /dev/null
+++ b/python2/tests/DirectSMBConnectionTests/test_storefile.py
@@ -0,0 +1,269 @@
+# -*- coding: utf-8 -*-
+
+import os, tempfile, random, time
+from StringIO import StringIO
+from smb.SMBConnection import SMBConnection
+from smb.smb2_constants import SMB2_DIALECT_2
+from util import getConnectionInfo
+from nose.tools import with_setup
+from smb import smb_structs
+
+try:
+    import hashlib
+    def MD5(): return hashlib.md5()
+except ImportError:
+    import md5
+    def MD5(): return md5.new()
+
+conn = None
+
+TEST_FILENAME = os.path.join(os.path.dirname(__file__), os.pardir, 'SupportFiles', 'binary.dat')
+TEST_FILESIZE = 256000
+TEST_DIGEST = 'bb6303f76e29f354b6fdf6ef58587e48'
+
+def setup_func_SMB1():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = False
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2():
+    global conn
+    smb_structs.SUPPORT_SMB2 = True
+    smb_structs.SUPPORT_SMB2x = False
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2x():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = True
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def teardown_func():
+    global conn
+    conn.close()
+
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_store_long_filename_SMB1():
+    global conn
+    filename = os.sep + 'StoreTest %d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+
+    filesize = conn.storeFile('smbtest', filename, open(TEST_FILENAME, 'rb'))
+    assert filesize == TEST_FILESIZE
+
+    entries = conn.listPath('smbtest', os.path.dirname(filename.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(filename.replace('/', os.sep)) in filenames
+
+    buf = StringIO()
+    file_attributes, file_size = conn.retrieveFile('smbtest', filename, buf)
+    assert file_size == TEST_FILESIZE
+
+    md = MD5()
+    md.update(buf.getvalue())
+    assert md.hexdigest() == TEST_DIGEST
+    buf.close()
+
+    conn.deleteFiles('smbtest', filename)
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_store_from_offset_SMB1():
+    global conn
+    filename = os.sep + 'StoreTest %d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+
+    buf = StringIO('0123456789')
+    filesize = conn.storeFile('smbtest', filename, buf)
+    assert filesize == 10
+
+    buf = StringIO('aa')
+    pos = conn.storeFileFromOffset('smbtest', filename, buf, 5)
+    assert pos == 7
+
+    buf = StringIO()
+    file_attributes, file_size = conn.retrieveFile('smbtest', filename, buf)
+    assert file_size == 10
+    assert buf.getvalue() == '01234aa789'
+    buf.close()
+
+    conn.deleteFiles('smbtest', filename)
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_store_long_filename_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    filename = os.sep + 'StoreTest %d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+
+    filesize = conn.storeFile('smbtest', filename, open(TEST_FILENAME, 'rb'))
+    assert filesize == TEST_FILESIZE
+
+    entries = conn.listPath('smbtest', os.path.dirname(filename.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(filename.replace('/', os.sep)) in filenames
+
+    buf = StringIO()
+    file_attributes, file_size = conn.retrieveFile('smbtest', filename, buf)
+    assert file_size == TEST_FILESIZE
+
+    md = MD5()
+    md.update(buf.getvalue())
+    assert md.hexdigest() == TEST_DIGEST
+    buf.close()
+
+    conn.deleteFiles('smbtest', filename)
+
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_store_long_filename_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    filename = os.sep + 'StoreTest %d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+
+    filesize = conn.storeFile('smbtest', filename, open(TEST_FILENAME, 'rb'))
+    assert filesize == TEST_FILESIZE
+
+    entries = conn.listPath('smbtest', os.path.dirname(filename.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(filename.replace('/', os.sep)) in filenames
+
+    buf = StringIO()
+    file_attributes, file_size = conn.retrieveFile('smbtest', filename, buf)
+    assert file_size == TEST_FILESIZE
+
+    md = MD5()
+    md.update(buf.getvalue())
+    assert md.hexdigest() == TEST_DIGEST
+    buf.close()
+
+    conn.deleteFiles('smbtest', filename)
+
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_store_unicode_filename_SMB1():
+    global conn
+    filename = os.sep + u'上载测试 %d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+
+    filesize = conn.storeFile('smbtest', filename, open(TEST_FILENAME, 'rb'))
+    assert filesize == TEST_FILESIZE
+
+    entries = conn.listPath('smbtest', os.path.dirname(filename.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(filename.replace('/', os.sep)) in filenames
+
+    buf = StringIO()
+    file_attributes, file_size = conn.retrieveFile('smbtest', filename, buf)
+    assert file_size == TEST_FILESIZE
+
+    md = MD5()
+    md.update(buf.getvalue())
+    assert md.hexdigest() == TEST_DIGEST
+    buf.close()
+
+    conn.deleteFiles('smbtest', filename)
+
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_store_unicode_filename_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    filename = os.sep + u'上载测试 %d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+
+    filesize = conn.storeFile('smbtest', filename, open(TEST_FILENAME, 'rb'))
+    assert filesize == TEST_FILESIZE
+
+    entries = conn.listPath('smbtest', os.path.dirname(filename.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(filename.replace('/', os.sep)) in filenames
+
+    buf = StringIO()
+    file_attributes, file_size = conn.retrieveFile('smbtest', filename, buf)
+    assert file_size == TEST_FILESIZE
+
+    md = MD5()
+    md.update(buf.getvalue())
+    assert md.hexdigest() == TEST_DIGEST
+    buf.close()
+
+    conn.deleteFiles('smbtest', filename)
+
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_store_unicode_filename_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    filename = os.sep + u'上载测试 %d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+
+    filesize = conn.storeFile('smbtest', filename, open(TEST_FILENAME, 'rb'))
+    assert filesize == TEST_FILESIZE
+
+    entries = conn.listPath('smbtest', os.path.dirname(filename.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(filename.replace('/', os.sep)) in filenames
+
+    buf = StringIO()
+    file_attributes, file_size = conn.retrieveFile('smbtest', filename, buf)
+    assert file_size == TEST_FILESIZE
+
+    md = MD5()
+    md.update(buf.getvalue())
+    assert md.hexdigest() == TEST_DIGEST
+    buf.close()
+
+    conn.deleteFiles('smbtest', filename)
+
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_store_from_offset_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    filename = os.sep + 'StoreTest %d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+
+    buf = StringIO('0123456789')
+    filesize = conn.storeFile('smbtest', filename, buf)
+    assert filesize == 10
+
+    buf = StringIO('aa')
+    pos = conn.storeFileFromOffset('smbtest', filename, buf, 5)
+    assert pos == 7
+
+    buf = StringIO()
+    file_attributes, file_size = conn.retrieveFile('smbtest', filename, buf)
+    assert file_size == 10
+    assert buf.getvalue() == '01234aa789'
+    buf.close()
+
+    conn.deleteFiles('smbtest', filename)
+
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_store_from_offset_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    filename = os.sep + 'StoreTest %d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+
+    buf = StringIO('0123456789')
+    filesize = conn.storeFile('smbtest', filename, buf)
+    assert filesize == 10
+
+    buf = StringIO('aa')
+    pos = conn.storeFileFromOffset('smbtest', filename, buf, 5)
+    print(pos)
+    assert pos == 7
+
+    buf = StringIO()
+    file_attributes, file_size = conn.retrieveFile('smbtest', filename, buf)
+    assert file_size == 10
+    assert buf.getvalue() == '01234aa789'
+    buf.close()
+
+    conn.deleteFiles('smbtest', filename)
diff --git a/python2/tests/DirectSMBConnectionTests/util.py b/python2/tests/DirectSMBConnectionTests/util.py
new file mode 100644
index 00000000..12f82afa
--- /dev/null
+++ b/python2/tests/DirectSMBConnectionTests/util.py
@@ -0,0 +1,19 @@
+
+import os
+from ConfigParser import SafeConfigParser
+
+def getConnectionInfo():
+    config_filename = os.path.join(os.path.dirname(__file__), os.path.pardir, 'connection.ini')
+    cp = SafeConfigParser()
+    cp.read(config_filename)
+
+    info = {
+        'server_name': cp.get('server', 'name'),
+        'server_ip': cp.get('server', 'ip'),
+        'server_port': cp.getint('server', 'direct_port'),
+        'client_name': cp.get('client', 'name'),
+        'user': cp.get('user', 'name'),
+        'password': cp.get('user', 'password'),
+        'is_direct_tcp': True,
+    }
+    return info
diff --git a/python2/tests/DirectSMBTwistedTests/test_auth.py b/python2/tests/DirectSMBTwistedTests/test_auth.py
new file mode 100644
index 00000000..1e3e09c9
--- /dev/null
+++ b/python2/tests/DirectSMBTwistedTests/test_auth.py
@@ -0,0 +1,77 @@
+
+from nose.twistedtools import reactor, deferred
+from twisted.internet import defer
+from smb.SMBProtocol import SMBProtocolFactory
+from smb import smb_structs
+from util import getConnectionInfo
+
+
+class AuthFactory(SMBProtocolFactory):
+
+    def __init__(self, *args, **kwargs):
+        SMBProtocolFactory.__init__(self, *args, **kwargs)
+        self.d = defer.Deferred()
+        self.d.addBoth(self.testDone)
+
+    def testDone(self, r):
+        if self.instance:
+            self.instance.transport.loseConnection()
+        return r
+
+    def onAuthOK(self):
+        self.d.callback(True)
+
+    def onAuthFailed(self):
+        self.d.callback(False)
+
+
+@deferred(timeout=5.0)
+def test_NTLMv1_auth_SMB1():
+    def result(auth_passed):
+        assert auth_passed
+
+    smb_structs.SUPPORT_SMB2 = False
+    info = getConnectionInfo()
+    factory = AuthFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = False)
+    factory.d.addCallback(result)
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+
+@deferred(timeout=5.0)
+def test_NTLMv2_auth_SMB1():
+    def result(auth_passed):
+        assert auth_passed
+
+    smb_structs.SUPPORT_SMB2 = False
+    info = getConnectionInfo()
+    factory = AuthFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.d.addCallback(result)
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+
+@deferred(timeout=5.0)
+def test_NTLMv1_auth_SMB2():
+    def result(auth_passed):
+        assert auth_passed
+
+    smb_structs.SUPPORT_SMB2 = True
+    info = getConnectionInfo()
+    factory = AuthFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = False)
+    factory.d.addCallback(result)
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+
+@deferred(timeout=5.0)
+def test_NTLMv2_auth_SMB2():
+    def result(auth_passed):
+        assert auth_passed
+
+    smb_structs.SUPPORT_SMB2 = True
+    info = getConnectionInfo()
+    factory = AuthFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.d.addCallback(result)
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
diff --git a/python2/tests/DirectSMBTwistedTests/test_createdeletedirectory.py b/python2/tests/DirectSMBTwistedTests/test_createdeletedirectory.py
new file mode 100644
index 00000000..508f43c6
--- /dev/null
+++ b/python2/tests/DirectSMBTwistedTests/test_createdeletedirectory.py
@@ -0,0 +1,99 @@
+# -*- coding: utf-8 -*-
+
+import os, random, time
+from nose.twistedtools import reactor, deferred
+from twisted.internet import defer
+from smb.SMBProtocol import SMBProtocolFactory
+from smb import smb_structs
+from util import getConnectionInfo
+
+
+class DirectoryFactory(SMBProtocolFactory):
+
+    def __init__(self, *args, **kwargs):
+        SMBProtocolFactory.__init__(self, *args, **kwargs)
+        self.d = defer.Deferred()
+        self.d.addBoth(self.testDone)
+        self.service_name = ''
+        self.path = ''
+
+    def testDone(self, r):
+        if self.instance:
+            self.instance.transport.loseConnection()
+        return r
+
+    def createDone(self, result):
+        d = self.listPath(self.service_name, os.path.dirname(self.path.replace('/', os.sep)))
+        d.addCallback(self.listComplete)
+        d.addErrback(self.d.errback)
+
+    def listComplete(self, entries):
+        names = map(lambda e: e.filename, entries)
+        assert os.path.basename(self.path.replace('/', os.sep)) in names
+
+        d = self.deleteDirectory(self.service_name, self.path)
+        d.addCallback(self.deleteDone)
+        d.addErrback(self.d.errback)
+
+    def deleteDone(self, result):
+        d = self.listPath(self.service_name, os.path.dirname(self.path.replace('/', os.sep)))
+        d.addCallback(self.list2Complete)
+        d.addErrback(self.d.errback)
+
+    def list2Complete(self, entries):
+        names = map(lambda e: e.filename, entries)
+        assert os.path.basename(self.path.replace('/', os.sep)) not in names
+        self.d.callback(True)
+
+    def onAuthOK(self):
+        d = self.createDirectory(self.service_name, self.path)
+        d.addCallback(self.createDone)
+        d.addErrback(self.d.errback)
+
+    def onAuthFailed(self):
+        self.d.errback('Auth failed')
+
+
+@deferred(timeout=15.0)
+def test_english_directory_SMB1():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = False
+
+    factory = DirectoryFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service_name = 'smbtest'
+    factory.path = os.sep + 'TestDir %d-%d' % ( time.time(), random.randint(0, 1000) )
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=15.0)
+def test_english_directory_SMB2():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = True
+
+    factory = DirectoryFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service_name = 'smbtest'
+    factory.path = os.sep + 'TestDir %d-%d' % ( time.time(), random.randint(0, 1000) )
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=15.0)
+def test_unicode_directory_SMB1():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = False
+
+    factory = DirectoryFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service_name = 'smbtest'
+    factory.path = os.sep + u'文件夹创建 %d-%d' % ( time.time(), random.randint(0, 1000) )
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=15.0)
+def test_unicode_directory_SMB2():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = True
+
+    factory = DirectoryFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service_name = 'smbtest'
+    factory.path = os.sep + u'文件夹创建 %d-%d' % ( time.time(), random.randint(0, 1000) )
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
diff --git a/python2/tests/DirectSMBTwistedTests/test_echo.py b/python2/tests/DirectSMBTwistedTests/test_echo.py
new file mode 100644
index 00000000..a60bad98
--- /dev/null
+++ b/python2/tests/DirectSMBTwistedTests/test_echo.py
@@ -0,0 +1,39 @@
+
+from nose.twistedtools import reactor, deferred
+from twisted.internet import defer
+from smb.SMBProtocol import SMBProtocolFactory
+from util import getConnectionInfo
+
+
+class EchoFactory(SMBProtocolFactory):
+
+    def __init__(self, *args, **kwargs):
+        SMBProtocolFactory.__init__(self, *args, **kwargs)
+        self.d = defer.Deferred()
+        self.d.addBoth(self.testDone)
+        self.echo_data = 'This is an echo test'
+
+    def testDone(self, r):
+        if self.instance:
+            self.instance.transport.loseConnection()
+        return r
+
+    def onAuthOK(self):
+        def cb(data):
+            assert data == self.echo_data
+            self.d.callback(True)
+
+        d = self.echo(self.echo_data)
+        d.addCallback(cb)
+        d.addErrback(self.d.errback)
+
+    def onAuthFailed(self):
+        self.d.errback('Auth failed')
+
+
+@deferred(timeout=15.0)
+def test_echo():
+    info = getConnectionInfo()
+    factory = EchoFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
diff --git a/python2/tests/DirectSMBTwistedTests/test_listpath.py b/python2/tests/DirectSMBTwistedTests/test_listpath.py
new file mode 100644
index 00000000..d00aebd5
--- /dev/null
+++ b/python2/tests/DirectSMBTwistedTests/test_listpath.py
@@ -0,0 +1,56 @@
+
+from nose.twistedtools import reactor, deferred
+from twisted.internet import defer
+from smb.SMBProtocol import SMBProtocolFactory
+from smb import smb_structs
+from util import getConnectionInfo
+
+
+class ListPathFactory(SMBProtocolFactory):
+
+    def __init__(self, *args, **kwargs):
+        SMBProtocolFactory.__init__(self, *args, **kwargs)
+        self.d = defer.Deferred()
+        self.d.addBoth(self.testDone)
+
+    def testDone(self, r):
+        if self.instance:
+            self.instance.transport.loseConnection()
+        return r
+
+    def onAuthOK(self):
+        def cb(results):
+            filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+            assert ( u'\u6d4b\u8bd5\u6587\u4ef6\u5939', True ) in filenames  # Test non-English folder names
+            assert ( u'Test Folder with Long Name', True ) in filenames      # Test long English folder names
+            assert ( u'TestDir1', True ) in filenames                        # Test short English folder names
+            assert ( u'Implementing CIFS - SMB.html', False ) in filenames   # Test long English file names
+            assert ( u'rfc1001.txt', False ) in filenames                    # Test short English file names
+
+            self.d.callback(True)
+
+        d = self.listPath('smbtest', '/', timeout = 15)
+        d.addCallback(cb)
+        d.addErrback(self.d.errback)
+
+    def onAuthFailed(self):
+        self.d.errback('Auth failed')
+
+
+@deferred(timeout=15.0)
+def test_listPath_SMB1():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = False
+
+    factory = ListPathFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=15.0)
+def test_listPath_SMB2():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = True
+
+    factory = ListPathFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
diff --git a/python2/tests/DirectSMBTwistedTests/test_listshares.py b/python2/tests/DirectSMBTwistedTests/test_listshares.py
new file mode 100644
index 00000000..a787ab21
--- /dev/null
+++ b/python2/tests/DirectSMBTwistedTests/test_listshares.py
@@ -0,0 +1,51 @@
+
+from nose.twistedtools import reactor, deferred
+from twisted.internet import defer
+from smb.SMBProtocol import SMBProtocolFactory
+from smb import smb_structs
+from util import getConnectionInfo
+
+
+class ListSharesFactory(SMBProtocolFactory):
+
+    def __init__(self, *args, **kwargs):
+        SMBProtocolFactory.__init__(self, *args, **kwargs)
+        self.d = defer.Deferred()
+        self.d.addBoth(self.testDone)
+
+    def testDone(self, r):
+        if self.instance:
+            self.instance.transport.loseConnection()
+        return r
+
+    def onAuthOK(self):
+        def cb(results):
+            assert 'smbtest' in map(lambda r: r.name.lower(), results)
+            self.d.callback(True)
+            self.instance.transport.loseConnection()
+
+        d = self.listShares(timeout = 15)
+        d.addCallback(cb)
+        d.addErrback(self.d.errback)
+
+    def onAuthFailed(self):
+        self.d.errback('Auth failed')
+
+
+@deferred(timeout=15.0)
+def test_listshares_SMB1():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = False
+
+    factory = ListSharesFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=15.0)
+def test_listshares_SMB2():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = True
+
+    factory = ListSharesFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
diff --git a/python2/tests/DirectSMBTwistedTests/test_listsnapshots.py b/python2/tests/DirectSMBTwistedTests/test_listsnapshots.py
new file mode 100644
index 00000000..339599a7
--- /dev/null
+++ b/python2/tests/DirectSMBTwistedTests/test_listsnapshots.py
@@ -0,0 +1,57 @@
+
+from nose.twistedtools import reactor, deferred
+from twisted.internet import defer
+from smb.SMBProtocol import SMBProtocolFactory
+from smb import smb_structs
+from util import getConnectionInfo
+
+
+class ListSnapshotsFactory(SMBProtocolFactory):
+
+    def __init__(self, *args, **kwargs):
+        SMBProtocolFactory.__init__(self, *args, **kwargs)
+        self.d = defer.Deferred()
+        self.d.addBoth(self.testDone)
+        self.service_name = None
+        self.path = None
+
+    def testDone(self, r):
+        if self.instance:
+            self.instance.transport.loseConnection()
+        return r
+
+    def onAuthOK(self):
+        def cb(results):
+            assert len(results) > 0
+            self.d.callback(True)
+            self.instance.transport.loseConnection()
+
+        d = self.listSnapshots(self.service_name, self.path, timeout = 15)
+        d.addCallback(cb)
+        d.addErrback(self.d.errback)
+
+    def onAuthFailed(self):
+        self.d.errback('Auth failed')
+
+
+@deferred(timeout=15.0)
+def test_listshares_SMB1():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = False
+
+    factory = ListSnapshotsFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service_name = 'smbtest'
+    factory.path = '/rfc1001.txt'
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=15.0)
+def test_listshares_SMB2():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = True
+
+    factory = ListSnapshotsFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service_name = 'smbtest'
+    factory.path = '/rfc1001.txt'
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
diff --git a/python2/tests/DirectSMBTwistedTests/test_rename.py b/python2/tests/DirectSMBTwistedTests/test_rename.py
new file mode 100644
index 00000000..3e5d80b6
--- /dev/null
+++ b/python2/tests/DirectSMBTwistedTests/test_rename.py
@@ -0,0 +1,174 @@
+# -*- coding: utf-8 -*-
+
+import os, random, time
+from StringIO import StringIO
+from nose.twistedtools import reactor, deferred
+from twisted.internet import defer
+from smb.SMBProtocol import SMBProtocolFactory
+from smb import smb_structs
+from util import getConnectionInfo
+
+
+class RenameFactory(SMBProtocolFactory):
+
+    def __init__(self, *args, **kwargs):
+        SMBProtocolFactory.__init__(self, *args, **kwargs)
+        self.d = defer.Deferred()
+        self.d.addBoth(self.testDone)
+        self.service = ''
+        self.new_path = ''
+        self.old_path = ''
+
+    def testDone(self, r):
+        if self.instance:
+            self.instance.transport.loseConnection()
+        return r
+
+    def pathCreated(self, result):
+        d = self.listPath(self.service, os.path.dirname(self.old_path.replace('/', os.sep)))
+        d.addCallback(self.listComplete)
+        d.addErrback(self.d.errback)
+
+    def listComplete(self, entries):
+        filenames = map(lambda e: e.filename, entries)
+        assert os.path.basename(self.old_path.replace('/', os.sep)) in filenames
+        assert os.path.basename(self.new_path.replace('/', os.sep)) not in filenames
+
+        d = self.rename(self.service, self.old_path, self.new_path)
+        d.addCallback(self.renameComplete)
+        d.addErrback(self.d.errback)
+
+    def renameComplete(self, result):
+        d = self.listPath(self.service, os.path.dirname(self.new_path.replace('/', os.sep)))
+        d.addCallback(self.list2Complete)
+        d.addErrback(self.d.errback)
+
+    def list2Complete(self, entries):
+        filenames = map(lambda e: e.filename, entries)
+        assert os.path.basename(self.new_path.replace('/', os.sep)) in filenames
+        assert os.path.basename(self.old_path.replace('/', os.sep)) not in filenames
+        self.cleanup()
+
+    def onAuthFailed(self):
+        self.d.errback('Auth failed')
+
+
+class RenameFileFactory(RenameFactory):
+
+    def onAuthOK(self):
+        d = self.storeFile(self.service, self.old_path, StringIO('Rename file test'))
+        d.addCallback(self.pathCreated)
+        d.addErrback(self.d.errback)
+
+    def cleanup(self):
+        d = self.deleteFiles(self.service, self.new_path)
+        d.chainDeferred(self.d)
+
+
+class RenameDirectoryFactory(RenameFactory):
+
+    def onAuthOK(self):
+        d = self.createDirectory(self.service, self.old_path)
+        d.addCallback(self.pathCreated)
+        d.addErrback(self.d.errback)
+
+    def cleanup(self):
+        d = self.deleteDirectory(self.service, self.new_path)
+        d.chainDeferred(self.d)
+
+
+@deferred(timeout=30.0)
+def test_rename_english_file_SMB1():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = False
+
+    factory = RenameFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.old_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    factory.new_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_rename_english_file_SMB2():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = True
+
+    factory = RenameFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.old_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    factory.new_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_rename_unicode_file_SMB1():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = False
+
+    factory = RenameFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.old_path = u'/改名测试 %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    factory.new_path = u'/改名测试 %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_rename_unicode_file_SMB2():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = True
+
+    factory = RenameFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.old_path = u'/改名测试 %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    factory.new_path = u'/改名测试 %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_rename_english_directory_SMB1():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = False
+
+    factory = RenameDirectoryFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.old_path = '/RenameTest %d-%d' % ( time.time(), random.randint(1000, 9999) )
+    factory.new_path = '/RenameTest %d-%d' % ( time.time(), random.randint(1000, 9999) )
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_rename_english_directory_SMB2():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = True
+
+    factory = RenameDirectoryFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.old_path = '/RenameTest %d-%d' % ( time.time(), random.randint(1000, 9999) )
+    factory.new_path = '/RenameTest %d-%d' % ( time.time(), random.randint(1000, 9999) )
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_rename_unicode_directory_SMB1():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = False
+
+    factory = RenameDirectoryFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.old_path = u'/改名测试 %d-%d' % ( time.time(), random.randint(1000, 9999) )
+    factory.new_path = u'/改名测试 %d-%d' % ( time.time(), random.randint(1000, 9999) )
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_rename_unicode_directory_SMB2():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = True
+
+    factory = RenameDirectoryFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.old_path = u'/改名测试 %d-%d' % ( time.time(), random.randint(1000, 9999) )
+    factory.new_path = u'/改名测试 %d-%d' % ( time.time(), random.randint(1000, 9999) )
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
diff --git a/python2/tests/DirectSMBTwistedTests/test_retrievefile.py b/python2/tests/DirectSMBTwistedTests/test_retrievefile.py
new file mode 100644
index 00000000..476f09ae
--- /dev/null
+++ b/python2/tests/DirectSMBTwistedTests/test_retrievefile.py
@@ -0,0 +1,278 @@
+# -*- coding: utf-8 -*-
+
+import os, tempfile
+from nose.twistedtools import reactor, deferred
+from twisted.internet import defer
+from smb.SMBProtocol import SMBProtocolFactory
+from smb import smb_structs
+from util import getConnectionInfo
+
+try:
+    import hashlib
+    def MD5(): return hashlib.md5()
+except ImportError:
+    import md5
+    def MD5(): return md5.new()
+
+
+class RetrieveFileFactory(SMBProtocolFactory):
+
+    def __init__(self, *args, **kwargs):
+        SMBProtocolFactory.__init__(self, *args, **kwargs)
+        self.d = defer.Deferred()
+        self.d.addBoth(self.testDone)
+        self.temp_fh = tempfile.NamedTemporaryFile(prefix = 'pysmbtest-')
+        self.service = ''
+        self.path = ''
+        self.digest = ''
+        self.offset = 0
+        self.max_length = -1
+        self.filesize = 0
+
+    def testDone(self, r):
+        if self.instance:
+            self.instance.transport.loseConnection()
+        return r
+
+    def fileRetrieved(self, write_result):
+        file_obj, file_attributes, file_size = write_result
+        assert file_obj == self.temp_fh
+
+        md = MD5()
+        filesize = 0
+        self.temp_fh.seek(0)
+        while True:
+            s = self.temp_fh.read(8192)
+            if not s:
+                break
+            md.update(s)
+            filesize += len(s)
+
+        assert self.filesize == filesize
+        assert md.hexdigest() == self.digest
+
+        self.temp_fh.close()
+        self.d.callback(True)
+        self.instance.transport.loseConnection()
+
+    def onAuthOK(self):
+        assert self.service
+        assert self.path
+
+        d = self.retrieveFileFromOffset(self.service, self.path, self.temp_fh, self.offset, self.max_length, timeout = 15)
+        d.addCallback(self.fileRetrieved)
+        d.addErrback(self.d.errback)
+
+    def onAuthFailed(self):
+        self.d.errback('Auth failed')
+
+
+@deferred(timeout=30.0)
+def test_retr_multiplereads_SMB1():
+    # Test file retrieval using multiple ReadAndx calls (assuming each call will not reach more than 65534 bytes)
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = False
+
+    factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.path = '/rfc1001.txt'
+    factory.digest = '5367c2bbf97f521059c78eab65309ad3'
+    factory.filesize = 158437
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_retr_multiplereads_SMB2():
+    # Test file retrieval using multiple ReadAndx calls (assuming each call will not reach more than 65534 bytes)
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = True
+
+    factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.path = '/rfc1001.txt'
+    factory.digest = '5367c2bbf97f521059c78eab65309ad3'
+    factory.filesize = 158437
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_retr_longfilename_SMB1():
+    # Test file retrieval that has a long English filename
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = False
+
+    factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.path = '/Implementing CIFS - SMB.html'
+    factory.digest = '671c5700d279fcbbf958c1bba3c2639e'
+    factory.filesize = 421269
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_retr_longfilename_SMB2():
+    # Test file retrieval that has a long English filename
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = True
+
+    factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.path = '/Implementing CIFS - SMB.html'
+    factory.digest = '671c5700d279fcbbf958c1bba3c2639e'
+    factory.filesize = 421269
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_retr_unicodefilename_SMB1():
+    # Test file retrieval that has a long non-English filename inside a folder with a non-English name
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = False
+
+    factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.path = u'/测试文件夹/垃圾文件.dat'
+    factory.digest = '8a44c1e80d55e91c92350955cdf83442'
+    factory.filesize = 256000
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_retr_unicodefilename_SMB2():
+    # Test file retrieval that has a long non-English filename inside a folder with a non-English name
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = True
+
+    factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.path = u'/测试文件夹/垃圾文件.dat'
+    factory.digest = '8a44c1e80d55e91c92350955cdf83442'
+    factory.filesize = 256000
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_retr_offset_SMB1():
+    # Test file retrieval from offset to EOF
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = False
+
+    factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.path = u'/测试文件夹/垃圾文件.dat'
+    factory.digest = 'a141bd8024571ce7cb5c67f2b0d8ea0b'
+    factory.filesize = 156000
+    factory.offset = 100000
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_retr_offset_SMB2():
+    # Test file retrieval from offset to EOF
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = True
+
+    factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.path = u'/测试文件夹/垃圾文件.dat'
+    factory.digest = 'a141bd8024571ce7cb5c67f2b0d8ea0b'
+    factory.filesize = 156000
+    factory.offset = 100000
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_retr_offset_and_biglimit_SMB1():
+    # Test file retrieval from offset with a big max_length
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = False
+
+    factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.path = u'/测试文件夹/垃圾文件.dat'
+    factory.digest = '83b7afd7c92cdece3975338b5ca0b1c5'
+    factory.filesize = 100000
+    factory.offset = 100000
+    factory.max_length = 100000
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_retr_offset_and_biglimit_SMB2():
+    # Test file retrieval from offset with a big max_length
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = True
+
+    factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.path = u'/测试文件夹/垃圾文件.dat'
+    factory.digest = '83b7afd7c92cdece3975338b5ca0b1c5'
+    factory.filesize = 100000
+    factory.offset = 100000
+    factory.max_length = 100000
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_retr_offset_and_smalllimit_SMB1():
+    # Test file retrieval from offset with a small max_length
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = False
+
+    factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.path = u'/测试文件夹/垃圾文件.dat'
+    factory.digest = '746f60a96b39b712a7b6e17ddde19986'
+    factory.filesize = 10
+    factory.offset = 100000
+    factory.max_length = 10
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_retr_offset_and_smalllimit_SMB2():
+    # Test file retrieval from offset with a small max_length
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = True
+
+    factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.path = u'/测试文件夹/垃圾文件.dat'
+    factory.digest = '746f60a96b39b712a7b6e17ddde19986'
+    factory.filesize = 10
+    factory.offset = 100000
+    factory.max_length = 10
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_retr_offset_and_zerolimit_SMB1():
+    # Test file retrieval from offset to EOF with max_length=0
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = False
+
+    factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.path = u'/测试文件夹/垃圾文件.dat'
+    factory.digest = 'd41d8cd98f00b204e9800998ecf8427e'
+    factory.filesize = 0
+    factory.offset = 100000
+    factory.max_length = 0
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_retr_offset_and_zerolimit_SMB2():
+    # Test file retrieval from offset to EOF with max_length=0
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = True
+    
+    factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.path = u'/测试文件夹/垃圾文件.dat'
+    factory.digest = 'd41d8cd98f00b204e9800998ecf8427e'
+    factory.filesize = 0
+    factory.offset = 100000
+    factory.max_length = 0
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
diff --git a/python2/tests/DirectSMBTwistedTests/test_storefile.py b/python2/tests/DirectSMBTwistedTests/test_storefile.py
new file mode 100644
index 00000000..8d639f71
--- /dev/null
+++ b/python2/tests/DirectSMBTwistedTests/test_storefile.py
@@ -0,0 +1,141 @@
+# -*- coding: utf-8 -*-
+
+import os, time, random
+from StringIO import StringIO
+from nose.twistedtools import reactor, deferred
+from twisted.internet import defer
+from smb.SMBProtocol import SMBProtocolFactory
+from smb import smb_structs
+from util import getConnectionInfo
+
+try:
+    import hashlib
+    def MD5(): return hashlib.md5()
+except ImportError:
+    import md5
+    def MD5(): return md5.new()
+
+class StoreFilesFactory(SMBProtocolFactory):
+    """
+    A super test factory that tests store file, list files, retrieve file and delete file functionlities in sequence.
+    """
+
+    TEST_FILENAME = os.path.join(os.path.dirname(__file__), os.pardir, 'SupportFiles', 'binary.dat')
+    TEST_FILESIZE = 256000
+    TEST_DIGEST = 'bb6303f76e29f354b6fdf6ef58587e48'
+
+    def __init__(self, *args, **kwargs):
+        SMBProtocolFactory.__init__(self, *args, **kwargs)
+        self.d = defer.Deferred()
+        self.d.addBoth(self.testDone)
+        self.service_name = ''
+        self.filename = ''
+
+    def testDone(self, r):
+        if self.instance:
+            self.instance.transport.loseConnection()
+        return r
+
+    def storeComplete(self, result):
+        file_obj, filesize = result
+        file_obj.close()
+        assert filesize == self.TEST_FILESIZE
+
+        d = self.listPath(self.service_name, os.path.dirname(self.filename.replace('/', os.sep)))
+        d.addCallback(self.listComplete)
+        d.addErrback(self.d.errback)
+
+    def listComplete(self, entries):
+        filenames = map(lambda e: e.filename, entries)
+        assert os.path.basename(self.filename.replace('/', os.sep)) in filenames
+
+        for entry in entries:
+            if os.path.basename(self.filename.replace('/', os.sep)) == entry.filename:
+                # The following asserts will fail if the remote machine's time is not in sync with the test machine's time
+                assert abs(entry.create_time - time.time()) < 3
+                assert abs(entry.last_access_time - time.time()) < 3
+                assert abs(entry.last_write_time - time.time()) < 3
+                assert abs(entry.last_attr_change_time - time.time()) < 3
+                break
+
+        d = self.retrieveFile(self.service_name, self.filename, StringIO())
+        d.addCallback(self.retrieveComplete)
+        d.addErrback(self.d.errback)
+
+    def retrieveComplete(self, result):
+        file_obj, file_attributes, file_size = result
+
+        md = MD5()
+        md.update(file_obj.getvalue())
+        file_obj.close()
+
+        assert file_size == self.TEST_FILESIZE
+        assert md.hexdigest() == self.TEST_DIGEST
+
+        d = self.deleteFiles(self.service_name, self.filename)
+        d.addCallback(self.deleteComplete)
+        d.addErrback(self.d.errback)
+
+    def deleteComplete(self, result):
+        d = self.listPath(self.service_name, os.path.dirname(self.filename.replace('/', os.sep)))
+        d.addCallback(self.list2Complete)
+        d.addErrback(self.d.errback)
+
+    def list2Complete(self, entries):
+        filenames = map(lambda e: e.filename, entries)
+        assert os.path.basename(self.filename.replace('/', os.sep)) not in filenames
+        self.d.callback(True)
+        self.instance.transport.loseConnection()
+
+    def onAuthOK(self):
+        d = self.storeFile(self.service_name, self.filename, open(self.TEST_FILENAME, 'rb'))
+        d.addCallback(self.storeComplete)
+        d.addErrback(self.d.errback)
+
+    def onAuthFailed(self):
+        self.d.errback('Auth failed')
+
+
+@deferred(timeout=30.0)
+def test_store_long_filename_SMB1():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = False
+
+    factory = StoreFilesFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service_name = 'smbtest'
+    factory.filename = os.sep + 'StoreTest %d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_store_long_filename_SMB2():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = True
+
+    factory = StoreFilesFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service_name = 'smbtest'
+    factory.filename = os.sep + 'StoreTest %d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_store_unicode_filename_SMB1():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = False
+
+    factory = StoreFilesFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service_name = 'smbtest'
+    factory.filename = os.sep + u'上载测试 %d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_store_unicode_filename_SMB2():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = True
+
+    factory = StoreFilesFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service_name = 'smbtest'
+    factory.filename = os.sep + u'上载测试 %d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
diff --git a/python2/tests/DirectSMBTwistedTests/util.py b/python2/tests/DirectSMBTwistedTests/util.py
new file mode 100644
index 00000000..12f82afa
--- /dev/null
+++ b/python2/tests/DirectSMBTwistedTests/util.py
@@ -0,0 +1,19 @@
+
+import os
+from ConfigParser import SafeConfigParser
+
+def getConnectionInfo():
+    config_filename = os.path.join(os.path.dirname(__file__), os.path.pardir, 'connection.ini')
+    cp = SafeConfigParser()
+    cp.read(config_filename)
+
+    info = {
+        'server_name': cp.get('server', 'name'),
+        'server_ip': cp.get('server', 'ip'),
+        'server_port': cp.getint('server', 'direct_port'),
+        'client_name': cp.get('client', 'name'),
+        'user': cp.get('user', 'name'),
+        'password': cp.get('user', 'password'),
+        'is_direct_tcp': True,
+    }
+    return info
diff --git a/python2/tests/NetBIOSTests/__init__.py b/python2/tests/NetBIOSTests/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/python2/tests/NetBIOSTests/test_queryname.py b/python2/tests/NetBIOSTests/test_queryname.py
new file mode 100644
index 00000000..a727cba4
--- /dev/null
+++ b/python2/tests/NetBIOSTests/test_queryname.py
@@ -0,0 +1,16 @@
+
+from nmb.NetBIOS import NetBIOS
+from nose.tools import with_setup
+
+conn = None
+
+def teardown_func():
+    global conn
+    conn.close()
+
+@with_setup(teardown = teardown_func)
+def test_broadcast():
+    global conn
+    conn = NetBIOS()
+    assert conn.queryName('MICHAEL-I5PC', timeout = 10)
+
diff --git a/python2/tests/NetBIOSTwistedTests/__init__.py b/python2/tests/NetBIOSTwistedTests/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/python2/tests/NetBIOSTwistedTests/test_queryname.py b/python2/tests/NetBIOSTwistedTests/test_queryname.py
new file mode 100644
index 00000000..43e45486
--- /dev/null
+++ b/python2/tests/NetBIOSTwistedTests/test_queryname.py
@@ -0,0 +1,21 @@
+
+from nose.twistedtools import reactor, deferred
+from twisted.internet import defer
+from nmb.NetBIOSProtocol import NBNSProtocol
+from nose.tools import with_setup
+
+
+@deferred(timeout=15.0)
+def test_broadcast():
+    def cb(results):
+        assert results
+
+    def cleanup(r):
+        p.transport.stopListening()
+
+    p = NBNSProtocol()
+    d = p.queryName('MICHAEL-I5PC', timeout = 10)
+    d.addCallback(cb)
+    d.addBoth(cleanup)
+
+    return d
diff --git a/python2/tests/README_1st.txt b/python2/tests/README_1st.txt
new file mode 100644
index 00000000..7e918bf8
--- /dev/null
+++ b/python2/tests/README_1st.txt
@@ -0,0 +1,32 @@
+
+Steps to Follow to Run the Unit Tests
+=====================================
+
+1a. Install Nose Testing Framework
+All the unit tests here are designed to be conducted with the nose testing framework.
+You can install the latest nose testing framework by running: easy_install nose
+For more information on nose testing, please visit http://readthedocs.org/docs/nose/en/latest/
+
+1b. Install the Twisted framework
+If you need to test the SMB/NetBIOS protocol implementations for Twisted framework,
+you should install the Twisted framework from http://twistedmatrix.com/
+or by running: easy_install Twisted
+Without the Twisted framework, the Twisted tests will fail.
+
+2. Prepare a Shared Folder "smbtest" on a Remote Server
+To run the unit tests here, besides installing the nose testing framework, you will
+also need to prepare a shared folder on a remote server.
+pysmb has been tested against Samba 3.x, Windows XP SP3 and Windows Vista.
+The shared folder must be named "smbtest".
+
+3. Download smbtest.zip from https://miketeo.net/files/Projects/pysmb/smbtest.zip
+Unzip the contents of this zip file in the shared folder.
+
+4. Update Connection Details in connection.ini
+In the same folder where you are viewing this readme file, there should be an ini file
+called "connection.ini". Edit this file's connection details to match the shared folder's
+access information.
+
+5. Run the Unit Tests in the python2 folder
+Just run: nosetests -v tests
+or selectively: nosetests -v tests/SMBConnectionTests
diff --git a/python2/tests/SMBConnectionTests/__init__.py b/python2/tests/SMBConnectionTests/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/python2/tests/SMBConnectionTests/test_SMBHandler.py b/python2/tests/SMBConnectionTests/test_SMBHandler.py
new file mode 100644
index 00000000..7a28b563
--- /dev/null
+++ b/python2/tests/SMBConnectionTests/test_SMBHandler.py
@@ -0,0 +1,66 @@
+# -*- coding: utf-8 -*-
+
+import os, urllib, urllib2, time, random
+from StringIO import StringIO
+from smb.SMBHandler import SMBHandler
+import util
+
+
+try:
+    import hashlib
+    def MD5(): return hashlib.md5()
+except ImportError:
+    import md5
+    def MD5(): return md5.new()
+
+
+
+def test_basic():
+    # Basic test for smb URLs
+    director = urllib2.build_opener(SMBHandler)
+    fh = director.open('smb://%(user)s:%(password)s@%(server_ip)s/smbtest/rfc1001.txt' % util.getConnectionInfo())
+
+    s = fh.read()
+    md = MD5()
+    md.update(s)
+    assert md.hexdigest() == '5367c2bbf97f521059c78eab65309ad3'
+    assert len(s) == 158437
+
+    fh.close()
+
+
+def test_unicode():
+    # Test smb URLs with unicode paths
+    director = urllib2.build_opener(SMBHandler)
+    fh = director.open(u'smb://%(user)s:%(password)s@%(server_ip)s/smbtest/测试文件夹/垃圾文件.dat' % util.getConnectionInfo())
+
+    s = fh.read()
+    md = MD5()
+    md.update(s)
+    assert md.hexdigest() == '8a44c1e80d55e91c92350955cdf83442'
+    assert len(s) == 256000
+
+    fh.close()
+
+
+
+TEST_FILENAME = os.path.join(os.path.dirname(__file__), os.pardir, 'SupportFiles', 'binary.dat')
+TEST_FILESIZE = 256000
+TEST_DIGEST = 'bb6303f76e29f354b6fdf6ef58587e48'
+
+def test_upload():
+    info = util.getConnectionInfo()
+    info['filename'] = os.sep + 'StoreTest-%d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+
+    director = urllib2.build_opener(SMBHandler)
+    upload_fh = director.open('smb://%(user)s:%(password)s@%(server_ip)s/smbtest/%(filename)s' % info, data = open(TEST_FILENAME, 'rb'))
+
+    retr_fh = director.open('smb://%(user)s:%(password)s@%(server_ip)s/smbtest/%(filename)s' % info)
+
+    s = retr_fh.read()
+    md = MD5()
+    md.update(s)
+
+    assert md.hexdigest() == TEST_DIGEST
+    assert len(s) == TEST_FILESIZE
+
diff --git a/python2/tests/SMBConnectionTests/test_auth.py b/python2/tests/SMBConnectionTests/test_auth.py
new file mode 100644
index 00000000..b28e150c
--- /dev/null
+++ b/python2/tests/SMBConnectionTests/test_auth.py
@@ -0,0 +1,72 @@
+
+from smb.SMBConnection import SMBConnection
+from util import getConnectionInfo
+from nose.tools import with_setup
+from smb import smb_structs
+
+conn, conn2, conn3 = None, None, None
+
+def teardown_func():
+    global conn, conn2, conn3
+    if conn:
+        conn.close()
+    if conn2:
+        conn2.close()
+    if conn3:
+        conn3.close();
+
+@with_setup(teardown = teardown_func)
+def test_NTLMv1_auth_SMB1():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = False
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], domain = info['domain'], use_ntlm_v2 = False)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+    conn2 = SMBConnection(info['user'], 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = False)
+    assert not conn2.connect(info['server_ip'], info['server_port'])
+
+    conn3 = SMBConnection('INVALIDUSER', 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = False)
+    assert not conn3.connect(info['server_ip'], info['server_port'])
+
+@with_setup(teardown = teardown_func)
+def test_NTLMv2_auth_SMB1():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = False
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], domain = info['domain'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+    conn2 = SMBConnection(info['user'], 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert not conn2.connect(info['server_ip'], info['server_port'])
+
+    conn3 = SMBConnection('INVALIDUSER', 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert not conn3.connect(info['server_ip'], info['server_port'])
+
+@with_setup(teardown = teardown_func)
+def test_NTLMv1_auth_SMB2():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = True
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], domain = info['domain'], use_ntlm_v2 = False)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+    conn2 = SMBConnection(info['user'], 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = False)
+    assert not conn2.connect(info['server_ip'], info['server_port'])
+
+    conn3 = SMBConnection('INVALIDUSER', 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = False)
+    assert not conn3.connect(info['server_ip'], info['server_port'])
+
+@with_setup(teardown = teardown_func)
+def test_NTLMv2_auth_SMB2():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = True
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], domain = info['domain'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+    conn2 = SMBConnection(info['user'], 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert not conn2.connect(info['server_ip'], info['server_port'])
+
+    conn3 = SMBConnection('INVALIDUSER', 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert not conn3.connect(info['server_ip'], info['server_port'])
diff --git a/python2/tests/SMBConnectionTests/test_createdeletedirectory.py b/python2/tests/SMBConnectionTests/test_createdeletedirectory.py
new file mode 100644
index 00000000..6430f31e
--- /dev/null
+++ b/python2/tests/SMBConnectionTests/test_createdeletedirectory.py
@@ -0,0 +1,145 @@
+# -*- coding: utf-8 -*-
+
+import os, time, random
+from smb.SMBConnection import SMBConnection
+from smb.smb2_constants import SMB2_DIALECT_2
+from util import getConnectionInfo
+from nose.tools import with_setup
+from smb import smb_structs
+
+conn = None
+
+def setup_func_SMB1():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = False
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2():
+    global conn
+    smb_structs.SUPPORT_SMB2 = True
+    smb_structs.SUPPORT_SMB2x = False
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2x():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = True
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def teardown_func():
+    global conn
+    conn.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_english_directory_SMB1():
+    global conn
+
+    path = os.sep + 'TestDir %d-%d' % ( time.time(), random.randint(0, 1000) )
+    conn.createDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) in names
+
+    conn.deleteDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) not in names
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_english_directory_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    path = os.sep + 'TestDir %d-%d' % ( time.time(), random.randint(0, 1000) )
+    conn.createDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) in names
+
+    conn.deleteDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) not in names
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_english_directory_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    path = os.sep + 'TestDir %d-%d' % ( time.time(), random.randint(0, 1000) )
+    conn.createDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) in names
+
+    conn.deleteDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) not in names
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_unicode_directory_SMB1():
+    global conn
+
+    path = os.sep + u'文件夹创建 %d-%d' % ( time.time(), random.randint(0, 1000) )
+    conn.createDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) in names
+
+    conn.deleteDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) not in names
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_unicode_directory_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    path = os.sep + u'文件夹创建 %d-%d' % ( time.time(), random.randint(0, 1000) )
+    conn.createDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) in names
+
+    conn.deleteDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) not in names
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_unicode_directory_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    path = os.sep + u'文件夹创建 %d-%d' % ( time.time(), random.randint(0, 1000) )
+    conn.createDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) in names
+
+    conn.deleteDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) not in names
diff --git a/python2/tests/SMBConnectionTests/test_deletepattern.py b/python2/tests/SMBConnectionTests/test_deletepattern.py
new file mode 100644
index 00000000..3cf5a267
--- /dev/null
+++ b/python2/tests/SMBConnectionTests/test_deletepattern.py
@@ -0,0 +1,153 @@
+# -*- coding: utf-8 -*-
+
+import os, time, random
+from StringIO import StringIO
+from smb.SMBConnection import SMBConnection
+from smb.smb2_constants import SMB2_DIALECT_2
+from util import getConnectionInfo
+from nose.tools import with_setup
+from smb import smb_structs
+
+conn = None
+
+def setup_func_SMB1():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = False
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2():
+    global conn
+    smb_structs.SUPPORT_SMB2 = True
+    smb_structs.SUPPORT_SMB2x = False
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2x():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = True
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def teardown_func():
+    global conn
+    conn.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_delete_SMB1():
+    global conn
+
+    path = os.sep + u'testDelete %d-%d' % ( time.time(), random.randint(0, 1000) )
+    conn.createDirectory('smbtest', path)
+
+    for filename in [ 'aaTest.txt', 'aaBest.txt', 'aaTest.bin', 'aaBest.bin', 'random.txt' ]:
+        conn.storeFile('smbtest', path+"/"+filename, StringIO("0123456789"))
+
+    results = conn.listPath('smbtest', path)
+    filenames = map(lambda r: r.filename, results)
+    assert 'aaTest.txt' in filenames
+    assert 'aaBest.txt' in filenames
+    assert 'aaTest.bin' in filenames
+    assert 'aaBest.bin' in filenames
+    assert 'random.txt' in filenames
+
+    conn.deleteFiles('smbtest', path+'/aa*.txt')
+
+    results = conn.listPath('smbtest', path)
+    filenames = map(lambda r: r.filename, results)
+    assert 'aaTest.txt' not in filenames
+    assert 'aaBest.txt' not in filenames
+    assert 'aaTest.bin' in filenames
+    assert 'aaBest.bin' in filenames
+    assert 'random.txt' in filenames
+
+    conn.deleteFiles('smbtest', path+'/aaTest.*')
+
+    results = conn.listPath('smbtest', path)
+    filenames = map(lambda r: r.filename, results)
+    assert 'aaTest.bin' not in filenames
+    assert 'aaBest.bin' in filenames
+    assert 'random.txt' in filenames
+
+    conn.deleteFiles('smbtest', path+'/*')
+    conn.deleteDirectory('smbtest', path)
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_delete_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    path = os.sep + u'testDelete %d-%d' % ( time.time(), random.randint(0, 1000) )
+    conn.createDirectory('smbtest', path)
+
+    for filename in [ 'aaTest.txt', 'aaBest.txt', 'aaTest.bin', 'aaBest.bin', 'random.txt' ]:
+        conn.storeFile('smbtest', path+"/"+filename, StringIO("0123456789"))
+
+    results = conn.listPath('smbtest', path)
+    filenames = map(lambda r: r.filename, results)
+    assert 'aaTest.txt' in filenames
+    assert 'aaBest.txt' in filenames
+    assert 'aaTest.bin' in filenames
+    assert 'aaBest.bin' in filenames
+    assert 'random.txt' in filenames
+
+    conn.deleteFiles('smbtest', path+'/aa*.txt')
+
+    results = conn.listPath('smbtest', path)
+    filenames = map(lambda r: r.filename, results)
+    assert 'aaTest.txt' not in filenames
+    assert 'aaBest.txt' not in filenames
+    assert 'aaTest.bin' in filenames
+    assert 'aaBest.bin' in filenames
+    assert 'random.txt' in filenames
+
+    conn.deleteFiles('smbtest', path+'/aaTest.*')
+
+    results = conn.listPath('smbtest', path)
+    filenames = map(lambda r: r.filename, results)
+    assert 'aaTest.bin' not in filenames
+    assert 'aaBest.bin' in filenames
+    assert 'random.txt' in filenames
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_delete_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    path = os.sep + u'testDelete %d-%d' % ( time.time(), random.randint(0, 1000) )
+    conn.createDirectory('smbtest', path)
+
+    for filename in [ 'aaTest.txt', 'aaBest.txt', 'aaTest.bin', 'aaBest.bin', 'random.txt' ]:
+        conn.storeFile('smbtest', path+"/"+filename, StringIO("0123456789"))
+
+    results = conn.listPath('smbtest', path)
+    filenames = map(lambda r: r.filename, results)
+    assert 'aaTest.txt' in filenames
+    assert 'aaBest.txt' in filenames
+    assert 'aaTest.bin' in filenames
+    assert 'aaBest.bin' in filenames
+    assert 'random.txt' in filenames
+
+    conn.deleteFiles('smbtest', path+'/aa*.txt')
+
+    results = conn.listPath('smbtest', path)
+    filenames = map(lambda r: r.filename, results)
+    assert 'aaTest.txt' not in filenames
+    assert 'aaBest.txt' not in filenames
+    assert 'aaTest.bin' in filenames
+    assert 'aaBest.bin' in filenames
+    assert 'random.txt' in filenames
+
+    conn.deleteFiles('smbtest', path+'/aaTest.*')
+
+    results = conn.listPath('smbtest', path)
+    filenames = map(lambda r: r.filename, results)
+    assert 'aaTest.bin' not in filenames
+    assert 'aaBest.bin' in filenames
+    assert 'random.txt' in filenames
diff --git a/python2/tests/SMBConnectionTests/test_echo.py b/python2/tests/SMBConnectionTests/test_echo.py
new file mode 100644
index 00000000..33759727
--- /dev/null
+++ b/python2/tests/SMBConnectionTests/test_echo.py
@@ -0,0 +1,25 @@
+
+import random
+from smb.SMBConnection import SMBConnection
+from util import getConnectionInfo
+from nose.tools import with_setup
+
+conn = None
+
+def setup_func():
+    global conn
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def teardown_func():
+    global conn
+    conn.close()
+
+@with_setup(setup_func, teardown_func)
+def test_echo():
+    global conn
+
+    data = '%d' % random.randint(1000, 9999)
+    assert conn.echo(data) == data
+    
diff --git a/python2/tests/SMBConnectionTests/test_getattributes.py b/python2/tests/SMBConnectionTests/test_getattributes.py
new file mode 100644
index 00000000..64185a56
--- /dev/null
+++ b/python2/tests/SMBConnectionTests/test_getattributes.py
@@ -0,0 +1,84 @@
+# -*- coding: utf-8 -*-
+
+from smb.SMBConnection import SMBConnection
+from smb.smb2_constants import SMB2_DIALECT_2
+from util import getConnectionInfo
+from nose.tools import with_setup
+from smb import smb_structs
+
+conn = None
+
+def setup_func_SMB1():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = False
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2():
+    global conn
+    smb_structs.SUPPORT_SMB2 = True
+    smb_structs.SUPPORT_SMB2x = False
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2x():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = True
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def teardown_func():
+    global conn
+    conn.close()
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_getAttributes_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    info = conn.getAttributes('smbtest', '/Test Folder with Long Name/')
+    assert info.isDirectory
+
+    info = conn.getAttributes('smbtest', '/rfc1001.txt')
+    assert not info.isDirectory
+    assert info.file_size == 158437
+    assert info.alloc_size == 159744
+
+    info = conn.getAttributes('smbtest', u'/\u6d4b\u8bd5\u6587\u4ef6\u5939')
+    assert info.isDirectory
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_getAttributes_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    info = conn.getAttributes('smbtest', '/Test Folder with Long Name/')
+    assert info.isDirectory
+
+    info = conn.getAttributes('smbtest', '/rfc1001.txt')
+    assert not info.isDirectory
+    assert info.file_size == 158437
+    assert info.alloc_size == 159744
+
+    info = conn.getAttributes('smbtest', u'/\u6d4b\u8bd5\u6587\u4ef6\u5939')
+    assert info.isDirectory
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_getAttributes_SMB1():
+    global conn
+    info = conn.getAttributes('smbtest', '/Test Folder with Long Name/')
+    assert info.isDirectory
+
+    info = conn.getAttributes('smbtest', '/rfc1001.txt')
+    assert not info.isDirectory
+    assert info.file_size == 158437
+    assert info.alloc_size == 159744
+
+    info = conn.getAttributes('smbtest', u'/\u6d4b\u8bd5\u6587\u4ef6\u5939')
+    assert info.isDirectory
diff --git a/python2/tests/SMBConnectionTests/test_listpath.py b/python2/tests/SMBConnectionTests/test_listpath.py
new file mode 100644
index 00000000..abfcb771
--- /dev/null
+++ b/python2/tests/SMBConnectionTests/test_listpath.py
@@ -0,0 +1,202 @@
+# -*- coding: utf-8 -*-
+
+from smb.SMBConnection import SMBConnection
+from smb.smb_constants import *
+from smb.smb2_constants import SMB2_DIALECT_2
+from util import getConnectionInfo
+from nose.tools import with_setup
+from smb import smb_structs
+
+conn = None
+
+def setup_func_SMB1():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = False
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2():
+    global conn
+    smb_structs.SUPPORT_SMB2 = True
+    smb_structs.SUPPORT_SMB2x = False
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2x():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = True
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def teardown_func():
+    global conn
+    conn.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_listPath_SMB1():
+    global conn
+    results = conn.listPath('smbtest', '/')
+    filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+    assert ( u'\u6d4b\u8bd5\u6587\u4ef6\u5939', True ) in filenames  # Test non-English folder names
+    assert ( u'Test Folder with Long Name', True ) in filenames      # Test long English folder names
+    assert ( u'TestDir1', True ) in filenames                        # Test short English folder names
+    assert ( u'Implementing CIFS - SMB.html', False ) in filenames   # Test long English file names
+    assert ( u'rfc1001.txt', False ) in filenames                    # Test short English file names
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_listSubPath_SMB1():
+    global conn
+    results = conn.listPath('smbtest', '/Test Folder with Long Name/')
+    filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+    assert ( u'Test File.txt', False ) in filenames
+    assert ( u'Test Folder', True ) in filenames
+    assert ( u'子文件夹', True ) in filenames
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_listPathWithManyFiles_SMB1():
+    global conn
+    results = conn.listPath('smbtest', '/RFC Archive/')
+    filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+    assert len(filenames)==999
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_listPath_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+    results = conn.listPath('smbtest', '/')
+    filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+    assert ( u'\u6d4b\u8bd5\u6587\u4ef6\u5939', True ) in filenames  # Test non-English folder names
+    assert ( u'Test Folder with Long Name', True ) in filenames      # Test long English folder names
+    assert ( u'TestDir1', True ) in filenames                        # Test short English folder names
+    assert ( u'Implementing CIFS - SMB.html', False ) in filenames   # Test long English file names
+    assert ( u'rfc1001.txt', False ) in filenames                    # Test short English file names
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_listPath_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+    results = conn.listPath('smbtest', '/')
+    filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+    assert ( u'\u6d4b\u8bd5\u6587\u4ef6\u5939', True ) in filenames  # Test non-English folder names
+    assert ( u'Test Folder with Long Name', True ) in filenames      # Test long English folder names
+    assert ( u'TestDir1', True ) in filenames                        # Test short English folder names
+    assert ( u'Implementing CIFS - SMB.html', False ) in filenames   # Test long English file names
+    assert ( u'rfc1001.txt', False ) in filenames                    # Test short English file names
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_listSubPath_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+    results = conn.listPath('smbtest', '/Test Folder with Long Name/')
+    filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+    assert ( u'Test File.txt', False ) in filenames
+    assert ( u'Test Folder', True ) in filenames
+    assert ( u'子文件夹', True ) in filenames
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_listSubPath_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+    results = conn.listPath('smbtest', '/Test Folder with Long Name/')
+    filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+    assert ( u'Test File.txt', False ) in filenames
+    assert ( u'Test Folder', True ) in filenames
+    assert ( u'子文件夹', True ) in filenames
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_listPathWithManyFiles_SMB2():
+    global conn
+    results = conn.listPath('smbtest', '/RFC Archive/')
+    filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+    assert len(filenames)==999
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_listPathFilterForDirectory_SMB1():
+    global conn
+    results = conn.listPath('smbtest', '/Test Folder with Long Name', search = SMB_FILE_ATTRIBUTE_DIRECTORY)
+    filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+    assert len(filenames) > 0
+    for f, isDirectory in filenames:
+        assert isDirectory
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_listPathFilterForDirectory_SMB2():
+    global conn
+    results = conn.listPath('smbtest', '/Test Folder with Long Name', search = SMB_FILE_ATTRIBUTE_DIRECTORY)
+    filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+    assert len(filenames) > 0
+    for f, isDirectory in filenames:
+        assert isDirectory
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_listPathFilterForFiles_SMB1():
+    global conn
+    results = conn.listPath('smbtest', '/Test Folder with Long Name', search = SMB_FILE_ATTRIBUTE_READONLY | SMB_FILE_ATTRIBUTE_HIDDEN | SMB_FILE_ATTRIBUTE_SYSTEM | SMB_FILE_ATTRIBUTE_ARCHIVE | SMB_FILE_ATTRIBUTE_INCL_NORMAL)
+    filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+    assert len(filenames) > 0
+    for f, isDirectory in filenames:
+        assert not isDirectory
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_listPathFilterForFiles_SMB2():
+    global conn
+    results = conn.listPath('smbtest', '/Test Folder with Long Name', search = SMB_FILE_ATTRIBUTE_READONLY | SMB_FILE_ATTRIBUTE_HIDDEN | SMB_FILE_ATTRIBUTE_SYSTEM | SMB_FILE_ATTRIBUTE_ARCHIVE | SMB_FILE_ATTRIBUTE_INCL_NORMAL)
+    filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+    assert len(filenames) > 0
+    for f, isDirectory in filenames:
+        assert not isDirectory
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_listPathFilterPattern_SMB1():
+    global conn
+    results = conn.listPath('smbtest', '/Test Folder with Long Name', pattern = 'Test*')
+    filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+    assert len(filenames) == 2
+    assert ( u'Test File.txt', False ) in filenames
+    assert ( u'Test Folder', True ) in filenames
+    assert ( u'子文件夹', True ) not in filenames
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_listPathFilterPattern_SMB2():
+    global conn
+    results = conn.listPath('smbtest', '/Test Folder with Long Name', pattern = 'Test*')
+    filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+    assert len(filenames) == 2
+    assert ( u'Test File.txt', False ) in filenames
+    assert ( u'Test Folder', True ) in filenames
+    assert ( u'子文件夹', True ) not in filenames
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_listPathFilterUnicodePattern_SMB1():
+    global conn
+    results = conn.listPath('smbtest', '/Test Folder with Long Name', pattern = u'*件夹')
+    filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+    assert len(filenames) == 1
+    assert ( u'Test File.txt', False ) not in filenames
+    assert ( u'Test Folder', True ) not in filenames
+    assert ( u'子文件夹', True ) in filenames
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_listPathFilterUnicodePattern_SMB2():
+    global conn
+    results = conn.listPath('smbtest', '/Test Folder with Long Name', pattern = u'*件夹')
+    filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+    assert len(filenames) == 1
+    assert ( u'Test File.txt', False ) not in filenames
+    assert ( u'Test Folder', True ) not in filenames
+    assert ( u'子文件夹', True ) in filenames
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_listPathFilterEmptyList_SMB1():
+    global conn
+    results = conn.listPath('smbtest', '/RFC Archive', pattern = '*.abc')
+    filenames = list(map(lambda r: ( r.filename, r.isDirectory ), results))
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_listPathFilterEmptyList_SMB2():
+    global conn
+    results = conn.listPath('smbtest', '/RFC Archive', pattern = '*.abc')
+    filenames = list(map(lambda r: ( r.filename, r.isDirectory ), results))
diff --git a/python2/tests/SMBConnectionTests/test_listshares.py b/python2/tests/SMBConnectionTests/test_listshares.py
new file mode 100644
index 00000000..a5d4ae5e
--- /dev/null
+++ b/python2/tests/SMBConnectionTests/test_listshares.py
@@ -0,0 +1,54 @@
+
+from smb.SMBConnection import SMBConnection
+from smb.smb2_constants import SMB2_DIALECT_2
+from util import getConnectionInfo
+from nose.tools import with_setup
+from smb import smb_structs
+
+conn = None
+
+def setup_func_SMB1():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = False
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2():
+    global conn
+    smb_structs.SUPPORT_SMB2 = True
+    smb_structs.SUPPORT_SMB2x = False
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2x():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = True
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def teardown_func():
+    global conn
+    conn.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_listshares_SMB1():
+    global conn
+    results = conn.listShares()
+    assert 'smbtest' in map(lambda r: r.name.lower(), results)
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_listshares_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+    results = conn.listShares()
+    assert 'smbtest' in map(lambda r: r.name.lower(), results)
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_listshares_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+    results = conn.listShares()
+    assert 'smbtest' in map(lambda r: r.name.lower(), results)
diff --git a/python2/tests/SMBConnectionTests/test_listsnapshots.py b/python2/tests/SMBConnectionTests/test_listsnapshots.py
new file mode 100644
index 00000000..788a23e2
--- /dev/null
+++ b/python2/tests/SMBConnectionTests/test_listsnapshots.py
@@ -0,0 +1,57 @@
+
+from smb.SMBConnection import SMBConnection
+from smb.smb2_constants import SMB2_DIALECT_2
+from util import getConnectionInfo
+from nose.tools import with_setup
+from smb import smb_structs
+
+conn = None
+
+def setup_func_SMB1():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = False
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2():
+    global conn
+    smb_structs.SUPPORT_SMB2 = True
+    smb_structs.SUPPORT_SMB2x = False
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2x():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = True
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def teardown_func():
+    global conn
+    conn.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_listsnapshots_SMB1():
+    global conn
+    results = conn.listSnapshots('smbtest', '/rfc1001.txt')
+    assert len(results) > 0
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_listsnapshots_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+    results = conn.listSnapshots('smbtest', '/rfc1001.txt')
+    assert len(results) > 0
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_listsnapshots_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+    results = conn.listSnapshots('smbtest', '/rfc1001.txt')
+    assert len(results) > 0
diff --git a/python2/tests/SMBConnectionTests/test_rename.py b/python2/tests/SMBConnectionTests/test_rename.py
new file mode 100644
index 00000000..2d61e9f7
--- /dev/null
+++ b/python2/tests/SMBConnectionTests/test_rename.py
@@ -0,0 +1,321 @@
+# -*- coding: utf-8 -*-
+
+import os, time, random
+from StringIO import StringIO
+from smb.SMBConnection import SMBConnection
+from smb.smb2_constants import SMB2_DIALECT_2
+from util import getConnectionInfo
+from nose.tools import with_setup
+from smb import smb_structs
+
+conn = None
+
+def setup_func_SMB1():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = False
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2():
+    global conn
+    smb_structs.SUPPORT_SMB2 = True
+    smb_structs.SUPPORT_SMB2x = False
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2x():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = True
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def teardown_func():
+    global conn
+    conn.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_rename_english_file_SMB1():
+    global conn
+
+    old_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    new_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.storeFile('smbtest', old_path, StringIO('Rename file test'))
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteFiles('smbtest', new_path)
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_rename_english_file_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    old_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    new_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.storeFile('smbtest', old_path, StringIO('Rename file test'))
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteFiles('smbtest', new_path)
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_rename_english_file_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    old_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    new_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.storeFile('smbtest', old_path, StringIO('Rename file test'))
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteFiles('smbtest', new_path)
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_rename_unicode_file_SMB1():
+    global conn
+
+    old_path = u'/改名测试 %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    new_path = u'/改名测试 %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.storeFile('smbtest', old_path, StringIO('Rename file test'))
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteFiles('smbtest', new_path)
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_rename_unicode_file_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    old_path = u'/改名测试 %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    new_path = u'/改名测试 %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.storeFile('smbtest', old_path, StringIO('Rename file test'))
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteFiles('smbtest', new_path)
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_rename_unicode_file_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    old_path = u'/改名测试 %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    new_path = u'/改名测试 %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.storeFile('smbtest', old_path, StringIO('Rename file test'))
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteFiles('smbtest', new_path)
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_rename_english_directory_SMB1():
+    global conn
+
+    old_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    new_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.createDirectory('smbtest', old_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteDirectory('smbtest', new_path)
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_rename_english_directory_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    old_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    new_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.createDirectory('smbtest', old_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteDirectory('smbtest', new_path)
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_rename_english_directory_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    old_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    new_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.createDirectory('smbtest', old_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteDirectory('smbtest', new_path)
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_rename_unicode_directory_SMB1():
+    global conn
+
+    old_path = u'/改名测试 %d-%d' % ( time.time(), random.randint(1000, 9999) )
+    new_path = u'/改名测试 %d-%d' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.createDirectory('smbtest', old_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteDirectory('smbtest', new_path)
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_rename_unicode_directory_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    old_path = u'/改名测试 %d-%d' % ( time.time(), random.randint(1000, 9999) )
+    new_path = u'/改名测试 %d-%d' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.createDirectory('smbtest', old_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteDirectory('smbtest', new_path)
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_rename_unicode_directory_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    old_path = u'/改名测试 %d-%d' % ( time.time(), random.randint(1000, 9999) )
+    new_path = u'/改名测试 %d-%d' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.createDirectory('smbtest', old_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteDirectory('smbtest', new_path)
diff --git a/python2/tests/SMBConnectionTests/test_retrievefile.py b/python2/tests/SMBConnectionTests/test_retrievefile.py
new file mode 100644
index 00000000..c47bdef7
--- /dev/null
+++ b/python2/tests/SMBConnectionTests/test_retrievefile.py
@@ -0,0 +1,369 @@
+# -*- coding: utf-8 -*-
+
+import os, tempfile
+from StringIO import StringIO
+from smb.SMBConnection import SMBConnection
+from smb.smb2_constants import SMB2_DIALECT_2
+from util import getConnectionInfo
+from nose.tools import with_setup
+from smb import smb_structs
+
+try:
+    import hashlib
+    def MD5(): return hashlib.md5()
+except ImportError:
+    import md5
+    def MD5(): return md5.new()
+
+conn = None
+
+def setup_func_SMB1():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = False
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2():
+    global conn
+    smb_structs.SUPPORT_SMB2 = True
+    smb_structs.SUPPORT_SMB2x = False
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2x():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = True
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def teardown_func():
+    global conn
+    conn.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_retr_multiplereads_SMB1():
+    # Test file retrieval using multiple ReadAndx calls (assuming each call will not reach more than 65534 bytes)
+    global conn
+    temp_fh = StringIO()
+    file_attributes, filesize = conn.retrieveFile('smbtest', '/rfc1001.txt', temp_fh)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '5367c2bbf97f521059c78eab65309ad3'
+    assert filesize == 158437
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_retr_multiplereads_SMB2():
+    # Test file retrieval using multiple ReadAndx calls (assuming each call will not reach more than 65534 bytes)
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    temp_fh = StringIO()
+    file_attributes, filesize = conn.retrieveFile('smbtest', '/rfc1001.txt', temp_fh)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '5367c2bbf97f521059c78eab65309ad3'
+    assert filesize == 158437
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_retr_multiplereads_SMB2x():
+    # Test file retrieval using multiple ReadAndx calls (assuming each call will not reach more than 65534 bytes)
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    temp_fh = StringIO()
+    file_attributes, filesize = conn.retrieveFile('smbtest', '/rfc1001.txt', temp_fh)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '5367c2bbf97f521059c78eab65309ad3'
+    assert filesize == 158437
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_retr_longfilename_SMB1():
+    # Test file retrieval that has a long English filename
+    global conn
+    temp_fh = StringIO()
+    file_attributes, filesize = conn.retrieveFile('smbtest', '/Implementing CIFS - SMB.html', temp_fh)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '671c5700d279fcbbf958c1bba3c2639e'
+    assert filesize == 421269
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_retr_longfilename_SMB2():
+    # Test file retrieval that has a long English filename
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    temp_fh = StringIO()
+    file_attributes, filesize = conn.retrieveFile('smbtest', '/Implementing CIFS - SMB.html', temp_fh)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '671c5700d279fcbbf958c1bba3c2639e'
+    assert filesize == 421269
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_retr_longfilename_SMB2x():
+    # Test file retrieval that has a long English filename
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    temp_fh = StringIO()
+    file_attributes, filesize = conn.retrieveFile('smbtest', '/Implementing CIFS - SMB.html', temp_fh)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '671c5700d279fcbbf958c1bba3c2639e'
+    assert filesize == 421269
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_retr_unicodefilename_SMB1():
+    # Test file retrieval that has a long non-English filename inside a folder with a non-English name
+    global conn
+    temp_fh = StringIO()
+    file_attributes, filesize = conn.retrieveFile('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '8a44c1e80d55e91c92350955cdf83442'
+    assert filesize == 256000
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_retr_unicodefilename_SMB2():
+    # Test file retrieval that has a long non-English filename inside a folder with a non-English name
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    temp_fh = StringIO()
+    file_attributes, filesize = conn.retrieveFile('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '8a44c1e80d55e91c92350955cdf83442'
+    assert filesize == 256000
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_retr_unicodefilename_SMB2x():
+    # Test file retrieval that has a long non-English filename inside a folder with a non-English name
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    temp_fh = StringIO()
+    file_attributes, filesize = conn.retrieveFile('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '8a44c1e80d55e91c92350955cdf83442'
+    assert filesize == 256000
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_retr_offset_SMB1():
+    # Test file retrieval from offset to EOF
+    global conn
+    temp_fh = StringIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == 'a141bd8024571ce7cb5c67f2b0d8ea0b'
+    assert filesize == 156000
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_retr_offset_SMB2():
+    # Test file retrieval from offset to EOF
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    temp_fh = StringIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == 'a141bd8024571ce7cb5c67f2b0d8ea0b'
+    assert filesize == 156000
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_retr_offset_SMB2x():
+    # Test file retrieval from offset to EOF
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    temp_fh = StringIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == 'a141bd8024571ce7cb5c67f2b0d8ea0b'
+    assert filesize == 156000
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_retr_offset_and_biglimit_SMB1():
+    # Test file retrieval from offset with a big max_length
+    global conn
+    temp_fh = StringIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000, max_length = 100000)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '83b7afd7c92cdece3975338b5ca0b1c5'
+    assert filesize == 100000
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_retr_offset_and_biglimit_SMB2():
+    # Test file retrieval from offset with a big max_length
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    temp_fh = StringIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000, max_length = 100000)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '83b7afd7c92cdece3975338b5ca0b1c5'
+    assert filesize == 100000
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_retr_offset_and_biglimit_SMB2x():
+    # Test file retrieval from offset with a big max_length
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    temp_fh = StringIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000, max_length = 100000)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '83b7afd7c92cdece3975338b5ca0b1c5'
+    assert filesize == 100000
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_retr_offset_and_smalllimit_SMB1():
+    # Test file retrieval from offset with a small max_length
+    global conn
+    temp_fh = StringIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000, max_length = 10)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '746f60a96b39b712a7b6e17ddde19986'
+    assert filesize == 10
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_retr_offset_and_smalllimit_SMB2():
+    # Test file retrieval from offset with a small max_length
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    temp_fh = StringIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000, max_length = 10)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '746f60a96b39b712a7b6e17ddde19986'
+    assert filesize == 10
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_retr_offset_and_smalllimit_SMB2x():
+    # Test file retrieval from offset with a small max_length
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    temp_fh = StringIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000, max_length = 10)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '746f60a96b39b712a7b6e17ddde19986'
+    assert filesize == 10
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_retr_offset_and_zerolimit_SMB1():
+    # Test file retrieval from offset to EOF with max_length=0
+    global conn
+    temp_fh = StringIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000, max_length = 0)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == 'd41d8cd98f00b204e9800998ecf8427e'
+    assert filesize == 0
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_retr_offset_and_zerolimit_SMB2():
+    # Test file retrieval from offset to EOF with max_length=0
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    temp_fh = StringIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000, max_length = 0)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == 'd41d8cd98f00b204e9800998ecf8427e'
+    assert filesize == 0
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_retr_offset_and_zerolimit_SMB2x():
+    # Test file retrieval from offset to EOF with max_length=0
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    temp_fh = StringIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000, max_length = 0)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == 'd41d8cd98f00b204e9800998ecf8427e'
+    assert filesize == 0
+
+    temp_fh.close()
diff --git a/python2/tests/SMBConnectionTests/test_security.py b/python2/tests/SMBConnectionTests/test_security.py
new file mode 100644
index 00000000..24966cc7
--- /dev/null
+++ b/python2/tests/SMBConnectionTests/test_security.py
@@ -0,0 +1,53 @@
+# -*- coding: utf-8 -*-
+
+import os, tempfile
+from StringIO import StringIO
+from smb.SMBConnection import SMBConnection
+from smb.smb2_constants import SMB2_DIALECT_2
+from util import getConnectionInfo
+from nose.tools import with_setup
+from smb import smb_structs
+
+try:
+    import hashlib
+    def MD5(): return hashlib.md5()
+except ImportError:
+    import md5
+    def MD5(): return md5.new()
+
+conn = None
+
+def setup_func_SMB2():
+    global conn
+    smb_structs.SUPPORT_SMB2 = True
+    smb_structs.SUPPORT_SMB2x = False
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2x():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = True
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def teardown_func():
+    global conn
+    conn.close()
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_security_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+    # TODO: Need a way to setup the environment on the remote server and perform some verification on the returned results.
+    attributes = conn.getSecurity('smbtest', '/rfc1001.txt')
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_security_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+    # TODO: Need a way to setup the environment on the remote server and perform some verification on the returned results.
+    attributes = conn.getSecurity('smbtest', '/rfc1001.txt')
diff --git a/python2/tests/SMBConnectionTests/test_storefile.py b/python2/tests/SMBConnectionTests/test_storefile.py
new file mode 100644
index 00000000..3e9e5121
--- /dev/null
+++ b/python2/tests/SMBConnectionTests/test_storefile.py
@@ -0,0 +1,268 @@
+# -*- coding: utf-8 -*-
+
+import os, tempfile, random, time
+from StringIO import StringIO
+from smb.SMBConnection import SMBConnection
+from smb.smb2_constants import SMB2_DIALECT_2
+from util import getConnectionInfo
+from nose.tools import with_setup
+from smb import smb_structs
+
+try:
+    import hashlib
+    def MD5(): return hashlib.md5()
+except ImportError:
+    import md5
+    def MD5(): return md5.new()
+
+conn = None
+
+TEST_FILENAME = os.path.join(os.path.dirname(__file__), os.pardir, 'SupportFiles', 'binary.dat')
+TEST_FILESIZE = 256000
+TEST_DIGEST = 'bb6303f76e29f354b6fdf6ef58587e48'
+
+def setup_func_SMB1():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = False
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2():
+    global conn
+    smb_structs.SUPPORT_SMB2 = True
+    smb_structs.SUPPORT_SMB2x = False
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2x():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = True
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def teardown_func():
+    global conn
+    conn.close()
+
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_store_long_filename_SMB1():
+    global conn
+    filename = os.sep + 'StoreTest %d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+
+    filesize = conn.storeFile('smbtest', filename, open(TEST_FILENAME, 'rb'))
+    assert filesize == TEST_FILESIZE
+
+    entries = conn.listPath('smbtest', os.path.dirname(filename.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(filename.replace('/', os.sep)) in filenames
+
+    buf = StringIO()
+    file_attributes, file_size = conn.retrieveFile('smbtest', filename, buf)
+    assert file_size == TEST_FILESIZE
+
+    md = MD5()
+    md.update(buf.getvalue())
+    assert md.hexdigest() == TEST_DIGEST
+    buf.close()
+
+    conn.deleteFiles('smbtest', filename)
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_store_from_offset_SMB1():
+    global conn
+    filename = os.sep + 'StoreTest %d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+
+    buf = StringIO('0123456789')
+    filesize = conn.storeFile('smbtest', filename, buf)
+    assert filesize == 10
+
+    buf = StringIO('aa')
+    pos = conn.storeFileFromOffset('smbtest', filename, buf, 5)
+    assert pos == 7
+
+    buf = StringIO()
+    file_attributes, file_size = conn.retrieveFile('smbtest', filename, buf)
+    assert file_size == 10
+    assert buf.getvalue() == '01234aa789'
+    buf.close()
+
+    conn.deleteFiles('smbtest', filename)
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_store_long_filename_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    filename = os.sep + 'StoreTest %d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+
+    filesize = conn.storeFile('smbtest', filename, open(TEST_FILENAME, 'rb'))
+    assert filesize == TEST_FILESIZE
+
+    entries = conn.listPath('smbtest', os.path.dirname(filename.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(filename.replace('/', os.sep)) in filenames
+
+    buf = StringIO()
+    file_attributes, file_size = conn.retrieveFile('smbtest', filename, buf)
+    assert file_size == TEST_FILESIZE
+
+    md = MD5()
+    md.update(buf.getvalue())
+    assert md.hexdigest() == TEST_DIGEST
+    buf.close()
+
+    conn.deleteFiles('smbtest', filename)
+
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_store_long_filename_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    filename = os.sep + 'StoreTest %d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+
+    filesize = conn.storeFile('smbtest', filename, open(TEST_FILENAME, 'rb'))
+    assert filesize == TEST_FILESIZE
+
+    entries = conn.listPath('smbtest', os.path.dirname(filename.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(filename.replace('/', os.sep)) in filenames
+
+    buf = StringIO()
+    file_attributes, file_size = conn.retrieveFile('smbtest', filename, buf)
+    assert file_size == TEST_FILESIZE
+
+    md = MD5()
+    md.update(buf.getvalue())
+    assert md.hexdigest() == TEST_DIGEST
+    buf.close()
+
+    conn.deleteFiles('smbtest', filename)
+
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_store_unicode_filename_SMB1():
+    global conn
+    filename = os.sep + u'上载测试 %d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+
+    filesize = conn.storeFile('smbtest', filename, open(TEST_FILENAME, 'rb'))
+    assert filesize == TEST_FILESIZE
+
+    entries = conn.listPath('smbtest', os.path.dirname(filename.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(filename.replace('/', os.sep)) in filenames
+
+    buf = StringIO()
+    file_attributes, file_size = conn.retrieveFile('smbtest', filename, buf)
+    assert file_size == TEST_FILESIZE
+
+    md = MD5()
+    md.update(buf.getvalue())
+    assert md.hexdigest() == TEST_DIGEST
+    buf.close()
+
+    conn.deleteFiles('smbtest', filename)
+
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_store_unicode_filename_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    filename = os.sep + u'上载测试 %d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+
+    filesize = conn.storeFile('smbtest', filename, open(TEST_FILENAME, 'rb'))
+    assert filesize == TEST_FILESIZE
+
+    entries = conn.listPath('smbtest', os.path.dirname(filename.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(filename.replace('/', os.sep)) in filenames
+
+    buf = StringIO()
+    file_attributes, file_size = conn.retrieveFile('smbtest', filename, buf)
+    assert file_size == TEST_FILESIZE
+
+    md = MD5()
+    md.update(buf.getvalue())
+    assert md.hexdigest() == TEST_DIGEST
+    buf.close()
+
+    conn.deleteFiles('smbtest', filename)
+
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_store_unicode_filename_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    filename = os.sep + u'上载测试 %d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+
+    filesize = conn.storeFile('smbtest', filename, open(TEST_FILENAME, 'rb'))
+    assert filesize == TEST_FILESIZE
+
+    entries = conn.listPath('smbtest', os.path.dirname(filename.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(filename.replace('/', os.sep)) in filenames
+
+    buf = StringIO()
+    file_attributes, file_size = conn.retrieveFile('smbtest', filename, buf)
+    assert file_size == TEST_FILESIZE
+
+    md = MD5()
+    md.update(buf.getvalue())
+    assert md.hexdigest() == TEST_DIGEST
+    buf.close()
+
+    conn.deleteFiles('smbtest', filename)
+
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_store_from_offset_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    filename = os.sep + 'StoreTest %d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+
+    buf = StringIO('0123456789')
+    filesize = conn.storeFile('smbtest', filename, buf)
+    assert filesize == 10
+
+    buf = StringIO('aa')
+    pos = conn.storeFileFromOffset('smbtest', filename, buf, 5)
+    assert pos == 7
+
+    buf = StringIO()
+    file_attributes, file_size = conn.retrieveFile('smbtest', filename, buf)
+    assert file_size == 10
+    assert buf.getvalue() == '01234aa789'
+    buf.close()
+
+    conn.deleteFiles('smbtest', filename)
+
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_store_from_offset_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    filename = os.sep + 'StoreTest %d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+
+    buf = StringIO('0123456789')
+    filesize = conn.storeFile('smbtest', filename, buf)
+    assert filesize == 10
+
+    buf = StringIO('aa')
+    pos = conn.storeFileFromOffset('smbtest', filename, buf, 5)
+    assert pos == 7
+
+    buf = StringIO()
+    file_attributes, file_size = conn.retrieveFile('smbtest', filename, buf)
+    assert file_size == 10
+    assert buf.getvalue() == '01234aa789'
+    buf.close()
+
+    conn.deleteFiles('smbtest', filename)
diff --git a/python2/tests/SMBConnectionTests/test_with_context.py b/python2/tests/SMBConnectionTests/test_with_context.py
new file mode 100644
index 00000000..58d95677
--- /dev/null
+++ b/python2/tests/SMBConnectionTests/test_with_context.py
@@ -0,0 +1,11 @@
+# -*- coding: utf-8 -*-
+
+from smb.SMBConnection import SMBConnection
+from .util import getConnectionInfo
+
+def test_context():
+    info = getConnectionInfo()
+    with SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) as conn:
+        assert conn.connect(info['server_ip'], info['server_port'])
+
+    assert conn.sock is None
diff --git a/python2/tests/SMBConnectionTests/util.py b/python2/tests/SMBConnectionTests/util.py
new file mode 100644
index 00000000..4f52d11c
--- /dev/null
+++ b/python2/tests/SMBConnectionTests/util.py
@@ -0,0 +1,19 @@
+
+import os
+from ConfigParser import SafeConfigParser
+
+def getConnectionInfo():
+    config_filename = os.path.join(os.path.dirname(__file__), os.path.pardir, 'connection.ini')
+    cp = SafeConfigParser()
+    cp.read(config_filename)
+
+    info = {
+        'server_name': cp.get('server', 'name'),
+        'server_ip': cp.get('server', 'ip'),
+        'server_port': cp.getint('server', 'port'),
+        'client_name': cp.get('client', 'name'),
+        'user': cp.get('user', 'name'),
+        'password': cp.get('user', 'password'),
+        'domain': cp.get('user', 'domain')
+    }
+    return info
diff --git a/python2/tests/SMBTwistedTests/__init__.py b/python2/tests/SMBTwistedTests/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/python2/tests/SMBTwistedTests/test_auth.py b/python2/tests/SMBTwistedTests/test_auth.py
new file mode 100644
index 00000000..1e3e09c9
--- /dev/null
+++ b/python2/tests/SMBTwistedTests/test_auth.py
@@ -0,0 +1,77 @@
+
+from nose.twistedtools import reactor, deferred
+from twisted.internet import defer
+from smb.SMBProtocol import SMBProtocolFactory
+from smb import smb_structs
+from util import getConnectionInfo
+
+
+class AuthFactory(SMBProtocolFactory):
+
+    def __init__(self, *args, **kwargs):
+        SMBProtocolFactory.__init__(self, *args, **kwargs)
+        self.d = defer.Deferred()
+        self.d.addBoth(self.testDone)
+
+    def testDone(self, r):
+        if self.instance:
+            self.instance.transport.loseConnection()
+        return r
+
+    def onAuthOK(self):
+        self.d.callback(True)
+
+    def onAuthFailed(self):
+        self.d.callback(False)
+
+
+@deferred(timeout=5.0)
+def test_NTLMv1_auth_SMB1():
+    def result(auth_passed):
+        assert auth_passed
+
+    smb_structs.SUPPORT_SMB2 = False
+    info = getConnectionInfo()
+    factory = AuthFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = False)
+    factory.d.addCallback(result)
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+
+@deferred(timeout=5.0)
+def test_NTLMv2_auth_SMB1():
+    def result(auth_passed):
+        assert auth_passed
+
+    smb_structs.SUPPORT_SMB2 = False
+    info = getConnectionInfo()
+    factory = AuthFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.d.addCallback(result)
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+
+@deferred(timeout=5.0)
+def test_NTLMv1_auth_SMB2():
+    def result(auth_passed):
+        assert auth_passed
+
+    smb_structs.SUPPORT_SMB2 = True
+    info = getConnectionInfo()
+    factory = AuthFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = False)
+    factory.d.addCallback(result)
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+
+@deferred(timeout=5.0)
+def test_NTLMv2_auth_SMB2():
+    def result(auth_passed):
+        assert auth_passed
+
+    smb_structs.SUPPORT_SMB2 = True
+    info = getConnectionInfo()
+    factory = AuthFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.d.addCallback(result)
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
diff --git a/python2/tests/SMBTwistedTests/test_createdeletedirectory.py b/python2/tests/SMBTwistedTests/test_createdeletedirectory.py
new file mode 100644
index 00000000..508f43c6
--- /dev/null
+++ b/python2/tests/SMBTwistedTests/test_createdeletedirectory.py
@@ -0,0 +1,99 @@
+# -*- coding: utf-8 -*-
+
+import os, random, time
+from nose.twistedtools import reactor, deferred
+from twisted.internet import defer
+from smb.SMBProtocol import SMBProtocolFactory
+from smb import smb_structs
+from util import getConnectionInfo
+
+
+class DirectoryFactory(SMBProtocolFactory):
+
+    def __init__(self, *args, **kwargs):
+        SMBProtocolFactory.__init__(self, *args, **kwargs)
+        self.d = defer.Deferred()
+        self.d.addBoth(self.testDone)
+        self.service_name = ''
+        self.path = ''
+
+    def testDone(self, r):
+        if self.instance:
+            self.instance.transport.loseConnection()
+        return r
+
+    def createDone(self, result):
+        d = self.listPath(self.service_name, os.path.dirname(self.path.replace('/', os.sep)))
+        d.addCallback(self.listComplete)
+        d.addErrback(self.d.errback)
+
+    def listComplete(self, entries):
+        names = map(lambda e: e.filename, entries)
+        assert os.path.basename(self.path.replace('/', os.sep)) in names
+
+        d = self.deleteDirectory(self.service_name, self.path)
+        d.addCallback(self.deleteDone)
+        d.addErrback(self.d.errback)
+
+    def deleteDone(self, result):
+        d = self.listPath(self.service_name, os.path.dirname(self.path.replace('/', os.sep)))
+        d.addCallback(self.list2Complete)
+        d.addErrback(self.d.errback)
+
+    def list2Complete(self, entries):
+        names = map(lambda e: e.filename, entries)
+        assert os.path.basename(self.path.replace('/', os.sep)) not in names
+        self.d.callback(True)
+
+    def onAuthOK(self):
+        d = self.createDirectory(self.service_name, self.path)
+        d.addCallback(self.createDone)
+        d.addErrback(self.d.errback)
+
+    def onAuthFailed(self):
+        self.d.errback('Auth failed')
+
+
+@deferred(timeout=15.0)
+def test_english_directory_SMB1():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = False
+
+    factory = DirectoryFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service_name = 'smbtest'
+    factory.path = os.sep + 'TestDir %d-%d' % ( time.time(), random.randint(0, 1000) )
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=15.0)
+def test_english_directory_SMB2():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = True
+
+    factory = DirectoryFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service_name = 'smbtest'
+    factory.path = os.sep + 'TestDir %d-%d' % ( time.time(), random.randint(0, 1000) )
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=15.0)
+def test_unicode_directory_SMB1():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = False
+
+    factory = DirectoryFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service_name = 'smbtest'
+    factory.path = os.sep + u'文件夹创建 %d-%d' % ( time.time(), random.randint(0, 1000) )
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=15.0)
+def test_unicode_directory_SMB2():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = True
+
+    factory = DirectoryFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service_name = 'smbtest'
+    factory.path = os.sep + u'文件夹创建 %d-%d' % ( time.time(), random.randint(0, 1000) )
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
diff --git a/python2/tests/SMBTwistedTests/test_echo.py b/python2/tests/SMBTwistedTests/test_echo.py
new file mode 100644
index 00000000..a60bad98
--- /dev/null
+++ b/python2/tests/SMBTwistedTests/test_echo.py
@@ -0,0 +1,39 @@
+
+from nose.twistedtools import reactor, deferred
+from twisted.internet import defer
+from smb.SMBProtocol import SMBProtocolFactory
+from util import getConnectionInfo
+
+
+class EchoFactory(SMBProtocolFactory):
+
+    def __init__(self, *args, **kwargs):
+        SMBProtocolFactory.__init__(self, *args, **kwargs)
+        self.d = defer.Deferred()
+        self.d.addBoth(self.testDone)
+        self.echo_data = 'This is an echo test'
+
+    def testDone(self, r):
+        if self.instance:
+            self.instance.transport.loseConnection()
+        return r
+
+    def onAuthOK(self):
+        def cb(data):
+            assert data == self.echo_data
+            self.d.callback(True)
+
+        d = self.echo(self.echo_data)
+        d.addCallback(cb)
+        d.addErrback(self.d.errback)
+
+    def onAuthFailed(self):
+        self.d.errback('Auth failed')
+
+
+@deferred(timeout=15.0)
+def test_echo():
+    info = getConnectionInfo()
+    factory = EchoFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
diff --git a/python2/tests/SMBTwistedTests/test_getattributes.py b/python2/tests/SMBTwistedTests/test_getattributes.py
new file mode 100644
index 00000000..f84450b6
--- /dev/null
+++ b/python2/tests/SMBTwistedTests/test_getattributes.py
@@ -0,0 +1,100 @@
+
+from nose.twistedtools import reactor, deferred
+from twisted.internet import defer
+from smb.SMBProtocol import SMBProtocolFactory
+from smb import smb_structs
+from util import getConnectionInfo
+
+
+class GetAttributesFactory(SMBProtocolFactory):
+
+    def __init__(self, *args, **kwargs):
+        SMBProtocolFactory.__init__(self, *args, **kwargs)
+        self.d = defer.Deferred()
+        self.d.addBoth(self.testDone)
+        self.path = ''
+        self.is_directory = False
+
+    def testDone(self, r):
+        if self.instance:
+            self.instance.transport.loseConnection()
+        return r
+
+    def onAuthOK(self):
+        def cb(info):
+            assert info.isDirectory == self.is_directory
+            self.d.callback(True)
+
+        d = self.getAttributes('smbtest', self.path, timeout = 15)
+        d.addCallback(cb)
+        d.addErrback(self.d.errback)
+
+    def onAuthFailed(self):
+        self.d.errback('Auth failed')
+
+
+@deferred(timeout=15.0)
+def test_getAttributes_SMB1_test1():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = False
+
+    factory = GetAttributesFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.path = '/Test Folder with Long Name/'
+    factory.is_directory = True
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=15.0)
+def test_getAttributes_SMB1_test2():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = False
+
+    factory = GetAttributesFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.path = '/rfc1001.txt'
+    factory.is_directory = False
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=15.0)
+def test_getAttributes_SMB1_test3():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = False
+
+    factory = GetAttributesFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.path = u'/\u6d4b\u8bd5\u6587\u4ef6\u5939'
+    factory.is_directory = True
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=15.0)
+def test_getAttributes_SMB2_test1():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = True
+
+    factory = GetAttributesFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.path = '/Test Folder with Long Name/'
+    factory.is_directory = True
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=15.0)
+def test_getAttributes_SMB2_test2():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = True
+
+    factory = GetAttributesFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.path = '/rfc1001.txt'
+    factory.is_directory = False
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=15.0)
+def test_getAttributes_SMB2_test3():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = True
+
+    factory = GetAttributesFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.path = u'/\u6d4b\u8bd5\u6587\u4ef6\u5939'
+    factory.is_directory = True
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
diff --git a/python2/tests/SMBTwistedTests/test_listpath.py b/python2/tests/SMBTwistedTests/test_listpath.py
new file mode 100644
index 00000000..d00aebd5
--- /dev/null
+++ b/python2/tests/SMBTwistedTests/test_listpath.py
@@ -0,0 +1,56 @@
+
+from nose.twistedtools import reactor, deferred
+from twisted.internet import defer
+from smb.SMBProtocol import SMBProtocolFactory
+from smb import smb_structs
+from util import getConnectionInfo
+
+
+class ListPathFactory(SMBProtocolFactory):
+
+    def __init__(self, *args, **kwargs):
+        SMBProtocolFactory.__init__(self, *args, **kwargs)
+        self.d = defer.Deferred()
+        self.d.addBoth(self.testDone)
+
+    def testDone(self, r):
+        if self.instance:
+            self.instance.transport.loseConnection()
+        return r
+
+    def onAuthOK(self):
+        def cb(results):
+            filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+            assert ( u'\u6d4b\u8bd5\u6587\u4ef6\u5939', True ) in filenames  # Test non-English folder names
+            assert ( u'Test Folder with Long Name', True ) in filenames      # Test long English folder names
+            assert ( u'TestDir1', True ) in filenames                        # Test short English folder names
+            assert ( u'Implementing CIFS - SMB.html', False ) in filenames   # Test long English file names
+            assert ( u'rfc1001.txt', False ) in filenames                    # Test short English file names
+
+            self.d.callback(True)
+
+        d = self.listPath('smbtest', '/', timeout = 15)
+        d.addCallback(cb)
+        d.addErrback(self.d.errback)
+
+    def onAuthFailed(self):
+        self.d.errback('Auth failed')
+
+
+@deferred(timeout=15.0)
+def test_listPath_SMB1():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = False
+
+    factory = ListPathFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=15.0)
+def test_listPath_SMB2():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = True
+
+    factory = ListPathFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
diff --git a/python2/tests/SMBTwistedTests/test_listshares.py b/python2/tests/SMBTwistedTests/test_listshares.py
new file mode 100644
index 00000000..a787ab21
--- /dev/null
+++ b/python2/tests/SMBTwistedTests/test_listshares.py
@@ -0,0 +1,51 @@
+
+from nose.twistedtools import reactor, deferred
+from twisted.internet import defer
+from smb.SMBProtocol import SMBProtocolFactory
+from smb import smb_structs
+from util import getConnectionInfo
+
+
+class ListSharesFactory(SMBProtocolFactory):
+
+    def __init__(self, *args, **kwargs):
+        SMBProtocolFactory.__init__(self, *args, **kwargs)
+        self.d = defer.Deferred()
+        self.d.addBoth(self.testDone)
+
+    def testDone(self, r):
+        if self.instance:
+            self.instance.transport.loseConnection()
+        return r
+
+    def onAuthOK(self):
+        def cb(results):
+            assert 'smbtest' in map(lambda r: r.name.lower(), results)
+            self.d.callback(True)
+            self.instance.transport.loseConnection()
+
+        d = self.listShares(timeout = 15)
+        d.addCallback(cb)
+        d.addErrback(self.d.errback)
+
+    def onAuthFailed(self):
+        self.d.errback('Auth failed')
+
+
+@deferred(timeout=15.0)
+def test_listshares_SMB1():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = False
+
+    factory = ListSharesFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=15.0)
+def test_listshares_SMB2():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = True
+
+    factory = ListSharesFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
diff --git a/python2/tests/SMBTwistedTests/test_listsnapshots.py b/python2/tests/SMBTwistedTests/test_listsnapshots.py
new file mode 100644
index 00000000..339599a7
--- /dev/null
+++ b/python2/tests/SMBTwistedTests/test_listsnapshots.py
@@ -0,0 +1,57 @@
+
+from nose.twistedtools import reactor, deferred
+from twisted.internet import defer
+from smb.SMBProtocol import SMBProtocolFactory
+from smb import smb_structs
+from util import getConnectionInfo
+
+
+class ListSnapshotsFactory(SMBProtocolFactory):
+
+    def __init__(self, *args, **kwargs):
+        SMBProtocolFactory.__init__(self, *args, **kwargs)
+        self.d = defer.Deferred()
+        self.d.addBoth(self.testDone)
+        self.service_name = None
+        self.path = None
+
+    def testDone(self, r):
+        if self.instance:
+            self.instance.transport.loseConnection()
+        return r
+
+    def onAuthOK(self):
+        def cb(results):
+            assert len(results) > 0
+            self.d.callback(True)
+            self.instance.transport.loseConnection()
+
+        d = self.listSnapshots(self.service_name, self.path, timeout = 15)
+        d.addCallback(cb)
+        d.addErrback(self.d.errback)
+
+    def onAuthFailed(self):
+        self.d.errback('Auth failed')
+
+
+@deferred(timeout=15.0)
+def test_listshares_SMB1():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = False
+
+    factory = ListSnapshotsFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service_name = 'smbtest'
+    factory.path = '/rfc1001.txt'
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=15.0)
+def test_listshares_SMB2():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = True
+
+    factory = ListSnapshotsFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service_name = 'smbtest'
+    factory.path = '/rfc1001.txt'
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
diff --git a/python2/tests/SMBTwistedTests/test_rename.py b/python2/tests/SMBTwistedTests/test_rename.py
new file mode 100644
index 00000000..3e5d80b6
--- /dev/null
+++ b/python2/tests/SMBTwistedTests/test_rename.py
@@ -0,0 +1,174 @@
+# -*- coding: utf-8 -*-
+
+import os, random, time
+from StringIO import StringIO
+from nose.twistedtools import reactor, deferred
+from twisted.internet import defer
+from smb.SMBProtocol import SMBProtocolFactory
+from smb import smb_structs
+from util import getConnectionInfo
+
+
+class RenameFactory(SMBProtocolFactory):
+
+    def __init__(self, *args, **kwargs):
+        SMBProtocolFactory.__init__(self, *args, **kwargs)
+        self.d = defer.Deferred()
+        self.d.addBoth(self.testDone)
+        self.service = ''
+        self.new_path = ''
+        self.old_path = ''
+
+    def testDone(self, r):
+        if self.instance:
+            self.instance.transport.loseConnection()
+        return r
+
+    def pathCreated(self, result):
+        d = self.listPath(self.service, os.path.dirname(self.old_path.replace('/', os.sep)))
+        d.addCallback(self.listComplete)
+        d.addErrback(self.d.errback)
+
+    def listComplete(self, entries):
+        filenames = map(lambda e: e.filename, entries)
+        assert os.path.basename(self.old_path.replace('/', os.sep)) in filenames
+        assert os.path.basename(self.new_path.replace('/', os.sep)) not in filenames
+
+        d = self.rename(self.service, self.old_path, self.new_path)
+        d.addCallback(self.renameComplete)
+        d.addErrback(self.d.errback)
+
+    def renameComplete(self, result):
+        d = self.listPath(self.service, os.path.dirname(self.new_path.replace('/', os.sep)))
+        d.addCallback(self.list2Complete)
+        d.addErrback(self.d.errback)
+
+    def list2Complete(self, entries):
+        filenames = map(lambda e: e.filename, entries)
+        assert os.path.basename(self.new_path.replace('/', os.sep)) in filenames
+        assert os.path.basename(self.old_path.replace('/', os.sep)) not in filenames
+        self.cleanup()
+
+    def onAuthFailed(self):
+        self.d.errback('Auth failed')
+
+
+class RenameFileFactory(RenameFactory):
+
+    def onAuthOK(self):
+        d = self.storeFile(self.service, self.old_path, StringIO('Rename file test'))
+        d.addCallback(self.pathCreated)
+        d.addErrback(self.d.errback)
+
+    def cleanup(self):
+        d = self.deleteFiles(self.service, self.new_path)
+        d.chainDeferred(self.d)
+
+
+class RenameDirectoryFactory(RenameFactory):
+
+    def onAuthOK(self):
+        d = self.createDirectory(self.service, self.old_path)
+        d.addCallback(self.pathCreated)
+        d.addErrback(self.d.errback)
+
+    def cleanup(self):
+        d = self.deleteDirectory(self.service, self.new_path)
+        d.chainDeferred(self.d)
+
+
+@deferred(timeout=30.0)
+def test_rename_english_file_SMB1():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = False
+
+    factory = RenameFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.old_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    factory.new_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_rename_english_file_SMB2():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = True
+
+    factory = RenameFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.old_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    factory.new_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_rename_unicode_file_SMB1():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = False
+
+    factory = RenameFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.old_path = u'/改名测试 %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    factory.new_path = u'/改名测试 %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_rename_unicode_file_SMB2():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = True
+
+    factory = RenameFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.old_path = u'/改名测试 %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    factory.new_path = u'/改名测试 %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_rename_english_directory_SMB1():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = False
+
+    factory = RenameDirectoryFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.old_path = '/RenameTest %d-%d' % ( time.time(), random.randint(1000, 9999) )
+    factory.new_path = '/RenameTest %d-%d' % ( time.time(), random.randint(1000, 9999) )
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_rename_english_directory_SMB2():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = True
+
+    factory = RenameDirectoryFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.old_path = '/RenameTest %d-%d' % ( time.time(), random.randint(1000, 9999) )
+    factory.new_path = '/RenameTest %d-%d' % ( time.time(), random.randint(1000, 9999) )
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_rename_unicode_directory_SMB1():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = False
+
+    factory = RenameDirectoryFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.old_path = u'/改名测试 %d-%d' % ( time.time(), random.randint(1000, 9999) )
+    factory.new_path = u'/改名测试 %d-%d' % ( time.time(), random.randint(1000, 9999) )
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_rename_unicode_directory_SMB2():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = True
+
+    factory = RenameDirectoryFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.old_path = u'/改名测试 %d-%d' % ( time.time(), random.randint(1000, 9999) )
+    factory.new_path = u'/改名测试 %d-%d' % ( time.time(), random.randint(1000, 9999) )
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
diff --git a/python2/tests/SMBTwistedTests/test_retrievefile.py b/python2/tests/SMBTwistedTests/test_retrievefile.py
new file mode 100644
index 00000000..476f09ae
--- /dev/null
+++ b/python2/tests/SMBTwistedTests/test_retrievefile.py
@@ -0,0 +1,278 @@
+# -*- coding: utf-8 -*-
+
+import os, tempfile
+from nose.twistedtools import reactor, deferred
+from twisted.internet import defer
+from smb.SMBProtocol import SMBProtocolFactory
+from smb import smb_structs
+from util import getConnectionInfo
+
+try:
+    import hashlib
+    def MD5(): return hashlib.md5()
+except ImportError:
+    import md5
+    def MD5(): return md5.new()
+
+
+class RetrieveFileFactory(SMBProtocolFactory):
+
+    def __init__(self, *args, **kwargs):
+        SMBProtocolFactory.__init__(self, *args, **kwargs)
+        self.d = defer.Deferred()
+        self.d.addBoth(self.testDone)
+        self.temp_fh = tempfile.NamedTemporaryFile(prefix = 'pysmbtest-')
+        self.service = ''
+        self.path = ''
+        self.digest = ''
+        self.offset = 0
+        self.max_length = -1
+        self.filesize = 0
+
+    def testDone(self, r):
+        if self.instance:
+            self.instance.transport.loseConnection()
+        return r
+
+    def fileRetrieved(self, write_result):
+        file_obj, file_attributes, file_size = write_result
+        assert file_obj == self.temp_fh
+
+        md = MD5()
+        filesize = 0
+        self.temp_fh.seek(0)
+        while True:
+            s = self.temp_fh.read(8192)
+            if not s:
+                break
+            md.update(s)
+            filesize += len(s)
+
+        assert self.filesize == filesize
+        assert md.hexdigest() == self.digest
+
+        self.temp_fh.close()
+        self.d.callback(True)
+        self.instance.transport.loseConnection()
+
+    def onAuthOK(self):
+        assert self.service
+        assert self.path
+
+        d = self.retrieveFileFromOffset(self.service, self.path, self.temp_fh, self.offset, self.max_length, timeout = 15)
+        d.addCallback(self.fileRetrieved)
+        d.addErrback(self.d.errback)
+
+    def onAuthFailed(self):
+        self.d.errback('Auth failed')
+
+
+@deferred(timeout=30.0)
+def test_retr_multiplereads_SMB1():
+    # Test file retrieval using multiple ReadAndx calls (assuming each call will not reach more than 65534 bytes)
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = False
+
+    factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.path = '/rfc1001.txt'
+    factory.digest = '5367c2bbf97f521059c78eab65309ad3'
+    factory.filesize = 158437
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_retr_multiplereads_SMB2():
+    # Test file retrieval using multiple ReadAndx calls (assuming each call will not reach more than 65534 bytes)
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = True
+
+    factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.path = '/rfc1001.txt'
+    factory.digest = '5367c2bbf97f521059c78eab65309ad3'
+    factory.filesize = 158437
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_retr_longfilename_SMB1():
+    # Test file retrieval that has a long English filename
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = False
+
+    factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.path = '/Implementing CIFS - SMB.html'
+    factory.digest = '671c5700d279fcbbf958c1bba3c2639e'
+    factory.filesize = 421269
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_retr_longfilename_SMB2():
+    # Test file retrieval that has a long English filename
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = True
+
+    factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.path = '/Implementing CIFS - SMB.html'
+    factory.digest = '671c5700d279fcbbf958c1bba3c2639e'
+    factory.filesize = 421269
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_retr_unicodefilename_SMB1():
+    # Test file retrieval that has a long non-English filename inside a folder with a non-English name
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = False
+
+    factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.path = u'/测试文件夹/垃圾文件.dat'
+    factory.digest = '8a44c1e80d55e91c92350955cdf83442'
+    factory.filesize = 256000
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_retr_unicodefilename_SMB2():
+    # Test file retrieval that has a long non-English filename inside a folder with a non-English name
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = True
+
+    factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.path = u'/测试文件夹/垃圾文件.dat'
+    factory.digest = '8a44c1e80d55e91c92350955cdf83442'
+    factory.filesize = 256000
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_retr_offset_SMB1():
+    # Test file retrieval from offset to EOF
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = False
+
+    factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.path = u'/测试文件夹/垃圾文件.dat'
+    factory.digest = 'a141bd8024571ce7cb5c67f2b0d8ea0b'
+    factory.filesize = 156000
+    factory.offset = 100000
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_retr_offset_SMB2():
+    # Test file retrieval from offset to EOF
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = True
+
+    factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.path = u'/测试文件夹/垃圾文件.dat'
+    factory.digest = 'a141bd8024571ce7cb5c67f2b0d8ea0b'
+    factory.filesize = 156000
+    factory.offset = 100000
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_retr_offset_and_biglimit_SMB1():
+    # Test file retrieval from offset with a big max_length
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = False
+
+    factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.path = u'/测试文件夹/垃圾文件.dat'
+    factory.digest = '83b7afd7c92cdece3975338b5ca0b1c5'
+    factory.filesize = 100000
+    factory.offset = 100000
+    factory.max_length = 100000
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_retr_offset_and_biglimit_SMB2():
+    # Test file retrieval from offset with a big max_length
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = True
+
+    factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.path = u'/测试文件夹/垃圾文件.dat'
+    factory.digest = '83b7afd7c92cdece3975338b5ca0b1c5'
+    factory.filesize = 100000
+    factory.offset = 100000
+    factory.max_length = 100000
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_retr_offset_and_smalllimit_SMB1():
+    # Test file retrieval from offset with a small max_length
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = False
+
+    factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.path = u'/测试文件夹/垃圾文件.dat'
+    factory.digest = '746f60a96b39b712a7b6e17ddde19986'
+    factory.filesize = 10
+    factory.offset = 100000
+    factory.max_length = 10
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_retr_offset_and_smalllimit_SMB2():
+    # Test file retrieval from offset with a small max_length
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = True
+
+    factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.path = u'/测试文件夹/垃圾文件.dat'
+    factory.digest = '746f60a96b39b712a7b6e17ddde19986'
+    factory.filesize = 10
+    factory.offset = 100000
+    factory.max_length = 10
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_retr_offset_and_zerolimit_SMB1():
+    # Test file retrieval from offset to EOF with max_length=0
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = False
+
+    factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.path = u'/测试文件夹/垃圾文件.dat'
+    factory.digest = 'd41d8cd98f00b204e9800998ecf8427e'
+    factory.filesize = 0
+    factory.offset = 100000
+    factory.max_length = 0
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_retr_offset_and_zerolimit_SMB2():
+    # Test file retrieval from offset to EOF with max_length=0
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = True
+    
+    factory = RetrieveFileFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.path = u'/测试文件夹/垃圾文件.dat'
+    factory.digest = 'd41d8cd98f00b204e9800998ecf8427e'
+    factory.filesize = 0
+    factory.offset = 100000
+    factory.max_length = 0
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
diff --git a/python2/tests/SMBTwistedTests/test_storefile.py b/python2/tests/SMBTwistedTests/test_storefile.py
new file mode 100644
index 00000000..8d639f71
--- /dev/null
+++ b/python2/tests/SMBTwistedTests/test_storefile.py
@@ -0,0 +1,141 @@
+# -*- coding: utf-8 -*-
+
+import os, time, random
+from StringIO import StringIO
+from nose.twistedtools import reactor, deferred
+from twisted.internet import defer
+from smb.SMBProtocol import SMBProtocolFactory
+from smb import smb_structs
+from util import getConnectionInfo
+
+try:
+    import hashlib
+    def MD5(): return hashlib.md5()
+except ImportError:
+    import md5
+    def MD5(): return md5.new()
+
+class StoreFilesFactory(SMBProtocolFactory):
+    """
+    A super test factory that tests store file, list files, retrieve file and delete file functionlities in sequence.
+    """
+
+    TEST_FILENAME = os.path.join(os.path.dirname(__file__), os.pardir, 'SupportFiles', 'binary.dat')
+    TEST_FILESIZE = 256000
+    TEST_DIGEST = 'bb6303f76e29f354b6fdf6ef58587e48'
+
+    def __init__(self, *args, **kwargs):
+        SMBProtocolFactory.__init__(self, *args, **kwargs)
+        self.d = defer.Deferred()
+        self.d.addBoth(self.testDone)
+        self.service_name = ''
+        self.filename = ''
+
+    def testDone(self, r):
+        if self.instance:
+            self.instance.transport.loseConnection()
+        return r
+
+    def storeComplete(self, result):
+        file_obj, filesize = result
+        file_obj.close()
+        assert filesize == self.TEST_FILESIZE
+
+        d = self.listPath(self.service_name, os.path.dirname(self.filename.replace('/', os.sep)))
+        d.addCallback(self.listComplete)
+        d.addErrback(self.d.errback)
+
+    def listComplete(self, entries):
+        filenames = map(lambda e: e.filename, entries)
+        assert os.path.basename(self.filename.replace('/', os.sep)) in filenames
+
+        for entry in entries:
+            if os.path.basename(self.filename.replace('/', os.sep)) == entry.filename:
+                # The following asserts will fail if the remote machine's time is not in sync with the test machine's time
+                assert abs(entry.create_time - time.time()) < 3
+                assert abs(entry.last_access_time - time.time()) < 3
+                assert abs(entry.last_write_time - time.time()) < 3
+                assert abs(entry.last_attr_change_time - time.time()) < 3
+                break
+
+        d = self.retrieveFile(self.service_name, self.filename, StringIO())
+        d.addCallback(self.retrieveComplete)
+        d.addErrback(self.d.errback)
+
+    def retrieveComplete(self, result):
+        file_obj, file_attributes, file_size = result
+
+        md = MD5()
+        md.update(file_obj.getvalue())
+        file_obj.close()
+
+        assert file_size == self.TEST_FILESIZE
+        assert md.hexdigest() == self.TEST_DIGEST
+
+        d = self.deleteFiles(self.service_name, self.filename)
+        d.addCallback(self.deleteComplete)
+        d.addErrback(self.d.errback)
+
+    def deleteComplete(self, result):
+        d = self.listPath(self.service_name, os.path.dirname(self.filename.replace('/', os.sep)))
+        d.addCallback(self.list2Complete)
+        d.addErrback(self.d.errback)
+
+    def list2Complete(self, entries):
+        filenames = map(lambda e: e.filename, entries)
+        assert os.path.basename(self.filename.replace('/', os.sep)) not in filenames
+        self.d.callback(True)
+        self.instance.transport.loseConnection()
+
+    def onAuthOK(self):
+        d = self.storeFile(self.service_name, self.filename, open(self.TEST_FILENAME, 'rb'))
+        d.addCallback(self.storeComplete)
+        d.addErrback(self.d.errback)
+
+    def onAuthFailed(self):
+        self.d.errback('Auth failed')
+
+
+@deferred(timeout=30.0)
+def test_store_long_filename_SMB1():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = False
+
+    factory = StoreFilesFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service_name = 'smbtest'
+    factory.filename = os.sep + 'StoreTest %d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_store_long_filename_SMB2():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = True
+
+    factory = StoreFilesFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service_name = 'smbtest'
+    factory.filename = os.sep + 'StoreTest %d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_store_unicode_filename_SMB1():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = False
+
+    factory = StoreFilesFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service_name = 'smbtest'
+    factory.filename = os.sep + u'上载测试 %d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
+
+@deferred(timeout=30.0)
+def test_store_unicode_filename_SMB2():
+    info = getConnectionInfo()
+    smb_structs.SUPPORT_SMB2 = True
+
+    factory = StoreFilesFactory(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    factory.service_name = 'smbtest'
+    factory.filename = os.sep + u'上载测试 %d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+    reactor.connectTCP(info['server_ip'], info['server_port'], factory)
+    return factory.d
diff --git a/python2/tests/SMBTwistedTests/util.py b/python2/tests/SMBTwistedTests/util.py
new file mode 100644
index 00000000..1c8fe895
--- /dev/null
+++ b/python2/tests/SMBTwistedTests/util.py
@@ -0,0 +1,18 @@
+
+import os
+from ConfigParser import SafeConfigParser
+
+def getConnectionInfo():
+    config_filename = os.path.join(os.path.dirname(__file__), os.path.pardir, 'connection.ini')
+    cp = SafeConfigParser()
+    cp.read(config_filename)
+
+    info = {
+        'server_name': cp.get('server', 'name'),
+        'server_ip': cp.get('server', 'ip'),
+        'server_port': cp.getint('server', 'port'),
+        'client_name': cp.get('client', 'name'),
+        'user': cp.get('user', 'name'),
+        'password': cp.get('user', 'password'),
+    }
+    return info
diff --git a/python2/tests/SupportFiles/binary.dat b/python2/tests/SupportFiles/binary.dat
new file mode 100644
index 00000000..f2b3f581
Binary files /dev/null and b/python2/tests/SupportFiles/binary.dat differ
diff --git a/python2/tests/__init__.py b/python2/tests/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/python2/tests/connection.ini b/python2/tests/connection.ini
new file mode 100644
index 00000000..d8d249de
--- /dev/null
+++ b/python2/tests/connection.ini
@@ -0,0 +1,14 @@
+
+[server]
+name = SERVER
+ip = 192.168.1.1
+port = 139
+direct_port = 445
+
+[client]
+name = TESTCLIENT
+
+[user]
+name = myuser
+password = mypassword
+domain =
diff --git a/python2/tests/test_ntlm.py b/python2/tests/test_ntlm.py
new file mode 100644
index 00000000..0624304c
--- /dev/null
+++ b/python2/tests/test_ntlm.py
@@ -0,0 +1,47 @@
+
+import binascii
+from smb import ntlm
+
+def test_NTLMv1_without_extended_security():
+    password = 'Password'
+    server_challenge = '\x01\x23\x45\x67\x89\xab\xcd\xef'
+
+    nt_challenge_response, lm_challenge_response, session_key = ntlm.generateChallengeResponseV1(password,
+                                                                                                 server_challenge,
+                                                                                                 has_extended_security = False,
+                                                                                                 client_challenge = '\xAA'*8)
+
+    assert binascii.hexlify(nt_challenge_response).lower() == '67 c4 30 11 f3 02 98 a2 ad 35 ec e6 4f 16 33 1c 44 bd be d9 27 84 1f 94'.replace(' ', '')  # [MS-NLMP]: 4.2.2.2.1
+    assert binascii.hexlify(lm_challenge_response).lower() == '98 de f7 b8 7f 88 aa 5d af e2 df 77 96 88 a1 72 de f1 1c 7d 5c cd ef 13'.replace(' ', '')  # [MS-NLMP]: 4.2.2.2.2
+
+
+def test_NTLMv1_with_extended_security():
+    password = 'Password'
+    server_challenge = '\x01\x23\x45\x67\x89\xab\xcd\xef'
+
+    nt_challenge_response, lm_challenge_response, session_key = ntlm.generateChallengeResponseV1(password,
+                                                                                                 server_challenge,
+                                                                                                 has_extended_security = True,
+                                                                                                 client_challenge = '\xAA'*8)
+
+    assert binascii.hexlify(nt_challenge_response).lower() == '75 37 f8 03 ae 36 71 28 ca 45 82 04 bd e7 ca f8 1e 97 ed 26 83 26 72 32'.replace(' ', '')  # [MS-NLMP]: 4.2.3.2.2
+    assert binascii.hexlify(lm_challenge_response).lower() == 'aa aa aa aa aa aa aa aa 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00'.replace(' ', '')  # [MS-NLMP]: 4.2.3.2.1
+
+
+def test_NTLMv2():
+    user = 'User'
+    password = 'Password'
+    domain = 'Domain'
+    server_challenge = '\x01\x23\x45\x67\x89\xab\xcd\xef'
+
+    server_avpair = binascii.unhexlify('01 00 0c 00 53 00 65 00 72 00 76 00 65 00 72 00'.replace(' ', ''))
+    domain_avpair = binascii.unhexlify('02 00 0c 00 44 00 6f 00 6d 00 61 00 69 00 6e 00'.replace(' ', ''))
+
+    nt_challenge_response, lm_challenge_response, session_key = ntlm.generateChallengeResponseV2(password,
+                                                                                                 user,
+                                                                                                 server_challenge,
+                                                                                                 server_avpair + domain_avpair + '\0'*4,
+                                                                                                 domain,
+                                                                                                 client_challenge = '\xAA'*8)
+
+    assert binascii.hexlify(lm_challenge_response).lower() == '86 c3 50 97 ac 9c ec 10 25 54 76 4a 57 cc cc 19 aa aa aa aa aa aa aa aa'.replace(' ', '')  # [MS-NLMP]: 4.2.4.2.1
diff --git a/python2/tests/test_security_descriptors.py b/python2/tests/test_security_descriptors.py
new file mode 100644
index 00000000..f81be4ba
--- /dev/null
+++ b/python2/tests/test_security_descriptors.py
@@ -0,0 +1,139 @@
+import binascii
+
+from smb import security_descriptors as sd
+from smb import smb_constants as sc
+
+
+def test_sid_string_representation():
+    sid = sd.SID(1, 5, [2, 3, 4])
+    assert str(sid) == "S-1-5-2-3-4"
+    sid = sd.SID(1, 2**32 + 3, [])
+    assert str(sid) == "S-1-0x100000003"
+    sid = sd.SID(1, 2**32, [3, 2, 1])
+    assert str(sid) == "S-1-0x100000000-3-2-1"
+
+
+def test_sid_binary_parsing():
+    raw_sid = binascii.unhexlify("""
+        01 05 00 00 00 00 00 05  15 00 00 00 de 53 c1 2a
+        2a 4f da ca c1 79 a6 32  b1 04 00 00
+    """.translate(None, ' \n'))
+    assert str(sd.SID.from_bytes(raw_sid)) == "S-1-5-21-717312990-3403304746-849770945-1201"
+    raw_sid += "garbage"
+    assert str(sd.SID.from_bytes(raw_sid)) == "S-1-5-21-717312990-3403304746-849770945-1201"
+    sid, tail = sd.SID.from_bytes(raw_sid, return_tail=True)
+    assert str(sid) == "S-1-5-21-717312990-3403304746-849770945-1201"
+    assert tail == "garbage"
+
+
+def test_ace_binary_parsing():
+    raw_ace = binascii.unhexlify("""
+        00 10 24 00 ff 01 1f 00  01 05 00 00 00 00 00 05
+        15 00 00 00 de 53 c1 2a  2a 4f da ca c1 79 a6 32
+        6e 04 00 00
+    """.translate(None, ' \n'))
+    ace = sd.ACE.from_bytes(raw_ace)
+    assert str(ace.sid) == "S-1-5-21-717312990-3403304746-849770945-1134"
+    assert ace.type == sd.ACE_TYPE_ACCESS_ALLOWED
+    assert ace.flags == sd.ACE_FLAG_INHERITED
+    assert ace.mask == (sc.SYNCHRONIZE | sc.WRITE_OWNER | sc.WRITE_DAC
+                        | sc.READ_CONTROL | sc.DELETE | sc.FILE_READ_DATA
+                        | sc.FILE_WRITE_DATA | sc.FILE_APPEND_DATA
+                        | sc.FILE_READ_EA | sc.FILE_WRITE_EA | sc.FILE_EXECUTE
+                        | sc.FILE_DELETE_CHILD | sc.FILE_READ_ATTRIBUTES
+                        | sc.FILE_WRITE_ATTRIBUTES)
+    assert not ace.additional_data
+
+    raw_ace = binascii.unhexlify("""
+        00 13 18 00 a9 00 12 00  01 02 00 00 00 00 00 05
+        20 00 00 00 21 02 00 00
+    """.translate(None, ' \n'))
+    ace = sd.ACE.from_bytes(raw_ace)
+    assert str(ace.sid) == "S-1-5-32-545"
+    assert ace.type == sd.ACE_TYPE_ACCESS_ALLOWED
+    assert ace.flags == (sd.ACE_FLAG_INHERITED | sd.ACE_FLAG_CONTAINER_INHERIT
+                         | sd.ACE_FLAG_OBJECT_INHERIT)
+    assert ace.mask == (sc.SYNCHRONIZE | sc.READ_CONTROL | sc.FILE_READ_DATA
+                        | sc.FILE_READ_EA | sc.FILE_EXECUTE
+                        | sc.FILE_READ_ATTRIBUTES)
+    assert not ace.additional_data
+
+    raw_ace = binascii.unhexlify("""
+        01 03 24 00 a9 00 02 00  01 05 00 00 00 00 00 05
+        15 00 00 00 de 53 c1 2a  2a 4f da ca c1 79 a6 32
+        6c 04 00 00
+    """.translate(None, ' \n'))
+    ace = sd.ACE.from_bytes(raw_ace)
+    assert str(ace.sid) == "S-1-5-21-717312990-3403304746-849770945-1132"
+    assert ace.type == sd.ACE_TYPE_ACCESS_DENIED
+    assert ace.flags == (sd.ACE_FLAG_CONTAINER_INHERIT
+                         | sd.ACE_FLAG_OBJECT_INHERIT)
+    assert ace.mask == (sc.READ_CONTROL | sc.FILE_READ_DATA | sc.FILE_READ_EA
+                        | sc.FILE_EXECUTE | sc.FILE_READ_ATTRIBUTES)
+    assert not ace.additional_data
+
+
+def test_acl_binary_parsing():
+    raw_acl = binascii.unhexlify("""
+        02 00 70 00 04 00 00 00  00 10 18 00 89 00 10 00
+        01 02 00 00 00 00 00 05  20 00 00 00 21 02 00 00
+        00 10 14 00 ff 01 1f 00  01 01 00 00 00 00 00 05
+        12 00 00 00 00 10 18 00  ff 01 1f 00 01 02 00 00
+        00 00 00 05 20 00 00 00  20 02 00 00 00 10 24 00
+        ff 01 1f 00 01 05 00 00  00 00 00 05 15 00 00 00
+        de 53 c1 2a 2a 4f da ca  c1 79 a6 32 b1 04 00 00
+    """.translate(None, ' \n'))
+    acl = sd.ACL.from_bytes(raw_acl)
+    assert acl.revision == 2
+    assert len(acl.aces) == 4
+
+    ace = acl.aces[0]
+    assert ace.type == sd.ACE_TYPE_ACCESS_ALLOWED
+    assert str(ace.sid) == "S-1-5-32-545"
+    assert ace.flags == sd.ACE_FLAG_INHERITED
+    assert ace.mask == (sc.SYNCHRONIZE | sc.FILE_READ_DATA | sc.FILE_READ_EA
+                        | sc.FILE_READ_ATTRIBUTES)
+
+    ace = acl.aces[3]
+    assert ace.type == sd.ACE_TYPE_ACCESS_ALLOWED
+    assert str(ace.sid) == "S-1-5-21-717312990-3403304746-849770945-1201"
+    assert ace.flags == sd.ACE_FLAG_INHERITED
+    assert ace.mask == (sc.SYNCHRONIZE | sc.WRITE_OWNER | sc.WRITE_DAC
+                        | sc.READ_CONTROL | sc.DELETE | sc.FILE_READ_DATA
+                        | sc.FILE_WRITE_DATA | sc.FILE_APPEND_DATA
+                        | sc.FILE_READ_EA | sc.FILE_WRITE_EA | sc.FILE_EXECUTE
+                        | sc.FILE_DELETE_CHILD | sc.FILE_READ_ATTRIBUTES
+                        | sc.FILE_WRITE_ATTRIBUTES)
+
+
+def test_descriptor_binary_parsing():
+    raw_descriptor = binascii.unhexlify("""
+        01 00 04 84 14 00 00 00  30 00 00 00 00 00 00 00
+        4c 00 00 00 01 05 00 00  00 00 00 05 15 00 00 00
+        de 53 c1 2a 2a 4f da ca  c1 79 a6 32 b1 04 00 00
+        01 05 00 00 00 00 00 05  15 00 00 00 de 53 c1 2a
+        2a 4f da ca c1 79 a6 32  01 02 00 00 02 00 70 00
+        04 00 00 00 00 10 18 00  89 00 10 00 01 02 00 00
+        00 00 00 05 20 00 00 00  21 02 00 00 00 10 14 00
+        ff 01 1f 00 01 01 00 00  00 00 00 05 12 00 00 00
+        00 10 18 00 ff 01 1f 00  01 02 00 00 00 00 00 05
+        20 00 00 00 20 02 00 00  00 10 24 00 ff 01 1f 00
+        01 05 00 00 00 00 00 05  15 00 00 00 de 53 c1 2a
+        2a 4f da ca c1 79 a6 32  b1 04 00 00
+    """.translate(None, ' \n'))
+    descriptor = sd.SecurityDescriptor.from_bytes(raw_descriptor)
+    assert descriptor.flags == (sd.SECURITY_DESCRIPTOR_SELF_RELATIVE
+                                | sd.SECURITY_DESCRIPTOR_DACL_PRESENT
+                                | sd.SECURITY_DESCRIPTOR_DACL_AUTO_INHERITED)
+    assert descriptor.dacl is not None
+    assert descriptor.sacl is None
+    assert str(descriptor.owner) == "S-1-5-21-717312990-3403304746-849770945-1201"
+    assert str(descriptor.group) == "S-1-5-21-717312990-3403304746-849770945-513"
+
+    acl = descriptor.dacl
+    assert acl.revision == 2
+    assert len(acl.aces) == 4
+    assert str(acl.aces[0].sid) == sd.SID_BUILTIN_USERS
+    assert str(acl.aces[1].sid) == sd.SID_LOCAL_SYSTEM
+    assert str(acl.aces[2].sid) == sd.SID_BUILTIN_ADMINISTRATORS
+    assert str(acl.aces[3].sid) == "S-1-5-21-717312990-3403304746-849770945-1201"
diff --git a/python2/tests/test_securityblob.py b/python2/tests/test_securityblob.py
new file mode 100644
index 00000000..5f18a4e3
--- /dev/null
+++ b/python2/tests/test_securityblob.py
@@ -0,0 +1,91 @@
+
+import binascii
+from smb import securityblob
+
+
+def test_NTLMSSP_NEGOTIATE_encoding():
+    ntlm_data = binascii.unhexlify('4e544c4d5353500001000000978208e200000000000000000000000000000000060072170000000f')  # The NTLM negotiate message
+    blob = securityblob.generateNegotiateSecurityBlob(ntlm_data)
+
+    TARGET = binascii.unhexlify("""
+60 48 06 06 2b 06 01 05 05 02 a0 3e 30 3c a0 0e
+30 0c 06 0a 2b 06 01 04 01 82 37 02 02 0a a2 2a
+04 28 4e 54 4c 4d 53 53 50 00 01 00 00 00 97 82
+08 e2 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+00 00 06 00 72 17 00 00 00 0f
+""".replace(' ', '').replace('\n', ''))
+
+    assert blob == TARGET
+
+
+def test_NTLMSSP_CHALLENGE_decoding():
+    blob = binascii.unhexlify("""
+a1 81 be 30 81 bb a0 03 0a 01 01 a1 0c 06 0a 2b
+06 01 04 01 82 37 02 02 0a a2 81 a5 04 81 a2 4e
+54 4c 4d 53 53 50 00 02 00 00 00 0a 00 0a 00 38
+00 00 00 15 82 8a e2 32 81 ce 29 7f de 3f 80 00
+00 00 00 00 00 00 00 60 00 60 00 42 00 00 00 06
+01 00 00 00 00 00 0f 43 00 45 00 54 00 55 00 53
+00 02 00 0a 00 43 00 45 00 54 00 55 00 53 00 01
+00 0a 00 43 00 45 00 54 00 55 00 53 00 04 00 16
+00 6c 00 6f 00 63 00 61 00 6c 00 64 00 6f 00 6d
+00 61 00 69 00 6e 00 03 00 22 00 63 00 65 00 74
+00 75 00 73 00 2e 00 6c 00 6f 00 63 00 61 00 6c
+00 64 00 6f 00 6d 00 61 00 69 00 6e 00 00 00 00
+00""".replace(' ', '').replace('\n', ''))
+
+    RESPONSE_TOKENS = binascii.unhexlify("""
+4e 54 4c 4d 53 53 50 00 02 00 00 00 0a 00 0a 00
+38 00 00 00 15 82 8a e2 32 81 ce 29 7f de 3f 80
+00 00 00 00 00 00 00 00 60 00 60 00 42 00 00 00
+06 01 00 00 00 00 00 0f 43 00 45 00 54 00 55 00
+53 00 02 00 0a 00 43 00 45 00 54 00 55 00 53 00
+01 00 0a 00 43 00 45 00 54 00 55 00 53 00 04 00
+16 00 6c 00 6f 00 63 00 61 00 6c 00 64 00 6f 00
+6d 00 61 00 69 00 6e 00 03 00 22 00 63 00 65 00
+74 00 75 00 73 00 2e 00 6c 00 6f 00 63 00 61 00
+6c 00 64 00 6f 00 6d 00 61 00 69 00 6e 00 00 00
+00 00
+""".replace(' ', '').replace('\n', ''))
+
+    result, response_tokens = securityblob.decodeChallengeSecurityBlob(blob)
+
+    assert result == securityblob.RESULT_ACCEPT_INCOMPLETE
+    assert response_tokens == RESPONSE_TOKENS
+
+
+def test_NTLMSSP_AUTH_encoding():
+    ntlm_data = binascii.unhexlify("""
+4e 54 4c 4d 53 53 50 00 03 00 00 00 01 00 01 00
+70 00 00 00 00 00 00 00 71 00 00 00 00 00 00 00
+58 00 00 00 00 00 00 00 58 00 00 00 18 00 18 00
+58 00 00 00 10 00 10 00 71 00 00 00 15 8a 88 e2
+06 00 72 17 00 00 00 0f 06 49 3b c4 f6 2a 2b be
+61 a6 81 e7 cc 58 37 b4 4d 00 49 00 43 00 48 00
+41 00 45 00 4c 00 2d 00 49 00 35 00 50 00 43 00
+00 a7 0d b4 74 c3 d8 14 c9 df 3d 80 6d 87 94 42
+bc
+""".replace(' ', '').replace('\n', ''))
+
+    TARGET = binascii.unhexlify("""
+a1 81 8a 30 81 87 a2 81 84 04 81 81 4e 54 4c 4d
+53 53 50 00 03 00 00 00 01 00 01 00 70 00 00 00
+00 00 00 00 71 00 00 00 00 00 00 00 58 00 00 00
+00 00 00 00 58 00 00 00 18 00 18 00 58 00 00 00
+10 00 10 00 71 00 00 00 15 8a 88 e2 06 00 72 17
+00 00 00 0f 06 49 3b c4 f6 2a 2b be 61 a6 81 e7
+cc 58 37 b4 4d 00 49 00 43 00 48 00 41 00 45 00
+4c 00 2d 00 49 00 35 00 50 00 43 00 00 a7 0d b4
+74 c3 d8 14 c9 df 3d 80 6d 87 94 42 bc
+""".replace(' ', '').replace('\n', ''))
+
+    blob = securityblob.generateAuthSecurityBlob(ntlm_data)
+
+    assert blob == TARGET
+
+
+def test_auth_response_decoding():
+    blob = binascii.unhexlify("a1 07 30 05 a0 03 0a 01 00".replace(' ', ''))
+
+    result = securityblob.decodeAuthResponseSecurityBlob(blob)
+    assert result == securityblob.RESULT_ACCEPT_COMPLETED
diff --git a/python3/nmb/NetBIOS.py b/python3/nmb/NetBIOS.py
new file mode 100644
index 00000000..3a39bae2
--- /dev/null
+++ b/python3/nmb/NetBIOS.py
@@ -0,0 +1,144 @@
+
+import os, logging, random, socket, time, select
+from .base import NBNS, NotConnectedError
+from .nmb_constants import TYPE_CLIENT, TYPE_SERVER, TYPE_WORKSTATION
+
+class NetBIOS(NBNS):
+
+    log = logging.getLogger('NMB.NetBIOS')
+
+    def __init__(self, broadcast = True, listen_port = 0):
+        """
+        Instantiate a NetBIOS instance, and creates a IPv4 UDP socket to listen/send NBNS packets.
+
+        :param boolean broadcast: A boolean flag to indicate if we should setup the listening UDP port in broadcast mode
+        :param integer listen_port: Specifies the UDP port number to bind to for listening. If zero, OS will automatically select a free port number.
+        """
+        self.broadcast = broadcast
+        self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+        if self.broadcast:
+            self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
+        if listen_port:
+            self.sock.bind(( '', listen_port ))
+
+    def close(self):
+        """
+        Close the underlying and free resources.
+
+        The NetBIOS instance should not be used to perform any operations after this method returns.
+
+        :return: None
+        """
+        self.sock.close()
+        self.sock = None
+
+    def write(self, data, ip, port):
+        assert self.sock, 'Socket is already closed'
+        self.sock.sendto(data, ( ip, port ))
+
+    def queryName(self, name, ip = '', port = 137, timeout = 30):
+        """
+        Send a query on the network and hopes that if machine matching the *name* will reply with its IP address.
+
+        :param string ip: If the NBNSProtocol instance was instianted with broadcast=True, then this parameter can be an empty string. We will leave it to the OS to determine an appropriate broadcast address.
+                          If the NBNSProtocol instance was instianted with broadcast=False, then you should provide a target IP to send the query.
+        :param integer port: The NetBIOS-NS port (IANA standard defines this port to be 137). You should not touch this parameter unless you know what you are doing.
+        :param integer/float timeout: Number of seconds to wait for a reply, after which the method will return None
+        :return: A list of IP addresses in dotted notation (aaa.bbb.ccc.ddd). On timeout, returns None.
+        """
+        assert self.sock, 'Socket is already closed'
+
+        trn_id = random.randint(1, 0xFFFF)
+        data = self.prepareNameQuery(trn_id, name)
+        if self.broadcast and not ip:
+            ip = '<broadcast>'
+        elif not ip:
+            self.log.warning('queryName: ip parameter is empty. OS might not transmit this query to the network')
+
+        self.write(data, ip, port)
+
+        return self._pollForNetBIOSPacket(trn_id, timeout)
+
+    def queryIPForName(self, ip, port = 137, timeout = 30):
+        """
+        Send a query to the machine with *ip* and hopes that the machine will reply back with its name.
+
+        The implementation of this function is contributed by Jason Anderson.
+
+        :param string ip: If the NBNSProtocol instance was instianted with broadcast=True, then this parameter can be an empty string. We will leave it to the OS to determine an appropriate broadcast address.
+                          If the NBNSProtocol instance was instianted with broadcast=False, then you should provide a target IP to send the query.
+        :param integer port: The NetBIOS-NS port (IANA standard defines this port to be 137). You should not touch this parameter unless you know what you are doing.
+        :param integer/float timeout: Number of seconds to wait for a reply, after which the method will return None
+        :return: A list of string containing the names of the machine at *ip*. On timeout, returns None.
+        """
+        assert self.sock, 'Socket is already closed'
+
+        trn_id = random.randint(1, 0xFFFF)
+        data = self.prepareNetNameQuery(trn_id, False)
+        self.write(data, ip, port)
+        ret = self._pollForQueryPacket(trn_id, timeout)
+        if ret:
+            return list(map(lambda s: s[0], filter(lambda s: s[1] == TYPE_SERVER, ret)))
+        else:
+            return None
+
+    #
+    # Protected Methods
+    #
+
+    def _pollForNetBIOSPacket(self, wait_trn_id, timeout):
+        end_time = time.time() - timeout
+        while True:
+            try:
+                _timeout = time.time()-end_time
+                if _timeout <= 0:
+                    return None
+
+                ready, _, _ = select.select([ self.sock.fileno() ], [ ], [ ], _timeout)
+                if not ready:
+                    return None
+
+                data, _ = self.sock.recvfrom(0xFFFF)
+                if len(data) == 0:
+                    raise NotConnectedError
+
+                trn_id, ret = self.decodePacket(data)
+
+                if trn_id == wait_trn_id:
+                    return ret
+            except select.error as ex:
+                if type(ex) is tuple:
+                    if ex[0] != errno.EINTR and ex[0] != errno.EAGAIN:
+                        raise ex
+                else:
+                    raise ex
+
+    #
+    # Contributed by Jason Anderson
+    #
+    def _pollForQueryPacket(self, wait_trn_id, timeout):
+        end_time = time.time() - timeout
+        while True:
+            try:
+                _timeout = time.time()-end_time
+                if _timeout <= 0:
+                    return None
+
+                ready, _, _ = select.select([ self.sock.fileno() ], [ ], [ ], _timeout)
+                if not ready:
+                    return None
+
+                data, _ = self.sock.recvfrom(0xFFFF)
+                if len(data) == 0:
+                    raise NotConnectedError
+
+                trn_id, ret = self.decodeIPQueryPacket(data)
+
+                if trn_id == wait_trn_id:
+                    return ret
+            except select.error as ex:
+                if type(ex) is tuple:
+                    if ex[0] != errno.EINTR and ex[0] != errno.EAGAIN:
+                        raise ex
+                else:
+                    raise ex
diff --git a/python3/nmb/NetBIOSProtocol.py b/python3/nmb/NetBIOSProtocol.py
new file mode 100644
index 00000000..9e4bf866
--- /dev/null
+++ b/python3/nmb/NetBIOSProtocol.py
@@ -0,0 +1,134 @@
+
+import os, logging, random, socket, time
+from twisted.internet import reactor, defer
+from twisted.internet.protocol import DatagramProtocol
+from .base import NBNS
+
+class NetBIOSTimeout(Exception):
+    """Raised in NBNSProtocol via Deferred.errback method when queryName method has timeout waiting for reply"""
+    pass
+
+class NBNSProtocol(DatagramProtocol, NBNS):
+
+    log = logging.getLogger('NMB.NBNSProtocol')
+
+    def __init__(self, broadcast = True, listen_port = 0):
+        """
+        Instantiate a NBNSProtocol instance.
+
+        This automatically calls reactor.listenUDP method to start listening for incoming packets, so you **must not** call the listenUDP method again.
+
+        :param boolean broadcast: A boolean flag to indicate if we should setup the listening UDP port in broadcast mode
+        :param integer listen_port: Specifies the UDP port number to bind to for listening. If zero, OS will automatically select a free port number.
+        """
+        self.broadcast = broadcast
+        self.pending_trns = { }  # TRN ID -> ( expiry_time, name, Deferred instance )
+        self.transport = reactor.listenUDP(listen_port, self)
+        if self.broadcast:
+            self.transport.getHandle().setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
+        reactor.callLater(1, self.cleanupPendingTrns)
+
+    def datagramReceived(self, data, from_info):
+        host, port = from_info
+        trn_id, ret = self.decodePacket(data)
+
+        # pending transaction exists for trn_id - handle it and remove from queue
+        if trn_id in self.pending_trns:
+            _, ip, d = self.pending_trns.pop(trn_id)
+            if ip is NAME_QUERY:
+                # decode as query packet
+                trn_id, ret = self.decodeIPQueryPacket(data)
+            d.callback(ret)
+
+    def write(self, data, ip, port):
+        # We don't use the transport.write method directly as it keeps raising DeprecationWarning for ip='<broadcast>'
+        self.transport.getHandle().sendto(data, ( ip, port ))
+
+    def queryName(self, name, ip = '', port = 137, timeout = 30):
+        """
+        Send a query on the network and hopes that if machine matching the *name* will reply with its IP address.
+
+        :param string ip: If the NBNSProtocol instance was instianted with broadcast=True, then this parameter can be an empty string. We will leave it to the OS to determine an appropriate broadcast address.
+                          If the NBNSProtocol instance was instianted with broadcast=False, then you should provide a target IP to send the query.
+        :param integer port: The NetBIOS-NS port (IANA standard defines this port to be 137). You should not touch this parameter unless you know what you are doing.
+        :param integer/float timeout: Number of seconds to wait for a reply, after which the returned Deferred instance will be called with a NetBIOSTimeout exception.
+        :return: A *twisted.internet.defer.Deferred* instance. The callback function will be called with a list of IP addresses in dotted notation (aaa.bbb.ccc.ddd).
+                 On timeout, the errback function will be called with a Failure instance wrapping around a NetBIOSTimeout exception
+        """
+        trn_id = random.randint(1, 0xFFFF)
+        while True:
+            if trn_id not in self.pending_trns:
+                break
+            else:
+                trn_id = (trn_id + 1) & 0xFFFF
+
+        data = self.prepareNameQuery(trn_id, name)
+        if self.broadcast and not ip:
+            ip = '<broadcast>'
+        elif not ip:
+            self.log.warning('queryName: ip parameter is empty. OS might not transmit this query to the network')
+
+        self.write(data, ip, port)
+
+        d = defer.Deferred()
+        self.pending_trns[trn_id] = ( time.time()+timeout, name, d )
+        return d
+
+    def queryIPForName(self, ip, port = 137, timeout = 30):
+        """
+        Send a query to the machine with *ip* and hopes that the machine will reply back with its name.
+
+        The implementation of this function is contributed by Jason Anderson.
+
+        :param string ip: If the NBNSProtocol instance was instianted with broadcast=True, then this parameter can be an empty string. We will leave it to the OS to determine an appropriate broadcast address.
+                          If the NBNSProtocol instance was instianted with broadcast=False, then you should provide a target IP to send the query.
+        :param integer port: The NetBIOS-NS port (IANA standard defines this port to be 137). You should not touch this parameter unless you know what you are doing.
+        :param integer/float timeout: Number of seconds to wait for a reply, after which the method will return None
+        :return: A *twisted.internet.defer.Deferred* instance. The callback function will be called with a list of names of the machine at *ip*.
+                 On timeout, the errback function will be called with a Failure instance wrapping around a NetBIOSTimeout exception
+        """
+        trn_id = random.randint(1, 0xFFFF)
+        while True:
+            if trn_id not in self.pending_trns:
+                break
+            else:
+                trn_id = (trn_id + 1) & 0xFFFF
+
+        data = self.prepareNetNameQuery(trn_id)
+        self.write(data, ip, port)
+
+        d = defer.Deferred()
+        d2 = defer.Deferred()
+        d2.addErrback(d.errback)
+
+        def stripCode(ret):
+            if ret is not None: # got valid response. Somehow the callback is also called when there is an error.
+                d.callback(map(lambda s: s[0], filter(lambda s: s[1] == TYPE_SERVER, ret)))
+
+        d2.addCallback(stripCode)
+        self.pending_trns[trn_id] = ( time.time()+timeout, NAME_QUERY, d2 )
+        return d
+
+    def stopProtocol(self):
+        DatagramProtocol.stopProtocol(self)
+
+    def cleanupPendingTrns(self):
+        now = time.time()
+
+        # reply should have been received in the past
+        # info is tuple of ( expiry_time, name, d )
+        expired = filter(lambda trn_id, info: info[0] < now, self.pending_trns.iteritems())
+
+        # remove expired items from dict + call errback
+        def expire_item(item):
+            trn_id, (expiry_time, name, d) = item
+
+            del self.pending_trns[trn_id]
+            try:
+                d.errback(NetBIOSTimeout(name))
+            except: pass
+
+        map(expire_item, expired)
+
+        if self.transport:
+            reactor.callLater(1, self.cleanupPendingTrns)
diff --git a/python3/nmb/__init__.py b/python3/nmb/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/python3/nmb/base.py b/python3/nmb/base.py
new file mode 100644
index 00000000..d792a861
--- /dev/null
+++ b/python3/nmb/base.py
@@ -0,0 +1,183 @@
+
+import struct, logging, random
+from .nmb_constants import *
+from .nmb_structs import *
+from .utils import encode_name
+
+class NMBSession:
+
+    log = logging.getLogger('NMB.NMBSession')
+
+    def __init__(self, my_name, remote_name, host_type = TYPE_SERVER, is_direct_tcp = False):
+        self.my_name = my_name.upper()
+        self.remote_name = remote_name.upper()
+        self.host_type = host_type
+        self.data_buf = b''
+
+        if is_direct_tcp:
+            self.data_nmb = DirectTCPSessionMessage()
+            self.sendNMBPacket = self._sendNMBPacket_DirectTCP
+        else:
+            self.data_nmb = NMBSessionMessage()
+            self.sendNMBPacket = self._sendNMBPacket_NetBIOS
+
+    #
+    # Overridden Methods
+    #
+
+    def write(self, data):
+        raise NotImplementedError
+
+    def onNMBSessionMessage(self, flags, data):
+        pass
+
+    def onNMBSessionOK(self):
+        pass
+
+    def onNMBSessionFailed(self):
+        pass
+
+    #
+    # Public Methods
+    #
+
+    def feedData(self, data):
+        self.data_buf = self.data_buf + data
+
+        offset = 0
+        while True:
+            length = self.data_nmb.decode(self.data_buf, offset)
+            if length == 0:
+                break
+            elif length > 0:
+                offset += length
+                self._processNMBSessionPacket(self.data_nmb)
+            else:
+                raise NMBError
+
+        if offset > 0:
+            self.data_buf = self.data_buf[offset:]
+
+    def sendNMBMessage(self, data):
+        self.sendNMBPacket(SESSION_MESSAGE, data)
+
+    def requestNMBSession(self):
+        my_name_encoded = encode_name(self.my_name, TYPE_WORKSTATION)
+        remote_name_encoded = encode_name(self.remote_name, self.host_type)
+        self.sendNMBPacket(SESSION_REQUEST, remote_name_encoded + my_name_encoded)
+
+    #
+    # Protected Methods
+    #
+
+    def _processNMBSessionPacket(self, packet):
+        if packet.type == SESSION_MESSAGE:
+            self.onNMBSessionMessage(packet.flags, packet.data)
+        elif packet.type == POSITIVE_SESSION_RESPONSE:
+            self.onNMBSessionOK()
+        elif packet.type == NEGATIVE_SESSION_RESPONSE:
+            self.onNMBSessionFailed()
+        elif packet.type == SESSION_KEEPALIVE:
+            # Discard keepalive packets - [RFC1002]: 5.2.2.1
+            pass
+        else:
+            self.log.warning('Unrecognized NMB session type: 0x%02x', packet.type)
+
+    def _sendNMBPacket_NetBIOS(self, packet_type, data):
+        length = len(data)
+        assert length <= 0x01FFFF
+        flags = 0
+        if length > 0xFFFF:
+            flags |= 0x01
+            length &= 0xFFFF
+        self.write(struct.pack('>BBH', packet_type, flags, length) + data)
+
+    def _sendNMBPacket_DirectTCP(self, packet_type, data):
+        length = len(data)
+        assert length <= 0x00FFFFFF
+        self.write(struct.pack('>I', length) + data)
+
+
+class NBNS:
+
+    log = logging.getLogger('NMB.NBNS')
+
+    HEADER_STRUCT_FORMAT = '>HHHHHH'
+    HEADER_STRUCT_SIZE = struct.calcsize(HEADER_STRUCT_FORMAT)
+
+    def write(self, data, ip, port):
+        raise NotImplementedError
+
+    def decodePacket(self, data):
+        if len(data) < self.HEADER_STRUCT_SIZE:
+            raise Exception
+
+        trn_id, code, question_count, answer_count, authority_count, additional_count = \
+            struct.unpack(self.HEADER_STRUCT_FORMAT, data[:self.HEADER_STRUCT_SIZE])
+
+        is_response = bool((code >> 15) & 0x01)
+        opcode = (code >> 11) & 0x0F
+        flags = (code >> 4) & 0x7F
+        rcode = code & 0x0F
+
+        if opcode == 0x0000 and is_response:
+            name_len = data[self.HEADER_STRUCT_SIZE]
+            # Constant 2 for the padding bytes before/after the Name and constant 8 for the Type,
+            # Class and TTL fields in the Answer section after the Name:
+            offset = self.HEADER_STRUCT_SIZE + 2 + name_len + 8
+            record_count = (struct.unpack('>H', data[offset:offset+2])[0]) // 6
+
+            offset += 4  # Constant 4 for the Data Length and Flags field
+            ret = []
+            for i in range(0, record_count):
+                ret.append('%d.%d.%d.%d' % struct.unpack('4B', (data[offset:offset + 4])))
+                offset += 6
+            return trn_id, ret
+        else:
+            return trn_id, None
+
+    def prepareNameQuery(self, trn_id, name, is_broadcast = True):
+        header = struct.pack(self.HEADER_STRUCT_FORMAT,
+                             trn_id, (is_broadcast and 0x0110) or 0x0100, 1, 0, 0, 0)
+        payload = encode_name(name, 0x20) + b'\x00\x20\x00\x01'
+
+        return header + payload
+
+    #
+    # Contributed by Jason Anderson
+    #
+    def decodeIPQueryPacket(self, data):
+        if len(data) < self.HEADER_STRUCT_SIZE:
+            raise Exception
+
+        trn_id, code, question_count, answer_count, authority_count, additional_count = struct.unpack(self.HEADER_STRUCT_FORMAT, data[:self.HEADER_STRUCT_SIZE])
+
+        is_response = bool((code >> 15) & 0x01)
+        opcode = (code >> 11) & 0x0F
+        flags = (code >> 4) & 0x7F
+        rcode = code & 0x0F
+        numnames = data[self.HEADER_STRUCT_SIZE + 44]
+
+        if numnames > 0:
+            ret = [ ]
+            offset = self.HEADER_STRUCT_SIZE + 45
+
+            for i in range(0, numnames):
+                mynme = data[offset:offset + 15]
+                mynme = mynme.strip()
+                ret.append(( str(mynme, 'ascii'), data[offset+15] ))
+                offset += 18
+
+            return trn_id, ret
+        else:
+            return trn_id, None
+
+    #
+    # Contributed by Jason Anderson
+    #
+    def prepareNetNameQuery(self, trn_id, is_broadcast = True):
+        header = struct.pack(self.HEADER_STRUCT_FORMAT,
+                             trn_id, (is_broadcast and 0x0010) or 0x0000, 1, 0, 0, 0)
+        payload = encode_name('*', 0) + b'\x00\x21\x00\x01'
+
+        return header + payload
diff --git a/python3/nmb/nmb_constants.py b/python3/nmb/nmb_constants.py
new file mode 100644
index 00000000..fcf6007a
--- /dev/null
+++ b/python3/nmb/nmb_constants.py
@@ -0,0 +1,38 @@
+
+# Default port for NetBIOS name service
+NETBIOS_NS_PORT = 137
+
+# Default port for NetBIOS session service
+NETBIOS_SESSION_PORT = 139
+
+# Owner Node Type Constants
+NODE_B = 0x00
+NODE_P = 0x01
+NODE_M = 0x10
+NODE_RESERVED = 0x11
+
+# Name Type Constants
+TYPE_UNKNOWN = 0x01
+TYPE_WORKSTATION = 0x00
+TYPE_CLIENT = 0x03
+TYPE_SERVER = 0x20
+TYPE_DOMAIN_MASTER = 0x1B
+TYPE_MASTER_BROWSER = 0x1D
+TYPE_BROWSER = 0x1E
+
+TYPE_NAMES = { TYPE_UNKNOWN: 'Unknown',
+               TYPE_WORKSTATION: 'Workstation',
+               TYPE_CLIENT: 'Client',
+               TYPE_SERVER: 'Server',
+               TYPE_MASTER_BROWSER: 'Master Browser',
+               TYPE_BROWSER: 'Browser Server',
+               TYPE_DOMAIN_MASTER: 'Domain Master'
+               }
+
+# Values for Session Packet Type field in Session Packets
+SESSION_MESSAGE = 0x00
+SESSION_REQUEST = 0x81
+POSITIVE_SESSION_RESPONSE = 0x82
+NEGATIVE_SESSION_RESPONSE = 0x83
+REGTARGET_SESSION_RESPONSE = 0x84
+SESSION_KEEPALIVE = 0x85
diff --git a/python3/nmb/nmb_structs.py b/python3/nmb/nmb_structs.py
new file mode 100644
index 00000000..d1eb165e
--- /dev/null
+++ b/python3/nmb/nmb_structs.py
@@ -0,0 +1,66 @@
+
+import struct
+
+class NMBError(Exception): pass
+
+class NotConnectedError(NMBError):
+    """
+    Raisd when the underlying NMB connection has been disconnected or not connected yet
+    """
+    pass
+
+class NMBSessionMessage:
+
+    HEADER_STRUCT_FORMAT = '>BBH'
+    HEADER_STRUCT_SIZE = struct.calcsize(HEADER_STRUCT_FORMAT)
+
+    def __init__(self):
+        self.reset()
+
+    def reset(self):
+        self.type = 0
+        self.flags = 0
+        self.data = ''
+
+    def decode(self, data, offset):
+        data_len = len(data)
+
+        if data_len < offset + self.HEADER_STRUCT_SIZE:
+            # Not enough data for decoding
+            return 0
+
+        self.reset()
+        self.type, self.flags, length = struct.unpack(self.HEADER_STRUCT_FORMAT, data[offset:offset+self.HEADER_STRUCT_SIZE])
+
+        if self.flags & 0x01:
+            length |= 0x010000
+
+        if data_len < offset + self.HEADER_STRUCT_SIZE + length:
+            return 0
+
+        self.data = data[offset+self.HEADER_STRUCT_SIZE:offset+self.HEADER_STRUCT_SIZE+length]
+        return self.HEADER_STRUCT_SIZE + length
+
+class DirectTCPSessionMessage(NMBSessionMessage):
+
+    HEADER_STRUCT_FORMAT = '>I'
+    HEADER_STRUCT_SIZE = struct.calcsize(HEADER_STRUCT_FORMAT)
+
+    def decode(self, data, offset):
+        data_len = len(data)
+
+        if data_len < offset + self.HEADER_STRUCT_SIZE:
+            # Not enough data for decoding
+            return 0
+
+        self.reset()
+        length = struct.unpack(self.HEADER_STRUCT_FORMAT, data[offset:offset+self.HEADER_STRUCT_SIZE])[0]
+
+        if length >> 24 != 0:
+            raise NMBError("Invalid protocol header for Direct TCP session message")
+
+        if data_len < offset + self.HEADER_STRUCT_SIZE + length:
+            return 0
+
+        self.data = data[offset+self.HEADER_STRUCT_SIZE:offset+self.HEADER_STRUCT_SIZE+length]
+        return self.HEADER_STRUCT_SIZE + length
diff --git a/python3/nmb/utils.py b/python3/nmb/utils.py
new file mode 100644
index 00000000..c1c4ced1
--- /dev/null
+++ b/python3/nmb/utils.py
@@ -0,0 +1,50 @@
+
+import string, re
+
+
+def encode_name(name, type, scope = None):
+    """
+    Perform first and second level encoding of name as specified in RFC 1001 (Section 4)
+    """
+    if name == '*':
+        name = name + '\0' * 15
+    elif len(name) > 15:
+        name = name[:15] + chr(type)
+    else:
+        name = name.ljust(15) + chr(type)
+
+    def _do_first_level_encoding(m):
+        s = ord(m.group(0))
+        return string.ascii_uppercase[s >> 4] + string.ascii_uppercase[s & 0x0f]
+
+    encoded_name = chr(len(name) * 2) + re.sub('.', _do_first_level_encoding, name)
+    if scope:
+        encoded_scope = ''
+        for s in string.split(scope, '.'):
+            encoded_scope = encoded_scope + chr(len(s)) + s
+        return bytes(encoded_name + encoded_scope + '\0', 'ascii')
+    else:
+        return bytes(encoded_name + '\0', 'ascii')
+
+
+def decode_name(name):
+    name_length = ord(name[0])
+    assert name_length == 32
+
+    def _do_first_level_decoding(m):
+        s = m.group(0)
+        return chr(((ord(s[0]) - ord('A')) << 4) | (ord(s[1]) - ord('A')))
+
+    decoded_name = re.sub('..', _do_first_level_decoding, name[1:33])
+    if name[33] == '\0':
+        return 34, decoded_name, ''
+    else:
+        decoded_domain = ''
+        offset = 34
+        while 1:
+            domain_length = ord(name[offset])
+            if domain_length == 0:
+                break
+            decoded_domain = '.' + name[offset:offset + domain_length]
+            offset = offset + domain_length
+        return offset + 1, decoded_name, decoded_domain
diff --git a/python3/pysmb.egg-info/PKG-INFO b/python3/pysmb.egg-info/PKG-INFO
new file mode 100644
index 00000000..64f3cbe7
--- /dev/null
+++ b/python3/pysmb.egg-info/PKG-INFO
@@ -0,0 +1,26 @@
+Metadata-Version: 1.1
+Name: pysmb
+Version: 1.1.20
+Summary: pysmb is an experimental SMB/CIFS library written in Python to support file sharing between Windows and Linux machines
+Home-page: https://miketeo.net/projects/pysmb
+Author: Michael Teo
+Author-email: miketeo@miketeo.net
+License: zlib/libpng
+Description: pysmb is an experimental SMB/CIFS library written in Python. It implements the client-side SMB/CIFS protocol which allows your Python application to access and transfer files to/from SMB/CIFS shared folders like your Windows file sharing and Samba folders.
+Keywords: windows samba cifs sharing ftp smb linux
+Platform: UNKNOWN
+Classifier: Development Status :: 5 - Production/Stable
+Classifier: Environment :: Win32 (MS Windows)
+Classifier: Environment :: Console
+Classifier: License :: OSI Approved :: zlib/libpng License
+Classifier: Operating System :: Microsoft :: Windows
+Classifier: Operating System :: POSIX
+Classifier: Programming Language :: Python
+Classifier: Programming Language :: Python :: 2.4
+Classifier: Programming Language :: Python :: 2.5
+Classifier: Programming Language :: Python :: 2.6
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3
+Classifier: Topic :: Communications :: File Sharing
+Classifier: Topic :: Software Development :: Libraries :: Python Modules
+Classifier: Topic :: System :: Networking
diff --git a/python3/pysmb.egg-info/SOURCES.txt b/python3/pysmb.egg-info/SOURCES.txt
new file mode 100644
index 00000000..aa9ab76a
--- /dev/null
+++ b/python3/pysmb.egg-info/SOURCES.txt
@@ -0,0 +1,256 @@
+CHANGELOG
+LICENSE
+MANIFEST.in
+README.txt
+setup.py
+docs/doctrees/environment.pickle
+docs/doctrees/extending.doctree
+docs/doctrees/index.doctree
+docs/doctrees/api/nmb_NBNSProtocol.doctree
+docs/doctrees/api/nmb_NetBIOS.doctree
+docs/doctrees/api/smb_SMBConnection.doctree
+docs/doctrees/api/smb_SMBHandler.doctree
+docs/doctrees/api/smb_SMBProtocolFactory.doctree
+docs/doctrees/api/smb_SharedDevice.doctree
+docs/doctrees/api/smb_SharedFile.doctree
+docs/doctrees/api/smb_exceptions.doctree
+docs/html/.buildinfo
+docs/html/extending.html
+docs/html/genindex.html
+docs/html/index.html
+docs/html/objects.inv
+docs/html/search.html
+docs/html/searchindex.js
+docs/html/_modules/index.html
+docs/html/_modules/nmb/NetBIOS.html
+docs/html/_modules/nmb/NetBIOSProtocol.html
+docs/html/_modules/smb/SMBConnection.html
+docs/html/_modules/smb/SMBProtocol.html
+docs/html/_modules/smb/base.html
+docs/html/_modules/smb/smb_structs.html
+docs/html/_sources/extending.txt
+docs/html/_sources/index.txt
+docs/html/_sources/api/nmb_NBNSProtocol.txt
+docs/html/_sources/api/nmb_NetBIOS.txt
+docs/html/_sources/api/smb_SMBConnection.txt
+docs/html/_sources/api/smb_SMBHandler.txt
+docs/html/_sources/api/smb_SMBProtocolFactory.txt
+docs/html/_sources/api/smb_SharedDevice.txt
+docs/html/_sources/api/smb_SharedFile.txt
+docs/html/_sources/api/smb_exceptions.txt
+docs/html/_static/ajax-loader.gif
+docs/html/_static/basic.css
+docs/html/_static/comment-bright.png
+docs/html/_static/comment-close.png
+docs/html/_static/comment.png
+docs/html/_static/contents.png
+docs/html/_static/doctools.js
+docs/html/_static/down-pressed.png
+docs/html/_static/down.png
+docs/html/_static/file.png
+docs/html/_static/jquery.js
+docs/html/_static/minus.png
+docs/html/_static/navigation.png
+docs/html/_static/plus.png
+docs/html/_static/pygments.css
+docs/html/_static/searchtools.js
+docs/html/_static/sphinxdoc.css
+docs/html/_static/underscore.js
+docs/html/_static/up-pressed.png
+docs/html/_static/up.png
+docs/html/_static/websupport.js
+docs/html/api/nmb_NBNSProtocol.html
+docs/html/api/nmb_NetBIOS.html
+docs/html/api/smb_SMBConnection.html
+docs/html/api/smb_SMBHandler.html
+docs/html/api/smb_SMBProtocolFactory.html
+docs/html/api/smb_SharedDevice.html
+docs/html/api/smb_SharedFile.html
+docs/html/api/smb_exceptions.html
+python2/nmb/NetBIOS.py
+python2/nmb/NetBIOSProtocol.py
+python2/nmb/__init__.py
+python2/nmb/base.py
+python2/nmb/nmb_constants.py
+python2/nmb/nmb_structs.py
+python2/nmb/utils.py
+python2/smb/SMBConnection.py
+python2/smb/SMBHandler.py
+python2/smb/SMBProtocol.py
+python2/smb/__init__.py
+python2/smb/base.py
+python2/smb/ntlm.py
+python2/smb/security_descriptors.py
+python2/smb/securityblob.py
+python2/smb/smb2_constants.py
+python2/smb/smb2_structs.py
+python2/smb/smb_constants.py
+python2/smb/smb_structs.py
+python2/smb/utils/README.txt
+python2/smb/utils/U32.py
+python2/smb/utils/__init__.py
+python2/smb/utils/md4.py
+python2/smb/utils/pyDes.py
+python2/smb/utils/sha256.py
+python2/tests/README_1st.txt
+python2/tests/__init__.py
+python2/tests/connection.ini
+python2/tests/smbtest.7z
+python2/tests/test_ntlm.py
+python2/tests/test_security_descriptors.py
+python2/tests/test_securityblob.py
+python2/tests/DirectSMBConnectionTests/__init__.py
+python2/tests/DirectSMBConnectionTests/test_SMBHandler.py
+python2/tests/DirectSMBConnectionTests/test_auth.py
+python2/tests/DirectSMBConnectionTests/test_createdeletedirectory.py
+python2/tests/DirectSMBConnectionTests/test_echo.py
+python2/tests/DirectSMBConnectionTests/test_listpath.py
+python2/tests/DirectSMBConnectionTests/test_listshares.py
+python2/tests/DirectSMBConnectionTests/test_listsnapshots.py
+python2/tests/DirectSMBConnectionTests/test_rename.py
+python2/tests/DirectSMBConnectionTests/test_retrievefile.py
+python2/tests/DirectSMBConnectionTests/test_storefile.py
+python2/tests/DirectSMBConnectionTests/util.py
+python2/tests/DirectSMBTwistedTests/test_auth.py
+python2/tests/DirectSMBTwistedTests/test_createdeletedirectory.py
+python2/tests/DirectSMBTwistedTests/test_echo.py
+python2/tests/DirectSMBTwistedTests/test_listpath.py
+python2/tests/DirectSMBTwistedTests/test_listshares.py
+python2/tests/DirectSMBTwistedTests/test_listsnapshots.py
+python2/tests/DirectSMBTwistedTests/test_rename.py
+python2/tests/DirectSMBTwistedTests/test_retrievefile.py
+python2/tests/DirectSMBTwistedTests/test_storefile.py
+python2/tests/DirectSMBTwistedTests/util.py
+python2/tests/NetBIOSTests/__init__.py
+python2/tests/NetBIOSTests/test_queryname.py
+python2/tests/NetBIOSTwistedTests/__init__.py
+python2/tests/NetBIOSTwistedTests/test_queryname.py
+python2/tests/SMBConnectionTests/__init__.py
+python2/tests/SMBConnectionTests/test_SMBHandler.py
+python2/tests/SMBConnectionTests/test_auth.py
+python2/tests/SMBConnectionTests/test_createdeletedirectory.py
+python2/tests/SMBConnectionTests/test_deletepattern.py
+python2/tests/SMBConnectionTests/test_echo.py
+python2/tests/SMBConnectionTests/test_getattributes.py
+python2/tests/SMBConnectionTests/test_listpath.py
+python2/tests/SMBConnectionTests/test_listshares.py
+python2/tests/SMBConnectionTests/test_listsnapshots.py
+python2/tests/SMBConnectionTests/test_rename.py
+python2/tests/SMBConnectionTests/test_retrievefile.py
+python2/tests/SMBConnectionTests/test_security.py
+python2/tests/SMBConnectionTests/test_storefile.py
+python2/tests/SMBConnectionTests/util.py
+python2/tests/SMBTwistedTests/__init__.py
+python2/tests/SMBTwistedTests/test_auth.py
+python2/tests/SMBTwistedTests/test_createdeletedirectory.py
+python2/tests/SMBTwistedTests/test_echo.py
+python2/tests/SMBTwistedTests/test_getattributes.py
+python2/tests/SMBTwistedTests/test_listpath.py
+python2/tests/SMBTwistedTests/test_listshares.py
+python2/tests/SMBTwistedTests/test_listsnapshots.py
+python2/tests/SMBTwistedTests/test_rename.py
+python2/tests/SMBTwistedTests/test_retrievefile.py
+python2/tests/SMBTwistedTests/test_storefile.py
+python2/tests/SMBTwistedTests/util.py
+python2/tests/SupportFiles/binary.dat
+python3/nmb/NetBIOS.py
+python3/nmb/NetBIOSProtocol.py
+python3/nmb/__init__.py
+python3/nmb/base.py
+python3/nmb/nmb_constants.py
+python3/nmb/nmb_structs.py
+python3/nmb/utils.py
+python3/pysmb.egg-info/PKG-INFO
+python3/pysmb.egg-info/SOURCES.txt
+python3/pysmb.egg-info/dependency_links.txt
+python3/pysmb.egg-info/requires.txt
+python3/pysmb.egg-info/top_level.txt
+python3/smb/SMBConnection.py
+python3/smb/SMBHandler.py
+python3/smb/SMBProtocol.py
+python3/smb/__init__.py
+python3/smb/base.py
+python3/smb/ntlm.py
+python3/smb/security_descriptors.py
+python3/smb/securityblob.py
+python3/smb/smb2_constants.py
+python3/smb/smb2_structs.py
+python3/smb/smb_constants.py
+python3/smb/smb_structs.py
+python3/smb/utils/U32.py
+python3/smb/utils/__init__.py
+python3/smb/utils/md4.py
+python3/smb/utils/pyDes.py
+python3/smb/utils/sha256.py
+python3/tests/__init__.py
+python3/tests/connection.ini
+python3/tests/smbtest.7z
+python3/tests/test_ntlm.py
+python3/tests/test_security_descriptors.py
+python3/tests/test_securityblob.py
+python3/tests/DirectSMBConnectionTests/__init__.py
+python3/tests/DirectSMBConnectionTests/test_auth.py
+python3/tests/DirectSMBConnectionTests/test_createdeletedirectory.py
+python3/tests/DirectSMBConnectionTests/test_echo.py
+python3/tests/DirectSMBConnectionTests/test_listpath.py
+python3/tests/DirectSMBConnectionTests/test_listshares.py
+python3/tests/DirectSMBConnectionTests/test_listsnapshots.py
+python3/tests/DirectSMBConnectionTests/test_rename.py
+python3/tests/DirectSMBConnectionTests/test_retrievefile.py
+python3/tests/DirectSMBConnectionTests/test_storefile.py
+python3/tests/DirectSMBConnectionTests/util.py
+python3/tests/DirectSMBTwistedTests/test_auth.py
+python3/tests/DirectSMBTwistedTests/test_createdeletedirectory.py
+python3/tests/DirectSMBTwistedTests/test_echo.py
+python3/tests/DirectSMBTwistedTests/test_listpath.py
+python3/tests/DirectSMBTwistedTests/test_listshares.py
+python3/tests/DirectSMBTwistedTests/test_listsnapshots.py
+python3/tests/DirectSMBTwistedTests/test_rename.py
+python3/tests/DirectSMBTwistedTests/test_retrievefile.py
+python3/tests/DirectSMBTwistedTests/test_storefile.py
+python3/tests/DirectSMBTwistedTests/util.py
+python3/tests/NetBIOSTests/__init__.py
+python3/tests/NetBIOSTests/test_queryname.py
+python3/tests/NetBIOSTwistedTests/__init__.py
+python3/tests/NetBIOSTwistedTests/test_queryname.py
+python3/tests/SMBConnectionTests/__init__.py
+python3/tests/SMBConnectionTests/test_SMBHandler.py
+python3/tests/SMBConnectionTests/test_auth.py
+python3/tests/SMBConnectionTests/test_createdeletedirectory.py
+python3/tests/SMBConnectionTests/test_deletepattern.py
+python3/tests/SMBConnectionTests/test_echo.py
+python3/tests/SMBConnectionTests/test_getattributes.py
+python3/tests/SMBConnectionTests/test_listpath.py
+python3/tests/SMBConnectionTests/test_listshares.py
+python3/tests/SMBConnectionTests/test_listsnapshots.py
+python3/tests/SMBConnectionTests/test_rename.py
+python3/tests/SMBConnectionTests/test_retrievefile.py
+python3/tests/SMBConnectionTests/test_storefile.py
+python3/tests/SMBConnectionTests/util.py
+python3/tests/SMBTwistedTests/__init__.py
+python3/tests/SMBTwistedTests/test_auth.py
+python3/tests/SMBTwistedTests/test_createdeletedirectory.py
+python3/tests/SMBTwistedTests/test_echo.py
+python3/tests/SMBTwistedTests/test_getattributes.py
+python3/tests/SMBTwistedTests/test_listpath.py
+python3/tests/SMBTwistedTests/test_listshares.py
+python3/tests/SMBTwistedTests/test_listsnapshots.py
+python3/tests/SMBTwistedTests/test_rename.py
+python3/tests/SMBTwistedTests/test_retrievefile.py
+python3/tests/SMBTwistedTests/test_storefile.py
+python3/tests/SMBTwistedTests/util.py
+python3/tests/SupportFiles/binary.dat
+sphinx/Makefile
+sphinx/make.bat
+sphinx/source/conf.py
+sphinx/source/extending.rst
+sphinx/source/index.rst
+sphinx/source/api/nmb_NBNSProtocol.rst
+sphinx/source/api/nmb_NetBIOS.rst
+sphinx/source/api/smb_SMBConnection.rst
+sphinx/source/api/smb_SMBHandler.rst
+sphinx/source/api/smb_SMBProtocolFactory.rst
+sphinx/source/api/smb_SharedDevice.rst
+sphinx/source/api/smb_SharedFile.rst
+sphinx/source/api/smb_exceptions.rst
+sphinx/source/api/smb_security_descriptors.rst
\ No newline at end of file
diff --git a/python3/pysmb.egg-info/dependency_links.txt b/python3/pysmb.egg-info/dependency_links.txt
new file mode 100644
index 00000000..8b137891
--- /dev/null
+++ b/python3/pysmb.egg-info/dependency_links.txt
@@ -0,0 +1 @@
+
diff --git a/python3/pysmb.egg-info/requires.txt b/python3/pysmb.egg-info/requires.txt
new file mode 100644
index 00000000..38fe4145
--- /dev/null
+++ b/python3/pysmb.egg-info/requires.txt
@@ -0,0 +1 @@
+pyasn1
diff --git a/python3/pysmb.egg-info/top_level.txt b/python3/pysmb.egg-info/top_level.txt
new file mode 100644
index 00000000..65ad1103
--- /dev/null
+++ b/python3/pysmb.egg-info/top_level.txt
@@ -0,0 +1,2 @@
+nmb
+smb
diff --git a/python3/smb/SMBConnection.py b/python3/smb/SMBConnection.py
new file mode 100644
index 00000000..89afa6b0
--- /dev/null
+++ b/python3/smb/SMBConnection.py
@@ -0,0 +1,640 @@
+
+import os, logging, select, socket, types, struct, errno
+from .smb_constants import *
+from .smb_structs import *
+from .base import SMB, NotConnectedError, NotReadyError, SMBTimeout
+
+
+class SMBConnection(SMB):
+
+    log = logging.getLogger('SMB.SMBConnection')
+
+    #: SMB messages will never be signed regardless of remote server's configurations; access errors will occur if the remote server requires signing.
+    SIGN_NEVER = 0
+    #: SMB messages will be signed when remote server supports signing but not requires signing.
+    SIGN_WHEN_SUPPORTED = 1
+    #: SMB messages will only be signed when remote server requires signing.
+    SIGN_WHEN_REQUIRED = 2
+
+    def __init__(self, username, password, my_name, remote_name, domain = '', use_ntlm_v2 = True, sign_options = SIGN_WHEN_REQUIRED, is_direct_tcp = False):
+        """
+        Create a new SMBConnection instance.
+
+        *username* and *password* are the user credentials required to authenticate the underlying SMB connection with the remote server.
+        File operations can only be proceeded after the connection has been authenticated successfully.
+
+        Note that you need to call *connect* method to actually establish the SMB connection to the remote server and perform authentication.
+
+        The default TCP port for most SMB/CIFS servers using NetBIOS over TCP/IP is 139.
+        Some newer server installations might also support Direct hosting of SMB over TCP/IP; for these servers, the default TCP port is 445.
+
+        :param string my_name: The local NetBIOS machine name that will identify where this connection is originating from.
+                               You can freely choose a name as long as it contains a maximum of 15 alphanumeric characters and does not contain spaces and any of ``\/:*?";|+``
+        :param string remote_name: The NetBIOS machine name of the remote server.
+                                   On windows, you can find out the machine name by right-clicking on the "My Computer" and selecting "Properties".
+                                   This parameter must be the same as what has been configured on the remote server, or else the connection will be rejected.
+        :param string domain: The network domain. On windows, it is known as the workgroup. Usually, it is safe to leave this parameter as an empty string.
+        :param boolean use_ntlm_v2: Indicates whether pysmb should be NTLMv1 or NTLMv2 authentication algorithm for authentication.
+                                    The choice of NTLMv1 and NTLMv2 is configured on the remote server, and there is no mechanism to auto-detect which algorithm has been configured.
+                                    Hence, we can only "guess" or try both algorithms.
+                                    On Sambda, Windows Vista and Windows 7, NTLMv2 is enabled by default. On Windows XP, we can use NTLMv1 before NTLMv2.
+        :param int sign_options: Determines whether SMB messages will be signed. Default is *SIGN_WHEN_REQUIRED*.
+                                 If *SIGN_WHEN_REQUIRED* (value=2), SMB messages will only be signed when remote server requires signing.
+                                 If *SIGN_WHEN_SUPPORTED* (value=1), SMB messages will be signed when remote server supports signing but not requires signing.
+                                 If *SIGN_NEVER* (value=0), SMB messages will never be signed regardless of remote server's configurations; access errors will occur if the remote server requires signing.
+        :param boolean is_direct_tcp: Controls whether the NetBIOS over TCP/IP (is_direct_tcp=False) or the newer Direct hosting of SMB over TCP/IP (is_direct_tcp=True) will be used for the communication.
+                                      The default parameter is False which will use NetBIOS over TCP/IP for wider compatibility (TCP port: 139).
+        """
+        SMB.__init__(self, username, password, my_name, remote_name, domain, use_ntlm_v2, sign_options, is_direct_tcp)
+        self.sock = None
+        self.auth_result = None
+        self.is_busy = False
+        self.is_direct_tcp = is_direct_tcp
+
+    #
+    # SMB (and its superclass) Methods
+    #
+
+    def onAuthOK(self):
+        self.auth_result = True
+
+    def onAuthFailed(self):
+        self.auth_result = False
+
+    def write(self, data):
+        assert self.sock
+        data_len = len(data)
+        total_sent = 0
+        while total_sent < data_len:
+            sent = self.sock.send(data[total_sent:])
+            if sent == 0:
+                raise NotConnectedError('Server disconnected')
+            total_sent = total_sent + sent
+
+    #
+    # Support for "with" context
+    #
+    def __enter__(self):
+        return self
+
+    def __exit__(self, *args):
+        self.close()
+
+    #
+    # Misc Properties
+    #
+
+    @property
+    def isUsingSMB2(self):
+        """A convenient property to return True if the underlying SMB connection is using SMB2 protocol."""
+        return self.is_using_smb2
+
+
+    #
+    # Public Methods
+    #
+
+    def connect(self, ip, port = 139, sock_family = socket.AF_INET, timeout = 60):
+        """
+        Establish the SMB connection to the remote SMB/CIFS server.
+
+        You must call this method before attempting any of the file operations with the remote server.
+        This method will block until the SMB connection has attempted at least one authentication.
+
+        :return: A boolean value indicating the result of the authentication atttempt: True if authentication is successful; False, if otherwise.
+        """
+        if self.sock:
+            self.sock.close()
+
+        self.auth_result = None
+        self.sock = socket.socket(sock_family)
+        self.sock.settimeout(timeout)
+        self.sock.connect(( ip, port ))
+
+        self.is_busy = True
+        try:
+            if not self.is_direct_tcp:
+                self.requestNMBSession()
+            else:
+                self.onNMBSessionOK()
+            while self.auth_result is None:
+                self._pollForNetBIOSPacket(timeout)
+        finally:
+            self.is_busy = False
+
+        return self.auth_result
+
+    def close(self):
+        """
+        Terminate the SMB connection (if it has been started) and release any sources held by the underlying socket.
+        """
+        if self.sock:
+            self.sock.close()
+            self.sock = None
+
+    def listShares(self, timeout = 30):
+        """
+        Retrieve a list of shared resources on remote server.
+
+        :return: A list of :doc:`smb.base.SharedDevice<smb_SharedDevice>` instances describing the shared resource
+        """
+        if not self.sock:
+            raise NotConnectedError('Not connected to server')
+
+        results = [ ]
+
+        def cb(entries):
+            self.is_busy = False
+            results.extend(entries)
+
+        def eb(failure):
+            self.is_busy = False
+            raise failure
+
+        self.is_busy = True
+        try:
+            self._listShares(cb, eb, timeout)
+            while self.is_busy:
+                self._pollForNetBIOSPacket(timeout)
+        finally:
+            self.is_busy = False
+
+        return results
+
+    def listPath(self, service_name, path,
+                 search = SMB_FILE_ATTRIBUTE_READONLY | SMB_FILE_ATTRIBUTE_HIDDEN | SMB_FILE_ATTRIBUTE_SYSTEM | SMB_FILE_ATTRIBUTE_DIRECTORY | SMB_FILE_ATTRIBUTE_ARCHIVE | SMB_FILE_ATTRIBUTE_INCL_NORMAL,
+                 pattern = '*', timeout = 30):
+        """
+        Retrieve a directory listing of files/folders at *path*
+
+        For simplicity, pysmb defines a "normal" file as a file entry that is not read-only, not hidden, not system, not archive and not a directory.
+        It ignores other attributes like compression, indexed, sparse, temporary and encryption.
+
+        Note that the default search parameter will query for all read-only (SMB_FILE_ATTRIBUTE_READONLY), hidden (SMB_FILE_ATTRIBUTE_HIDDEN),
+        system (SMB_FILE_ATTRIBUTE_SYSTEM), archive (SMB_FILE_ATTRIBUTE_ARCHIVE), normal (SMB_FILE_ATTRIBUTE_INCL_NORMAL) files
+        and directories (SMB_FILE_ATTRIBUTE_DIRECTORY).
+        If you do not need to include "normal" files in the result, define your own search parameter without the SMB_FILE_ATTRIBUTE_INCL_NORMAL constant.
+        SMB_FILE_ATTRIBUTE_NORMAL should be used by itself and not be used with other bit constants.
+
+        :param string/unicode service_name: the name of the shared folder for the *path*
+        :param string/unicode path: path relative to the *service_name* where we are interested to learn about its files/sub-folders.
+        :param integer search: integer value made up from a bitwise-OR of *SMB_FILE_ATTRIBUTE_xxx* bits (see smb_constants.py).
+        :param string/unicode pattern: the filter to apply to the results before returning to the client.
+        :return: A list of :doc:`smb.base.SharedFile<smb_SharedFile>` instances.
+        """
+        if not self.sock:
+            raise NotConnectedError('Not connected to server')
+
+        results = [ ]
+
+        def cb(entries):
+            self.is_busy = False
+            results.extend(entries)
+
+        def eb(failure):
+            self.is_busy = False
+            raise failure
+
+        self.is_busy = True
+        try:
+            self._listPath(service_name, path, cb, eb, search = search, pattern = pattern, timeout = timeout)
+            while self.is_busy:
+                self._pollForNetBIOSPacket(timeout)
+        finally:
+            self.is_busy = False
+
+        return results
+
+    def listSnapshots(self, service_name, path, timeout = 30):
+        """
+        Retrieve a list of available snapshots (shadow copies) for *path*.
+
+        Note that snapshot features are only supported on Windows Vista Business, Enterprise and Ultimate, and on all Windows 7 editions.
+
+        :param string/unicode service_name: the name of the shared folder for the *path*
+        :param string/unicode path: path relative to the *service_name* where we are interested in the list of available snapshots
+        :return: A list of python *datetime.DateTime* instances in GMT/UTC time zone
+        """
+        if not self.sock:
+            raise NotConnectedError('Not connected to server')
+
+        results = [ ]
+
+        def cb(entries):
+            self.is_busy = False
+            results.extend(entries)
+
+        def eb(failure):
+            self.is_busy = False
+            raise failure
+
+        self.is_busy = True
+        try:
+            self._listSnapshots(service_name, path, cb, eb, timeout = timeout)
+            while self.is_busy:
+                self._pollForNetBIOSPacket(timeout)
+        finally:
+            self.is_busy = False
+
+        return results
+
+    def getAttributes(self, service_name, path, timeout = 30):
+        """
+        Retrieve information about the file at *path* on the *service_name*.
+
+        :param string/unicode service_name: the name of the shared folder for the *path*
+        :param string/unicode path: Path of the file on the remote server. If the file cannot be opened for reading, an :doc:`OperationFailure<smb_exceptions>` will be raised.
+        :return: A :doc:`smb.base.SharedFile<smb_SharedFile>` instance containing the attributes of the file.
+        """
+        if not self.sock:
+            raise NotConnectedError('Not connected to server')
+
+        results = [ ]
+
+        def cb(info):
+            self.is_busy = False
+            results.append(info)
+
+        def eb(failure):
+            self.is_busy = False
+            raise failure
+
+        self.is_busy = True
+        try:
+            self._getAttributes(service_name, path, cb, eb, timeout)
+            while self.is_busy:
+                self._pollForNetBIOSPacket(timeout)
+        finally:
+            self.is_busy = False
+
+        return results[0]
+
+    def getSecurity(self, service_name, path, timeout = 30):
+        """
+        Retrieve the security descriptor of the file at *path* on the *service_name*.
+
+        :param string/unicode service_name: the name of the shared folder for the *path*
+        :param string/unicode path: Path of the file on the remote server. If the file cannot be opened for reading, an :doc:`OperationFailure<smb_exceptions>` will be raised.
+        :return: A :class:`smb.security_descriptors.SecurityDescriptor` instance containing the security information of the file.
+        """
+        if not self.sock:
+            raise NotConnectedError('Not connected to server')
+
+        results = [ ]
+
+        def cb(info):
+            self.is_busy = False
+            results.append(info)
+
+        def eb(failure):
+            self.is_busy = False
+            raise failure
+
+        self.is_busy = True
+        try:
+            self._getSecurity(service_name, path, cb, eb, timeout)
+            while self.is_busy:
+                self._pollForNetBIOSPacket(timeout)
+        finally:
+            self.is_busy = False
+
+        return results[0]
+
+    def retrieveFile(self, service_name, path, file_obj, timeout = 30):
+        """
+        Retrieve the contents of the file at *path* on the *service_name* and write these contents to the provided *file_obj*.
+
+        Use *retrieveFileFromOffset()* method if you wish to specify the offset to read from the remote *path* and/or the number of bytes to write to the *file_obj*.
+
+        :param string/unicode service_name: the name of the shared folder for the *path*
+        :param string/unicode path: Path of the file on the remote server. If the file cannot be opened for reading, an :doc:`OperationFailure<smb_exceptions>` will be raised.
+        :param file_obj: A file-like object that has a *write* method. Data will be written continuously to *file_obj* until EOF is received from the remote service. In Python3, this file-like object must have a *write* method which accepts a bytes parameter.
+        :return: A 2-element tuple of ( file attributes of the file on server, number of bytes written to *file_obj* ).
+                 The file attributes is an integer value made up from a bitwise-OR of *SMB_FILE_ATTRIBUTE_xxx* bits (see smb_constants.py)
+        """
+        return self.retrieveFileFromOffset(service_name, path, file_obj, 0, -1, timeout)
+
+    def retrieveFileFromOffset(self, service_name, path, file_obj, offset = 0, max_length = -1, timeout = 30):
+        """
+        Retrieve the contents of the file at *path* on the *service_name* and write these contents to the provided *file_obj*.
+
+        :param string/unicode service_name: the name of the shared folder for the *path*
+        :param string/unicode path: Path of the file on the remote server. If the file cannot be opened for reading, an :doc:`OperationFailure<smb_exceptions>` will be raised.
+        :param file_obj: A file-like object that has a *write* method. Data will be written continuously to *file_obj* up to *max_length* number of bytes. In Python3, this file-like object must have a *write* method which accepts a bytes parameter.
+        :param integer/long offset: the offset in the remote *path* where the first byte will be read and written to *file_obj*. Must be either zero or a positive integer/long value.
+        :param integer/long max_length: maximum number of bytes to read from the remote *path* and write to the *file_obj*. Specify a negative value to read from *offset* to the EOF.
+                                        If zero, the method returns immediately after the file is opened successfully for reading.
+        :return: A 2-element tuple of ( file attributes of the file on server, number of bytes written to *file_obj* ).
+                 The file attributes is an integer value made up from a bitwise-OR of *SMB_FILE_ATTRIBUTE_xxx* bits (see smb_constants.py)
+        """
+        if not self.sock:
+            raise NotConnectedError('Not connected to server')
+
+        results = [ ]
+
+        def cb(r):
+            self.is_busy = False
+            results.append(r[1:])
+
+        def eb(failure):
+            self.is_busy = False
+            raise failure
+
+        self.is_busy = True
+        try:
+            self._retrieveFileFromOffset(service_name, path, file_obj, cb, eb, offset, max_length, timeout = timeout)
+            while self.is_busy:
+                self._pollForNetBIOSPacket(timeout)
+        finally:
+            self.is_busy = False
+
+        return results[0]
+
+    def storeFile(self, service_name, path, file_obj, timeout = 30):
+        """
+        Store the contents of the *file_obj* at *path* on the *service_name*.
+        If the file already exists on the remote server, it will be truncated and overwritten.
+
+        :param string/unicode service_name: the name of the shared folder for the *path*
+        :param string/unicode path: Path of the file on the remote server. If the file at *path* does not exist, it will be created. Otherwise, it will be overwritten.
+                                    If the *path* refers to a folder or the file cannot be opened for writing, an :doc:`OperationFailure<smb_exceptions>` will be raised.
+        :param file_obj: A file-like object that has a *read* method. Data will read continuously from *file_obj* until EOF. In Python3, this file-like object must have a *read* method which returns a bytes parameter.
+        :return: Number of bytes uploaded
+        """
+        return self.storeFileFromOffset(service_name, path, file_obj, 0, True, timeout)
+
+    def storeFileFromOffset(self, service_name, path, file_obj, offset = 0, truncate = False, timeout = 30):
+        """
+        Store the contents of the *file_obj* at *path* on the *service_name*.
+
+        :param string/unicode service_name: the name of the shared folder for the *path*
+        :param string/unicode path: Path of the file on the remote server. If the file at *path* does not exist, it will be created.
+                                    If the *path* refers to a folder or the file cannot be opened for writing, an :doc:`OperationFailure<smb_exceptions>` will be raised.
+        :param file_obj: A file-like object that has a *read* method. Data will read continuously from *file_obj* until EOF.
+        :param offset: Long integer value which specifies the offset in the remote server to start writing. First byte of the file is 0.
+        :param truncate: Boolean value. If True and the file exists on the remote server, it will be truncated first before writing. Default is False.
+        :return: the file position where the next byte will be written.
+        """
+        if not self.sock:
+            raise NotConnectedError('Not connected to server')
+
+        results = [ ]
+
+        def cb(r):
+            self.is_busy = False
+            results.append(r[1])
+
+        def eb(failure):
+            self.is_busy = False
+            raise failure
+
+        self.is_busy = True
+        try:
+            self._storeFileFromOffset(service_name, path, file_obj, cb, eb, offset, truncate = truncate, timeout = timeout)
+            while self.is_busy:
+                self._pollForNetBIOSPacket(timeout)
+        finally:
+            self.is_busy = False
+
+        return results[0]
+
+    def deleteFiles(self, service_name, path_file_pattern, timeout = 30):
+        """
+        Delete one or more regular files. It supports the use of wildcards in file names, allowing for deletion of multiple files in a single request.
+
+        :param string/unicode service_name: Contains the name of the shared folder.
+        :param string/unicode path_file_pattern: The pathname of the file(s) to be deleted, relative to the service_name.
+                                                 Wildcards may be used in th filename component of the path.
+                                                 If your path/filename contains non-English characters, you must pass in an unicode string.
+        :return: None
+        """
+        if not self.sock:
+            raise NotConnectedError('Not connected to server')
+
+        def cb(r):
+            self.is_busy = False
+
+        def eb(failure):
+            self.is_busy = False
+            raise failure
+
+        self.is_busy = True
+        try:
+            self._deleteFiles(service_name, path_file_pattern, cb, eb, timeout = timeout)
+            while self.is_busy:
+                self._pollForNetBIOSPacket(timeout)
+        finally:
+            self.is_busy = False
+
+    def resetFileAttributes(self, service_name, path_file_pattern, timeout = 30):
+        """
+        Reset file attributes of one or more regular files or folders.
+        It supports the use of wildcards in file names, allowing for unlocking of multiple files/folders in a single request.
+        This function is very helpful when deleting files/folders that are read-only.
+        Note: this function is currently only implemented for SMB2! Technically, it sets the FILE_ATTRIBUTE_NORMAL flag, therefore clearing all other flags. (See https://msdn.microsoft.com/en-us/library/cc232110.aspx for further information)
+
+        :param string/unicode service_name: Contains the name of the shared folder.
+        :param string/unicode path_file_pattern: The pathname of the file(s) to be deleted, relative to the service_name.
+                                                 Wildcards may be used in the filename component of the path.
+                                                 If your path/filename contains non-English characters, you must pass in an unicode string.
+        :return: None
+        """
+        if not self.sock:
+            raise NotConnectedError('Not connected to server')
+
+        def cb(r):
+            self.is_busy = False
+
+        def eb(failure):
+            self.is_busy = False
+            raise failure
+
+        self.is_busy = True
+        try:
+            self._resetFileAttributes(service_name, path_file_pattern, cb, eb, timeout = timeout)
+            while self.is_busy:
+                self._pollForNetBIOSPacket(timeout)
+        finally:
+            self.is_busy = False
+
+
+    def createDirectory(self, service_name, path, timeout = 30):
+        """
+        Creates a new directory *path* on the *service_name*.
+
+        :param string/unicode service_name: Contains the name of the shared folder.
+        :param string/unicode path: The path of the new folder (relative to) the shared folder.
+                                    If the path contains non-English characters, an unicode string must be used to pass in the path.
+        :return: None
+        """
+        if not self.sock:
+            raise NotConnectedError('Not connected to server')
+
+        def cb(r):
+            self.is_busy = False
+
+        def eb(failure):
+            self.is_busy = False
+            raise failure
+
+        self.is_busy = True
+        try:
+            self._createDirectory(service_name, path, cb, eb, timeout = timeout)
+            while self.is_busy:
+                self._pollForNetBIOSPacket(timeout)
+        finally:
+            self.is_busy = False
+
+    def deleteDirectory(self, service_name, path, timeout = 30):
+        """
+        Delete the empty folder at *path* on *service_name*
+
+        :param string/unicode service_name: Contains the name of the shared folder.
+        :param string/unicode path: The path of the to-be-deleted folder (relative to) the shared folder.
+                                    If the path contains non-English characters, an unicode string must be used to pass in the path.
+        :return: None
+        """
+        if not self.sock:
+            raise NotConnectedError('Not connected to server')
+
+        def cb(r):
+            self.is_busy = False
+
+        def eb(failure):
+            self.is_busy = False
+            raise failure
+
+        self.is_busy = True
+        try:
+            self._deleteDirectory(service_name, path, cb, eb, timeout = timeout)
+            while self.is_busy:
+                self._pollForNetBIOSPacket(timeout)
+        finally:
+            self.is_busy = False
+
+    def rename(self, service_name, old_path, new_path, timeout = 30):
+        """
+        Rename a file or folder at *old_path* to *new_path* shared at *service_name*. Note that this method cannot be used to rename file/folder across different shared folders
+
+        *old_path* and *new_path* are string/unicode referring to the old and new path of the renamed resources (relative to) the shared folder.
+        If the path contains non-English characters, an unicode string must be used to pass in the path.
+
+        :param string/unicode service_name: Contains the name of the shared folder.
+        :return: None
+        """
+        if not self.sock:
+            raise NotConnectedError('Not connected to server')
+
+        def cb(r):
+            self.is_busy = False
+
+        def eb(failure):
+            self.is_busy = False
+            raise failure
+
+        self.is_busy = True
+        try:
+            self._rename(service_name, old_path, new_path, cb, eb)
+            while self.is_busy:
+                self._pollForNetBIOSPacket(timeout)
+        finally:
+            self.is_busy = False
+
+    def echo(self, data, timeout = 10):
+        """
+        Send an echo command containing *data* to the remote SMB/CIFS server. The remote SMB/CIFS will reply with the same *data*.
+
+        :param bytes data: Data to send to the remote server. Must be a bytes object.
+        :return: The *data* parameter
+        """
+        if not self.sock:
+            raise NotConnectedError('Not connected to server')
+
+        results = [ ]
+
+        def cb(r):
+            self.is_busy = False
+            results.append(r)
+
+        def eb(failure):
+            self.is_busy = False
+            raise failure
+
+        self.is_busy = True
+        try:
+            self._echo(data, cb, eb)
+            while self.is_busy:
+                self._pollForNetBIOSPacket(timeout)
+        finally:
+            self.is_busy = False
+
+        return results[0]
+
+    #
+    # Protected Methods
+    #
+
+    def _pollForNetBIOSPacket(self, timeout):
+        expiry_time = time.time() + timeout
+        read_len = 4
+        data = b''
+
+        while read_len > 0:
+            try:
+                if expiry_time < time.time():
+                    raise SMBTimeout
+
+                ready, _, _ = select.select([ self.sock.fileno() ], [ ], [ ], timeout)
+                if not ready:
+                    raise SMBTimeout
+
+                d = self.sock.recv(read_len)
+                if len(d) == 0:
+                    raise NotConnectedError
+
+                data = data + d
+                read_len -= len(d)
+            except select.error as ex:
+                if isinstance(ex, tuple):
+                    if ex[0] != errno.EINTR and ex[0] != errno.EAGAIN:
+                        raise ex
+                else:
+                    raise ex
+
+        type_, flags, length = struct.unpack('>BBH', data)
+        if type_ == 0x0:
+            # This is a Direct TCP packet
+            # The length is specified in the header from byte 8. (0-indexed)
+            # we read a structure assuming NBT, so to get the real length
+            # combine the length and flag fields together
+            length = length + (flags << 16)
+        else:
+            # This is a NetBIOS over TCP (NBT) packet
+            # The length is specified in the header from byte 16. (0-indexed)
+            if flags & 0x01:
+                length = length | 0x10000
+
+        read_len = length
+        while read_len > 0:
+            try:
+                if expiry_time < time.time():
+                    raise SMBTimeout
+
+                ready, _, _ = select.select([ self.sock.fileno() ], [ ], [ ], timeout)
+                if not ready:
+                    raise SMBTimeout
+
+                d = self.sock.recv(read_len)
+                if len(d) == 0:
+                    raise NotConnectedError
+
+                data = data + d
+                read_len -= len(d)
+            except select.error as ex:
+                if isinstance(ex, tuple):
+                    if ex[0] != errno.EINTR and ex[0] != errno.EAGAIN:
+                        raise ex
+                else:
+                    raise ex
+
+        self.feedData(data)
diff --git a/python3/smb/SMBHandler.py b/python3/smb/SMBHandler.py
new file mode 100644
index 00000000..042d3567
--- /dev/null
+++ b/python3/smb/SMBHandler.py
@@ -0,0 +1,90 @@
+
+import os, sys, socket, urllib.request, urllib.error, urllib.parse, mimetypes, email, tempfile
+from urllib.parse import (unwrap, unquote, splittype, splithost, quote,
+     splitport, splittag, splitattr, splituser, splitpasswd, splitvalue)
+from urllib.response import addinfourl
+from urllib.request import ftpwrapper
+from nmb.NetBIOS import NetBIOS
+from smb.SMBConnection import SMBConnection
+
+from io import BytesIO
+
+USE_NTLM = True
+MACHINE_NAME = None
+
+class SMBHandler(urllib.request.BaseHandler):
+
+    def smb_open(self, req):
+        global USE_NTLM, MACHINE_NAME
+
+        if not req.host:
+            raise urllib.error.URLError('SMB error: no host given')
+        host, port = splitport(req.host)
+        if port is None:
+            port = 139
+        else:
+            port = int(port)
+
+        # username/password handling
+        user, host = splituser(host)
+        if user:
+            user, passwd = splitpasswd(user)
+        else:
+            passwd = None
+        host = unquote(host)
+        user = user or ''
+
+        domain = ''
+        if ';' in user:
+            domain, user = user.split(';', 1)
+
+        passwd = passwd or ''
+        myname = MACHINE_NAME or self.generateClientMachineName()
+
+        n = NetBIOS()
+        names = n.queryIPForName(host)
+        if names:
+            server_name = names[0]
+        else:
+            raise urllib.error.URLError('SMB error: Hostname does not reply back with its machine name')
+
+        path, attrs = splitattr(req.selector)
+        if path.startswith('/'):
+            path = path[1:]
+        dirs = path.split('/')
+        dirs = list(map(unquote, dirs))
+        service, path = dirs[0], '/'.join(dirs[1:])
+
+        try:
+            conn = SMBConnection(user, passwd, myname, server_name, domain=domain, use_ntlm_v2 = USE_NTLM)
+            conn.connect(host, port)
+
+            headers = email.message.Message()
+            if req.data:
+                filelen = conn.storeFile(service, path, req.data)
+
+                headers.add_header('Content-length', '0')
+                fp = BytesIO(b"")
+            else:
+                fp = self.createTempFile()
+                file_attrs, retrlen = conn.retrieveFile(service, path, fp)
+                fp.seek(0)
+
+                mtype = mimetypes.guess_type(req.get_full_url())[0]
+                if mtype:
+                    headers.add_header('Content-type', mtype)
+                if retrlen is not None and retrlen >= 0:
+                    headers.add_header('Content-length', '%d' % retrlen)
+
+            return addinfourl(fp, headers, req.get_full_url())
+        except Exception as ex:
+            raise urllib.error.URLError('smb error: %s' % ex).with_traceback(sys.exc_info()[2])
+
+    def createTempFile(self):
+        return tempfile.TemporaryFile()
+
+    def generateClientMachineName(self):
+        hostname = socket.gethostname()
+        if hostname:
+            return hostname.split('.')[0]
+        return 'SMB%d' % os.getpid()
diff --git a/python3/smb/SMBProtocol.py b/python3/smb/SMBProtocol.py
new file mode 100644
index 00000000..31b2e88a
--- /dev/null
+++ b/python3/smb/SMBProtocol.py
@@ -0,0 +1,410 @@
+
+import os, logging, time
+from twisted.internet import reactor, defer
+from twisted.internet.protocol import ClientFactory, Protocol
+from .smb_constants import *
+from .smb_structs import *
+from .base import SMB, NotConnectedError, NotReadyError, SMBTimeout
+
+
+__all__ = [ 'SMBProtocolFactory', 'NotConnectedError', 'NotReadyError' ]
+
+
+class SMBProtocol(Protocol, SMB):
+
+    log = logging.getLogger('SMB.SMBProtocol')
+
+    #
+    # Protocol Methods
+    #
+
+    def connectionMade(self):
+        self.factory.instance = self
+        if not self.is_direct_tcp:
+            self.requestNMBSession()
+        else:
+            self.onNMBSessionOK()
+
+
+    def connectionLost(self, reason):
+        if self.factory.instance == self:
+            self.instance = None
+
+    def dataReceived(self, data):
+        self.feedData(data)
+
+    #
+    # SMB (and its superclass) Methods
+    #
+
+    def write(self, data):
+        self.transport.write(data)
+
+    def onAuthOK(self):
+        if self.factory.instance == self:
+            self.factory.onAuthOK()
+            reactor.callLater(1, self._cleanupPendingRequests)
+
+    def onAuthFailed(self):
+        if self.factory.instance == self:
+            self.factory.onAuthFailed()
+
+    def onNMBSessionFailed(self):
+        self.log.error('Cannot establish NetBIOS session. You might have provided a wrong remote_name')
+
+    #
+    # Protected Methods
+    #
+
+    def _cleanupPendingRequests(self):
+        if self.factory.instance == self:
+            now = time.time()
+            to_remove = []
+            for mid, r in self.pending_requests.items():
+                if r.expiry_time < now:
+                    try:
+                        r.errback(SMBTimeout())
+                    except Exception: pass
+                    to_remove.append(mid)
+
+            for mid in to_remove:
+                del self.pending_requests[mid]
+
+            reactor.callLater(1, self._cleanupPendingRequests)
+
+
+class SMBProtocolFactory(ClientFactory):
+
+    protocol = SMBProtocol
+    log = logging.getLogger('SMB.SMBFactory')
+
+    #: SMB messages will never be signed regardless of remote server's configurations; access errors will occur if the remote server requires signing.
+    SIGN_NEVER = 0
+    #: SMB messages will be signed when remote server supports signing but not requires signing.
+    SIGN_WHEN_SUPPORTED = 1
+    #: SMB messages will only be signed when remote server requires signing.
+    SIGN_WHEN_REQUIRED = 2
+
+    def __init__(self, username, password, my_name, remote_name, domain = '', use_ntlm_v2 = True, sign_options = SIGN_WHEN_REQUIRED, is_direct_tcp = False):
+        """
+        Create a new SMBProtocolFactory instance. You will pass this instance to *reactor.connectTCP()* which will then instantiate the TCP connection to the remote SMB/CIFS server.
+        Note that the default TCP port for most SMB/CIFS servers using NetBIOS over TCP/IP is 139.
+        Some newer server installations might also support Direct hosting of SMB over TCP/IP; for these servers, the default TCP port is 445.
+
+        *username* and *password* are the user credentials required to authenticate the underlying SMB connection with the remote server.
+        File operations can only be proceeded after the connection has been authenticated successfully.
+
+        :param string my_name: The local NetBIOS machine name that will identify where this connection is originating from.
+                               You can freely choose a name as long as it contains a maximum of 15 alphanumeric characters and does not contain spaces and any of ``\/:*?";|+``
+        :param string remote_name: The NetBIOS machine name of the remote server.
+                                   On windows, you can find out the machine name by right-clicking on the "My Computer" and selecting "Properties".
+                                   This parameter must be the same as what has been configured on the remote server, or else the connection will be rejected.
+        :param string domain: The network domain. On windows, it is known as the workgroup. Usually, it is safe to leave this parameter as an empty string.
+        :param boolean use_ntlm_v2: Indicates whether pysmb should be NTLMv1 or NTLMv2 authentication algorithm for authentication.
+                                    The choice of NTLMv1 and NTLMv2 is configured on the remote server, and there is no mechanism to auto-detect which algorithm has been configured.
+                                    Hence, we can only "guess" or try both algorithms.
+                                    On Sambda, Windows Vista and Windows 7, NTLMv2 is enabled by default. On Windows XP, we can use NTLMv1 before NTLMv2.
+        :param int sign_options: Determines whether SMB messages will be signed. Default is *SIGN_WHEN_REQUIRED*.
+                                 If *SIGN_WHEN_REQUIRED* (value=2), SMB messages will only be signed when remote server requires signing.
+                                 If *SIGN_WHEN_SUPPORTED* (value=1), SMB messages will be signed when remote server supports signing but not requires signing.
+                                 If *SIGN_NEVER* (value=0), SMB messages will never be signed regardless of remote server's configurations; access errors will occur if the remote server requires signing.
+        :param boolean is_direct_tcp: Controls whether the NetBIOS over TCP/IP (is_direct_tcp=False) or the newer Direct hosting of SMB over TCP/IP (is_direct_tcp=True) will be used for the communication.
+                                      The default parameter is False which will use NetBIOS over TCP/IP for wider compatibility (TCP port: 139).
+        """
+        self.username = username
+        self.password = password
+        self.my_name = my_name
+        self.remote_name = remote_name
+        self.domain = domain
+        self.use_ntlm_v2 = use_ntlm_v2
+        self.sign_options = sign_options
+        self.is_direct_tcp = is_direct_tcp
+        self.instance = None    #: The single SMBProtocol instance for each SMBProtocolFactory instance. Usually, you should not need to touch this attribute directly.
+
+    #
+    # Public Property
+    #
+
+    @property
+    def isReady(self):
+        """A convenient property to return True if the underlying SMB connection has connected to remote server, has successfully authenticated itself and is ready for file operations."""
+        return bool(self.instance and self.instance.has_authenticated)
+
+    @property
+    def isUsingSMB2(self):
+        """A convenient property to return True if the underlying SMB connection is using SMB2 protocol."""
+        return self.instance and self.instance.is_using_smb2
+
+    #
+    # Public Methods for Callbacks
+    #
+
+    def onAuthOK(self):
+        """
+        Override this method in your *SMBProtocolFactory* subclass to add in post-authentication handling.
+        This method will be called when the server has replied that the SMB connection has been successfully authenticated.
+        File operations can proceed when this method has been called.
+        """
+        pass
+
+    def onAuthFailed(self):
+        """
+        Override this method in your *SMBProtocolFactory* subclass to add in post-authentication handling.
+        This method will be called when the server has replied that the SMB connection has been successfully authenticated.
+
+        If you want to retry authenticating from this method,
+         1. Disconnect the underlying SMB connection (call ``self.instance.transport.loseConnection()``)
+         2. Create a new SMBProtocolFactory subclass instance with different user credientials or different NTLM algorithm flag.
+         3. Call ``reactor.connectTCP`` with the new instance to re-establish the SMB connection
+        """
+        pass
+
+    #
+    # Public Methods
+    #
+
+    def listShares(self, timeout = 30):
+        """
+        Retrieve a list of shared resources on remote server.
+
+        :param integer/float timeout: Number of seconds that pysmb will wait before raising *SMBTimeout* via the returned *Deferred* instance's *errback* method.
+        :return: A *twisted.internet.defer.Deferred* instance. The callback function will be called with a list of :doc:`smb.base.SharedDevice<smb_SharedDevice>` instances.
+        """
+        if not self.instance:
+            raise NotConnectedError('Not connected to server')
+
+        d = defer.Deferred()
+        self.instance._listShares(d.callback, d.errback, timeout)
+        return d
+
+    def listPath(self, service_name, path,
+                 search = SMB_FILE_ATTRIBUTE_READONLY | SMB_FILE_ATTRIBUTE_HIDDEN | SMB_FILE_ATTRIBUTE_SYSTEM | SMB_FILE_ATTRIBUTE_DIRECTORY | SMB_FILE_ATTRIBUTE_ARCHIVE | SMB_FILE_ATTRIBUTE_INCL_NORMAL,
+                 pattern = '*', timeout = 30):
+        """
+        Retrieve a directory listing of files/folders at *path*
+
+        For simplicity, pysmb defines a "normal" file as a file entry that is not read-only, not hidden, not system, not archive and not a directory.
+        It ignores other attributes like compression, indexed, sparse, temporary and encryption.
+
+        Note that the default search parameter will query for all read-only (SMB_FILE_ATTRIBUTE_READONLY), hidden (SMB_FILE_ATTRIBUTE_HIDDEN),
+        system (SMB_FILE_ATTRIBUTE_SYSTEM), archive (SMB_FILE_ATTRIBUTE_ARCHIVE), normal (SMB_FILE_ATTRIBUTE_INCL_NORMAL) files
+        and directories (SMB_FILE_ATTRIBUTE_DIRECTORY).
+        If you do not need to include "normal" files in the result, define your own search parameter without the SMB_FILE_ATTRIBUTE_INCL_NORMAL constant.
+        SMB_FILE_ATTRIBUTE_NORMAL should be used by itself and not be used with other bit constants.
+
+        :param string/unicode service_name: the name of the shared folder for the *path*
+        :param string/unicode path: path relative to the *service_name* where we are interested to learn about its files/sub-folders.
+        :param integer search: integer value made up from a bitwise-OR of *SMB_FILE_ATTRIBUTE_xxx* bits (see smb_constants.py).
+        :param string/unicode pattern: the filter to apply to the results before returning to the client.
+        :param integer/float timeout: Number of seconds that pysmb will wait before raising *SMBTimeout* via the returned *Deferred* instance's *errback* method.
+        :return: A *twisted.internet.defer.Deferred* instance. The callback function will be called with a list of :doc:`smb.base.SharedFile<smb_SharedFile>` instances.
+        """
+        if not self.instance:
+            raise NotConnectedError('Not connected to server')
+
+        d = defer.Deferred()
+        self.instance._listPath(service_name, path, d.callback, d.errback, search = search, pattern = pattern, timeout = timeout)
+        return d
+
+    def listSnapshots(self, service_name, path, timeout = 30):
+        """
+        Retrieve a list of available snapshots (a.k.a. shadow copies) for *path*.
+
+        Note that snapshot features are only supported on Windows Vista Business, Enterprise and Ultimate, and on all Windows 7 editions.
+
+        :param string/unicode service_name: the name of the shared folder for the *path*
+        :param string/unicode path: path relative to the *service_name* where we are interested in the list of available snapshots
+        :return: A *twisted.internet.defer.Deferred* instance. The callback function will be called with a list of python *datetime.DateTime*
+                 instances in GMT/UTC time zone
+        """
+        if not self.instance:
+            raise NotConnectedError('Not connected to server')
+
+        d = defer.Deferred()
+        self.instance._listSnapshots(service_name, path, d.callback, d.errback, timeout = timeout)
+        return d
+
+    def getAttributes(self, service_name, path, timeout = 30):
+        """
+        Retrieve information about the file at *path* on the *service_name*.
+
+        :param string/unicode service_name: the name of the shared folder for the *path*
+        :param string/unicode path: Path of the file on the remote server. If the file cannot be opened for reading, an :doc:`OperationFailure<smb_exceptions>` will be raised.
+        :return: A *twisted.internet.defer.Deferred* instance. The callback function will be called with a :doc:`smb.base.SharedFile<smb_SharedFile>` instance containing the attributes of the file.
+        """
+        if not self.instance:
+            raise NotConnectedError('Not connected to server')
+
+        d = defer.Deferred()
+        self.instance._getAttributes(service_name, path, d.callback, d.errback, timeout = timeout)
+        return d
+
+    def retrieveFile(self, service_name, path, file_obj, timeout = 30):
+        """
+        Retrieve the contents of the file at *path* on the *service_name* and write these contents to the provided *file_obj*.
+
+        Use *retrieveFileFromOffset()* method if you need to specify the offset to read from the remote *path* and/or the maximum number of bytes to write to the *file_obj*.
+
+        The meaning of the *timeout* parameter will be different from other file operation methods. As the downloaded file usually exceeeds the maximum size
+        of each SMB/CIFS data message, it will be packetized into a series of request messages (each message will request about about 60kBytes).
+        The *timeout* parameter is an integer/float value that specifies the timeout interval for these individual SMB/CIFS message to be transmitted and downloaded from the remote SMB/CIFS server.
+
+        :param string/unicode service_name: the name of the shared folder for the *path*
+        :param string/unicode path: Path of the file on the remote server. If the file cannot be opened for reading, an :doc:`OperationFailure<smb_exceptions>` will be called in the returned *Deferred* errback.
+        :param file_obj: A file-like object that has a *write* method. Data will be written continuously to *file_obj* until EOF is received from the remote service. In Python3, this file-like object must have a *write* method which accepts a bytes parameter.
+        :return: A *twisted.internet.defer.Deferred* instance. The callback function will be called with a 3-element tuple of ( *file_obj*, file attributes of the file on server, number of bytes written to *file_obj* ).
+                 The file attributes is an integer value made up from a bitwise-OR of *SMB_FILE_ATTRIBUTE_xxx* bits (see smb_constants.py)
+        """
+        return self.retrieveFileFromOffset(service_name, path, file_obj, 0, -1, timeout)
+
+    def retrieveFileFromOffset(self, service_name, path, file_obj, offset = 0, max_length = -1, timeout = 30):
+        """
+        Retrieve the contents of the file at *path* on the *service_name* and write these contents to the provided *file_obj*.
+
+        The meaning of the *timeout* parameter will be different from other file operation methods. As the downloaded file usually exceeeds the maximum size
+        of each SMB/CIFS data message, it will be packetized into a series of request messages (each message will request about about 60kBytes).
+        The *timeout* parameter is an integer/float value that specifies the timeout interval for these individual SMB/CIFS message to be transmitted and downloaded from the remote SMB/CIFS server.
+
+        :param string/unicode service_name: the name of the shared folder for the *path*
+        :param string/unicode path: Path of the file on the remote server. If the file cannot be opened for reading, an :doc:`OperationFailure<smb_exceptions>` will be called in the returned *Deferred* errback.
+        :param file_obj: A file-like object that has a *write* method. Data will be written continuously to *file_obj* until EOF is received from the remote service. In Python3, this file-like object must have a *write* method which accepts a bytes parameter.
+        :param integer/long offset: the offset in the remote *path* where the first byte will be read and written to *file_obj*. Must be either zero or a positive integer/long value.
+        :param integer/long max_length: maximum number of bytes to read from the remote *path* and write to the *file_obj*. Specify a negative value to read from *offset* to the EOF.
+                                        If zero, the *Deferred* callback is invoked immediately after the file is opened successfully for reading.
+        :return: A *twisted.internet.defer.Deferred* instance. The callback function will be called with a 3-element tuple of ( *file_obj*, file attributes of the file on server, number of bytes written to *file_obj* ).
+                 The file attributes is an integer value made up from a bitwise-OR of *SMB_FILE_ATTRIBUTE_xxx* bits (see smb_constants.py)
+        """
+        if not self.instance:
+            raise NotConnectedError('Not connected to server')
+
+        d = defer.Deferred()
+        self.instance._retrieveFileFromOffset(service_name, path, file_obj, d.callback, d.errback, offset, max_length, timeout = timeout)
+        return d
+
+    def storeFile(self, service_name, path, file_obj, timeout = 30):
+        """
+        Store the contents of the *file_obj* at *path* on the *service_name*.
+
+        The meaning of the *timeout* parameter will be different from other file operation methods. As the uploaded file usually exceeeds the maximum size
+        of each SMB/CIFS data message, it will be packetized into a series of messages (usually about 60kBytes).
+        The *timeout* parameter is an integer/float value that specifies the timeout interval for these individual SMB/CIFS message to be transmitted and acknowledged
+        by the remote SMB/CIFS server.
+
+        :param string/unicode service_name: the name of the shared folder for the *path*
+        :param string/unicode path: Path of the file on the remote server. If the file at *path* does not exist, it will be created. Otherwise, it will be overwritten.
+                                    If the *path* refers to a folder or the file cannot be opened for writing, an :doc:`OperationFailure<smb_exceptions>` will be called in the returned *Deferred* errback.
+        :param file_obj: A file-like object that has a *read* method. Data will read continuously from *file_obj* until EOF. In Python3, this file-like object must have a *read* method which returns a bytes parameter.
+        :return: A *twisted.internet.defer.Deferred* instance. The callback function will be called with a 2-element tuple of ( *file_obj*, number of bytes uploaded ).
+        """
+        if not self.instance:
+            raise NotConnectedError('Not connected to server')
+
+        d = defer.Deferred()
+        self.instance._storeFile(service_name, path, file_obj, d.callback, d.errback, timeout = timeout)
+        return d
+
+    def deleteFiles(self, service_name, path_file_pattern, timeout = 30):
+        """
+        Delete one or more regular files. It supports the use of wildcards in file names, allowing for deletion of multiple files in a single request.
+
+        :param string/unicode service_name: Contains the name of the shared folder.
+        :param string/unicode path_file_pattern: The pathname of the file(s) to be deleted, relative to the service_name.
+                                                 Wildcards may be used in th filename component of the path.
+                                                 If your path/filename contains non-English characters, you must pass in an unicode string.
+        :param integer/float timeout: Number of seconds that pysmb will wait before raising *SMBTimeout* via the returned *Deferred* instance's *errback* method.
+        :return: A *twisted.internet.defer.Deferred* instance. The callback function will be called with the *path_file_pattern* parameter.
+        """
+        if not self.instance:
+            raise NotConnectedError('Not connected to server')
+
+        d = defer.Deferred()
+        self.instance._deleteFiles(service_name, path_file_pattern, d.callback, d.errback, timeout = timeout)
+        return d
+
+    def createDirectory(self, service_name, path):
+        """
+        Creates a new directory *path* on the *service_name*.
+
+        :param string/unicode service_name: Contains the name of the shared folder.
+        :param string/unicode path: The path of the new folder (relative to) the shared folder.
+                                    If the path contains non-English characters, an unicode string must be used to pass in the path.
+        :param integer/float timeout: Number of seconds that pysmb will wait before raising *SMBTimeout* via the returned *Deferred* instance's *errback* method.
+        :return: A *twisted.internet.defer.Deferred* instance. The callback function will be called with the *path* parameter.
+        """
+        if not self.instance:
+            raise NotConnectedError('Not connected to server')
+
+        d = defer.Deferred()
+        self.instance._createDirectory(service_name, path, d.callback, d.errback)
+        return d
+
+    def deleteDirectory(self, service_name, path):
+        """
+        Delete the empty folder at *path* on *service_name*
+
+        :param string/unicode service_name: Contains the name of the shared folder.
+        :param string/unicode path: The path of the to-be-deleted folder (relative to) the shared folder.
+                                    If the path contains non-English characters, an unicode string must be used to pass in the path.
+        :param integer/float timeout: Number of seconds that pysmb will wait before raising *SMBTimeout* via the returned *Deferred* instance's *errback* method.
+        :return: A *twisted.internet.defer.Deferred* instance. The callback function will be called with the *path* parameter.
+        """
+        if not self.instance:
+            raise NotConnectedError('Not connected to server')
+
+        d = defer.Deferred()
+        self.instance._deleteDirectory(service_name, path, d.callback, d.errback)
+        return d
+
+    def rename(self, service_name, old_path, new_path):
+        """
+        Rename a file or folder at *old_path* to *new_path* shared at *service_name*. Note that this method cannot be used to rename file/folder across different shared folders
+
+        *old_path* and *new_path* are string/unicode referring to the old and new path of the renamed resources (relative to) the shared folder.
+        If the path contains non-English characters, an unicode string must be used to pass in the path.
+
+        :param string/unicode service_name: Contains the name of the shared folder.
+        :param integer/float timeout: Number of seconds that pysmb will wait before raising *SMBTimeout* via the returned *Deferred* instance's *errback* method.
+        :return: A *twisted.internet.defer.Deferred* instance. The callback function will be called with a 2-element tuple of ( *old_path*, *new_path* ).
+        """
+        if not self.instance:
+            raise NotConnectedError('Not connected to server')
+
+        d = defer.Deferred()
+        self.instance._rename(service_name, old_path, new_path, d.callback, d.errback)
+        return d
+
+    def echo(self, data, timeout = 10):
+        """
+        Send an echo command containing *data* to the remote SMB/CIFS server. The remote SMB/CIFS will reply with the same *data*.
+
+        :param bytes data: Data to send to the remote server. Must be a bytes object.
+        :param integer/float timeout: Number of seconds that pysmb will wait before raising *SMBTimeout* via the returned *Deferred* instance's *errback* method.
+        :return: A *twisted.internet.defer.Deferred* instance. The callback function will be called with the *data* parameter.
+        """
+        if not self.instance:
+            raise NotConnectedError('Not connected to server')
+
+        d = defer.Deferred()
+        self.instance._echo(data, d.callback, d.errback, timeout)
+        return d
+
+    def closeConnection(self):
+        """
+        Disconnect from the remote SMB/CIFS server. The TCP connection will be closed at the earliest opportunity after this method returns.
+
+        :return: None
+        """
+        if not self.instance:
+            raise NotConnectedError('Not connected to server')
+
+        self.instance.transport.loseConnection()
+
+    #
+    # ClientFactory methods
+    # (Do not touch these unless you know what you are doing)
+    #
+
+    def buildProtocol(self, addr):
+        p = self.protocol(self.username, self.password, self.my_name, self.remote_name, self.domain, self.use_ntlm_v2, self.sign_options, self.is_direct_tcp)
+        p.factory = self
+        return p
diff --git a/python3/smb/__init__.py b/python3/smb/__init__.py
new file mode 100644
index 00000000..8b137891
--- /dev/null
+++ b/python3/smb/__init__.py
@@ -0,0 +1 @@
+
diff --git a/python3/smb/base.py b/python3/smb/base.py
new file mode 100644
index 00000000..69bb9658
--- /dev/null
+++ b/python3/smb/base.py
@@ -0,0 +1,2936 @@
+
+import logging, binascii, time, hmac
+from datetime import datetime
+from .smb_constants import *
+from .smb2_constants import *
+from .smb_structs import *
+from .smb2_structs import *
+from .security_descriptors import SecurityDescriptor
+from nmb.base import NMBSession
+from .utils import convertFILETIMEtoEpoch
+from . import ntlm, securityblob
+
+try:
+    import hashlib
+    sha256 = hashlib.sha256
+except ImportError:
+    from .utils import sha256
+
+
+class NotReadyError(Exception):
+    """Raised when SMB connection is not ready (i.e. not authenticated or authentication failed)"""
+    pass
+
+class NotConnectedError(Exception):
+    """Raised when underlying SMB connection has been disconnected or not connected yet"""
+    pass
+
+class SMBTimeout(Exception):
+    """Raised when a timeout has occurred while waiting for a response or for a SMB/CIFS operation to complete."""
+    pass
+
+
+class SMB(NMBSession):
+    """
+    This class represents a "connection" to the remote SMB/CIFS server.
+    It is not meant to be used directly in an application as it does not have any network transport implementations.
+
+    For application use, please refer to
+      - L{SMBProtocol.SMBProtocolFactory<smb.SMBProtocol>} if you are using Twisted framework
+
+    In [MS-CIFS], this class will contain attributes of Client, Client.Connection and Client.Session abstract data models.
+
+    References:
+    ===========
+      - [MS-CIFS]: 3.2.1
+    """
+
+    log = logging.getLogger('SMB.SMB')
+
+    SIGN_NEVER = 0
+    SIGN_WHEN_SUPPORTED = 1
+    SIGN_WHEN_REQUIRED = 2
+
+    def __init__(self, username, password, my_name, remote_name, domain = '', use_ntlm_v2 = True, sign_options = SIGN_WHEN_REQUIRED, is_direct_tcp = False):
+        NMBSession.__init__(self, my_name, remote_name, is_direct_tcp = is_direct_tcp)
+        self.username = username
+        self.password = password
+        self.domain = domain
+        self.sign_options = sign_options
+        self.is_direct_tcp = is_direct_tcp
+        self.use_ntlm_v2 = use_ntlm_v2 #: Similar to LMAuthenticationPolicy and NTAuthenticationPolicy as described in [MS-CIFS] 3.2.1.1
+        self.smb_message = SMBMessage(self)
+        self.is_using_smb2 = False   #: Are we communicating using SMB2 protocol? self.smb_message will be a SMB2Message instance if this flag is True
+        self.async_requests = { }    #: AsyncID mapped to _PendingRequest instance
+        self.pending_requests = { }  #: MID mapped to _PendingRequest instance
+        self.connected_trees = { }   #: Share name mapped to TID
+        self.next_rpc_call_id = 1    #: Next RPC callID value. Not used directly in SMB message. Usually encapsulated in sub-commands under SMB_COM_TRANSACTION or SMB_COM_TRANSACTION2 messages
+
+        self.has_negotiated = False
+        self.has_authenticated = False
+        self.is_signing_active = False           #: True if the remote server accepts message signing. All outgoing messages will be signed. Simiar to IsSigningActive as described in [MS-CIFS] 3.2.1.2
+        self.signing_session_key = None          #: Session key for signing packets, if signing is active. Similar to SigningSessionKey as described in [MS-CIFS] 3.2.1.2
+        self.signing_challenge_response = None   #: Contains the challenge response for signing, if signing is active. Similar to SigningChallengeResponse as described in [MS-CIFS] 3.2.1.2
+        self.mid = 0
+        self.uid = 0
+        self.next_signing_id = 2     #: Similar to ClientNextSendSequenceNumber as described in [MS-CIFS] 3.2.1.2
+
+        # SMB1 and SMB2 attributes
+        # Note that the interpretations of the values may differ between SMB1 and SMB2 protocols
+        self.capabilities = 0
+        self.security_mode = 0     #: Initialized from the SecurityMode field of the SMB_COM_NEGOTIATE message
+
+        # SMB1 attributes
+        # Most of the following attributes will be initialized upon receipt of SMB_COM_NEGOTIATE message from server (via self._updateServerInfo_SMB1 method)
+        self.use_plaintext_authentication = False  #: Similar to PlaintextAuthenticationPolicy in in [MS-CIFS] 3.2.1.1
+        self.max_raw_size = 0
+        self.max_buffer_size = 0   #: Similar to MaxBufferSize as described in [MS-CIFS] 3.2.1.1
+        self.max_mpx_count = 0     #: Similar to MaxMpxCount as described in [MS-CIFS] 3.2.1.1
+
+        # SMB2 attributes
+        self.max_read_size = 0      #: Similar to MaxReadSize as described in [MS-SMB2] 2.2.4
+        self.max_write_size = 0     #: Similar to MaxWriteSize as described in [MS-SMB2] 2.2.4
+        self.max_transact_size = 0  #: Similar to MaxTransactSize as described in [MS-SMB2] 2.2.4
+        self.session_id = 0         #: Similar to SessionID as described in [MS-SMB2] 2.2.4. This will be set in _updateState_SMB2 method
+        self.smb2_dialect = 0
+
+
+        # SMB 2.1 attributes
+        self.cap_leasing = False
+        self.cap_multi_credit = False
+        self.credits = 0   # how many credits we're allowed to spend per request
+
+        self._setupSMB1Methods()
+
+        self.log.info('Authentication with remote machine "%s" for user "%s" will be using NTLM %s authentication (%s extended security)',
+                      self.remote_name, self.username,
+                      (self.use_ntlm_v2 and 'v2') or 'v1',
+                      (SUPPORT_EXTENDED_SECURITY and 'with') or 'without')
+
+
+    #
+    # NMBSession Methods
+    #
+
+    def onNMBSessionOK(self):
+        self._sendSMBMessage(SMBMessage(self, ComNegotiateRequest()))
+
+    def onNMBSessionFailed(self):
+        pass
+
+    def onNMBSessionMessage(self, flags, data):
+        while True:
+            try:
+                i = self.smb_message.decode(data)
+            except SMB2ProtocolHeaderError:
+                self.log.info('Now switching over to SMB2 protocol communication')
+                self.is_using_smb2 = True
+                self.mid = 0  # Must reset messageID counter, or else remote SMB2 server will disconnect
+                self._setupSMB2Methods()
+                self.smb_message = self._klassSMBMessage(self)
+                i = self.smb_message.decode(data)
+                self.log.info('SMB2 dialect is 0x%04x', self.smb2_dialect)
+
+            next_message_offset = 0
+            if self.is_using_smb2:
+                next_message_offset = self.smb_message.next_command_offset
+
+                # update how many credits we're allowed to spend on requests
+                self.credits = self.smb_message.credit_response
+
+                # SMB2 CANCEL commands do not consume message IDs
+                if self.smb_message.command != SMB2_COM_CANCEL:
+                    self.log.debug('Received SMB2 packet from server - "%s" (command:0x%02X). Credit charge recv: %s',
+                                   SMB_COMMAND_NAMES.get(self.smb_message.command, '<unknown>'), self.smb_message.command, self.smb_message.credit_charge)
+                    if self.smb_message.credit_charge > 0:
+                        # Let's update the sequenceWindow based on the CreditsCharged
+                        # In the SMB 2.0.2 dialect, this field MUST NOT be used and MUST be reserved.
+                        # The sender MUST set this to 0, and the receiver MUST ignore it.
+                        # In all other dialects, this field indicates the number of credits that this request consumes.
+                        self.log.debug("Updating MID to add credit charge from server...")
+                        self.log.debug("*** Before: " + str(self.mid))
+                        self.mid = self.mid + (self.smb_message.credit_charge - 1)
+                        self.log.debug("*** After: " + str(self.mid))
+
+            if i > 0:
+                if not self.is_using_smb2:
+                    self.log.debug('Received SMB message "%s" (command:0x%2X flags:0x%02X flags2:0x%04X TID:%d UID:%d)',
+                                   SMB_COMMAND_NAMES.get(self.smb_message.command, '<unknown>'),
+                                   self.smb_message.command, self.smb_message.flags, self.smb_message.flags2, self.smb_message.tid, self.smb_message.uid)
+                else:
+                    self.log.debug('Received SMB2 message "%s" (command:0x%04X flags:0x%04x)',
+                                   SMB2_COMMAND_NAMES.get(self.smb_message.command, '<unknown>'),
+                                   self.smb_message.command, self.smb_message.flags)
+                if self._updateState(self.smb_message):
+                    # We need to create a new instance instead of calling reset() because the instance could be captured in the message history.
+                    self.smb_message = self._klassSMBMessage(self)
+
+            if next_message_offset > 0:
+                data = data[next_message_offset:]
+            else:
+                break
+
+    #
+    # Public Methods for Overriding in Subclasses
+    #
+
+    def onAuthOK(self):
+        pass
+
+    def onAuthFailed(self):
+        pass
+
+    #
+    # Protected Methods
+    #
+
+    def _setupSMB1Methods(self):
+        self._klassSMBMessage = SMBMessage
+        self._updateState = self._updateState_SMB1
+        self._updateServerInfo = self._updateServerInfo_SMB1
+        self._handleNegotiateResponse = self._handleNegotiateResponse_SMB1
+        self._sendSMBMessage = self._sendSMBMessage_SMB1
+        self._handleSessionChallenge = self._handleSessionChallenge_SMB1
+        self._listShares = self._listShares_SMB1
+        self._listPath = self._listPath_SMB1
+        self._listSnapshots = self._listSnapshots_SMB1
+        self._getSecurity = self._getSecurity_SMB1
+        self._getAttributes = self._getAttributes_SMB1
+        self._retrieveFile = self._retrieveFile_SMB1
+        self._retrieveFileFromOffset = self._retrieveFileFromOffset_SMB1
+        self._storeFile = self._storeFile_SMB1
+        self._storeFileFromOffset = self._storeFileFromOffset_SMB1
+        self._deleteFiles = self._deleteFiles_SMB1
+        self._resetFileAttributes = self._resetFileAttributes_SMB1
+        self._createDirectory = self._createDirectory_SMB1
+        self._deleteDirectory = self._deleteDirectory_SMB1
+        self._rename = self._rename_SMB1
+        self._echo = self._echo_SMB1
+
+    def _setupSMB2Methods(self):
+        self._klassSMBMessage = SMB2Message
+        self._updateState = self._updateState_SMB2
+        self._updateServerInfo = self._updateServerInfo_SMB2
+        self._handleNegotiateResponse = self._handleNegotiateResponse_SMB2
+        self._sendSMBMessage = self._sendSMBMessage_SMB2
+        self._handleSessionChallenge = self._handleSessionChallenge_SMB2
+        self._listShares = self._listShares_SMB2
+        self._listPath = self._listPath_SMB2
+        self._listSnapshots = self._listSnapshots_SMB2
+        self._getSecurity = self._getSecurity_SMB2
+        self._getAttributes = self._getAttributes_SMB2
+        self._retrieveFile = self._retrieveFile_SMB2
+        self._retrieveFileFromOffset = self._retrieveFileFromOffset_SMB2
+        self._storeFile = self._storeFile_SMB2
+        self._storeFileFromOffset = self._storeFileFromOffset_SMB2
+        self._deleteFiles = self._deleteFiles_SMB2
+        self._resetFileAttributes = self._resetFileAttributes_SMB2
+        self._createDirectory = self._createDirectory_SMB2
+        self._deleteDirectory = self._deleteDirectory_SMB2
+        self._rename = self._rename_SMB2
+        self._echo = self._echo_SMB2
+
+    def _getNextRPCCallID(self):
+        self.next_rpc_call_id += 1
+        return self.next_rpc_call_id
+
+    #
+    # SMB2 Methods Family
+    #
+
+    def _sendSMBMessage_SMB2(self, smb_message):
+        if smb_message.mid == 0:
+            smb_message.mid = self._getNextMID_SMB2()
+
+        if smb_message.command != SMB2_COM_NEGOTIATE:
+            smb_message.session_id = self.session_id
+
+        if self.is_signing_active:
+            smb_message.flags |= SMB2_FLAGS_SIGNED
+            raw_data = smb_message.encode()
+            smb_message.signature = hmac.new(self.signing_session_key, raw_data, sha256).digest()[:16]
+
+            smb_message.raw_data = smb_message.encode()
+            self.log.debug('MID is %d. Signature is %s. Total raw message is %d bytes', smb_message.mid, binascii.hexlify(smb_message.signature), len(smb_message.raw_data))
+        else:
+            smb_message.raw_data = smb_message.encode()
+        self.sendNMBMessage(smb_message.raw_data)
+
+    def _getNextMID_SMB2(self):
+        self.mid += 1
+        return self.mid
+
+    def _updateState_SMB2(self, message):
+        if message.isReply:
+            if message.command == SMB2_COM_NEGOTIATE:
+                if message.status == 0:
+                    if self.smb_message.payload.dialect_revision == SMB2_DIALECT_2ALL:
+                        # Dialects from SMB 2.1 must be negotiated in a second negotiate phase
+                        # We send a SMB2 Negotiate Request to accomplish this
+                        self._sendSMBMessage(SMB2Message(self, SMB2NegotiateRequest()))
+                    else:
+                        if self.smb_message.payload.dialect_revision == SMB2_DIALECT_21:
+                            # We negotiated SMB 2.1.
+                            # we must now send credit requests (MUST!)
+                            #self.send_credits_request = True
+                            pass
+
+                        self.has_negotiated = True
+                        self.log.info('SMB2 dialect negotiation successful')
+                        self.dialect = self.smb_message.payload.dialect_revision
+                        self._updateServerInfo(message.payload)
+                        self._handleNegotiateResponse(message)
+                else:
+                    raise ProtocolError('Unknown status value (0x%08X) in SMB2_COM_NEGOTIATE' % message.status,
+                                        message.raw_data, message)
+            elif message.command == SMB2_COM_SESSION_SETUP:
+                if message.status == 0:
+                    self.session_id = message.session_id
+                    try:
+                        result = securityblob.decodeAuthResponseSecurityBlob(message.payload.security_blob)
+                        if result == securityblob.RESULT_ACCEPT_COMPLETED:
+                            self.has_authenticated = True
+                            self.log.info('Authentication (on SMB2) successful!')
+
+                            # [MS-SMB2]: 3.2.5.3.1
+                            # If the security subsystem indicates that the session was established by an anonymous user,
+                            # Session.SigningRequired MUST be set to FALSE.
+                            # If the SMB2_SESSION_FLAG_IS_GUEST bit is set in the SessionFlags field of the
+                            # SMB2 SESSION_SETUP Response and if Session.SigningRequired is TRUE, this indicates a SESSION_SETUP
+                            # failure and the connection MUST be terminated. If the SMB2_SESSION_FLAG_IS_GUEST bit is set in the SessionFlags
+                            # field of the SMB2 SESSION_SETUP Response and if RequireMessageSigning is FALSE, Session.SigningRequired
+                            # MUST be set to FALSE.
+                            if message.payload.isGuestSession or message.payload.isAnonymousSession:
+                                self.is_signing_active = False
+                                self.log.info('Signing disabled because session is guest/anonymous')
+
+                            self.onAuthOK()
+                        else:
+                            raise ProtocolError('SMB2_COM_SESSION_SETUP status is 0 but security blob negResult value is %d' % result, message.raw_data, message)
+                    except securityblob.BadSecurityBlobError as ex:
+                        raise ProtocolError(str(ex), message.raw_data, message)
+                elif message.status == 0xc0000016:  # STATUS_MORE_PROCESSING_REQUIRED
+                    self.session_id = message.session_id
+                    try:
+                        result, ntlm_token = securityblob.decodeChallengeSecurityBlob(message.payload.security_blob)
+                        if result == securityblob.RESULT_ACCEPT_INCOMPLETE:
+                            self._handleSessionChallenge(message, ntlm_token)
+                    except ( securityblob.BadSecurityBlobError, securityblob.UnsupportedSecurityProvider ) as ex:
+                        raise ProtocolError(str(ex), message.raw_data, message)
+                elif (message.status == 0xc000006d   # STATUS_LOGON_FAILURE
+                    or message.status == 0xc0000064  # STATUS_NO_SUCH_USER
+                    or message.status == 0xc000006a):# STATUS_WRONG_PASSWORD
+                    self.has_authenticated = False
+                    self.log.info('Authentication (on SMB2) failed. Please check username and password.')
+                    self.onAuthFailed()
+                elif (message.status == 0xc0000193    # STATUS_ACCOUNT_EXPIRED
+                    or message.status == 0xC0000071): # STATUS_PASSWORD_EXPIRED
+                    self.has_authenticated = False
+                    self.log.info('Authentication (on SMB2) failed. Account or password has expired.')
+                    self.onAuthFailed()
+                elif message.status == 0xc0000234: # STATUS_ACCOUNT_LOCKED_OUT
+                    self.has_authenticated = False
+                    self.log.info('Authentication (on SMB2) failed. Account has been locked due to too many invalid logon attempts.')
+                    self.onAuthFailed()
+                elif message.status == 0xc0000072: # STATUS_ACCOUNT_DISABLED
+                    self.has_authenticated = False
+                    self.log.info('Authentication (on SMB2) failed. Account has been disabled.')
+                    self.onAuthFailed()
+                elif (message.status == 0xc000006f    # STATUS_INVALID_LOGON_HOURS
+                    or message.status == 0xc000015b   # STATUS_LOGON_TYPE_NOT_GRANTED
+                    or message.status == 0xc0000070): # STATUS_INVALID_WORKSTATION
+                    self.has_authenticated = False
+                    self.log.info('Authentication (on SMB2) failed. Not allowed.')
+                    self.onAuthFailed()
+                elif message.status == 0xc000018c:  # STATUS_TRUSTED_DOMAIN_FAILURE
+                    self.has_authenticated = False
+                    self.log.info('Authentication (on SMB2) failed. Domain not trusted.')
+                    self.onAuthFailed()
+                elif message.status == 0xc000018d:  # STATUS_TRUSTED_RELATIONSHIP_FAILURE
+                    self.has_authenticated = False
+                    self.log.info('Authentication (on SMB2) failed. Workstation not trusted.')
+                    self.onAuthFailed()
+                else:
+                    raise ProtocolError('Unknown status value (0x%08X) in SMB_COM_SESSION_SETUP_ANDX (with extended security)' % message.status,
+                                        message.raw_data, message)
+
+            if message.isAsync:
+                if message.status == 0x00000103:  # STATUS_PENDING
+                    req = self.pending_requests.pop(message.mid, None)
+                    if req:
+                        self.async_requests[message.async_id] = req
+                else: # All other status including SUCCESS
+                    req = self.async_requests.pop(message.async_id, None)
+                    if req:
+                        req.callback(message, **req.kwargs)
+                        return True
+            else:
+                req = self.pending_requests.pop(message.mid, None)
+                if req:
+                    req.callback(message, **req.kwargs)
+                    return True
+
+
+    def _updateServerInfo_SMB2(self, payload):
+        self.capabilities = payload.capabilities
+        self.security_mode = payload.security_mode
+        self.max_transact_size = payload.max_transact_size
+        self.max_read_size = payload.max_read_size
+        self.max_write_size = payload.max_write_size
+        self.use_plaintext_authentication = False   # SMB2 never allows plaintext authentication
+
+        if (self.capabilities & SMB2_GLOBAL_CAP_LEASING) == SMB2_GLOBAL_CAP_LEASING:
+            self.cap_leasing = True
+
+        if (self.capabilities & SMB2_GLOBAL_CAP_LARGE_MTU) == SMB2_GLOBAL_CAP_LARGE_MTU:
+            self.cap_multi_credit = True
+
+
+    def _handleNegotiateResponse_SMB2(self, message):
+        ntlm_data = ntlm.generateNegotiateMessage()
+        blob = securityblob.generateNegotiateSecurityBlob(ntlm_data)
+        self._sendSMBMessage(SMB2Message(self, SMB2SessionSetupRequest(blob)))
+
+
+    def _handleSessionChallenge_SMB2(self, message, ntlm_token):
+        server_challenge, server_flags, server_info = ntlm.decodeChallengeMessage(ntlm_token)
+
+        self.log.info('Performing NTLMv2 authentication (on SMB2) with server challenge "%s"', binascii.hexlify(server_challenge))
+
+        if self.use_ntlm_v2:
+            self.log.info('Performing NTLMv2 authentication (on SMB2) with server challenge "%s"', binascii.hexlify(server_challenge))
+            nt_challenge_response, lm_challenge_response, session_key = ntlm.generateChallengeResponseV2(self.password,
+                                                                                                         self.username,
+                                                                                                         server_challenge,
+                                                                                                         server_info,
+                                                                                                         self.domain)
+
+        else:
+            self.log.info('Performing NTLMv1 authentication (on SMB2) with server challenge "%s"', binascii.hexlify(server_challenge))
+            nt_challenge_response, lm_challenge_response, session_key = ntlm.generateChallengeResponseV1(self.password, server_challenge, True)
+
+        ntlm_data = ntlm.generateAuthenticateMessage(server_flags,
+                                                     nt_challenge_response,
+                                                     lm_challenge_response,
+                                                     session_key,
+                                                     self.username,
+                                                     self.domain,
+                                                     self.my_name)
+
+        if self.log.isEnabledFor(logging.DEBUG):
+            self.log.debug('NT challenge response is "%s" (%d bytes)', binascii.hexlify(nt_challenge_response), len(nt_challenge_response))
+            self.log.debug('LM challenge response is "%s" (%d bytes)', binascii.hexlify(lm_challenge_response), len(lm_challenge_response))
+
+        blob = securityblob.generateAuthSecurityBlob(ntlm_data)
+        self._sendSMBMessage(SMB2Message(self, SMB2SessionSetupRequest(blob)))
+
+        if self.security_mode & SMB2_NEGOTIATE_SIGNING_REQUIRED:
+            self.log.info('Server requires all SMB messages to be signed')
+            self.is_signing_active = (self.sign_options != SMB.SIGN_NEVER)
+        elif self.security_mode & SMB2_NEGOTIATE_SIGNING_ENABLED:
+            self.log.info('Server supports SMB signing')
+            self.is_signing_active = (self.sign_options == SMB.SIGN_WHEN_SUPPORTED)
+        else:
+            self.is_signing_active = False
+
+        if self.is_signing_active:
+            self.log.info("SMB signing activated. All SMB messages will be signed.")
+            self.signing_session_key = (session_key + b'\0'*16)[:16]
+            if self.capabilities & CAP_EXTENDED_SECURITY:
+                self.signing_challenge_response = None
+            else:
+                self.signing_challenge_response = blob
+        else:
+            self.log.info("SMB signing deactivated. SMB messages will NOT be signed.")
+
+
+    def _listShares_SMB2(self, callback, errback, timeout = 30):
+        if not self.has_authenticated:
+            raise NotReadyError('SMB connection not authenticated')
+
+        expiry_time = time.time() + timeout
+        path = 'IPC$'
+        messages_history = [ ]
+
+        def connectSrvSvc(tid):
+            m = SMB2Message(self, SMB2CreateRequest('srvsvc',
+                                              file_attributes = 0,
+                                              access_mask = FILE_READ_DATA | FILE_WRITE_DATA | FILE_APPEND_DATA | FILE_READ_EA | FILE_WRITE_EA | READ_CONTROL | FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES | SYNCHRONIZE,
+                                              share_access = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
+                                              oplock = SMB2_OPLOCK_LEVEL_NONE,
+                                              impersonation = SEC_IMPERSONATE,
+                                              create_options = FILE_NON_DIRECTORY_FILE | FILE_OPEN_NO_RECALL,
+                                              create_disp = FILE_OPEN))
+
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectSrvSvcCB, errback, tid = tid)
+            messages_history.append(m)
+
+        def connectSrvSvcCB(create_message, **kwargs):
+            messages_history.append(create_message)
+            if create_message.status == 0:
+                call_id = self._getNextRPCCallID()
+                # The data_bytes are binding call to Server Service RPC using DCE v1.1 RPC over SMB. See [MS-SRVS] and [C706]
+                # If you wish to understand the meanings of the byte stream, I would suggest you use a recent version of WireShark to packet capture the stream
+                data_bytes = \
+                    binascii.unhexlify(b"""05 00 0b 03 10 00 00 00 74 00 00 00""".replace(b' ', b'')) + \
+                    struct.pack('<I', call_id) + \
+                    binascii.unhexlify(b"""
+b8 10 b8 10 00 00 00 00 02 00 00 00 00 00 01 00
+c8 4f 32 4b 70 16 d3 01 12 78 5a 47 bf 6e e1 88
+03 00 00 00 04 5d 88 8a eb 1c c9 11 9f e8 08 00
+2b 10 48 60 02 00 00 00 01 00 01 00 c8 4f 32 4b
+70 16 d3 01 12 78 5a 47 bf 6e e1 88 03 00 00 00
+2c 1c b7 6c 12 98 40 45 03 00 00 00 00 00 00 00
+01 00 00 00
+""".replace(b' ', b'').replace(b'\n', b''))
+                m = SMB2Message(self, SMB2WriteRequest(create_message.payload.fid, data_bytes, 0))
+                m.tid = kwargs['tid']
+                self._sendSMBMessage(m)
+                self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, rpcBindCB, errback, tid = kwargs['tid'], fid = create_message.payload.fid)
+                messages_history.append(m)
+            else:
+                errback(OperationFailure('Failed to list shares: Unable to locate Server Service RPC endpoint', messages_history))
+
+        def rpcBindCB(trans_message, **kwargs):
+            messages_history.append(trans_message)
+            if trans_message.status == 0:
+                m = SMB2Message(self, SMB2ReadRequest(kwargs['fid'], read_len = 1024, read_offset = 0))
+                m.tid = kwargs['tid']
+                self._sendSMBMessage(m)
+                self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, rpcReadCB, errback, tid = kwargs['tid'], fid = kwargs['fid'])
+                messages_history.append(m)
+            else:
+                closeFid(kwargs['tid'], kwargs['fid'], error = 'Failed to list shares: Unable to read from Server Service RPC endpoint')
+
+        def rpcReadCB(read_message, **kwargs):
+            messages_history.append(read_message)
+            if read_message.status == 0:
+                call_id = self._getNextRPCCallID()
+
+                padding = b''
+                remote_name = '\\\\' + self.remote_name
+                server_len = len(remote_name) + 1
+                server_bytes_len = server_len * 2
+                if server_len % 2 != 0:
+                    padding = b'\0\0'
+                    server_bytes_len += 2
+
+                # The data bytes are the RPC call to NetrShareEnum (Opnum 15) at Server Service RPC.
+                # If you wish to understand the meanings of the byte stream, I would suggest you use a recent version of WireShark to packet capture the stream
+                data_bytes = \
+                    binascii.unhexlify(b"""05 00 00 03 10 00 00 00""".replace(b' ', b'')) + \
+                    struct.pack('<HHI', 72+server_bytes_len, 0, call_id) + \
+                    binascii.unhexlify(b"""4c 00 00 00 00 00 0f 00 00 00 02 00""".replace(b' ', b'')) + \
+                    struct.pack('<III', server_len, 0, server_len) + \
+                    (remote_name + '\0').encode('UTF-16LE') + padding + \
+                    binascii.unhexlify(b"""
+01 00 00 00 01 00 00 00 04 00 02 00 00 00 00 00
+00 00 00 00 ff ff ff ff 08 00 02 00 00 00 00 00
+""".replace(b' ', b'').replace(b'\n', b''))
+                m = SMB2Message(self, SMB2IoctlRequest(kwargs['fid'], 0x0011C017, flags = 0x01, max_out_size = 8196, in_data = data_bytes))
+                m.tid = kwargs['tid']
+                self._sendSMBMessage(m)
+                self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, listShareResultsCB, errback, tid = kwargs['tid'], fid = kwargs['fid'])
+                messages_history.append(m)
+            else:
+                closeFid(kwargs['tid'], kwargs['fid'], error = 'Failed to list shares: Unable to bind to Server Service RPC endpoint')
+
+        def listShareResultsCB(result_message, **kwargs):
+            messages_history.append(result_message)
+            if result_message.status == 0:
+                # The payload.data_bytes will contain the results of the RPC call to NetrShareEnum (Opnum 15) at Server Service RPC.
+                data_bytes = result_message.payload.out_data
+
+                if data_bytes[3] & 0x02 == 0:
+                    sendReadRequest(kwargs['tid'], kwargs['fid'], data_bytes)
+                else:
+                    decodeResults(kwargs['tid'], kwargs['fid'], data_bytes)
+            else:
+                closeFid(kwargs['tid'], kwargs['fid'])
+                errback(OperationFailure('Failed to list shares: Unable to retrieve shared device list', messages_history))
+
+        def decodeResults(tid, fid, data_bytes):
+            shares_count = struct.unpack('<I', data_bytes[36:40])[0]
+            results = [ ]     # A list of SharedDevice instances
+            offset = 36 + 12  # You need to study the byte stream to understand the meaning of these constants
+            for i in range(0, shares_count):
+                results.append(SharedDevice(struct.unpack('<I', data_bytes[offset+4:offset+8])[0], None, None))
+                offset += 12
+
+            for i in range(0, shares_count):
+                max_length, _, length = struct.unpack('<III', data_bytes[offset:offset+12])
+                offset += 12
+                results[i].name = data_bytes[offset:offset+length*2-2].decode('UTF-16LE')
+
+                if length % 2 != 0:
+                    offset += (length * 2 + 2)
+                else:
+                    offset += (length * 2)
+
+                max_length, _, length = struct.unpack('<III', data_bytes[offset:offset+12])
+                offset += 12
+                results[i].comments = data_bytes[offset:offset+length*2-2].decode('UTF-16LE')
+
+                if length % 2 != 0:
+                    offset += (length * 2 + 2)
+                else:
+                    offset += (length * 2)
+
+            closeFid(tid, fid)
+            callback(results)
+
+        def sendReadRequest(tid, fid, data_bytes):
+            read_count = min(4280, self.max_read_size)
+            m = SMB2Message(self, SMB2ReadRequest(fid, 0, read_count))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, readCB, errback,
+                                                           tid = tid, fid = fid, data_bytes = data_bytes)
+
+        def readCB(read_message, **kwargs):
+            messages_history.append(read_message)
+            if read_message.status == 0:
+                data_bytes = read_message.payload.data
+
+                if data_bytes[3] & 0x02 == 0:
+                    sendReadRequest(kwargs['tid'], kwargs['fid'], kwargs['data_bytes'] + data_bytes[24:])
+                else:
+                    decodeResults(kwargs['tid'], kwargs['fid'], kwargs['data_bytes'] + data_bytes[24:])
+            else:
+                closeFid(kwargs['tid'], kwargs['fid'])
+                errback(OperationFailure('Failed to list shares: Unable to retrieve shared device list', messages_history))
+
+        def closeFid(tid, fid, results = None, error = None):
+            m = SMB2Message(self, SMB2CloseRequest(fid))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, closeCB, errback, results = results, error = error)
+            messages_history.append(m)
+
+        def closeCB(close_message, **kwargs):
+            if kwargs['results'] is not None:
+                callback(kwargs['results'])
+            elif kwargs['error'] is not None:
+                errback(OperationFailure(kwargs['error'], messages_history))
+
+        if path not in self.connected_trees:
+            def connectCB(connect_message, **kwargs):
+                messages_history.append(connect_message)
+                if connect_message.status == 0:
+                    self.connected_trees[path] = connect_message.tid
+                    connectSrvSvc(connect_message.tid)
+                else:
+                    errback(OperationFailure('Failed to list shares: Unable to connect to IPC$', messages_history))
+
+            m = SMB2Message(self, SMB2TreeConnectRequest(r'\\%s\%s' % ( self.remote_name.upper(), path )))
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectCB, errback, path = path)
+            messages_history.append(m)
+        else:
+            connectSrvSvc(self.connected_trees[path])
+
+    def _listPath_SMB2(self, service_name, path, callback, errback, search, pattern, timeout = 30):
+        if not self.has_authenticated:
+            raise NotReadyError('SMB connection not authenticated')
+
+        expiry_time = time.time() + timeout
+        path = path.replace('/', '\\')
+        if path.startswith('\\'):
+            path = path[1:]
+        if path.endswith('\\'):
+            path = path[:-1]
+        messages_history = [ ]
+        results = [ ]
+
+        def sendCreate(tid):
+            create_context_data = binascii.unhexlify(b"""
+28 00 00 00 10 00 04 00 00 00 18 00 10 00 00 00
+44 48 6e 51 00 00 00 00 00 00 00 00 00 00 00 00
+00 00 00 00 00 00 00 00 18 00 00 00 10 00 04 00
+00 00 18 00 00 00 00 00 4d 78 41 63 00 00 00 00
+00 00 00 00 10 00 04 00 00 00 18 00 00 00 00 00
+51 46 69 64 00 00 00 00
+""".replace(b' ', b'').replace(b'\n', b''))
+            m = SMB2Message(self, SMB2CreateRequest(path,
+                                              file_attributes = 0,
+                                              access_mask = FILE_READ_DATA | FILE_READ_EA | FILE_READ_ATTRIBUTES | SYNCHRONIZE,
+                                              share_access = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
+                                              oplock = SMB2_OPLOCK_LEVEL_NONE,
+                                              impersonation = SEC_IMPERSONATE,
+                                              create_options = FILE_DIRECTORY_FILE,
+                                              create_disp = FILE_OPEN,
+                                              create_context_data = create_context_data))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, createCB, errback, tid = tid)
+            messages_history.append(m)
+
+        def createCB(create_message, **kwargs):
+            messages_history.append(create_message)
+            if create_message.status == 0:
+                sendQuery(kwargs['tid'], create_message.payload.fid, b'')
+            else:
+                errback(OperationFailure('Failed to list %s on %s: Unable to open directory' % ( path, service_name ), messages_history))
+
+        def sendQuery(tid, fid, data_buf):
+            if self.smb2_dialect != SMB2_DIALECT_2 and self.cap_multi_credit:
+                output_buf_len = 64 * 1024 * (self.credits - 1)
+            else:
+                output_buf_len = self.max_transact_size
+
+            m = SMB2Message(self, SMB2QueryDirectoryRequest(fid, pattern,
+                                                      info_class = 0x25,   # FileIdBothDirectoryInformation
+                                                      flags = 0,
+                                                      output_buf_len = output_buf_len))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, queryCB, errback, tid = tid, fid = fid, data_buf = data_buf)
+            messages_history.append(m)
+
+        def queryCB(query_message, **kwargs):
+            messages_history.append(query_message)
+            if query_message.status == 0:
+                data_buf = decodeQueryStruct(kwargs['data_buf'] + query_message.payload.data)
+                sendQuery(kwargs['tid'], kwargs['fid'], data_buf)
+            elif query_message.status == 0x80000006:  # STATUS_NO_MORE_FILES
+                closeFid(kwargs['tid'], kwargs['fid'], results = results)
+            else:
+                closeFid(kwargs['tid'], kwargs['fid'], error = query_message.status)
+
+        def decodeQueryStruct(data_bytes):
+            # FileIdBothDirectoryInformation structure. See [MS-SMB]: 2.2.8.1.3 and [MS-FSCC]: 2.4.17
+            info_format = '<IIQQQQQQIIIBB24sHQ'
+            info_size = struct.calcsize(info_format)
+
+            data_length = len(data_bytes)
+            offset = 0
+            while offset < data_length:
+                if offset + info_size > data_length:
+                    return data_bytes[offset:]
+
+                next_offset, _, \
+                create_time, last_access_time, last_write_time, last_attr_change_time, \
+                file_size, alloc_size, file_attributes, filename_length, ea_size, \
+                short_name_length, _, short_name, _, file_id = struct.unpack(info_format, data_bytes[offset:offset+info_size])
+
+                offset2 = offset + info_size
+                if offset2 + filename_length > data_length:
+                    return data_bytes[offset:]
+
+                filename = data_bytes[offset2:offset2+filename_length].decode('UTF-16LE')
+                short_name = short_name[:short_name_length].decode('UTF-16LE')
+
+                accept_result = False
+                if (file_attributes & 0xff) in ( 0x00, ATTR_NORMAL ): # Only the first 8-bits are compared. We ignore other bits like temp, compressed, encryption, sparse, indexed, etc
+                    accept_result = (search == SMB_FILE_ATTRIBUTE_NORMAL) or (search & SMB_FILE_ATTRIBUTE_INCL_NORMAL)
+                else:
+                    accept_result = (file_attributes & search) > 0
+                if accept_result:
+                    results.append(SharedFile(convertFILETIMEtoEpoch(create_time), convertFILETIMEtoEpoch(last_access_time),
+                                              convertFILETIMEtoEpoch(last_write_time), convertFILETIMEtoEpoch(last_attr_change_time),
+                                              file_size, alloc_size, file_attributes, short_name, filename, file_id))
+
+                if next_offset:
+                    offset += next_offset
+                else:
+                    break
+            return b''
+
+        def closeFid(tid, fid, results = None, error = None):
+            m = SMB2Message(self, SMB2CloseRequest(fid))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, closeCB, errback, results = results, error = error)
+            messages_history.append(m)
+
+        def closeCB(close_message, **kwargs):
+            if kwargs['results'] is not None:
+                callback(kwargs['results'])
+            elif kwargs['error'] is not None:
+                if kwargs['error'] == 0xC000000F:  # [MS-ERREF]: STATUS_NO_SUCH_FILE
+                    # Remote server returns STATUS_NO_SUCH_FILE error so we assume that the search returns no matching files
+                    callback([ ])
+                else:
+                    errback(OperationFailure('Failed to list %s on %s: Query failed with errorcode 0x%08x' % ( path, service_name, kwargs['error'] ), messages_history))
+
+        if service_name not in self.connected_trees:
+            def connectCB(connect_message, **kwargs):
+                messages_history.append(connect_message)
+                if connect_message.status == 0:
+                    self.connected_trees[service_name] = connect_message.tid
+                    sendCreate(connect_message.tid)
+                else:
+                    errback(OperationFailure('Failed to list %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history))
+
+            m = SMB2Message(self, SMB2TreeConnectRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name )))
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectCB, errback, path = service_name)
+            messages_history.append(m)
+        else:
+            sendCreate(self.connected_trees[service_name])
+
+    def _getAttributes_SMB2(self, service_name, path, callback, errback, timeout = 30):
+        if not self.has_authenticated:
+            raise NotReadyError('SMB connection not authenticated')
+
+        expiry_time = time.time() + timeout
+        path = path.replace('/', '\\')
+        if path.startswith('\\'):
+            path = path[1:]
+        if path.endswith('\\'):
+            path = path[:-1]
+        messages_history = [ ]
+
+        def sendCreate(tid):
+            create_context_data = binascii.unhexlify("""
+28 00 00 00 10 00 04 00 00 00 18 00 10 00 00 00
+44 48 6e 51 00 00 00 00 00 00 00 00 00 00 00 00
+00 00 00 00 00 00 00 00 18 00 00 00 10 00 04 00
+00 00 18 00 00 00 00 00 4d 78 41 63 00 00 00 00
+00 00 00 00 10 00 04 00 00 00 18 00 00 00 00 00
+51 46 69 64 00 00 00 00
+""".replace(' ', '').replace('\n', ''))
+            m = SMB2Message(self, SMB2CreateRequest(path,
+                                              file_attributes = 0,
+                                              access_mask = FILE_READ_DATA | FILE_READ_EA | FILE_READ_ATTRIBUTES | SYNCHRONIZE,
+                                              share_access = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
+                                              oplock = SMB2_OPLOCK_LEVEL_NONE,
+                                              impersonation = SEC_IMPERSONATE,
+                                              create_options = 0,
+                                              create_disp = FILE_OPEN,
+                                              create_context_data = create_context_data))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, createCB, errback, tid = tid)
+            messages_history.append(m)
+
+        def createCB(create_message, **kwargs):
+            messages_history.append(create_message)
+            if create_message.status == 0:
+                p = create_message.payload
+                filename = self._extractLastPathComponent(path)
+                info = SharedFile(p.create_time, p.lastaccess_time, p.lastwrite_time, p.change_time,
+                                  p.file_size, p.allocation_size, p.file_attributes,
+                                  filename, filename)
+                closeFid(kwargs['tid'], p.fid, info = info)
+            else:
+                errback(OperationFailure('Failed to get attributes for %s on %s: Unable to open remote file object' % ( path, service_name ), messages_history))
+
+        def closeFid(tid, fid, info = None, error = None):
+            m = SMB2Message(self, SMB2CloseRequest(fid))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, closeCB, errback, info = info, error = error)
+            messages_history.append(m)
+
+        def closeCB(close_message, **kwargs):
+            if kwargs['info'] is not None:
+                callback(kwargs['info'])
+            elif kwargs['error'] is not None:
+                errback(OperationFailure('Failed to get attributes for %s on %s: Query failed with errorcode 0x%08x' % ( path, service_name, kwargs['error'] ), messages_history))
+
+        if service_name not in self.connected_trees:
+            def connectCB(connect_message, **kwargs):
+                messages_history.append(connect_message)
+                if connect_message.status == 0:
+                    self.connected_trees[service_name] = connect_message.tid
+                    sendCreate(connect_message.tid)
+                else:
+                    errback(OperationFailure('Failed to get attributes for %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history))
+
+            m = SMB2Message(self, SMB2TreeConnectRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name )))
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectCB, errback, path = service_name)
+            messages_history.append(m)
+        else:
+            sendCreate(self.connected_trees[service_name])
+
+    def _getSecurity_SMB2(self, service_name, path, callback, errback, timeout = 30):
+        if not self.has_authenticated:
+            raise NotReadyError('SMB connection not authenticated')
+
+        expiry_time = time.time() + timeout
+        path = path.replace('/', '\\')
+        if path.startswith('\\'):
+            path = path[1:]
+        if path.endswith('\\'):
+            path = path[:-1]
+        messages_history = [ ]
+        results = [ ]
+
+        def sendCreate(tid):
+            m = SMB2Message(self, SMB2CreateRequest(path,
+                                              file_attributes = 0,
+                                              access_mask = FILE_READ_DATA | FILE_READ_EA | FILE_READ_ATTRIBUTES | READ_CONTROL | SYNCHRONIZE,
+                                              share_access = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
+                                              oplock = SMB2_OPLOCK_LEVEL_NONE,
+                                              impersonation = SEC_IMPERSONATE,
+                                              create_options = 0,
+                                              create_disp = FILE_OPEN))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, createCB, errback, tid = tid)
+            messages_history.append(m)
+
+        def createCB(create_message, **kwargs):
+            messages_history.append(create_message)
+            if create_message.status == 0:
+                if self.smb2_dialect != SMB2_DIALECT_2 and self.cap_multi_credit:
+                    output_buf_len = 64 * 1024 * (self.credits - 1)
+                else:
+                    output_buf_len = self.max_transact_size
+
+                m = SMB2Message(self, SMB2QueryInfoRequest(create_message.payload.fid,
+                                                     flags = 0,
+                                                     additional_info = OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION,
+                                                     info_type = SMB2_INFO_SECURITY,
+                                                     file_info_class = 0, # [MS-SMB2] 2.2.37, 3.2.4.12
+                                                     input_buf = '',
+                                                     output_buf_len = output_buf_len))
+                m.tid = kwargs['tid']
+                self._sendSMBMessage(m)
+                self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, queryCB, errback, tid = kwargs['tid'], fid = create_message.payload.fid)
+                messages_history.append(m)
+            else:
+                errback(OperationFailure('Failed to get the security descriptor of %s on %s: Unable to open file or directory' % ( path, service_name ), messages_history))
+
+        def queryCB(query_message, **kwargs):
+            messages_history.append(query_message)
+            if query_message.status == 0:
+                security = SecurityDescriptor.from_bytes(query_message.payload.data)
+                closeFid(kwargs['tid'], kwargs['fid'], result = security)
+            else:
+                closeFid(kwargs['tid'], kwargs['fid'], error = query_message.status)
+
+        def closeFid(tid, fid, result = None, error = None):
+            m = SMB2Message(self, SMB2CloseRequest(fid))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, closeCB, errback, result = result, error = error)
+            messages_history.append(m)
+
+        def closeCB(close_message, **kwargs):
+            if kwargs['result'] is not None:
+                callback(kwargs['result'])
+            elif kwargs['error'] is not None:
+                errback(OperationFailure('Failed to get the security descriptor of %s on %s: Query failed with errorcode 0x%08x' % ( path, service_name, kwargs['error'] ), messages_history))
+
+        if service_name not in self.connected_trees:
+            def connectCB(connect_message, **kwargs):
+                messages_history.append(connect_message)
+                if connect_message.status == 0:
+                    self.connected_trees[service_name] = connect_message.tid
+                    sendCreate(connect_message.tid)
+                else:
+                    errback(OperationFailure('Failed to get the security descriptor of %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history))
+
+            m = SMB2Message(self, SMB2TreeConnectRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name )))
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectCB, errback, path = service_name)
+            messages_history.append(m)
+        else:
+            sendCreate(self.connected_trees[service_name])
+
+    def _retrieveFile_SMB2(self, service_name, path, file_obj, callback, errback, timeout = 30):
+        return self._retrieveFileFromOffset(service_name, path, file_obj, callback, errback, 0, -1, timeout)
+
+    def _retrieveFileFromOffset_SMB2(self, service_name, path, file_obj, callback, errback, starting_offset, max_length, timeout = 30):
+        if not self.has_authenticated:
+            raise NotReadyError('SMB connection not authenticated')
+
+        expiry_time = time.time() + timeout
+        path = path.replace('/', '\\')
+        if path.startswith('\\'):
+            path = path[1:]
+        if path.endswith('\\'):
+            path = path[:-1]
+        messages_history = [ ]
+        results = [ ]
+
+        def sendCreate(tid):
+            create_context_data = binascii.unhexlify(b"""
+28 00 00 00 10 00 04 00 00 00 18 00 10 00 00 00
+44 48 6e 51 00 00 00 00 00 00 00 00 00 00 00 00
+00 00 00 00 00 00 00 00 18 00 00 00 10 00 04 00
+00 00 18 00 00 00 00 00 4d 78 41 63 00 00 00 00
+00 00 00 00 10 00 04 00 00 00 18 00 00 00 00 00
+51 46 69 64 00 00 00 00
+""".replace(b' ', b'').replace(b'\n', b''))
+            m = SMB2Message(self, SMB2CreateRequest(path,
+                                              file_attributes = 0,
+                                              access_mask = FILE_READ_DATA | FILE_READ_EA | FILE_READ_ATTRIBUTES | READ_CONTROL | SYNCHRONIZE,
+                                              share_access = FILE_SHARE_READ | FILE_SHARE_WRITE,
+                                              oplock = SMB2_OPLOCK_LEVEL_NONE,
+                                              impersonation = SEC_IMPERSONATE,
+                                              create_options = FILE_SEQUENTIAL_ONLY | FILE_NON_DIRECTORY_FILE,
+                                              create_disp = FILE_OPEN,
+                                              create_context_data = create_context_data))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, createCB, errback, tid = tid)
+            messages_history.append(m)
+
+        def createCB(create_message, **kwargs):
+            messages_history.append(create_message)
+            if create_message.status == 0:
+                m = SMB2Message(self, SMB2QueryInfoRequest(create_message.payload.fid,
+                                                     flags = 0,
+                                                     additional_info = 0,
+                                                     info_type = SMB2_INFO_FILE,
+                                                     file_info_class = 0x16,  # FileStreamInformation [MS-FSCC] 2.4
+                                                     input_buf = b'',
+                                                     output_buf_len = 4096))
+                m.tid = kwargs['tid']
+                self._sendSMBMessage(m)
+                self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, infoCB, errback,
+                                                               tid = kwargs['tid'],
+                                                               fid = create_message.payload.fid,
+                                                               file_attributes = create_message.payload.file_attributes)
+                messages_history.append(m)
+            else:
+                errback(OperationFailure('Failed to retrieve %s on %s: Unable to open file' % ( path, service_name ), messages_history))
+
+        def infoCB(info_message, **kwargs):
+            messages_history.append(info_message)
+            if info_message.status == 0:
+                file_len = struct.unpack('<Q', info_message.payload.data[8:16])[0]
+                if max_length == 0 or starting_offset > file_len:
+                    closeFid(info_message.tid, kwargs['fid'])
+                    callback(( file_obj, kwargs['file_attributes'], 0 ))  # Note that this is a tuple of 3-elements
+                else:
+                    remaining_len = max_length
+                    if remaining_len < 0:
+                        remaining_len = file_len
+                    if starting_offset + remaining_len > file_len:
+                        remaining_len = file_len - starting_offset
+                    sendRead(kwargs['tid'], kwargs['fid'], starting_offset, remaining_len, 0, kwargs['file_attributes'])
+            else:
+                errback(OperationFailure('Failed to retrieve %s on %s: Unable to retrieve information on file' % ( path, service_name ), messages_history))
+
+        def sendRead(tid, fid, offset, remaining_len, read_len, file_attributes):
+            read_count = min(self.max_read_size, remaining_len)
+
+            if self.smb2_dialect != SMB2_DIALECT_2 and self.cap_multi_credit:
+                max_read_count = 64 * 1024 * (self.credits -1)
+                read_count = min(read_count, max_read_count)
+
+            m = SMB2Message(self, SMB2ReadRequest(fid, offset, read_count))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, readCB, errback,
+                                                           tid = tid, fid = fid, offset = offset,
+                                                           remaining_len = remaining_len,
+                                                           read_len = read_len,
+                                                           file_attributes = file_attributes)
+
+        def readCB(read_message, **kwargs):
+            # To avoid crazy memory usage when retrieving large files, we do not save every read_message in messages_history.
+            if read_message.status == 0:
+                data_len = read_message.payload.data_length
+                file_obj.write(read_message.payload.data)
+
+                remaining_len = kwargs['remaining_len'] - data_len
+
+                if remaining_len > 0:
+                    sendRead(kwargs['tid'], kwargs['fid'], kwargs['offset'] + data_len, remaining_len, kwargs['read_len'] + data_len, kwargs['file_attributes'])
+                else:
+                    closeFid(kwargs['tid'], kwargs['fid'], ret = ( file_obj, kwargs['file_attributes'], kwargs['read_len'] + data_len ))
+            else:
+                messages_history.append(read_message)
+                closeFid(kwargs['tid'], kwargs['fid'], error = read_message.status)
+
+        def closeFid(tid, fid, ret = None, error = None):
+            m = SMB2Message(self, SMB2CloseRequest(fid))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, closeCB, errback, ret = ret, error = error)
+            messages_history.append(m)
+
+        def closeCB(close_message, **kwargs):
+            if kwargs['ret'] is not None:
+                callback(kwargs['ret'])
+            elif kwargs['error'] is not None:
+                errback(OperationFailure('Failed to retrieve %s on %s: Read failed' % ( path, service_name ), messages_history))
+
+        if service_name not in self.connected_trees:
+            def connectCB(connect_message, **kwargs):
+                messages_history.append(connect_message)
+                if connect_message.status == 0:
+                    self.connected_trees[service_name] = connect_message.tid
+                    sendCreate(connect_message.tid)
+                else:
+                    errback(OperationFailure('Failed to retrieve %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history))
+
+            m = SMB2Message(self, SMB2TreeConnectRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name )))
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectCB, errback, path = service_name)
+            messages_history.append(m)
+        else:
+            sendCreate(self.connected_trees[service_name])
+
+    def _storeFile_SMB2(self, service_name, path, file_obj, callback, errback, timeout = 30):
+        self._storeFileFromOffset_SMB2(service_name, path, file_obj, callback, errback, 0, True, timeout)
+
+    def _storeFileFromOffset_SMB2(self, service_name, path, file_obj, callback, errback, starting_offset, truncate = False, timeout = 30):
+        if not self.has_authenticated:
+            raise NotReadyError('SMB connection not authenticated')
+
+        expiry_time = time.time() + timeout
+        path = path.replace('/', '\\')
+        if path.startswith('\\'):
+            path = path[1:]
+        if path.endswith('\\'):
+            path = path[:-1]
+        messages_history = [ ]
+
+        def sendCreate(tid):
+            create_context_data = binascii.unhexlify(b"""
+28 00 00 00 10 00 04 00 00 00 18 00 10 00 00 00
+44 48 6e 51 00 00 00 00 00 00 00 00 00 00 00 00
+00 00 00 00 00 00 00 00 20 00 00 00 10 00 04 00
+00 00 18 00 08 00 00 00 41 6c 53 69 00 00 00 00
+85 62 00 00 00 00 00 00 18 00 00 00 10 00 04 00
+00 00 18 00 00 00 00 00 4d 78 41 63 00 00 00 00
+00 00 00 00 10 00 04 00 00 00 18 00 00 00 00 00
+51 46 69 64 00 00 00 00
+""".replace(b' ', b'').replace(b'\n', b''))
+            m = SMB2Message(self, SMB2CreateRequest(path,
+                                              file_attributes = ATTR_ARCHIVE,
+                                              access_mask = FILE_READ_DATA | FILE_WRITE_DATA | FILE_APPEND_DATA | FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES | FILE_READ_EA | FILE_WRITE_EA | READ_CONTROL | SYNCHRONIZE,
+                                              share_access = 0,
+                                              oplock = SMB2_OPLOCK_LEVEL_NONE,
+                                              impersonation = SEC_IMPERSONATE,
+                                              create_options = FILE_SEQUENTIAL_ONLY | FILE_NON_DIRECTORY_FILE,
+                                              create_disp = FILE_OVERWRITE_IF if truncate else FILE_OPEN_IF,
+                                              create_context_data = create_context_data))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, createCB, errback, tid = tid)
+            messages_history.append(m)
+
+        def createCB(create_message, **kwargs):
+            create_message.tid = kwargs['tid']
+            messages_history.append(create_message)
+            if create_message.status == 0:
+                sendWrite(create_message.tid, create_message.payload.fid, starting_offset)
+            else:
+                errback(OperationFailure('Failed to store %s on %s: Unable to open file' % ( path, service_name ), messages_history))
+
+        def sendWrite(tid, fid, offset):
+            if self.smb2_dialect != SMB2_DIALECT_2 and self.cap_multi_credit:
+                write_count = 64 * 1024 * (self.credits -1)
+            else:
+                write_count = self.max_write_size
+            data = file_obj.read(write_count)
+            data_len = len(data)
+            if data_len > 0:
+                m = SMB2Message(self, SMB2WriteRequest(fid, data, offset))
+                m.tid = tid
+                self._sendSMBMessage(m)
+                self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, writeCB, errback, tid = tid, fid = fid, offset = offset+data_len)
+            else:
+                closeFid(tid, fid, offset = offset)
+
+        def writeCB(write_message, **kwargs):
+            # To avoid crazy memory usage when saving large files, we do not save every write_message in messages_history.
+            if write_message.status == 0:
+                sendWrite(kwargs['tid'], kwargs['fid'], kwargs['offset'])
+            else:
+                messages_history.append(write_message)
+                closeFid(kwargs['tid'], kwargs['fid'])
+                errback(OperationFailure('Failed to store %s on %s: Write failed' % ( path, service_name ), messages_history))
+
+        def closeFid(tid, fid, error = None, offset = None):
+            m = SMB2Message(self, SMB2CloseRequest(fid))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, closeCB, errback, fid = fid, offset = offset, error = error)
+            messages_history.append(m)
+
+        def closeCB(close_message, **kwargs):
+            if kwargs['offset'] is not None:
+                callback(( file_obj, kwargs['offset'] ))  # Note that this is a tuple of 2-elements
+            elif kwargs['error'] is not None:
+                errback(OperationFailure('Failed to store %s on %s: Write failed' % ( path, service_name ), messages_history))
+
+        if service_name not in self.connected_trees:
+            def connectCB(connect_message, **kwargs):
+                messages_history.append(connect_message)
+                if connect_message.status == 0:
+                    self.connected_trees[service_name] = connect_message.tid
+                    sendCreate(connect_message.tid)
+                else:
+                    errback(OperationFailure('Failed to store %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history))
+
+            m = SMB2Message(self, SMB2TreeConnectRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name )))
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, connectCB, errback, path = service_name)
+            messages_history.append(m)
+        else:
+            sendCreate(self.connected_trees[service_name])
+
+
+    def _deleteFiles_SMB2(self, service_name, path_file_pattern, callback, errback, timeout = 30):
+        if not self.has_authenticated:
+            raise NotReadyError('SMB connection not authenticated')
+
+        expiry_time = time.time() + timeout
+        path = path_file_pattern.replace('/', '\\')
+        if path.startswith('\\'):
+            path = path[1:]
+        if path.endswith('\\'):
+            path = path[:-1]
+        messages_history = [ ]
+
+        def sendCreate(tid):
+            create_context_data = binascii.unhexlify(b"""
+28 00 00 00 10 00 04 00 00 00 18 00 10 00 00 00
+44 48 6e 51 00 00 00 00 00 00 00 00 00 00 00 00
+00 00 00 00 00 00 00 00 18 00 00 00 10 00 04 00
+00 00 18 00 00 00 00 00 4d 78 41 63 00 00 00 00
+00 00 00 00 10 00 04 00 00 00 18 00 00 00 00 00
+51 46 69 64 00 00 00 00
+""".replace(b' ', b'').replace(b'\n', b''))
+            m = SMB2Message(self, SMB2CreateRequest(path,
+                                              file_attributes = 0,
+                                              access_mask = DELETE | FILE_READ_ATTRIBUTES,
+                                              share_access = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
+                                              oplock = SMB2_OPLOCK_LEVEL_NONE,
+                                              impersonation = SEC_IMPERSONATE,
+                                              create_options = FILE_NON_DIRECTORY_FILE,
+                                              create_disp = FILE_OPEN,
+                                              create_context_data = create_context_data))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, createCB, errback, tid = tid)
+            messages_history.append(m)
+
+        def createCB(open_message, **kwargs):
+            open_message.tid = kwargs['tid']
+            messages_history.append(open_message)
+            if open_message.status == 0:
+                sendDelete(open_message.tid, open_message.payload.fid)
+            else:
+                errback(OperationFailure('Failed to delete %s on %s: Unable to open file' % ( path, service_name ), messages_history))
+
+        def sendDelete(tid, fid):
+            m = SMB2Message(self, SMB2SetInfoRequest(fid,
+                                               additional_info = 0,
+                                               info_type = SMB2_INFO_FILE,
+                                               file_info_class = 0x0d,  # SMB2_FILE_DISPOSITION_INFO
+                                               data = b'\x01'))
+            # [MS-SMB2]: 2.2.39, [MS-FSCC]: 2.4.11
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, deleteCB, errback, tid = tid, fid = fid)
+            messages_history.append(m)
+
+        def deleteCB(delete_message, **kwargs):
+            messages_history.append(delete_message)
+            if delete_message.status == 0:
+                closeFid(kwargs['tid'], kwargs['fid'], status = 0)
+            else:
+                closeFid(kwargs['tid'], kwargs['fid'], status = delete_message.status)
+
+        def closeFid(tid, fid, status = None):
+            m = SMB2Message(self, SMB2CloseRequest(fid))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, closeCB, errback, status = status)
+            messages_history.append(m)
+
+        def closeCB(close_message, **kwargs):
+            if kwargs['status'] == 0:
+                callback(path_file_pattern)
+            else:
+                errback(OperationFailure('Failed to delete %s on %s: Delete failed' % ( path, service_name ), messages_history))
+
+        if service_name not in self.connected_trees:
+            def connectCB(connect_message, **kwargs):
+                messages_history.append(connect_message)
+                if connect_message.status == 0:
+                    self.connected_trees[service_name] = connect_message.tid
+                    sendCreate(connect_message.tid)
+                else:
+                    errback(OperationFailure('Failed to delete %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history))
+
+            m = SMB2Message(self, SMB2TreeConnectRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name )))
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectCB, errback, path = service_name)
+            messages_history.append(m)
+        else:
+            sendCreate(self.connected_trees[service_name])
+
+    def _resetFileAttributes_SMB2(self, service_name, path_file_pattern, callback, errback, timeout = 30):
+        if not self.has_authenticated:
+            raise NotReadyError('SMB connection not authenticated')
+
+        expiry_time = time.time() + timeout
+        path = path_file_pattern.replace('/', '\\')
+        if path.startswith('\\'):
+            path = path[1:]
+        if path.endswith('\\'):
+            path = path[:-1]
+        messages_history = [ ]
+
+        def sendCreate(tid):
+            create_context_data = binascii.unhexlify("""
+28 00 00 00 10 00 04 00 00 00 18 00 10 00 00 00
+44 48 6e 51 00 00 00 00 00 00 00 00 00 00 00 00
+00 00 00 00 00 00 00 00 18 00 00 00 10 00 04 00
+00 00 18 00 00 00 00 00 4d 78 41 63 00 00 00 00
+00 00 00 00 10 00 04 00 00 00 18 00 00 00 00 00
+51 46 69 64 00 00 00 00
+""".replace(' ', '').replace('\n', ''))
+
+            m = SMB2Message(self, SMB2CreateRequest(path,
+                                              file_attributes = 0,
+                                              access_mask = FILE_WRITE_ATTRIBUTES,
+                                              share_access = FILE_SHARE_READ | FILE_SHARE_WRITE,
+                                              oplock = SMB2_OPLOCK_LEVEL_NONE,
+                                              impersonation = SEC_IMPERSONATE,
+                                              create_options = 0,
+                                              create_disp = FILE_OPEN,
+                                              create_context_data = create_context_data))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, createCB, errback, tid = tid)
+            messages_history.append(m)
+
+        def createCB(open_message, **kwargs):
+            messages_history.append(open_message)
+            if open_message.status == 0:
+                sendReset(kwargs['tid'], open_message.payload.fid)
+            else:
+                errback(OperationFailure('Failed to reset attributes of %s on %s: Unable to open file' % ( path, service_name ), messages_history))
+
+        def sendReset(tid, fid):
+            m = SMB2Message(self, SMB2SetInfoRequest(fid,
+                                               additional_info = 0,
+                                               info_type = SMB2_INFO_FILE,
+                                               file_info_class = 4,  # FileBasicInformation
+                                               data = struct.pack('qqqqii',0,0,0,0,0x80,0))) # FILE_ATTRIBUTE_NORMAL
+            # [MS-SMB2]: 2.2.39, [MS-FSCC]: 2.4, [MS-FSCC]: 2.4.7, [MS-FSCC]: 2.6
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, resetCB, errback, tid = tid, fid = fid)
+            messages_history.append(m)
+
+        def resetCB(reset_message, **kwargs):
+            messages_history.append(reset_message)
+            if reset_message.status == 0:
+                closeFid(kwargs['tid'], kwargs['fid'], status = 0)
+            else:
+                closeFid(kwargs['tid'], kwargs['fid'], status = reset_message.status)
+
+        def closeFid(tid, fid, status = None):
+            m = SMB2Message(self, SMB2CloseRequest(fid))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, closeCB, errback, status = status)
+            messages_history.append(m)
+
+        def closeCB(close_message, **kwargs):
+            if kwargs['status'] == 0:
+                callback(path_file_pattern)
+            else:
+                errback(OperationFailure('Failed to reset attributes of %s on %s: Reset failed' % ( path, service_name ), messages_history))
+
+        if service_name not in self.connected_trees:
+            def connectCB(connect_message, **kwargs):
+                messages_history.append(connect_message)
+                if connect_message.status == 0:
+                    self.connected_trees[service_name] = connect_message.tid
+                    sendCreate(connect_message.tid)
+                else:
+                    errback(OperationFailure('Failed to reset attributes of %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history))
+
+            m = SMB2Message(self, SMB2TreeConnectRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name )))
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectCB, errback, path = service_name)
+            messages_history.append(m)
+        else:
+            sendCreate(self.connected_trees[service_name])
+
+
+
+    def _createDirectory_SMB2(self, service_name, path, callback, errback, timeout = 30):
+        if not self.has_authenticated:
+            raise NotReadyError('SMB connection not authenticated')
+
+        expiry_time = time.time() + timeout
+        path = path.replace('/', '\\')
+        if path.startswith('\\'):
+            path = path[1:]
+        if path.endswith('\\'):
+            path = path[:-1]
+        messages_history = [ ]
+
+        def sendCreate(tid):
+            create_context_data = binascii.unhexlify(b"""
+28 00 00 00 10 00 04 00 00 00 18 00 10 00 00 00
+44 48 6e 51 00 00 00 00 00 00 00 00 00 00 00 00
+00 00 00 00 00 00 00 00 18 00 00 00 10 00 04 00
+00 00 18 00 00 00 00 00 4d 78 41 63 00 00 00 00
+00 00 00 00 10 00 04 00 00 00 18 00 00 00 00 00
+51 46 69 64 00 00 00 00
+""".replace(b' ', b'').replace(b'\n', b''))
+            m = SMB2Message(self, SMB2CreateRequest(path,
+                                              file_attributes = 0,
+                                              access_mask = FILE_READ_DATA | FILE_WRITE_DATA | FILE_READ_EA | FILE_WRITE_EA | FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES | READ_CONTROL | DELETE | SYNCHRONIZE,
+                                              share_access = 0,
+                                              oplock = SMB2_OPLOCK_LEVEL_NONE,
+                                              impersonation = SEC_IMPERSONATE,
+                                              create_options = FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT,
+                                              create_disp = FILE_CREATE,
+                                              create_context_data = create_context_data))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, createCB, errback, tid = tid)
+            messages_history.append(m)
+
+        def createCB(create_message, **kwargs):
+            messages_history.append(create_message)
+            if create_message.status == 0:
+                closeFid(kwargs['tid'], create_message.payload.fid)
+            else:
+                errback(OperationFailure('Failed to create directory %s on %s: Create failed' % ( path, service_name ), messages_history))
+
+        def closeFid(tid, fid):
+            m = SMB2Message(self, SMB2CloseRequest(fid))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, closeCB, errback)
+            messages_history.append(m)
+
+        def closeCB(close_message, **kwargs):
+            callback(path)
+
+        if service_name not in self.connected_trees:
+            def connectCB(connect_message, **kwargs):
+                messages_history.append(connect_message)
+                if connect_message.status == 0:
+                    self.connected_trees[service_name] = connect_message.tid
+                    sendCreate(connect_message.tid)
+                else:
+                    errback(OperationFailure('Failed to create directory %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history))
+
+            m = SMB2Message(self, SMB2TreeConnectRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name )))
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectCB, errback, path = service_name)
+            messages_history.append(m)
+        else:
+            sendCreate(self.connected_trees[service_name])
+
+    def _deleteDirectory_SMB2(self, service_name, path, callback, errback, timeout = 30):
+        if not self.has_authenticated:
+            raise NotReadyError('SMB connection not authenticated')
+
+        expiry_time = time.time() + timeout
+        path = path.replace('/', '\\')
+        if path.startswith('\\'):
+            path = path[1:]
+        if path.endswith('\\'):
+            path = path[:-1]
+        messages_history = [ ]
+
+        def sendCreate(tid):
+            create_context_data = binascii.unhexlify(b"""
+28 00 00 00 10 00 04 00 00 00 18 00 10 00 00 00
+44 48 6e 51 00 00 00 00 00 00 00 00 00 00 00 00
+00 00 00 00 00 00 00 00 18 00 00 00 10 00 04 00
+00 00 18 00 00 00 00 00 4d 78 41 63 00 00 00 00
+00 00 00 00 10 00 04 00 00 00 18 00 00 00 00 00
+51 46 69 64 00 00 00 00
+""".replace(b' ', b'').replace(b'\n', b''))
+            m = SMB2Message(self, SMB2CreateRequest(path,
+                                              file_attributes = 0,
+                                              access_mask = DELETE | FILE_READ_ATTRIBUTES,
+                                              share_access = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
+                                              oplock = SMB2_OPLOCK_LEVEL_NONE,
+                                              impersonation = SEC_IMPERSONATE,
+                                              create_options = FILE_DIRECTORY_FILE,
+                                              create_disp = FILE_OPEN,
+                                              create_context_data = create_context_data))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, createCB, errback, tid = tid)
+            messages_history.append(m)
+
+        def createCB(open_message, **kwargs):
+            messages_history.append(open_message)
+            if open_message.status == 0:
+                sendDelete(kwargs['tid'], open_message.payload.fid)
+            else:
+                errback(OperationFailure('Failed to delete %s on %s: Unable to open directory' % ( path, service_name ), messages_history))
+
+        def sendDelete(tid, fid):
+            m = SMB2Message(self, SMB2SetInfoRequest(fid,
+                                               additional_info = 0,
+                                               info_type = SMB2_INFO_FILE,
+                                               file_info_class = 0x0d,  # SMB2_FILE_DISPOSITION_INFO
+                                               data = b'\x01'))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, deleteCB, errback, tid = tid, fid = fid)
+            messages_history.append(m)
+
+        def deleteCB(delete_message, **kwargs):
+            messages_history.append(delete_message)
+            if delete_message.status == 0:
+                closeFid(kwargs['tid'], kwargs['fid'], status = 0)
+            else:
+                closeFid(kwargs['tid'], kwargs['fid'], status = delete_message.status)
+
+        def closeFid(tid, fid, status = None):
+            m = SMB2Message(self, SMB2CloseRequest(fid))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, closeCB, errback, status = status)
+            messages_history.append(m)
+
+        def closeCB(close_message, **kwargs):
+            if kwargs['status'] == 0:
+                callback(path)
+            else:
+                errback(OperationFailure('Failed to delete %s on %s: Delete failed' % ( path, service_name ), messages_history))
+
+        if service_name not in self.connected_trees:
+            def connectCB(connect_message, **kwargs):
+                messages_history.append(connect_message)
+                if connect_message.status == 0:
+                    self.connected_trees[service_name] = connect_message.tid
+                    sendCreate(connect_message.tid)
+                else:
+                    errback(OperationFailure('Failed to delete %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history))
+
+            m = SMB2Message(self, SMB2TreeConnectRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name )))
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectCB, errback, path = service_name)
+            messages_history.append(m)
+        else:
+            sendCreate(self.connected_trees[service_name])
+
+    def _rename_SMB2(self, service_name, old_path, new_path, callback, errback, timeout = 30):
+        if not self.has_authenticated:
+            raise NotReadyError('SMB connection not authenticated')
+
+        expiry_time = time.time() + timeout
+        messages_history = [ ]
+
+        new_path = new_path.replace('/', '\\')
+        if new_path.startswith('\\'):
+            new_path = new_path[1:]
+        if new_path.endswith('\\'):
+            new_path = new_path[:-1]
+
+        old_path = old_path.replace('/', '\\')
+        if old_path.startswith('\\'):
+            old_path = old_path[1:]
+        if old_path.endswith('\\'):
+            old_path = old_path[:-1]
+
+        def sendCreate(tid):
+            create_context_data = binascii.unhexlify(b"""
+28 00 00 00 10 00 04 00 00 00 18 00 10 00 00 00
+44 48 6e 51 00 00 00 00 00 00 00 00 00 00 00 00
+00 00 00 00 00 00 00 00 18 00 00 00 10 00 04 00
+00 00 18 00 00 00 00 00 4d 78 41 63 00 00 00 00
+00 00 00 00 10 00 04 00 00 00 18 00 00 00 00 00
+51 46 69 64 00 00 00 00
+""".replace(b' ', b'').replace(b'\n', b''))
+            m = SMB2Message(self, SMB2CreateRequest(old_path,
+                                              file_attributes = 0,
+                                              access_mask = DELETE | FILE_READ_ATTRIBUTES | SYNCHRONIZE,
+                                              share_access = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
+                                              oplock = SMB2_OPLOCK_LEVEL_NONE,
+                                              impersonation = SEC_IMPERSONATE,
+                                              create_options = FILE_SYNCHRONOUS_IO_NONALERT,
+                                              create_disp = FILE_OPEN,
+                                              create_context_data = create_context_data))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, createCB, errback, tid = tid)
+            messages_history.append(m)
+
+        def createCB(create_message, **kwargs):
+            messages_history.append(create_message)
+            if create_message.status == 0:
+                sendRename(kwargs['tid'], create_message.payload.fid)
+            else:
+                errback(OperationFailure('Failed to rename %s on %s: Unable to open file/directory' % ( old_path, service_name ), messages_history))
+
+        def sendRename(tid, fid):
+            data = b'\x00'*16 + struct.pack('<I', len(new_path)*2) + new_path.encode('UTF-16LE')
+            m = SMB2Message(self, SMB2SetInfoRequest(fid,
+                                               additional_info = 0,
+                                               info_type = SMB2_INFO_FILE,
+                                               file_info_class = 0x0a,  # SMB2_FILE_RENAME_INFO
+                                               data = data))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, renameCB, errback, tid = tid, fid = fid)
+            messages_history.append(m)
+
+        def renameCB(rename_message, **kwargs):
+            messages_history.append(rename_message)
+            if rename_message.status == 0:
+                closeFid(kwargs['tid'], kwargs['fid'], status = 0)
+            else:
+                closeFid(kwargs['tid'], kwargs['fid'], status = rename_message.status)
+
+        def closeFid(tid, fid, status = None):
+            m = SMB2Message(self, SMB2CloseRequest(fid))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, closeCB, errback, status = status)
+            messages_history.append(m)
+
+        def closeCB(close_message, **kwargs):
+            if kwargs['status'] == 0:
+                callback(( old_path, new_path ))
+            else:
+                errback(OperationFailure('Failed to rename %s on %s: Rename failed' % ( old_path, service_name ), messages_history))
+
+        if service_name not in self.connected_trees:
+            def connectCB(connect_message, **kwargs):
+                messages_history.append(connect_message)
+                if connect_message.status == 0:
+                    self.connected_trees[service_name] = connect_message.tid
+                    sendCreate(connect_message.tid)
+                else:
+                    errback(OperationFailure('Failed to rename %s on %s: Unable to connect to shared device' % ( old_path, service_name ), messages_history))
+
+            m = SMB2Message(self, SMB2TreeConnectRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name )))
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectCB, errback, path = service_name)
+            messages_history.append(m)
+        else:
+            sendCreate(self.connected_trees[service_name])
+
+    def _listSnapshots_SMB2(self, service_name, path, callback, errback, timeout = 30):
+        if not self.has_authenticated:
+            raise NotReadyError('SMB connection not authenticated')
+
+        expiry_time = time.time() + timeout
+        path = path.replace('/', '\\')
+        if path.startswith('\\'):
+            path = path[1:]
+        if path.endswith('\\'):
+            path = path[:-1]
+        messages_history = [ ]
+
+        def sendCreate(tid):
+            create_context_data = binascii.unhexlify(b"""
+28 00 00 00 10 00 04 00 00 00 18 00 10 00 00 00
+44 48 6e 51 00 00 00 00 00 00 00 00 00 00 00 00
+00 00 00 00 00 00 00 00 00 00 00 00 10 00 04 00
+00 00 18 00 00 00 00 00 4d 78 41 63 00 00 00 00
+""".replace(b' ', b'').replace(b'\n', b''))
+            m = SMB2Message(self, SMB2CreateRequest(path,
+                                              file_attributes = 0,
+                                              access_mask = FILE_READ_DATA | FILE_READ_ATTRIBUTES | SYNCHRONIZE,
+                                              share_access = FILE_SHARE_READ | FILE_SHARE_WRITE,
+                                              oplock = SMB2_OPLOCK_LEVEL_NONE,
+                                              impersonation = SEC_IMPERSONATE,
+                                              create_options = FILE_SYNCHRONOUS_IO_NONALERT,
+                                              create_disp = FILE_OPEN,
+                                              create_context_data = create_context_data))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, createCB, errback, tid = tid)
+            messages_history.append(m)
+
+        def createCB(create_message, **kwargs):
+            messages_history.append(create_message)
+            if create_message.status == 0:
+                sendEnumSnapshots(kwargs['tid'], create_message.payload.fid)
+            else:
+                errback(OperationFailure('Failed to list snapshots %s on %s: Unable to open file/directory' % ( old_path, service_name ), messages_history))
+
+        def sendEnumSnapshots(tid, fid):
+            m = SMB2Message(self, SMB2IoctlRequest(fid,
+                                             ctlcode = 0x00144064,  # FSCTL_SRV_ENUMERATE_SNAPSHOTS
+                                             flags = 0x0001,
+                                             in_data = b''))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, enumSnapshotsCB, errback, tid = tid, fid = fid)
+            messages_history.append(m)
+
+        def enumSnapshotsCB(enum_message, **kwargs):
+            messages_history.append(enum_message)
+            if enum_message.status == 0:
+                results = [ ]
+                snapshots_count = struct.unpack('<I', enum_message.payload.out_data[4:8])[0]
+                for i in range(0, snapshots_count):
+                    s = enum_message.payload.out_data[12+i*50:12+48+i*50].decode('UTF-16LE')
+                    results.append(datetime(*list(map(int, ( s[5:9], s[10:12], s[13:15], s[16:18], s[19:21], s[22:24] )))))
+                closeFid(kwargs['tid'], kwargs['fid'], results = results)
+            else:
+                closeFid(kwargs['tid'], kwargs['fid'], status = enum_message.status)
+
+        def closeFid(tid, fid, status = None, results = None):
+            m = SMB2Message(self, SMB2CloseRequest(fid))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, closeCB, errback, status = status, results = results)
+            messages_history.append(m)
+
+        def closeCB(close_message, **kwargs):
+            if kwargs['results'] is not None:
+                callback(kwargs['results'])
+            else:
+                errback(OperationFailure('Failed to list snapshots %s on %s: List failed' % ( path, service_name ), messages_history))
+
+        if service_name not in self.connected_trees:
+            def connectCB(connect_message, **kwargs):
+                messages_history.append(connect_message)
+                if connect_message.status == 0:
+                    self.connected_trees[service_name] = connect_message.tid
+                    sendCreate(connect_message.tid)
+                else:
+                    errback(OperationFailure('Failed to list snapshots %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history))
+
+            m = SMB2Message(self, SMB2TreeConnectRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name )))
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectCB, errback, path = service_name)
+            messages_history.append(m)
+        else:
+            sendCreate(self.connected_trees[service_name])
+
+    def _echo_SMB2(self, data, callback, errback, timeout = 30):
+        messages_history = [ ]
+
+        def echoCB(echo_message, **kwargs):
+            messages_history.append(echo_message)
+            if echo_message.status == 0:
+                callback(data)
+            else:
+                errback(OperationFailure('Echo failed', messages_history))
+
+        m = SMB2Message(self, SMB2EchoRequest())
+        self._sendSMBMessage(m)
+        self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, echoCB, errback)
+        messages_history.append(m)
+
+
+    #
+    # SMB1 Methods Family
+    #
+
+    def _sendSMBMessage_SMB1(self, smb_message):
+        if smb_message.mid == 0:
+            smb_message.mid = self._getNextMID_SMB1()
+        if not smb_message.uid:
+            smb_message.uid = self.uid
+        if self.is_signing_active:
+            smb_message.flags2 |= SMB_FLAGS2_SMB_SECURITY_SIGNATURE
+
+            # Increment the next_signing_id as described in [MS-CIFS] 3.2.4.1.3
+            smb_message.security = self.next_signing_id
+            self.next_signing_id += 2  # All our defined messages currently have responses, so always increment by 2
+            raw_data = smb_message.encode()
+
+            md = ntlm.MD5(self.signing_session_key)
+            if self.signing_challenge_response:
+                md.update(self.signing_challenge_response)
+            md.update(raw_data)
+            signature = md.digest()[:8]
+
+            self.log.debug('MID is %d. Signing ID is %d. Signature is %s. Total raw message is %d bytes', smb_message.mid, smb_message.security, binascii.hexlify(signature), len(raw_data))
+            smb_message.raw_data = raw_data[:14] + signature + raw_data[22:]
+        else:
+            smb_message.raw_data = smb_message.encode()
+        self.sendNMBMessage(smb_message.raw_data)
+
+    def _getNextMID_SMB1(self):
+        self.mid += 1
+        if self.mid >= 0xFFFF: # MID cannot be 0xFFFF. [MS-CIFS]: 2.2.1.6.2
+            # We don't use MID of 0 as MID can be reused for SMB_COM_TRANSACTION2_SECONDARY messages
+            # where if mid=0, _sendSMBMessage will re-assign new MID values again
+            self.mid = 1
+        return self.mid
+
+    def _updateState_SMB1(self, message):
+        if message.isReply:
+            if message.command == SMB_COM_NEGOTIATE:
+                if not message.status.hasError:
+                    self.has_negotiated = True
+                    self.log.info('SMB dialect negotiation successful (ExtendedSecurity:%s)', message.hasExtendedSecurity)
+                    self._updateServerInfo(message.payload)
+                    self._handleNegotiateResponse(message)
+                else:
+                    raise ProtocolError('Unknown status value (0x%08X) in SMB_COM_NEGOTIATE' % message.status.internal_value,
+                                        message.raw_data, message)
+            elif message.command == SMB_COM_SESSION_SETUP_ANDX:
+                if message.hasExtendedSecurity:
+                    if not message.status.hasError:
+                        try:
+                            result = securityblob.decodeAuthResponseSecurityBlob(message.payload.security_blob)
+                            if result == securityblob.RESULT_ACCEPT_COMPLETED:
+                                self.log.debug('SMB uid is now %d', message.uid)
+                                self.uid = message.uid
+                                self.has_authenticated = True
+                                self.log.info('Authentication (with extended security) successful!')
+                                self.onAuthOK()
+                            else:
+                                raise ProtocolError('SMB_COM_SESSION_SETUP_ANDX status is 0 but security blob negResult value is %d' % result, message.raw_data, message)
+                        except securityblob.BadSecurityBlobError as ex:
+                            raise ProtocolError(str(ex), message.raw_data, message)
+                    elif message.status.internal_value == 0xc0000016:  # STATUS_MORE_PROCESSING_REQUIRED
+                        try:
+                            result, ntlm_token = securityblob.decodeChallengeSecurityBlob(message.payload.security_blob)
+                            if result == securityblob.RESULT_ACCEPT_INCOMPLETE:
+                                self._handleSessionChallenge(message, ntlm_token)
+                        except ( securityblob.BadSecurityBlobError, securityblob.UnsupportedSecurityProvider ) as ex:
+                            raise ProtocolError(str(ex), message.raw_data, message)
+                    elif (message.status.internal_value == 0xc000006d    # STATUS_LOGON_FAILURE
+                        or message.status.internal_value == 0xc0000064   # STATUS_NO_SUCH_USER
+                        or message.status.internal_value == 0xc000006a): # STATUS_WRONG_PASSWORD
+                        self.has_authenticated = False
+                        self.log.info('Authentication (with extended security) failed. Please check username and password.')
+                        self.onAuthFailed()
+                    elif (message.status.internal_value == 0xc0000193    # STATUS_ACCOUNT_EXPIRED
+                        or message.status.internal_value == 0xC0000071): # STATUS_PASSWORD_EXPIRED
+                        self.has_authenticated = False
+                        self.log.info('Authentication (with extended security) failed. Account or password has expired.')
+                        self.onAuthFailed()
+                    elif message.status.internal_value == 0xc0000234: # STATUS_ACCOUNT_LOCKED_OUT
+                        self.has_authenticated = False
+                        self.log.info('Authentication (with extended security) failed. Account has been locked due to too many invalid logon attempts.')
+                        self.onAuthFailed()
+                    elif message.status.internal_value == 0xc0000072: # STATUS_ACCOUNT_DISABLED
+                        self.has_authenticated = False
+                        self.log.info('Authentication (with extended security) failed. Account has been disabled.')
+                        self.onAuthFailed()
+                    elif (message.status.internal_value == 0xc000006f    # STATUS_INVALID_LOGON_HOURS
+                        or message.status.internal_value == 0xc000015b   # STATUS_LOGON_TYPE_NOT_GRANTED
+                        or message.status.internal_value == 0xc0000070): # STATUS_INVALID_WORKSTATION
+                        self.has_authenticated = False
+                        self.log.info('Authentication (with extended security) failed. Not allowed.')
+                        self.onAuthFailed()
+                    elif message.status.internal_value == 0xc000018c:  # STATUS_TRUSTED_DOMAIN_FAILURE
+                        self.has_authenticated = False
+                        self.log.info('Authentication (with extended security) failed. Domain not trusted.')
+                        self.onAuthFailed()
+                    elif message.status.internal_value == 0xc000018d:  # STATUS_TRUSTED_RELATIONSHIP_FAILURE
+                        self.has_authenticated = False
+                        self.log.info('Authentication (with extended security) failed. Workstation not trusted.')
+                        self.onAuthFailed()
+                    else:
+                        raise ProtocolError('Unknown status value (0x%08X) in SMB_COM_SESSION_SETUP_ANDX (with extended security)' % message.status.internal_value,
+                                            message.raw_data, message)
+                else:
+                    if message.status.internal_value == 0:
+                        self.log.debug('SMB uid is now %d', message.uid)
+                        self.uid = message.uid
+                        self.has_authenticated = True
+                        self.log.info('Authentication (without extended security) successful!')
+                        self.onAuthOK()
+                    else:
+                        self.has_authenticated = False
+                        self.log.info('Authentication (without extended security) failed. Please check username and password')
+                        self.onAuthFailed()
+            elif message.command == SMB_COM_TREE_CONNECT_ANDX:
+                try:
+                    req = self.pending_requests[message.mid]
+                except KeyError:
+                    pass
+                else:
+                    if not message.status.hasError:
+                        self.connected_trees[req.kwargs['path']] = message.tid
+
+            req = self.pending_requests.pop(message.mid, None)
+            if req:
+                req.callback(message, **req.kwargs)
+                return True
+
+
+    def _updateServerInfo_SMB1(self, payload):
+        self.capabilities = payload.capabilities
+        self.security_mode = payload.security_mode
+        self.max_raw_size = payload.max_raw_size
+        self.max_buffer_size = payload.max_buffer_size
+        self.max_mpx_count = payload.max_mpx_count
+        self.use_plaintext_authentication = not bool(payload.security_mode & NEGOTIATE_ENCRYPT_PASSWORDS)
+
+        if self.use_plaintext_authentication:
+            self.log.warning('Remote server only supports plaintext authentication. Your password can be stolen easily over the network.')
+
+
+    def _handleSessionChallenge_SMB1(self, message, ntlm_token):
+        assert message.hasExtendedSecurity
+
+        if message.uid and not self.uid:
+            self.uid = message.uid
+
+        server_challenge, server_flags, server_info = ntlm.decodeChallengeMessage(ntlm_token)
+        if self.use_ntlm_v2:
+            self.log.info('Performing NTLMv2 authentication (with extended security) with server challenge "%s"', binascii.hexlify(server_challenge))
+            nt_challenge_response, lm_challenge_response, session_key = ntlm.generateChallengeResponseV2(self.password,
+                                                                                                         self.username,
+                                                                                                         server_challenge,
+                                                                                                         server_info,
+                                                                                                         self.domain)
+
+        else:
+            self.log.info('Performing NTLMv1 authentication (with extended security) with server challenge "%s"', binascii.hexlify(server_challenge))
+            nt_challenge_response, lm_challenge_response, session_key = ntlm.generateChallengeResponseV1(self.password, server_challenge, True)
+
+        ntlm_data = ntlm.generateAuthenticateMessage(server_flags,
+                                                     nt_challenge_response,
+                                                     lm_challenge_response,
+                                                     session_key,
+                                                     self.username,
+                                                     self.domain,
+                                                     self.my_name)
+
+        if self.log.isEnabledFor(logging.DEBUG):
+            self.log.debug('NT challenge response is "%s" (%d bytes)', binascii.hexlify(nt_challenge_response), len(nt_challenge_response))
+            self.log.debug('LM challenge response is "%s" (%d bytes)', binascii.hexlify(lm_challenge_response), len(lm_challenge_response))
+
+        blob = securityblob.generateAuthSecurityBlob(ntlm_data)
+        self._sendSMBMessage(SMBMessage(self, ComSessionSetupAndxRequest__WithSecurityExtension(0, blob)))
+
+        if self.security_mode & NEGOTIATE_SECURITY_SIGNATURES_REQUIRE:
+            self.log.info('Server requires all SMB messages to be signed')
+            self.is_signing_active = (self.sign_options != SMB.SIGN_NEVER)
+        elif self.security_mode & NEGOTIATE_SECURITY_SIGNATURES_ENABLE:
+            self.log.info('Server supports SMB signing')
+            self.is_signing_active = (self.sign_options == SMB.SIGN_WHEN_SUPPORTED)
+        else:
+            self.is_signing_active = False
+
+        if self.is_signing_active:
+            self.log.info("SMB signing activated. All SMB messages will be signed.")
+            self.signing_session_key = session_key
+            if self.capabilities & CAP_EXTENDED_SECURITY:
+                self.signing_challenge_response = None
+            else:
+                self.signing_challenge_response = blob
+        else:
+            self.log.info("SMB signing deactivated. SMB messages will NOT be signed.")
+
+
+    def _handleNegotiateResponse_SMB1(self, message):
+        if message.uid and not self.uid:
+            self.uid = message.uid
+
+        if message.hasExtendedSecurity or message.payload.supportsExtendedSecurity:
+            ntlm_data = ntlm.generateNegotiateMessage()
+            blob = securityblob.generateNegotiateSecurityBlob(ntlm_data)
+            self._sendSMBMessage(SMBMessage(self, ComSessionSetupAndxRequest__WithSecurityExtension(message.payload.session_key, blob)))
+        else:
+            nt_password, _, _ = ntlm.generateChallengeResponseV1(self.password, message.payload.challenge, False)
+            self.log.info('Performing NTLMv1 authentication (without extended security) with challenge "%s" and hashed password of "%s"',
+                          binascii.hexlify(message.payload.challenge),
+                          binascii.hexlify(nt_password))
+            self._sendSMBMessage(SMBMessage(self, ComSessionSetupAndxRequest__NoSecurityExtension(message.payload.session_key,
+                                                                                           self.username,
+                                                                                           nt_password,
+                                                                                           True,
+                                                                                           self.domain)))
+
+    def _listShares_SMB1(self, callback, errback, timeout = 30):
+        if not self.has_authenticated:
+            raise NotReadyError('SMB connection not authenticated')
+
+        expiry_time = time.time() + timeout
+        path = 'IPC$'
+        messages_history = [ ]
+
+        def connectSrvSvc(tid):
+            m = SMBMessage(self, ComNTCreateAndxRequest('\\srvsvc',
+                                                  flags = NT_CREATE_REQUEST_EXTENDED_RESPONSE,
+                                                  access_mask = READ_CONTROL | FILE_WRITE_ATTRIBUTES | FILE_READ_ATTRIBUTES | FILE_WRITE_EA | FILE_READ_EA | FILE_APPEND_DATA | FILE_WRITE_DATA | FILE_READ_DATA,
+                                                  share_access = FILE_SHARE_READ | FILE_SHARE_WRITE,
+                                                  create_disp = FILE_OPEN,
+                                                  create_options = FILE_OPEN_NO_RECALL | FILE_NON_DIRECTORY_FILE,
+                                                  impersonation = SEC_IMPERSONATE,
+                                                  security_flags = 0))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectSrvSvcCB, errback)
+            messages_history.append(m)
+
+        def connectSrvSvcCB(create_message, **kwargs):
+            messages_history.append(create_message)
+            if not create_message.status.hasError:
+                call_id = self._getNextRPCCallID()
+                # See [MS-CIFS]: 2.2.5.6.1 for more information on TRANS_TRANSACT_NMPIPE (0x0026) parameters
+                setup_bytes = struct.pack('<HH', 0x0026, create_message.payload.fid)
+                # The data_bytes are binding call to Server Service RPC using DCE v1.1 RPC over SMB. See [MS-SRVS] and [C706]
+                # If you wish to understand the meanings of the byte stream, I would suggest you use a recent version of WireShark to packet capture the stream
+                data_bytes = \
+                    binascii.unhexlify(b"""05 00 0b 03 10 00 00 00 48 00 00 00""".replace(b' ', b'')) + \
+                    struct.pack('<I', call_id) + \
+                    binascii.unhexlify(b"""
+b8 10 b8 10 00 00 00 00 01 00 00 00 00 00 01 00
+c8 4f 32 4b 70 16 d3 01 12 78 5a 47 bf 6e e1 88
+03 00 00 00 04 5d 88 8a eb 1c c9 11 9f e8 08 00
+2b 10 48 60 02 00 00 00""".replace(b' ', b'').replace(b'\n', b''))
+                m = SMBMessage(self, ComTransactionRequest(max_params_count = 0,
+                                                     max_data_count = 4280,
+                                                     max_setup_count = 0,
+                                                     data_bytes = data_bytes,
+                                                     setup_bytes = setup_bytes))
+                m.tid = create_message.tid
+                self._sendSMBMessage(m)
+                self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, rpcBindCB, errback, fid = create_message.payload.fid)
+                messages_history.append(m)
+            else:
+                errback(OperationFailure('Failed to list shares: Unable to locate Server Service RPC endpoint', messages_history))
+
+        def rpcBindCB(trans_message, **kwargs):
+            messages_history.append(trans_message)
+            if not trans_message.status.hasError:
+                call_id = self._getNextRPCCallID()
+
+                padding = b''
+                server_len = len(self.remote_name) + 1
+                server_bytes_len = server_len * 2
+                if server_len % 2 != 0:
+                    padding = b'\0\0'
+                    server_bytes_len += 2
+
+                # See [MS-CIFS]: 2.2.5.6.1 for more information on TRANS_TRANSACT_NMPIPE (0x0026) parameters
+                setup_bytes = struct.pack('<HH', 0x0026, kwargs['fid'])
+                # The data bytes are the RPC call to NetrShareEnum (Opnum 15) at Server Service RPC.
+                # If you wish to understand the meanings of the byte stream, I would suggest you use a recent version of WireShark to packet capture the stream
+                data_bytes = \
+                    binascii.unhexlify(b"""05 00 00 03 10 00 00 00""".replace(b' ', b'')) + \
+                    struct.pack('<HHI', 72+server_bytes_len, 0, call_id) + \
+                    binascii.unhexlify(b"""4c 00 00 00 00 00 0f 00 00 00 02 00""".replace(b' ', b'')) + \
+                    struct.pack('<III', server_len, 0, server_len) + \
+                    (self.remote_name + '\0').encode('UTF-16LE') + padding + \
+                    binascii.unhexlify(b"""
+01 00 00 00 01 00 00 00 04 00 02 00 00 00 00 00
+00 00 00 00 ff ff ff ff 08 00 02 00 00 00 00 00
+""".replace(b' ', b'').replace(b'\n', b''))
+                m = SMBMessage(self, ComTransactionRequest(max_params_count = 0,
+                                                     max_data_count = 4280,
+                                                     max_setup_count = 0,
+                                                     data_bytes = data_bytes,
+                                                     setup_bytes = setup_bytes))
+                m.tid = trans_message.tid
+                self._sendSMBMessage(m)
+                self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, listShareResultsCB, errback, fid = kwargs['fid'])
+                messages_history.append(m)
+            else:
+                closeFid(trans_message.tid, kwargs['fid'])
+                errback(OperationFailure('Failed to list shares: Unable to bind to Server Service RPC endpoint', messages_history))
+
+        def listShareResultsCB(result_message, **kwargs):
+            messages_history.append(result_message)
+            if not result_message.status.hasError:
+                # The payload.data_bytes will contain the results of the RPC call to NetrShareEnum (Opnum 15) at Server Service RPC.
+                data_bytes = result_message.payload.data_bytes
+
+                if data_bytes[3] & 0x02 == 0:
+                    sendReadRequest(result_message.tid, kwargs['fid'], data_bytes)
+                else:
+                    decodeResults(result_message.tid, kwargs['fid'], data_bytes)
+            else:
+                closeFid(result_message.tid, kwargs['fid'])
+                errback(OperationFailure('Failed to list shares: Unable to retrieve shared device list', messages_history))
+
+        def decodeResults(tid, fid, data_bytes):
+            shares_count = struct.unpack('<I', data_bytes[36:40])[0]
+            results = [ ]     # A list of SharedDevice instances
+            offset = 36 + 12  # You need to study the byte stream to understand the meaning of these constants
+            for i in range(0, shares_count):
+                results.append(SharedDevice(struct.unpack('<I', data_bytes[offset+4:offset+8])[0], None, None))
+                offset += 12
+
+            for i in range(0, shares_count):
+                max_length, _, length = struct.unpack('<III', data_bytes[offset:offset+12])
+                offset += 12
+                results[i].name = data_bytes[offset:offset+length*2-2].decode('UTF-16LE')
+
+                if length % 2 != 0:
+                    offset += (length * 2 + 2)
+                else:
+                    offset += (length * 2)
+
+                max_length, _, length = struct.unpack('<III', data_bytes[offset:offset+12])
+                offset += 12
+                results[i].comments = data_bytes[offset:offset+length*2-2].decode('UTF-16LE')
+
+                if length % 2 != 0:
+                    offset += (length * 2 + 2)
+                else:
+                    offset += (length * 2)
+
+            closeFid(tid, fid)
+            callback(results)
+
+        def sendReadRequest(tid, fid, data_bytes):
+            read_count = min(4280, self.max_raw_size - 2)
+            m = SMBMessage(self, ComReadAndxRequest(fid = fid,
+                                              offset = 0,
+                                              max_return_bytes_count = read_count,
+                                              min_return_bytes_count = read_count))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, readCB, errback, fid = fid, data_bytes = data_bytes)
+
+        def readCB(read_message, **kwargs):
+            messages_history.append(read_message)
+            if not read_message.status.hasError:
+                data_bytes = read_message.payload.data
+
+                if data_bytes[3] & 0x02 == 0:
+                    sendReadRequest(read_message.tid, kwargs['fid'], kwargs['data_bytes'] + data_bytes[24:])
+                else:
+                    decodeResults(read_message.tid, kwargs['fid'], kwargs['data_bytes'] + data_bytes[24:])
+            else:
+                closeFid(read_message.tid, kwargs['fid'])
+                errback(OperationFailure('Failed to list shares: Unable to retrieve shared device list', messages_history))
+
+        def closeFid(tid, fid):
+            m = SMBMessage(self, ComCloseRequest(fid))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            messages_history.append(m)
+
+        def connectCB(connect_message, **kwargs):
+            messages_history.append(connect_message)
+            if not connect_message.status.hasError:
+                self.connected_trees[path] = connect_message.tid
+                connectSrvSvc(connect_message.tid)
+            else:
+                errback(OperationFailure('Failed to list shares: Unable to connect to IPC$', messages_history))
+
+        m = SMBMessage(self, ComTreeConnectAndxRequest(r'\\%s\%s' % ( self.remote_name.upper(), path ), SERVICE_ANY, ''))
+        self._sendSMBMessage(m)
+        self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectCB, errback, path = path)
+        messages_history.append(m)
+
+    def _listPath_SMB1(self, service_name, path, callback, errback, search, pattern, timeout = 30):
+        if not self.has_authenticated:
+            raise NotReadyError('SMB connection not authenticated')
+
+        expiry_time = time.time() + timeout
+        path = path.replace('/', '\\')
+        if not path.endswith('\\'):
+            path += '\\'
+        messages_history = [ ]
+        results = [ ]
+
+        def sendFindFirst(tid, support_dfs=False):
+            setup_bytes = struct.pack('<H', 0x0001)  # TRANS2_FIND_FIRST2 sub-command. See [MS-CIFS]: 2.2.6.2.1
+            params_bytes = \
+                struct.pack('<HHHHI',
+                            search & 0xFFFF, # SearchAttributes (need to restrict the values due to introduction of SMB_FILE_ATTRIBUTE_INCL_NORMAL)
+                            100,    # SearchCount
+                            0x0006, # Flags: SMB_FIND_CLOSE_AT_EOS | SMB_FIND_RETURN_RESUME_KEYS
+                            0x0104, # InfoLevel: SMB_FIND_FILE_BOTH_DIRECTORY_INFO
+                            0x0000) # SearchStorageType (seems to be ignored by Windows)
+            if support_dfs:
+                params_bytes += ("\\" + self.remote_name + "\\" + service_name + path + pattern + '\0').encode('UTF-16LE')
+            else:
+                params_bytes += (path + pattern + '\0').encode('UTF-16LE')
+
+            m = SMBMessage(self, ComTransaction2Request(max_params_count = 10,
+                                                  max_data_count = 16644,
+                                                  max_setup_count = 0,
+                                                  params_bytes = params_bytes,
+                                                  setup_bytes = setup_bytes))
+            m.tid = tid
+            if support_dfs:
+                m.flags2 |= SMB_FLAGS2_DFS
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, findFirstCB, errback)
+            messages_history.append(m)
+
+        def decodeFindStruct(data_bytes):
+            # SMB_FIND_FILE_BOTH_DIRECTORY_INFO structure. See [MS-CIFS]: 2.2.8.1.7 and [MS-SMB]: 2.2.8.1.1
+            info_format = '<IIQQQQQQIIIBB24s'
+            info_size = struct.calcsize(info_format)
+
+            data_length = len(data_bytes)
+            offset = 0
+            while offset < data_length:
+                if offset + info_size > data_length:
+                    return data_bytes[offset:]
+
+                next_offset, _, \
+                create_time, last_access_time, last_write_time, last_attr_change_time, \
+                file_size, alloc_size, file_attributes, filename_length, ea_size, \
+                short_name_length, _, short_name = struct.unpack(info_format, data_bytes[offset:offset+info_size])
+
+                offset2 = offset + info_size
+                if offset2 + filename_length > data_length:
+                    return data_bytes[offset:]
+
+                filename = data_bytes[offset2:offset2+filename_length].decode('UTF-16LE')
+                short_name = short_name.decode('UTF-16LE')
+
+                accept_result = False
+                if (file_attributes & 0xff) in ( 0x00, ATTR_NORMAL ): # Only the first 8-bits are compared. We ignore other bits like temp, compressed, encryption, sparse, indexed, etc
+                    accept_result = (search == SMB_FILE_ATTRIBUTE_NORMAL) or (search & SMB_FILE_ATTRIBUTE_INCL_NORMAL)
+                else:
+                    accept_result = (file_attributes & search) > 0
+                if accept_result:
+                    results.append(SharedFile(convertFILETIMEtoEpoch(create_time), convertFILETIMEtoEpoch(last_access_time),
+                                              convertFILETIMEtoEpoch(last_write_time), convertFILETIMEtoEpoch(last_attr_change_time),
+                                              file_size, alloc_size, file_attributes, short_name, filename))
+
+                if next_offset:
+                    offset += next_offset
+                else:
+                    break
+            return b''
+
+        def findFirstCB(find_message, **kwargs):
+            messages_history.append(find_message)
+            if not find_message.status.hasError:
+                if 'total_count' not in kwargs:
+                    # TRANS2_FIND_FIRST2 response. [MS-CIFS]: 2.2.6.2.2
+                    sid, search_count, end_of_search, _, last_name_offset = struct.unpack('<HHHHH', find_message.payload.params_bytes[:10])
+                    kwargs.update({ 'sid': sid, 'end_of_search': end_of_search, 'last_name_offset': last_name_offset, 'data_buf': b'' })
+                else:
+                    sid, end_of_search, last_name_offset = kwargs['sid'], kwargs['end_of_search'], kwargs['last_name_offset']
+
+                send_next = True
+                if find_message.payload.data_bytes:
+                    d = decodeFindStruct(kwargs['data_buf'] + find_message.payload.data_bytes)
+                    if 'data_count' not in kwargs:
+                        if len(find_message.payload.data_bytes) != find_message.payload.total_data_count:
+                            kwargs.update({ 'data_count': len(find_message.payload.data_bytes),
+                                            'total_count': find_message.payload.total_data_count,
+                                            'data_buf': d,
+                                            })
+                            send_next = False
+                    else:
+                        kwargs['data_count'] += len(find_message.payload.data_bytes)
+                        kwargs['total_count'] = min(find_message.payload.total_data_count, kwargs['total_count'])
+                        kwargs['data_buf'] = d
+                        if kwargs['data_count'] != kwargs['total_count']:
+                            send_next = False
+
+                if not send_next:
+                    self.pending_requests[find_message.mid] = _PendingRequest(find_message.mid, expiry_time, findFirstCB, errback, **kwargs)
+                elif end_of_search:
+                    callback(results)
+                else:
+                    sendFindNext(find_message.tid, sid, 0, results[-1].filename, kwargs.get('support_dfs', False))
+            else:
+                if find_message.status.internal_value == 0xC000000F:  # [MS-ERREF]: STATUS_NO_SUCH_FILE
+                    # Remote server returns STATUS_NO_SUCH_FILE error so we assume that the search returns no matching files
+                    callback([ ])
+                else:
+                    errback(OperationFailure('Failed to list %s on %s: Unable to retrieve file list' % ( path, service_name ), messages_history))
+
+        def sendFindNext(tid, sid, resume_key, resume_file, support_dfs):
+            setup_bytes = struct.pack('<H', 0x0002)  # TRANS2_FIND_NEXT2 sub-command. See [MS-CIFS]: 2.2.6.3.1
+            params_bytes = \
+                struct.pack('<HHHIH',
+                            sid,        # SID
+                            100,        # SearchCount
+                            0x0104,     # InfoLevel: SMB_FIND_FILE_BOTH_DIRECTORY_INFO
+                            resume_key, # ResumeKey
+                            0x0006)     # Flags: SMB_FIND_RETURN_RESUME_KEYS | SMB_FIND_CLOSE_AT_EOS
+            params_bytes += (resume_file+'\0').encode('UTF-16LE')
+
+            m = SMBMessage(self, ComTransaction2Request(max_params_count = 10,
+                                                  max_data_count = 16644,
+                                                  max_setup_count = 0,
+                                                  params_bytes = params_bytes,
+                                                  setup_bytes = setup_bytes))
+            m.tid = tid
+            if support_dfs:
+                m.flags2 |= SMB_FLAGS2_DFS
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, findNextCB, errback, sid = sid, support_dfs = support_dfs)
+            messages_history.append(m)
+
+        def findNextCB(find_message, **kwargs):
+            messages_history.append(find_message)
+            if not find_message.status.hasError:
+                if 'total_count' not in kwargs:
+                    # TRANS2_FIND_NEXT2 response. [MS-CIFS]: 2.2.6.3.2
+                    search_count, end_of_search, _, last_name_offset = struct.unpack('<HHHH', find_message.payload.params_bytes[:8])
+                    kwargs.update({ 'end_of_search': end_of_search, 'last_name_offset': last_name_offset, 'data_buf': b'' })
+                else:
+                    end_of_search, last_name_offset = kwargs['end_of_search'], kwargs['last_name_offset']
+
+                send_next = True
+                if find_message.payload.data_bytes:
+                    d = decodeFindStruct(kwargs['data_buf'] + find_message.payload.data_bytes)
+                    if 'data_count' not in kwargs:
+                        if len(find_message.payload.data_bytes) != find_message.payload.total_data_count:
+                            kwargs.update({ 'data_count': len(find_message.payload.data_bytes),
+                                            'total_count': find_message.payload.total_data_count,
+                                            'data_buf': d,
+                                            })
+                            send_next = False
+                    else:
+                        kwargs['data_count'] += len(find_message.payload.data_bytes)
+                        kwargs['total_count'] = min(find_message.payload.total_data_count, kwargs['total_count'])
+                        kwargs['data_buf'] = d
+                        if kwargs['data_count'] != kwargs['total_count']:
+                            send_next = False
+
+                if not send_next:
+                    self.pending_requests[find_message.mid] = _PendingRequest(find_message.mid, expiry_time, findNextCB, errback, **kwargs)
+                elif end_of_search:
+                    callback(results)
+                else:
+                    sendFindNext(find_message.tid, kwargs['sid'], 0, results[-1].filename, kwargs.get('support_dfs', False))
+            else:
+                errback(OperationFailure('Failed to list %s on %s: Unable to retrieve file list' % ( path, service_name ), messages_history))
+
+        def sendDFSReferral(tid):
+            setup_bytes = struct.pack('<H', 0x0010)  # TRANS2_GET_DFS_REFERRAL sub-command. See [MS-CIFS]: 2.2.6.16.1
+            params_bytes = struct.pack('<H', 3)      # Max referral level 3
+            params_bytes += ("\\" + self.remote_name + "\\" + service_name).encode('UTF-16LE')
+
+            m = SMBMessage(self, ComTransaction2Request(max_params_count = 10,
+                                                  max_data_count = 16644,
+                                                  max_setup_count = 0,
+                                                  params_bytes = params_bytes,
+                                                  setup_bytes = setup_bytes))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, dfsReferralCB, errback)
+            messages_history.append(m)
+
+        def dfsReferralCB(dfs_message, **kwargs):
+            sendFindFirst(dfs_message.tid, True)
+
+        if service_name not in self.connected_trees:
+            def connectCB(connect_message, **kwargs):
+                messages_history.append(connect_message)
+                if not connect_message.status.hasError:
+                    self.connected_trees[service_name] = connect_message.tid
+                    if connect_message.payload.optional_support & SMB_TREE_CONNECTX_SUPPORT_DFS:
+                        sendDFSReferral(connect_message.tid)
+                    else:
+                        sendFindFirst(connect_message.tid, False)
+                else:
+                    errback(OperationFailure('Failed to list %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history))
+
+            m = SMBMessage(self, ComTreeConnectAndxRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name ), SERVICE_ANY, ''))
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectCB, errback, path = service_name)
+            messages_history.append(m)
+        else:
+            sendFindFirst(self.connected_trees[service_name])
+
+    def _getAttributes_SMB1(self, service_name, path, callback, errback, timeout = 30):
+        if not self.has_authenticated:
+            raise NotReadyError('SMB connection not authenticated')
+
+        expiry_time = time.time() + timeout
+        path = path.replace('/', '\\')
+        if path.startswith('\\'):
+            path = path[1:]
+        if path.endswith('\\'):
+            path = path[:-1]
+        messages_history = [ ]
+
+        def sendQuery(tid):
+            setup_bytes = struct.pack('<H', 0x0005)  # TRANS2_QUERY_PATH_INFORMATION sub-command. See [MS-CIFS]: 2.2.6.6.1
+            params_bytes = \
+                struct.pack('<HI',
+                            0x0107, # SMB_QUERY_FILE_ALL_INFO ([MS-CIFS] 2.2.2.3.3)
+                            0x0000) # Reserved
+            params_bytes += (path + '\0').encode('UTF-16LE')
+
+            m = SMBMessage(self, ComTransaction2Request(max_params_count = 2,
+                                                  max_data_count = 65535,
+                                                  max_setup_count = 0,
+                                                  params_bytes = params_bytes,
+                                                  setup_bytes = setup_bytes))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, queryCB, errback)
+            messages_history.append(m)
+
+        def queryCB(query_message, **kwargs):
+            messages_history.append(query_message)
+            if not query_message.status.hasError:
+                info_format = '<QQQQIIQQ'
+                info_size = struct.calcsize(info_format)
+                create_time, last_access_time, last_write_time, last_attr_change_time, \
+                file_attributes, _, alloc_size, file_size = struct.unpack(info_format, query_message.payload.data_bytes[:info_size])
+                filename = self._extractLastPathComponent(path)
+
+                info = SharedFile(convertFILETIMEtoEpoch(create_time), convertFILETIMEtoEpoch(last_access_time), convertFILETIMEtoEpoch(last_write_time), convertFILETIMEtoEpoch(last_attr_change_time),
+                                  file_size, alloc_size, file_attributes, filename, filename)
+                callback(info)
+            else:
+                errback(OperationFailure('Failed to get attributes for %s on %s: Read failed' % ( path, service_name ), messages_history))
+
+        if service_name not in self.connected_trees:
+            def connectCB(connect_message, **kwargs):
+                messages_history.append(connect_message)
+                if not connect_message.status.hasError:
+                    self.connected_trees[service_name] = connect_message.tid
+                    sendQuery(connect_message.tid)
+                else:
+                    errback(OperationFailure('Failed to get attributes for %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history))
+
+            m = SMBMessage(self, ComTreeConnectAndxRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name ), SERVICE_ANY, ''))
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectCB, errback, path = service_name)
+            messages_history.append(m)
+        else:
+            sendQuery(self.connected_trees[service_name])
+
+    def _getSecurity_SMB1(self, service_name, path_file_pattern, callback, errback, timeout = 30):
+        raise NotReadyError('getSecurity is not yet implemented for SMB1')
+
+    def _retrieveFile_SMB1(self, service_name, path, file_obj, callback, errback, timeout = 30):
+        return self._retrieveFileFromOffset(service_name, path, file_obj, callback, errback, 0, -1, timeout)
+
+    def _retrieveFileFromOffset_SMB1(self, service_name, path, file_obj, callback, errback, starting_offset, max_length, timeout = 30):
+        if not self.has_authenticated:
+            raise NotReadyError('SMB connection not authenticated')
+
+        path = path.replace('/', '\\')
+        messages_history = [ ]
+
+        def sendOpen(tid):
+            m = SMBMessage(self, ComOpenAndxRequest(filename = path,
+                                              access_mode = 0x0040,  # Sharing mode: Deny nothing to others
+                                              open_mode = 0x0001,    # Failed if file does not exist
+                                              search_attributes = SMB_FILE_ATTRIBUTE_HIDDEN | SMB_FILE_ATTRIBUTE_SYSTEM,
+                                              timeout = timeout * 1000))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, openCB, errback)
+            messages_history.append(m)
+
+        def openCB(open_message, **kwargs):
+            messages_history.append(open_message)
+            if not open_message.status.hasError:
+                if max_length == 0:
+                    closeFid(open_message.tid, open_message.payload.fid)
+                    callback(( file_obj, open_message.payload.file_attributes, 0 ))
+                else:
+                    sendRead(open_message.tid, open_message.payload.fid, starting_offset, open_message.payload.file_attributes, 0, max_length)
+            else:
+                errback(OperationFailure('Failed to retrieve %s on %s: Unable to open file' % ( path, service_name ), messages_history))
+
+        def sendRead(tid, fid, offset, file_attributes, read_len, remaining_len):
+            read_count = self.max_raw_size - 2
+            m = SMBMessage(self, ComReadAndxRequest(fid = fid,
+                                              offset = offset,
+                                              max_return_bytes_count = read_count,
+                                              min_return_bytes_count = min(0xFFFF, read_count)))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, readCB, errback, fid = fid, offset = offset, file_attributes = file_attributes,
+                                                           read_len = read_len, remaining_len = remaining_len)
+
+        def readCB(read_message, **kwargs):
+            # To avoid crazy memory usage when retrieving large files, we do not save every read_message in messages_history.
+            if not read_message.status.hasError:
+                read_len = kwargs['read_len']
+                remaining_len = kwargs['remaining_len']
+                data_len = read_message.payload.data_length
+                if max_length > 0:
+                    if data_len > remaining_len:
+                        file_obj.write(read_message.payload.data[:remaining_len])
+                        read_len += remaining_len
+                        remaining_len = 0
+                    else:
+                        file_obj.write(read_message.payload.data)
+                        remaining_len -= data_len
+                        read_len += data_len
+                else:
+                    file_obj.write(read_message.payload.data)
+                    read_len += data_len
+
+                if (max_length > 0 and remaining_len <= 0) or data_len < (self.max_raw_size - 2):
+                    closeFid(read_message.tid, kwargs['fid'])
+                    callback(( file_obj, kwargs['file_attributes'], read_len ))  # Note that this is a tuple of 3-elements
+                else:
+                    sendRead(read_message.tid, kwargs['fid'], kwargs['offset']+data_len, kwargs['file_attributes'], read_len, remaining_len)
+            else:
+                messages_history.append(read_message)
+                closeFid(read_message.tid, kwargs['fid'])
+                errback(OperationFailure('Failed to retrieve %s on %s: Read failed' % ( path, service_name ), messages_history))
+
+        def closeFid(tid, fid):
+            m = SMBMessage(self, ComCloseRequest(fid))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            messages_history.append(m)
+
+        if service_name not in self.connected_trees:
+            def connectCB(connect_message, **kwargs):
+                messages_history.append(connect_message)
+                if not connect_message.status.hasError:
+                    self.connected_trees[service_name] = connect_message.tid
+                    sendOpen(connect_message.tid)
+                else:
+                    errback(OperationFailure('Failed to retrieve %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history))
+
+            m = SMBMessage(self, ComTreeConnectAndxRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name ), SERVICE_ANY, ''))
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, connectCB, errback, path = service_name)
+            messages_history.append(m)
+        else:
+            sendOpen(self.connected_trees[service_name])
+
+    def _storeFile_SMB1(self, service_name, path, file_obj, callback, errback, timeout = 30):
+        self._storeFileFromOffset_SMB1(service_name, path, file_obj, callback, errback, 0, True, timeout)
+
+    def _storeFileFromOffset_SMB1(self, service_name, path, file_obj, callback, errback, starting_offset, truncate = False, timeout = 30):
+        if not self.has_authenticated:
+            raise NotReadyError('SMB connection not authenticated')
+
+        path = path.replace('/', '\\')
+        messages_history = [ ]
+
+        def sendOpen(tid):
+            m = SMBMessage(self, ComOpenAndxRequest(filename = path,
+                                              access_mode = 0x0041,  # Sharing mode: Deny nothing to others + Open for writing
+                                              open_mode = 0x0012 if truncate else 0x0011,    # Create file if file does not exist. Overwrite or append depending on truncate parameter.
+                                              search_attributes = SMB_FILE_ATTRIBUTE_HIDDEN | SMB_FILE_ATTRIBUTE_SYSTEM,
+                                              timeout = timeout * 1000))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, openCB, errback)
+            messages_history.append(m)
+
+        def openCB(open_message, **kwargs):
+            messages_history.append(open_message)
+            if not open_message.status.hasError:
+                sendWrite(open_message.tid, open_message.payload.fid, starting_offset)
+            else:
+                errback(OperationFailure('Failed to store %s on %s: Unable to open file' % ( path, service_name ), messages_history))
+
+        def sendWrite(tid, fid, offset):
+            # For message signing, the total SMB message size must be not exceed the max_buffer_size. Non-message signing does not have this limitation
+            write_count = min((self.is_signing_active and (self.max_buffer_size-64)) or self.max_raw_size, 0xFFFF-1)  # Need to minus 1 byte from 0xFFFF because of the first NULL byte in the ComWriteAndxRequest message data
+            data_bytes = file_obj.read(write_count)
+            data_len = len(data_bytes)
+            if data_len > 0:
+                m = SMBMessage(self, ComWriteAndxRequest(fid = fid, offset = offset, data_bytes = data_bytes))
+                m.tid = tid
+                self._sendSMBMessage(m)
+                self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, writeCB, errback, fid = fid, offset = offset+data_len)
+            else:
+                closeFid(tid, fid)
+                callback(( file_obj, offset ))  # Note that this is a tuple of 2-elements
+
+        def writeCB(write_message, **kwargs):
+            # To avoid crazy memory usage when saving large files, we do not save every write_message in messages_history.
+            if not write_message.status.hasError:
+                sendWrite(write_message.tid, kwargs['fid'], kwargs['offset'])
+            else:
+                messages_history.append(write_message)
+                closeFid(write_message.tid, kwargs['fid'])
+                errback(OperationFailure('Failed to store %s on %s: Write failed' % ( path, service_name ), messages_history))
+
+        def closeFid(tid, fid):
+            m = SMBMessage(self, ComCloseRequest(fid))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            messages_history.append(m)
+
+        if service_name not in self.connected_trees:
+            def connectCB(connect_message, **kwargs):
+                messages_history.append(connect_message)
+                if not connect_message.status.hasError:
+                    self.connected_trees[service_name] = connect_message.tid
+                    sendOpen(connect_message.tid)
+                else:
+                    errback(OperationFailure('Failed to store %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history))
+
+            m = SMBMessage(self, ComTreeConnectAndxRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name ), SERVICE_ANY, ''))
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, connectCB, errback, path = service_name)
+            messages_history.append(m)
+        else:
+            sendOpen(self.connected_trees[service_name])
+
+    def _deleteFiles_SMB1(self, service_name, path_file_pattern, callback, errback, timeout = 30):
+        if not self.has_authenticated:
+            raise NotReadyError('SMB connection not authenticated')
+
+        path = path_file_pattern.replace('/', '\\')
+        messages_history = [ ]
+
+        def sendDelete(tid):
+            m = SMBMessage(self, ComDeleteRequest(filename_pattern = path,
+                                            search_attributes = SMB_FILE_ATTRIBUTE_HIDDEN | SMB_FILE_ATTRIBUTE_SYSTEM))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, deleteCB, errback)
+            messages_history.append(m)
+
+        def deleteCB(delete_message, **kwargs):
+            messages_history.append(delete_message)
+            if not delete_message.status.hasError:
+                callback(path_file_pattern)
+            else:
+                errback(OperationFailure('Failed to store %s on %s: Delete failed' % ( path, service_name ), messages_history))
+
+        if service_name not in self.connected_trees:
+            def connectCB(connect_message, **kwargs):
+                messages_history.append(connect_message)
+                if not connect_message.status.hasError:
+                    self.connected_trees[service_name] = connect_message.tid
+                    sendDelete(connect_message.tid)
+                else:
+                    errback(OperationFailure('Failed to delete %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history))
+
+            m = SMBMessage(self, ComTreeConnectAndxRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name ), SERVICE_ANY, ''))
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, connectCB, errback, path = service_name)
+            messages_history.append(m)
+        else:
+            sendDelete(self.connected_trees[service_name])
+
+    def _resetFileAttributes_SMB1(self, service_name, path_file_pattern, callback, errback, timeout = 30):
+        raise NotReadyError('resetFileAttributes is not yet implemented for SMB1')
+
+    def _createDirectory_SMB1(self, service_name, path, callback, errback, timeout = 30):
+        if not self.has_authenticated:
+            raise NotReadyError('SMB connection not authenticated')
+
+        path = path.replace('/', '\\')
+        messages_history = [ ]
+
+        def sendCreate(tid):
+            m = SMBMessage(self, ComCreateDirectoryRequest(path))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, createCB, errback)
+            messages_history.append(m)
+
+        def createCB(create_message, **kwargs):
+            messages_history.append(create_message)
+            if not create_message.status.hasError:
+                callback(path)
+            else:
+                errback(OperationFailure('Failed to create directory %s on %s: Create failed' % ( path, service_name ), messages_history))
+
+        if service_name not in self.connected_trees:
+            def connectCB(connect_message, **kwargs):
+                messages_history.append(connect_message)
+                if not connect_message.status.hasError:
+                    self.connected_trees[service_name] = connect_message.tid
+                    sendCreate(connect_message.tid)
+                else:
+                    errback(OperationFailure('Failed to create directory %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history))
+
+            m = SMBMessage(self, ComTreeConnectAndxRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name ), SERVICE_ANY, ''))
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, connectCB, errback, path = service_name)
+            messages_history.append(m)
+        else:
+            sendCreate(self.connected_trees[service_name])
+
+    def _deleteDirectory_SMB1(self, service_name, path, callback, errback, timeout = 30):
+        if not self.has_authenticated:
+            raise NotReadyError('SMB connection not authenticated')
+
+        path = path.replace('/', '\\')
+        messages_history = [ ]
+
+        def sendDelete(tid):
+            m = SMBMessage(self, ComDeleteDirectoryRequest(path))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, deleteCB, errback)
+            messages_history.append(m)
+
+        def deleteCB(delete_message, **kwargs):
+            messages_history.append(delete_message)
+            if not delete_message.status.hasError:
+                callback(path)
+            else:
+                errback(OperationFailure('Failed to delete directory %s on %s: Delete failed' % ( path, service_name ), messages_history))
+
+        if service_name not in self.connected_trees:
+            def connectCB(connect_message, **kwargs):
+                messages_history.append(connect_message)
+                if not connect_message.status.hasError:
+                    self.connected_trees[service_name] = connect_message.tid
+                    sendDelete(connect_message.tid)
+                else:
+                    errback(OperationFailure('Failed to delete %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history))
+
+            m = SMBMessage(self, ComTreeConnectAndxRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name ), SERVICE_ANY, ''))
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, connectCB, errback, path = service_name)
+            messages_history.append(m)
+        else:
+            sendDelete(self.connected_trees[service_name])
+
+    def _rename_SMB1(self, service_name, old_path, new_path, callback, errback, timeout = 30):
+        if not self.has_authenticated:
+            raise NotReadyError('SMB connection not authenticated')
+
+        new_path = new_path.replace('/', '\\')
+        old_path = old_path.replace('/', '\\')
+        messages_history = [ ]
+
+        def sendRename(tid):
+            m = SMBMessage(self, ComRenameRequest(old_path = old_path,
+                                            new_path = new_path,
+                                            search_attributes = SMB_FILE_ATTRIBUTE_HIDDEN | SMB_FILE_ATTRIBUTE_SYSTEM))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, renameCB, errback)
+            messages_history.append(m)
+
+        def renameCB(rename_message, **kwargs):
+            messages_history.append(rename_message)
+            if not rename_message.status.hasError:
+                callback(( old_path, new_path ))  # Note that this is a tuple of 2-elements
+            else:
+                errback(OperationFailure('Failed to rename %s on %s: Rename failed' % ( old_path, service_name ), messages_history))
+
+        if service_name not in self.connected_trees:
+            def connectCB(connect_message, **kwargs):
+                messages_history.append(connect_message)
+                if not connect_message.status.hasError:
+                    self.connected_trees[service_name] = connect_message.tid
+                    sendRename(connect_message.tid)
+                else:
+                    errback(OperationFailure('Failed to rename %s on %s: Unable to connect to shared device' % ( old_path, service_name ), messages_history))
+
+            m = SMBMessage(self, ComTreeConnectAndxRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name ), SERVICE_ANY, ''))
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, connectCB, errback, path = service_name)
+            messages_history.append(m)
+        else:
+            sendRename(self.connected_trees[service_name])
+
+    def _listSnapshots_SMB1(self, service_name, path, callback, errback, timeout = 30):
+        if not self.has_authenticated:
+            raise NotReadyError('SMB connection not authenticated')
+
+        expiry_time = time.time() + timeout
+        path = path.replace('/', '\\')
+        if not path.endswith('\\'):
+            path += '\\'
+        messages_history = [ ]
+        results = [ ]
+
+        def sendOpen(tid):
+            m = SMBMessage(self, ComOpenAndxRequest(filename = path,
+                                              access_mode = 0x0040,  # Sharing mode: Deny nothing to others
+                                              open_mode = 0x0001,    # Failed if file does not exist
+                                              search_attributes = 0,
+                                              timeout = timeout * 1000))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, openCB, errback)
+            messages_history.append(m)
+
+        def openCB(open_message, **kwargs):
+            messages_history.append(open_message)
+            if not open_message.status.hasError:
+                sendEnumSnapshots(open_message.tid, open_message.payload.fid)
+            else:
+                errback(OperationFailure('Failed to list snapshots %s on %s: Unable to open path' % ( path, service_name ), messages_history))
+
+        def sendEnumSnapshots(tid, fid):
+            # [MS-CIFS]: 2.2.7.2
+            # [MS-SMB]: 2.2.7.2.1
+            setup_bytes = struct.pack('<IHBB',
+                                      0x00144064,  # [MS-SMB]: 2.2.7.2.1
+                                      fid,         # FID
+                                      0x01,        # IsFctl
+                                      0)           # IsFlags
+            m = SMBMessage(self, ComNTTransactRequest(function = 0x0002,  # NT_TRANSACT_IOCTL. [MS-CIFS]: 2.2.7.2.1
+                                                max_params_count = 0,
+                                                max_data_count = 0xFFFF,
+                                                max_setup_count = 0,
+                                                setup_bytes = setup_bytes))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, enumSnapshotsCB, errback, tid = tid, fid = fid)
+            messages_history.append(m)
+
+        def enumSnapshotsCB(enum_message, **kwargs):
+            messages_history.append(enum_message)
+            if not enum_message.status.hasError:
+                results = [ ]
+                snapshots_count = struct.unpack('<I', enum_message.payload.data_bytes[4:8])[0]
+                for i in range(0, snapshots_count):
+                    s = enum_message.payload.data_bytes[12+i*50:12+48+i*50].decode('UTF-16LE')
+                    results.append(datetime(*list(map(int, ( s[5:9], s[10:12], s[13:15], s[16:18], s[19:21], s[22:24] )))))
+                closeFid(kwargs['tid'], kwargs['fid'])
+                callback(results)
+            else:
+                closeFid(kwargs['tid'], kwargs['fid'])
+                errback(OperationFailure('Failed to list snapshots %s on %s: Unable to list snapshots on path' % ( path, service_name ), messages_history))
+
+        def closeFid(tid, fid):
+            m = SMBMessage(self, ComCloseRequest(fid))
+            m.tid = tid
+            self._sendSMBMessage(m)
+            messages_history.append(m)
+
+        if service_name not in self.connected_trees:
+            def connectCB(connect_message, **kwargs):
+                messages_history.append(connect_message)
+                if not connect_message.status.hasError:
+                    self.connected_trees[service_name] = connect_message.tid
+                    sendOpen(connect_message.tid)
+                else:
+                    errback(OperationFailure('Failed to list snapshots %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history))
+
+            m = SMBMessage(self, ComTreeConnectAndxRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name ), SERVICE_ANY, ''))
+            self._sendSMBMessage(m)
+            self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectCB, errback, path = service_name)
+            messages_history.append(m)
+        else:
+            sendOpen(self.connected_trees[service_name])
+
+    def _echo_SMB1(self, data, callback, errback, timeout = 30):
+        messages_history = [ ]
+
+        if not isinstance(data, type(b'')):
+            raise TypeError('Echo data must be %s not %s' % (type(b'').__name__, type(data).__name__))
+
+        def echoCB(echo_message, **kwargs):
+            messages_history.append(echo_message)
+            if not echo_message.status.hasError:
+                callback(echo_message.payload.data)
+            else:
+                errback(OperationFailure('Echo failed', messages_history))
+
+        m = SMBMessage(self, ComEchoRequest(echo_data = data))
+        self._sendSMBMessage(m)
+        self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, echoCB, errback)
+        messages_history.append(m)
+
+    def _extractLastPathComponent(self, path):
+        return path.replace('\\', '/').split('/')[-1]
+
+
+class SharedDevice:
+    """
+    Contains information about a single shared device on the remote server.
+
+    The following attributes are available:
+
+    * name : An unicode string containing the name of the shared device
+    * comments : An unicode string containing the user description of the shared device
+    """
+
+    # The following constants are taken from [MS-SRVS]: 2.2.2.4
+    # They are used to identify the type of shared resource from the results from the NetrShareEnum in Server Service RPC
+    DISK_TREE   = 0x00
+    PRINT_QUEUE = 0x01
+    COMM_DEVICE = 0x02
+    IPC         = 0x03
+
+    def __init__(self, type, name, comments):
+        self._type = type
+        self.name = name         #: An unicode string containing the name of the shared device
+        self.comments = comments #: An unicode string containing the user description of the shared device
+
+    @property
+    def type(self):
+        """
+        Returns one of the following integral constants.
+         - SharedDevice.DISK_TREE
+         - SharedDevice.PRINT_QUEUE
+         - SharedDevice.COMM_DEVICE
+         - SharedDevice.IPC
+        """
+        return self._type & 0xFFFF
+
+    @property
+    def isSpecial(self):
+        """
+        Returns True if this shared device is a special share reserved for interprocess communication (IPC$)
+        or remote administration of the server (ADMIN$). Can also refer to administrative shares such as
+        C$, D$, E$, and so forth
+        """
+        return bool(self._type & 0x80000000)
+
+    @property
+    def isTemporary(self):
+        """
+        Returns True if this is a temporary share that is not persisted for creation each time the file server initializes.
+        """
+        return bool(self._type & 0x40000000)
+
+    def __unicode__(self):
+        return 'Shared device: %s (type:0x%02x comments:%s)' % (self.name, self.type, self.comments )
+
+
+class SharedFile:
+    """
+    Contain information about a file/folder entry that is shared on the shared device.
+
+    As an application developer, you should not need to instantiate a *SharedFile* instance directly in your application.
+    These *SharedFile* instances are usually returned via a call to *listPath* method in :doc:`smb.SMBProtocol.SMBProtocolFactory<smb_SMBProtocolFactory>`.
+
+    If you encounter *SharedFile* instance where its short_name attribute is empty but the filename attribute contains a short name which does not correspond
+    to any files/folders on your remote shared device, it could be that the original filename on the file/folder entry on the shared device contains
+    one of these prohibited characters: "\/[]:+|<>=;?,* (see [MS-CIFS]: 2.2.1.1.1 for more details).
+
+    The following attributes are available:
+
+    * create_time : Float value in number of seconds since 1970-01-01 00:00:00 to the time of creation of this file resource on the remote server
+    * last_access_time : Float value in number of seconds since 1970-01-01 00:00:00 to the time of last access of this file resource on the remote server
+    * last_write_time : Float value in number of seconds since 1970-01-01 00:00:00 to the time of last modification of this file resource on the remote server
+    * last_attr_change_time : Float value in number of seconds since 1970-01-01 00:00:00 to the time of last attribute change of this file resource on the remote server
+    * file_size : File size in number of bytes
+    * alloc_size : Total number of bytes allocated to store this file
+    * file_attributes : A SMB_EXT_FILE_ATTR integer value. See [MS-CIFS]: 2.2.1.2.3. You can perform bit-wise tests to determine the status of the file using the ATTR_xxx constants in smb_constants.py.
+    * short_name : Unicode string containing the short name of this file (usually in 8.3 notation)
+    * filename : Unicode string containing the long filename of this file. Each OS has a limit to the length of this file name. On Windows, it is 256 characters.
+    * file_id : Long value representing the file reference number for the file. If the remote system does not support this field, this field will be None or 0. See [MS-FSCC]: 2.4.17
+    """
+
+    def __init__(self, create_time, last_access_time, last_write_time, last_attr_change_time, file_size, alloc_size, file_attributes, short_name, filename, file_id=None):
+        self.create_time = create_time  #: Float value in number of seconds since 1970-01-01 00:00:00 to the time of creation of this file resource on the remote server
+        self.last_access_time = last_access_time  #: Float value in number of seconds since 1970-01-01 00:00:00 to the time of last access of this file resource on the remote server
+        self.last_write_time = last_write_time    #: Float value in number of seconds since 1970-01-01 00:00:00 to the time of last modification of this file resource on the remote server
+        self.last_attr_change_time = last_attr_change_time  #: Float value in number of seconds since 1970-01-01 00:00:00 to the time of last attribute change of this file resource on the remote server
+        self.file_size = file_size   #: File size in number of bytes
+        self.alloc_size = alloc_size #: Total number of bytes allocated to store this file
+        self.file_attributes = file_attributes #: A SMB_EXT_FILE_ATTR integer value. See [MS-CIFS]: 2.2.1.2.3. You can perform bit-wise tests to determine the status of the file using the ATTR_xxx constants in smb_constants.py.
+        self.short_name = short_name #: Unicode string containing the short name of this file (usually in 8.3 notation)
+        self.filename = filename     #: Unicode string containing the long filename of this file. Each OS has a limit to the length of this file name. On Windows, it is 256 characters.
+        self.file_id = file_id       #: Long value representing the file reference number for the file. If the remote system does not support this field, this field will be None or 0. See [MS-FSCC]: 2.4.17
+
+    @property
+    def isDirectory(self):
+        """A convenience property to return True if this file resource is a directory on the remote server"""
+        return bool(self.file_attributes & ATTR_DIRECTORY)
+
+    @property
+    def isReadOnly(self):
+        """A convenient property to return True if this file resource is read-only on the remote server"""
+        return bool(self.file_attributes & ATTR_READONLY)
+
+    @property
+    def isNormal(self):
+        """
+        A convenient property to return True if this is a normal file.
+
+        Note that pysmb defines a normal file as a file entry that is not read-only, not hidden, not system, not archive and not a directory.
+        It ignores other attributes like compression, indexed, sparse, temporary and encryption.
+        """
+        return (self.file_attributes==ATTR_NORMAL) or ((self.file_attributes & 0xff)==0)
+
+    def __unicode__(self):
+        return 'Shared file: %s (FileSize:%d bytes, isDirectory:%s)' % ( self.filename, self.file_size, self.isDirectory )
+
+
+class _PendingRequest:
+
+    def __init__(self, mid, expiry_time, callback, errback, **kwargs):
+        self.mid = mid
+        self.expiry_time = expiry_time
+        self.callback = callback
+        self.errback = errback
+        self.kwargs = kwargs
diff --git a/python3/smb/ntlm.py b/python3/smb/ntlm.py
new file mode 100644
index 00000000..a2a3bdde
--- /dev/null
+++ b/python3/smb/ntlm.py
@@ -0,0 +1,246 @@
+
+import types, hmac, binascii, struct, random
+from .utils.pyDes import des
+
+try:
+    import hashlib
+    hashlib.new('md4')
+
+    def MD4(): return hashlib.new('md4')
+except ( ImportError, ValueError ):
+    from .utils.md4 import MD4
+
+try:
+    import hashlib
+    def MD5(s): return hashlib.md5(s)
+except ImportError:
+    import md5
+    def MD5(s): return md5.new(s)
+
+################
+# NTLMv2 Methods
+################
+
+# The following constants are defined in accordance to [MS-NLMP]: 2.2.2.5
+
+NTLM_NegotiateUnicode                =  0x00000001
+NTLM_NegotiateOEM                    =  0x00000002
+NTLM_RequestTarget                   =  0x00000004
+NTLM_Unknown9                        =  0x00000008
+NTLM_NegotiateSign                   =  0x00000010
+NTLM_NegotiateSeal                   =  0x00000020
+NTLM_NegotiateDatagram               =  0x00000040
+NTLM_NegotiateLanManagerKey          =  0x00000080
+NTLM_Unknown8                        =  0x00000100
+NTLM_NegotiateNTLM                   =  0x00000200
+NTLM_NegotiateNTOnly                 =  0x00000400
+NTLM_Anonymous                       =  0x00000800
+NTLM_NegotiateOemDomainSupplied      =  0x00001000
+NTLM_NegotiateOemWorkstationSupplied =  0x00002000
+NTLM_Unknown6                        =  0x00004000
+NTLM_NegotiateAlwaysSign             =  0x00008000
+NTLM_TargetTypeDomain                =  0x00010000
+NTLM_TargetTypeServer                =  0x00020000
+NTLM_TargetTypeShare                 =  0x00040000
+NTLM_NegotiateExtendedSecurity       =  0x00080000
+NTLM_NegotiateIdentify               =  0x00100000
+NTLM_Unknown5                        =  0x00200000
+NTLM_RequestNonNTSessionKey          =  0x00400000
+NTLM_NegotiateTargetInfo             =  0x00800000
+NTLM_Unknown4                        =  0x01000000
+NTLM_NegotiateVersion                =  0x02000000
+NTLM_Unknown3                        =  0x04000000
+NTLM_Unknown2                        =  0x08000000
+NTLM_Unknown1                        =  0x10000000
+NTLM_Negotiate128                    =  0x20000000
+NTLM_NegotiateKeyExchange            =  0x40000000
+NTLM_Negotiate56                     =  0x80000000
+
+NTLM_FLAGS = NTLM_NegotiateUnicode | \
+             NTLM_RequestTarget | \
+             NTLM_NegotiateNTLM | \
+             NTLM_NegotiateAlwaysSign | \
+             NTLM_NegotiateExtendedSecurity | \
+             NTLM_NegotiateTargetInfo | \
+             NTLM_NegotiateVersion | \
+             NTLM_Negotiate128 | \
+             NTLM_NegotiateKeyExchange | \
+             NTLM_Negotiate56
+
+def generateNegotiateMessage():
+    """
+    References:
+    ===========
+    - [MS-NLMP]: 2.2.1.1
+    """
+    s = struct.pack('<8sII8s8s8s',
+                    b'NTLMSSP\0', 0x01, NTLM_FLAGS,
+                    b'\0' * 8,  # Domain
+                    b'\0' * 8,  # Workstation
+                    b'\x06\x00\x72\x17\x00\x00\x00\x0F')  # Version [MS-NLMP]: 2.2.2.10
+    return s
+
+
+def generateAuthenticateMessage(challenge_flags, nt_response, lm_response, session_key, user, domain = 'WORKGROUP', workstation = 'LOCALHOST'):
+    """
+    References:
+    ===========
+    - [MS-NLMP]: 2.2.1.3
+    """
+    FORMAT = '<8sIHHIHHIHHIHHIHHIHHII'
+    FORMAT_SIZE = struct.calcsize(FORMAT)
+
+    lm_response_length = len(lm_response)
+    lm_response_offset = FORMAT_SIZE
+    nt_response_length = len(nt_response)
+    nt_response_offset = lm_response_offset + lm_response_length
+    domain_unicode = domain.encode('UTF-16LE')
+    domain_length = len(domain_unicode)
+    domain_offset = nt_response_offset + nt_response_length
+
+    padding = b''
+    if domain_offset % 2 != 0:
+        padding = b'\0'
+        domain_offset += 1
+
+    user_unicode = user.encode('UTF-16LE')
+    user_length = len(user_unicode)
+    user_offset = domain_offset + domain_length
+    workstation_unicode = workstation.encode('UTF-16LE')
+    workstation_length = len(workstation_unicode)
+    workstation_offset = user_offset + user_length
+    session_key_length = len(session_key)
+    session_key_offset = workstation_offset + workstation_length
+
+    auth_flags = challenge_flags
+    auth_flags &= ~NTLM_NegotiateVersion
+
+    s = struct.pack(FORMAT,
+                    b'NTLMSSP\0', 0x03,
+                    lm_response_length, lm_response_length, lm_response_offset,
+                    nt_response_length, nt_response_length, nt_response_offset,
+                    domain_length, domain_length, domain_offset,
+                    user_length, user_length, user_offset,
+                    workstation_length, workstation_length, workstation_offset,
+                    session_key_length, session_key_length, session_key_offset,
+                    auth_flags)
+
+    return s + lm_response + nt_response + padding + domain_unicode + user_unicode + workstation_unicode + session_key
+
+
+def decodeChallengeMessage(ntlm_data):
+    """
+    References:
+    ===========
+    - [MS-NLMP]: 2.2.1.2
+    - [MS-NLMP]: 2.2.2.1 (AV_PAIR)
+    """
+    FORMAT = '<8sIHHII8s8sHHI'
+    FORMAT_SIZE = struct.calcsize(FORMAT)
+
+    signature, message_type, \
+    targetname_len, targetname_maxlen, targetname_offset, \
+    flags, challenge, _, \
+    targetinfo_len, targetinfo_maxlen, targetinfo_offset, \
+        = struct.unpack(FORMAT, bytes(ntlm_data[:FORMAT_SIZE]))
+
+    assert signature == b'NTLMSSP\0'
+    assert message_type == 0x02
+
+    return challenge, flags, bytes(ntlm_data[targetinfo_offset:targetinfo_offset+targetinfo_len])
+
+
+def generateChallengeResponseV2(password, user, server_challenge, server_info, domain = '', client_challenge = None):
+    client_timestamp = b'\0' * 8
+
+    if not client_challenge:
+        client_challenge = bytes([ random.getrandbits(8) for i in range(0, 8) ])
+
+    assert len(client_challenge) == 8
+
+    d = MD4()
+    d.update(password.encode('UTF-16LE'))
+    ntlm_hash = d.digest()   # The NT password hash
+    response_key = hmac.new(ntlm_hash, (user.upper() + domain).encode('UTF-16LE'), 'md5').digest()  # The NTLMv2 password hash. In [MS-NLMP], this is the result of NTOWFv2 and LMOWFv2 functions
+    temp = b'\x01\x01' + b'\0'*6 + client_timestamp + client_challenge + b'\0'*4 + server_info
+    ntproofstr = hmac.new(response_key, server_challenge + temp, 'md5').digest()
+
+    nt_challenge_response = ntproofstr + temp
+    lm_challenge_response = hmac.new(response_key, server_challenge + client_challenge, 'md5').digest() + client_challenge
+    session_key = hmac.new(response_key, ntproofstr, 'md5').digest()
+
+    return nt_challenge_response, lm_challenge_response, session_key
+
+
+################
+# NTLMv1 Methods
+################
+
+def expandDesKey(key):
+    """Expand the key from a 7-byte password key into a 8-byte DES key"""
+    s = [ ((key[0] >> 1) & 0x7f) << 1,
+          ((key[0] & 0x01) << 6 | ((key[1] >> 2) & 0x3f)) << 1,
+          ((key[1] & 0x03) << 5 | ((key[2] >> 3) & 0x1f)) << 1,
+          ((key[2] & 0x07) << 4 | ((key[3] >> 4) & 0x0f)) << 1,
+          ((key[3] & 0x0f) << 3 | ((key[4] >> 5) & 0x07)) << 1,
+          ((key[4] & 0x1f) << 2 | ((key[5] >> 6) & 0x03)) << 1,
+          ((key[5] & 0x3f) << 1 | ((key[6] >> 7) & 0x01)) << 1,
+          (key[6] & 0x7f) << 1
+        ]
+    return bytes(s)
+
+
+def DESL(K, D):
+    """
+    References:
+    ===========
+    - http://ubiqx.org/cifs/SMB.html (2.8.3.4)
+    - [MS-NLMP]: Section 6
+    """
+    d1 = des(expandDesKey(K[0:7]))
+    d2 = des(expandDesKey(K[7:14]))
+    d3 = des(expandDesKey(K[14:16] + b'\0' * 5))
+    return d1.encrypt(D) + d2.encrypt(D) + d3.encrypt(D)
+
+
+def generateChallengeResponseV1(password, server_challenge, has_extended_security = False, client_challenge = None):
+    """
+    Generate a NTLMv1 response
+
+    @param password: User password string
+    @param server_challange: A 8-byte challenge string sent from the server
+    @param has_extended_security: A boolean value indicating whether NTLMSSP_NEGOTIATE_EXTENDED_SESSIONSECURITY flag is enabled in the NTLM negFlag
+    @param client_challenge: A 8-byte string representing client challenge. If None, it will be generated randomly if needed by the response generation
+    @return: a tuple of ( NT challenge response string, LM challenge response string )
+
+    References:
+    ===========
+    - http://ubiqx.org/cifs/SMB.html (2.8.3.3 and 2.8.3.4)
+    - [MS-NLMP]: 3.3.1
+    """
+    _password = bytes((password.upper() + '\0' * 14)[:14], 'ascii')
+    d1 = des(expandDesKey(_password[:7]))
+    d2 = des(expandDesKey(_password[7:]))
+    lm_response_key = d1.encrypt(b"KGS!@#$%") + d2.encrypt(b"KGS!@#$%")  # LM password hash. In [MS-NLMP], this is the result of LMOWFv1 function
+
+    d = MD4()
+    d.update(password.encode('UTF-16LE'))
+    nt_response_key = d.digest()   # In [MS-NLMP], this is the result of NTOWFv1 function
+
+    if has_extended_security:
+        if not client_challenge:
+            client_challenge = bytes([ random.getrandbits(8) for i in range(0, 8) ])
+
+        assert len(client_challenge) == 8
+
+        lm_challenge_response = client_challenge + b'\0'*16
+        nt_challenge_response = DESL(nt_response_key, MD5(server_challenge + client_challenge).digest()[0:8])
+    else:
+        nt_challenge_response = DESL(nt_response_key, server_challenge)   # The result after DESL is the NT response
+        lm_challenge_response = DESL(lm_response_key, server_challenge)   # The result after DESL is the LM response
+
+    d = MD4()
+    d.update(nt_response_key)
+    session_key = d.digest()
+
+    return nt_challenge_response, lm_challenge_response, session_key
diff --git a/python3/smb/security_descriptors.py b/python3/smb/security_descriptors.py
new file mode 100644
index 00000000..44a678f3
--- /dev/null
+++ b/python3/smb/security_descriptors.py
@@ -0,0 +1,367 @@
+"""
+This module implements security descriptors, and the partial structures
+used in them, as specified in [MS-DTYP].
+"""
+
+import struct
+
+
+# Security descriptor control flags
+# [MS-DTYP]: 2.4.6
+SECURITY_DESCRIPTOR_OWNER_DEFAULTED = 0x0001
+SECURITY_DESCRIPTOR_GROUP_DEFAULTED = 0x0002
+SECURITY_DESCRIPTOR_DACL_PRESENT = 0x0004
+SECURITY_DESCRIPTOR_DACL_DEFAULTED = 0x0008
+SECURITY_DESCRIPTOR_SACL_PRESENT = 0x0010
+SECURITY_DESCRIPTOR_SACL_DEFAULTED = 0x0020
+SECURITY_DESCRIPTOR_SERVER_SECURITY = 0x0040
+SECURITY_DESCRIPTOR_DACL_TRUSTED = 0x0080
+SECURITY_DESCRIPTOR_DACL_COMPUTED_INHERITANCE_REQUIRED = 0x0100
+SECURITY_DESCRIPTOR_SACL_COMPUTED_INHERITANCE_REQUIRED = 0x0200
+SECURITY_DESCRIPTOR_DACL_AUTO_INHERITED = 0x0400
+SECURITY_DESCRIPTOR_SACL_AUTO_INHERITED = 0x0800
+SECURITY_DESCRIPTOR_DACL_PROTECTED = 0x1000
+SECURITY_DESCRIPTOR_SACL_PROTECTED = 0x2000
+SECURITY_DESCRIPTOR_RM_CONTROL_VALID = 0x4000
+SECURITY_DESCRIPTOR_SELF_RELATIVE = 0x8000
+
+# ACE types
+# [MS-DTYP]: 2.4.4.1
+ACE_TYPE_ACCESS_ALLOWED = 0x00
+ACE_TYPE_ACCESS_DENIED = 0x01
+ACE_TYPE_SYSTEM_AUDIT = 0x02
+ACE_TYPE_SYSTEM_ALARM = 0x03
+ACE_TYPE_ACCESS_ALLOWED_COMPOUND = 0x04
+ACE_TYPE_ACCESS_ALLOWED_OBJECT = 0x05
+ACE_TYPE_ACCESS_DENIED_OBJECT = 0x06
+ACE_TYPE_SYSTEM_AUDIT_OBJECT = 0x07
+ACE_TYPE_SYSTEM_ALARM_OBJECT = 0x08
+ACE_TYPE_ACCESS_ALLOWED_CALLBACK = 0x09
+ACE_TYPE_ACCESS_DENIED_CALLBACK = 0x0A
+ACE_TYPE_ACCESS_ALLOWED_CALLBACK_OBJECT = 0x0B
+ACE_TYPE_ACCESS_DENIED_CALLBACK_OBJECT = 0x0C
+ACE_TYPE_SYSTEM_AUDIT_CALLBACK = 0x0D
+ACE_TYPE_SYSTEM_ALARM_CALLBACK = 0x0E
+ACE_TYPE_SYSTEM_AUDIT_CALLBACK_OBJECT = 0x0F
+ACE_TYPE_SYSTEM_ALARM_CALLBACK_OBJECT = 0x10
+ACE_TYPE_SYSTEM_MANDATORY_LABEL = 0x11
+ACE_TYPE_SYSTEM_RESOURCE_ATTRIBUTE = 0x12
+ACE_TYPE_SYSTEM_SCOPED_POLICY_ID = 0x13
+
+# ACE flags
+# [MS-DTYP]: 2.4.4.1
+ACE_FLAG_OBJECT_INHERIT = 0x01
+ACE_FLAG_CONTAINER_INHERIT = 0x02
+ACE_FLAG_NO_PROPAGATE_INHERIT = 0x04
+ACE_FLAG_INHERIT_ONLY = 0x08
+ACE_FLAG_INHERITED = 0x10
+ACE_FLAG_SUCCESSFUL_ACCESS = 0x40
+ACE_FLAG_FAILED_ACCESS = 0x80
+
+# Pre-defined well-known SIDs
+# [MS-DTYP]: 2.4.2.4
+SID_NULL = "S-1-0-0"
+SID_EVERYONE = "S-1-1-0"
+SID_LOCAL = "S-1-2-0"
+SID_CONSOLE_LOGON = "S-1-2-1"
+SID_CREATOR_OWNER = "S-1-3-0"
+SID_CREATOR_GROUP = "S-1-3-1"
+SID_OWNER_SERVER = "S-1-3-2"
+SID_GROUP_SERVER = "S-1-3-3"
+SID_OWNER_RIGHTS = "S-1-3-4"
+SID_NT_AUTHORITY = "S-1-5"
+SID_DIALUP = "S-1-5-1"
+SID_NETWORK = "S-1-5-2"
+SID_BATCH = "S-1-5-3"
+SID_INTERACTIVE = "S-1-5-4"
+SID_SERVICE = "S-1-5-6"
+SID_ANONYMOUS = "S-1-5-7"
+SID_PROXY = "S-1-5-8"
+SID_ENTERPRISE_DOMAIN_CONTROLLERS = "S-1-5-9"
+SID_PRINCIPAL_SELF = "S-1-5-10"
+SID_AUTHENTICATED_USERS = "S-1-5-11"
+SID_RESTRICTED_CODE = "S-1-5-12"
+SID_TERMINAL_SERVER_USER = "S-1-5-13"
+SID_REMOTE_INTERACTIVE_LOGON = "S-1-5-14"
+SID_THIS_ORGANIZATION = "S-1-5-15"
+SID_IUSR = "S-1-5-17"
+SID_LOCAL_SYSTEM = "S-1-5-18"
+SID_LOCAL_SERVICE = "S-1-5-19"
+SID_NETWORK_SERVICE = "S-1-5-20"
+SID_COMPOUNDED_AUTHENTICATION = "S-1-5-21-0-0-0-496"
+SID_CLAIMS_VALID = "S-1-5-21-0-0-0-497"
+SID_BUILTIN_ADMINISTRATORS = "S-1-5-32-544"
+SID_BUILTIN_USERS = "S-1-5-32-545"
+SID_BUILTIN_GUESTS = "S-1-5-32-546"
+SID_POWER_USERS = "S-1-5-32-547"
+SID_ACCOUNT_OPERATORS = "S-1-5-32-548"
+SID_SERVER_OPERATORS = "S-1-5-32-549"
+SID_PRINTER_OPERATORS = "S-1-5-32-550"
+SID_BACKUP_OPERATORS = "S-1-5-32-551"
+SID_REPLICATOR = "S-1-5-32-552"
+SID_ALIAS_PREW2KCOMPACC = "S-1-5-32-554"
+SID_REMOTE_DESKTOP = "S-1-5-32-555"
+SID_NETWORK_CONFIGURATION_OPS = "S-1-5-32-556"
+SID_INCOMING_FOREST_TRUST_BUILDERS = "S-1-5-32-557"
+SID_PERFMON_USERS = "S-1-5-32-558"
+SID_PERFLOG_USERS = "S-1-5-32-559"
+SID_WINDOWS_AUTHORIZATION_ACCESS_GROUP = "S-1-5-32-560"
+SID_TERMINAL_SERVER_LICENSE_SERVERS = "S-1-5-32-561"
+SID_DISTRIBUTED_COM_USERS = "S-1-5-32-562"
+SID_IIS_IUSRS = "S-1-5-32-568"
+SID_CRYPTOGRAPHIC_OPERATORS = "S-1-5-32-569"
+SID_EVENT_LOG_READERS = "S-1-5-32-573"
+SID_CERTIFICATE_SERVICE_DCOM_ACCESS = "S-1-5-32-574"
+SID_RDS_REMOTE_ACCESS_SERVERS = "S-1-5-32-575"
+SID_RDS_ENDPOINT_SERVERS = "S-1-5-32-576"
+SID_RDS_MANAGEMENT_SERVERS = "S-1-5-32-577"
+SID_HYPER_V_ADMINS = "S-1-5-32-578"
+SID_ACCESS_CONTROL_ASSISTANCE_OPS = "S-1-5-32-579"
+SID_REMOTE_MANAGEMENT_USERS = "S-1-5-32-580"
+SID_WRITE_RESTRICTED_CODE = "S-1-5-33"
+SID_NTLM_AUTHENTICATION = "S-1-5-64-10"
+SID_SCHANNEL_AUTHENTICATION = "S-1-5-64-14"
+SID_DIGEST_AUTHENTICATION = "S-1-5-64-21"
+SID_THIS_ORGANIZATION_CERTIFICATE = "S-1-5-65-1"
+SID_NT_SERVICE = "S-1-5-80"
+SID_USER_MODE_DRIVERS = "S-1-5-84-0-0-0-0-0"
+SID_LOCAL_ACCOUNT = "S-1-5-113"
+SID_LOCAL_ACCOUNT_AND_MEMBER_OF_ADMINISTRATORS_GROUP = "S-1-5-114"
+SID_OTHER_ORGANIZATION = "S-1-5-1000"
+SID_ALL_APP_PACKAGES = "S-1-15-2-1"
+SID_ML_UNTRUSTED = "S-1-16-0"
+SID_ML_LOW = "S-1-16-4096"
+SID_ML_MEDIUM = "S-1-16-8192"
+SID_ML_MEDIUM_PLUS = "S-1-16-8448"
+SID_ML_HIGH = "S-1-16-12288"
+SID_ML_SYSTEM = "S-1-16-16384"
+SID_ML_PROTECTED_PROCESS = "S-1-16-20480"
+SID_AUTHENTICATION_AUTHORITY_ASSERTED_IDENTITY = "S-1-18-1"
+SID_SERVICE_ASSERTED_IDENTITY = "S-1-18-2"
+SID_FRESH_PUBLIC_KEY_IDENTITY = "S-1-18-3"
+SID_KEY_TRUST_IDENTITY = "S-1-18-4"
+SID_KEY_PROPERTY_MFA = "S-1-18-5"
+SID_KEY_PROPERTY_ATTESTATION = "S-1-18-6"
+
+
+class SID(object):
+    """
+    A Windows security identifier. Represents a single principal, such a
+    user or a group, as a sequence of numbers consisting of the revision,
+    identifier authority, and a variable-length list of subauthorities.
+
+    See [MS-DTYP]: 2.4.2
+    """
+    def __init__(self, revision, identifier_authority, subauthorities):
+        #: Revision, should always be 1.
+        self.revision = revision
+        #: An integer representing the identifier authority.
+        self.identifier_authority = identifier_authority
+        #: A list of integers representing all subauthorities.
+        self.subauthorities = subauthorities
+
+    def __str__(self):
+        """
+        String representation, as specified in [MS-DTYP]: 2.4.2.1
+        """
+        if self.identifier_authority >= 2**32:
+            id_auth = '%#x' % (self.identifier_authority,)
+        else:
+            id_auth = self.identifier_authority
+        auths = [self.revision, id_auth] + self.subauthorities
+        return 'S-' + '-'.join(str(subauth) for subauth in auths)
+
+    def __repr__(self):
+        return 'SID(%r)' % (str(self),)
+
+    @classmethod
+    def from_bytes(cls, data, return_tail=False):
+        revision, subauth_count = struct.unpack('<BB', data[:2])
+        identifier_authority = struct.unpack('>Q', b'\x00\x00' + data[2:8])[0]
+        subauth_data = data[8:]
+        subauthorities = [struct.unpack('<L', subauth_data[4 * i : 4 * (i+1)])[0]
+                          for i in range(subauth_count)]
+        sid = cls(revision, identifier_authority, subauthorities)
+        if return_tail:
+            return sid, subauth_data[4 * subauth_count :]
+        return sid
+
+
+class ACE(object):
+    """
+    Represents a single access control entry.
+
+    See [MS-DTYP]: 2.4.4
+    """
+    HEADER_FORMAT = '<BBH'
+
+    def __init__(self, type_, flags, mask, sid, additional_data):
+        #: An integer representing the type of the ACE. One of the
+        #: ``ACE_TYPE_*`` constants. Corresponds to the ``AceType`` field
+        #: from [MS-DTYP] 2.4.4.1.
+        self.type = type_
+        #: An integer bitmask with ACE flags, corresponds to the
+        #: ``AceFlags`` field.
+        self.flags = flags
+        #: An integer representing the ``ACCESS_MASK`` as specified in
+        #: [MS-DTYP] 2.4.3.
+        self.mask = mask
+        #: The :class:`SID` of a trustee.
+        self.sid = sid
+        #: A dictionary of additional fields present in the ACE, depending
+        #: on the type. The following fields can be present:
+        #:
+        #: * ``flags``
+        #: * ``object_type``
+        #: * ``inherited_object_type``
+        #: * ``application_data``
+        #: * ``attribute_data``
+        self.additional_data = additional_data
+
+    def __repr__(self):
+        return "ACE(type=%#04x, flags=%#04x, mask=%#010x, sid=%s)" % (
+            self.type, self.flags, self.mask, self.sid,
+        )
+
+    @property
+    def isInheritOnly(self):
+        """Convenience property which indicates if this ACE is inherit
+        only, meaning that it doesn't apply to the object itself."""
+        return bool(self.flags & ACE_FLAG_INHERIT_ONLY)
+
+    @classmethod
+    def from_bytes(cls, data):
+        header_size = struct.calcsize(cls.HEADER_FORMAT)
+        header = data[:header_size]
+        type_, flags, size = struct.unpack(cls.HEADER_FORMAT, header)
+
+        assert len(data) >= size
+
+        body = data[header_size:size]
+        additional_data = {}
+
+        # In all ACE types, the mask immediately follows the header.
+        mask = struct.unpack('<I', body[:4])[0]
+        body = body[4:]
+
+        # All OBJECT-type ACEs contain additional flags, and two GUIDs as
+        # the following fields.
+        if type_ in (ACE_TYPE_ACCESS_ALLOWED_OBJECT,
+                     ACE_TYPE_ACCESS_DENIED_OBJECT,
+                     ACE_TYPE_ACCESS_ALLOWED_CALLBACK_OBJECT,
+                     ACE_TYPE_ACCESS_DENIED_CALLBACK_OBJECT,
+                     ACE_TYPE_SYSTEM_AUDIT_OBJECT,
+                     ACE_TYPE_SYSTEM_AUDIT_CALLBACK_OBJECT):
+            additional_data['flags'] = struct.unpack('<I', body[:4])[0]
+            additional_data['object_type'] = body[4:20]
+            additional_data['inherited_object_type'] = body[20:36]
+            body = body[36:]
+
+        # Then the SID in all types.
+        sid, body = SID.from_bytes(body, return_tail=True)
+
+        # CALLBACK-type ACEs (and for some obscure reason,
+        # SYSTEM_AUDIT_OBJECT) have a final tail of application data.
+        if type_ in (ACE_TYPE_ACCESS_ALLOWED_CALLBACK,
+                     ACE_TYPE_ACCESS_DENIED_CALLBACK,
+                     ACE_TYPE_ACCESS_ALLOWED_CALLBACK_OBJECT,
+                     ACE_TYPE_ACCESS_DENIED_CALLBACK_OBJECT,
+                     ACE_TYPE_SYSTEM_AUDIT_OBJECT,
+                     ACE_TYPE_SYSTEM_AUDIT_CALLBACK,
+                     ACE_TYPE_SYSTEM_AUDIT_CALLBACK_OBJECT):
+            additional_data['application_data'] = body
+
+        # SYSTEM_RESOURCE_ATTRIBUTE ACEs have a tail of attribute data.
+        if type_ == ACE_TYPE_SYSTEM_RESOURCE_ATTRIBUTE:
+            additional_data['attribute_data'] = body
+
+        return cls(type_, flags, mask, sid, additional_data)
+
+
+class ACL(object):
+    """
+    Access control list, encapsulating a sequence of access control
+    entries.
+
+    See [MS-DTYP]: 2.4.5
+    """
+    HEADER_FORMAT = '<BBHHH'
+
+    def __init__(self, revision, aces):
+        #: Integer value of the revision.
+        self.revision = revision
+        #: List of :class:`ACE` instances.
+        self.aces = aces
+
+    def __repr__(self):
+        return "ACL(%r)" % (self.aces,)
+
+    @classmethod
+    def from_bytes(cls, data):
+        revision = None
+        aces = []
+
+        header_size = struct.calcsize(cls.HEADER_FORMAT)
+        header, remaining = data[:header_size], data[header_size:]
+        revision, sbz1, size, count, sbz2 = struct.unpack(cls.HEADER_FORMAT, header)
+
+        assert len(data) >= size
+
+        for i in range(count):
+            ace_size = struct.unpack('<H', remaining[2:4])[0]
+            ace_data, remaining = remaining[:ace_size], remaining[ace_size:]
+            aces.append(ACE.from_bytes(ace_data))
+
+        return cls(revision, aces)
+
+
+class SecurityDescriptor(object):
+    """
+    Represents a security descriptor.
+
+    See [MS-DTYP]: 2.4.6
+    """
+
+    HEADER_FORMAT = '<BBHIIII'
+
+    def __init__(self, flags, owner, group, dacl, sacl):
+        #: Integer bitmask of control flags. Corresponds to the
+        #: ``Control`` field in [MS-DTYP] 2.4.6.
+        self.flags = flags
+        #: Instance of :class:`SID` representing the owner user.
+        self.owner = owner
+        #: Instance of :class:`SID` representing the owner group.
+        self.group = group
+        #: Instance of :class:`ACL` representing the discretionary access
+        #: control list, which specifies access restrictions of an object.
+        self.dacl = dacl
+        #: Instance of :class:`ACL` representing the system access control
+        #: list, which specifies audit logging of an object.
+        self.sacl = sacl
+
+    @classmethod
+    def from_bytes(cls, data):
+        owner = None
+        group = None
+        dacl = None
+        sacl = None
+
+        header = data[:struct.calcsize(cls.HEADER_FORMAT)]
+        (revision, sbz1, flags, owner_offset, group_offset, sacl_offset,
+         dacl_offset) = struct.unpack(cls.HEADER_FORMAT, header)
+
+        assert revision == 1
+        assert flags & SECURITY_DESCRIPTOR_SELF_RELATIVE
+        for offset in (owner_offset, group_offset, sacl_offset, dacl_offset):
+            assert 0 <= offset < len(data)
+
+        if owner_offset:
+            owner = SID.from_bytes(data[owner_offset:])
+        if group_offset:
+            group = SID.from_bytes(data[group_offset:])
+        if dacl_offset:
+            dacl = ACL.from_bytes(data[dacl_offset:])
+        if sacl_offset:
+            sacl = ACL.from_bytes(data[sacl_offset:])
+
+        return cls(flags, owner, group, dacl, sacl)
diff --git a/python3/smb/securityblob.py b/python3/smb/securityblob.py
new file mode 100644
index 00000000..84050955
--- /dev/null
+++ b/python3/smb/securityblob.py
@@ -0,0 +1,136 @@
+
+from pyasn1.type import tag, univ, namedtype, namedval, constraint
+from pyasn1.codec.der import encoder, decoder
+
+__all__ = [ 'generateNegotiateSecurityBlob', 'generateAuthSecurityBlob', 'decodeChallengeSecurityBlob', 'decodeAuthResponseSecurityBlob' ]
+
+
+class UnsupportedSecurityProvider(Exception): pass
+class BadSecurityBlobError(Exception): pass
+
+
+def generateNegotiateSecurityBlob(ntlm_data):
+    mech_token = univ.OctetString(ntlm_data).subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2))
+    mech_types = MechTypeList().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0))
+    mech_types.setComponentByPosition(0, univ.ObjectIdentifier('1.3.6.1.4.1.311.2.2.10'))
+
+    n = NegTokenInit().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0))
+    n.setComponentByName('mechTypes', mech_types)
+    n.setComponentByName('mechToken', mech_token)
+
+    nt = NegotiationToken()
+    nt.setComponentByName('negTokenInit', n)
+
+    ct = ContextToken()
+    ct.setComponentByName('thisMech', univ.ObjectIdentifier('1.3.6.1.5.5.2'))
+    ct.setComponentByName('innerContextToken', nt)
+
+    return encoder.encode(ct)
+
+
+def generateAuthSecurityBlob(ntlm_data):
+    response_token = univ.OctetString(ntlm_data).subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2))
+
+    n = NegTokenTarg().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1))
+    n.setComponentByName('responseToken', response_token)
+
+    nt = NegotiationToken()
+    nt.setComponentByName('negTokenTarg', n)
+
+    return encoder.encode(nt)
+
+
+def decodeChallengeSecurityBlob(data):
+    try:
+        d, _ = decoder.decode(data, asn1Spec = NegotiationToken())
+        nt = d.getComponentByName('negTokenTarg')
+
+        token = nt.getComponentByName('responseToken')
+        if not token:
+            raise BadSecurityBlobError('NTLMSSP_CHALLENGE security blob does not contain responseToken field')
+
+        provider_oid = nt.getComponentByName('supportedMech')
+        if provider_oid and str(provider_oid) != '1.3.6.1.4.1.311.2.2.10':  # This OID is defined in [MS-NLMP]: 1.9
+            raise UnsupportedSecurityProvider('Security provider "%s" is not supported by pysmb' % str(provider_oid))
+
+        result = nt.getComponentByName('negResult')
+        return int(result), token
+    except Exception as ex:
+        raise BadSecurityBlobError(str(ex))
+
+
+def decodeAuthResponseSecurityBlob(data):
+    try:
+        d, _ = decoder.decode(data, asn1Spec = NegotiationToken())
+        nt = d.getComponentByName('negTokenTarg')
+
+        result = nt.getComponentByName('negResult')
+        return int(result)
+    except Exception as ex:
+        raise BadSecurityBlobError(str(ex))
+
+
+#
+# GSS-API ASN.1 (RFC2478 section 3.2.1)
+#
+
+RESULT_ACCEPT_COMPLETED = 0
+RESULT_ACCEPT_INCOMPLETE = 1
+RESULT_REJECT = 2
+
+class NegResultEnumerated(univ.Enumerated):
+    namedValues = namedval.NamedValues(
+        ( 'accept_completed', 0 ),
+        ( 'accept_incomplete', 1 ),
+        ( 'reject', 2 )
+    )
+    subtypeSpec = univ.Enumerated.subtypeSpec + constraint.SingleValueConstraint(0, 1, 2)
+
+
+class MechTypeList(univ.SequenceOf):
+    componentType = univ.ObjectIdentifier()
+
+
+class ContextFlags(univ.BitString):
+    namedValues = namedval.NamedValues(
+        ( 'delegFlag', 0 ),
+        ( 'mutualFlag', 1 ),
+        ( 'replayFlag', 2 ),
+        ( 'sequenceFlag', 3 ),
+        ( 'anonFlag', 4 ),
+        ( 'confFlag', 5 ),
+        ( 'integFlag', 6 )
+    )
+
+
+class NegTokenInit(univ.Sequence):
+    componentType = namedtype.NamedTypes(
+        namedtype.OptionalNamedType('mechTypes', MechTypeList().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0))),
+        namedtype.OptionalNamedType('reqFlags', ContextFlags().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1))),
+        namedtype.OptionalNamedType('mechToken', univ.OctetString().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 2))),
+        namedtype.OptionalNamedType('mechListMIC', univ.OctetString().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 3)))
+    )
+
+
+class NegTokenTarg(univ.Sequence):
+    componentType = namedtype.NamedTypes(
+        namedtype.OptionalNamedType('negResult', NegResultEnumerated().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0))),
+        namedtype.OptionalNamedType('supportedMech', univ.ObjectIdentifier().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1))),
+        namedtype.OptionalNamedType('responseToken', univ.OctetString().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 2))),
+        namedtype.OptionalNamedType('mechListMIC', univ.OctetString().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 3)))
+    )
+
+
+class NegotiationToken(univ.Choice):
+    componentType = namedtype.NamedTypes(
+        namedtype.NamedType('negTokenInit', NegTokenInit().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0))),
+        namedtype.NamedType('negTokenTarg', NegTokenTarg().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1)))
+    )
+
+
+class ContextToken(univ.Sequence):
+    tagSet = univ.Sequence.tagSet.tagImplicitly(tag.Tag(tag.tagClassApplication, tag.tagFormatConstructed, 0))
+    componentType = namedtype.NamedTypes(
+        namedtype.NamedType('thisMech', univ.ObjectIdentifier()),
+        namedtype.NamedType('innerContextToken', NegotiationToken())
+    )
diff --git a/python3/smb/smb2_constants.py b/python3/smb/smb2_constants.py
new file mode 100644
index 00000000..024ed2c4
--- /dev/null
+++ b/python3/smb/smb2_constants.py
@@ -0,0 +1,115 @@
+
+# Bitmask for Flags field in SMB2 message header
+SMB2_FLAGS_SERVER_TO_REDIR = 0x01
+SMB2_FLAGS_ASYNC_COMMAND = 0x02
+SMB2_FLAGS_RELATED_OPERATIONS = 0x04
+SMB2_FLAGS_SIGNED = 0x08
+SMB2_FLAGS_DFS_OPERATIONS = 0x10000000
+
+# Values for Command field in SMB2 message header
+SMB2_COM_NEGOTIATE = 0x0000
+SMB2_COM_SESSION_SETUP = 0x0001
+SMB2_COM_LOGOFF = 0x0002
+SMB2_COM_TREE_CONNECT = 0x0003
+SMB2_COM_TREE_DISCONNECT = 0x0004
+SMB2_COM_CREATE = 0x0005
+SMB2_COM_CLOSE = 0x0006
+SMB2_COM_FLUSH = 0x0007
+SMB2_COM_READ = 0x0008
+SMB2_COM_WRITE = 0x0009
+SMB2_COM_LOCK = 0x000A
+SMB2_COM_IOCTL = 0x000B
+SMB2_COM_CANCEL = 0x000C
+SMB2_COM_ECHO = 0x000D
+SMB2_COM_QUERY_DIRECTORY = 0x000E
+SMB2_COM_CHANGE_NOTIFY = 0x000F
+SMB2_COM_QUERY_INFO = 0x0010
+SMB2_COM_SET_INFO = 0x0011
+SMB2_COM_OPLOCK_BREAK = 0x0012
+
+SMB2_COMMAND_NAMES = {
+    0x0000: 'SMB2_COM_NEGOTIATE',
+    0x0001: 'SMB2_COM_SESSION_SETUP',
+    0x0002: 'SMB2_COM_LOGOFF',
+    0x0003: 'SMB2_COM_TREE_CONNECT',
+    0x0004: 'SMB2_COM_TREE_DISCONNECT',
+    0x0005: 'SMB2_COM_CREATE',
+    0x0006: 'SMB2_COM_CLOSE',
+    0x0007: 'SMB2_COM_FLUSH',
+    0x0008: 'SMB2_COM_READ',
+    0x0009: 'SMB2_COM_WRITE',
+    0x000A: 'SMB2_COM_LOCK',
+    0x000B: 'SMB2_COM_IOCTL',
+    0x000C: 'SMB2_COM_CANCEL',
+    0x000D: 'SMB2_COM_ECHO',
+    0x000E: 'SMB2_COM_QUERY_DIRECTORY',
+    0x000F: 'SMB2_COM_CHANGE_NOTIFY',
+    0x0010: 'SMB2_COM_QUERY_INFO',
+    0x0011: 'SMB2_COM_SET_INFO',
+    0x0012: 'SMB2_COM_OPLOCK_BREAK',
+}
+
+# Values for dialect_revision field in SMB2NegotiateResponse class
+SMB2_DIALECT_2 = 0x0202  # 2.0.2 - First SMB2 version
+SMB2_DIALECT_21 = 0x0210  # 2.1 - Windows 7
+SMB2_DIALET_30 = 0x0300  # 3.0 - Windows 8
+SMB2_DIALECT_302 = 0x0302  # 3.0.2 - Windows 8.1
+SMB2_DIALECT_311 = 0x0311  # 3.1.1 - Windows 10
+SMB2_DIALECT_2ALL = 0x02FF  # Wildcard (for negotiation only)
+
+# Bit mask for SecurityMode field in SMB2NegotiateResponse class
+SMB2_NEGOTIATE_SIGNING_ENABLED = 0x0001
+SMB2_NEGOTIATE_SIGNING_REQUIRED = 0x0002
+
+# Values for ShareType field in SMB2TreeConnectResponse class
+SMB2_SHARE_TYPE_DISK = 0x01
+SMB2_SHARE_TYPE_PIPE = 0x02
+SMB2_SHARE_TYPE_PRINTER = 0x03
+
+# Bitmask for Capabilities in SMB2TreeConnectResponse class
+SMB2_SHARE_CAP_DFS = 0x0008
+
+
+# SMB 2.1 / 3 Capabilities flags
+SMB2_GLOBAL_CAP_DFS = 0x01
+SMB2_GLOBAL_CAP_LEASING = 0x02
+SMB2_GLOBAL_CAP_LARGE_MTU = 0x04
+SMB2_GLOBAL_CAP_MULTI_CHANNEL = 0x08
+SMB2_GLOBAL_CAP_PERSISTENT_HANDLES = 0x10
+SMB2_GLOBAL_CAP_DIRECTORY_LEASING = 0x20
+SMB2_GLOBAL_CAP_ENCRYPTION = 0x40
+
+
+# Values for OpLockLevel field in SMB2CreateRequest class
+SMB2_OPLOCK_LEVEL_NONE = 0x00
+SMB2_OPLOCK_LEVEL_II = 0x01
+SMB2_OPLOCK_LEVEL_EXCLUSIVE = 0x08
+SMB2_OPLOCK_LEVEL_BATCH = 0x09
+SMB2_OPLOCK_LEVEL_LEASE = 0xFF
+
+# Values for FileAttributes field in SMB2CreateRequest class
+# The values are defined in [MS-FSCC] 2.6
+SMB2_FILE_ATTRIBUTE_ARCHIVE = 0x0020
+SMB2_FILE_ATTRIBUTE_COMPRESSED = 0x0800
+SMB2_FILE_ATTRIBUTE_DIRECTORY = 0x0010
+SMB2_FILE_ATTRIBUTE_ENCRYPTED = 0x4000
+SMB2_FILE_ATTRIBUTE_HIDDEN = 0x0002
+SMB2_FILE_ATTRIBUTE_NORMAL = 0x0080
+SMB2_FILE_ATTRIBUTE_NOTINDEXED = 0x2000
+SMB2_FILE_ATTRIBUTE_OFFLINE = 0x1000
+SMB2_FILE_ATTRIBUTE_READONLY = 0x0001
+SMB2_FILE_ATTRIBUTE_SPARSE = 0x0200
+SMB2_FILE_ATTRIBUTE_SYSTEM = 0x0004
+SMB2_FILE_ATTRIBUTE_TEMPORARY = 0x0100
+
+# Values for CreateAction field in SMB2CreateResponse class
+SMB2_FILE_SUPERCEDED = 0x00
+SMB2_FILE_OPENED = 0x01
+SMB2_FILE_CREATED = 0x02
+SMB2_FILE_OVERWRITTEN = 0x03
+
+# Values for InfoType field in SMB2QueryInfoRequest class
+SMB2_INFO_FILE = 0x01
+SMB2_INFO_FILESYSTEM = 0x02
+SMB2_INFO_SECURITY = 0x03
+SMB2_INFO_QUOTA = 0x04
diff --git a/python3/smb/smb2_structs.py b/python3/smb/smb2_structs.py
new file mode 100644
index 00000000..f396628a
--- /dev/null
+++ b/python3/smb/smb2_structs.py
@@ -0,0 +1,1002 @@
+
+import os, sys, struct, types, logging, binascii, time, uuid
+from io import StringIO
+from .smb_structs import ProtocolError
+from .smb_constants import *
+from .smb2_constants import *
+from .utils import convertFILETIMEtoEpoch
+
+
+class SMB2Message:
+
+    HEADER_STRUCT_FORMAT = "<4sHHIHHI"  # This refers to the common header part that is shared by both sync and async SMB2 header
+    HEADER_STRUCT_SIZE = struct.calcsize(HEADER_STRUCT_FORMAT)
+
+    ASYNC_HEADER_STRUCT_FORMAT = "<IQQQ16s"
+    ASYNC_HEADER_STRUCT_SIZE = struct.calcsize(ASYNC_HEADER_STRUCT_FORMAT)
+
+    SYNC_HEADER_STRUCT_FORMAT = "<IQIIQ16s"
+    SYNC_HEADER_STRUCT_SIZE = struct.calcsize(SYNC_HEADER_STRUCT_FORMAT)
+
+    HEADER_SIZE = 64
+
+    log = logging.getLogger('SMB.SMB2Message')
+    protocol = 2
+
+    def __init__(self, conn = None, payload = None):
+        """
+        Initialise a new SMB2 Message.
+        conn - reference to the connection, the SMB class
+        payload - the message payload, if any
+        """
+        self.reset()
+        self.conn = conn
+        if payload:
+            self.payload = payload
+            self.payload.initMessage(self)
+
+    def __str__(self):
+        b = StringIO()
+        b.write('Command: 0x%02X (%s) %s' % ( self.command, SMB2_COMMAND_NAMES.get(self.command, '<unknown>'), os.linesep ))
+        b.write('Status: 0x%08X %s' % ( self.status, os.linesep ))
+        b.write('Flags: 0x%02X %s' % ( self.flags, os.linesep ))
+        b.write('PID: %d %s' % ( self.pid, os.linesep ))
+        b.write('MID: %d %s' % ( self.mid, os.linesep ))
+        b.write('TID: %d %s' % ( self.tid, os.linesep ))
+        b.write('Data: %d bytes %s%s %s' % ( len(self.data), os.linesep, str(binascii.hexlify(self.data)), os.linesep ))
+        return b.getvalue()
+
+    def reset(self):
+        self.raw_data = b''
+        self.command = 0
+        self.status = 0
+        self.flags = 0
+
+        self.next_command_offset = 0
+        self.mid = 0
+        self.session_id = 0
+        self.signature = b'\0'*16
+        self.payload = None
+        self.data = b''
+
+        # For async SMB2 message
+        self.async_id = 0
+
+        # For sync SMB2 message
+        self.pid = 0
+        self.tid = 0
+
+        # credit related
+        self.credit_charge = 0
+        self.credit_request = 1
+
+        # Not used in this class. Maintained for compatibility with SMBMessage class
+        self.flags2 = 0
+        self.uid = 0
+        self.security = 0
+        self.parameters_data = b''
+
+    def encode(self):
+        """
+        Encode this SMB2 message into a series of bytes suitable to be embedded with a NetBIOS session message.
+        AssertionError will be raised if this SMB message has not been initialized with an SMB instance
+        AssertionError will be raised if this SMB message has not been initialized with a Payload instance
+
+        The header format is:
+        - Protocol ID
+        - Structure Size
+        - Credit Charge
+        - Status / Channel Sequence
+        - Command
+        - Credit Request / Credit Response
+        - Flags
+        - Next Compound
+        - MessageId
+        - Reserved
+        - TreeId
+        - Session ID
+        - Signature
+
+        @return: a string containing the encoded SMB2 message
+        """
+        assert self.payload
+
+        self.pid = os.getpid()
+        self.payload.prepare(self)
+
+        # If Connection.Dialect is not "2.0.2" and if Connection.SupportsMultiCredit is TRUE, the
+        # CreditCharge field in the SMB2 header MUST be set to ( 1 + (OutputBufferLength - 1) / 65536 )
+        # This only applies to SMB2ReadRequest, SMB2WriteRequest, SMB2IoctlRequest and SMB2QueryDirectory
+        # See: MS-SMB2 3.2.4.1.5: For all other requests, the client MUST set CreditCharge to 1, even if the
+        # payload size of a request or the anticipated response is greater than 65536.
+        if self.conn.smb2_dialect != SMB2_DIALECT_2:
+            if self.conn.cap_multi_credit:
+                # self.credit_charge will be set by some commands if necessary (Read/Write/Ioctl/QueryDirectory)
+                # If not set, but dialect is SMB 2.1 or above, we must set it to 1
+                if self.credit_charge is 0:
+                    self.credit_charge = 1
+            else:
+                # If >= SMB 2.1, but server does not support multi credit operations we must set to 1
+                self.credit_charge = 1
+
+        if self.mid > 3:
+            self.credit_request = 127
+
+        headers_data = struct.pack(self.HEADER_STRUCT_FORMAT,
+                                   b'\xFESMB',  # Protocol ID
+                                   self.HEADER_SIZE,  # Structure Size
+                                   self.credit_charge,  # Credit Charge
+                                   self.status,  # Status / Channel Sequence
+                                   self.command,  # Command
+                                   self.credit_request,  # Credit Request / Credit Response
+                                   self.flags, # Flags
+                                   ) + \
+                       struct.pack(self.SYNC_HEADER_STRUCT_FORMAT,
+                                    self.next_command_offset, # Next Compound
+                                    self.mid,  # Message ID
+                                    self.pid,  # Process ID
+                                    self.tid,  # Tree ID
+                                    self.session_id,  # Session ID
+                                    self.signature)  # Signature
+        return headers_data + self.data
+
+    def decode(self, buf):
+        """
+        Decodes the SMB message in buf.
+        All fields of the SMB2Message object will be reset to default values before decoding.
+        On errors, do not assume that the fields will be reinstated back to what they are before
+        this method is invoked.
+
+        References
+        ==========
+        - [MS-SMB2]: 2.2.1
+
+        @param buf: data containing one complete SMB2 message
+        @type buf: string
+        @return: a positive integer indicating the number of bytes used in buf to decode this SMB message
+        @raise ProtocolError: raised when decoding fails
+        """
+        buf_len = len(buf)
+        if buf_len < 64:  # All SMB2 headers must be at least 64 bytes. [MS-SMB2]: 2.2.1.1, 2.2.1.2
+            raise ProtocolError('Not enough data to decode SMB2 header', buf)
+
+        self.reset()
+
+        protocol, struct_size, self.credit_charge, self.status, \
+            self.command, self.credit_response, \
+            self.flags = struct.unpack(self.HEADER_STRUCT_FORMAT, buf[:self.HEADER_STRUCT_SIZE])
+        protocol, struct_size, self.credit_charge, self.status, \
+            self.command, self.credit_re, self.flags = struct.unpack(self.HEADER_STRUCT_FORMAT, buf[:self.HEADER_STRUCT_SIZE])
+
+        if protocol != b'\xFESMB':
+            raise ProtocolError('Invalid 4-byte SMB2 protocol field', buf)
+
+        if struct_size != self.HEADER_SIZE:
+            raise ProtocolError('Invalid SMB2 header structure size')
+
+        if self.isAsync:
+            if buf_len < self.HEADER_STRUCT_SIZE+self.ASYNC_HEADER_STRUCT_SIZE:
+                raise ProtocolError('Not enough data to decode SMB2 header', buf)
+
+            self.next_command_offset, self.mid, self.async_id, self.session_id, \
+                self.signature = struct.unpack(self.ASYNC_HEADER_STRUCT_FORMAT,
+                                               buf[self.HEADER_STRUCT_SIZE:self.HEADER_STRUCT_SIZE+self.ASYNC_HEADER_STRUCT_SIZE])
+        else:
+            if buf_len < self.HEADER_STRUCT_SIZE+self.SYNC_HEADER_STRUCT_SIZE:
+                raise ProtocolError('Not enough data to decode SMB2 header', buf)
+
+            self.next_command_offset, self.mid, self.pid, self.tid, self.session_id, \
+                self.signature = struct.unpack(self.SYNC_HEADER_STRUCT_FORMAT,
+                                               buf[self.HEADER_STRUCT_SIZE:self.HEADER_STRUCT_SIZE+self.SYNC_HEADER_STRUCT_SIZE])
+
+        if self.next_command_offset > 0:
+            self.raw_data = buf[:self.next_command_offset]
+            self.data = buf[self.HEADER_SIZE:self.next_command_offset]
+        else:
+            self.raw_data = buf
+            self.data = buf[self.HEADER_SIZE:]
+
+        self._decodeCommand()
+        if self.payload:
+            self.payload.decode(self)
+
+        return len(self.raw_data)
+
+    def _decodeCommand(self):
+        if self.command == SMB2_COM_READ:
+            self.payload = SMB2ReadResponse()
+        elif self.command == SMB2_COM_WRITE:
+            self.payload = SMB2WriteResponse()
+        elif self.command == SMB2_COM_QUERY_DIRECTORY:
+            self.payload = SMB2QueryDirectoryResponse()
+        elif self.command == SMB2_COM_CREATE:
+            self.payload = SMB2CreateResponse()
+        elif self.command == SMB2_COM_CLOSE:
+            self.payload = SMB2CloseResponse()
+        elif self.command == SMB2_COM_QUERY_INFO:
+            self.payload = SMB2QueryInfoResponse()
+        elif self.command == SMB2_COM_SET_INFO:
+            self.payload = SMB2SetInfoResponse()
+        elif self.command == SMB2_COM_IOCTL:
+            self.payload = SMB2IoctlResponse()
+        elif self.command == SMB2_COM_TREE_CONNECT:
+            self.payload = SMB2TreeConnectResponse()
+        elif self.command == SMB2_COM_SESSION_SETUP:
+            self.payload = SMB2SessionSetupResponse()
+        elif self.command == SMB2_COM_NEGOTIATE:
+            self.payload = SMB2NegotiateResponse()
+        elif self.command == SMB2_COM_ECHO:
+            self.payload = SMB2EchoResponse()
+
+    @property
+    def isAsync(self):
+        return bool(self.flags & SMB2_FLAGS_ASYNC_COMMAND)
+
+    @property
+    def isReply(self):
+        return bool(self.flags & SMB2_FLAGS_SERVER_TO_REDIR)
+
+
+class Structure:
+
+    def initMessage(self, message):
+        pass
+
+    def prepare(self, message):
+        raise NotImplementedError
+
+    def decode(self, message):
+        raise NotImplementedError
+
+
+class SMB2NegotiateRequest(Structure):
+    """
+    2.2.3 SMB2 NEGOTIATE Request
+    The SMB2 NEGOTIATE Request packet is used by the client to notify the server what dialects of the SMB 2 Protocol
+    the client understands. This request is composed of an SMB2 header, as specified in section 2.2.1,
+    followed by this request structure:
+
+    SMB2 Negotiate Request Packet structure:
+        StructureSize (2 bytes)
+        DialectCount (2 bytes)
+        SecurityMode (2 bytes)
+        Reserved (2 bytes)
+        Capabilities (4 bytes)
+        ClientGuid (16 bytes)
+        ClientStartTime (8 bytes):
+        ClientStartTime (8 bytes):
+        Dialects (variable): An array of one or more 16-bit integers
+
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.3
+
+    """
+
+
+    STRUCTURE_FORMAT = "<HHHHI16sQHH"
+    STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT)
+
+    def initMessage(self, message):
+        Structure.initMessage(self, message)
+        message.command = SMB2_COM_NEGOTIATE
+
+    def prepare(self, message):
+        # TODO! Do we need to save the GUID and present it later in other requests?
+        # The SMB docs don't exactly explain what the guid is for
+        message.data = struct.pack(self.STRUCTURE_FORMAT,
+                                   36,           # Structure size. Must be 36 as mandated by [MS-SMB2] 2.2.3
+                                   2,            # DialectCount
+                                   0x01,         # Security mode
+                                   0,            # Reserved
+                                   0x00,         # Capabilities
+                                   uuid.uuid4().bytes, # Client GUID
+                                   0,            # Client start time
+                                   SMB2_DIALECT_2,
+                                   SMB2_DIALECT_21)
+
+
+class SMB2NegotiateResponse(Structure):
+    """
+    Contains information on the SMB2_NEGOTIATE response from server
+
+    After calling the decode method, each instance will contain the following attributes,
+    - security_mode (integer)
+    - dialect_revision (integer)
+    - server_guid (string)
+    - max_transact_size (integer)
+    - max_read_size (integer)
+    - max_write_size (integer)
+    - system_time (long)
+    - server_start_time (long)
+    - security_blob (string)
+
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.4
+    """
+
+    STRUCTURE_FORMAT = "<HHHH16sIIIIQQHHI"
+    STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT)
+
+    def decode(self, message):
+        assert message.command == SMB2_COM_NEGOTIATE
+
+        if message.status == 0:
+            struct_size, self.security_mode, self.dialect_revision, _, self.server_guid, self.capabilities, \
+            self.max_transact_size, self.max_read_size, self.max_write_size, self.system_time, self.server_start_time, \
+            security_buf_offset, security_buf_len, _ = struct.unpack(self.STRUCTURE_FORMAT, message.raw_data[SMB2Message.HEADER_SIZE:SMB2Message.HEADER_SIZE+self.STRUCTURE_SIZE])
+
+            self.server_start_time = convertFILETIMEtoEpoch(self.server_start_time)
+            self.system_time = convertFILETIMEtoEpoch(self.system_time)
+            self.security_blob = message.raw_data[security_buf_offset:security_buf_offset+security_buf_len]
+            message.conn.smb2_dialect = self.dialect_revision
+
+
+class SMB2SessionSetupRequest(Structure):
+    """
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.5
+    """
+
+    STRUCTURE_FORMAT = "<HBBIIHHQ"
+    STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT)
+
+    def __init__(self, security_blob):
+        self.security_blob = security_blob
+
+    def initMessage(self, message):
+        Structure.initMessage(self, message)
+        message.command = SMB2_COM_SESSION_SETUP
+
+    def prepare(self, message):
+        message.data = struct.pack(self.STRUCTURE_FORMAT,
+                                   25,   # Structure size. Must be 25 as mandated by [MS-SMB2] 2.2.5
+                                   0,    # VcNumber
+                                   0x01, # Security mode
+                                   0x00, # Capabilities
+                                   0,    # Channel
+                                   SMB2Message.HEADER_SIZE + self.STRUCTURE_SIZE,
+                                   len(self.security_blob),
+                                   0) + self.security_blob
+
+
+class SMB2SessionSetupResponse(Structure):
+    """
+    Contains information about the SMB2_COM_SESSION_SETUP response from the server.
+
+    If the message has no errors, each instance contains the following attributes:
+    - session_flags (integer)
+    - security_blob (string)
+
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.6
+    """
+
+    STRUCTURE_FORMAT = "<HHHH"
+    STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT)
+
+    @property
+    def isGuestSession(self):
+        return (self.session_flags & 0x0001) > 0   # SMB2_SESSION_FLAG_IS_GUEST
+
+    @property
+    def isAnonymousSession(self):
+        return (self.session_flags & 0x0002) > 0   # SMB2_SESSION_FLAG_IS_NULL
+
+    def decode(self, message):
+        assert message.command == SMB2_COM_SESSION_SETUP
+
+        struct_size, self.session_flags, security_blob_offset, security_blob_len \
+            = struct.unpack(self.STRUCTURE_FORMAT, message.raw_data[SMB2Message.HEADER_SIZE:SMB2Message.HEADER_SIZE+self.STRUCTURE_SIZE])
+
+        self.security_blob = message.raw_data[security_blob_offset:security_blob_offset+security_blob_len]
+
+
+class SMB2TreeConnectRequest(Structure):
+    """
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.9
+    """
+
+    STRUCTURE_FORMAT = "<HHHH"
+    STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT)
+
+    def __init__(self, path):
+        self.path = path
+
+    def initMessage(self, message):
+        Structure.initMessage(self, message)
+        message.command = SMB2_COM_TREE_CONNECT
+
+    def prepare(self, message):
+        message.data = struct.pack(self.STRUCTURE_FORMAT,
+                                   9,  # Structure size. Must be 9 as mandated by [MS-SMB2] 2.2.9
+                                   0,  # Reserved
+                                   SMB2Message.HEADER_SIZE + self.STRUCTURE_SIZE,
+                                   len(self.path)*2) + self.path.encode('UTF-16LE')
+
+
+class SMB2TreeConnectResponse(Structure):
+    """
+    Contains information about the SMB2_COM_TREE_CONNECT response from the server.
+
+    If the message has no errors, each instance contains the following attributes:
+    - share_type (integer): one of the SMB2_SHARE_TYPE_xxx constants
+    - share_flags (integer)
+    - capabilities (integer): bitmask of SMB2_SHARE_CAP_xxx
+    - maximal_access (integer)
+
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.10
+    """
+
+    STRUCTURE_FORMAT = "<HBBIII"
+    STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT)
+
+    def decode(self, message):
+        assert message.command == SMB2_COM_TREE_CONNECT
+
+        if message.status == 0:
+            struct_size, self.share_type, _, \
+                self.share_flags, self.capabilities, self.maximal_access \
+                = struct.unpack(self.STRUCTURE_FORMAT, message.raw_data[SMB2Message.HEADER_SIZE:SMB2Message.HEADER_SIZE+self.STRUCTURE_SIZE])
+
+
+class SMB2CreateRequest(Structure):
+    """
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.13
+    """
+
+    STRUCTURE_FORMAT = "<HBBIQQIIIIIHHII"
+    STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT)
+
+    def __init__(self, filename, file_attributes = 0,
+                 access_mask = 0, share_access = 0, create_disp = 0, create_options = 0,
+                 impersonation = SEC_ANONYMOUS,
+                 oplock = SMB2_OPLOCK_LEVEL_NONE,
+                 create_context_data = b''):
+        self.filename = filename
+        self.file_attributes = file_attributes
+        self.access_mask = access_mask
+        self.share_access = share_access
+        self.create_disp = create_disp
+        self.create_options = create_options
+        self.oplock = oplock
+        self.impersonation = impersonation
+        self.create_context_data = create_context_data or b''
+
+    def initMessage(self, message):
+        Structure.initMessage(self, message)
+        message.command = SMB2_COM_CREATE
+
+    def prepare(self, message):
+        buf = self.filename.encode('UTF-16LE')
+        if self.create_context_data:
+            n = SMB2Message.HEADER_SIZE + self.STRUCTURE_SIZE + len(buf)
+            if n % 8 != 0:
+                buf += b'\0'*(8-n%8)
+                create_context_offset = SMB2Message.HEADER_SIZE + self.STRUCTURE_SIZE + len(buf)
+            else:
+                create_context_offset = n
+            buf += self.create_context_data
+        else:
+            create_context_offset = 0
+        if not buf:
+            buf = b'\0'
+
+        assert create_context_offset % 8 == 0
+        message.data = struct.pack(self.STRUCTURE_FORMAT,
+                                   57,   # Structure size. Must be 57 as mandated by [MS-SMB2] 2.2.13
+                                   0,    # SecurityFlag. Must be 0
+                                   self.oplock,
+                                   self.impersonation,
+                                   0,    # SmbCreateFlags. Must be 0
+                                   0,    # Reserved. Must be 0
+                                   self.access_mask,  # DesiredAccess. [MS-SMB2] 2.2.13.1
+                                   self.file_attributes,
+                                   self.share_access,
+                                   self.create_disp,
+                                   self.create_options,
+                                   SMB2Message.HEADER_SIZE + self.STRUCTURE_SIZE,  # NameOffset
+                                   len(self.filename)*2,    # NameLength in bytes
+                                   create_context_offset,   # CreateContextOffset
+                                   len(self.create_context_data)   # CreateContextLength
+                                  ) + buf
+
+class SMB2CreateResponse(Structure):
+    """
+    Contains information about the SMB2_COM_CREATE response from the server.
+
+    If the message has no errors, each instance contains the following attributes:
+    - oplock (integer): one of SMB2_OPLOCK_LEVEL_xxx constants
+    - create_action (integer): one of SMB2_FILE_xxx constants
+    - allocation_size (long)
+    - file_size (long)
+    - file_attributes (integer)
+    - fid (16-bytes string)
+    - create_time, lastaccess_time, lastwrite_time, change_time (float)
+
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.14
+    """
+
+    STRUCTURE_FORMAT = "<HBBIQQQQQQII16sII"
+    STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT)
+
+    def decode(self, message):
+        assert message.command == SMB2_COM_CREATE
+
+        if message.status == 0:
+            struct_size, self.oplock, _, self.create_action, \
+            create_time, lastaccess_time, lastwrite_time, change_time, \
+            self.allocation_size, self.file_size, self.file_attributes, \
+            _, self.fid, _, _ = struct.unpack(self.STRUCTURE_FORMAT, message.raw_data[SMB2Message.HEADER_SIZE:SMB2Message.HEADER_SIZE+self.STRUCTURE_SIZE])
+
+            self.create_time = convertFILETIMEtoEpoch(create_time)
+            self.lastaccess_time = convertFILETIMEtoEpoch(lastaccess_time)
+            self.lastwrite_time = convertFILETIMEtoEpoch(lastwrite_time)
+            self.change_time = convertFILETIMEtoEpoch(change_time)
+
+
+class SMB2WriteRequest(Structure):
+    """
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.21
+    """
+
+    STRUCTURE_FORMAT = "<HHIQ16sIIHHI"
+    STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT)
+
+    def __init__(self, fid, data, offset, remaining_len = 0, flags = 0):
+        assert len(fid) == 16
+        self.fid = fid
+        self.data = data
+        self.offset = offset
+        self.remaining_len = remaining_len
+        self.flags = flags
+
+    def initMessage(self, message):
+        Structure.initMessage(self, message)
+        message.command = SMB2_COM_WRITE
+
+    def prepare(self, message):
+        message.data = struct.pack(self.STRUCTURE_FORMAT,
+                                   49,  # Structure size. Must be 49 as mandated by [MS-SMB2] 2.2.21
+                                   SMB2Message.HEADER_SIZE + self.STRUCTURE_SIZE,  # DataOffset
+                                   len(self.data),
+                                   self.offset,
+                                   self.fid,
+                                   0,  # Channel. Must be 0
+                                   self.remaining_len,  # RemainingBytes
+                                   0,  # WriteChannelInfoOffset,
+                                   0,  # WriteChannelInfoLength
+                                   self.flags) + self.data
+
+        # MS-SMB2 3.2.4.7
+        # If a client requests writing to a file, Connection.Dialect is not "2.0.2", and if
+        # Connection.SupportsMultiCredit is TRUE, the CreditCharge field in the SMB2 header MUST be set
+        # to ( 1 + (Length - 1) / 65536 )
+        if message.conn.smb2_dialect != SMB2_DIALECT_2 and message.conn.cap_multi_credit:
+            message.credit_charge = int(1 + (len(self.data) -1) / 65536)
+
+
+class SMB2WriteResponse(Structure):
+    """
+    Contains information about the SMB2_WRITE response from the server.
+
+    If the message has no errors, each instance contains the following attributes:
+    - count (integer)
+
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.22
+    """
+
+    STRUCTURE_FORMAT = "<HHIIHH"
+    STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT)
+
+    def decode(self, message):
+        assert message.command == SMB2_COM_WRITE
+        if message.status == 0:
+            struct_size, _, self.count, _, _, _ = struct.unpack(self.STRUCTURE_FORMAT, message.raw_data[SMB2Message.HEADER_SIZE:SMB2Message.HEADER_SIZE+self.STRUCTURE_SIZE])
+
+
+
+class SMB2ReadRequest(Structure):
+    """
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.19
+    """
+
+    STRUCTURE_FORMAT = "<HBBIQ16sIIIHH"
+    STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT)
+
+    def __init__(self, fid, read_offset, read_len, min_read_len = 0):
+        self.fid = fid
+        self.read_offset = read_offset
+        self.read_len = read_len
+        self.min_read_len = min_read_len
+
+    def initMessage(self, message):
+        Structure.initMessage(self, message)
+        message.command = SMB2_COM_READ
+
+    def prepare(self, message):
+        message.data = struct.pack(self.STRUCTURE_FORMAT,
+                                   49,   # Structure size. Must be 49 as mandated by [MS-SMB2] 2.2.19
+                                   0,    # Padding
+                                   0,    # Reserved
+                                   self.read_len,
+                                   self.read_offset,
+                                   self.fid,
+                                   self.min_read_len,
+                                   0,    # Channel
+                                   0,    # RemainingBytes
+                                   0,    # ReadChannelInfoOffset
+                                   0     # ReadChannelInfoLength
+                                  ) + b'\0'
+
+        # MS-SMB2 3.2.4.6
+        # If a client requests reading from a file, Connection.Dialect is not "2.0.2", and if
+        # Connection.SupportsMultiCredit is TRUE, the CreditCharge field in the SMB2 header MUST be set
+        # to ( 1 + (Length - 1) / 65536 )
+        if message.conn.smb2_dialect != SMB2_DIALECT_2 and message.conn.cap_multi_credit:
+            message.credit_charge = int(1 + (self.read_len -1) / 65536)
+
+
+class SMB2ReadResponse(Structure):
+    """
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.20
+    """
+
+    STRUCTURE_FORMAT = "<HBBIII"
+    STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT)
+
+    def decode(self, message):
+        assert message.command == SMB2_COM_READ
+
+        if message.status == 0:
+            struct_size, data_offset, _, self.data_length, _, _ = struct.unpack(self.STRUCTURE_FORMAT, message.raw_data[SMB2Message.HEADER_SIZE:SMB2Message.HEADER_SIZE+self.STRUCTURE_SIZE])
+            self.data = message.raw_data[data_offset:data_offset+self.data_length]
+
+
+class SMB2IoctlRequest(Structure):
+    """
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.31
+    """
+
+    STRUCTURE_FORMAT = "<HHI16sIIIIIIII"
+    STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT)
+
+    def __init__(self, fid, ctlcode, flags, in_data, max_out_size = 65536):
+        self.ctlcode = ctlcode
+        self.fid = fid
+        self.flags = flags
+        self.in_data = in_data
+        self.max_out_size = max_out_size
+
+    def initMessage(self, message):
+        Structure.initMessage(self, message)
+        message.command = SMB2_COM_IOCTL
+
+    def prepare(self, message):
+        message.data = struct.pack(self.STRUCTURE_FORMAT,
+                                   57,   # Structure size. Must be 57 as mandated by [MS-SMB2] 2.2.31
+                                   0,    # Reserved
+                                   self.ctlcode,  # CtlCode
+                                   self.fid,
+                                   SMB2Message.HEADER_SIZE + self.STRUCTURE_SIZE,  # InputOffset
+                                   len(self.in_data),  # InputCount
+                                   0,   # MaxInputResponse
+                                   0,   # OutputOffset
+                                   0,   # OutputCount
+                                   self.max_out_size,   # MaxOutputResponse
+                                   self.flags,   # Flags
+                                   0    # Reserved
+                                  ) + self.in_data
+
+        # If Connection.SupportsMultiCredit is TRUE, the CreditCharge field in the SMB2 header
+        # SHOULD be set to (max(InputCount, MaxOutputResponse) - 1) / 65536 + 1
+        if message.conn.smb2_dialect != SMB2_DIALECT_2 and message.conn.cap_multi_credit:
+            message.credit_charge = int((max(len(self.in_data), self.max_out_size) - 1) / 65536 + 1)
+
+
+class SMB2IoctlResponse(Structure):
+    """
+    Contains information about the SMB2_IOCTL response from the server.
+
+    If the message has no errors, each instance contains the following attributes:
+    - ctlcode (integer)
+    - fid (16-bytes string)
+    - flags (integer)
+    - in_data (string)
+    - out_data (string)
+
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.32
+    """
+
+    STRUCTURE_FORMAT = "<HHI16sIIIIII"
+    STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT)
+
+    def decode(self, message):
+        assert message.command == SMB2_COM_IOCTL
+
+        if message.status == 0:
+            struct_size, _, self.ctlcode, self.fid, \
+            input_offset, input_len, output_offset, output_len, \
+            self.flags, _ = struct.unpack(self.STRUCTURE_FORMAT, message.raw_data[SMB2Message.HEADER_SIZE:SMB2Message.HEADER_SIZE+self.STRUCTURE_SIZE])
+
+            if input_len > 0:
+                self.in_data = message.raw_data[input_offset:input_offset+input_len]
+            else:
+                self.in_data = b''
+
+            if output_len > 0:
+                self.out_data = message.raw_data[output_offset:output_offset+output_len]
+            else:
+                self.out_data = b''
+
+
+class SMB2CloseRequest(Structure):
+    """
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.15
+    """
+
+    STRUCTURE_FORMAT = "<HHI16s"
+    STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT)
+
+    def __init__(self, fid, flags = 0):
+        self.fid = fid
+        self.flags = flags
+
+    def initMessage(self, message):
+        Structure.initMessage(self, message)
+        message.command = SMB2_COM_CLOSE
+
+    def prepare(self, message):
+        message.data = struct.pack(self.STRUCTURE_FORMAT,
+                                   24,  # Structure size. Must be 24 as mandated by [MS-SMB2]: 2.2.15
+                                   self.flags,
+                                   0,   # Reserved. Must be 0
+                                   self.fid)
+
+
+class SMB2CloseResponse(Structure):
+    """
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.16
+    """
+
+    def decode(self, message):
+        assert message.command == SMB2_COM_CLOSE
+
+
+class SMB2QueryDirectoryRequest(Structure):
+    """
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.33
+    """
+
+    STRUCTURE_FORMAT = "<HBBI16sHHI"
+    STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT)
+
+    def __init__(self, fid, filename, info_class, flags, output_buf_len):
+        self.fid = fid
+        self.filename = filename
+        self.info_class = info_class
+        self.flags = flags
+        self.output_buf_len = output_buf_len
+
+    def initMessage(self, message):
+        Structure.initMessage(self, message)
+        message.command = SMB2_COM_QUERY_DIRECTORY
+
+    def prepare(self, message):
+        message.data = struct.pack(self.STRUCTURE_FORMAT,
+                                   33,   # Structure size. Must be 33 as mandated by [MS-SMB2] 2.2.33
+                                   self.info_class,   # FileInformationClass
+                                   self.flags,        # Flags
+                                   0,                 # FileIndex
+                                   self.fid,          # FileID
+                                   SMB2Message.HEADER_SIZE + self.STRUCTURE_SIZE,  # FileNameOffset
+                                   len(self.filename)*2,
+                                   self.output_buf_len) + self.filename.encode('UTF-16LE')
+
+        # MS-SMB2 3.2.4.17
+        # If Connection.Dialect is not "2.0.2" and if Connection.SupportsMultiCredit is TRUE, the
+        # CreditCharge field in the SMB2 header MUST be set to ( 1 + (OutputBufferLength - 1) / 65536 )
+        if message.conn.smb2_dialect != SMB2_DIALECT_2 and message.conn.cap_multi_credit:
+            message.credit_charge = int(1 + (self.output_buf_len -1) / 65536)
+
+
+class SMB2QueryDirectoryResponse(Structure):
+    """
+    Contains information about the SMB2_COM_QUERY_DIRECTORY response from the server.
+
+    If the message has no errors, each instance contains the following attributes:
+    - data_length (integer)
+    - data (string)
+
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.34
+    """
+
+    STRUCTURE_FORMAT = "<HHI"
+    STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT)
+
+    def decode(self, message):
+        assert message.command == SMB2_COM_QUERY_DIRECTORY
+
+        if message.status == 0:
+            struct_size, offset, self.data_length = struct.unpack(self.STRUCTURE_FORMAT, message.raw_data[SMB2Message.HEADER_SIZE:SMB2Message.HEADER_SIZE+self.STRUCTURE_SIZE])
+            self.data = message.raw_data[offset:offset+self.data_length]
+
+
+class SMB2QueryInfoRequest(Structure):
+    """
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.37
+    """
+
+    STRUCTURE_FORMAT = "<HBBIHHIII16s"
+    STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT)
+
+    def __init__(self, fid, flags, additional_info, info_type, file_info_class, input_buf, output_buf_len):
+        self.fid = fid
+        self.flags = flags
+        self.additional_info = additional_info
+        self.info_type = info_type
+        self.file_info_class = file_info_class
+        self.output_buf_len = output_buf_len
+        self.input_buf = input_buf or b''
+
+    def initMessage(self, message):
+        Structure.initMessage(self, message)
+        message.command = SMB2_COM_QUERY_INFO
+
+    def prepare(self, message):
+        message.data = struct.pack(self.STRUCTURE_FORMAT,
+                                   41,  # Structure size. Must be 41 as mandated by [MS-SMB2] 2.2.37
+                                   self.info_type,         # InfoType
+                                   self.file_info_class,   # FileInfoClass
+                                   self.output_buf_len,    # OutputBufferLength
+                                   SMB2Message.HEADER_SIZE + self.STRUCTURE_SIZE,  # InputBufferOffset
+                                   0,   # Reserved
+                                   len(self.input_buf),    # InputBufferLength
+                                   self.additional_info,   # AdditionalInformation
+                                   self.flags,             # Flags
+                                   self.fid                # FileId
+                                  ) + self.input_buf
+
+        # MS-SMB2 3.2.4.17
+        # If Connection.Dialect is not "2.0.2" and if Connection.SupportsMultiCredit is TRUE, the
+        # CreditCharge field in the SMB2 header MUST be set to ( 1 + (OutputBufferLength - 1) / 65536 )
+        if message.conn.smb2_dialect != SMB2_DIALECT_2 and message.conn.cap_multi_credit:
+            message.credit_charge = int(1 + ((self.output_buf_len + len(self.input_buf)) -1) / 65536)
+
+
+class SMB2QueryInfoResponse(Structure):
+    """
+    Contains information about the SMB2_COM_QUERY_INFO response from the server.
+
+    If the message has no errors, each instance contains the following attributes:
+    - data_length (integer)
+    - data (string)
+
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.38
+    """
+
+    STRUCTURE_FORMAT = "<HHI"
+    STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT)
+
+    def decode(self, message):
+        assert message.command == SMB2_COM_QUERY_INFO
+
+        if message.status == 0:
+            struct_size, buf_offset, self.data_length = struct.unpack(self.STRUCTURE_FORMAT, message.raw_data[SMB2Message.HEADER_SIZE:SMB2Message.HEADER_SIZE+self.STRUCTURE_SIZE])
+            self.data = message.raw_data[buf_offset:buf_offset+self.data_length]
+
+
+class SMB2SetInfoRequest(Structure):
+    """
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.39
+    """
+
+    STRUCTURE_FORMAT = "<HBBIHHI16s"
+    STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT)
+
+    def __init__(self, fid, additional_info, info_type, file_info_class, data):
+        self.fid = fid
+        self.additional_info = additional_info
+        self.info_type = info_type
+        self.file_info_class = file_info_class
+        self.data = data or b''
+
+    def initMessage(self, message):
+        Structure.initMessage(self, message)
+        message.command = SMB2_COM_SET_INFO
+
+    def prepare(self, message):
+        message.data = struct.pack(self.STRUCTURE_FORMAT,
+                                   33,   # StructureSize. Must be 33 as mandated by [MS-SMB2] 2.2.39
+                                   self.info_type,        # InfoType
+                                   self.file_info_class,  # FileInfoClass
+                                   len(self.data),        # BufferLength
+                                   SMB2Message.HEADER_SIZE + self.STRUCTURE_SIZE,  # BufferOffset
+                                   0,   # Reserved
+                                   self.additional_info,  # AdditionalInformation
+                                   self.fid               # FileId
+                                  ) + self.data
+
+        # MS-SMB2 3.2.4.17
+        # If Connection.Dialect is not "2.0.2" and if Connection.SupportsMultiCredit is TRUE, the
+        # CreditCharge field in the SMB2 header MUST be set to ( 1 + (OutputBufferLength - 1) / 65536 )
+        if message.conn.smb2_dialect != SMB2_DIALECT_2 and message.conn.cap_multi_credit:
+            message.credit_charge = int(1 + (len(self.data) -1) / 65536)
+
+
+class SMB2SetInfoResponse(Structure):
+    """
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.40
+    """
+
+    def decode(self, message):
+        pass
+
+
+class SMB2EchoRequest(Structure):
+    """
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.28
+    """
+
+    STRUCTURE_FORMAT = '<HH'
+    STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT)
+
+    def initMessage(self, message):
+        Structure.initMessage(self, message)
+        message.command = SMB2_COM_ECHO
+
+    def prepare(self, message):
+        message.data = struct.pack(self.STRUCTURE_FORMAT,
+                                   4,   # StructureSize. Must be 4 as mandated by [MS-SMB2] 2.2.29
+                                   0)   # Reserved
+
+class SMB2EchoResponse(Structure):
+    """
+    References:
+    ===========
+    - [MS-SMB2]: 2.2.29
+    """
+
+    def decode(self, message):
+        pass
diff --git a/python3/smb/smb_constants.py b/python3/smb/smb_constants.py
new file mode 100644
index 00000000..de856520
--- /dev/null
+++ b/python3/smb/smb_constants.py
@@ -0,0 +1,257 @@
+
+# Values for Command field in SMB message header
+SMB_COM_CREATE_DIRECTORY = 0x00
+SMB_COM_DELETE_DIRECTORY = 0x01
+SMB_COM_CLOSE = 0x04
+SMB_COM_DELETE = 0x06
+SMB_COM_RENAME = 0x07
+SMB_COM_TRANSACTION = 0x25
+SMB_COM_ECHO = 0x2B
+SMB_COM_OPEN_ANDX = 0x2D
+SMB_COM_READ_ANDX = 0x2E
+SMB_COM_WRITE_ANDX = 0x2F
+SMB_COM_TRANSACTION2 = 0x32
+SMB_COM_NEGOTIATE = 0x72
+SMB_COM_SESSION_SETUP_ANDX = 0x73
+SMB_COM_TREE_CONNECT_ANDX = 0x75
+SMB_COM_NT_TRANSACT = 0xA0
+SMB_COM_NT_CREATE_ANDX = 0xA2
+
+SMB_COMMAND_NAMES = {
+    0x00: 'SMB_COM_CREATE_DIRECTORY',
+    0x01: 'SMB_COM_DELETE_DIRECTORY',
+    0x04: 'SMB_COM_CLOSE',
+    0x06: 'SMB_COM_DELETE',
+    0x25: 'SMB_COM_TRANSACTION',
+    0x2B: 'SMB_COM_ECHO',
+    0x2D: 'SMB_COM_OPEN_ANDX',
+    0x2E: 'SMB_COM_READ_ANDX',
+    0x2F: 'SMB_COM_WRITE_ANDX',
+    0x32: 'SMB_COM_TRANSACTION2',
+    0x72: 'SMB_COM_NEGOTIATE',
+    0x73: 'SMB_COM_SESSION_SETUP_ANDX',
+    0x75: 'SMB_COM_TREE_CONNECT_ANDX',
+    0xA0: 'SMB_COM_NT_TRANSACT',
+    0xA2: 'SMB_COM_NT_CREATE_ANDX',
+}
+
+# Bitmask for Flags field in SMB message header
+SMB_FLAGS_LOCK_AND_READ_OK = 0x01       # LANMAN1.0
+SMB_FLAGS_BUF_AVAIL = 0x02              # LANMAN1.0, Obsolete
+SMB_FLAGS_CASE_INSENSITIVE = 0x08       # LANMAN1.0, Obsolete
+SMB_FLAGS_CANONICALIZED_PATHS = 0x10    # LANMAN1.0, Obsolete
+SMB_FLAGS_OPLOCK = 0x20                 # LANMAN1.0, Obsolete
+SMB_FLAGS_OPBATCH = 0x40                # LANMAN1.0, Obsolete
+SMB_FLAGS_REPLY = 0x80                  # LANMAN1.0
+
+# Bitmask for Flags2 field in SMB message header
+SMB_FLAGS2_LONG_NAMES = 0x0001              # LANMAN2.0
+SMB_FLAGS2_EAS = 0x0002                     # LANMAN1.2
+SMB_FLAGS2_SMB_SECURITY_SIGNATURE = 0x0004  # NT LANMAN
+SMB_FLAGS2_IS_LONG_NAME = 0x0040            # NT LANMAN
+SMB_FLAGS2_DFS = 0x1000                     # NT LANMAN
+SMB_FLAGS2_REPARSE_PATH = 0x0400            #
+SMB_FLAGS2_EXTENDED_SECURITY = 0x0800       #
+SMB_FLAGS2_PAGING_IO = 0x2000               # NT LANMAN
+SMB_FLAGS2_NT_STATUS = 0x4000               # NT LANMAN
+SMB_FLAGS2_UNICODE = 0x8000                 # NT LANMAN
+
+# Bitmask for Capabilities field in SMB_COM_SESSION_SETUP_ANDX response
+# [MS-SMB]: 2.2.4.5.2.1 (Capabilities field)
+CAP_RAW_MODE = 0x01
+CAP_MPX_MODE = 0x02
+CAP_UNICODE = 0x04
+CAP_LARGE_FILES = 0x08
+CAP_NT_SMBS = 0x10
+CAP_RPC_REMOTE_APIS = 0x20
+CAP_STATUS32 = 0x40
+CAP_LEVEL_II_OPLOCKS = 0x80
+CAP_LOCK_AND_READ = 0x0100
+CAP_NT_FIND = 0x0200
+CAP_DFS = 0x1000
+CAP_INFOLEVEL_PASSTHRU = 0x2000
+CAP_LARGE_READX = 0x4000
+CAP_LARGE_WRITEX = 0x8000
+CAP_LWIO = 0x010000
+CAP_UNIX = 0x800000
+CAP_COMPRESSED = 0x02000000
+CAP_DYNAMIC_REAUTH = 0x20000000
+CAP_PERSISTENT_HANDLES = 0x40000000
+CAP_EXTENDED_SECURITY = 0x80000000
+
+# Value for Action field in SMB_COM_SESSION_SETUP_ANDX response
+SMB_SETUP_GUEST = 0x0001
+SMB_SETUP_USE_LANMAN_KEY = 0X0002
+
+# Bitmask for SecurityMode field in SMB_COM_NEGOTIATE response
+NEGOTIATE_USER_SECURITY = 0x01
+NEGOTIATE_ENCRYPT_PASSWORDS = 0x02
+NEGOTIATE_SECURITY_SIGNATURES_ENABLE = 0x04
+NEGOTIATE_SECURITY_SIGNATURES_REQUIRE = 0x08
+
+# Available constants for Service field in SMB_COM_TREE_CONNECT_ANDX request
+# [MS-CIFS]: 2.2.4.55.1 (Service field)
+SERVICE_PRINTER = 'LPT1:'
+SERVICE_NAMED_PIPE = 'IPC'
+SERVICE_COMM = 'COMM'
+SERVICE_ANY = '?????'
+
+# Bitmask for Flags field in SMB_COM_NT_CREATE_ANDX request
+# [MS-CIFS]: 2.2.4.64.1
+# [MS-SMB]: 2.2.4.9.1
+NT_CREATE_REQUEST_OPLOCK = 0x02
+NT_CREATE_REQUEST_OPBATCH = 0x04
+NT_CREATE_OPEN_TARGET_DIR = 0x08
+NT_CREATE_REQUEST_EXTENDED_RESPONSE = 0x10  # Defined in [MS-SMB]: 2.2.4.9.1
+
+# Bitmask for DesiredAccess field in SMB_COM_NT_CREATE_ANDX request
+# and SMB2CreateRequest class
+# Also used for MaximalAccess field in SMB2TreeConnectResponse class
+# [MS-CIFS]: 2.2.4.64.1
+# [MS-SMB2]: 2.2.13.1.1
+FILE_READ_DATA = 0x01
+FILE_WRITE_DATA = 0X02
+FILE_APPEND_DATA = 0x04
+FILE_READ_EA = 0x08
+FILE_WRITE_EA = 0x10
+FILE_EXECUTE = 0x20
+FILE_DELETE_CHILD = 0x40
+FILE_READ_ATTRIBUTES = 0x80
+FILE_WRITE_ATTRIBUTES = 0x0100
+DELETE = 0x010000
+READ_CONTROL = 0x020000
+WRITE_DAC = 0x040000
+WRITE_OWNER = 0x080000
+SYNCHRONIZE = 0x100000
+ACCESS_SYSTEM_SECURITY = 0x01000000
+MAXIMUM_ALLOWED = 0x02000000
+GENERIC_ALL = 0x10000000
+GENERIC_EXECUTE = 0x20000000
+GENERIC_WRITE = 0x40000000
+GENERIC_READ = 0x80000000
+
+# SMB_EXT_FILE_ATTR bitmask ([MS-CIFS]: 2.2.1.2.3)
+# Includes extensions defined in [MS-SMB] 2.2.1.2.1
+# Bitmask for FileAttributes field in SMB_COM_NT_CREATE_ANDX request ([MS-CIFS]: 2.2.4.64.1)
+# Also used for FileAttributes field in SMB2CreateRequest class ([MS-SMB2]: 2.2.13)
+ATTR_READONLY = 0x01
+ATTR_HIDDEN = 0x02
+ATTR_SYSTEM = 0x04
+ATTR_DIRECTORY = 0x10
+ATTR_ARCHIVE = 0x20
+ATTR_NORMAL = 0x80
+ATTR_TEMPORARY = 0x0100
+ATTR_SPARSE = 0x0200
+ATTR_REPARSE_POINT = 0x0400
+ATTR_COMPRESSED = 0x0800
+ATTR_OFFLINE = 0x1000
+ATTR_NOT_CONTENT_INDEXED = 0x2000
+ATTR_ENCRYPTED = 0x4000
+POSIX_SEMANTICS = 0x01000000
+BACKUP_SEMANTICS = 0x02000000
+DELETE_ON_CLOSE = 0x04000000
+SEQUENTIAL_SCAN = 0x08000000
+RANDOM_ACCESS = 0x10000000
+NO_BUFFERING = 0x20000000
+WRITE_THROUGH = 0x80000000
+
+# Bitmask for ShareAccess field in SMB_COM_NT_CREATE_ANDX request
+# and SMB2CreateRequest class
+# [MS-CIFS]: 2.2.4.64.1
+# [MS-SMB2]: 2.2.13
+FILE_SHARE_NONE = 0x00
+FILE_SHARE_READ = 0x01
+FILE_SHARE_WRITE = 0x02
+FILE_SHARE_DELETE = 0x04
+
+# Values for CreateDisposition field in SMB_COM_NT_CREATE_ANDX request
+# and SMB2CreateRequest class
+# [MS-CIFS]: 2.2.4.64.1
+# [MS-SMB2]: 2.2.13
+FILE_SUPERSEDE = 0x00
+FILE_OPEN = 0x01
+FILE_CREATE = 0x02
+FILE_OPEN_IF = 0x03
+FILE_OVERWRITE = 0x04
+FILE_OVERWRITE_IF = 0x05
+
+# Bitmask for CreateOptions field in SMB_COM_NT_CREATE_ANDX request
+# and SMB2CreateRequest class
+# [MS-CIFS]: 2.2.4.64.1
+# [MS-SMB2]: 2.2.13
+FILE_DIRECTORY_FILE = 0x01
+FILE_WRITE_THROUGH = 0x02
+FILE_SEQUENTIAL_ONLY = 0x04
+FILE_NO_INTERMEDIATE_BUFFERING = 0x08
+FILE_SYNCHRONOUS_IO_ALERT = 0x10
+FILE_SYNCHRONOUS_IO_NONALERT = 0x20
+FILE_NON_DIRECTORY_FILE = 0x40
+FILE_CREATE_TREE_CONNECTION = 0x80
+FILE_COMPLETE_IF_OPLOCKED = 0x0100
+FILE_NO_EA_KNOWLEDGE = 0x0200
+FILE_OPEN_FOR_RECOVERY = 0x0400
+FILE_RANDOM_ACCESS = 0x0800
+FILE_DELETE_ON_CLOSE = 0x1000
+FILE_OPEN_BY_FILE_ID = 0x2000
+FILE_OPEN_FOR_BACKUP_INTENT = 0x4000
+FILE_NO_COMPRESSION = 0x8000
+FILE_RESERVE_OPFILTER = 0x100000
+FILE_OPEN_NO_RECALL = 0x400000
+FILE_OPEN_FOR_FREE_SPACE_QUERY = 0x800000
+
+# Values for ImpersonationLevel field in SMB_COM_NT_CREATE_ANDX request
+# and SMB2CreateRequest class
+# For interpretations about these values, refer to [MS-WSO] and [MSDN-IMPERS]
+# [MS-CIFS]: 2.2.4.64.1
+# [MS-SMB]: 2.2.4.9.1
+# [MS-SMB2]: 2.2.13
+SEC_ANONYMOUS = 0x00
+SEC_IDENTIFY = 0x01
+SEC_IMPERSONATE = 0x02
+SEC_DELEGATION = 0x03   # Defined in [MS-SMB]: 2.2.4.9.1
+
+# Values for SecurityFlags field in SMB_COM_NT_CREATE_ANDX request
+# [MS-CIFS]: 2.2.4.64.1
+SMB_SECURITY_CONTEXT_TRACKING = 0x01
+SMB_SECURITY_EFFECTIVE_ONLY = 0x02
+
+# Bitmask for Flags field in SMB_COM_TRANSACTION2 request
+# [MS-CIFS]: 2.2.4.46.1
+DISCONNECT_TID = 0x01
+NO_RESPONSE = 0x02
+
+# Bitmask for basic file attributes
+# [MS-CIFS]: 2.2.1.2.4
+SMB_FILE_ATTRIBUTE_NORMAL = 0x00
+SMB_FILE_ATTRIBUTE_READONLY = 0x01
+SMB_FILE_ATTRIBUTE_HIDDEN = 0x02
+SMB_FILE_ATTRIBUTE_SYSTEM = 0x04
+SMB_FILE_ATTRIBUTE_VOLUME = 0x08  # Unsupported for listPath() operations
+SMB_FILE_ATTRIBUTE_DIRECTORY = 0x10
+SMB_FILE_ATTRIBUTE_ARCHIVE = 0x20
+# SMB_FILE_ATTRIBUTE_INCL_NORMAL is a special placeholder to include normal files
+# with other search attributes for listPath() operations. It is not defined in the MS-CIFS specs.
+SMB_FILE_ATTRIBUTE_INCL_NORMAL = 0x10000
+# Do not use the following values for listPath() operations as they are not supported for SMB2
+SMB_SEARCH_ATTRIBUTE_READONLY = 0x0100
+SMB_SEARCH_ATTRIBUTE_HIDDEN = 0x0200
+SMB_SEARCH_ATTRIBUTE_SYSTEM = 0x0400
+SMB_SEARCH_ATTRIBUTE_DIRECTORY = 0x1000
+SMB_SEARCH_ATTRIBUTE_ARCHIVE = 0x2000
+
+# Bitmask for OptionalSupport field in SMB_COM_TREE_CONNECT_ANDX response
+SMB_TREE_CONNECTX_SUPPORT_SEARCH = 0x0001
+SMB_TREE_CONNECTX_SUPPORT_DFS = 0x0002
+
+# Bitmask for security information fields, specified as
+# AdditionalInformation in SMB2
+# [MS-SMB]: 2.2.7.4
+# [MS-SMB2]: 2.2.37
+OWNER_SECURITY_INFORMATION = 0x00000001
+GROUP_SECURITY_INFORMATION = 0x00000002
+DACL_SECURITY_INFORMATION = 0x00000004
+SACL_SECURITY_INFORMATION = 0x00000008
+LABEL_SECURITY_INFORMATION = 0x00000010
+ATTRIBUTE_SECURITY_INFORMATION = 0x00000020
+SCOPE_SECURITY_INFORMATION = 0x00000040
+BACKUP_SECURITY_INFORMATION = 0x00010000
diff --git a/python3/smb/smb_structs.py b/python3/smb/smb_structs.py
new file mode 100644
index 00000000..c943d91a
--- /dev/null
+++ b/python3/smb/smb_structs.py
@@ -0,0 +1,1425 @@
+
+import os, sys, struct, types, logging, binascii, time
+from io import StringIO
+from .smb_constants import *
+
+
+# Set to True if you want to enable support for extended security. Required for Windows Vista and later
+SUPPORT_EXTENDED_SECURITY = True
+
+# Set to True if you want to enable SMB2 protocol.
+SUPPORT_SMB2 = True
+
+# Set to True if you want to enable SMB2.1 and above protocol.
+SUPPORT_SMB2x = True
+
+# Supported dialects
+NT_LAN_MANAGER_DIALECT = 0  # 'NT LM 0.12' is always the first element in the dialect list and must always be included (MS-SMB 2.2.4.5.1)
+
+# Return the list of support SMB dialects based on the SUPPORT_x constants
+def init_dialects_list():
+    dialects = [ b'NT LM 0.12' ]
+    if SUPPORT_SMB2:
+        dialects.append(b'SMB 2.002')
+    if SUPPORT_SMB2x:
+        dialects.append(b'SMB 2.???')
+    return dialects
+
+
+class UnsupportedFeature(Exception):
+    """
+    Raised when an supported feature is present/required in the protocol but is not
+    currently supported by pysmb
+    """
+    pass
+
+
+class ProtocolError(Exception):
+
+    def __init__(self, message, data_buf = None, smb_message = None):
+        self.message = message
+        self.data_buf = data_buf
+        self.smb_message = smb_message
+
+    def __str__(self):
+        b = StringIO()
+        b.write(self.message + os.linesep)
+        if self.smb_message:
+            b.write('=' * 20 + ' SMB Message ' + '=' * 20 + os.linesep)
+            b.write(str(self.smb_message))
+
+        if self.data_buf:
+            b.write('=' * 20 + ' SMB Data Packet (hex) ' + '=' * 20 + os.linesep)
+            b.write(str(binascii.hexlify(self.data_buf)))
+            b.write(os.linesep)
+
+        return b.getvalue()
+
+class SMB2ProtocolHeaderError(ProtocolError):
+
+    def __init__(self):
+        ProtocolError.__init__(self, "Packet header belongs to SMB2")
+
+class OperationFailure(Exception):
+
+    def __init__(self, message, smb_messages):
+        self.message = message
+        self.smb_messages = smb_messages
+
+    def __str__(self):
+        b = StringIO()
+        b.write(self.message + os.linesep)
+
+        for idx, m in enumerate(self.smb_messages):
+            b.write('=' * 20 + ' SMB Message %d ' % idx + '=' * 20 + os.linesep)
+            b.write('SMB Header:' + os.linesep)
+            b.write('-----------' + os.linesep)
+            b.write(str(m))
+            b.write('SMB Data Packet (hex):' + os.linesep)
+            b.write('----------------------' + os.linesep)
+            b.write(str(binascii.hexlify(m.raw_data)))
+            b.write(os.linesep)
+
+        return b.getvalue()
+
+
+class SMBError:
+
+    def __init__(self):
+        self.reset()
+
+    def reset(self):
+        self.internal_value = 0
+        self.is_ntstatus = True
+
+    def __str__(self):
+        if self.is_ntstatus:
+            return 'NTSTATUS=0x%08X' % self.internal_value
+        else:
+            return 'ErrorClass=0x%02X ErrorCode=0x%04X' % ( self.internal_value >> 24, self.internal_value & 0xFFFF )
+
+    @property
+    def hasError(self):
+        return self.internal_value != 0
+
+
+class SMBMessage:
+
+    HEADER_STRUCT_FORMAT = "<4sBIBHHQxxHHHHB"
+    HEADER_STRUCT_SIZE = struct.calcsize(HEADER_STRUCT_FORMAT)
+
+    log = logging.getLogger('SMB.SMBMessage')
+    protocol = 1
+
+    def __init__(self, conn, payload = None):
+        self.reset()
+        self.conn = conn
+        if payload:
+            self.payload = payload
+            self.payload.initMessage(self)
+
+    def __str__(self):
+        b = StringIO()
+        b.write('Command: 0x%02X (%s) %s' % ( self.command, SMB_COMMAND_NAMES.get(self.command, '<unknown>'), os.linesep ))
+        b.write('Status: %s %s' % ( str(self.status), os.linesep ))
+        b.write('Flags: 0x%02X %s' % ( self.flags, os.linesep ))
+        b.write('Flags2: 0x%04X %s' % ( self.flags2, os.linesep ))
+        b.write('PID: %d %s' % ( self.pid, os.linesep ))
+        b.write('UID: %d %s' % ( self.uid, os.linesep ))
+        b.write('MID: %d %s' % ( self.mid, os.linesep ))
+        b.write('TID: %d %s' % ( self.tid, os.linesep ))
+        b.write('Security: 0x%016X %s' % ( self.security, os.linesep ))
+        b.write('Parameters: %d bytes %s%s %s' % ( len(self.parameters_data), os.linesep, str(binascii.hexlify(self.parameters_data)), os.linesep ))
+        b.write('Data: %d bytes %s%s %s' % ( len(self.data), os.linesep, str(binascii.hexlify(self.data)), os.linesep ))
+        return b.getvalue()
+
+    def reset(self):
+        self.raw_data = b''
+        self.command = 0
+        self.status = SMBError()
+        self.flags = 0
+        self.flags2 = 0
+        self.pid = 0
+        self.tid = 0
+        self.uid = 0
+        self.mid = 0
+        self.security = 0
+        self.parameters_data = b''
+        self.data = b''
+        self.payload = None
+
+    @property
+    def isAsync(self):
+        return bool(self.flags & SMB2_FLAGS_ASYNC_COMMAND)
+
+    @property
+    def isReply(self):
+        return bool(self.flags & SMB_FLAGS_REPLY)
+
+    @property
+    def hasExtendedSecurity(self):
+        return bool(self.flags2 & SMB_FLAGS2_EXTENDED_SECURITY)
+
+    def encode(self):
+        """
+        Encode this SMB message into a series of bytes suitable to be embedded with a NetBIOS session message.
+        AssertionError will be raised if this SMB message has not been initialized with a Payload instance
+
+        @return: a string containing the encoded SMB message
+        """
+        assert self.payload
+
+        self.pid = os.getpid()
+        self.payload.prepare(self)
+
+        parameters_len = len(self.parameters_data)
+        assert parameters_len % 2 == 0
+
+        headers_data = struct.pack(self.HEADER_STRUCT_FORMAT,
+                                   b'\xFFSMB', self.command, self.status.internal_value, self.flags,
+                                   self.flags2, (self.pid >> 16) & 0xFFFF, self.security, self.tid,
+                                   self.pid & 0xFFFF, self.uid, self.mid, int(parameters_len / 2))
+        return headers_data + self.parameters_data + struct.pack('<H', len(self.data)) + self.data
+
+    def decode(self, buf):
+        """
+        Decodes the SMB message in buf.
+        All fields of the SMBMessage object will be reset to default values before decoding.
+        On errors, do not assume that the fields will be reinstated back to what they are before
+        this method is invoked.
+
+        @param buf: data containing one complete SMB message
+        @type buf: string
+        @return: a positive integer indicating the number of bytes used in buf to decode this SMB message
+        @raise ProtocolError: raised when decoding fails
+        """
+        buf_len = len(buf)
+        if buf_len < self.HEADER_STRUCT_SIZE:
+            # We need at least 32 bytes (header) + 1 byte (parameter count)
+            raise ProtocolError('Not enough data to decode SMB header', buf)
+
+        self.reset()
+
+        protocol, self.command, status, self.flags, \
+        self.flags2, pid_high, self.security, self.tid, \
+        pid_low, self.uid, self.mid, params_count = struct.unpack(self.HEADER_STRUCT_FORMAT, buf[:self.HEADER_STRUCT_SIZE])
+
+        if protocol == b'\xFESMB':
+            raise SMB2ProtocolHeaderError()
+        if protocol != b'\xFFSMB':
+            raise ProtocolError('Invalid 4-byte protocol field', buf)
+
+        self.pid = (pid_high << 16) | pid_low
+        self.status.internal_value = status
+        self.status.is_ntstatus = bool(self.flags2 & SMB_FLAGS2_NT_STATUS)
+
+        offset = self.HEADER_STRUCT_SIZE
+        if buf_len < params_count * 2 + 2:
+            # Not enough data in buf to decode up to body length
+            raise ProtocolError('Not enough data. Parameters list decoding failed', buf)
+
+        datalen_offset = offset + params_count*2
+        body_len = struct.unpack('<H', buf[datalen_offset:datalen_offset+2])[0]
+        if body_len > 0 and buf_len < (datalen_offset + 2 + body_len):
+            # Not enough data in buf to decode body
+            raise ProtocolError('Not enough data. Body decoding failed', buf)
+
+        self.parameters_data = buf[offset:datalen_offset]
+
+        if body_len > 0:
+            self.data = buf[datalen_offset+2:datalen_offset+2+body_len]
+
+        self.raw_data = buf
+        self._decodePayload()
+
+        return self.HEADER_STRUCT_SIZE + params_count * 2 + 2 + body_len
+
+    def _decodePayload(self):
+        if self.command == SMB_COM_READ_ANDX:
+            self.payload = ComReadAndxResponse()
+        elif self.command == SMB_COM_WRITE_ANDX:
+            self.payload = ComWriteAndxResponse()
+        elif self.command == SMB_COM_TRANSACTION:
+            self.payload = ComTransactionResponse()
+        elif self.command == SMB_COM_TRANSACTION2:
+            self.payload = ComTransaction2Response()
+        elif self.command == SMB_COM_OPEN_ANDX:
+            self.payload = ComOpenAndxResponse()
+        elif self.command == SMB_COM_NT_CREATE_ANDX:
+            self.payload = ComNTCreateAndxResponse()
+        elif self.command == SMB_COM_TREE_CONNECT_ANDX:
+            self.payload = ComTreeConnectAndxResponse()
+        elif self.command == SMB_COM_ECHO:
+            self.payload = ComEchoResponse()
+        elif self.command == SMB_COM_SESSION_SETUP_ANDX:
+            self.payload = ComSessionSetupAndxResponse()
+        elif self.command == SMB_COM_NEGOTIATE:
+            self.payload = ComNegotiateResponse()
+
+        if self.payload:
+            self.payload.decode(self)
+
+
+class Payload:
+
+    DEFAULT_ANDX_PARAM_HEADER = b'\xFF\x00\x00\x00'
+    DEFAULT_ANDX_PARAM_SIZE = 4
+
+    def initMessage(self, message):
+        # SMB_FLAGS2_UNICODE must always be enabled. Without this, almost all the Payload subclasses will need to be
+        # rewritten to check for OEM/Unicode strings which will be tedious. Fortunately, almost all tested CIFS services
+        # support SMB_FLAGS2_UNICODE by default.
+        assert message.payload == self
+        message.flags =  SMB_FLAGS_CASE_INSENSITIVE | SMB_FLAGS_CANONICALIZED_PATHS
+        message.flags2 = SMB_FLAGS2_UNICODE | SMB_FLAGS2_NT_STATUS | SMB_FLAGS2_IS_LONG_NAME | SMB_FLAGS2_LONG_NAMES
+
+        if SUPPORT_EXTENDED_SECURITY:
+            message.flags2 |= SMB_FLAGS2_EXTENDED_SECURITY
+
+    def prepare(self, message):
+        raise NotImplementedError
+
+    def decode(self, message):
+        raise NotImplementedError
+
+
+class ComNegotiateRequest(Payload):
+    """
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.52.1
+    - [MS-SMB]: 2.2.4.5.1
+    """
+
+    def initMessage(self, message):
+        Payload.initMessage(self, message)
+        message.command = SMB_COM_NEGOTIATE
+
+    def prepare(self, message):
+        assert message.payload == self
+        message.parameters_data = b''
+        message.data = b''.join(map(lambda s: b'\x02'+s+b'\x00', init_dialects_list()))
+
+
+class ComNegotiateResponse(Payload):
+    """
+    Contains information on the SMB_COM_NEGOTIATE response from server
+
+    After calling the decode method, each instance will contain the following attributes,
+    - security_mode (integer)
+    - max_mpx_count (integer)
+    - max_number_vcs (integer)
+    - max_buffer_size (long)
+    - max_raw_size (long)
+    - session_key (long)
+    - capabilities (long)
+    - system_time (long)
+    - server_time_zone (integer)
+    - challenge_length (integer)
+
+    If the underlying SMB message's flag2 does not have SMB_FLAGS2_EXTENDED_SECURITY bit enabled,
+    then the instance will have the following additional attributes,
+    - challenge (string)
+    - domain (unicode)
+
+    If the underlying SMB message's flags2 has SMB_FLAGS2_EXTENDED_SECURITY bit enabled,
+    then the instance will have the following additional attributes,
+    - server_guid (string)
+    - security_blob (string)
+
+    References:
+    ===========
+    - [MS-SMB]: 2.2.4.5.2.1
+    - [MS-CIFS]: 2.2.4.52.2
+    """
+
+    PAYLOAD_STRUCT_FORMAT = '<HBHHIIIIQHB'
+    PAYLOAD_STRUCT_SIZE = struct.calcsize(PAYLOAD_STRUCT_FORMAT)
+
+    def decode(self, message):
+        assert message.command == SMB_COM_NEGOTIATE
+
+        if not message.isReply:
+            raise ProtocolError('Not a SMB_COM_NEGOTIATE reply', message.raw_data, message)
+
+        self.security_mode, self.max_mpx_count, self.max_number_vcs, self.max_buffer_size, \
+        self.max_raw_size, self.session_key, self.capabilities, self.system_time, self.server_time_zone, \
+        self.challenge_length = ( 0, ) * 10
+
+        data_len = len(message.parameters_data)
+        if data_len < 2:
+            raise ProtocolError('Not enough data to decode SMB_COM_NEGOTIATE dialect_index field', message.raw_data, message)
+
+        self.dialect_index = struct.unpack('<H', message.parameters_data[:2])[0]
+        if self.dialect_index == NT_LAN_MANAGER_DIALECT:
+            if data_len != (0x11 * 2):
+                raise ProtocolError('NT LAN Manager dialect selected in SMB_COM_NEGOTIATE but parameters bytes count (%d) does not meet specs' % data_len,
+                                    message.raw_data, message)
+            else:
+                _, self.security_mode, self.max_mpx_count, self.max_number_vcs, self.max_buffer_size, \
+                self.max_raw_size, self.session_key, self.capabilities, self.system_time, self.server_time_zone, \
+                self.challenge_length = struct.unpack(self.PAYLOAD_STRUCT_FORMAT, message.parameters_data[:self.PAYLOAD_STRUCT_SIZE])
+        elif self.dialect_index == 0xFFFF:
+            raise ProtocolError('Server does not support any of the pysmb dialects. Please email pysmb to add in support for your OS',
+                                message.raw_data, message)
+        else:
+            raise ProtocolError('Unknown dialect index (0x%04X)' % self.dialect_index, message.raw_data, message)
+
+        data_len = len(message.data)
+        if not message.hasExtendedSecurity:
+            self.challenge, self.domain = '', ''
+            if self.challenge_length > 0:
+                if data_len >= self.challenge_length:
+                    self.challenge = message.data[:self.challenge_length]
+
+                    s = b''
+                    offset = self.challenge_length
+                    while offset < data_len:
+                        _s = message.data[offset:offset+2]
+                        if _s == b'\0\0':
+                            self.domain = s.decode('UTF-16LE')
+                            break
+                        else:
+                            s += _s
+                            offset += 2
+                else:
+                    raise ProtocolError('Not enough data to decode SMB_COM_NEGOTIATE (without security extensions) Challenge field', message.raw_data, message)
+        else:
+            if data_len < 16:
+                raise ProtocolError('Not enough data to decode SMB_COM_NEGOTIATE (with security extensions) ServerGUID field', message.raw_data, message)
+
+            self.server_guid = message.data[:16]
+            self.security_blob = message.data[16:]
+
+    @property
+    def supportsExtendedSecurity(self):
+        return bool(self.capabilities & CAP_EXTENDED_SECURITY)
+
+
+class ComSessionSetupAndxRequest__WithSecurityExtension(Payload):
+    """
+    References:
+    ===========
+    - [MS-SMB]: 2.2.4.6.1
+    """
+
+    PAYLOAD_STRUCT_FORMAT = '<HHHIHII'
+
+    def __init__(self, session_key, security_blob):
+        self.session_key = session_key
+        self.security_blob = security_blob
+
+    def initMessage(self, message):
+        Payload.initMessage(self, message)
+        message.command = SMB_COM_SESSION_SETUP_ANDX
+
+    def prepare(self, message):
+        assert message.hasExtendedSecurity
+
+        message.flags2 |= SMB_FLAGS2_UNICODE
+
+        cap = CAP_UNICODE | CAP_STATUS32 | CAP_EXTENDED_SECURITY | CAP_NT_SMBS
+
+        message.parameters_data = \
+            self.DEFAULT_ANDX_PARAM_HEADER + \
+            struct.pack(self.PAYLOAD_STRUCT_FORMAT,
+                        16644, 10, 1, self.session_key, len(self.security_blob), 0, cap)
+
+        message.data = self.security_blob
+        if (SMBMessage.HEADER_STRUCT_SIZE + len(message.parameters_data) + len(message.data)) % 2 != 0:
+            message.data = message.data + b'\0'
+        message.data = message.data + b'\0' * 4
+
+
+class ComSessionSetupAndxRequest__NoSecurityExtension(Payload):
+    """
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.53.1
+    """
+
+    PAYLOAD_STRUCT_FORMAT = '<HHHIHHII'
+
+    def __init__(self, session_key, username, password, is_unicode, domain):
+        self.username = username
+        self.session_key = session_key
+        self.password = password
+        self.is_unicode = is_unicode
+        self.domain = domain
+
+    def initMessage(self, message):
+        Payload.initMessage(self, message)
+        message.command = SMB_COM_SESSION_SETUP_ANDX
+
+    def prepare(self, message):
+        if self.is_unicode:
+            message.flags2 |= SMB_FLAGS2_UNICODE
+        else:
+            message.flags2 &= (~SMB_FLAGS2_UNICODE & 0xFFFF)
+
+        password_len = len(self.password)
+        message.parameters_data = \
+            self.DEFAULT_ANDX_PARAM_HEADER + \
+            struct.pack(self.PAYLOAD_STRUCT_FORMAT,
+                        16644, 10, 0, self.session_key,
+                        (not self.is_unicode and password_len) or 0,
+                        (self.is_unicode and password_len) or 0,
+                        0,
+                        CAP_UNICODE | CAP_LARGE_FILES | CAP_STATUS32)
+
+        est_offset = SMBMessage.HEADER_STRUCT_SIZE + len(message.parameters_data)  # To check if data until SMB paramaters are aligned to a 16-bit boundary
+
+        message.data = self.password
+        if (est_offset + len(message.data)) % 2 != 0 and message.flags2 & SMB_FLAGS2_UNICODE:
+            message.data = message.data + b'\0'
+
+        if message.flags2 & SMB_FLAGS2_UNICODE:
+            message.data = message.data + self.username.encode('UTF-16LE') + b'\0'
+        else:
+            message.data = message.data + str(self.username).encode('UTF-8') + b'\0'
+
+        if (est_offset + len(message.data)) % 2 != 0 and message.flags2 & SMB_FLAGS2_UNICODE:
+            message.data = message.data + b'\0'
+
+        if message.flags2 & SMB_FLAGS2_UNICODE:
+            message.data = message.data + self.domain.encode('UTF-16LE') + b'\0\0' + 'pysmb'.encode('UTF-16LE') + b'\0\0'
+        else:
+            message.data = message.data + self.domain.encode('UTF-8') + b'\0pysmb\0'
+
+
+class ComSessionSetupAndxResponse(Payload):
+    """
+    Contains information on the SMB_COM_SESSION_SETUP_ANDX response from server
+
+    If the underlying SMB message's flags2 does not have SMB_FLAGS2_EXTENDED_SECURITY bit enabled,
+    then the instance will have the following attributes,
+    - action
+
+    If the underlying SMB message's flags2 has SMB_FLAGS2_EXTENDED_SECURITY bit enabled
+    and the message status is STATUS_MORE_PROCESSING_REQUIRED or equals to 0x00 (no error),
+    then the instance will have the following attributes,
+    - action
+    - securityblob
+
+    If the underlying SMB message's flags2 has SMB_FLAGS2_EXTENDED_SECURITY bit enabled but
+    the message status is not STATUS_MORE_PROCESSING_REQUIRED
+
+    References:
+    ===========
+    - [MS-SMB]: 2.2.4.6.2
+    - [MS-CIFS]: 2.2.4.53.2
+    """
+
+    NOSECURE_PARAMETER_STRUCT_FORMAT = '<BBHH'
+    NOSECURE_PARAMETER_STRUCT_SIZE = struct.calcsize(NOSECURE_PARAMETER_STRUCT_FORMAT)
+
+    SECURE_PARAMETER_STRUCT_FORMAT = '<BBHHH'
+    SECURE_PARAMETER_STRUCT_SIZE = struct.calcsize(SECURE_PARAMETER_STRUCT_FORMAT)
+
+    def decode(self, message):
+        assert message.command == SMB_COM_SESSION_SETUP_ANDX
+        if not message.hasExtendedSecurity:
+            if not message.status.hasError:
+                if len(message.parameters_data) < self.NOSECURE_PARAMETER_STRUCT_SIZE:
+                    raise ProtocolError('Not enough data to decode SMB_COM_SESSION_SETUP_ANDX (no security extensions) parameters', message.raw_data, message)
+
+                _, _, _, self.action = struct.unpack(self.NOSECURE_PARAMETER_STRUCT_FORMAT, message.parameters_data[:self.NOSECURE_PARAMETER_STRUCT_SIZE])
+        else:
+            if not message.status.hasError or message.status.internal_value == 0xc0000016:   # STATUS_MORE_PROCESSING_REQUIRED
+                if len(message.parameters_data) < self.SECURE_PARAMETER_STRUCT_SIZE:
+                    raise ProtocolError('Not enough data to decode SMB_COM_SESSION_SETUP_ANDX (with security extensions) parameters', message.raw_data, message)
+
+                _, _, _, self.action, blob_length = struct.unpack(self.SECURE_PARAMETER_STRUCT_FORMAT, message.parameters_data[:self.SECURE_PARAMETER_STRUCT_SIZE])
+                if len(message.data) < blob_length:
+                    raise ProtocolError('Not enough data to decode SMB_COM_SESSION_SETUP_ANDX (with security extensions) security blob', message.raw_data, message)
+
+                self.security_blob = message.data[:blob_length]
+
+
+class ComTreeConnectAndxRequest(Payload):
+    """
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.55.1
+    - [MS-SMB]: 2.2.4.7.1
+    """
+
+    PAYLOAD_STRUCT_FORMAT = '<HH'
+    PAYLOAD_STRUCT_SIZE = struct.calcsize(PAYLOAD_STRUCT_FORMAT)
+
+    def __init__(self, path, service, password = ''):
+        self.path = path
+        self.service = service
+        self.password = password + '\0'
+
+    def initMessage(self, message):
+        Payload.initMessage(self, message)
+        message.command = SMB_COM_TREE_CONNECT_ANDX
+
+    def prepare(self, message):
+        password_len = len(self.password)
+        message.parameters_data = \
+            self.DEFAULT_ANDX_PARAM_HEADER + \
+            struct.pack(self.PAYLOAD_STRUCT_FORMAT,
+                        0x08 | \
+                            ((message.hasExtendedSecurity and 0x0004) or 0x00) | \
+                            ((message.tid and message.tid != 0xffff and 0x0001) or 0x00),  # Disconnect tid, if message.tid must be non-zero
+                        password_len)
+
+        padding = b''
+        if password_len % 2 == 0:
+            padding = b'\0'
+
+        # Note that service field is never encoded in UTF-16LE. [MS-CIFS]: 2.2.1.1
+        message.data = self.password.encode('UTF-8') + padding + self.path.encode('UTF-16LE') + b'\0\0' + self.service.encode('UTF-8') + b'\0'
+
+
+class ComTreeConnectAndxResponse(Payload):
+    """
+    Contains information about the SMB_COM_TREE_CONNECT_ANDX response from the server.
+
+    If the message has no errors, each instance contains the following attributes:
+    - optional_support
+
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.55.2
+    """
+
+    PAYLOAD_STRUCT_FORMAT = '<BBHH'
+    PAYLOAD_STRUCT_SIZE = struct.calcsize(PAYLOAD_STRUCT_FORMAT)
+
+    def decode(self, message):
+        assert message.command == SMB_COM_TREE_CONNECT_ANDX
+
+        if not message.status.hasError:
+            if len(message.parameters_data) < self.PAYLOAD_STRUCT_SIZE:
+                raise ProtocolError('Not enough data to decode SMB_COM_TREE_CONNECT_ANDX parameters', message.raw_data, message)
+
+            _, _, _, self.optional_support = struct.unpack(self.PAYLOAD_STRUCT_FORMAT, message.parameters_data[:self.PAYLOAD_STRUCT_SIZE])
+
+
+class ComNTCreateAndxRequest(Payload):
+    """
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.64.1
+    - [MS-SMB]: 2.2.4.9.1
+    """
+
+    PAYLOAD_STRUCT_FORMAT = '<BHIIIQIIIIIB'
+    PAYLOAD_STRUCT_SIZE = struct.calcsize(PAYLOAD_STRUCT_FORMAT)
+
+    def __init__(self, filename, flags = 0, root_fid = 0, access_mask = 0, allocation_size = 0, ext_attr = 0,
+                 share_access = 0, create_disp = 0, create_options = 0, impersonation = 0, security_flags = 0):
+        self.filename = (filename + '\0').encode('UTF-16LE')
+        self.flags = flags
+        self.root_fid = root_fid
+        self.access_mask = access_mask
+        self.allocation_size = allocation_size
+        self.ext_attr = ext_attr
+        self.share_access = share_access
+        self.create_disp = create_disp
+        self.create_options = create_options
+        self.impersonation = impersonation
+        self.security_flags = security_flags
+
+    def initMessage(self, message):
+        Payload.initMessage(self, message)
+        message.command = SMB_COM_NT_CREATE_ANDX
+
+    def prepare(self, message):
+        filename_len = len(self.filename)
+
+        message.parameters_data = \
+            self.DEFAULT_ANDX_PARAM_HEADER + \
+            struct.pack(self.PAYLOAD_STRUCT_FORMAT,
+                        0x00,                  # reserved
+                        filename_len,          # NameLength
+                        self.flags,            # Flags
+                        self.root_fid,         # RootDirectoryFID
+                        self.access_mask,      # DesiredAccess
+                        self.allocation_size,  # AllocationSize
+                        self.ext_attr,         # ExtFileAttributes
+                        self.share_access,     # ShareAccess
+                        self.create_disp,      # CreateDisposition
+                        self.create_options,   # CreateOptions
+                        self.impersonation,    # ImpersonationLevel
+                        self.security_flags)   # SecurityFlags
+
+        padding = b''
+        if (message.HEADER_STRUCT_SIZE + len(message.parameters_data)) % 2 != 0:
+            padding = b'\0'
+
+        message.data = padding + self.filename
+
+
+class ComNTCreateAndxResponse(Payload):
+    """
+    Contains (partial) information about the SMB_COM_NT_CREATE_ANDX response from the server.
+
+    Each instance contains the following attributes after decoding:
+    - oplock_level
+    - fid
+
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.64.2
+    """
+    PAYLOAD_STRUCT_FORMAT = '<BBHBH'
+    PAYLOAD_STRUCT_SIZE = struct.calcsize(PAYLOAD_STRUCT_FORMAT)
+
+    def decode(self, message):
+        assert message.command == SMB_COM_NT_CREATE_ANDX
+
+        if not message.status.hasError:
+            if len(message.parameters_data) < self.PAYLOAD_STRUCT_SIZE:
+                raise ProtocolError('Not enough data to decode SMB_COM_NT_CREATE_ANDX parameters', message.raw_data, message)
+
+            _, _, _, self.oplock_level, self.fid = struct.unpack(self.PAYLOAD_STRUCT_FORMAT, message.parameters_data[:self.PAYLOAD_STRUCT_SIZE])
+
+
+class ComTransactionRequest(Payload):
+    """
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.33.1
+    """
+
+    PAYLOAD_STRUCT_FORMAT = '<HHHHBBHIHHHHHH'
+    PAYLOAD_STRUCT_SIZE = struct.calcsize(PAYLOAD_STRUCT_FORMAT)
+
+    def __init__(self, max_params_count, max_data_count, max_setup_count,
+                 total_params_count = 0, total_data_count = 0,
+                 params_bytes = b'', data_bytes = b'', setup_bytes = b'',
+                 flags = 0, timeout = 0, name = "\\PIPE\\"):
+        self.total_params_count = total_params_count or len(params_bytes)
+        self.total_data_count = total_data_count or len(data_bytes)
+        self.max_params_count = max_params_count
+        self.max_data_count = max_data_count
+        self.max_setup_count = max_setup_count
+        self.flags = flags
+        self.timeout = timeout
+        self.params_bytes = params_bytes
+        self.data_bytes = data_bytes
+        self.setup_bytes = setup_bytes
+        self.name = name
+
+    def initMessage(self, message):
+        Payload.initMessage(self, message)
+        message.command = SMB_COM_TRANSACTION
+
+    def prepare(self, message):
+        name = (self.name + '\0').encode('UTF-16LE')
+        name_len = len(name)
+        setup_bytes_len = len(self.setup_bytes)
+        params_bytes_len = len(self.params_bytes)
+        data_bytes_len = len(self.data_bytes)
+
+        padding0 = b''
+        offset = message.HEADER_STRUCT_SIZE + self.PAYLOAD_STRUCT_SIZE + setup_bytes_len + 2 # constant 2 is for the ByteCount field in the SMB header (i.e. field which indicates number of data bytes after the SMB parameters)
+        if offset % 2 != 0:
+            padding0 = b'\0'
+            offset += 1
+
+        offset += name_len  # For the name field
+        padding1 = b''
+        if offset % 4 != 0:
+            padding1 = b'\0'*(4-offset%4)
+            offset += (4-offset%4)
+
+        if params_bytes_len > 0:
+            params_bytes_offset = offset
+            offset += params_bytes_len
+        else:
+            params_bytes_offset = 0
+
+        padding2 = b''
+        if offset % 4 != 0:
+            padding2 = b'\0'*(4-offset%4)
+            offset += (4-offset%4)
+
+        if data_bytes_len > 0:
+            data_bytes_offset = offset
+        else:
+            data_bytes_offset = 0
+
+        message.parameters_data = \
+            struct.pack(self.PAYLOAD_STRUCT_FORMAT,
+                        self.total_params_count,
+                        self.total_data_count,
+                        self.max_params_count,
+                        self.max_data_count,
+                        self.max_setup_count,
+                        0x00,           # Reserved1. Must be 0x00
+                        self.flags,
+                        self.timeout,
+                        0x0000,         # Reserved2. Must be 0x0000
+                        params_bytes_len,
+                        params_bytes_offset,
+                        data_bytes_len,
+                        data_bytes_offset,
+                        int(setup_bytes_len / 2)) + \
+            self.setup_bytes
+
+        message.data = padding0 + name + padding1 + self.params_bytes + padding2 + self.data_bytes
+
+
+class ComTransactionResponse(Payload):
+    """
+    Contains information about a SMB_COM_TRANSACTION response from the server
+
+    After decoding, each instance contains the following attributes:
+    - total_params_count (integer)
+    - total_data_count (integer)
+    - setup_bytes (string)
+    - data_bytes (string)
+    - params_bytes (string)
+
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.33.2
+    """
+
+    PAYLOAD_STRUCT_FORMAT = '<HHHHHHHHHH'
+    PAYLOAD_STRUCT_SIZE = struct.calcsize(PAYLOAD_STRUCT_FORMAT)
+
+    def decode(self, message):
+        assert message.command == SMB_COM_TRANSACTION
+
+        if not message.status.hasError:
+            if len(message.parameters_data) < self.PAYLOAD_STRUCT_SIZE:
+                raise ProtocolError('Not enough data to decode SMB_COM_TRANSACTION parameters', message.raw_data, message)
+
+            self.total_params_count, self.total_data_count, _, \
+            params_bytes_len, params_bytes_offset, params_bytes_displ, \
+            data_bytes_len, data_bytes_offset, data_bytes_displ, \
+            setup_count = struct.unpack(self.PAYLOAD_STRUCT_FORMAT, message.parameters_data[:self.PAYLOAD_STRUCT_SIZE])
+
+            if setup_count > 0:
+                setup_bytes_len = setup_count * 2
+
+                if len(message.parameters_data) < self.PAYLOAD_STRUCT_SIZE + setup_bytes_len:
+                    raise ProtocolError('Not enough data to decode SMB_COM_TRANSACTION parameters', message.raw_data, message)
+
+                self.setup_bytes = message.parameters_data[self.PAYLOAD_STRUCT_SIZE:self.PAYLOAD_STRUCT_SIZE+setup_bytes_len]
+            else:
+                self.setup_bytes = ''
+
+            offset = message.HEADER_STRUCT_SIZE + self.PAYLOAD_STRUCT_SIZE + setup_count * 2 + 2 # constant 2 is for the ByteCount field in the SMB header (i.e. field which indicates number of data bytes after the SMB parameters)
+
+            if params_bytes_len > 0:
+                self.params_bytes = message.data[params_bytes_offset-offset:params_bytes_offset-offset+params_bytes_len]
+            else:
+                self.params_bytes = ''
+
+            if data_bytes_len > 0:
+                self.data_bytes = message.data[data_bytes_offset-offset:data_bytes_offset-offset+data_bytes_len]
+            else:
+                self.data_bytes = ''
+
+
+class ComTransaction2Request(Payload):
+    """
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.46.1
+    """
+
+    PAYLOAD_STRUCT_FORMAT = 'HHHHBBHIHHHHHH'
+    PAYLOAD_STRUCT_SIZE = struct.calcsize(PAYLOAD_STRUCT_FORMAT)
+
+    def __init__(self, max_params_count, max_data_count, max_setup_count,
+                 total_params_count = 0, total_data_count = 0,
+                 params_bytes = b'', data_bytes = b'', setup_bytes = b'',
+                 flags = 0, timeout = 0):
+        self.total_params_count = total_params_count or len(params_bytes)
+        self.total_data_count = total_data_count or len(data_bytes)
+        self.max_params_count = max_params_count
+        self.max_data_count = max_data_count
+        self.max_setup_count = max_setup_count
+        self.flags = flags
+        self.timeout = timeout
+        self.params_bytes = params_bytes
+        self.data_bytes = data_bytes
+        self.setup_bytes = setup_bytes
+
+    def initMessage(self, message):
+        Payload.initMessage(self, message)
+        message.command = SMB_COM_TRANSACTION2
+
+    def prepare(self, message):
+        setup_bytes_len = len(self.setup_bytes)
+        params_bytes_len = len(self.params_bytes)
+        data_bytes_len = len(self.data_bytes)
+        name = b'\0\0'
+
+        padding0 = b''
+        offset = message.HEADER_STRUCT_SIZE + self.PAYLOAD_STRUCT_SIZE + setup_bytes_len + 2 # constant 2 is for the ByteCount field in the SMB header (i.e. field which indicates number of data bytes after the SMB parameters)
+        if offset % 2 != 0:
+            padding0 = b'\0'
+            offset += 1
+
+        offset += 2  # For the name field
+        padding1 = b''
+        if offset % 4 != 0:
+            padding1 = b'\0'*(4-offset%4)
+
+        if params_bytes_len > 0:
+            params_bytes_offset = offset
+            offset += params_bytes_len
+        else:
+            params_bytes_offset = 0
+
+        padding2 = b''
+        if offset % 4 != 0:
+            padding2 = b'\0'*(4-offset%4)
+
+        if data_bytes_len > 0:
+            data_bytes_offset = offset
+        else:
+            data_bytes_offset = 0
+
+        message.parameters_data = \
+            struct.pack(self.PAYLOAD_STRUCT_FORMAT,
+                        self.total_params_count,
+                        self.total_data_count,
+                        self.max_params_count,
+                        self.max_data_count,
+                        self.max_setup_count,
+                        0x00,           # Reserved1. Must be 0x00
+                        self.flags,
+                        self.timeout,
+                        0x0000,         # Reserved2. Must be 0x0000
+                        params_bytes_len,
+                        params_bytes_offset,
+                        data_bytes_len,
+                        data_bytes_offset,
+                        int(setup_bytes_len / 2)) + \
+            self.setup_bytes
+
+        message.data = padding0 + name + padding1 + self.params_bytes + padding2 + self.data_bytes
+
+
+class ComTransaction2Response(Payload):
+    """
+    Contains information about a SMB_COM_TRANSACTION2 response from the server
+
+    After decoding, each instance contains the following attributes:
+    - total_params_count (integer)
+    - total_data_count (integer)
+    - setup_bytes (string)
+    - data_bytes (string)
+    - params_bytes (string)
+
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.46.2
+    """
+
+    PAYLOAD_STRUCT_FORMAT = '<HHHHHHHHHBB'
+    PAYLOAD_STRUCT_SIZE = struct.calcsize(PAYLOAD_STRUCT_FORMAT)
+
+    def decode(self, message):
+        assert message.command == SMB_COM_TRANSACTION2
+
+        if not message.status.hasError:
+            if len(message.parameters_data) < self.PAYLOAD_STRUCT_SIZE:
+                raise ProtocolError('Not enough data to decode SMB_COM_TRANSACTION2 parameters', message.raw_data, message)
+
+            self.total_params_count, self.total_data_count, _, \
+            params_bytes_len, params_bytes_offset, params_bytes_displ, \
+            data_bytes_len, data_bytes_offset, data_bytes_displ, \
+            setup_count, _ = struct.unpack(self.PAYLOAD_STRUCT_FORMAT, message.parameters_data[:self.PAYLOAD_STRUCT_SIZE])
+
+            if setup_count > 0:
+                setup_bytes_len = setup_count * 2
+
+                if len(message.parameters_data) < self.PAYLOAD_STRUCT_SIZE + setup_bytes_len:
+                    raise ProtocolError('Not enough data to decode SMB_COM_TRANSACTION parameters', message.raw_data, message)
+
+                self.setup_bytes = message.parameters_data[self.PAYLOAD_STRUCT_SIZE:self.PAYLOAD_STRUCT_SIZE+setup_bytes_len]
+            else:
+                self.setup_bytes = ''
+
+            offset = message.HEADER_STRUCT_SIZE + self.PAYLOAD_STRUCT_SIZE + setup_count * 2 + 2 # constant 2 is for the ByteCount field in the SMB header (i.e. field which indicates number of data bytes after the SMB parameters)
+
+            if params_bytes_len > 0:
+                self.params_bytes = message.data[params_bytes_offset-offset:params_bytes_offset-offset+params_bytes_len]
+            else:
+                self.params_bytes = ''
+
+            if data_bytes_len > 0:
+                self.data_bytes = message.data[data_bytes_offset-offset:data_bytes_offset-offset+data_bytes_len]
+            else:
+                self.data_bytes = ''
+
+
+class ComCloseRequest(Payload):
+    """
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.5.1
+    """
+
+    PAYLOAD_STRUCT_FORMAT = '<HI'
+    PAYLOAD_STRUCT_SIZE = struct.calcsize(PAYLOAD_STRUCT_FORMAT)
+
+    def __init__(self, fid, last_modified_time = 0xFFFFFFFF):
+        self.fid = fid
+        self.last_modified_time = last_modified_time
+
+    def initMessage(self, message):
+        Payload.initMessage(self, message)
+        message.command = SMB_COM_CLOSE
+
+    def prepare(self, message):
+        message.parameters_data = struct.pack(self.PAYLOAD_STRUCT_FORMAT, self.fid, self.last_modified_time)
+        message.data = b''
+
+
+class ComOpenAndxRequest(Payload):
+    """
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.41.1
+    """
+
+    PAYLOAD_STRUCT_FORMAT = '<HHHHIHIII'
+    PAYLOAD_STRUCT_SIZE = struct.calcsize(PAYLOAD_STRUCT_FORMAT)
+
+    def __init__(self, filename, access_mode, open_mode, flags = 0x0000, search_attributes = 0, file_attributes = 0, create_time = 0, timeout = 0):
+        """
+        @param create_time: Epoch time value to indicate the time of creation for this file. If zero, we will automatically assign the current time
+        @type create_time: int
+        @param timeout: Number of milliseconds to wait for blocked open request before failing
+        @type timeout: int
+        """
+        self.filename = filename
+        self.access_mode = access_mode
+        self.open_mode = open_mode
+        self.flags = flags
+        self.search_attributes = search_attributes
+        self.file_attributes = file_attributes
+        self.create_time = create_time or int(time.time())
+        self.timeout = timeout
+
+    def initMessage(self, message):
+        Payload.initMessage(self, message)
+        message.command = SMB_COM_OPEN_ANDX
+
+    def prepare(self, message):
+        message.parameters_data = \
+            self.DEFAULT_ANDX_PARAM_HEADER + \
+            struct.pack(self.PAYLOAD_STRUCT_FORMAT,
+                        self.flags,
+                        self.access_mode,
+                        self.search_attributes,
+                        self.file_attributes,
+                        self.create_time,
+                        self.open_mode,
+                        0,  # AllocationSize
+                        0,  # Timeout (in milli-secs)
+                        0)  # Reserved
+
+        message.data = b'\0' + self.filename.encode('UTF-16LE') + b'\0\0'
+
+
+class ComOpenAndxResponse(Payload):
+    """
+    Contains information about a SMB_COM_OPEN_ANDX response from the server
+
+    After decoding, each instance will contain the following attributes:
+    - fid (integer)
+    - file_attributes (integer)
+    - last_write_time (long)
+    - access_rights (integer)
+    - resource_type (integer)
+    - open_results (integer)
+
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.41.2
+    - [MS-SMB]: 2.2.4.1.2
+    """
+
+    PAYLOAD_STRUCT_FORMAT = '<BBHHHIIHHHHHHH'
+    PAYLOAD_STRUCT_SIZE = struct.calcsize(PAYLOAD_STRUCT_FORMAT)
+
+    def decode(self, message):
+        assert message.command == SMB_COM_OPEN_ANDX
+
+        if not message.status.hasError:
+            if len(message.parameters_data) < self.PAYLOAD_STRUCT_SIZE:
+                raise ProtocolError('Not enough data to decode SMB_COM_OPEN_ANDX parameters', message.raw_data, message)
+
+            _, _, _, self.fid, self.file_attributes, self.last_write_time, _, \
+            self.access_rights, self.resource_type, _, self.open_results, _, _, _ = struct.unpack(self.PAYLOAD_STRUCT_FORMAT,
+                                                                                                  message.parameters_data[:self.PAYLOAD_STRUCT_SIZE])
+
+
+class ComWriteAndxRequest(Payload):
+    """
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.43.1
+    - [MS-SMB]: 2.2.4.3.1
+    """
+
+    PAYLOAD_STRUCT_FORMAT = '<HIIHHHHHI'
+    PAYLOAD_STRUCT_SIZE = struct.calcsize(PAYLOAD_STRUCT_FORMAT)
+
+    def __init__(self, fid, data_bytes, offset, write_mode = 0, timeout = 0):
+        """
+        @param timeout: Number of milliseconds to wait for blocked write request before failing. Must be zero for writing to regular file
+        @type timeout: int
+        """
+        self.fid = fid
+        self.offset = offset
+        self.data_bytes = data_bytes
+        self.timeout = timeout
+        self.write_mode = write_mode
+
+    def initMessage(self, message):
+        Payload.initMessage(self, message)
+        message.command = SMB_COM_WRITE_ANDX
+
+    def prepare(self, message):
+        # constant 1 is to account for the pad byte in the message.data
+        # constant 2 is for the ByteCount field in the SMB header (i.e. field which indicates number of data bytes after the SMB parameters)
+        data_offset = message.HEADER_STRUCT_SIZE + self.DEFAULT_ANDX_PARAM_SIZE + self.PAYLOAD_STRUCT_SIZE + 1 + 2
+        data_len = len(self.data_bytes)
+
+        message.parameters_data = \
+            self.DEFAULT_ANDX_PARAM_HEADER + \
+            struct.pack(self.PAYLOAD_STRUCT_FORMAT,
+                        self.fid,
+                        self.offset & 0xFFFFFFFF,
+                        self.timeout,
+                        self.write_mode,
+                        data_len,   # Remaining
+                        0x0000,     # Reserved
+                        len(self.data_bytes),  # DataLength
+                        data_offset,           # DataOffset
+                        self.offset >> 32)     # OffsetHigh field defined in [MS-SMB]: 2.2.4.3.1
+
+        message.data = b'\0' + self.data_bytes
+
+
+class ComWriteAndxResponse(Payload):
+    """
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.43.2
+    - [MS-SMB]: 2.2.4.3.2
+    """
+
+    PAYLOAD_STRUCT_FORMAT = '<BBHHHHH'  # We follow the SMB_COM_WRITEX_ANDX server extensions in [MS-SMB]: 2.2.4.3.2
+    PAYLOAD_STRUCT_SIZE = struct.calcsize(PAYLOAD_STRUCT_FORMAT)
+
+    def decode(self, message):
+        assert message.command == SMB_COM_WRITE_ANDX
+
+        if not message.status.hasError:
+            if len(message.parameters_data) < self.PAYLOAD_STRUCT_SIZE:
+                raise ProtocolError('Not enough data to decode SMB_COM_WRITE_ANDX parameters', message.raw_data, message)
+
+            _, _, _, count, self.available, high_count, _ = struct.unpack(self.PAYLOAD_STRUCT_FORMAT, message.parameters_data[:self.PAYLOAD_STRUCT_SIZE])
+            self.count = (count & 0xFFFF) | (high_count << 16)
+
+
+class ComReadAndxRequest(Payload):
+    """
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.42.1
+    - [MS-SMB]: 2.2.4.2.1
+    """
+
+    PAYLOAD_STRUCT_FORMAT = '<HIHHIHI'
+    PAYLOAD_STRUCT_SIZE = struct.calcsize(PAYLOAD_STRUCT_FORMAT)
+
+    def __init__(self, fid, offset, max_return_bytes_count, min_return_bytes_count, timeout = 0, remaining = 0):
+        """
+        @param timeout: If reading from a regular file, this parameter must be 0.
+        @type timeout: int
+        """
+        self.fid = fid
+        self.remaining = remaining
+        self.max_return_bytes_count = max_return_bytes_count
+        self.min_return_bytes_count = min_return_bytes_count
+        self.offset = offset
+        self.timeout = timeout
+
+    def initMessage(self, message):
+        Payload.initMessage(self, message)
+        message.command = SMB_COM_READ_ANDX
+
+    def prepare(self, message):
+        message.parameters_data = \
+            self.DEFAULT_ANDX_PARAM_HEADER + \
+            struct.pack(self.PAYLOAD_STRUCT_FORMAT,
+                        self.fid,
+                        self.offset & 0xFFFFFFFF,
+                        self.max_return_bytes_count,
+                        self.min_return_bytes_count,
+                        self.timeout or (self.max_return_bytes_count >> 32),  # Note that in [MS-SMB]: 2.2.4.2.1, this field can also act as MaxCountHigh field
+                        self.remaining, # In [MS-CIFS]: 2.2.4.42.1, this field must be set to 0x0000
+                        self.offset >> 32)
+
+        message.data = b''
+
+
+class ComReadAndxResponse(Payload):
+    """
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.42.2
+    - [MS-SMB]: 2.2.4.2.2
+    """
+
+    PAYLOAD_STRUCT_FORMAT = '<BBHHHHHHHHHHH'
+    PAYLOAD_STRUCT_SIZE = struct.calcsize(PAYLOAD_STRUCT_FORMAT)
+
+    def decode(self, message):
+        assert message.command == SMB_COM_READ_ANDX
+
+        if not message.status.hasError:
+            if len(message.parameters_data) < self.PAYLOAD_STRUCT_SIZE:
+                raise ProtocolError('Not enough data to decode SMB_COM_READ_ANDX parameters', message.raw_data, message)
+
+            _, _, _, _, _, _, self.data_length, data_offset, _, _, _, _, _ = struct.unpack(self.PAYLOAD_STRUCT_FORMAT,
+                                                                                           message.parameters_data[:self.PAYLOAD_STRUCT_SIZE])
+
+            offset = data_offset - message.HEADER_STRUCT_SIZE - self.PAYLOAD_STRUCT_SIZE - 2  # constant 2 is for the ByteCount field in the SMB header (i.e. field which indicates number of data bytes after the SMB parameters)
+            self.data = message.data[offset:offset+self.data_length]
+            assert len(self.data) == self.data_length
+
+
+class ComDeleteRequest(Payload):
+    """
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.7.1
+    """
+
+    def __init__(self, filename_pattern, search_attributes = 0):
+        self.filename_pattern = filename_pattern
+        self.search_attributes = search_attributes
+
+    def initMessage(self, message):
+        Payload.initMessage(self, message)
+        message.command = SMB_COM_DELETE
+
+    def prepare(self, message):
+        message.parameters_data = struct.pack('<H', self.search_attributes)
+        message.data = b'\x04' + self.filename_pattern.encode('UTF-16LE') + b'\0\0'
+
+
+class ComCreateDirectoryRequest(Payload):
+    """
+    Although this command has been marked deprecated in [MS-CIFS], we continue to use it for its simplicity
+    as compared to its replacement TRANS2_CREATE_DIRECTORY sub-command [MS-CIFS]: 2.2.6.14
+
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.1.1
+    """
+
+    def __init__(self, path):
+        self.path = path
+
+    def initMessage(self, message):
+        Payload.initMessage(self, message)
+        message.command = SMB_COM_CREATE_DIRECTORY
+
+    def prepare(self, message):
+        message.parameters_data = b''
+        message.data = b'\x04' + self.path.encode('UTF-16LE') + b'\0\0'
+
+
+class ComDeleteDirectoryRequest(Payload):
+    """
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.2.1
+    """
+
+    def __init__(self, path):
+        self.path = path
+
+    def initMessage(self, message):
+        Payload.initMessage(self, message)
+        message.command = SMB_COM_DELETE_DIRECTORY
+
+    def prepare(self, message):
+        message.parameters_data = b''
+        message.data = b'\x04' + self.path.encode('UTF-16LE') + b'\0\0'
+
+
+class ComRenameRequest(Payload):
+    """
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.8.1
+    """
+
+    def __init__(self, old_path, new_path, search_attributes = 0):
+        self.old_path = old_path
+        self.new_path = new_path
+        self.search_attributes = search_attributes
+
+    def initMessage(self, message):
+        Payload.initMessage(self, message)
+        message.command = SMB_COM_RENAME
+
+    def prepare(self, message):
+        message.parameters_data = struct.pack('<H', self.search_attributes)
+        message.data = b'\x04' + self.old_path.encode('UTF-16LE') + b'\x00\x00\x04\x00' + self.new_path.encode('UTF-16LE') + b'\x00\x00'
+
+
+class ComEchoRequest(Payload):
+    """
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.39.1
+    """
+
+    def __init__(self, echo_data = b'', echo_count = 1):
+        self.echo_count = echo_count
+        self.echo_data = echo_data
+
+    def initMessage(self, message):
+        Payload.initMessage(self, message)
+        message.command = SMB_COM_ECHO
+        message.tid = 0xFFFF
+
+    def prepare(self, message):
+        message.parameters_data = struct.pack('<H', self.echo_count)
+        message.data = self.echo_data
+
+
+class ComEchoResponse(Payload):
+    """
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.39.2
+    """
+
+    def decode(self, message):
+        self.sequence_number = struct.unpack('<H', message.parameters_data[:2])[0]
+        self.data = message.data
+
+
+class ComNTTransactRequest(Payload):
+    """
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.62.1
+    """
+    PAYLOAD_STRUCT_FORMAT = '<BHIIIIIIIIBH'
+    PAYLOAD_STRUCT_SIZE = struct.calcsize(PAYLOAD_STRUCT_FORMAT)
+
+    def __init__(self, function, max_params_count, max_data_count, max_setup_count,
+                 total_params_count = 0, total_data_count = 0,
+                 params_bytes = b'', setup_bytes = b'', data_bytes = b''):
+        self.function = function
+        self.total_params_count = total_params_count or len(params_bytes)
+        self.total_data_count = total_data_count or len(data_bytes)
+        self.max_params_count = max_params_count
+        self.max_data_count = max_data_count
+        self.max_setup_count = max_setup_count
+        self.params_bytes = params_bytes
+        self.setup_bytes = setup_bytes
+        self.data_bytes = data_bytes
+
+    def initMessage(self, message):
+        Payload.initMessage(self, message)
+        message.command = SMB_COM_NT_TRANSACT
+
+    def prepare(self, message):
+        setup_bytes_len = len(self.setup_bytes)
+        params_bytes_len = len(self.params_bytes)
+        data_bytes_len = len(self.data_bytes)
+
+        padding0 = b''
+        offset = message.HEADER_STRUCT_SIZE + self.PAYLOAD_STRUCT_SIZE + setup_bytes_len + 2 # constant 2 is for the ByteCount field in the SMB header (i.e. field which indicates number of data bytes after the SMB parameters)
+        if offset % 4 != 0:
+            padding0 = b'\0'*(4-offset%4)
+            offset += (4-offset%4)
+
+        if params_bytes_len > 0:
+            params_bytes_offset = offset
+        else:
+            params_bytes_offset = 0
+
+        offset += params_bytes_len
+        padding1 = b''
+        if offset % 4 != 0:
+            padding1 = b'\0'*(4-offset%4)
+            offset += (4-offset%4)
+
+        if data_bytes_len > 0:
+            data_bytes_offset = offset
+        else:
+            data_bytes_offset = 0
+
+        message.parameters_data = \
+            struct.pack(self.PAYLOAD_STRUCT_FORMAT,
+                        self.max_setup_count,
+                        0x00,           # Reserved1. Must be 0x00
+                        self.total_params_count,
+                        self.total_data_count,
+                        self.max_params_count,
+                        self.max_data_count,
+                        params_bytes_len,
+                        params_bytes_offset,
+                        data_bytes_len,
+                        data_bytes_offset,
+                        int(setup_bytes_len / 2),
+                        self.function) + \
+            self.setup_bytes
+
+        message.data = padding0 + self.params_bytes + padding1 + self.data_bytes
+
+
+class ComNTTransactResponse(Payload):
+    """
+    Contains information about a SMB_COM_NT_TRANSACT response from the server
+
+    After decoding, each instance contains the following attributes:
+    - total_params_count (integer)
+    - total_data_count (integer)
+    - setup_bytes (string)
+    - data_bytes (string)
+    - params_bytes (string)
+
+    References:
+    ===========
+    - [MS-CIFS]: 2.2.4.62.2
+    """
+    PAYLOAD_STRUCT_FORMAT = '<3sIIIIIIIIBH'
+    PAYLOAD_STRUCT_SIZE = struct.calcsize(PAYLOAD_STRUCT_FORMAT)
+
+    def decode(self, message):
+        assert message.command == SMB_COM_NT_TRANSACT
+
+        if not message.status.hasError:
+            _, self.total_params_count, self.total_data_count, \
+            params_count, params_offset, params_displ, \
+            data_count, data_offset, data_displ, setup_count = struct.unpack(self.PAYLOAD_STRUCT_FORMAT,
+                                                                             message.parameters_data[:self.PAYLOAD_STRUCT_SIZE])
+
+            self.setup_bytes = message.parameters_data[self.PAYLOAD_STRUCT_SIZE:self.PAYLOAD_STRUCT_SIZE+setup_count*2]
+
+            if params_count > 0:
+                params_offset -= message.HEADER_STRUCT_SIZE + self.PAYLOAD_STRUCT_SIZE + setup_count*2 + 2
+                self.params_bytes = message.data[params_offset:params_offset+params_count]
+            else:
+                self.params_bytes = b''
+
+            if data_count > 0:
+                data_offset -= message.HEADER_STRUCT_SIZE + self.PAYLOAD_STRUCT_SIZE + setup_count*2 + 2
+                self.data_bytes = message.data[data_offset:data_offset+data_count]
+            else:
+                self.data_bytes = b''
diff --git a/python3/smb/utils/U32.py b/python3/smb/utils/U32.py
new file mode 100644
index 00000000..f08db2d4
--- /dev/null
+++ b/python3/smb/utils/U32.py
@@ -0,0 +1,148 @@
+#    U32.py implements 32-bit unsigned int class for Python
+#    Version 1.0
+#    Copyright (C) 2001-2002  Dmitry Rozmanov
+#
+#    This library is free software; you can redistribute it and/or
+#    modify it under the terms of the GNU Lesser General Public
+#    License as published by the Free Software Foundation; either
+#    version 2.1 of the License, or (at your option) any later version.
+#
+#    This library is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#    Lesser General Public License for more details.
+#
+#    You should have received a copy of the GNU Lesser General Public
+#    License along with this library; if not, write to the Free Software
+#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#
+#    e-mail: dima@xenon.spb.ru
+#
+#====================================================================
+
+C = 0x1000000000
+
+#--------------------------------------------------------------------
+def norm(n):
+    return n & 0xFFFFFFFF
+
+#====================================================================
+class U32:
+    v = 0
+
+    #--------------------------------------------------------------------
+    def __init__(self, value = 0):
+        self.v = C + norm(abs(int(value)))
+
+    #--------------------------------------------------------------------
+    def set(self, value = 0):
+        self.v = C + norm(abs(int(value)))
+
+    #--------------------------------------------------------------------
+    def __repr__(self):
+        return hex(norm(self.v))
+
+    #--------------------------------------------------------------------
+    def __long__(self): return int(norm(self.v))
+
+    #--------------------------------------------------------------------
+    def __int__(self): return int(norm(self.v))
+
+    #--------------------------------------------------------------------
+    def __chr__(self): return chr(norm(self.v))
+
+    #--------------------------------------------------------------------
+    def __add__(self, b):
+        r = U32()
+        r.v = C + norm(self.v + b.v)
+        return r
+
+    #--------------------------------------------------------------------
+    def __sub__(self, b):
+        r = U32()
+        if self.v < b.v:
+            r.v = C + norm(0x100000000 - (b.v - self.v))
+        else: r.v = C + norm(self.v - b.v)
+        return r
+
+    #--------------------------------------------------------------------
+    def __mul__(self, b):
+        r = U32()
+        r.v = C + norm(self.v * b.v)
+        return r
+
+    #--------------------------------------------------------------------
+    def __div__(self, b):
+        r = U32()
+        r.v = C + (norm(self.v) / norm(b.v))
+        return r
+
+    #--------------------------------------------------------------------
+    def __mod__(self, b):
+        r = U32()
+        r.v = C + (norm(self.v) % norm(b.v))
+        return r
+
+    #--------------------------------------------------------------------
+    def __neg__(self): return U32(self.v)
+
+    #--------------------------------------------------------------------
+    def __pos__(self): return U32(self.v)
+
+    #--------------------------------------------------------------------
+    def __abs__(self): return U32(self.v)
+
+    #--------------------------------------------------------------------
+    def __invert__(self):
+        r = U32()
+        r.v = C + norm(~self.v)
+        return r
+
+    #--------------------------------------------------------------------
+    def __lshift__(self, b):
+        r = U32()
+        r.v = C + norm(self.v << b)
+        return r
+
+    #--------------------------------------------------------------------
+    def __rshift__(self, b):
+        r = U32()
+        r.v = C + (norm(self.v) >> b)
+        return r
+
+    #--------------------------------------------------------------------
+    def __and__(self, b):
+        r = U32()
+        r.v = C + norm(self.v & b.v)
+        return r
+
+    #--------------------------------------------------------------------
+    def __or__(self, b):
+        r = U32()
+        r.v = C + norm(self.v | b.v)
+        return r
+
+    #--------------------------------------------------------------------
+    def __xor__(self, b):
+        r = U32()
+        r.v = C + norm(self.v ^ b.v)
+        return r
+
+    #--------------------------------------------------------------------
+    def __not__(self):
+        return U32(not norm(self.v))
+
+    #--------------------------------------------------------------------
+    def truth(self):
+        return norm(self.v)
+
+    #--------------------------------------------------------------------
+    def __cmp__(self, b):
+        if norm(self.v) > norm(b.v): return 1
+        elif norm(self.v) < norm(b.v): return -1
+        else: return 0
+
+    #--------------------------------------------------------------------
+    def __bool__(self):
+        return norm(self.v)
+        
diff --git a/python3/smb/utils/__init__.py b/python3/smb/utils/__init__.py
new file mode 100644
index 00000000..20aa5355
--- /dev/null
+++ b/python3/smb/utils/__init__.py
@@ -0,0 +1,3 @@
+
+def convertFILETIMEtoEpoch(t):
+    return (t - 116444736000000000) / 10000000.0;
diff --git a/python3/smb/utils/md4.py b/python3/smb/utils/md4.py
new file mode 100644
index 00000000..49489045
--- /dev/null
+++ b/python3/smb/utils/md4.py
@@ -0,0 +1,256 @@
+#    md4.py implements md4 hash class for Python
+#    Version 1.0
+#    Copyright (C) 2001-2002  Dmitry Rozmanov
+#
+#    based on md4.c from "the Python Cryptography Toolkit, version 1.0.0
+#    Copyright (C) 1995, A.M. Kuchling"
+#
+#    This library is free software; you can redistribute it and/or
+#    modify it under the terms of the GNU Lesser General Public
+#    License as published by the Free Software Foundation; either
+#    version 2.1 of the License, or (at your option) any later version.
+#
+#    This library is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#    Lesser General Public License for more details.
+#
+#    You should have received a copy of the GNU Lesser General Public
+#    License along with this library; if not, write to the Free Software
+#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#
+#    e-mail: dima@xenon.spb.ru
+#
+#====================================================================
+
+# MD4 validation data
+
+md4_test= [
+      ('', 0x31d6cfe0d16ae931b73c59d7e0c089c0),
+      ("a",   0xbde52cb31de33e46245e05fbdbd6fb24),
+      ("abc",   0xa448017aaf21d8525fc10ae87aa6729d),
+      ("message digest",   0xd9130a8164549fe818874806e1c7014b),
+      ("abcdefghijklmnopqrstuvwxyz",   0xd79e1c308aa5bbcdeea8ed63df412da9),
+      ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
+       0x043f8582f241db351ce627e153e7f0e4),
+      ("12345678901234567890123456789012345678901234567890123456789012345678901234567890",
+      0xe33b4ddc9c38f2199c3e7b164fcc0536),
+     ]
+
+#====================================================================
+from .U32 import U32
+
+#--------------------------------------------------------------------
+class MD4:
+    A = None
+    B = None
+    C = None
+    D = None
+    count, len1, len2 = None, None, None
+    buf = []
+
+    #-----------------------------------------------------
+    def __init__(self):
+
+
+        self.A = U32(0x67452301)
+        self.B = U32(0xefcdab89)
+        self.C = U32(0x98badcfe)
+        self.D = U32(0x10325476)
+        self.count, self.len1, self.len2 = U32(0), U32(0), U32(0)
+        self.buf = [0x00] * 64
+
+    #-----------------------------------------------------
+    def __repr__(self):
+        r = 'A = %s, \nB = %s, \nC = %s, \nD = %s.\n' % (self.A.__repr__(), self.B.__repr__(), self.C.__repr__(), self.D.__repr__())
+        r = r + 'count = %s, \nlen1 = %s, \nlen2 = %s.\n' % (self.count.__repr__(), self.len1.__repr__(), self.len2.__repr__())
+        for i in range(4):
+            for j in range(16):
+                r = r + '%4s ' % hex(self.buf[i+j])
+            r = r + '\n'
+
+        return r
+    #-----------------------------------------------------
+    def make_copy(self):
+
+        dest = new()
+
+        dest.len1 = self.len1
+        dest.len2 = self.len2
+        dest.A = self.A
+        dest.B = self.B
+        dest.C = self.C
+        dest.D = self.D
+        dest.count = self.count
+        for i in range(int(self.count)):
+            dest.buf[i] = self.buf[i]
+
+        return dest
+
+    #-----------------------------------------------------
+    def update(self, str):
+        if isinstance(str, bytes):
+            buf = list(str)
+        else:
+            buf = [ord(i) for i in str]
+
+        ilen = U32(len(buf))
+
+        # check if the first length is out of range
+        # as the length is measured in bits then multiplay it by 8
+        if (int(self.len1 + (ilen << 3)) < int(self.len1)):
+            self.len2 = self.len2 + U32(1)
+
+        self.len1 = self.len1 + (ilen << 3)
+        self.len2 = self.len2 + (ilen >> 29)
+
+        L = U32(0)
+        bufpos = 0
+        while (int(ilen) > 0):
+            if (64 - int(self.count)) < int(ilen): L = U32(64 - int(self.count))
+            else: L = ilen
+            for i in range(int(L)): self.buf[i + int(self.count)] = buf[i + bufpos]
+            self.count = self.count + L
+            ilen = ilen - L
+            bufpos = bufpos + int(L)
+
+            if (int(self.count) == 64):
+                self.count = U32(0)
+                X = []
+                i = 0
+                for j in range(16):
+                    X.append(U32(self.buf[i]) + (U32(self.buf[i+1]) << 8)  + \
+                    (U32(self.buf[i+2]) << 16) + (U32(self.buf[i+3]) << 24))
+                    i = i + 4
+
+                A = self.A
+                B = self.B
+                C = self.C
+                D = self.D
+
+                A = f1(A,B,C,D, 0, 3, X)
+                D = f1(D,A,B,C, 1, 7, X)
+                C = f1(C,D,A,B, 2,11, X)
+                B = f1(B,C,D,A, 3,19, X)
+                A = f1(A,B,C,D, 4, 3, X)
+                D = f1(D,A,B,C, 5, 7, X)
+                C = f1(C,D,A,B, 6,11, X)
+                B = f1(B,C,D,A, 7,19, X)
+                A = f1(A,B,C,D, 8, 3, X)
+                D = f1(D,A,B,C, 9, 7, X)
+                C = f1(C,D,A,B,10,11, X)
+                B = f1(B,C,D,A,11,19, X)
+                A = f1(A,B,C,D,12, 3, X)
+                D = f1(D,A,B,C,13, 7, X)
+                C = f1(C,D,A,B,14,11, X)
+                B = f1(B,C,D,A,15,19, X)
+
+                A = f2(A,B,C,D, 0, 3, X)
+                D = f2(D,A,B,C, 4, 5, X)
+                C = f2(C,D,A,B, 8, 9, X)
+                B = f2(B,C,D,A,12,13, X)
+                A = f2(A,B,C,D, 1, 3, X)
+                D = f2(D,A,B,C, 5, 5, X)
+                C = f2(C,D,A,B, 9, 9, X)
+                B = f2(B,C,D,A,13,13, X)
+                A = f2(A,B,C,D, 2, 3, X)
+                D = f2(D,A,B,C, 6, 5, X)
+                C = f2(C,D,A,B,10, 9, X)
+                B = f2(B,C,D,A,14,13, X)
+                A = f2(A,B,C,D, 3, 3, X)
+                D = f2(D,A,B,C, 7, 5, X)
+                C = f2(C,D,A,B,11, 9, X)
+                B = f2(B,C,D,A,15,13, X)
+
+                A = f3(A,B,C,D, 0, 3, X)
+                D = f3(D,A,B,C, 8, 9, X)
+                C = f3(C,D,A,B, 4,11, X)
+                B = f3(B,C,D,A,12,15, X)
+                A = f3(A,B,C,D, 2, 3, X)
+                D = f3(D,A,B,C,10, 9, X)
+                C = f3(C,D,A,B, 6,11, X)
+                B = f3(B,C,D,A,14,15, X)
+                A = f3(A,B,C,D, 1, 3, X)
+                D = f3(D,A,B,C, 9, 9, X)
+                C = f3(C,D,A,B, 5,11, X)
+                B = f3(B,C,D,A,13,15, X)
+                A = f3(A,B,C,D, 3, 3, X)
+                D = f3(D,A,B,C,11, 9, X)
+                C = f3(C,D,A,B, 7,11, X)
+                B = f3(B,C,D,A,15,15, X)
+
+                self.A = self.A + A
+                self.B = self.B + B
+                self.C = self.C + C
+                self.D = self.D + D
+
+    #-----------------------------------------------------
+    def digest(self):
+
+        res = [0x00] * 16
+        s = [0x00] * 8
+        padding = [0x00] * 64
+        padding[0] = 0x80
+        padlen, oldlen1, oldlen2 = U32(0), U32(0), U32(0)
+
+        temp = self.make_copy()
+
+        oldlen1 = temp.len1
+        oldlen2 = temp.len2
+        if (56 <= int(self.count)): padlen = U32(56 - int(self.count) + 64)
+        else: padlen = U32(56 - int(self.count))
+
+        temp.update(int_array2str(padding[:int(padlen)]))
+
+        s[0]= (oldlen1)        & U32(0xFF)
+        s[1]=((oldlen1) >>  8) & U32(0xFF)
+        s[2]=((oldlen1) >> 16) & U32(0xFF)
+        s[3]=((oldlen1) >> 24) & U32(0xFF)
+        s[4]= (oldlen2)        & U32(0xFF)
+        s[5]=((oldlen2) >>  8) & U32(0xFF)
+        s[6]=((oldlen2) >> 16) & U32(0xFF)
+        s[7]=((oldlen2) >> 24) & U32(0xFF)
+        temp.update(int_array2str(s))
+
+        res[ 0]= temp.A        & U32(0xFF)
+        res[ 1]=(temp.A >>  8) & U32(0xFF)
+        res[ 2]=(temp.A >> 16) & U32(0xFF)
+        res[ 3]=(temp.A >> 24) & U32(0xFF)
+        res[ 4]= temp.B        & U32(0xFF)
+        res[ 5]=(temp.B >>  8) & U32(0xFF)
+        res[ 6]=(temp.B >> 16) & U32(0xFF)
+        res[ 7]=(temp.B >> 24) & U32(0xFF)
+        res[ 8]= temp.C        & U32(0xFF)
+        res[ 9]=(temp.C >>  8) & U32(0xFF)
+        res[10]=(temp.C >> 16) & U32(0xFF)
+        res[11]=(temp.C >> 24) & U32(0xFF)
+        res[12]= temp.D        & U32(0xFF)
+        res[13]=(temp.D >>  8) & U32(0xFF)
+        res[14]=(temp.D >> 16) & U32(0xFF)
+        res[15]=(temp.D >> 24) & U32(0xFF)
+
+        return int_array2str(res).encode('UTF-16LE')
+
+#====================================================================
+# helpers
+def F(x, y, z): return (((x) & (y)) | ((~x) & (z)))
+def G(x, y, z): return (((x) & (y)) | ((x) & (z)) | ((y) & (z)))
+def H(x, y, z): return ((x) ^ (y) ^ (z))
+
+def ROL(x, n): return (((x) << n) | ((x) >> (32-n)))
+
+def f1(a, b, c, d, k, s, X): return ROL(a + F(b, c, d) + X[k], s)
+def f2(a, b, c, d, k, s, X): return ROL(a + G(b, c, d) + X[k] + U32(0x5a827999), s)
+def f3(a, b, c, d, k, s, X): return ROL(a + H(b, c, d) + X[k] + U32(0x6ed9eba1), s)
+
+#--------------------------------------------------------------------
+# helper function
+def int_array2str(array):
+        str = ''
+        for i in array:
+            str = str + chr(i)
+        return str
+
+#--------------------------------------------------------------------
+# To be able to use md4.new() instead of md4.MD4()
+new = MD4
diff --git a/python3/smb/utils/pyDes.py b/python3/smb/utils/pyDes.py
new file mode 100644
index 00000000..b2135058
--- /dev/null
+++ b/python3/smb/utils/pyDes.py
@@ -0,0 +1,852 @@
+#############################################################################
+# 				Documentation				    #
+#############################################################################
+
+# Author:   Todd Whiteman
+# Date:     16th March, 2009
+# Verion:   2.0.0
+# License:  Public Domain - free to do as you wish
+# Homepage: http://twhiteman.netfirms.com/des.html
+#
+# This is a pure python implementation of the DES encryption algorithm.
+# It's pure python to avoid portability issues, since most DES 
+# implementations are programmed in C (for performance reasons).
+#
+# Triple DES class is also implemented, utilising the DES base. Triple DES
+# is either DES-EDE3 with a 24 byte key, or DES-EDE2 with a 16 byte key.
+#
+# See the README.txt that should come with this python module for the
+# implementation methods used.
+#
+# Thanks to:
+#  * David Broadwell for ideas, comments and suggestions.
+#  * Mario Wolff for pointing out and debugging some triple des CBC errors.
+#  * Santiago Palladino for providing the PKCS5 padding technique.
+#  * Shaya for correcting the PAD_PKCS5 triple des CBC errors.
+#
+"""A pure python implementation of the DES and TRIPLE DES encryption algorithms.
+
+Class initialization
+--------------------
+pyDes.des(key, [mode], [IV], [pad], [padmode])
+pyDes.triple_des(key, [mode], [IV], [pad], [padmode])
+
+key     -> Bytes containing the encryption key. 8 bytes for DES, 16 or 24 bytes
+	   for Triple DES
+mode    -> Optional argument for encryption type, can be either
+	   pyDes.ECB (Electronic Code Book) or pyDes.CBC (Cypher Block Chaining)
+IV      -> Optional Initial Value bytes, must be supplied if using CBC mode.
+	   Length must be 8 bytes.
+pad     -> Optional argument, set the pad character (PAD_NORMAL) to use during
+	   all encrypt/decrpt operations done with this instance.
+padmode -> Optional argument, set the padding mode (PAD_NORMAL or PAD_PKCS5)
+	   to use during all encrypt/decrpt operations done with this instance.
+
+I recommend to use PAD_PKCS5 padding, as then you never need to worry about any
+padding issues, as the padding can be removed unambiguously upon decrypting
+data that was encrypted using PAD_PKCS5 padmode.
+
+Common methods
+--------------
+encrypt(data, [pad], [padmode])
+decrypt(data, [pad], [padmode])
+
+data    -> Bytes to be encrypted/decrypted
+pad     -> Optional argument. Only when using padmode of PAD_NORMAL. For
+	   encryption, adds this characters to the end of the data block when
+	   data is not a multiple of 8 bytes. For decryption, will remove the
+	   trailing characters that match this pad character from the last 8
+	   bytes of the unencrypted data block.
+padmode -> Optional argument, set the padding mode, must be one of PAD_NORMAL
+	   or PAD_PKCS5). Defaults to PAD_NORMAL.
+	  
+
+Example
+-------
+from pyDes import *
+
+data = "Please encrypt my data"
+k = des("DESCRYPT", CBC, "\0\0\0\0\0\0\0\0", pad=None, padmode=PAD_PKCS5)
+# For Python3, you'll need to use bytes, i.e.:
+#   data = b"Please encrypt my data"
+#   k = des(b"DESCRYPT", CBC, b"\0\0\0\0\0\0\0\0", pad=None, padmode=PAD_PKCS5)
+d = k.encrypt(data)
+print "Encrypted: %r" % d
+print "Decrypted: %r" % k.decrypt(d)
+assert k.decrypt(d, padmode=PAD_PKCS5) == data
+
+
+See the module source (pyDes.py) for more examples of use.
+You can also run the pyDes.py file without and arguments to see a simple test.
+
+Note: This code was not written for high-end systems needing a fast
+      implementation, but rather a handy portable solution with small usage.
+
+"""
+
+import sys
+
+# _pythonMajorVersion is used to handle Python2 and Python3 differences.
+_pythonMajorVersion = sys.version_info[0]
+
+# Modes of crypting / cyphering
+ECB =	0
+CBC =	1
+
+# Modes of padding
+PAD_NORMAL = 1
+PAD_PKCS5 = 2
+
+# PAD_PKCS5: is a method that will unambiguously remove all padding
+#            characters after decryption, when originally encrypted with
+#            this padding mode.
+# For a good description of the PKCS5 padding technique, see:
+# http://www.faqs.org/rfcs/rfc1423.html
+
+# The base class shared by des and triple des.
+class _baseDes(object):
+	def __init__(self, mode=ECB, IV=None, pad=None, padmode=PAD_NORMAL):
+		if IV:
+			IV = self._guardAgainstUnicode(IV)
+		if pad:
+			pad = self._guardAgainstUnicode(pad)
+		self.block_size = 8
+		# Sanity checking of arguments.
+		if pad and padmode == PAD_PKCS5:
+			raise ValueError("Cannot use a pad character with PAD_PKCS5")
+		if IV and len(IV) != self.block_size:
+			raise ValueError("Invalid Initial Value (IV), must be a multiple of " + str(self.block_size) + " bytes")
+
+		# Set the passed in variables
+		self._mode = mode
+		self._iv = IV
+		self._padding = pad
+		self._padmode = padmode
+
+	def getKey(self):
+		"""getKey() -> bytes"""
+		return self.__key
+
+	def setKey(self, key):
+		"""Will set the crypting key for this object."""
+		key = self._guardAgainstUnicode(key)
+		self.__key = key
+
+	def getMode(self):
+		"""getMode() -> pyDes.ECB or pyDes.CBC"""
+		return self._mode
+
+	def setMode(self, mode):
+		"""Sets the type of crypting mode, pyDes.ECB or pyDes.CBC"""
+		self._mode = mode
+
+	def getPadding(self):
+		"""getPadding() -> bytes of length 1. Padding character."""
+		return self._padding
+
+	def setPadding(self, pad):
+		"""setPadding() -> bytes of length 1. Padding character."""
+		if pad is not None:
+			pad = self._guardAgainstUnicode(pad)
+		self._padding = pad
+
+	def getPadMode(self):
+		"""getPadMode() -> pyDes.PAD_NORMAL or pyDes.PAD_PKCS5"""
+		return self._padmode
+		
+	def setPadMode(self, mode):
+		"""Sets the type of padding mode, pyDes.PAD_NORMAL or pyDes.PAD_PKCS5"""
+		self._padmode = mode
+
+	def getIV(self):
+		"""getIV() -> bytes"""
+		return self._iv
+
+	def setIV(self, IV):
+		"""Will set the Initial Value, used in conjunction with CBC mode"""
+		if not IV or len(IV) != self.block_size:
+			raise ValueError("Invalid Initial Value (IV), must be a multiple of " + str(self.block_size) + " bytes")
+		IV = self._guardAgainstUnicode(IV)
+		self._iv = IV
+
+	def _padData(self, data, pad, padmode):
+		# Pad data depending on the mode
+		if padmode is None:
+			# Get the default padding mode.
+			padmode = self.getPadMode()
+		if pad and padmode == PAD_PKCS5:
+			raise ValueError("Cannot use a pad character with PAD_PKCS5")
+
+		if padmode == PAD_NORMAL:
+			if len(data) % self.block_size == 0:
+				# No padding required.
+				return data
+
+			if not pad:
+				# Get the default padding.
+				pad = self.getPadding()
+			if not pad:
+				raise ValueError("Data must be a multiple of " + str(self.block_size) + " bytes in length. Use padmode=PAD_PKCS5 or set the pad character.")
+			data += (self.block_size - (len(data) % self.block_size)) * pad
+		
+		elif padmode == PAD_PKCS5:
+			pad_len = 8 - (len(data) % self.block_size)
+			if _pythonMajorVersion < 3:
+				data += pad_len * chr(pad_len)
+			else:
+				data += bytes([pad_len] * pad_len)
+
+		return data
+
+	def _unpadData(self, data, pad, padmode):
+		# Unpad data depending on the mode.
+		if not data:
+			return data
+		if pad and padmode == PAD_PKCS5:
+			raise ValueError("Cannot use a pad character with PAD_PKCS5")
+		if padmode is None:
+			# Get the default padding mode.
+			padmode = self.getPadMode()
+
+		if padmode == PAD_NORMAL:
+			if not pad:
+				# Get the default padding.
+				pad = self.getPadding()
+			if pad:
+				data = data[:-self.block_size] + \
+				       data[-self.block_size:].rstrip(pad)
+
+		elif padmode == PAD_PKCS5:
+			if _pythonMajorVersion < 3:
+				pad_len = ord(data[-1])
+			else:
+				pad_len = data[-1]
+			data = data[:-pad_len]
+
+		return data
+
+	def _guardAgainstUnicode(self, data):
+		# Only accept byte strings or ascii unicode values, otherwise
+		# there is no way to correctly decode the data into bytes.
+		if _pythonMajorVersion < 3:
+			if isinstance(data, str):
+				raise ValueError("pyDes can only work with bytes, not Unicode strings.")
+		else:
+			if isinstance(data, str):
+				# Only accept ascii unicode values.
+				try:
+					return data.encode('ascii')
+				except UnicodeEncodeError:
+					pass
+				raise ValueError("pyDes can only work with encoded strings, not Unicode.")
+		return data
+
+#############################################################################
+# 				    DES					    #
+#############################################################################
+class des(_baseDes):
+	"""DES encryption/decrytpion class
+
+	Supports ECB (Electronic Code Book) and CBC (Cypher Block Chaining) modes.
+
+	pyDes.des(key,[mode], [IV])
+
+	key  -> Bytes containing the encryption key, must be exactly 8 bytes
+	mode -> Optional argument for encryption type, can be either pyDes.ECB
+		(Electronic Code Book), pyDes.CBC (Cypher Block Chaining)
+	IV   -> Optional Initial Value bytes, must be supplied if using CBC mode.
+		Must be 8 bytes in length.
+	pad  -> Optional argument, set the pad character (PAD_NORMAL) to use
+		during all encrypt/decrpt operations done with this instance.
+	padmode -> Optional argument, set the padding mode (PAD_NORMAL or
+		PAD_PKCS5) to use during all encrypt/decrpt operations done
+		with this instance.
+	"""
+
+
+	# Permutation and translation tables for DES
+	__pc1 = [56, 48, 40, 32, 24, 16,  8,
+		  0, 57, 49, 41, 33, 25, 17,
+		  9,  1, 58, 50, 42, 34, 26,
+		 18, 10,  2, 59, 51, 43, 35,
+		 62, 54, 46, 38, 30, 22, 14,
+		  6, 61, 53, 45, 37, 29, 21,
+		 13,  5, 60, 52, 44, 36, 28,
+		 20, 12,  4, 27, 19, 11,  3
+	]
+
+	# number left rotations of pc1
+	__left_rotations = [
+		1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1
+	]
+
+	# permuted choice key (table 2)
+	__pc2 = [
+		13, 16, 10, 23,  0,  4,
+		 2, 27, 14,  5, 20,  9,
+		22, 18, 11,  3, 25,  7,
+		15,  6, 26, 19, 12,  1,
+		40, 51, 30, 36, 46, 54,
+		29, 39, 50, 44, 32, 47,
+		43, 48, 38, 55, 33, 52,
+		45, 41, 49, 35, 28, 31
+	]
+
+	# initial permutation IP
+	__ip = [57, 49, 41, 33, 25, 17, 9,  1,
+		59, 51, 43, 35, 27, 19, 11, 3,
+		61, 53, 45, 37, 29, 21, 13, 5,
+		63, 55, 47, 39, 31, 23, 15, 7,
+		56, 48, 40, 32, 24, 16, 8,  0,
+		58, 50, 42, 34, 26, 18, 10, 2,
+		60, 52, 44, 36, 28, 20, 12, 4,
+		62, 54, 46, 38, 30, 22, 14, 6
+	]
+
+	# Expansion table for turning 32 bit blocks into 48 bits
+	__expansion_table = [
+		31,  0,  1,  2,  3,  4,
+		 3,  4,  5,  6,  7,  8,
+		 7,  8,  9, 10, 11, 12,
+		11, 12, 13, 14, 15, 16,
+		15, 16, 17, 18, 19, 20,
+		19, 20, 21, 22, 23, 24,
+		23, 24, 25, 26, 27, 28,
+		27, 28, 29, 30, 31,  0
+	]
+
+	# The (in)famous S-boxes
+	__sbox = [
+		# S1
+		[14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7,
+		 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8,
+		 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0,
+		 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13],
+
+		# S2
+		[15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10,
+		 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5,
+		 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15,
+		 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9],
+
+		# S3
+		[10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8,
+		 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1,
+		 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7,
+		 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12],
+
+		# S4
+		[7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15,
+		 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9,
+		 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4,
+		 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14],
+
+		# S5
+		[2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9,
+		 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6,
+		 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14,
+		 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3],
+
+		# S6
+		[12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11,
+		 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8,
+		 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6,
+		 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13],
+
+		# S7
+		[4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1,
+		 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6,
+		 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2,
+		 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12],
+
+		# S8
+		[13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7,
+		 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2,
+		 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8,
+		 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11],
+	]
+
+
+	# 32-bit permutation function P used on the output of the S-boxes
+	__p = [
+		15, 6, 19, 20, 28, 11,
+		27, 16, 0, 14, 22, 25,
+		4, 17, 30, 9, 1, 7,
+		23,13, 31, 26, 2, 8,
+		18, 12, 29, 5, 21, 10,
+		3, 24
+	]
+
+	# final permutation IP^-1
+	__fp = [
+		39,  7, 47, 15, 55, 23, 63, 31,
+		38,  6, 46, 14, 54, 22, 62, 30,
+		37,  5, 45, 13, 53, 21, 61, 29,
+		36,  4, 44, 12, 52, 20, 60, 28,
+		35,  3, 43, 11, 51, 19, 59, 27,
+		34,  2, 42, 10, 50, 18, 58, 26,
+		33,  1, 41,  9, 49, 17, 57, 25,
+		32,  0, 40,  8, 48, 16, 56, 24
+	]
+
+	# Type of crypting being done
+	ENCRYPT =	0x00
+	DECRYPT =	0x01
+
+	# Initialisation
+	def __init__(self, key, mode=ECB, IV=None, pad=None, padmode=PAD_NORMAL):
+		# Sanity checking of arguments.
+		if len(key) != 8:
+			raise ValueError("Invalid DES key size. Key must be exactly 8 bytes long.")
+		_baseDes.__init__(self, mode, IV, pad, padmode)
+		self.key_size = 8
+
+		self.L = []
+		self.R = []
+		self.Kn = [ [0] * 48 ] * 16	# 16 48-bit keys (K1 - K16)
+		self.final = []
+
+		self.setKey(key)
+
+	def setKey(self, key):
+		"""Will set the crypting key for this object. Must be 8 bytes."""
+		_baseDes.setKey(self, key)
+		self.__create_sub_keys()
+
+	def __String_to_BitList(self, data):
+		"""Turn the string data, into a list of bits (1, 0)'s"""
+		if _pythonMajorVersion < 3:
+			# Turn the strings into integers. Python 3 uses a bytes
+			# class, which already has this behaviour.
+			data = [ord(c) for c in data]
+		l = len(data) * 8
+		result = [0] * l
+		pos = 0
+		for ch in data:
+			i = 7
+			while i >= 0:
+				if ch & (1 << i) != 0:
+					result[pos] = 1
+				else:
+					result[pos] = 0
+				pos += 1
+				i -= 1
+
+		return result
+
+	def __BitList_to_String(self, data):
+		"""Turn the list of bits -> data, into a string"""
+		result = []
+		pos = 0
+		c = 0
+		while pos < len(data):
+			c += data[pos] << (7 - (pos % 8))
+			if (pos % 8) == 7:
+				result.append(c)
+				c = 0
+			pos += 1
+
+		if _pythonMajorVersion < 3:
+			return ''.join([ chr(c) for c in result ])
+		else:
+			return bytes(result)
+
+	def __permutate(self, table, block):
+		"""Permutate this block with the specified table"""
+		return list([block[x] for x in table])
+	
+	# Transform the secret key, so that it is ready for data processing
+	# Create the 16 subkeys, K[1] - K[16]
+	def __create_sub_keys(self):
+		"""Create the 16 subkeys K[1] to K[16] from the given key"""
+		key = self.__permutate(des.__pc1, self.__String_to_BitList(self.getKey()))
+		i = 0
+		# Split into Left and Right sections
+		self.L = key[:28]
+		self.R = key[28:]
+		while i < 16:
+			j = 0
+			# Perform circular left shifts
+			while j < des.__left_rotations[i]:
+				self.L.append(self.L[0])
+				del self.L[0]
+
+				self.R.append(self.R[0])
+				del self.R[0]
+
+				j += 1
+
+			# Create one of the 16 subkeys through pc2 permutation
+			self.Kn[i] = self.__permutate(des.__pc2, self.L + self.R)
+
+			i += 1
+
+	# Main part of the encryption algorithm, the number cruncher :)
+	def __des_crypt(self, block, crypt_type):
+		"""Crypt the block of data through DES bit-manipulation"""
+		block = self.__permutate(des.__ip, block)
+		self.L = block[:32]
+		self.R = block[32:]
+
+		# Encryption starts from Kn[1] through to Kn[16]
+		if crypt_type == des.ENCRYPT:
+			iteration = 0
+			iteration_adjustment = 1
+		# Decryption starts from Kn[16] down to Kn[1]
+		else:
+			iteration = 15
+			iteration_adjustment = -1
+
+		i = 0
+		while i < 16:
+			# Make a copy of R[i-1], this will later become L[i]
+			tempR = self.R[:]
+
+			# Permutate R[i - 1] to start creating R[i]
+			self.R = self.__permutate(des.__expansion_table, self.R)
+
+			# Exclusive or R[i - 1] with K[i], create B[1] to B[8] whilst here
+			self.R = list(map(lambda x, y: x ^ y, self.R, self.Kn[iteration]))
+			B = [self.R[:6], self.R[6:12], self.R[12:18], self.R[18:24], self.R[24:30], self.R[30:36], self.R[36:42], self.R[42:]]
+			# Optimization: Replaced below commented code with above
+			#j = 0
+			#B = []
+			#while j < len(self.R):
+			#	self.R[j] = self.R[j] ^ self.Kn[iteration][j]
+			#	j += 1
+			#	if j % 6 == 0:
+			#		B.append(self.R[j-6:j])
+
+			# Permutate B[1] to B[8] using the S-Boxes
+			j = 0
+			Bn = [0] * 32
+			pos = 0
+			while j < 8:
+				# Work out the offsets
+				m = (B[j][0] << 1) + B[j][5]
+				n = (B[j][1] << 3) + (B[j][2] << 2) + (B[j][3] << 1) + B[j][4]
+
+				# Find the permutation value
+				v = des.__sbox[j][(m << 4) + n]
+
+				# Turn value into bits, add it to result: Bn
+				Bn[pos] = (v & 8) >> 3
+				Bn[pos + 1] = (v & 4) >> 2
+				Bn[pos + 2] = (v & 2) >> 1
+				Bn[pos + 3] = v & 1
+
+				pos += 4
+				j += 1
+
+			# Permutate the concatination of B[1] to B[8] (Bn)
+			self.R = self.__permutate(des.__p, Bn)
+
+			# Xor with L[i - 1]
+			self.R = list(map(lambda x, y: x ^ y, self.R, self.L))
+			# Optimization: This now replaces the below commented code
+			#j = 0
+			#while j < len(self.R):
+			#	self.R[j] = self.R[j] ^ self.L[j]
+			#	j += 1
+
+			# L[i] becomes R[i - 1]
+			self.L = tempR
+
+			i += 1
+			iteration += iteration_adjustment
+		
+		# Final permutation of R[16]L[16]
+		self.final = self.__permutate(des.__fp, self.R + self.L)
+		return self.final
+
+
+	# Data to be encrypted/decrypted
+	def crypt(self, data, crypt_type):
+		"""Crypt the data in blocks, running it through des_crypt()"""
+
+		# Error check the data
+		if not data:
+			return ''
+		if len(data) % self.block_size != 0:
+			if crypt_type == des.DECRYPT: # Decryption must work on 8 byte blocks
+				raise ValueError("Invalid data length, data must be a multiple of " + str(self.block_size) + " bytes\n.")
+			if not self.getPadding():
+				raise ValueError("Invalid data length, data must be a multiple of " + str(self.block_size) + " bytes\n. Try setting the optional padding character")
+			else:
+				data += (self.block_size - (len(data) % self.block_size)) * self.getPadding()
+			# print "Len of data: %f" % (len(data) / self.block_size)
+
+		if self.getMode() == CBC:
+			if self.getIV():
+				iv = self.__String_to_BitList(self.getIV())
+			else:
+				raise ValueError("For CBC mode, you must supply the Initial Value (IV) for ciphering")
+
+		# Split the data into blocks, crypting each one seperately
+		i = 0
+		dict = {}
+		result = []
+		#cached = 0
+		#lines = 0
+		while i < len(data):
+			# Test code for caching encryption results
+			#lines += 1
+			#if dict.has_key(data[i:i+8]):
+				#print "Cached result for: %s" % data[i:i+8]
+			#	cached += 1
+			#	result.append(dict[data[i:i+8]])
+			#	i += 8
+			#	continue
+				
+			block = self.__String_to_BitList(data[i:i+8])
+
+			# Xor with IV if using CBC mode
+			if self.getMode() == CBC:
+				if crypt_type == des.ENCRYPT:
+					block = list(map(lambda x, y: x ^ y, block, iv))
+					#j = 0
+					#while j < len(block):
+					#	block[j] = block[j] ^ iv[j]
+					#	j += 1
+
+				processed_block = self.__des_crypt(block, crypt_type)
+
+				if crypt_type == des.DECRYPT:
+					processed_block = list(map(lambda x, y: x ^ y, processed_block, iv))
+					#j = 0
+					#while j < len(processed_block):
+					#	processed_block[j] = processed_block[j] ^ iv[j]
+					#	j += 1
+					iv = block
+				else:
+					iv = processed_block
+			else:
+				processed_block = self.__des_crypt(block, crypt_type)
+
+
+			# Add the resulting crypted block to our list
+			#d = self.__BitList_to_String(processed_block)
+			#result.append(d)
+			result.append(self.__BitList_to_String(processed_block))
+			#dict[data[i:i+8]] = d
+			i += 8
+
+		# print "Lines: %d, cached: %d" % (lines, cached)
+
+		# Return the full crypted string
+		if _pythonMajorVersion < 3:
+			return ''.join(result)
+		else:
+			return bytes.fromhex('').join(result)
+
+	def encrypt(self, data, pad=None, padmode=None):
+		"""encrypt(data, [pad], [padmode]) -> bytes
+
+		data : Bytes to be encrypted
+		pad  : Optional argument for encryption padding. Must only be one byte
+		padmode : Optional argument for overriding the padding mode.
+
+		The data must be a multiple of 8 bytes and will be encrypted
+		with the already specified key. Data does not have to be a
+		multiple of 8 bytes if the padding character is supplied, or
+		the padmode is set to PAD_PKCS5, as bytes will then added to
+		ensure the be padded data is a multiple of 8 bytes.
+		"""
+		data = self._guardAgainstUnicode(data)
+		if pad is not None:
+			pad = self._guardAgainstUnicode(pad)
+		data = self._padData(data, pad, padmode)
+		return self.crypt(data, des.ENCRYPT)
+
+	def decrypt(self, data, pad=None, padmode=None):
+		"""decrypt(data, [pad], [padmode]) -> bytes
+
+		data : Bytes to be encrypted
+		pad  : Optional argument for decryption padding. Must only be one byte
+		padmode : Optional argument for overriding the padding mode.
+
+		The data must be a multiple of 8 bytes and will be decrypted
+		with the already specified key. In PAD_NORMAL mode, if the
+		optional padding character is supplied, then the un-encrypted
+		data will have the padding characters removed from the end of
+		the bytes. This pad removal only occurs on the last 8 bytes of
+		the data (last data block). In PAD_PKCS5 mode, the special
+		padding end markers will be removed from the data after decrypting.
+		"""
+		data = self._guardAgainstUnicode(data)
+		if pad is not None:
+			pad = self._guardAgainstUnicode(pad)
+		data = self.crypt(data, des.DECRYPT)
+		return self._unpadData(data, pad, padmode)
+
+
+
+#############################################################################
+# 				Triple DES				    #
+#############################################################################
+class triple_des(_baseDes):
+	"""Triple DES encryption/decrytpion class
+
+	This algorithm uses the DES-EDE3 (when a 24 byte key is supplied) or
+	the DES-EDE2 (when a 16 byte key is supplied) encryption methods.
+	Supports ECB (Electronic Code Book) and CBC (Cypher Block Chaining) modes.
+
+	pyDes.des(key, [mode], [IV])
+
+	key  -> Bytes containing the encryption key, must be either 16 or
+	        24 bytes long
+	mode -> Optional argument for encryption type, can be either pyDes.ECB
+		(Electronic Code Book), pyDes.CBC (Cypher Block Chaining)
+	IV   -> Optional Initial Value bytes, must be supplied if using CBC mode.
+		Must be 8 bytes in length.
+	pad  -> Optional argument, set the pad character (PAD_NORMAL) to use
+		during all encrypt/decrpt operations done with this instance.
+	padmode -> Optional argument, set the padding mode (PAD_NORMAL or
+		PAD_PKCS5) to use during all encrypt/decrpt operations done
+		with this instance.
+	"""
+	def __init__(self, key, mode=ECB, IV=None, pad=None, padmode=PAD_NORMAL):
+		_baseDes.__init__(self, mode, IV, pad, padmode)
+		self.setKey(key)
+
+	def setKey(self, key):
+		"""Will set the crypting key for this object. Either 16 or 24 bytes long."""
+		self.key_size = 24  # Use DES-EDE3 mode
+		if len(key) != self.key_size:
+			if len(key) == 16: # Use DES-EDE2 mode
+				self.key_size = 16
+			else:
+				raise ValueError("Invalid triple DES key size. Key must be either 16 or 24 bytes long")
+		if self.getMode() == CBC:
+			if not self.getIV():
+				# Use the first 8 bytes of the key
+				self._iv = key[:self.block_size]
+			if len(self.getIV()) != self.block_size:
+				raise ValueError("Invalid IV, must be 8 bytes in length")
+		self.__key1 = des(key[:8], self._mode, self._iv,
+				  self._padding, self._padmode)
+		self.__key2 = des(key[8:16], self._mode, self._iv,
+				  self._padding, self._padmode)
+		if self.key_size == 16:
+			self.__key3 = self.__key1
+		else:
+			self.__key3 = des(key[16:], self._mode, self._iv,
+					  self._padding, self._padmode)
+		_baseDes.setKey(self, key)
+
+	# Override setter methods to work on all 3 keys.
+
+	def setMode(self, mode):
+		"""Sets the type of crypting mode, pyDes.ECB or pyDes.CBC"""
+		_baseDes.setMode(self, mode)
+		for key in (self.__key1, self.__key2, self.__key3):
+			key.setMode(mode)
+
+	def setPadding(self, pad):
+		"""setPadding() -> bytes of length 1. Padding character."""
+		_baseDes.setPadding(self, pad)
+		for key in (self.__key1, self.__key2, self.__key3):
+			key.setPadding(pad)
+
+	def setPadMode(self, mode):
+		"""Sets the type of padding mode, pyDes.PAD_NORMAL or pyDes.PAD_PKCS5"""
+		_baseDes.setPadMode(self, mode)
+		for key in (self.__key1, self.__key2, self.__key3):
+			key.setPadMode(mode)
+
+	def setIV(self, IV):
+		"""Will set the Initial Value, used in conjunction with CBC mode"""
+		_baseDes.setIV(self, IV)
+		for key in (self.__key1, self.__key2, self.__key3):
+			key.setIV(IV)
+
+	def encrypt(self, data, pad=None, padmode=None):
+		"""encrypt(data, [pad], [padmode]) -> bytes
+
+		data : bytes to be encrypted
+		pad  : Optional argument for encryption padding. Must only be one byte
+		padmode : Optional argument for overriding the padding mode.
+
+		The data must be a multiple of 8 bytes and will be encrypted
+		with the already specified key. Data does not have to be a
+		multiple of 8 bytes if the padding character is supplied, or
+		the padmode is set to PAD_PKCS5, as bytes will then added to
+		ensure the be padded data is a multiple of 8 bytes.
+		"""
+		ENCRYPT = des.ENCRYPT
+		DECRYPT = des.DECRYPT
+		data = self._guardAgainstUnicode(data)
+		if pad is not None:
+			pad = self._guardAgainstUnicode(pad)
+		# Pad the data accordingly.
+		data = self._padData(data, pad, padmode)
+		if self.getMode() == CBC:
+			self.__key1.setIV(self.getIV())
+			self.__key2.setIV(self.getIV())
+			self.__key3.setIV(self.getIV())
+			i = 0
+			result = []
+			while i < len(data):
+				block = self.__key1.crypt(data[i:i+8], ENCRYPT)
+				block = self.__key2.crypt(block, DECRYPT)
+				block = self.__key3.crypt(block, ENCRYPT)
+				self.__key1.setIV(block)
+				self.__key2.setIV(block)
+				self.__key3.setIV(block)
+				result.append(block)
+				i += 8
+			if _pythonMajorVersion < 3:
+				return ''.join(result)
+			else:
+				return bytes.fromhex('').join(result)
+		else:
+			data = self.__key1.crypt(data, ENCRYPT)
+			data = self.__key2.crypt(data, DECRYPT)
+			return self.__key3.crypt(data, ENCRYPT)
+
+	def decrypt(self, data, pad=None, padmode=None):
+		"""decrypt(data, [pad], [padmode]) -> bytes
+
+		data : bytes to be encrypted
+		pad  : Optional argument for decryption padding. Must only be one byte
+		padmode : Optional argument for overriding the padding mode.
+
+		The data must be a multiple of 8 bytes and will be decrypted
+		with the already specified key. In PAD_NORMAL mode, if the
+		optional padding character is supplied, then the un-encrypted
+		data will have the padding characters removed from the end of
+		the bytes. This pad removal only occurs on the last 8 bytes of
+		the data (last data block). In PAD_PKCS5 mode, the special
+		padding end markers will be removed from the data after
+		decrypting, no pad character is required for PAD_PKCS5.
+		"""
+		ENCRYPT = des.ENCRYPT
+		DECRYPT = des.DECRYPT
+		data = self._guardAgainstUnicode(data)
+		if pad is not None:
+			pad = self._guardAgainstUnicode(pad)
+		if self.getMode() == CBC:
+			self.__key1.setIV(self.getIV())
+			self.__key2.setIV(self.getIV())
+			self.__key3.setIV(self.getIV())
+			i = 0
+			result = []
+			while i < len(data):
+				iv = data[i:i+8]
+				block = self.__key3.crypt(iv,    DECRYPT)
+				block = self.__key2.crypt(block, ENCRYPT)
+				block = self.__key1.crypt(block, DECRYPT)
+				self.__key1.setIV(iv)
+				self.__key2.setIV(iv)
+				self.__key3.setIV(iv)
+				result.append(block)
+				i += 8
+			if _pythonMajorVersion < 3:
+				data = ''.join(result)
+			else:
+				data = bytes.fromhex('').join(result)
+		else:
+			data = self.__key3.crypt(data, DECRYPT)
+			data = self.__key2.crypt(data, ENCRYPT)
+			data = self.__key1.crypt(data, DECRYPT)
+		return self._unpadData(data, pad, padmode)
diff --git a/python3/smb/utils/sha256.py b/python3/smb/utils/sha256.py
new file mode 100644
index 00000000..d535a4b6
--- /dev/null
+++ b/python3/smb/utils/sha256.py
@@ -0,0 +1,110 @@
+#!/usr/bin/python
+__author__ = 'Thomas Dixon'
+__license__ = 'MIT'
+
+import copy, struct, sys
+
+digest_size = 32
+blocksize = 1
+
+def new(m=None):
+    return sha256(m)
+
+class sha256(object):
+    _k = (0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
+          0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
+          0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
+          0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
+          0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
+          0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
+          0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
+          0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
+          0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
+          0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
+          0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
+          0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
+          0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
+          0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
+          0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
+          0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2)
+    _h = (0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
+          0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19)
+    _output_size = 8
+
+    blocksize = 1
+    block_size = 64
+    digest_size = 32
+
+    def __init__(self, m=None):
+        self._buffer = ''
+        self._counter = 0
+
+        if m is not None:
+            if type(m) is not str:
+                raise TypeError('%s() argument 1 must be string, not %s' % (self.__class__.__name__, type(m).__name__))
+            self.update(m)
+
+    def _rotr(self, x, y):
+        return ((x >> y) | (x << (32-y))) & 0xFFFFFFFF
+
+    def _sha256_process(self, c):
+        w = [0]*64
+        w[0:15] = struct.unpack('!16L', c)
+
+        for i in range(16, 64):
+            s0 = self._rotr(w[i-15], 7) ^ self._rotr(w[i-15], 18) ^ (w[i-15] >> 3)
+            s1 = self._rotr(w[i-2], 17) ^ self._rotr(w[i-2], 19) ^ (w[i-2] >> 10)
+            w[i] = (w[i-16] + s0 + w[i-7] + s1) & 0xFFFFFFFF
+
+        a,b,c,d,e,f,g,h = self._h
+
+        for i in range(64):
+            s0 = self._rotr(a, 2) ^ self._rotr(a, 13) ^ self._rotr(a, 22)
+            maj = (a & b) ^ (a & c) ^ (b & c)
+            t2 = s0 + maj
+            s1 = self._rotr(e, 6) ^ self._rotr(e, 11) ^ self._rotr(e, 25)
+            ch = (e & f) ^ ((~e) & g)
+            t1 = h + s1 + ch + self._k[i] + w[i]
+
+            h = g
+            g = f
+            f = e
+            e = (d + t1) & 0xFFFFFFFF
+            d = c
+            c = b
+            b = a
+            a = (t1 + t2) & 0xFFFFFFFF
+
+        self._h = [(x+y) & 0xFFFFFFFF for x,y in zip(self._h, [a,b,c,d,e,f,g,h])]
+
+    def update(self, m):
+        if not m:
+            return
+        if type(m) is not str:
+            raise TypeError('%s() argument 1 must be string, not %s' % (sys._getframe().f_code.co_name, type(m).__name__))
+
+        self._buffer += m
+        self._counter += len(m)
+
+        while len(self._buffer) >= 64:
+            self._sha256_process(self._buffer[:64])
+            self._buffer = self._buffer[64:]
+
+    def digest(self):
+        mdi = self._counter & 0x3F
+        length = struct.pack('!Q', self._counter<<3)
+
+        if mdi < 56:
+            padlen = 55-mdi
+        else:
+            padlen = 119-mdi
+
+        r = self.copy()
+        r.update('\x80'+('\x00'*padlen)+length)
+        return ''.join([struct.pack('!L', i) for i in r._h[:self._output_size]])
+
+    def hexdigest(self):
+        return self.digest().encode('hex')
+
+    def copy(self):
+        return copy.deepcopy(self)
diff --git a/python3/tests/DirectSMBConnectionTests/__init__.py b/python3/tests/DirectSMBConnectionTests/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/python3/tests/DirectSMBConnectionTests/test_auth.py b/python3/tests/DirectSMBConnectionTests/test_auth.py
new file mode 100644
index 00000000..5b63a9c6
--- /dev/null
+++ b/python3/tests/DirectSMBConnectionTests/test_auth.py
@@ -0,0 +1,72 @@
+
+from smb.SMBConnection import SMBConnection
+from .util import getConnectionInfo
+from nose.tools import with_setup
+from smb import smb_structs
+
+conn, conn2, conn3 = None, None, None
+
+def teardown_func():
+    global conn, conn2, conn3
+    if conn:
+        conn.close()
+    if conn2:
+        conn2.close()
+    if conn3:
+        conn3.close();
+
+@with_setup(teardown = teardown_func)
+def test_NTLMv1_auth_SMB1():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = False
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], domain = info['domain'], use_ntlm_v2 = False, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+    conn2 = SMBConnection(info['user'], 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = False, is_direct_tcp = True)
+    assert not conn2.connect(info['server_ip'], info['server_port'])
+
+    conn3 = SMBConnection('INVALIDUSER', 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = False, is_direct_tcp = True)
+    assert not conn3.connect(info['server_ip'], info['server_port'])
+
+@with_setup(teardown = teardown_func)
+def test_NTLMv2_auth_SMB1():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = False
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], domain = info['domain'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+    conn2 = SMBConnection(info['user'], 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert not conn2.connect(info['server_ip'], info['server_port'])
+
+    conn3 = SMBConnection('INVALIDUSER', 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert not conn3.connect(info['server_ip'], info['server_port'])
+
+@with_setup(teardown = teardown_func)
+def test_NTLMv1_auth_SMB2():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = True
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], domain = info['domain'], use_ntlm_v2 = False)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+    conn2 = SMBConnection(info['user'], 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = False)
+    assert not conn2.connect(info['server_ip'], info['server_port'])
+
+    conn3 = SMBConnection('INVALIDUSER', 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = False)
+    assert not conn3.connect(info['server_ip'], info['server_port'])
+
+@with_setup(teardown = teardown_func)
+def test_NTLMv2_auth_SMB2():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = True
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], domain = info['domain'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+    conn2 = SMBConnection(info['user'], 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert not conn2.connect(info['server_ip'], info['server_port'])
+
+    conn3 = SMBConnection('INVALIDUSER', 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert not conn3.connect(info['server_ip'], info['server_port'])
diff --git a/python3/tests/DirectSMBConnectionTests/test_createdeletedirectory.py b/python3/tests/DirectSMBConnectionTests/test_createdeletedirectory.py
new file mode 100644
index 00000000..684b4eaa
--- /dev/null
+++ b/python3/tests/DirectSMBConnectionTests/test_createdeletedirectory.py
@@ -0,0 +1,145 @@
+# -*- coding: utf-8 -*-
+
+import os, time, random
+from smb.SMBConnection import SMBConnection
+from smb.smb2_constants import SMB2_DIALECT_2
+from .util import getConnectionInfo
+from nose.tools import with_setup
+from smb import smb_structs
+
+conn = None
+
+def setup_func_SMB1():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = False
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2():
+    global conn
+    smb_structs.SUPPORT_SMB2 = True
+    smb_structs.SUPPORT_SMB2x = False
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2x():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = True
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def teardown_func():
+    global conn
+    conn.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_english_directory_SMB1():
+    global conn
+
+    path = os.sep + 'TestDir %d-%d' % ( time.time(), random.randint(0, 1000) )
+    conn.createDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) in names
+
+    conn.deleteDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) not in names
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_english_directory_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    path = os.sep + 'TestDir %d-%d' % ( time.time(), random.randint(0, 1000) )
+    conn.createDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) in names
+
+    conn.deleteDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) not in names
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_english_directory_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    path = os.sep + 'TestDir %d-%d' % ( time.time(), random.randint(0, 1000) )
+    conn.createDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) in names
+
+    conn.deleteDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) not in names
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_unicode_directory_SMB1():
+    global conn
+
+    path = os.sep + u'文件夹创建 %d-%d' % ( time.time(), random.randint(0, 1000) )
+    conn.createDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) in names
+
+    conn.deleteDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) not in names
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_unicode_directory_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    path = os.sep + u'文件夹创建 %d-%d' % ( time.time(), random.randint(0, 1000) )
+    conn.createDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) in names
+
+    conn.deleteDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) not in names
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_unicode_directory_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    path = os.sep + u'文件夹创建 %d-%d' % ( time.time(), random.randint(0, 1000) )
+    conn.createDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) in names
+
+    conn.deleteDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) not in names
diff --git a/python3/tests/DirectSMBConnectionTests/test_echo.py b/python3/tests/DirectSMBConnectionTests/test_echo.py
new file mode 100644
index 00000000..8159429e
--- /dev/null
+++ b/python3/tests/DirectSMBConnectionTests/test_echo.py
@@ -0,0 +1,24 @@
+
+import random
+from smb.SMBConnection import SMBConnection
+from .util import getConnectionInfo
+from nose.tools import with_setup
+
+conn = None
+
+def setup_func():
+    global conn
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def teardown_func():
+    global conn
+    conn.close()
+
+@with_setup(setup_func, teardown_func)
+def test_echo():
+    global conn
+
+    data = bytearray('%d' % random.randint(1000, 9999), 'ascii')
+    assert conn.echo(data) == data
diff --git a/python3/tests/DirectSMBConnectionTests/test_listpath.py b/python3/tests/DirectSMBConnectionTests/test_listpath.py
new file mode 100644
index 00000000..dee42175
--- /dev/null
+++ b/python3/tests/DirectSMBConnectionTests/test_listpath.py
@@ -0,0 +1,197 @@
+# -*- coding: utf-8 -*-
+
+from smb.SMBConnection import SMBConnection
+from smb.smb_constants import *
+from smb.smb2_constants import SMB2_DIALECT_2
+from .util import getConnectionInfo
+from nose.tools import with_setup
+from smb import smb_structs
+
+conn = None
+
+def setup_func_SMB1():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = False
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2():
+    global conn
+    smb_structs.SUPPORT_SMB2 = True
+    smb_structs.SUPPORT_SMB2x = False
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2x():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = True
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def teardown_func():
+    global conn
+    conn.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_listPath_SMB1():
+    global conn
+    results = conn.listPath('smbtest', '/')
+    filenames = list(map(lambda r: ( r.filename, r.isDirectory ), results))
+    assert ( u'\u6d4b\u8bd5\u6587\u4ef6\u5939', True ) in filenames  # Test non-English folder names
+    assert ( u'Test Folder with Long Name', True ) in filenames      # Test long English folder names
+    assert ( u'TestDir1', True ) in filenames                        # Test short English folder names
+    assert ( u'Implementing CIFS - SMB.html', False ) in filenames   # Test long English file names
+    assert ( u'rfc1001.txt', False ) in filenames                    # Test short English file names
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_listSubPath_SMB1():
+    global conn
+    results = conn.listPath('smbtest', '/Test Folder with Long Name/')
+    filenames = list(map(lambda r: ( r.filename, r.isDirectory ), results))
+    assert ( u'Test File.txt', False ) in filenames
+    assert ( u'Test Folder', True ) in filenames
+    assert ( u'子文件夹', True ) in filenames
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_listPathWithManyFiles_SMB1():
+    global conn
+    results = conn.listPath('smbtest', '/RFC Archive/')
+    filenames = list(map(lambda r: ( r.filename, r.isDirectory ), results))
+    assert len(filenames)==999
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_listPathWithManyFiles_SMB1():
+    global conn
+    results = conn.listPath('smbtest', '/RFC Archive/')
+    filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+    assert len(list(filenames))==999
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_listPath_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+    results = conn.listPath('smbtest', '/')
+    filenames = list(map(lambda r: ( r.filename, r.isDirectory ), results))
+    assert ( u'\u6d4b\u8bd5\u6587\u4ef6\u5939', True ) in filenames  # Test non-English folder names
+    assert ( u'Test Folder with Long Name', True ) in filenames      # Test long English folder names
+    assert ( u'TestDir1', True ) in filenames                        # Test short English folder names
+    assert ( u'Implementing CIFS - SMB.html', False ) in filenames   # Test long English file names
+    assert ( u'rfc1001.txt', False ) in filenames                    # Test short English file names
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_listPath_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+    results = conn.listPath('smbtest', '/')
+    filenames = list(map(lambda r: ( r.filename, r.isDirectory ), results))
+    assert ( u'\u6d4b\u8bd5\u6587\u4ef6\u5939', True ) in filenames  # Test non-English folder names
+    assert ( u'Test Folder with Long Name', True ) in filenames      # Test long English folder names
+    assert ( u'TestDir1', True ) in filenames                        # Test short English folder names
+    assert ( u'Implementing CIFS - SMB.html', False ) in filenames   # Test long English file names
+    assert ( u'rfc1001.txt', False ) in filenames                    # Test short English file names
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_listSubPath_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+    results = conn.listPath('smbtest', '/Test Folder with Long Name/')
+    filenames = list(map(lambda r: ( r.filename, r.isDirectory ), results))
+    assert ( u'Test File.txt', False ) in filenames
+    assert ( u'Test Folder', True ) in filenames
+    assert ( u'子文件夹', True ) in filenames
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_listSubPath_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+    results = conn.listPath('smbtest', '/Test Folder with Long Name/')
+    filenames = [( r.filename, r.isDirectory ) for r in results]
+    assert ( 'Test File.txt', False ) in filenames
+    assert ( 'Test Folder', True ) in filenames
+    assert ( '子文件夹', True ) in filenames
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_listPathWithManyFiles_SMB2():
+    global conn
+    results = conn.listPath('smbtest', '/RFC Archive/')
+    filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+    assert len(list(filenames))==999
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_listPathFilterForDirectory_SMB1():
+    global conn
+    results = conn.listPath('smbtest', '/Test Folder with Long Name', search = SMB_FILE_ATTRIBUTE_DIRECTORY)
+    filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+    assert len(list(filenames)) > 0
+    for f, isDirectory in filenames:
+        assert isDirectory
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_listPathFilterForDirectory_SMB2():
+    global conn
+    results = conn.listPath('smbtest', '/Test Folder with Long Name', search = SMB_FILE_ATTRIBUTE_DIRECTORY)
+    filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+    assert len(list(filenames)) > 0
+    for f, isDirectory in filenames:
+        assert isDirectory
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_listPathFilterForFiles_SMB1():
+    global conn
+    results = conn.listPath('smbtest', '/Test Folder with Long Name', search = SMB_FILE_ATTRIBUTE_READONLY | SMB_FILE_ATTRIBUTE_HIDDEN | SMB_FILE_ATTRIBUTE_SYSTEM | SMB_FILE_ATTRIBUTE_ARCHIVE | SMB_FILE_ATTRIBUTE_INCL_NORMAL)
+    filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+    assert len(list(filenames)) > 0
+    for f, isDirectory in filenames:
+        assert not isDirectory
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_listPathFilterForFiles_SMB2():
+    global conn
+    results = conn.listPath('smbtest', '/Test Folder with Long Name', search = SMB_FILE_ATTRIBUTE_READONLY | SMB_FILE_ATTRIBUTE_HIDDEN | SMB_FILE_ATTRIBUTE_SYSTEM | SMB_FILE_ATTRIBUTE_ARCHIVE | SMB_FILE_ATTRIBUTE_INCL_NORMAL)
+    filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+    assert len(list(filenames)) > 0
+    for f, isDirectory in filenames:
+        assert not isDirectory
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_listPathFilterPattern_SMB1():
+    global conn
+    results = conn.listPath('smbtest', '/Test Folder with Long Name', pattern = 'Test*')
+    filenames = list(map(lambda r: ( r.filename, r.isDirectory ), results))
+    assert len(filenames) == 2
+    assert ( u'Test File.txt', False ) in filenames
+    assert ( u'Test Folder', True ) in filenames
+    assert ( u'子文件夹', True ) not in filenames
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_listPathFilterPattern_SMB2():
+    global conn
+    results = conn.listPath('smbtest', '/Test Folder with Long Name', pattern = 'Test*')
+    filenames = list(map(lambda r: ( r.filename, r.isDirectory ), results))
+    assert len(filenames) == 2
+    assert ( u'Test File.txt', False ) in filenames
+    assert ( u'Test Folder', True ) in filenames
+    assert ( u'子文件夹', True ) not in filenames
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_listPathFilterUnicodePattern_SMB1():
+    global conn
+    results = conn.listPath('smbtest', '/Test Folder with Long Name', pattern = u'*件夹')
+    filenames = list(map(lambda r: ( r.filename, r.isDirectory ), results))
+    assert len(filenames) == 1
+    assert ( u'Test File.txt', False ) not in filenames
+    assert ( u'Test Folder', True ) not in filenames
+    assert ( u'子文件夹', True ) in filenames
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_listPathFilterUnicodePattern_SMB2():
+    global conn
+    results = conn.listPath('smbtest', '/Test Folder with Long Name', pattern = u'*件夹')
+    filenames = list(map(lambda r: ( r.filename, r.isDirectory ), results))
+    assert len(filenames) == 1
+    assert ( u'Test File.txt', False ) not in filenames
+    assert ( u'Test Folder', True ) not in filenames
+    assert ( u'子文件夹', True ) in filenames
diff --git a/python3/tests/DirectSMBConnectionTests/test_listshares.py b/python3/tests/DirectSMBConnectionTests/test_listshares.py
new file mode 100644
index 00000000..1374cbdd
--- /dev/null
+++ b/python3/tests/DirectSMBConnectionTests/test_listshares.py
@@ -0,0 +1,54 @@
+
+from smb.SMBConnection import SMBConnection
+from smb.smb2_constants import SMB2_DIALECT_2
+from .util import getConnectionInfo
+from nose.tools import with_setup
+from smb import smb_structs
+
+conn = None
+
+def setup_func_SMB1():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = False
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2():
+    global conn
+    smb_structs.SUPPORT_SMB2 = True
+    smb_structs.SUPPORT_SMB2x = False
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2x():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = True
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def teardown_func():
+    global conn
+    conn.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_listshares_SMB1():
+    global conn
+    results = conn.listShares()
+    assert 'smbtest' in list(map(lambda r: r.name.lower(), results))
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_listshares_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+    results = conn.listShares()
+    assert 'smbtest' in list(map(lambda r: r.name.lower(), results))
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_listshares_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+    results = conn.listShares()
+    assert 'smbtest' in list(map(lambda r: r.name.lower(), results))
diff --git a/python3/tests/DirectSMBConnectionTests/test_listsnapshots.py b/python3/tests/DirectSMBConnectionTests/test_listsnapshots.py
new file mode 100644
index 00000000..f6ce4e2d
--- /dev/null
+++ b/python3/tests/DirectSMBConnectionTests/test_listsnapshots.py
@@ -0,0 +1,57 @@
+
+from smb.SMBConnection import SMBConnection
+from smb.smb2_constants import SMB2_DIALECT_2
+from .util import getConnectionInfo
+from nose.tools import with_setup
+from smb import smb_structs
+
+conn = None
+
+def setup_func_SMB1():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = False
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2():
+    global conn
+    smb_structs.SUPPORT_SMB2 = True
+    smb_structs.SUPPORT_SMB2x = False
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2x():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = True
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def teardown_func():
+    global conn
+    conn.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_listsnapshots_SMB1():
+    global conn
+    results = conn.listSnapshots('smbtest', '/rfc1001.txt')
+    assert len(results) > 0
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_listsnapshots_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+    results = conn.listSnapshots('smbtest', '/rfc1001.txt')
+    assert len(results) > 0
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_listsnapshots_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+    results = conn.listSnapshots('smbtest', '/rfc1001.txt')
+    assert len(results) > 0
diff --git a/python3/tests/DirectSMBConnectionTests/test_rename.py b/python3/tests/DirectSMBConnectionTests/test_rename.py
new file mode 100644
index 00000000..3abb2a37
--- /dev/null
+++ b/python3/tests/DirectSMBConnectionTests/test_rename.py
@@ -0,0 +1,321 @@
+# -*- coding: utf-8 -*-
+
+import os, time, random
+from io import BytesIO
+from smb.SMBConnection import SMBConnection
+from smb.smb2_constants import SMB2_DIALECT_2
+from .util import getConnectionInfo
+from nose.tools import with_setup
+from smb import smb_structs
+
+conn = None
+
+def setup_func_SMB1():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = False
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2():
+    global conn
+    smb_structs.SUPPORT_SMB2 = True
+    smb_structs.SUPPORT_SMB2x = False
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2x():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = True
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def teardown_func():
+    global conn
+    conn.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_rename_english_file_SMB1():
+    global conn
+
+    old_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    new_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.storeFile('smbtest', old_path, BytesIO(b'Rename file test'))
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteFiles('smbtest', new_path)
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_rename_english_file_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    old_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    new_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.storeFile('smbtest', old_path, BytesIO(b'Rename file test'))
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteFiles('smbtest', new_path)
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_rename_english_file_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    old_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    new_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.storeFile('smbtest', old_path, BytesIO(b'Rename file test'))
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteFiles('smbtest', new_path)
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_rename_unicode_file_SMB1():
+    global conn
+
+    old_path = u'/改名测试 %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    new_path = u'/改名测试 %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.storeFile('smbtest', old_path, BytesIO(b'Rename file test'))
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteFiles('smbtest', new_path)
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_rename_unicode_file_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    old_path = u'/改名测试 %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    new_path = u'/改名测试 %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.storeFile('smbtest', old_path, BytesIO(b'Rename file test'))
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteFiles('smbtest', new_path)
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_rename_unicode_file_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    old_path = u'/改名测试 %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    new_path = u'/改名测试 %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.storeFile('smbtest', old_path, BytesIO(b'Rename file test'))
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteFiles('smbtest', new_path)
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_rename_english_directory_SMB1():
+    global conn
+
+    old_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    new_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.createDirectory('smbtest', old_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteDirectory('smbtest', new_path)
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_rename_english_directory_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    old_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    new_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.createDirectory('smbtest', old_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteDirectory('smbtest', new_path)
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_rename_english_directory_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    old_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    new_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.createDirectory('smbtest', old_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteDirectory('smbtest', new_path)
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_rename_unicode_directory_SMB1():
+    global conn
+
+    old_path = u'/改名测试 %d-%d' % ( time.time(), random.randint(1000, 9999) )
+    new_path = u'/改名测试 %d-%d' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.createDirectory('smbtest', old_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteDirectory('smbtest', new_path)
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_rename_unicode_directory_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    old_path = u'/改名测试 %d-%d' % ( time.time(), random.randint(1000, 9999) )
+    new_path = u'/改名测试 %d-%d' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.createDirectory('smbtest', old_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteDirectory('smbtest', new_path)
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_rename_unicode_directory_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    old_path = u'/改名测试 %d-%d' % ( time.time(), random.randint(1000, 9999) )
+    new_path = u'/改名测试 %d-%d' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.createDirectory('smbtest', old_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteDirectory('smbtest', new_path)
diff --git a/python3/tests/DirectSMBConnectionTests/test_retrievefile.py b/python3/tests/DirectSMBConnectionTests/test_retrievefile.py
new file mode 100644
index 00000000..8670d270
--- /dev/null
+++ b/python3/tests/DirectSMBConnectionTests/test_retrievefile.py
@@ -0,0 +1,369 @@
+# -*- coding: utf-8 -*-
+
+import os, tempfile
+from io import BytesIO
+from smb.SMBConnection import SMBConnection
+from smb.smb2_constants import SMB2_DIALECT_2
+from .util import getConnectionInfo
+from nose.tools import with_setup
+from smb import smb_structs
+
+try:
+    import hashlib
+    def MD5(): return hashlib.md5()
+except ImportError:
+    import md5
+    def MD5(): return md5.new()
+
+conn = None
+
+def setup_func_SMB1():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = False
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2():
+    global conn
+    smb_structs.SUPPORT_SMB2 = True
+    smb_structs.SUPPORT_SMB2x = False
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2x():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = True
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def teardown_func():
+    global conn
+    conn.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_retr_multiplereads_SMB1():
+    # Test file retrieval using multiple ReadAndx calls (assuming each call will not reach more than 65534 bytes)
+    global conn
+    temp_fh = BytesIO()
+    file_attributes, filesize = conn.retrieveFile('smbtest', '/rfc1001.txt', temp_fh)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '5367c2bbf97f521059c78eab65309ad3'
+    assert filesize == 158437
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_retr_multiplereads_SMB2():
+    # Test file retrieval using multiple ReadAndx calls (assuming each call will not reach more than 65534 bytes)
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    temp_fh = BytesIO()
+    file_attributes, filesize = conn.retrieveFile('smbtest', '/rfc1001.txt', temp_fh)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '5367c2bbf97f521059c78eab65309ad3'
+    assert filesize == 158437
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_retr_multiplereads_SMB2x():
+    # Test file retrieval using multiple ReadAndx calls (assuming each call will not reach more than 65534 bytes)
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    temp_fh = BytesIO()
+    file_attributes, filesize = conn.retrieveFile('smbtest', '/rfc1001.txt', temp_fh)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '5367c2bbf97f521059c78eab65309ad3'
+    assert filesize == 158437
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_retr_longfilename_SMB1():
+    # Test file retrieval that has a long English filename
+    global conn
+    temp_fh = BytesIO()
+    file_attributes, filesize = conn.retrieveFile('smbtest', '/Implementing CIFS - SMB.html', temp_fh)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '671c5700d279fcbbf958c1bba3c2639e'
+    assert filesize == 421269
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_retr_longfilename_SMB2():
+    # Test file retrieval that has a long English filename
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    temp_fh = BytesIO()
+    file_attributes, filesize = conn.retrieveFile('smbtest', '/Implementing CIFS - SMB.html', temp_fh)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '671c5700d279fcbbf958c1bba3c2639e'
+    assert filesize == 421269
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_retr_longfilename_SMB2x():
+    # Test file retrieval that has a long English filename
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    temp_fh = BytesIO()
+    file_attributes, filesize = conn.retrieveFile('smbtest', '/Implementing CIFS - SMB.html', temp_fh)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '671c5700d279fcbbf958c1bba3c2639e'
+    assert filesize == 421269
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_retr_unicodefilename_SMB1():
+    # Test file retrieval that has a long non-English filename inside a folder with a non-English name
+    global conn
+    temp_fh = BytesIO()
+    file_attributes, filesize = conn.retrieveFile('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '8a44c1e80d55e91c92350955cdf83442'
+    assert filesize == 256000
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_retr_unicodefilename_SMB2():
+    # Test file retrieval that has a long non-English filename inside a folder with a non-English name
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    temp_fh = BytesIO()
+    file_attributes, filesize = conn.retrieveFile('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '8a44c1e80d55e91c92350955cdf83442'
+    assert filesize == 256000
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_retr_unicodefilename_SMB2x():
+    # Test file retrieval that has a long non-English filename inside a folder with a non-English name
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    temp_fh = BytesIO()
+    file_attributes, filesize = conn.retrieveFile('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '8a44c1e80d55e91c92350955cdf83442'
+    assert filesize == 256000
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_retr_offset_SMB1():
+    # Test file retrieval from offset to EOF
+    global conn
+    temp_fh = BytesIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == 'a141bd8024571ce7cb5c67f2b0d8ea0b'
+    assert filesize == 156000
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_retr_offset_SMB2():
+    # Test file retrieval from offset to EOF
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    temp_fh = BytesIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == 'a141bd8024571ce7cb5c67f2b0d8ea0b'
+    assert filesize == 156000
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_retr_offset_SMB2x():
+    # Test file retrieval from offset to EOF
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    temp_fh = BytesIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == 'a141bd8024571ce7cb5c67f2b0d8ea0b'
+    assert filesize == 156000
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_retr_offset_and_biglimit_SMB1():
+    # Test file retrieval from offset with a big max_length
+    global conn
+    temp_fh = BytesIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000, max_length = 100000)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '83b7afd7c92cdece3975338b5ca0b1c5'
+    assert filesize == 100000
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_retr_offset_and_biglimit_SMB2():
+    # Test file retrieval from offset with a big max_length
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    temp_fh = BytesIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000, max_length = 100000)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '83b7afd7c92cdece3975338b5ca0b1c5'
+    assert filesize == 100000
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_retr_offset_and_biglimit_SMB2x():
+    # Test file retrieval from offset with a big max_length
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    temp_fh = BytesIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000, max_length = 100000)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '83b7afd7c92cdece3975338b5ca0b1c5'
+    assert filesize == 100000
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_retr_offset_and_smalllimit_SMB1():
+    # Test file retrieval from offset with a small max_length
+    global conn
+    temp_fh = BytesIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000, max_length = 10)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '746f60a96b39b712a7b6e17ddde19986'
+    assert filesize == 10
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_retr_offset_and_smalllimit_SMB2():
+    # Test file retrieval from offset with a small max_length
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    temp_fh = BytesIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000, max_length = 10)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '746f60a96b39b712a7b6e17ddde19986'
+    assert filesize == 10
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_retr_offset_and_smalllimit_SMB2x():
+    # Test file retrieval from offset with a small max_length
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    temp_fh = BytesIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000, max_length = 10)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '746f60a96b39b712a7b6e17ddde19986'
+    assert filesize == 10
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_retr_offset_and_zerolimit_SMB1():
+    # Test file retrieval from offset to EOF with max_length=0
+    global conn
+    temp_fh = BytesIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000, max_length = 0)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == 'd41d8cd98f00b204e9800998ecf8427e'
+    assert filesize == 0
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_retr_offset_and_zerolimit_SMB2():
+    # Test file retrieval from offset to EOF with max_length=0
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    temp_fh = BytesIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000, max_length = 0)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == 'd41d8cd98f00b204e9800998ecf8427e'
+    assert filesize == 0
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_retr_offset_and_zerolimit_SMB2x():
+    # Test file retrieval from offset to EOF with max_length=0
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    temp_fh = BytesIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000, max_length = 0)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == 'd41d8cd98f00b204e9800998ecf8427e'
+    assert filesize == 0
+
+    temp_fh.close()
diff --git a/python3/tests/DirectSMBConnectionTests/test_storefile.py b/python3/tests/DirectSMBConnectionTests/test_storefile.py
new file mode 100644
index 00000000..80365d11
--- /dev/null
+++ b/python3/tests/DirectSMBConnectionTests/test_storefile.py
@@ -0,0 +1,268 @@
+# -*- coding: utf-8 -*-
+
+import os, tempfile, random, time
+from io import BytesIO
+from smb.SMBConnection import SMBConnection
+from smb.smb2_constants import SMB2_DIALECT_2
+from .util import getConnectionInfo
+from nose.tools import with_setup
+from smb import smb_structs
+
+try:
+    import hashlib
+    def MD5(): return hashlib.md5()
+except ImportError:
+    import md5
+    def MD5(): return md5.new()
+
+conn = None
+
+TEST_FILENAME = os.path.join(os.path.dirname(__file__), os.pardir, 'SupportFiles', 'binary.dat')
+TEST_FILESIZE = 256000
+TEST_DIGEST = 'bb6303f76e29f354b6fdf6ef58587e48'
+
+def setup_func_SMB1():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = False
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2():
+    global conn
+    smb_structs.SUPPORT_SMB2 = True
+    smb_structs.SUPPORT_SMB2x = False
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2x():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = True
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True, is_direct_tcp = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def teardown_func():
+    global conn
+    conn.close()
+
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_store_long_filename_SMB1():
+    global conn
+    filename = os.sep + 'StoreTest %d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+
+    filesize = conn.storeFile('smbtest', filename, open(TEST_FILENAME, 'rb'))
+    assert filesize == TEST_FILESIZE
+
+    entries = conn.listPath('smbtest', os.path.dirname(filename.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(filename.replace('/', os.sep)) in filenames
+
+    buf = BytesIO()
+    file_attributes, file_size = conn.retrieveFile('smbtest', filename, buf)
+    assert file_size == TEST_FILESIZE
+
+    md = MD5()
+    md.update(buf.getvalue())
+    assert md.hexdigest() == TEST_DIGEST
+    buf.close()
+
+    conn.deleteFiles('smbtest', filename)
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_store_from_offset_SMB1():
+    global conn
+    filename = os.sep + 'StoreTest %d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+
+    buf = BytesIO(b'0123456789')
+    filesize = conn.storeFile('smbtest', filename, buf)
+    assert filesize == 10
+
+    buf = BytesIO(b'aa')
+    pos = conn.storeFileFromOffset('smbtest', filename, buf, 5)
+    assert pos == 7
+
+    buf = BytesIO()
+    file_attributes, file_size = conn.retrieveFile('smbtest', filename, buf)
+    assert file_size == 10
+    assert buf.getvalue() == b'01234aa789'
+    buf.close()
+
+    conn.deleteFiles('smbtest', filename)
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_store_long_filename_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    filename = os.sep + 'StoreTest %d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+
+    filesize = conn.storeFile('smbtest', filename, open(TEST_FILENAME, 'rb'))
+    assert filesize == TEST_FILESIZE
+
+    entries = conn.listPath('smbtest', os.path.dirname(filename.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(filename.replace('/', os.sep)) in filenames
+
+    buf = BytesIO()
+    file_attributes, file_size = conn.retrieveFile('smbtest', filename, buf)
+    assert file_size == TEST_FILESIZE
+
+    md = MD5()
+    md.update(buf.getvalue())
+    assert md.hexdigest() == TEST_DIGEST
+    buf.close()
+
+    conn.deleteFiles('smbtest', filename)
+
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_store_long_filename_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    filename = os.sep + 'StoreTest %d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+
+    filesize = conn.storeFile('smbtest', filename, open(TEST_FILENAME, 'rb'))
+    assert filesize == TEST_FILESIZE
+
+    entries = conn.listPath('smbtest', os.path.dirname(filename.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(filename.replace('/', os.sep)) in filenames
+
+    buf = BytesIO()
+    file_attributes, file_size = conn.retrieveFile('smbtest', filename, buf)
+    assert file_size == TEST_FILESIZE
+
+    md = MD5()
+    md.update(buf.getvalue())
+    assert md.hexdigest() == TEST_DIGEST
+    buf.close()
+
+    conn.deleteFiles('smbtest', filename)
+
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_store_unicode_filename_SMB1():
+    global conn
+    filename = os.sep + u'上载测试 %d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+
+    filesize = conn.storeFile('smbtest', filename, open(TEST_FILENAME, 'rb'))
+    assert filesize == TEST_FILESIZE
+
+    entries = conn.listPath('smbtest', os.path.dirname(filename.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(filename.replace('/', os.sep)) in filenames
+
+    buf = BytesIO()
+    file_attributes, file_size = conn.retrieveFile('smbtest', filename, buf)
+    assert file_size == TEST_FILESIZE
+
+    md = MD5()
+    md.update(buf.getvalue())
+    assert md.hexdigest() == TEST_DIGEST
+    buf.close()
+
+    conn.deleteFiles('smbtest', filename)
+
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_store_unicode_filename_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    filename = os.sep + u'上载测试 %d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+
+    filesize = conn.storeFile('smbtest', filename, open(TEST_FILENAME, 'rb'))
+    assert filesize == TEST_FILESIZE
+
+    entries = conn.listPath('smbtest', os.path.dirname(filename.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(filename.replace('/', os.sep)) in filenames
+
+    buf = BytesIO()
+    file_attributes, file_size = conn.retrieveFile('smbtest', filename, buf)
+    assert file_size == TEST_FILESIZE
+
+    md = MD5()
+    md.update(buf.getvalue())
+    assert md.hexdigest() == TEST_DIGEST
+    buf.close()
+
+    conn.deleteFiles('smbtest', filename)
+
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_store_unicode_filename_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    filename = os.sep + u'上载测试 %d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+
+    filesize = conn.storeFile('smbtest', filename, open(TEST_FILENAME, 'rb'))
+    assert filesize == TEST_FILESIZE
+
+    entries = conn.listPath('smbtest', os.path.dirname(filename.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(filename.replace('/', os.sep)) in filenames
+
+    buf = BytesIO()
+    file_attributes, file_size = conn.retrieveFile('smbtest', filename, buf)
+    assert file_size == TEST_FILESIZE
+
+    md = MD5()
+    md.update(buf.getvalue())
+    assert md.hexdigest() == TEST_DIGEST
+    buf.close()
+
+    conn.deleteFiles('smbtest', filename)
+
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_store_from_offset_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    filename = os.sep + 'StoreTest %d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+
+    buf = BytesIO(b'0123456789')
+    filesize = conn.storeFile('smbtest', filename, buf)
+    assert filesize == 10
+
+    buf = BytesIO(b'aa')
+    pos = conn.storeFileFromOffset('smbtest', filename, buf, 5)
+    assert pos == 7
+
+    buf = BytesIO()
+    file_attributes, file_size = conn.retrieveFile('smbtest', filename, buf)
+    assert file_size == 10
+    assert buf.getvalue() == b'01234aa789'
+    buf.close()
+
+    conn.deleteFiles('smbtest', filename)
+
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_store_from_offset_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    filename = os.sep + 'StoreTest %d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+
+    buf = BytesIO(b'0123456789')
+    filesize = conn.storeFile('smbtest', filename, buf)
+    assert filesize == 10
+
+    buf = BytesIO(b'aa')
+    pos = conn.storeFileFromOffset('smbtest', filename, buf, 5)
+    assert pos == 7
+
+    buf = BytesIO()
+    file_attributes, file_size = conn.retrieveFile('smbtest', filename, buf)
+    assert file_size == 10
+    assert buf.getvalue() == b'01234aa789'
+    buf.close()
+
+    conn.deleteFiles('smbtest', filename)
diff --git a/python3/tests/DirectSMBConnectionTests/util.py b/python3/tests/DirectSMBConnectionTests/util.py
new file mode 100644
index 00000000..0e1b1808
--- /dev/null
+++ b/python3/tests/DirectSMBConnectionTests/util.py
@@ -0,0 +1,19 @@
+
+import os
+from configparser import SafeConfigParser
+
+def getConnectionInfo():
+    config_filename = os.path.join(os.path.dirname(__file__), os.path.pardir, 'connection.ini')
+    cp = SafeConfigParser()
+    cp.read(config_filename)
+
+    info = {
+        'server_name': cp.get('server', 'name'),
+        'server_ip': cp.get('server', 'ip'),
+        'server_port': cp.getint('server', 'direct_port'),
+        'client_name': cp.get('client', 'name'),
+        'user': cp.get('user', 'name'),
+        'password': cp.get('user', 'password'),
+        'is_direct_tcp': True,
+    }
+    return info
diff --git a/python3/tests/NetBIOSTests/__init__.py b/python3/tests/NetBIOSTests/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/python3/tests/NetBIOSTests/test_queryname.py b/python3/tests/NetBIOSTests/test_queryname.py
new file mode 100644
index 00000000..a727cba4
--- /dev/null
+++ b/python3/tests/NetBIOSTests/test_queryname.py
@@ -0,0 +1,16 @@
+
+from nmb.NetBIOS import NetBIOS
+from nose.tools import with_setup
+
+conn = None
+
+def teardown_func():
+    global conn
+    conn.close()
+
+@with_setup(teardown = teardown_func)
+def test_broadcast():
+    global conn
+    conn = NetBIOS()
+    assert conn.queryName('MICHAEL-I5PC', timeout = 10)
+
diff --git a/python3/tests/README_1st.txt b/python3/tests/README_1st.txt
new file mode 100644
index 00000000..82c2ac8a
--- /dev/null
+++ b/python3/tests/README_1st.txt
@@ -0,0 +1,26 @@
+
+Steps to Follow to Run the Unit Tests
+=====================================
+
+1. Install Nose Testing Framework
+All the unit tests here are designed to be conducted with the nose testing framework.
+You can install the latest nose testing framework by running: easy_install nose
+For more information on nose testing, please visit http://readthedocs.org/docs/nose/en/latest/
+
+2. Prepare a Shared Folder "smbtest" on a Remote Server
+To run the unit tests here, besides installing the nose testing framework, you will
+also need to prepare a shared folder on a remote server.
+pysmb has been tested against Samba 3.x, Windows XP SP3 and Windows Vista.
+The shared folder must be named "smbtest".
+
+3. Download smbtest.zip from https://miketeo.net/files/Projects/pysmb/smbtest.zip
+Unzip the contents of this zip file in the shared folder.
+
+4. Update Connection Details in connection.ini
+In the same folder where you are viewing this readme file, there should be an ini file
+called "connection.ini". Edit this file's connection details to match the shared folder's
+access information.
+
+5. Run the Unit Tests in the python2 folder
+Just run: nosetests3 -v tests
+or selectively: nosetests3 -v tests/SMBConnectionTests
diff --git a/python3/tests/SMBConnectionTests/__init__.py b/python3/tests/SMBConnectionTests/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/python3/tests/SMBConnectionTests/test_SMBHandler.py b/python3/tests/SMBConnectionTests/test_SMBHandler.py
new file mode 100644
index 00000000..8fe5f022
--- /dev/null
+++ b/python3/tests/SMBConnectionTests/test_SMBHandler.py
@@ -0,0 +1,64 @@
+# -*- coding: utf-8 -*-
+
+import os, urllib.request, urllib.parse, urllib.error, urllib.request, urllib.error, urllib.parse, time, random
+from smb.SMBHandler import SMBHandler
+from . import util
+
+
+try:
+    import hashlib
+    def MD5(): return hashlib.md5()
+except ImportError:
+    import md5
+    def MD5(): return md5.new()
+
+
+
+def test_basic():
+    # Basic test for smb URLs
+    director = urllib.request.build_opener(SMBHandler)
+    fh = director.open('smb://%(user)s:%(password)s@%(server_ip)s/smbtest/rfc1001.txt' % util.getConnectionInfo())
+
+    s = fh.read()
+    md = MD5()
+    md.update(s)
+    assert md.hexdigest() == '5367c2bbf97f521059c78eab65309ad3'
+    assert len(s) == 158437
+
+    fh.close()
+
+
+def test_unicode():
+    # Test smb URLs with unicode paths
+    director = urllib.request.build_opener(SMBHandler)
+    fh = director.open('smb://%(user)s:%(password)s@%(server_ip)s/smbtest/测试文件夹/垃圾文件.dat' % util.getConnectionInfo())
+
+    s = fh.read()
+    md = MD5()
+    md.update(s)
+    assert md.hexdigest() == '8a44c1e80d55e91c92350955cdf83442'
+    assert len(s) == 256000
+
+    fh.close()
+
+
+
+TEST_FILENAME = os.path.join(os.path.dirname(__file__), os.pardir, 'SupportFiles', 'binary.dat')
+TEST_FILESIZE = 256000
+TEST_DIGEST = 'bb6303f76e29f354b6fdf6ef58587e48'
+
+def test_upload():
+    info = util.getConnectionInfo()
+    info['filename'] = os.sep + 'StoreTest-%d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+
+    director = urllib.request.build_opener(SMBHandler)
+    upload_fh = director.open('smb://%(user)s:%(password)s@%(server_ip)s/smbtest/%(filename)s' % info, data = open(TEST_FILENAME, 'rb'))
+
+    retr_fh = director.open('smb://%(user)s:%(password)s@%(server_ip)s/smbtest/%(filename)s' % info)
+
+    s = retr_fh.read()
+    md = MD5()
+    md.update(s)
+
+    assert md.hexdigest() == TEST_DIGEST
+    assert len(s) == TEST_FILESIZE
diff --git a/python3/tests/SMBConnectionTests/test_auth.py b/python3/tests/SMBConnectionTests/test_auth.py
new file mode 100644
index 00000000..2ca4510e
--- /dev/null
+++ b/python3/tests/SMBConnectionTests/test_auth.py
@@ -0,0 +1,72 @@
+
+from smb.SMBConnection import SMBConnection
+from .util import getConnectionInfo
+from nose.tools import with_setup
+from smb import smb_structs
+
+conn, conn2, conn3 = None, None, None
+
+def teardown_func():
+    global conn, conn2, conn3
+    if conn:
+        conn.close()
+    if conn2:
+        conn2.close()
+    if conn3:
+        conn3.close();
+
+@with_setup(teardown = teardown_func)
+def test_NTLMv1_auth_SMB1():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = False
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], domain = info['domain'], use_ntlm_v2 = False)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+    conn2 = SMBConnection(info['user'], 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = False)
+    assert not conn2.connect(info['server_ip'], info['server_port'])
+
+    conn3 = SMBConnection('INVALIDUSER', 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = False)
+    assert not conn3.connect(info['server_ip'], info['server_port'])
+
+@with_setup(teardown = teardown_func)
+def test_NTLMv2_auth_SMB1():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = False
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], domain = info['domain'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+    conn2 = SMBConnection(info['user'], 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert not conn2.connect(info['server_ip'], info['server_port'])
+
+    conn3 = SMBConnection('INVALIDUSER', 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert not conn3.connect(info['server_ip'], info['server_port'])
+
+@with_setup(teardown = teardown_func)
+def test_NTLMv1_auth_SMB2():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = True
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], domain = info['domain'], use_ntlm_v2 = False)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+    conn2 = SMBConnection(info['user'], 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = False)
+    assert not conn2.connect(info['server_ip'], info['server_port'])
+
+    conn3 = SMBConnection('INVALIDUSER', 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = False)
+    assert not conn3.connect(info['server_ip'], info['server_port'])
+
+@with_setup(teardown = teardown_func)
+def test_NTLMv2_auth_SMB2():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = True
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], domain = info['domain'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+    conn2 = SMBConnection(info['user'], 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert not conn2.connect(info['server_ip'], info['server_port'])
+
+    conn3 = SMBConnection('INVALIDUSER', 'wrongPass', info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert not conn3.connect(info['server_ip'], info['server_port'])
diff --git a/python3/tests/SMBConnectionTests/test_createdeletedirectory.py b/python3/tests/SMBConnectionTests/test_createdeletedirectory.py
new file mode 100644
index 00000000..5e128b13
--- /dev/null
+++ b/python3/tests/SMBConnectionTests/test_createdeletedirectory.py
@@ -0,0 +1,145 @@
+# -*- coding: utf-8 -*-
+
+import os, time, random
+from smb.SMBConnection import SMBConnection
+from smb.smb2_constants import SMB2_DIALECT_2
+from .util import getConnectionInfo
+from nose.tools import with_setup
+from smb import smb_structs
+
+conn = None
+
+def setup_func_SMB1():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = False
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2():
+    global conn
+    smb_structs.SUPPORT_SMB2 = True
+    smb_structs.SUPPORT_SMB2x = False
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2x():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = True
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def teardown_func():
+    global conn
+    conn.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_english_directory_SMB1():
+    global conn
+
+    path = os.sep + 'TestDir %d-%d' % ( time.time(), random.randint(0, 1000) )
+    conn.createDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) in names
+
+    conn.deleteDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) not in names
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_english_directory_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    path = os.sep + 'TestDir %d-%d' % ( time.time(), random.randint(0, 1000) )
+    conn.createDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) in names
+
+    conn.deleteDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) not in names
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_english_directory_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    path = os.sep + 'TestDir %d-%d' % ( time.time(), random.randint(0, 1000) )
+    conn.createDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) in names
+
+    conn.deleteDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) not in names
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_unicode_directory_SMB1():
+    global conn
+
+    path = os.sep + u'文件夹创建 %d-%d' % ( time.time(), random.randint(0, 1000) )
+    conn.createDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) in names
+
+    conn.deleteDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) not in names
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_unicode_directory_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    path = os.sep + u'文件夹创建 %d-%d' % ( time.time(), random.randint(0, 1000) )
+    conn.createDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) in names
+
+    conn.deleteDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) not in names
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_unicode_directory_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    path = os.sep + u'文件夹创建 %d-%d' % ( time.time(), random.randint(0, 1000) )
+    conn.createDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) in names
+
+    conn.deleteDirectory('smbtest', path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(path.replace('/', os.sep)))
+    names = map(lambda e: e.filename, entries)
+    assert os.path.basename(path.replace('/', os.sep)) not in names
diff --git a/python3/tests/SMBConnectionTests/test_deletepattern.py b/python3/tests/SMBConnectionTests/test_deletepattern.py
new file mode 100644
index 00000000..4e019654
--- /dev/null
+++ b/python3/tests/SMBConnectionTests/test_deletepattern.py
@@ -0,0 +1,153 @@
+# -*- coding: utf-8 -*-
+
+import os, time, random
+from io import BytesIO
+from smb.SMBConnection import SMBConnection
+from smb.smb2_constants import SMB2_DIALECT_2
+from .util import getConnectionInfo
+from nose.tools import with_setup
+from smb import smb_structs
+
+conn = None
+
+def setup_func_SMB1():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = False
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2():
+    global conn
+    smb_structs.SUPPORT_SMB2 = True
+    smb_structs.SUPPORT_SMB2x = False
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2x():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = True
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def teardown_func():
+    global conn
+    conn.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_delete_SMB1():
+    global conn
+
+    path = os.sep + u'testDelete %d-%d' % ( time.time(), random.randint(0, 1000) )
+    conn.createDirectory('smbtest', path)
+
+    for filename in [ 'aaTest.txt', 'aaBest.txt', 'aaTest.bin', 'aaBest.bin', 'random.txt' ]:
+        conn.storeFile('smbtest', path+"/"+filename, BytesIO(b"0123456789"))
+
+    results = conn.listPath('smbtest', path)
+    filenames = list(map(lambda r: r.filename, results))
+    assert 'aaTest.txt' in filenames
+    assert 'aaBest.txt' in filenames
+    assert 'aaTest.bin' in filenames
+    assert 'aaBest.bin' in filenames
+    assert 'random.txt' in filenames
+
+    conn.deleteFiles('smbtest', path+'/aa*.txt')
+
+    results = conn.listPath('smbtest', path)
+    filenames = list(map(lambda r: r.filename, results))
+    assert 'aaTest.txt' not in filenames
+    assert 'aaBest.txt' not in filenames
+    assert 'aaTest.bin' in filenames
+    assert 'aaBest.bin' in filenames
+    assert 'random.txt' in filenames
+
+    conn.deleteFiles('smbtest', path+'/aaTest.*')
+
+    results = conn.listPath('smbtest', path)
+    filenames = list(map(lambda r: r.filename, results))
+    assert 'aaTest.bin' not in filenames
+    assert 'aaBest.bin' in filenames
+    assert 'random.txt' in filenames
+
+    conn.deleteFiles('smbtest', path+'/*')
+    conn.deleteDirectory('smbtest', path)
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_delete_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    path = os.sep + u'testDelete %d-%d' % ( time.time(), random.randint(0, 1000) )
+    conn.createDirectory('smbtest', path)
+
+    for filename in [ 'aaTest.txt', 'aaBest.txt', 'aaTest.bin', 'aaBest.bin', 'random.txt' ]:
+        conn.storeFile('smbtest', path+"/"+filename, BytesIO(b"0123456789"))
+
+    results = conn.listPath('smbtest', path)
+    filenames = list(map(lambda r: r.filename, results))
+    assert 'aaTest.txt' in filenames
+    assert 'aaBest.txt' in filenames
+    assert 'aaTest.bin' in filenames
+    assert 'aaBest.bin' in filenames
+    assert 'random.txt' in filenames
+
+    conn.deleteFiles('smbtest', path+'/aa*.txt')
+
+    results = conn.listPath('smbtest', path)
+    filenames = list(map(lambda r: r.filename, results))
+    assert 'aaTest.txt' not in filenames
+    assert 'aaBest.txt' not in filenames
+    assert 'aaTest.bin' in filenames
+    assert 'aaBest.bin' in filenames
+    assert 'random.txt' in filenames
+
+    conn.deleteFiles('smbtest', path+'/aaTest.*')
+
+    results = conn.listPath('smbtest', path)
+    filenames = list(map(lambda r: r.filename, results))
+    assert 'aaTest.bin' not in filenames
+    assert 'aaBest.bin' in filenames
+    assert 'random.txt' in filenames
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_delete_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    path = os.sep + u'testDelete %d-%d' % ( time.time(), random.randint(0, 1000) )
+    conn.createDirectory('smbtest', path)
+
+    for filename in [ 'aaTest.txt', 'aaBest.txt', 'aaTest.bin', 'aaBest.bin', 'random.txt' ]:
+        conn.storeFile('smbtest', path+"/"+filename, BytesIO(b"0123456789"))
+
+    results = conn.listPath('smbtest', path)
+    filenames = list(map(lambda r: r.filename, results))
+    assert 'aaTest.txt' in filenames
+    assert 'aaBest.txt' in filenames
+    assert 'aaTest.bin' in filenames
+    assert 'aaBest.bin' in filenames
+    assert 'random.txt' in filenames
+
+    conn.deleteFiles('smbtest', path+'/aa*.txt')
+
+    results = conn.listPath('smbtest', path)
+    filenames = list(map(lambda r: r.filename, results))
+    assert 'aaTest.txt' not in filenames
+    assert 'aaBest.txt' not in filenames
+    assert 'aaTest.bin' in filenames
+    assert 'aaBest.bin' in filenames
+    assert 'random.txt' in filenames
+
+    conn.deleteFiles('smbtest', path+'/aaTest.*')
+
+    results = conn.listPath('smbtest', path)
+    filenames = list(map(lambda r: r.filename, results))
+    assert 'aaTest.bin' not in filenames
+    assert 'aaBest.bin' in filenames
+    assert 'random.txt' in filenames
diff --git a/python3/tests/SMBConnectionTests/test_echo.py b/python3/tests/SMBConnectionTests/test_echo.py
new file mode 100644
index 00000000..c81675d6
--- /dev/null
+++ b/python3/tests/SMBConnectionTests/test_echo.py
@@ -0,0 +1,24 @@
+
+import random
+from smb.SMBConnection import SMBConnection
+from .util import getConnectionInfo
+from nose.tools import with_setup
+
+conn = None
+
+def setup_func():
+    global conn
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def teardown_func():
+    global conn
+    conn.close()
+
+@with_setup(setup_func, teardown_func)
+def test_echo():
+    global conn
+
+    data = bytearray('%d' % random.randint(1000, 9999), 'ascii')
+    assert conn.echo(data) == data
diff --git a/python3/tests/SMBConnectionTests/test_getattributes.py b/python3/tests/SMBConnectionTests/test_getattributes.py
new file mode 100644
index 00000000..2ec57a52
--- /dev/null
+++ b/python3/tests/SMBConnectionTests/test_getattributes.py
@@ -0,0 +1,84 @@
+# -*- coding: utf-8 -*-
+
+from smb.SMBConnection import SMBConnection
+from smb.smb2_constants import SMB2_DIALECT_2
+from .util import getConnectionInfo
+from nose.tools import with_setup
+from smb import smb_structs
+
+conn = None
+
+def setup_func_SMB1():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = False
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2():
+    global conn
+    smb_structs.SUPPORT_SMB2 = True
+    smb_structs.SUPPORT_SMB2x = False
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2x():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = True
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def teardown_func():
+    global conn
+    conn.close()
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_getAttributes_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    info = conn.getAttributes('smbtest', '/Test Folder with Long Name/')
+    assert info.isDirectory
+
+    info = conn.getAttributes('smbtest', '/rfc1001.txt')
+    assert not info.isDirectory
+    assert info.file_size == 158437
+    assert info.alloc_size == 159744
+
+    info = conn.getAttributes('smbtest', u'/\u6d4b\u8bd5\u6587\u4ef6\u5939')
+    assert info.isDirectory
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_getAttributes_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    info = conn.getAttributes('smbtest', '/Test Folder with Long Name/')
+    assert info.isDirectory
+
+    info = conn.getAttributes('smbtest', '/rfc1001.txt')
+    assert not info.isDirectory
+    assert info.file_size == 158437
+    assert info.alloc_size == 159744
+
+    info = conn.getAttributes('smbtest', u'/\u6d4b\u8bd5\u6587\u4ef6\u5939')
+    assert info.isDirectory
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_getAttributes_SMB1():
+    global conn
+    info = conn.getAttributes('smbtest', '/Test Folder with Long Name/')
+    assert info.isDirectory
+
+    info = conn.getAttributes('smbtest', '/rfc1001.txt')
+    assert not info.isDirectory
+    assert info.file_size == 158437
+    assert info.alloc_size == 159744
+
+    info = conn.getAttributes('smbtest', u'/\u6d4b\u8bd5\u6587\u4ef6\u5939')
+    assert info.isDirectory
diff --git a/python3/tests/SMBConnectionTests/test_listpath.py b/python3/tests/SMBConnectionTests/test_listpath.py
new file mode 100644
index 00000000..56e32a7f
--- /dev/null
+++ b/python3/tests/SMBConnectionTests/test_listpath.py
@@ -0,0 +1,209 @@
+# -*- coding: utf-8 -*-
+
+from smb.SMBConnection import SMBConnection
+from smb.smb_constants import *
+from smb.smb2_constants import SMB2_DIALECT_2
+from .util import getConnectionInfo
+from nose.tools import with_setup
+from smb import smb_structs
+
+conn = None
+
+def setup_func_SMB1():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = False
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2():
+    global conn
+    smb_structs.SUPPORT_SMB2 = True
+    smb_structs.SUPPORT_SMB2x = False
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2x():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = True
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def teardown_func():
+    global conn
+    conn.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_listPath_SMB1():
+    global conn
+    results = conn.listPath('smbtest', '/')
+    filenames = list(map(lambda r: ( r.filename, r.isDirectory ), results))
+    assert ( u'\u6d4b\u8bd5\u6587\u4ef6\u5939', True ) in filenames  # Test non-English folder names
+    assert ( u'Test Folder with Long Name', True ) in filenames      # Test long English folder names
+    assert ( u'TestDir1', True ) in filenames                        # Test short English folder names
+    assert ( u'Implementing CIFS - SMB.html', False ) in filenames   # Test long English file names
+    assert ( u'rfc1001.txt', False ) in filenames                    # Test short English file names
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_listSubPath_SMB1():
+    global conn
+    results = conn.listPath('smbtest', '/Test Folder with Long Name/')
+    filenames = list(map(lambda r: ( r.filename, r.isDirectory ), results))
+    assert ( u'Test File.txt', False ) in filenames
+    assert ( u'Test Folder', True ) in filenames
+    assert ( u'子文件夹', True ) in filenames
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_listPathWithManyFiles_SMB1():
+    global conn
+    results = conn.listPath('smbtest', '/RFC Archive/')
+    filenames = list(map(lambda r: ( r.filename, r.isDirectory ), results))
+    assert len(filenames)==999
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_listPathWithManyFiles_SMB1():
+    global conn
+    results = conn.listPath('smbtest', '/RFC Archive/')
+    filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+    assert len(list(filenames))==999
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_listPath_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+    results = conn.listPath('smbtest', '/')
+    filenames = list(map(lambda r: ( r.filename, r.isDirectory ), results))
+    assert ( u'\u6d4b\u8bd5\u6587\u4ef6\u5939', True ) in filenames  # Test non-English folder names
+    assert ( u'Test Folder with Long Name', True ) in filenames      # Test long English folder names
+    assert ( u'TestDir1', True ) in filenames                        # Test short English folder names
+    assert ( u'Implementing CIFS - SMB.html', False ) in filenames   # Test long English file names
+    assert ( u'rfc1001.txt', False ) in filenames                    # Test short English file names
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_listPath_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+    results = conn.listPath('smbtest', '/')
+    filenames = list(map(lambda r: ( r.filename, r.isDirectory ), results))
+    assert ( u'\u6d4b\u8bd5\u6587\u4ef6\u5939', True ) in filenames  # Test non-English folder names
+    assert ( u'Test Folder with Long Name', True ) in filenames      # Test long English folder names
+    assert ( u'TestDir1', True ) in filenames                        # Test short English folder names
+    assert ( u'Implementing CIFS - SMB.html', False ) in filenames   # Test long English file names
+    assert ( u'rfc1001.txt', False ) in filenames                    # Test short English file names
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_listSubPath_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+    results = conn.listPath('smbtest', '/Test Folder with Long Name/')
+    filenames = list(map(lambda r: ( r.filename, r.isDirectory ), results))
+    assert ( u'Test File.txt', False ) in filenames
+    assert ( u'Test Folder', True ) in filenames
+    assert ( u'子文件夹', True ) in filenames
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_listSubPath_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+    results = conn.listPath('smbtest', '/Test Folder with Long Name/')
+    filenames = [( r.filename, r.isDirectory ) for r in results]
+    assert ( 'Test File.txt', False ) in filenames
+    assert ( 'Test Folder', True ) in filenames
+    assert ( '子文件夹', True ) in filenames
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_listPathWithManyFiles_SMB2():
+    global conn
+    results = conn.listPath('smbtest', '/RFC Archive/')
+    filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+    assert len(list(filenames))==999
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_listPathFilterForDirectory_SMB1():
+    global conn
+    results = conn.listPath('smbtest', '/Test Folder with Long Name', search = SMB_FILE_ATTRIBUTE_DIRECTORY)
+    filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+    assert len(list(filenames)) > 0
+    for f, isDirectory in filenames:
+        assert isDirectory
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_listPathFilterForDirectory_SMB2():
+    global conn
+    results = conn.listPath('smbtest', '/Test Folder with Long Name', search = SMB_FILE_ATTRIBUTE_DIRECTORY)
+    filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+    assert len(list(filenames)) > 0
+    for f, isDirectory in filenames:
+        assert isDirectory
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_listPathFilterForFiles_SMB1():
+    global conn
+    results = conn.listPath('smbtest', '/Test Folder with Long Name', search = SMB_FILE_ATTRIBUTE_READONLY | SMB_FILE_ATTRIBUTE_HIDDEN | SMB_FILE_ATTRIBUTE_SYSTEM | SMB_FILE_ATTRIBUTE_ARCHIVE | SMB_FILE_ATTRIBUTE_INCL_NORMAL)
+    filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+    assert len(list(filenames)) > 0
+    for f, isDirectory in filenames:
+        assert not isDirectory
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_listPathFilterForFiles_SMB2():
+    global conn
+    results = conn.listPath('smbtest', '/Test Folder with Long Name', search = SMB_FILE_ATTRIBUTE_READONLY | SMB_FILE_ATTRIBUTE_HIDDEN | SMB_FILE_ATTRIBUTE_SYSTEM | SMB_FILE_ATTRIBUTE_ARCHIVE | SMB_FILE_ATTRIBUTE_INCL_NORMAL)
+    filenames = map(lambda r: ( r.filename, r.isDirectory ), results)
+    assert len(list(filenames)) > 0
+    for f, isDirectory in filenames:
+        assert not isDirectory
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_listPathFilterPattern_SMB1():
+    global conn
+    results = conn.listPath('smbtest', '/Test Folder with Long Name', pattern = 'Test*')
+    filenames = list(map(lambda r: ( r.filename, r.isDirectory ), results))
+    assert len(filenames) == 2
+    assert ( u'Test File.txt', False ) in filenames
+    assert ( u'Test Folder', True ) in filenames
+    assert ( u'子文件夹', True ) not in filenames
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_listPathFilterPattern_SMB2():
+    global conn
+    results = conn.listPath('smbtest', '/Test Folder with Long Name', pattern = 'Test*')
+    filenames = list(map(lambda r: ( r.filename, r.isDirectory ), results))
+    assert len(filenames) == 2
+    assert ( u'Test File.txt', False ) in filenames
+    assert ( u'Test Folder', True ) in filenames
+    assert ( u'子文件夹', True ) not in filenames
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_listPathFilterUnicodePattern_SMB1():
+    global conn
+    results = conn.listPath('smbtest', '/Test Folder with Long Name', pattern = u'*件夹')
+    filenames = list(map(lambda r: ( r.filename, r.isDirectory ), results))
+    assert len(filenames) == 1
+    assert ( u'Test File.txt', False ) not in filenames
+    assert ( u'Test Folder', True ) not in filenames
+    assert ( u'子文件夹', True ) in filenames
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_listPathFilterUnicodePattern_SMB2():
+    global conn
+    results = conn.listPath('smbtest', '/Test Folder with Long Name', pattern = u'*件夹')
+    filenames = list(map(lambda r: ( r.filename, r.isDirectory ), results))
+    assert len(filenames) == 1
+    assert ( u'Test File.txt', False ) not in filenames
+    assert ( u'Test Folder', True ) not in filenames
+    assert ( u'子文件夹', True ) in filenames
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_listPathFilterEmptyList_SMB1():
+    global conn
+    results = conn.listPath('smbtest', '/RFC Archive', pattern = '*.abc')
+    filenames = list(map(lambda r: ( r.filename, r.isDirectory ), results))
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_listPathFilterEmptyList_SMB2():
+    global conn
+    results = conn.listPath('smbtest', '/RFC Archive', pattern = '*.abc')
+    filenames = list(map(lambda r: ( r.filename, r.isDirectory ), results))
diff --git a/python3/tests/SMBConnectionTests/test_listshares.py b/python3/tests/SMBConnectionTests/test_listshares.py
new file mode 100644
index 00000000..b79d2f43
--- /dev/null
+++ b/python3/tests/SMBConnectionTests/test_listshares.py
@@ -0,0 +1,54 @@
+
+from smb.SMBConnection import SMBConnection
+from smb.smb2_constants import SMB2_DIALECT_2
+from .util import getConnectionInfo
+from nose.tools import with_setup
+from smb import smb_structs
+
+conn = None
+
+def setup_func_SMB1():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = False
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2():
+    global conn
+    smb_structs.SUPPORT_SMB2 = True
+    smb_structs.SUPPORT_SMB2x = False
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2x():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = True
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def teardown_func():
+    global conn
+    conn.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_listshares_SMB1():
+    global conn
+    results = conn.listShares()
+    assert 'smbtest' in list(map(lambda r: r.name.lower(), results))
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_listshares_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+    results = conn.listShares()
+    assert 'smbtest' in list(map(lambda r: r.name.lower(), results))
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_listshares_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+    results = conn.listShares()
+    assert 'smbtest' in list(map(lambda r: r.name.lower(), results))
diff --git a/python3/tests/SMBConnectionTests/test_listsnapshots.py b/python3/tests/SMBConnectionTests/test_listsnapshots.py
new file mode 100644
index 00000000..ebb5f3d8
--- /dev/null
+++ b/python3/tests/SMBConnectionTests/test_listsnapshots.py
@@ -0,0 +1,57 @@
+
+from smb.SMBConnection import SMBConnection
+from smb.smb2_constants import SMB2_DIALECT_2
+from .util import getConnectionInfo
+from nose.tools import with_setup
+from smb import smb_structs
+
+conn = None
+
+def setup_func_SMB1():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = False
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2():
+    global conn
+    smb_structs.SUPPORT_SMB2 = True
+    smb_structs.SUPPORT_SMB2x = False
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2x():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = True
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def teardown_func():
+    global conn
+    conn.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_listsnapshots_SMB1():
+    global conn
+    results = conn.listSnapshots('smbtest', '/rfc1001.txt')
+    assert len(results) > 0
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_listsnapshots_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+    results = conn.listSnapshots('smbtest', '/rfc1001.txt')
+    assert len(results) > 0
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_listsnapshots_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+    results = conn.listSnapshots('smbtest', '/rfc1001.txt')
+    assert len(results) > 0
diff --git a/python3/tests/SMBConnectionTests/test_rename.py b/python3/tests/SMBConnectionTests/test_rename.py
new file mode 100644
index 00000000..1aa07b53
--- /dev/null
+++ b/python3/tests/SMBConnectionTests/test_rename.py
@@ -0,0 +1,321 @@
+# -*- coding: utf-8 -*-
+
+import os, time, random
+from io import BytesIO
+from smb.SMBConnection import SMBConnection
+from smb.smb2_constants import SMB2_DIALECT_2
+from .util import getConnectionInfo
+from nose.tools import with_setup
+from smb import smb_structs
+
+conn = None
+
+def setup_func_SMB1():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = False
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2():
+    global conn
+    smb_structs.SUPPORT_SMB2 = True
+    smb_structs.SUPPORT_SMB2x = False
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2x():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = True
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def teardown_func():
+    global conn
+    conn.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_rename_english_file_SMB1():
+    global conn
+
+    old_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    new_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.storeFile('smbtest', old_path, BytesIO(b'Rename file test'))
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteFiles('smbtest', new_path)
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_rename_english_file_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    old_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    new_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.storeFile('smbtest', old_path, BytesIO(b'Rename file test'))
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteFiles('smbtest', new_path)
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_rename_english_file_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    old_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    new_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.storeFile('smbtest', old_path, BytesIO(b'Rename file test'))
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteFiles('smbtest', new_path)
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_rename_unicode_file_SMB1():
+    global conn
+
+    old_path = u'/改名测试 %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    new_path = u'/改名测试 %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.storeFile('smbtest', old_path, BytesIO(b'Rename file test'))
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteFiles('smbtest', new_path)
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_rename_unicode_file_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    old_path = u'/改名测试 %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    new_path = u'/改名测试 %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.storeFile('smbtest', old_path, BytesIO(b'Rename file test'))
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteFiles('smbtest', new_path)
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_rename_unicode_file_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    old_path = u'/改名测试 %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    new_path = u'/改名测试 %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.storeFile('smbtest', old_path, BytesIO(b'Rename file test'))
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteFiles('smbtest', new_path)
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_rename_english_directory_SMB1():
+    global conn
+
+    old_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    new_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.createDirectory('smbtest', old_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteDirectory('smbtest', new_path)
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_rename_english_directory_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    old_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    new_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.createDirectory('smbtest', old_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteDirectory('smbtest', new_path)
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_rename_english_directory_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    old_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+    new_path = '/RenameTest %d-%d.txt' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.createDirectory('smbtest', old_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteDirectory('smbtest', new_path)
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_rename_unicode_directory_SMB1():
+    global conn
+
+    old_path = u'/改名测试 %d-%d' % ( time.time(), random.randint(1000, 9999) )
+    new_path = u'/改名测试 %d-%d' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.createDirectory('smbtest', old_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteDirectory('smbtest', new_path)
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_rename_unicode_directory_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    old_path = u'/改名测试 %d-%d' % ( time.time(), random.randint(1000, 9999) )
+    new_path = u'/改名测试 %d-%d' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.createDirectory('smbtest', old_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteDirectory('smbtest', new_path)
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_rename_unicode_directory_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    old_path = u'/改名测试 %d-%d' % ( time.time(), random.randint(1000, 9999) )
+    new_path = u'/改名测试 %d-%d' % ( time.time(), random.randint(1000, 9999) )
+
+    conn.createDirectory('smbtest', old_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) not in filenames
+
+    conn.rename('smbtest', old_path, new_path)
+
+    entries = conn.listPath('smbtest', os.path.dirname(old_path.replace('/', os.sep)))
+    filenames = list(map(lambda e: e.filename, entries))
+    assert os.path.basename(old_path.replace('/', os.sep)) not in filenames
+    assert os.path.basename(new_path.replace('/', os.sep)) in filenames
+
+    conn.deleteDirectory('smbtest', new_path)
diff --git a/python3/tests/SMBConnectionTests/test_retrievefile.py b/python3/tests/SMBConnectionTests/test_retrievefile.py
new file mode 100644
index 00000000..537dadc0
--- /dev/null
+++ b/python3/tests/SMBConnectionTests/test_retrievefile.py
@@ -0,0 +1,369 @@
+# -*- coding: utf-8 -*-
+
+import os, tempfile
+from io import BytesIO
+from smb.SMBConnection import SMBConnection
+from smb.smb2_constants import SMB2_DIALECT_2
+from .util import getConnectionInfo
+from nose.tools import with_setup
+from smb import smb_structs
+
+try:
+    import hashlib
+    def MD5(): return hashlib.md5()
+except ImportError:
+    import md5
+    def MD5(): return md5.new()
+
+conn = None
+
+def setup_func_SMB1():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = False
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2():
+    global conn
+    smb_structs.SUPPORT_SMB2 = True
+    smb_structs.SUPPORT_SMB2x = False
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2x():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = True
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def teardown_func():
+    global conn
+    conn.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_retr_multiplereads_SMB1():
+    # Test file retrieval using multiple ReadAndx calls (assuming each call will not reach more than 65534 bytes)
+    global conn
+    temp_fh = BytesIO()
+    file_attributes, filesize = conn.retrieveFile('smbtest', '/rfc1001.txt', temp_fh)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '5367c2bbf97f521059c78eab65309ad3'
+    assert filesize == 158437
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_retr_multiplereads_SMB2():
+    # Test file retrieval using multiple ReadAndx calls (assuming each call will not reach more than 65534 bytes)
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    temp_fh = BytesIO()
+    file_attributes, filesize = conn.retrieveFile('smbtest', '/rfc1001.txt', temp_fh)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '5367c2bbf97f521059c78eab65309ad3'
+    assert filesize == 158437
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_retr_multiplereads_SMB2x():
+    # Test file retrieval using multiple ReadAndx calls (assuming each call will not reach more than 65534 bytes)
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    temp_fh = BytesIO()
+    file_attributes, filesize = conn.retrieveFile('smbtest', '/rfc1001.txt', temp_fh)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '5367c2bbf97f521059c78eab65309ad3'
+    assert filesize == 158437
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_retr_longfilename_SMB1():
+    # Test file retrieval that has a long English filename
+    global conn
+    temp_fh = BytesIO()
+    file_attributes, filesize = conn.retrieveFile('smbtest', '/Implementing CIFS - SMB.html', temp_fh)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '671c5700d279fcbbf958c1bba3c2639e'
+    assert filesize == 421269
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_retr_longfilename_SMB2():
+    # Test file retrieval that has a long English filename
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    temp_fh = BytesIO()
+    file_attributes, filesize = conn.retrieveFile('smbtest', '/Implementing CIFS - SMB.html', temp_fh)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '671c5700d279fcbbf958c1bba3c2639e'
+    assert filesize == 421269
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_retr_longfilename_SMB2x():
+    # Test file retrieval that has a long English filename
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    temp_fh = BytesIO()
+    file_attributes, filesize = conn.retrieveFile('smbtest', '/Implementing CIFS - SMB.html', temp_fh)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '671c5700d279fcbbf958c1bba3c2639e'
+    assert filesize == 421269
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_retr_unicodefilename_SMB1():
+    # Test file retrieval that has a long non-English filename inside a folder with a non-English name
+    global conn
+    temp_fh = BytesIO()
+    file_attributes, filesize = conn.retrieveFile('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '8a44c1e80d55e91c92350955cdf83442'
+    assert filesize == 256000
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_retr_unicodefilename_SMB2():
+    # Test file retrieval that has a long non-English filename inside a folder with a non-English name
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    temp_fh = BytesIO()
+    file_attributes, filesize = conn.retrieveFile('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '8a44c1e80d55e91c92350955cdf83442'
+    assert filesize == 256000
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_retr_unicodefilename_SMB2x():
+    # Test file retrieval that has a long non-English filename inside a folder with a non-English name
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    temp_fh = BytesIO()
+    file_attributes, filesize = conn.retrieveFile('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '8a44c1e80d55e91c92350955cdf83442'
+    assert filesize == 256000
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_retr_offset_SMB1():
+    # Test file retrieval from offset to EOF
+    global conn
+    temp_fh = BytesIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == 'a141bd8024571ce7cb5c67f2b0d8ea0b'
+    assert filesize == 156000
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_retr_offset_SMB2():
+    # Test file retrieval from offset to EOF
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    temp_fh = BytesIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == 'a141bd8024571ce7cb5c67f2b0d8ea0b'
+    assert filesize == 156000
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_retr_offset_SMB2x():
+    # Test file retrieval from offset to EOF
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    temp_fh = BytesIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == 'a141bd8024571ce7cb5c67f2b0d8ea0b'
+    assert filesize == 156000
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_retr_offset_and_biglimit_SMB1():
+    # Test file retrieval from offset with a big max_length
+    global conn
+    temp_fh = BytesIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000, max_length = 100000)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '83b7afd7c92cdece3975338b5ca0b1c5'
+    assert filesize == 100000
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_retr_offset_and_biglimit_SMB2():
+    # Test file retrieval from offset with a big max_length
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    temp_fh = BytesIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000, max_length = 100000)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '83b7afd7c92cdece3975338b5ca0b1c5'
+    assert filesize == 100000
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_retr_offset_and_biglimit_SMB2x():
+    # Test file retrieval from offset with a big max_length
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    temp_fh = BytesIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000, max_length = 100000)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '83b7afd7c92cdece3975338b5ca0b1c5'
+    assert filesize == 100000
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_retr_offset_and_smalllimit_SMB1():
+    # Test file retrieval from offset with a small max_length
+    global conn
+    temp_fh = BytesIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000, max_length = 10)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '746f60a96b39b712a7b6e17ddde19986'
+    assert filesize == 10
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_retr_offset_and_smalllimit_SMB2():
+    # Test file retrieval from offset with a small max_length
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    temp_fh = BytesIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000, max_length = 10)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '746f60a96b39b712a7b6e17ddde19986'
+    assert filesize == 10
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_retr_offset_and_smalllimit_SMB2x():
+    # Test file retrieval from offset with a small max_length
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    temp_fh = BytesIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000, max_length = 10)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == '746f60a96b39b712a7b6e17ddde19986'
+    assert filesize == 10
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_retr_offset_and_zerolimit_SMB1():
+    # Test file retrieval from offset to EOF with max_length=0
+    global conn
+    temp_fh = BytesIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000, max_length = 0)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == 'd41d8cd98f00b204e9800998ecf8427e'
+    assert filesize == 0
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_retr_offset_and_zerolimit_SMB2():
+    # Test file retrieval from offset to EOF with max_length=0
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    temp_fh = BytesIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000, max_length = 0)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == 'd41d8cd98f00b204e9800998ecf8427e'
+    assert filesize == 0
+
+    temp_fh.close()
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_retr_offset_and_zerolimit_SMB2x():
+    # Test file retrieval from offset to EOF with max_length=0
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    temp_fh = BytesIO()
+    file_attributes, filesize = conn.retrieveFileFromOffset('smbtest', u'/测试文件夹/垃圾文件.dat', temp_fh, offset = 100000, max_length = 0)
+
+    md = MD5()
+    md.update(temp_fh.getvalue())
+    assert md.hexdigest() == 'd41d8cd98f00b204e9800998ecf8427e'
+    assert filesize == 0
+
+    temp_fh.close()
diff --git a/python3/tests/SMBConnectionTests/test_security.py b/python3/tests/SMBConnectionTests/test_security.py
new file mode 100644
index 00000000..d582f5c9
--- /dev/null
+++ b/python3/tests/SMBConnectionTests/test_security.py
@@ -0,0 +1,52 @@
+# -*- coding: utf-8 -*-
+
+import os, tempfile
+from smb.SMBConnection import SMBConnection
+from smb.smb2_constants import SMB2_DIALECT_2
+from .util import getConnectionInfo
+from nose.tools import with_setup
+from smb import smb_structs
+
+try:
+    import hashlib
+    def MD5(): return hashlib.md5()
+except ImportError:
+    import md5
+    def MD5(): return md5.new()
+
+conn = None
+
+def setup_func_SMB2():
+    global conn
+    smb_structs.SUPPORT_SMB2 = True
+    smb_structs.SUPPORT_SMB2x = False
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2x():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = True
+
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def teardown_func():
+    global conn
+    conn.close()
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_security_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+    # TODO: Need a way to setup the environment on the remote server and perform some verification on the returned results.
+    attributes = conn.getSecurity('smbtest', '/rfc1001.txt')
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_security_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+    # TODO: Need a way to setup the environment on the remote server and perform some verification on the returned results.
+    attributes = conn.getSecurity('smbtest', '/rfc1001.txt')
diff --git a/python3/tests/SMBConnectionTests/test_storefile.py b/python3/tests/SMBConnectionTests/test_storefile.py
new file mode 100644
index 00000000..fd2c24a1
--- /dev/null
+++ b/python3/tests/SMBConnectionTests/test_storefile.py
@@ -0,0 +1,268 @@
+# -*- coding: utf-8 -*-
+
+import os, tempfile, random, time
+from io import BytesIO
+from smb.SMBConnection import SMBConnection
+from smb.smb2_constants import SMB2_DIALECT_2
+from .util import getConnectionInfo
+from nose.tools import with_setup
+from smb import smb_structs
+
+try:
+    import hashlib
+    def MD5(): return hashlib.md5()
+except ImportError:
+    import md5
+    def MD5(): return md5.new()
+
+conn = None
+
+TEST_FILENAME = os.path.join(os.path.dirname(__file__), os.pardir, 'SupportFiles', 'binary.dat')
+TEST_FILESIZE = 256000
+TEST_DIGEST = 'bb6303f76e29f354b6fdf6ef58587e48'
+
+def setup_func_SMB1():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = False
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2():
+    global conn
+    smb_structs.SUPPORT_SMB2 = True
+    smb_structs.SUPPORT_SMB2x = False
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def setup_func_SMB2x():
+    global conn
+    smb_structs.SUPPORT_SMB2 = smb_structs.SUPPORT_SMB2x = True
+    info = getConnectionInfo()
+    conn = SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True)
+    assert conn.connect(info['server_ip'], info['server_port'])
+
+def teardown_func():
+    global conn
+    conn.close()
+
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_store_long_filename_SMB1():
+    global conn
+    filename = os.sep + 'StoreTest %d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+
+    filesize = conn.storeFile('smbtest', filename, open(TEST_FILENAME, 'rb'))
+    assert filesize == TEST_FILESIZE
+
+    entries = conn.listPath('smbtest', os.path.dirname(filename.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(filename.replace('/', os.sep)) in filenames
+
+    buf = BytesIO()
+    file_attributes, file_size = conn.retrieveFile('smbtest', filename, buf)
+    assert file_size == TEST_FILESIZE
+
+    md = MD5()
+    md.update(buf.getvalue())
+    assert md.hexdigest() == TEST_DIGEST
+    buf.close()
+
+    conn.deleteFiles('smbtest', filename)
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_store_from_offset_SMB1():
+    global conn
+    filename = os.sep + 'StoreTest %d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+
+    buf = BytesIO(b'0123456789')
+    filesize = conn.storeFile('smbtest', filename, buf)
+    assert filesize == 10
+
+    buf = BytesIO(b'aa')
+    pos = conn.storeFileFromOffset('smbtest', filename, buf, 5)
+    assert pos == 7
+
+    buf = BytesIO()
+    file_attributes, file_size = conn.retrieveFile('smbtest', filename, buf)
+    assert file_size == 10
+    assert buf.getvalue() == b'01234aa789'
+    buf.close()
+
+    conn.deleteFiles('smbtest', filename)
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_store_long_filename_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    filename = os.sep + 'StoreTest %d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+
+    filesize = conn.storeFile('smbtest', filename, open(TEST_FILENAME, 'rb'))
+    assert filesize == TEST_FILESIZE
+
+    entries = conn.listPath('smbtest', os.path.dirname(filename.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(filename.replace('/', os.sep)) in filenames
+
+    buf = BytesIO()
+    file_attributes, file_size = conn.retrieveFile('smbtest', filename, buf)
+    assert file_size == TEST_FILESIZE
+
+    md = MD5()
+    md.update(buf.getvalue())
+    assert md.hexdigest() == TEST_DIGEST
+    buf.close()
+
+    conn.deleteFiles('smbtest', filename)
+
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_store_long_filename_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    filename = os.sep + 'StoreTest %d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+
+    filesize = conn.storeFile('smbtest', filename, open(TEST_FILENAME, 'rb'))
+    assert filesize == TEST_FILESIZE
+
+    entries = conn.listPath('smbtest', os.path.dirname(filename.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(filename.replace('/', os.sep)) in filenames
+
+    buf = BytesIO()
+    file_attributes, file_size = conn.retrieveFile('smbtest', filename, buf)
+    assert file_size == TEST_FILESIZE
+
+    md = MD5()
+    md.update(buf.getvalue())
+    assert md.hexdigest() == TEST_DIGEST
+    buf.close()
+
+    conn.deleteFiles('smbtest', filename)
+
+
+@with_setup(setup_func_SMB1, teardown_func)
+def test_store_unicode_filename_SMB1():
+    global conn
+    filename = os.sep + u'上载测试 %d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+
+    filesize = conn.storeFile('smbtest', filename, open(TEST_FILENAME, 'rb'))
+    assert filesize == TEST_FILESIZE
+
+    entries = conn.listPath('smbtest', os.path.dirname(filename.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(filename.replace('/', os.sep)) in filenames
+
+    buf = BytesIO()
+    file_attributes, file_size = conn.retrieveFile('smbtest', filename, buf)
+    assert file_size == TEST_FILESIZE
+
+    md = MD5()
+    md.update(buf.getvalue())
+    assert md.hexdigest() == TEST_DIGEST
+    buf.close()
+
+    conn.deleteFiles('smbtest', filename)
+
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_store_unicode_filename_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    filename = os.sep + u'上载测试 %d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+
+    filesize = conn.storeFile('smbtest', filename, open(TEST_FILENAME, 'rb'))
+    assert filesize == TEST_FILESIZE
+
+    entries = conn.listPath('smbtest', os.path.dirname(filename.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(filename.replace('/', os.sep)) in filenames
+
+    buf = BytesIO()
+    file_attributes, file_size = conn.retrieveFile('smbtest', filename, buf)
+    assert file_size == TEST_FILESIZE
+
+    md = MD5()
+    md.update(buf.getvalue())
+    assert md.hexdigest() == TEST_DIGEST
+    buf.close()
+
+    conn.deleteFiles('smbtest', filename)
+
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_store_unicode_filename_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    filename = os.sep + u'上载测试 %d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+
+    filesize = conn.storeFile('smbtest', filename, open(TEST_FILENAME, 'rb'))
+    assert filesize == TEST_FILESIZE
+
+    entries = conn.listPath('smbtest', os.path.dirname(filename.replace('/', os.sep)))
+    filenames = map(lambda e: e.filename, entries)
+    assert os.path.basename(filename.replace('/', os.sep)) in filenames
+
+    buf = BytesIO()
+    file_attributes, file_size = conn.retrieveFile('smbtest', filename, buf)
+    assert file_size == TEST_FILESIZE
+
+    md = MD5()
+    md.update(buf.getvalue())
+    assert md.hexdigest() == TEST_DIGEST
+    buf.close()
+
+    conn.deleteFiles('smbtest', filename)
+
+
+@with_setup(setup_func_SMB2, teardown_func)
+def test_store_from_offset_SMB2():
+    global conn
+    assert conn.smb2_dialect == SMB2_DIALECT_2
+
+    filename = os.sep + 'StoreTest %d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+
+    buf = BytesIO(b'0123456789')
+    filesize = conn.storeFile('smbtest', filename, buf)
+    assert filesize == 10
+
+    buf = BytesIO(b'aa')
+    pos = conn.storeFileFromOffset('smbtest', filename, buf, 5)
+    assert pos == 7
+
+    buf = BytesIO()
+    file_attributes, file_size = conn.retrieveFile('smbtest', filename, buf)
+    assert file_size == 10
+    assert buf.getvalue() == b'01234aa789'
+    buf.close()
+
+    conn.deleteFiles('smbtest', filename)
+
+
+@with_setup(setup_func_SMB2x, teardown_func)
+def test_store_from_offset_SMB2x():
+    global conn
+    assert conn.smb2_dialect != SMB2_DIALECT_2
+
+    filename = os.sep + 'StoreTest %d-%d.dat' % ( time.time(), random.randint(0, 10000) )
+
+    buf = BytesIO(b'0123456789')
+    filesize = conn.storeFile('smbtest', filename, buf)
+    assert filesize == 10
+
+    buf = BytesIO(b'aa')
+    pos = conn.storeFileFromOffset('smbtest', filename, buf, 5)
+    assert pos == 7
+
+    buf = BytesIO()
+    file_attributes, file_size = conn.retrieveFile('smbtest', filename, buf)
+    assert file_size == 10
+    assert buf.getvalue() == b'01234aa789'
+    buf.close()
+
+    conn.deleteFiles('smbtest', filename)
diff --git a/python3/tests/SMBConnectionTests/test_with_context.py b/python3/tests/SMBConnectionTests/test_with_context.py
new file mode 100644
index 00000000..58d95677
--- /dev/null
+++ b/python3/tests/SMBConnectionTests/test_with_context.py
@@ -0,0 +1,11 @@
+# -*- coding: utf-8 -*-
+
+from smb.SMBConnection import SMBConnection
+from .util import getConnectionInfo
+
+def test_context():
+    info = getConnectionInfo()
+    with SMBConnection(info['user'], info['password'], info['client_name'], info['server_name'], use_ntlm_v2 = True) as conn:
+        assert conn.connect(info['server_ip'], info['server_port'])
+
+    assert conn.sock is None
diff --git a/python3/tests/SMBConnectionTests/util.py b/python3/tests/SMBConnectionTests/util.py
new file mode 100644
index 00000000..debf3bbe
--- /dev/null
+++ b/python3/tests/SMBConnectionTests/util.py
@@ -0,0 +1,19 @@
+
+import os
+from configparser import SafeConfigParser
+
+def getConnectionInfo():
+    config_filename = os.path.join(os.path.dirname(__file__), os.path.pardir, 'connection.ini')
+    cp = SafeConfigParser()
+    cp.read(config_filename)
+
+    info = {
+        'server_name': cp.get('server', 'name'),
+        'server_ip': cp.get('server', 'ip'),
+        'server_port': cp.getint('server', 'port'),
+        'client_name': cp.get('client', 'name'),
+        'user': cp.get('user', 'name'),
+        'password': cp.get('user', 'password'),
+        'domain': cp.get('user', 'domain')
+    }
+    return info
diff --git a/python3/tests/SupportFiles/binary.dat b/python3/tests/SupportFiles/binary.dat
new file mode 100644
index 00000000..f2b3f581
Binary files /dev/null and b/python3/tests/SupportFiles/binary.dat differ
diff --git a/python3/tests/__init__.py b/python3/tests/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/python3/tests/connection.ini b/python3/tests/connection.ini
new file mode 100644
index 00000000..d8d249de
--- /dev/null
+++ b/python3/tests/connection.ini
@@ -0,0 +1,14 @@
+
+[server]
+name = SERVER
+ip = 192.168.1.1
+port = 139
+direct_port = 445
+
+[client]
+name = TESTCLIENT
+
+[user]
+name = myuser
+password = mypassword
+domain =
diff --git a/python3/tests/test_ntlm.py b/python3/tests/test_ntlm.py
new file mode 100644
index 00000000..d7351565
--- /dev/null
+++ b/python3/tests/test_ntlm.py
@@ -0,0 +1,47 @@
+
+import binascii
+from smb import ntlm
+
+def test_NTLMv1_without_extended_security():
+    password = 'Password'
+    server_challenge = b'\x01\x23\x45\x67\x89\xab\xcd\xef'
+
+    nt_challenge_response, lm_challenge_response, session_key = ntlm.generateChallengeResponseV1(password,
+                                                                                                 server_challenge,
+                                                                                                 has_extended_security = False,
+                                                                                                 client_challenge = b'\xAA'*8)
+
+    assert binascii.hexlify(nt_challenge_response).lower() == b'67 c4 30 11 f3 02 98 a2 ad 35 ec e6 4f 16 33 1c 44 bd be d9 27 84 1f 94'.replace(b' ', b'')  # [MS-NLMP]: 4.2.2.2.1
+    assert binascii.hexlify(lm_challenge_response).lower() == b'98 de f7 b8 7f 88 aa 5d af e2 df 77 96 88 a1 72 de f1 1c 7d 5c cd ef 13'.replace(b' ', b'')  # [MS-NLMP]: 4.2.2.2.2
+
+
+def test_NTLMv1_with_extended_security():
+    password = 'Password'
+    server_challenge = b'\x01\x23\x45\x67\x89\xab\xcd\xef'
+
+    nt_challenge_response, lm_challenge_response, session_key = ntlm.generateChallengeResponseV1(password,
+                                                                                                 server_challenge,
+                                                                                                 has_extended_security = True,
+                                                                                                 client_challenge = b'\xAA'*8)
+
+    assert binascii.hexlify(nt_challenge_response).lower() == b'75 37 f8 03 ae 36 71 28 ca 45 82 04 bd e7 ca f8 1e 97 ed 26 83 26 72 32'.replace(b' ', b'')  # [MS-NLMP]: 4.2.3.2.2
+    assert binascii.hexlify(lm_challenge_response).lower() == b'aa aa aa aa aa aa aa aa 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00'.replace(b' ', b'')  # [MS-NLMP]: 4.2.3.2.1
+
+
+def test_NTLMv2():
+    user = 'User'
+    password = 'Password'
+    domain = 'Domain'
+    server_challenge = b'\x01\x23\x45\x67\x89\xab\xcd\xef'
+
+    server_avpair = binascii.unhexlify(b'01 00 0c 00 53 00 65 00 72 00 76 00 65 00 72 00'.replace(b' ', b''))
+    domain_avpair = binascii.unhexlify(b'02 00 0c 00 44 00 6f 00 6d 00 61 00 69 00 6e 00'.replace(b' ', b''))
+
+    nt_challenge_response, lm_challenge_response, session_key = ntlm.generateChallengeResponseV2(password,
+                                                                                                 user,
+                                                                                                 server_challenge,
+                                                                                                 server_avpair + domain_avpair + b'\0'*4,
+                                                                                                 domain,
+                                                                                                 client_challenge = b'\xAA'*8)
+
+    assert binascii.hexlify(lm_challenge_response).lower() == b'86 c3 50 97 ac 9c ec 10 25 54 76 4a 57 cc cc 19 aa aa aa aa aa aa aa aa'.replace(b' ', b'')  # [MS-NLMP]: 4.2.4.2.1
diff --git a/python3/tests/test_security_descriptors.py b/python3/tests/test_security_descriptors.py
new file mode 100644
index 00000000..7a87a849
--- /dev/null
+++ b/python3/tests/test_security_descriptors.py
@@ -0,0 +1,139 @@
+import binascii
+
+from smb import security_descriptors as sd
+from smb import smb_constants as sc
+
+
+def test_sid_string_representation():
+    sid = sd.SID(1, 5, [2, 3, 4])
+    assert str(sid) == "S-1-5-2-3-4"
+    sid = sd.SID(1, 2**32 + 3, [])
+    assert str(sid) == "S-1-0x100000003"
+    sid = sd.SID(1, 2**32, [3, 2, 1])
+    assert str(sid) == "S-1-0x100000000-3-2-1"
+
+
+def test_sid_binary_parsing():
+    raw_sid = binascii.unhexlify(b"""
+        01 05 00 00 00 00 00 05  15 00 00 00 de 53 c1 2a
+        2a 4f da ca c1 79 a6 32  b1 04 00 00
+    """.translate(None, b' \n'))
+    assert str(sd.SID.from_bytes(raw_sid)) == "S-1-5-21-717312990-3403304746-849770945-1201"
+    raw_sid += b"garbage"
+    assert str(sd.SID.from_bytes(raw_sid)) == "S-1-5-21-717312990-3403304746-849770945-1201"
+    sid, tail = sd.SID.from_bytes(raw_sid, return_tail=True)
+    assert str(sid) == "S-1-5-21-717312990-3403304746-849770945-1201"
+    assert tail == b"garbage"
+
+
+def test_ace_binary_parsing():
+    raw_ace = binascii.unhexlify(b"""
+        00 10 24 00 ff 01 1f 00  01 05 00 00 00 00 00 05
+        15 00 00 00 de 53 c1 2a  2a 4f da ca c1 79 a6 32
+        6e 04 00 00
+    """.translate(None, b' \n'))
+    ace = sd.ACE.from_bytes(raw_ace)
+    assert str(ace.sid) == "S-1-5-21-717312990-3403304746-849770945-1134"
+    assert ace.type == sd.ACE_TYPE_ACCESS_ALLOWED
+    assert ace.flags == sd.ACE_FLAG_INHERITED
+    assert ace.mask == (sc.SYNCHRONIZE | sc.WRITE_OWNER | sc.WRITE_DAC
+                        | sc.READ_CONTROL | sc.DELETE | sc.FILE_READ_DATA
+                        | sc.FILE_WRITE_DATA | sc.FILE_APPEND_DATA
+                        | sc.FILE_READ_EA | sc.FILE_WRITE_EA | sc.FILE_EXECUTE
+                        | sc.FILE_DELETE_CHILD | sc.FILE_READ_ATTRIBUTES
+                        | sc.FILE_WRITE_ATTRIBUTES)
+    assert not ace.additional_data
+
+    raw_ace = binascii.unhexlify(b"""
+        00 13 18 00 a9 00 12 00  01 02 00 00 00 00 00 05
+        20 00 00 00 21 02 00 00
+    """.translate(None, b' \n'))
+    ace = sd.ACE.from_bytes(raw_ace)
+    assert str(ace.sid) == "S-1-5-32-545"
+    assert ace.type == sd.ACE_TYPE_ACCESS_ALLOWED
+    assert ace.flags == (sd.ACE_FLAG_INHERITED | sd.ACE_FLAG_CONTAINER_INHERIT
+                         | sd.ACE_FLAG_OBJECT_INHERIT)
+    assert ace.mask == (sc.SYNCHRONIZE | sc.READ_CONTROL | sc.FILE_READ_DATA
+                        | sc.FILE_READ_EA | sc.FILE_EXECUTE
+                        | sc.FILE_READ_ATTRIBUTES)
+    assert not ace.additional_data
+
+    raw_ace = binascii.unhexlify(b"""
+        01 03 24 00 a9 00 02 00  01 05 00 00 00 00 00 05
+        15 00 00 00 de 53 c1 2a  2a 4f da ca c1 79 a6 32
+        6c 04 00 00
+    """.translate(None, b' \n'))
+    ace = sd.ACE.from_bytes(raw_ace)
+    assert str(ace.sid) == "S-1-5-21-717312990-3403304746-849770945-1132"
+    assert ace.type == sd.ACE_TYPE_ACCESS_DENIED
+    assert ace.flags == (sd.ACE_FLAG_CONTAINER_INHERIT
+                         | sd.ACE_FLAG_OBJECT_INHERIT)
+    assert ace.mask == (sc.READ_CONTROL | sc.FILE_READ_DATA | sc.FILE_READ_EA
+                        | sc.FILE_EXECUTE | sc.FILE_READ_ATTRIBUTES)
+    assert not ace.additional_data
+
+
+def test_acl_binary_parsing():
+    raw_acl = binascii.unhexlify(b"""
+        02 00 70 00 04 00 00 00  00 10 18 00 89 00 10 00
+        01 02 00 00 00 00 00 05  20 00 00 00 21 02 00 00
+        00 10 14 00 ff 01 1f 00  01 01 00 00 00 00 00 05
+        12 00 00 00 00 10 18 00  ff 01 1f 00 01 02 00 00
+        00 00 00 05 20 00 00 00  20 02 00 00 00 10 24 00
+        ff 01 1f 00 01 05 00 00  00 00 00 05 15 00 00 00
+        de 53 c1 2a 2a 4f da ca  c1 79 a6 32 b1 04 00 00
+    """.translate(None, b' \n'))
+    acl = sd.ACL.from_bytes(raw_acl)
+    assert acl.revision == 2
+    assert len(acl.aces) == 4
+
+    ace = acl.aces[0]
+    assert ace.type == sd.ACE_TYPE_ACCESS_ALLOWED
+    assert str(ace.sid) == "S-1-5-32-545"
+    assert ace.flags == sd.ACE_FLAG_INHERITED
+    assert ace.mask == (sc.SYNCHRONIZE | sc.FILE_READ_DATA | sc.FILE_READ_EA
+                        | sc.FILE_READ_ATTRIBUTES)
+
+    ace = acl.aces[3]
+    assert ace.type == sd.ACE_TYPE_ACCESS_ALLOWED
+    assert str(ace.sid) == "S-1-5-21-717312990-3403304746-849770945-1201"
+    assert ace.flags == sd.ACE_FLAG_INHERITED
+    assert ace.mask == (sc.SYNCHRONIZE | sc.WRITE_OWNER | sc.WRITE_DAC
+                        | sc.READ_CONTROL | sc.DELETE | sc.FILE_READ_DATA
+                        | sc.FILE_WRITE_DATA | sc.FILE_APPEND_DATA
+                        | sc.FILE_READ_EA | sc.FILE_WRITE_EA | sc.FILE_EXECUTE
+                        | sc.FILE_DELETE_CHILD | sc.FILE_READ_ATTRIBUTES
+                        | sc.FILE_WRITE_ATTRIBUTES)
+
+
+def test_descriptor_binary_parsing():
+    raw_descriptor = binascii.unhexlify(b"""
+        01 00 04 84 14 00 00 00  30 00 00 00 00 00 00 00
+        4c 00 00 00 01 05 00 00  00 00 00 05 15 00 00 00
+        de 53 c1 2a 2a 4f da ca  c1 79 a6 32 b1 04 00 00
+        01 05 00 00 00 00 00 05  15 00 00 00 de 53 c1 2a
+        2a 4f da ca c1 79 a6 32  01 02 00 00 02 00 70 00
+        04 00 00 00 00 10 18 00  89 00 10 00 01 02 00 00
+        00 00 00 05 20 00 00 00  21 02 00 00 00 10 14 00
+        ff 01 1f 00 01 01 00 00  00 00 00 05 12 00 00 00
+        00 10 18 00 ff 01 1f 00  01 02 00 00 00 00 00 05
+        20 00 00 00 20 02 00 00  00 10 24 00 ff 01 1f 00
+        01 05 00 00 00 00 00 05  15 00 00 00 de 53 c1 2a
+        2a 4f da ca c1 79 a6 32  b1 04 00 00
+    """.translate(None, b' \n'))
+    descriptor = sd.SecurityDescriptor.from_bytes(raw_descriptor)
+    assert descriptor.flags == (sd.SECURITY_DESCRIPTOR_SELF_RELATIVE
+                                | sd.SECURITY_DESCRIPTOR_DACL_PRESENT
+                                | sd.SECURITY_DESCRIPTOR_DACL_AUTO_INHERITED)
+    assert descriptor.dacl is not None
+    assert descriptor.sacl is None
+    assert str(descriptor.owner) == "S-1-5-21-717312990-3403304746-849770945-1201"
+    assert str(descriptor.group) == "S-1-5-21-717312990-3403304746-849770945-513"
+
+    acl = descriptor.dacl
+    assert acl.revision == 2
+    assert len(acl.aces) == 4
+    assert str(acl.aces[0].sid) == sd.SID_BUILTIN_USERS
+    assert str(acl.aces[1].sid) == sd.SID_LOCAL_SYSTEM
+    assert str(acl.aces[2].sid) == sd.SID_BUILTIN_ADMINISTRATORS
+    assert str(acl.aces[3].sid) == "S-1-5-21-717312990-3403304746-849770945-1201"
diff --git a/python3/tests/test_securityblob.py b/python3/tests/test_securityblob.py
new file mode 100644
index 00000000..fa0b99df
--- /dev/null
+++ b/python3/tests/test_securityblob.py
@@ -0,0 +1,91 @@
+
+import binascii
+from smb import securityblob
+
+
+def test_NTLMSSP_NEGOTIATE_encoding():
+    ntlm_data = binascii.unhexlify(b'4e544c4d5353500001000000978208e200000000000000000000000000000000060072170000000f')  # The NTLM negotiate message
+    blob = securityblob.generateNegotiateSecurityBlob(ntlm_data)
+
+    TARGET = binascii.unhexlify(b"""
+60 48 06 06 2b 06 01 05 05 02 a0 3e 30 3c a0 0e
+30 0c 06 0a 2b 06 01 04 01 82 37 02 02 0a a2 2a
+04 28 4e 54 4c 4d 53 53 50 00 01 00 00 00 97 82
+08 e2 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+00 00 06 00 72 17 00 00 00 0f
+""".replace(b' ', b'').replace(b'\n', b''))
+
+    assert blob == TARGET
+
+
+def test_NTLMSSP_CHALLENGE_decoding():
+    blob = binascii.unhexlify(b"""
+a1 81 be 30 81 bb a0 03 0a 01 01 a1 0c 06 0a 2b
+06 01 04 01 82 37 02 02 0a a2 81 a5 04 81 a2 4e
+54 4c 4d 53 53 50 00 02 00 00 00 0a 00 0a 00 38
+00 00 00 15 82 8a e2 32 81 ce 29 7f de 3f 80 00
+00 00 00 00 00 00 00 60 00 60 00 42 00 00 00 06
+01 00 00 00 00 00 0f 43 00 45 00 54 00 55 00 53
+00 02 00 0a 00 43 00 45 00 54 00 55 00 53 00 01
+00 0a 00 43 00 45 00 54 00 55 00 53 00 04 00 16
+00 6c 00 6f 00 63 00 61 00 6c 00 64 00 6f 00 6d
+00 61 00 69 00 6e 00 03 00 22 00 63 00 65 00 74
+00 75 00 73 00 2e 00 6c 00 6f 00 63 00 61 00 6c
+00 64 00 6f 00 6d 00 61 00 69 00 6e 00 00 00 00
+00""".replace(b' ', b'').replace(b'\n', b''))
+
+    RESPONSE_TOKENS = binascii.unhexlify(b"""
+4e 54 4c 4d 53 53 50 00 02 00 00 00 0a 00 0a 00
+38 00 00 00 15 82 8a e2 32 81 ce 29 7f de 3f 80
+00 00 00 00 00 00 00 00 60 00 60 00 42 00 00 00
+06 01 00 00 00 00 00 0f 43 00 45 00 54 00 55 00
+53 00 02 00 0a 00 43 00 45 00 54 00 55 00 53 00
+01 00 0a 00 43 00 45 00 54 00 55 00 53 00 04 00
+16 00 6c 00 6f 00 63 00 61 00 6c 00 64 00 6f 00
+6d 00 61 00 69 00 6e 00 03 00 22 00 63 00 65 00
+74 00 75 00 73 00 2e 00 6c 00 6f 00 63 00 61 00
+6c 00 64 00 6f 00 6d 00 61 00 69 00 6e 00 00 00
+00 00
+""".replace(b' ', b'').replace(b'\n', b''))
+
+    result, response_tokens = securityblob.decodeChallengeSecurityBlob(blob)
+
+    assert result == securityblob.RESULT_ACCEPT_INCOMPLETE
+    assert response_tokens == RESPONSE_TOKENS
+
+
+def test_NTLMSSP_AUTH_encoding():
+    ntlm_data = binascii.unhexlify(b"""
+4e 54 4c 4d 53 53 50 00 03 00 00 00 01 00 01 00
+70 00 00 00 00 00 00 00 71 00 00 00 00 00 00 00
+58 00 00 00 00 00 00 00 58 00 00 00 18 00 18 00
+58 00 00 00 10 00 10 00 71 00 00 00 15 8a 88 e2
+06 00 72 17 00 00 00 0f 06 49 3b c4 f6 2a 2b be
+61 a6 81 e7 cc 58 37 b4 4d 00 49 00 43 00 48 00
+41 00 45 00 4c 00 2d 00 49 00 35 00 50 00 43 00
+00 a7 0d b4 74 c3 d8 14 c9 df 3d 80 6d 87 94 42
+bc
+""".replace(b' ', b'').replace(b'\n', b''))
+
+    TARGET = binascii.unhexlify(b"""
+a1 81 8a 30 81 87 a2 81 84 04 81 81 4e 54 4c 4d
+53 53 50 00 03 00 00 00 01 00 01 00 70 00 00 00
+00 00 00 00 71 00 00 00 00 00 00 00 58 00 00 00
+00 00 00 00 58 00 00 00 18 00 18 00 58 00 00 00
+10 00 10 00 71 00 00 00 15 8a 88 e2 06 00 72 17
+00 00 00 0f 06 49 3b c4 f6 2a 2b be 61 a6 81 e7
+cc 58 37 b4 4d 00 49 00 43 00 48 00 41 00 45 00
+4c 00 2d 00 49 00 35 00 50 00 43 00 00 a7 0d b4
+74 c3 d8 14 c9 df 3d 80 6d 87 94 42 bc
+""".replace(b' ', b'').replace(b'\n', b''))
+
+    blob = securityblob.generateAuthSecurityBlob(ntlm_data)
+
+    assert blob == TARGET
+
+
+def test_auth_response_decoding():
+    blob = binascii.unhexlify(b"a1 07 30 05 a0 03 0a 01 00".replace(b' ', b''))
+
+    result = securityblob.decodeAuthResponseSecurityBlob(blob)
+    assert result == securityblob.RESULT_ACCEPT_COMPLETED
diff --git a/setup.cfg b/setup.cfg
new file mode 100644
index 00000000..861a9f55
--- /dev/null
+++ b/setup.cfg
@@ -0,0 +1,5 @@
+[egg_info]
+tag_build = 
+tag_date = 0
+tag_svn_revision = 0
+
diff --git a/setup.py b/setup.py
new file mode 100644
index 00000000..e746e949
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,36 @@
+import sys, os
+try:
+    from setuptools import setup
+except ImportError:
+    from distutils.core import setup
+
+pkgdir = { '': 'python%s' % sys.version_info[0] }
+
+setup(
+    name = "pysmb",
+    version = "1.1.26",
+    author = "Michael Teo",
+    author_email = "miketeo@miketeo.net",
+    license = "zlib/libpng",
+    description = "pysmb is an experimental SMB/CIFS library written in Python to support file sharing between Windows and Linux machines",
+    keywords = "windows samba cifs sharing ftp smb linux",
+    url = "https://miketeo.net/projects/pysmb",
+    package_dir = pkgdir,
+    packages = [ 'smb', 'smb.utils', 'nmb' ],
+    install_requires = [ 'pyasn1' ],
+    long_description="""pysmb is an experimental SMB/CIFS library written in Python. It implements the client-side SMB/CIFS protocol which allows your Python application to access and transfer files to/from SMB/CIFS shared folders like your Windows file sharing and Samba folders.""",
+    classifiers = [
+        "Development Status :: 5 - Production/Stable",
+        "Environment :: Win32 (MS Windows)",
+        "Environment :: Console",
+        "License :: OSI Approved :: zlib/libpng License",
+        "Operating System :: Microsoft :: Windows",
+        "Operating System :: POSIX",
+        "Programming Language :: Python",
+        "Programming Language :: Python :: 2.7",
+        "Programming Language :: Python :: 3",
+        "Topic :: Communications :: File Sharing",
+        "Topic :: Software Development :: Libraries :: Python Modules",
+        "Topic :: System :: Networking",
+    ],
+)
diff --git a/sphinx/Makefile b/sphinx/Makefile
new file mode 100644
index 00000000..052d1aa6
--- /dev/null
+++ b/sphinx/Makefile
@@ -0,0 +1,153 @@
+# Makefile for Sphinx documentation
+#
+
+# You can set these variables from the command line.
+SPHINXOPTS    =
+SPHINXBUILD   = sphinx-build
+PAPER         =
+BUILDDIR      = ../docs
+
+# Internal variables.
+PAPEROPT_a4     = -D latex_paper_size=a4
+PAPEROPT_letter = -D latex_paper_size=letter
+ALLSPHINXOPTS   = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source
+# the i18n builder cannot share the environment and doctrees with the others
+I18NSPHINXOPTS  = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source
+
+.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext
+
+help:
+	@echo "Please use \`make <target>' where <target> is one of"
+	@echo "  html       to make standalone HTML files"
+	@echo "  dirhtml    to make HTML files named index.html in directories"
+	@echo "  singlehtml to make a single large HTML file"
+	@echo "  pickle     to make pickle files"
+	@echo "  json       to make JSON files"
+	@echo "  htmlhelp   to make HTML files and a HTML help project"
+	@echo "  qthelp     to make HTML files and a qthelp project"
+	@echo "  devhelp    to make HTML files and a Devhelp project"
+	@echo "  epub       to make an epub"
+	@echo "  latex      to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
+	@echo "  latexpdf   to make LaTeX files and run them through pdflatex"
+	@echo "  text       to make text files"
+	@echo "  man        to make manual pages"
+	@echo "  texinfo    to make Texinfo files"
+	@echo "  info       to make Texinfo files and run them through makeinfo"
+	@echo "  gettext    to make PO message catalogs"
+	@echo "  changes    to make an overview of all changed/added/deprecated items"
+	@echo "  linkcheck  to check all external links for integrity"
+	@echo "  doctest    to run all doctests embedded in the documentation (if enabled)"
+
+clean:
+	-rm -rf $(BUILDDIR)/*
+
+html:
+	$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
+	@echo
+	@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
+
+dirhtml:
+	$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
+	@echo
+	@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
+
+singlehtml:
+	$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
+	@echo
+	@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
+
+pickle:
+	$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
+	@echo
+	@echo "Build finished; now you can process the pickle files."
+
+json:
+	$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
+	@echo
+	@echo "Build finished; now you can process the JSON files."
+
+htmlhelp:
+	$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
+	@echo
+	@echo "Build finished; now you can run HTML Help Workshop with the" \
+	      ".hhp project file in $(BUILDDIR)/htmlhelp."
+
+qthelp:
+	$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
+	@echo
+	@echo "Build finished; now you can run "qcollectiongenerator" with the" \
+	      ".qhcp project file in $(BUILDDIR)/qthelp, like this:"
+	@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/pysmb.qhcp"
+	@echo "To view the help file:"
+	@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/pysmb.qhc"
+
+devhelp:
+	$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
+	@echo
+	@echo "Build finished."
+	@echo "To view the help file:"
+	@echo "# mkdir -p $$HOME/.local/share/devhelp/pysmb"
+	@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/pysmb"
+	@echo "# devhelp"
+
+epub:
+	$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
+	@echo
+	@echo "Build finished. The epub file is in $(BUILDDIR)/epub."
+
+latex:
+	$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
+	@echo
+	@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
+	@echo "Run \`make' in that directory to run these through (pdf)latex" \
+	      "(use \`make latexpdf' here to do that automatically)."
+
+latexpdf:
+	$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
+	@echo "Running LaTeX files through pdflatex..."
+	$(MAKE) -C $(BUILDDIR)/latex all-pdf
+	@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
+
+text:
+	$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
+	@echo
+	@echo "Build finished. The text files are in $(BUILDDIR)/text."
+
+man:
+	$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
+	@echo
+	@echo "Build finished. The manual pages are in $(BUILDDIR)/man."
+
+texinfo:
+	$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
+	@echo
+	@echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
+	@echo "Run \`make' in that directory to run these through makeinfo" \
+	      "(use \`make info' here to do that automatically)."
+
+info:
+	$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
+	@echo "Running Texinfo files through makeinfo..."
+	make -C $(BUILDDIR)/texinfo info
+	@echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
+
+gettext:
+	$(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
+	@echo
+	@echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
+
+changes:
+	$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
+	@echo
+	@echo "The overview file is in $(BUILDDIR)/changes."
+
+linkcheck:
+	$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
+	@echo
+	@echo "Link check complete; look for any errors in the above output " \
+	      "or in $(BUILDDIR)/linkcheck/output.txt."
+
+doctest:
+	$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
+	@echo "Testing of doctests in the sources finished, look at the " \
+	      "results in $(BUILDDIR)/doctest/output.txt."
diff --git a/sphinx/make.bat b/sphinx/make.bat
new file mode 100644
index 00000000..18d48456
--- /dev/null
+++ b/sphinx/make.bat
@@ -0,0 +1,190 @@
+@ECHO OFF
+
+REM Command file for Sphinx documentation
+
+if "%SPHINXBUILD%" == "" (
+	set SPHINXBUILD=sphinx-build
+)
+set BUILDDIR=build
+set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% source
+set I18NSPHINXOPTS=%SPHINXOPTS% source
+if NOT "%PAPER%" == "" (
+	set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS%
+	set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS%
+)
+
+if "%1" == "" goto help
+
+if "%1" == "help" (
+	:help
+	echo.Please use `make ^<target^>` where ^<target^> is one of
+	echo.  html       to make standalone HTML files
+	echo.  dirhtml    to make HTML files named index.html in directories
+	echo.  singlehtml to make a single large HTML file
+	echo.  pickle     to make pickle files
+	echo.  json       to make JSON files
+	echo.  htmlhelp   to make HTML files and a HTML help project
+	echo.  qthelp     to make HTML files and a qthelp project
+	echo.  devhelp    to make HTML files and a Devhelp project
+	echo.  epub       to make an epub
+	echo.  latex      to make LaTeX files, you can set PAPER=a4 or PAPER=letter
+	echo.  text       to make text files
+	echo.  man        to make manual pages
+	echo.  texinfo    to make Texinfo files
+	echo.  gettext    to make PO message catalogs
+	echo.  changes    to make an overview over all changed/added/deprecated items
+	echo.  linkcheck  to check all external links for integrity
+	echo.  doctest    to run all doctests embedded in the documentation if enabled
+	goto end
+)
+
+if "%1" == "clean" (
+	for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i
+	del /q /s %BUILDDIR%\*
+	goto end
+)
+
+if "%1" == "html" (
+	%SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished. The HTML pages are in %BUILDDIR%/html.
+	goto end
+)
+
+if "%1" == "dirhtml" (
+	%SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml.
+	goto end
+)
+
+if "%1" == "singlehtml" (
+	%SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml.
+	goto end
+)
+
+if "%1" == "pickle" (
+	%SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished; now you can process the pickle files.
+	goto end
+)
+
+if "%1" == "json" (
+	%SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished; now you can process the JSON files.
+	goto end
+)
+
+if "%1" == "htmlhelp" (
+	%SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished; now you can run HTML Help Workshop with the ^
+.hhp project file in %BUILDDIR%/htmlhelp.
+	goto end
+)
+
+if "%1" == "qthelp" (
+	%SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished; now you can run "qcollectiongenerator" with the ^
+.qhcp project file in %BUILDDIR%/qthelp, like this:
+	echo.^> qcollectiongenerator %BUILDDIR%\qthelp\pysmb.qhcp
+	echo.To view the help file:
+	echo.^> assistant -collectionFile %BUILDDIR%\qthelp\pysmb.ghc
+	goto end
+)
+
+if "%1" == "devhelp" (
+	%SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished.
+	goto end
+)
+
+if "%1" == "epub" (
+	%SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished. The epub file is in %BUILDDIR%/epub.
+	goto end
+)
+
+if "%1" == "latex" (
+	%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished; the LaTeX files are in %BUILDDIR%/latex.
+	goto end
+)
+
+if "%1" == "text" (
+	%SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished. The text files are in %BUILDDIR%/text.
+	goto end
+)
+
+if "%1" == "man" (
+	%SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished. The manual pages are in %BUILDDIR%/man.
+	goto end
+)
+
+if "%1" == "texinfo" (
+	%SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo.
+	goto end
+)
+
+if "%1" == "gettext" (
+	%SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished. The message catalogs are in %BUILDDIR%/locale.
+	goto end
+)
+
+if "%1" == "changes" (
+	%SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.The overview file is in %BUILDDIR%/changes.
+	goto end
+)
+
+if "%1" == "linkcheck" (
+	%SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Link check complete; look for any errors in the above output ^
+or in %BUILDDIR%/linkcheck/output.txt.
+	goto end
+)
+
+if "%1" == "doctest" (
+	%SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Testing of doctests in the sources finished, look at the ^
+results in %BUILDDIR%/doctest/output.txt.
+	goto end
+)
+
+:end
diff --git a/sphinx/requirements.txt b/sphinx/requirements.txt
new file mode 100644
index 00000000..c14b1c83
--- /dev/null
+++ b/sphinx/requirements.txt
@@ -0,0 +1,2 @@
+twisted>=15.0.0
+pyasn1>=0.3.0
diff --git a/sphinx/source/api/nmb_NBNSProtocol.rst b/sphinx/source/api/nmb_NBNSProtocol.rst
new file mode 100644
index 00000000..94323fe2
--- /dev/null
+++ b/sphinx/source/api/nmb_NBNSProtocol.rst
@@ -0,0 +1,18 @@
+
+NBNSProtocol Class
+==================
+
+pysmb has a *NBNSProtocol* implementation for Twisted framework.
+This allows you to perform name query asynchronously without having your application to block and wait for the results.
+
+In your project,
+ 1. Create a NBNSProtocol instance.
+ 2. Just call *queryName* method which will return a *Deferred* instance. Add your callback function to the *Deferred* instance via *addCallback* method to receive the results of the name query.
+ 3. When you are done with the NBNSProtocol instance, call its <NBNSProtocol instance>.transport.stopListening method to remove this instance from the reactor.
+
+.. autoclass:: nmb.NetBIOSProtocol.NBNSProtocol
+    :members:
+    :special-members:
+
+.. autoclass:: nmb.NetBIOSProtocol.NetBIOSTimeout
+    :members:
diff --git a/sphinx/source/api/nmb_NetBIOS.rst b/sphinx/source/api/nmb_NetBIOS.rst
new file mode 100644
index 00000000..2949d952
--- /dev/null
+++ b/sphinx/source/api/nmb_NetBIOS.rst
@@ -0,0 +1,12 @@
+
+NetBIOS class
+=============
+
+To use the NetBIOS class in your application,
+ 1. Create a new NetBIOS instance
+ 2. Call *queryName* method for each name you wish to query. The method will block until a reply is received from the remote SMB/CIFS service, or until timeout.
+ 3. When you are done, call *close* method to release the underlying resources.
+
+.. autoclass:: nmb.NetBIOS.NetBIOS
+    :members:
+    :special-members:
diff --git a/sphinx/source/api/smb_SMBConnection.rst b/sphinx/source/api/smb_SMBConnection.rst
new file mode 100644
index 00000000..44782103
--- /dev/null
+++ b/sphinx/source/api/smb_SMBConnection.rst
@@ -0,0 +1,55 @@
+
+SMBConnection Class
+===================
+
+The SMBConnection is suitable for developers who wish to use pysmb to perform file operations with a remote SMB/CIFS server sequentially.
+
+Each file operation method, when invoked, will block and return after it has completed or has encountered an error.
+
+Example
+-------
+
+The following illustrates a simple file retrieving implementation.::
+
+    import tempfile
+    from smb.SMBConnection import SMBConnection
+
+    # There will be some mechanism to capture userID, password, client_machine_name, server_name and server_ip
+    # client_machine_name can be an arbitary ASCII string
+    # server_name should match the remote machine name, or else the connection will be rejected
+    conn = SMBConnection(userID, password, client_machine_name, server_name, use_ntlm_v2 = True)
+    assert conn.connect(server_ip, 139)
+
+    file_obj = tempfile.NamedTemporaryFile()
+    file_attributes, filesize = conn.retrieveFile('smbtest', '/rfc1001.txt', file_obj)
+
+    # Retrieved file contents are inside file_obj
+    # Do what you need with the file_obj and then close it
+    # Note that the file obj is positioned at the end-of-file,
+    # so you might need to perform a file_obj.seek() if you need
+    # to read from the beginning
+    file_obj.close()
+
+SMB2 Support
+-------------
+
+Starting from pysmb 1.1.0, pysmb will utilize SMB2 protocol for communication if the remote SMB/CIFS service supports SMB2.
+Otherwise, it will fallback automatically back to using SMB1 protocol.
+
+To disable SMB2 protocol in pysmb, set the *SUPPORT_SMB2* flag in the *smb_structs* module to *False* before creating the *SMBConnection* instance.::
+
+    from smb import smb_structs
+    smb_structs.SUPPORT_SMB2 = False
+
+Caveats
+-------
+
+* It is not meant to be used asynchronously.
+* A single *SMBConnection* instance should not be used to perform more than one operation concurrently at the same time.
+* Do not keep a *SMBConnection* instance "idle" for too long, i.e. keeping a *SMBConnection* instance but not using it.
+  Most SMB/CIFS servers have some sort of keepalive mechanism and impose a timeout limit.
+  If the clients fail to respond within the timeout limit, the SMB/CIFS server may disconnect the client.
+
+.. autoclass:: smb.SMBConnection.SMBConnection
+    :members:
+    :special-members:
diff --git a/sphinx/source/api/smb_SMBHandler.rst b/sphinx/source/api/smb_SMBHandler.rst
new file mode 100644
index 00000000..da106fee
--- /dev/null
+++ b/sphinx/source/api/smb_SMBHandler.rst
@@ -0,0 +1,48 @@
+
+SMbHandler Class
+================
+
+The SMBHandler class provides support for "smb://" URLs in the `urllib2 <http://docs.python.org/library/urllib2.html>`_ python package.
+
+Notes
+-----
+* Note that you need to pass in a valid hostname or IP address for the host component of the URL.
+  Do not use the Windows/NetBIOS machine name for the host component.
+* The first component of the path in the URL points to the name of the shared folder.
+  Subsequent path components will point to the directory/folder of the file.
+* You can retrieve and upload files, but you cannot delete files/folders or create folders.
+  In uploads, if the parent folders do not exist, an *urllib2.URLError* will be raised.
+
+Example
+-------
+
+The following code snippet illustrates file retrieval.::
+
+    # -*- coding: utf-8 -*-
+    import urllib2
+    from smb.SMBHandler import SMBHandler
+
+    director = urllib2.build_opener(SMBHandler)
+    fh = director.open('smb://myuserID:mypassword@192.168.1.1/sharedfolder/rfc1001.txt')
+
+    # Process fh like a file-like object and then close it.
+    fh.close()
+
+    # For paths/files with unicode characters, simply pass in the URL as an unicode string
+    fh2 = director.open(u'smb://myuserID:mypassword@192.168.1.1/sharedfolder/测试文件夹/垃圾文件.dat')
+
+    # Process fh2 like a file-like object and then close it.
+    fh2.close()
+
+The following code snippet illustrates file upload. You need to provide a file-like object for the *data* parameter in the *open()* method::
+
+    import urllib2
+    from smb.SMBHandler import SMBHandler
+
+    file_fh = open('local_file.dat', 'rb')
+
+    director = urllib2.build_opener(SMBHandler)
+    fh = director.open('smb://myuserID:mypassword@192.168.1.1/sharedfolder/upload_file.dat', data = file_fh)
+
+    # Reading from fh will only return an empty string
+    fh.close()
diff --git a/sphinx/source/api/smb_SMBProtocolFactory.rst b/sphinx/source/api/smb_SMBProtocolFactory.rst
new file mode 100644
index 00000000..dc967c39
--- /dev/null
+++ b/sphinx/source/api/smb_SMBProtocolFactory.rst
@@ -0,0 +1,93 @@
+
+SMBProtocolFactory Class
+========================
+
+For those who want to utilize pysmb in Twisted framework, pysmb has a *smb.SMBProtocol.SMBProtocol* implementation.
+In most cases, you do not need to touch or import the *SMBProtocol* directly. All the SMB functionalities are exposed in the *SMBProtocolFactory*.
+
+In your project,
+ 1. Create a new class and subclass *SMBProtocolFactory*.
+ 2. Override the *SMBProtocolFactory.onAuthOK* and *SMBProtocolFactory.onAuthFailed* instance methods to provide your own post-authenthentication handling.
+    Once *SMBProtocolFactory.onAuthOK* has been called by pymsb internals, your application is ready to communicate with the remote SMB/CIFS service through
+    the *SMBProtocolFactory* public methods such as *SMBProtocolFactory.storeFile*, *SMBProtocolFactory.retrieveFile*, etc.
+ 3. When you want to disconnect from the remote SMB/CIFS server, just call *SMBProtocolFactory.closeConnection* method.
+
+All the *SMBProtocolFactory* public methods that provide file functionlities will return a *twisted.internet.defer.Deferred* instance.
+A :doc:`NotReadyError<smb_exceptions>` exception is raised when the underlying SMB is not authenticated.
+If the underlying SMB connection has been terminated, a :doc:`NotConnectedError<smb_exceptions>` exception is raised.
+
+All the file operation methods in *SMBProtocolFactory* class accept a *timeout* parameter. This parameter specifies the time limit where pysmb will wait for the
+entire file operation (except *storeFile* and *retrieveFile* methods) to complete. If the file operation fails to complete within the timeout period, the returned
+*Deferred* instance's *errback* method will be called with a *SMBTimeout* exception.
+
+If you are interested in learning the results of the operation or to know when the operation has completed, you should
+add a handling method to the returned *Deferred* instance via *Deferred.addCallback*. If the file operation fails, the *Deferred.errback* function will be called
+with an :doc:`OperationFailure<smb_exceptions>`; on timeout, it will be called with a :doc:`SMBTimeout<smb_exceptions>`.
+
+Example
+-------
+
+The following illustrates a simple file retrieving implementation.::
+
+    import tempfile
+    from twisted.internet import reactor
+    from smb.SMBProtocol import SMBProtocolFactory
+
+    class RetrieveFileFactory(SMBProtocolFactory):
+
+        def __init__(self, *args, **kwargs):
+            SMBProtocolFactory.__init__(self, *args, **kwargs)
+
+        def fileRetrieved(self, write_result):
+            file_obj, file_attributes, file_size = write_result
+
+            # Retrieved file contents are inside file_obj
+            # Do what you need with the file_obj and then close it
+            # Note that the file obj is positioned at the end-of-file,
+            # so you might need to perform a file_obj.seek() to if you
+            # need to read from the beginning
+            file_obj.close()
+
+            self.transport.loseConnection()
+
+        def onAuthOK(self):
+            d = self.retrieveFile(self.service, self.path, tempfile.NamedTemporaryFile())
+            d.addCallback(self.fileRetrieved)
+            d.addErrback(self.d.errback)
+
+        def onAuthFailed(self):
+            print 'Auth failed'
+
+    # There will be some mechanism to capture userID, password, client_machine_name, server_name and server_ip
+    # client_machine_name can be an arbitary ASCII string
+    # server_name should match the remote machine name, or else the connection will be rejected
+    factory = RetrieveFileFactory(userID, password, client_machine_name, server_name, use_ntlm_v2 = True)
+    factory.service = 'smbtest'
+    factory.path = '/rfc1001.txt'
+    reactor.connectTCP(server_ip, 139, factory)
+
+
+
+
+SMB2 Support
+-------------
+
+Starting from pysmb 1.1.0, pysmb will utilize SMB2 protocol for communication if the remote SMB/CIFS service supports SMB2.
+Otherwise, it will fallback automatically back to using SMB1 protocol.
+
+To disable SMB2 protocol in pysmb, set the *SUPPORT_SMB2* flag in the *smb_structs* module to *False* before creating the *SMBProtocolFactory* instance.::
+
+    from smb import smb_structs
+    smb_structs.SUPPORT_SMB2 = False
+
+Caveats
+-------
+
+* A new factory instance must be created for each SMB connection to the remote SMB/CIFS service. Avoid reusing the same factory instance for more than one SMB connection.
+* The remote SMB/CIFS server usually imposes a limit of the number of concurrent file operations for each client. For example, to transfer a thousand files, you may need to setup a queue in your application and call *storeFile* or *retrieveFile* in batches.
+* The *timeout* parameter in the file operation methods are not precise; it is accurate to within 1 second interval, i.e. with a timeout of 0.5 sec, pysmb might raise
+  *SMBTimeout* exception after 1.5 sec.
+
+.. autoclass:: smb.SMBProtocol.SMBProtocolFactory
+    :members:
+    :special-members:
diff --git a/sphinx/source/api/smb_SharedDevice.rst b/sphinx/source/api/smb_SharedDevice.rst
new file mode 100644
index 00000000..9ac39b7e
--- /dev/null
+++ b/sphinx/source/api/smb_SharedDevice.rst
@@ -0,0 +1,6 @@
+
+SharedDevice Class
+==================
+
+.. autoclass:: smb.base.SharedDevice
+    :members:
diff --git a/sphinx/source/api/smb_SharedFile.rst b/sphinx/source/api/smb_SharedFile.rst
new file mode 100644
index 00000000..d71e43ca
--- /dev/null
+++ b/sphinx/source/api/smb_SharedFile.rst
@@ -0,0 +1,6 @@
+
+SharedFile Class
+================
+
+.. autoclass:: smb.base.SharedFile
+    :members:
diff --git a/sphinx/source/api/smb_exceptions.rst b/sphinx/source/api/smb_exceptions.rst
new file mode 100644
index 00000000..73406390
--- /dev/null
+++ b/sphinx/source/api/smb_exceptions.rst
@@ -0,0 +1,21 @@
+
+SMB Exceptions
+==============
+
+.. autoclass:: smb.base.SMBTimeout
+    :members:
+
+.. autoclass:: smb.base.NotReadyError
+    :members:
+
+.. autoclass:: smb.base.NotConnectedError
+    :members:
+
+.. autoclass:: smb.smb_structs.UnsupportedFeature
+    :members:
+
+.. autoclass:: smb.smb_structs.ProtocolError
+    :members:
+
+.. autoclass:: smb.smb_structs.OperationFailure
+    :members:
diff --git a/sphinx/source/api/smb_security_descriptors.rst b/sphinx/source/api/smb_security_descriptors.rst
new file mode 100644
index 00000000..0f048fe8
--- /dev/null
+++ b/sphinx/source/api/smb_security_descriptors.rst
@@ -0,0 +1,23 @@
+
+Security Descriptors
+====================
+
+.. module:: smb.security_descriptors
+   :synopsis: Data structures used in Windows security descriptors.
+
+This module implements security descriptors, and associated data
+structures, as specified in `[MS-DTYP]`_.
+
+.. autoclass:: SID
+   :members:
+
+.. autoclass:: ACE
+   :members:
+
+.. autoclass:: ACL
+   :members:
+
+.. autoclass:: SecurityDescriptor
+   :members:
+
+.. _[MS-DTYP]: https://msdn.microsoft.com/en-us/library/cc230273.aspx
diff --git a/sphinx/source/conf.py b/sphinx/source/conf.py
new file mode 100644
index 00000000..26accf46
--- /dev/null
+++ b/sphinx/source/conf.py
@@ -0,0 +1,244 @@
+# -*- coding: utf-8 -*-
+#
+# pysmb documentation build configuration file, created by
+# sphinx-quickstart on Sun Dec 18 15:54:40 2011.
+#
+# This file is execfile()d with the current directory set to its containing dir.
+#
+# Note that not all possible configuration values are present in this
+# autogenerated file.
+#
+# All configuration values have a default; values that are commented out
+# serve to show the default.
+
+import sys, os
+
+# If extensions (or modules to document with autodoc) are in another directory,
+# add these directories to sys.path here. If the directory is relative to the
+# documentation root, use os.path.abspath to make it absolute, like shown here.
+#sys.path.insert(0, os.path.abspath('.'))
+sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, 'python2'))
+
+# -- General configuration -----------------------------------------------------
+
+# If your documentation needs a minimal Sphinx version, state it here.
+#needs_sphinx = '1.0'
+
+# Add any Sphinx extension module names here, as strings. They can be extensions
+# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
+extensions = ['sphinx.ext.autodoc', 'sphinx.ext.todo', 'sphinx.ext.ifconfig', 'sphinx.ext.viewcode']
+
+# Add any paths that contain templates here, relative to this directory.
+templates_path = ['_templates']
+
+# The suffix of source filenames.
+source_suffix = '.rst'
+
+# The encoding of source files.
+#source_encoding = 'utf-8-sig'
+
+# The master toctree document.
+master_doc = 'index'
+
+# General information about the project.
+project = u'pysmb'
+copyright = u'2001-2018, Michael Teo http://miketeo.net/'
+
+# The version info for the project you're documenting, acts as replacement for
+# |version| and |release|, also used in various other places throughout the
+# built documents.
+#
+# The short X.Y version.
+version = '1.1.26'
+# The full version, including alpha/beta/rc tags.
+release = '1.1.26'
+
+# The language for content autogenerated by Sphinx. Refer to documentation
+# for a list of supported languages.
+#language = None
+
+# There are two options for replacing |today|: either, you set today to some
+# non-false value, then it is used:
+#today = ''
+# Else, today_fmt is used as the format for a strftime call.
+#today_fmt = '%B %d, %Y'
+
+# List of patterns, relative to source directory, that match files and
+# directories to ignore when looking for source files.
+exclude_patterns = []
+
+# The reST default role (used for this markup: `text`) to use for all documents.
+#default_role = None
+
+# If true, '()' will be appended to :func: etc. cross-reference text.
+#add_function_parentheses = True
+
+# If true, the current module name will be prepended to all description
+# unit titles (such as .. function::).
+#add_module_names = True
+
+# If true, sectionauthor and moduleauthor directives will be shown in the
+# output. They are ignored by default.
+#show_authors = False
+
+# The name of the Pygments (syntax highlighting) style to use.
+pygments_style = 'sphinx'
+
+# A list of ignored prefixes for module index sorting.
+#modindex_common_prefix = []
+
+autodoc_member_order = 'groupwise'
+
+# -- Options for HTML output ---------------------------------------------------
+
+# The theme to use for HTML and HTML Help pages.  See the documentation for
+# a list of builtin themes.
+html_theme = 'sphinxdoc'
+
+# Theme options are theme-specific and customize the look and feel of a theme
+# further.  For a list of options available for each theme, see the
+# documentation.
+#html_theme_options = {}
+
+# Add any paths that contain custom themes here, relative to this directory.
+#html_theme_path = []
+
+# The name for this set of Sphinx documents.  If None, it defaults to
+# "<project> v<release> documentation".
+#html_title = None
+
+# A shorter title for the navigation bar.  Default is the same as html_title.
+#html_short_title = None
+
+# The name of an image file (relative to this directory) to place at the top
+# of the sidebar.
+#html_logo = None
+
+# The name of an image file (within the static path) to use as favicon of the
+# docs.  This file should be a Windows icon file (.ico) being 16x16 or 32x32
+# pixels large.
+#html_favicon = None
+
+# Add any paths that contain custom static files (such as style sheets) here,
+# relative to this directory. They are copied after the builtin static files,
+# so a file named "default.css" will overwrite the builtin "default.css".
+html_static_path = ['_static']
+
+# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
+# using the given strftime format.
+#html_last_updated_fmt = '%b %d, %Y'
+
+# If true, SmartyPants will be used to convert quotes and dashes to
+# typographically correct entities.
+#html_use_smartypants = True
+
+# Custom sidebar templates, maps document names to template names.
+#html_sidebars = {}
+
+# Additional templates that should be rendered to pages, maps page names to
+# template names.
+#html_additional_pages = {}
+
+# If false, no module index is generated.
+#html_domain_indices = True
+
+# If false, no index is generated.
+#html_use_index = True
+
+# If true, the index is split into individual pages for each letter.
+#html_split_index = False
+
+# If true, links to the reST sources are added to the pages.
+#html_show_sourcelink = True
+
+# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
+#html_show_sphinx = True
+
+# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
+#html_show_copyright = True
+
+# If true, an OpenSearch description file will be output, and all pages will
+# contain a <link> tag referring to it.  The value of this option must be the
+# base URL from which the finished HTML is served.
+#html_use_opensearch = ''
+
+# This is the file name suffix for HTML files (e.g. ".xhtml").
+#html_file_suffix = None
+
+# Output file base name for HTML help builder.
+htmlhelp_basename = 'pysmbdoc'
+
+
+# -- Options for LaTeX output --------------------------------------------------
+
+latex_elements = {
+# The paper size ('letterpaper' or 'a4paper').
+#'papersize': 'letterpaper',
+
+# The font size ('10pt', '11pt' or '12pt').
+#'pointsize': '10pt',
+
+# Additional stuff for the LaTeX preamble.
+#'preamble': '',
+}
+
+# Grouping the document tree into LaTeX files. List of tuples
+# (source start file, target name, title, author, documentclass [howto/manual]).
+latex_documents = [
+  ('index', 'pysmb.tex', u'pysmb Documentation',
+   u'Michael Teo', 'manual'),
+]
+
+# The name of an image file (relative to this directory) to place at the top of
+# the title page.
+#latex_logo = None
+
+# For "manual" documents, if this is true, then toplevel headings are parts,
+# not chapters.
+#latex_use_parts = False
+
+# If true, show page references after internal links.
+#latex_show_pagerefs = False
+
+# If true, show URL addresses after external links.
+#latex_show_urls = False
+
+# Documents to append as an appendix to all manuals.
+#latex_appendices = []
+
+# If false, no module index is generated.
+#latex_domain_indices = True
+
+
+# -- Options for manual page output --------------------------------------------
+
+# One entry per manual page. List of tuples
+# (source start file, name, description, authors, manual section).
+man_pages = [
+    ('index', 'pysmb', u'pysmb Documentation',
+     [u'Michael Teo'], 1)
+]
+
+# If true, show URL addresses after external links.
+#man_show_urls = False
+
+
+# -- Options for Texinfo output ------------------------------------------------
+
+# Grouping the document tree into Texinfo files. List of tuples
+# (source start file, target name, title, author,
+#  dir menu entry, description, category)
+texinfo_documents = [
+  ('index', 'pysmb', u'pysmb Documentation',
+   u'Michael Teo', 'pysmb', 'One line description of project.',
+   'Miscellaneous'),
+]
+
+# Documents to append as an appendix to all manuals.
+#texinfo_appendices = []
+
+# If false, no module index is generated.
+#texinfo_domain_indices = True
+
+# How to display URL addresses: 'footnote', 'no', or 'inline'.
+#texinfo_show_urls = 'footnote'
diff --git a/sphinx/source/extending.rst b/sphinx/source/extending.rst
new file mode 100644
index 00000000..9945212e
--- /dev/null
+++ b/sphinx/source/extending.rst
@@ -0,0 +1,19 @@
+
+Extending pysmb For Other Frameworks
+====================================
+
+This page briefly describes the steps involved in extending pysmb for other frameworks.
+
+In general, you need to take care of the SMB TCP connection setup, i.e. finding the IP address of the remote server and connect to the SMB/CIFS service.
+Then you need to read/write synchronously or asynchronously from and to the SMB socket. And you need to handle post-authentication callback methods, and from these methods,
+initiate file operations with the remote SMB/CIFS server.
+
+Now the above steps in more technical details:
+ 1. Create a new class which subclasses the *smb.base.SMB* class. Most often, the connection setup will be part of the *__init__* method.
+ 2. Override the *write(self, data)* method to provide an implementation which will write *data* to the socket.
+ 3. Write your own loop handling method to read data from the socket. Once data have been read, call *feedData* method with the parameter.
+    The *feedData* method has its own internal buffer, so it can accept incomplete NetBIOS session packet data.
+ 4. Override
+   * *onAuthOK* method to include your own operations to perform when authentication is successful. You can initiate file operations in this method.
+   * *onAuthFailed* method to include your own processing on what to do when authentication fails. You can report this as an error, or to try a different NTLM authentication algorithm (*use_ntlm_v2* parameter in the constructor).
+   * *onNMBSessionFailed* method to include your own processing on what to do when pysmb fails to setup the NetBIOS session with the remote server. Usually, this is due to a wrong *remote_name* parameter in the constructor.
diff --git a/sphinx/source/index.rst b/sphinx/source/index.rst
new file mode 100644
index 00000000..7638fcd8
--- /dev/null
+++ b/sphinx/source/index.rst
@@ -0,0 +1,106 @@
+.. pysmb documentation master file, created by
+   sphinx-quickstart on Sun Dec 18 15:54:40 2011.
+   You can adapt this file completely to your liking, but it should at least
+   contain the root `toctree` directive.
+
+Welcome to pysmb's documentation!
+=================================
+
+pysmb is a pure Python implementation of the client-side SMB/CIFS protocol (SMB1 and SMB2) which is the underlying protocol
+that facilitates file sharing and printing between Windows machines, as well as with Linux machines via the Samba server application.
+pysmb is developed in Python 2.4.6, Python 2.7.1 and Python 3.2.3 and has been tested against shared folders on Windows XP SP3, Windows Vista, Windows 7 and Samba 3.x.
+
+The latest version of pysmb is always available at the pysmb project page at `miketeo.net <http://miketeo.net/wp/index.php/projects/pysmb>`_.
+
+License
+-------
+pysmb itself is licensed under an opensource license.
+You are free to use pysmb in any applications, including for commercial purposes.
+For more details on the terms of use, please read the LICENSE file that comes with your pysmb source.
+
+pysmb depends on other 3rd-party modules whose terms of use are not covered by pysmb.
+Use of these modules could possibly conflict with your licensing needs. Please exercise your own discretion to determine their suitabilities.
+I have listed these modules in the following section.
+
+Credits
+-------
+pysmb is not alone. It is made possible with support from other modules.
+
+* **pyasn1** : Pure Python implementation of ASN.1 parsing and encoding (not included together with pysmb; needs to be installed separately)
+* **md4** and **U32** : Pure Python implementation of MD4 hashing algorithm and 32-bit unsigned integer by Dmitry Rozmanov. Licensed under LGPL and included together with pysmb.
+* **pyDes** : Pure Python implementation of the DES encryption algorithm by Todd Whiteman. Free domain and included together with pysmb.
+* **sha256** : Pure Python implementation of SHA-256 message digest by Thomas Dixon. Licensed under MIT and included together with pysmb. This module is imported only when
+  the Python standard library (usually Python 2.4) does not provide the SHA-256 hash algorithm.
+
+In various places, there are references to different specifications. Most of these referenced specifications
+can be downloaded from Microsoft web site under Microsoft's "Open Specification Promise". If you need to download
+a copy of these specifications, please google for it. For example, google for "MS-CIFS" to download the CIFS specification for NT LM dialect.
+
+Package Contents and Description
+================================
+
+pysmb is organized into 2 main packages: smb and nmb.
+The smb package contains all the functionalities related to Server Message Block (SMB) implementation.
+As an application developer, you will be importing this module into your application.
+Hence, please take some time to familiarize yourself with the smb package contents.
+
+* **nmb/base.py** :
+  Contains the NetBIOSSession and NBNS abstract class which implements NetBIOS session and NetBIOS Name Service communication
+  without any network transport specifics.
+* **nmb/NetBIOS.py**:
+  Provides a NBNS implementation to query IP addresses for machine names. All operations are blocking I/O.
+* **nmb/NetBIOSProtocol.py** :
+  Provides the NBNS protocol implementation for use in Twisted framework.
+
+* **smb/base.py** :
+  Contains the SMB abstract class which implements the SMB communication without any network transport specifics.
+* **smb/ntlm.py** :
+  Contains the NTLMv1 and NTLMv2 authentication routines and the decoding/encoding of NTLM authentication messages within SMB messages.
+* **smb/securityblob.py** :
+  Provides routines to encode/decode the NTLMSSP security blob in the SMB messages.
+* **smb/smb_constants.py** :
+  All the constants used in the smb package for SMB1 protocol
+* **smb/smb_structs.py** :
+  Contains the internal classes used in the SMB package for SMB1 protocol. These classes are usually used to encode/decode the parameter and data blocks of specific SMB1 message.
+* **smb/smb2_constants.py** :
+  All the constants used in the smb package for SMB2 protocol
+* **smb/smb2_structs.py** :
+  Contains the internal classes used in the SMB package for SMB2 protocol. These classes are usually used to encode/decode the parameter and data blocks of specific SMB2 message.
+* **smb/SMBConnection.py** :
+  Contains a SMB protocol implementation. All operations are blocking I/O.
+* **smb/SMBProtocol.py** :
+  Contains the SMB protocol implementation for use in the Twisted framework.
+* **smb/SMBHandler.py** :
+  Provides support for "smb://" URL in the urllib2 python package.
+
+Using pysmb
+===========
+
+As an application developer who is looking to use pysmb to translate NetBIOS names to IP addresses,
+ * To use pysmb in applications where you want the file operations to return after they have completed (synchronous style), please read
+   :doc:`nmb.NetBIOS.NetBIOS<api/nmb_NetBIOS>` documentation.
+ * To use pysmb in Twisted, please read :doc:`nmb.NetBIOSProtocol.NBNSProtocol<api/nmb_NBNSProtocol>` documentation.
+
+As an application developer who is looking to use pysmb to implement file transfer or authentication over SMB:
+ * To use pysmb in applications where you want the file operations to return after they have completed (synchronous style), please read
+   :doc:`smb.SMBConnection.SMBConnection<api/smb_SMBConnection>` documentation.
+ * To use pysmb in Twisted, please read :doc:`smb.SMBProtocol.SMBProtocolFactory<api/smb_SMBProtocolFactory>` documentation.
+ * To support "smb://" URL in urllib2 python package, read :doc:`smb.SMBHandler.SMBHandler<api/smb_SMBHandler>` documentation.
+
+As a software developer who is looking to modify pysmb so that you can integrate it to other network frameworks:
+ * Read :doc:`extending`
+
+
+
+Indices and tables
+==================
+
+.. toctree::
+    :glob:
+    :maxdepth: 1
+
+    api/*
+    extending
+
+* :ref:`genindex`
+* :ref:`search`