Expert Python Programming - Second Edition Michał Jaworski all chapter instant download
Expert Python Programming - Second Edition Michał Jaworski all chapter instant download
com
https://ebookmeta.com/product/expert-python-programming-
second-edition-michal-jaworski/
OR CLICK HERE
DOWLOAD NOW
https://ebookmeta.com/product/expert-python-programming-second-
edition-michal-jaworski-tarek-ziade-ziade-jaworski/
ebookmeta.com
https://ebookmeta.com/product/expert-python-programming-second-
edition-michal-jaworski-tarek-ziade-ziade-jaworski-2/
ebookmeta.com
https://ebookmeta.com/product/expert-python-programming-second-
edition-michal-jaworski-tarek-ziade/
ebookmeta.com
https://ebookmeta.com/product/the-invention-of-race-in-the-european-
middle-ages-geraldine-heng/
ebookmeta.com
Chassepot To Famas French Military Rifles 1866 2016 1st
Edition Ian Mccollum
https://ebookmeta.com/product/chassepot-to-famas-french-military-
rifles-1866-2016-1st-edition-ian-mccollum/
ebookmeta.com
https://ebookmeta.com/product/music-as-intangible-cultural-heritage-
economic-cultural-and-social-identity-1st-edition-blanca-de-miguel-
molina/
ebookmeta.com
https://ebookmeta.com/product/discovering-philosophy-4th-edition-
thomas-i-white/
ebookmeta.com
https://ebookmeta.com/product/hunt-the-wood-an-mm-red-riding-hood-
retelling-beautiful-nightmares-book-1-1st-edition-anna-fury-amy-
pennza-2/
ebookmeta.com
https://ebookmeta.com/product/gmat-analytical-writing-solutions-to-
the-real-argument-topics-test-prep-series-5th-edition-publishers/
ebookmeta.com
Investment Science 2nd Edition David G. Luenberger
https://ebookmeta.com/product/investment-science-2nd-edition-david-g-
luenberger/
ebookmeta.com
Table of Contents
Expert Python Programming Second Edition
Credits
About the Authors
About the Reviewer
www.PacktPub.com
eBooks, discount offers, and more
Why subscribe?
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Current Status of Python
Where are we now and where we are going?
Why and how does Python change?
Getting up to date with changes – PEP documents
Python 3 adoption at the time of writing this book
The main differences between Python 3 and Python 2
Why should I care?
The main syntax differences and common pitfalls
Syntax changes
Changes in the standard library
Changes in datatypes and collections
The popular tools and techniques used for maintaining cross-
version compatibility
Not only CPython
Why should I care?
Stackless Python
Jython
IronPython
PyPy
Modern approaches to Python development
Application-level isolation of Python environments
Why isolation?
Popular solutions
virtualenv
venv
buildout
Which one to choose?
System-level environment isolation
Virtual development environments using Vagrant
Containerization versus virtualization
Popular productivity tools
Custom Python shells – IPython, bpython, ptpython, and so on
Setting up the PYTHONSTARTUP environment variable
IPython
bpython
ptpython
Interactive debuggers
Useful resources
Summary
2. Syntax Best Practices – below the Class Level
Python's built-in types
Strings and bytes
Implementation details
String concatenation
Collections
Lists and tuples
Implementation details
List comprehensions
Other idioms
Dictionaries
Implementation details
Weaknesses and alternatives
Sets
Implementation details
Beyond basic collections – the collections module
Advanced syntax
Iterators
The yield statement
Decorators
General syntax and possible implementations
As a function
As a class
Parametrizing decorators
Introspection preserving decorators
Usage and useful examples
Argument checking
Caching
Proxy
Context provider
Context managers – the with statement
General syntax and possible implementations
As a class
As a function – the contextlib module
Other syntax elements you may not know yet
The for … else … statement
Function annotations
The general syntax
The possible uses
Summary
3. Syntax Best Practices – above the Class Level
Subclassing built-in types
Accessing methods from superclasses
Old-style classes and super in Python 2
Understanding Python's Method Resolution Order
super pitfalls
Mixing super and explicit class calls
Heterogeneous arguments
Best practices
Advanced attribute access patterns
Descriptors
Real-life example – lazily evaluated attributes
Properties
Slots
Metaprogramming
Decorators – a method of metaprogramming
Class decorators
Using the __new__() method to override instance creation
process
Metaclasses
The general syntax
New Python 3 syntax for metaclasses
Metaclass usage
Metaclass pitfalls
Some tips on code generation
exec, eval, and compile
Abstract Syntax Tree
Import hooks
Projects using code generation patterns
Falcon's compiled router
Hy
Summary
4. Choosing Good Names
PEP 8 and naming best practices
Why and when to follow PEP 8?
Beyond PEP 8 – team-specific style guidelines
Naming styles
Variables
Constants
Naming and usage
Public and private variables
Functions and methods
The private controversy
Special methods
Arguments
Properties
Classes
Modules and packages
The naming guide
Using the has or is prefix for Boolean elements
Using plurals for variables that are collections
Using explicit names for dictionaries
Avoiding generic names
Avoiding existing names
Best practices for arguments
Building arguments by iterative design
Trust the arguments and your tests
Using *args and **kwargs magic arguments carefully
Class names
Module and package names
Useful tools
Pylint
pep8 and flake8
Summary
5. Writing a Package
Creating a package
The confusing state of Python packaging tools
The current landscape of Python packaging thanks to PyPA
Tool recommendations
Project configuration
setup.py
setup.cfg
MANIFEST.in
Most important metadata
Trove classifiers
Common patterns
Automated inclusion of version string from package
README file
Managing dependencies
The custom setup command
Working with packages during development
setup.py install
Uninstalling packages
setup.py develop or pip -e
Namespace packages
Why is it useful?
PEP 420 – implicit namespace packages
Namespace packages in previous Python versions
Uploading a package
PyPI – Python Package Index
Uploading to PyPI – or other package index
.pypirc
Source packages versus built packages
sdist
bdist and wheels
Standalone executables
When are standalone executables useful?
Popular tools
PyInstaller
cx_Freeze
py2exe and py2app
Security of Python code in executable packages
Making decompilation harder
Summary
6. Deploying Code
The Twelve-Factor App
Deployment automation using Fabric
Your own package index or index mirror
PyPI mirroring
Deployment using a package
Common conventions and practices
The filesystem hierarchy
Isolation
Using process supervision tools
Application code should be run in user space
Using reverse HTTP proxies
Reloading processes gracefully
Code instrumentation and monitoring
Logging errors – sentry/raven
Monitoring system and application metrics
Dealing with application logs
Basic low-level log practices
Tools for log processing
Summary
7. Python Extensions in Other Languages
Different language means – C or C++
How do extensions in C or C++ work
Why you might want to use extensions
Improving performance in critical code sections
Integrating existing code written in different languages
Integrating third-party dynamic libraries
Creating custom datatypes
Writing extensions
Pure C extensions
A closer look at Python/C API
Calling and binding conventions
Exception handling
Releasing GIL
Reference counting
Cython
Cython as a source to source compiler
Cython as a language
Challenges
Additional complexity
Debugging
Interfacing with dynamic libraries without extensions
ctypes
Loading libraries
Calling C functions using ctypes
Passing Python functions as C callbacks
CFFI
Summary
8. Managing Code
Version control systems
Centralized systems
Distributed systems
Distributed strategies
Centralized or distributed?
Use Git if you can
Git flow and GitHub flow
Continuous development processes
Continuous integration
Testing every commit
Merge testing through CI
Matrix testing
Continuous delivery
Continuous deployment
Popular tools for continuous integration
Jenkins
Buildbot
Travis CI
GitLab CI
Choosing the right tool and common pitfalls
Problem 1 – too complex build strategies
Problem 2 – too long building time
Problem 3 – external job definitions
Problem 4 – lack of isolation
Summary
9. Documenting Your Project
The seven rules of technical writing
Write in two steps
Target the readership
Use a simple style
Limit the scope of information
Use realistic code examples
Use a light but sufficient approach
Use templates
A reStructuredText primer
Section structure
Lists
Inline markup
Literal block
Links
Building the documentation
Building the portfolio
Design
Usage
Recipe
Tutorial
Module helper
Operations
Making your own portfolio
Building the landscape
Producer's layout
Consumer's layout
Working on the index pages
Registering module helpers
Adding index markers
Cross-references
Documentation building and continuous integration
Summary
10. Test-Driven Development
I don't test
Test-driven development principles
Preventing software regression
Improving code quality
Providing the best developer documentation
Producing robust code faster
What kind of tests?
Acceptance tests
Unit tests
Functional tests
Integration tests
Load and performance testing
Code quality testing
Python standard test tools
unittest
doctest
I do test
unittest pitfalls
unittest alternatives
nose
Test runner
Writing tests
Writing test fixtures
Integration with setuptools and a plug-in system
Wrap-up
py.test
Writing test fixtures
Disabling test functions and classes
Automated distributed tests
Wrap-up
Testing coverage
Fakes and mocks
Building a fake
Using mocks
Testing environment and dependency compatibility
Dependency matrix testing
Document-driven development
Writing a story
Summary
11. Optimization – General Principles and Profiling Techniques
The three rules of optimization
Make it work first
Work from the user's point of view
Keep the code readable and maintainable
Optimization strategy
Find another culprit
Scale the hardware
Writing a speed test
Finding bottlenecks
Profiling CPU usage
Macro-profiling
Micro-profiling
Measuring Pystones
Profiling memory usage
How Python deals with memory
Profiling memory
objgraph
C code memory leaks
Profiling network usage
Summary
12. Optimization – Some Powerful Techniques
Reducing the complexity
Cyclomatic complexity
The big O notation
Simplifying
Searching in a list
Using a set instead of a list
Cut the external calls, reduce the workload
Using collections
deque
defaultdict
namedtuple
Using architectural trade-offs
Using heuristics and approximation algorithms
Using task queues and delayed processing
Using probabilistic data structures
Caching
Deterministic caching
Nondeterministic caching
Cache services
Memcached
Summary
13. Concurrency
Why concurrency?
Multithreading
What is multithreading?
How Python deals with threads
When should threading be used?
Building responsive interfaces
Delegating work
Multiuser applications
An example of a threaded application
Using one thread per item
Using a thread pool
Using two-way queues
Dealing with errors and rate limiting
Multiprocessing
The built-in multiprocessing module
Using process pools
Using multiprocessing.dummy as a multithreading interface
Asynchronous programming
Cooperative multitasking and asynchronous I/O
Python async and await keywords
asyncio in older versions of Python
A practical example of asynchronous programming
Integrating nonasynchronous code with async using futures
Executors and futures
Using executors in an event loop
Summary
14. Useful Design Patterns
Creational patterns
Singleton
Structural patterns
Adapter
Interfaces
Using zope.interface
Using function annotations and abstract base classes
Using collections.abc
Proxy
Facade
Behavioral patterns
Observer
Visitor
Template
Summary
Index
Expert Python Programming
Second Edition
Another Random Document on
Scribd Without Any Related Topics
as readers are influenced far more by emotion than by close and exact
reason, the vast majority were carried away by the rush of feeling of
that mighty soul; and hence in the view of a philosophic monarchist
like Dumont, the publication of the “Reflections” was destined to be
“the salvation of Europe.” Certainly it was the first noteworthy effort of
a literary man to stem the tide of democracy; and if the writer had
advocated a practicable scheme for saving the French monarchy—say,
on the lines of that of Mirabeau—he would have rendered an
inestimable service. As it was, even the voice of a genius failed to
convince the French people that they must build their new fabric on
the lines laid down by Philip the Fair and Louis the Fourteenth.
While the “Reflections” caused little but irritation in France, they
also worked some harm in England. Readers by the thousand were
captivated by the glamour of Burke’s style, and became forthwith the
sworn foes of the persecutors of Marie Antoinette. The fall of that
erstwhile “morning star, full of life and splendour and joy,” involved in
one common gloom the emotions and the reason of Britons. “It is the
noblest, deepest, most animated and exalted work that I think I have
ever read.” So wrote Fanny Burney. The superlatives are significant.
Thenceforth events in France were viewed through the distorting
medium of a royalist romance. The change was fatal in every way.
England, which heretofore had guardedly sympathized with the French
reformers, now swung round to antagonism; and the French princes
who at Turin and Coblentz were striving to frame a Coalition against
their native land, saw in fancy John Bull as the paymaster of the
monarchist league, with Burke as the chief trumpeter.
In truth the great writer ran some risk of sinking to this level. He
became the unofficial representative of the French princes in this
country, while his son, Richard Burke, proceeded to Coblentz to work
on behalf of that clamorous clique. Memoir after memoir appeared
from the pen of Burke himself. Now it was a protest, purporting to
emanate from George III, against despoiling the French monarchy of
all its rights, and asserting that, if this caution were unheeded, our
903
ambassador would leave Paris. Now again it was a memorandum
of advice to the Queen of France, urging her to have nothing to do
with traitors (i.e., reformers), to maintain an attitude of silent disdain
of their offered help, and, above all, to induce her consort to refuse
904
the new democratic constitution. Fortunately neither of these
documents went beyond the doors of Burke’s study; but they survive
as curious proofs of his now distracted mood.
It was the misfortune of Burke at this time that majesty of diction
deserted him at Westminster, where his speeches and demeanour bore
the imprint of petulance and sourness. This appeared most painfully in
the famous scene which marked his severance from Fox. It occurred
during the debates on the Canada Bill in the spring of 1791. The
preoccupation of men’s minds with the French constitution, then slowly
taking shape, had been apparent in the course of the session. Fox had
often dragged in the subject to express his warm sympathy with the
democrats of Paris, and now desired to assimilate the Canada Bill
somewhat to the French model. To this Burke offered vehement
opposition, out-doing Fox in iteration. On 6th May, when the subject at
issue was Canada, he defied the rules of the House by speaking solely
on France. Six times he was called to order. Still he went on, in more
and more heated tones, until he crowned his diatribe with the
declaration that the difference between him and his friend involved an
end of their connection; for with his latest words he would exclaim:
“Fly from the French Constitution.” Fox here whispered to him: “There
is no loss of friends.” “Yes,” retorted Burke, “there is a loss of friends; I
know the price of my conduct; I have done my duty at the price of my
friend; our friendship is at an end.” A little later, when Fox rose to
905
reply, words failed him and tears trickled down his cheeks. No
scene in Parliament in that age produced so profound an emotion. It
deepened the affection felt for that generous statesman; while the
once inspiring figure of Burke now stood forth in the hard and
repellent outlines of a fanatic.
Far better would it have been had he confined himself to the
higher domains of literature, where he was at home. His “Appeal from
the New to the Old Whigs,” which appeared in July 1791, is a great
and moving production; and his less known “Thoughts on French
Affairs” (December 1791) is remarkable for its keen insight into the
causes that made for disruption or revolt in the European lands, not
906
even excluding Great Britain. In this one respect Burke excelled
Pitt, just as nervous apprehension will detect dangers ahead that are
hidden from the serene gaze of an optimist. Wilberforce judged Pitt to
907
be somewhat deficient in foresight; and we may ascribe this defect
to his intense hopefulness and his lack of close acquaintance with men
in this country and, still more, on the Continent. Burke found that both
the Prime Minister and Grenville had not the slightest fear of the effect
of revolutionary ideas in this Kingdom “either at present or at any time
908
to come.” Here Burke was the truer prophet. But how could Pitt sift
the wise from the unwise in the copious output of Burke’s mind? They
mingle so closely as to bewilder the closest observer even now, when
the mists of passion enveloping those controversies have partly cleared
away. Sentiment palpitated visibly in all Burke’s utterances; and the
teachings of the philosopher were lost amidst the diatribes of the
partisan.
In fact, it was difficult for a practical statesman to take the orator
seriously. In April 1791 he had furiously attacked Pitt’s Russian policy;
and, as we have seen, the differences between them were more than
political, they were temperamental. No characteristic of Pitt is more
remarkable than the balance of his faculties and the evenness of his
disposition. No defect in Burke’s nature is more patent than his lack of
self-control, to which, rather than to his poverty, I am inclined to
ascribe his exclusion from the Whig Cabinets. Irritability in small things
had long been his bane; and now to the solution of the greatest
problem in modern history he brought a fund of passion and prejudice
equal to that of any of the French émigrés who were pestering the
Courts of Europe to crush the new ideas by force.
Yet, however much Pitt mistrusted Burke the politician, he admired
him as a writer; so at least we gather from a somewhat enigmatical
reference in Wilberforce’s diary. “22nd November (1790): Went to
Wimbledon—Dundas, Lord Chatham, Pitt, Grenville, Ryder. Much talk
about Burke’s book. Lord Chatham, Pitt and I seemed to agree: contra,
909
Grenville and Ryder.” If this entry be correct, Wilberforce and
Grenville were destined soon to change their opinions. It may be that
Pitt and Wilberforce agreed with Burke owing to their dislike of the
iconoclastic methods of the French democrats, and that Grenville’s cold
nature was repelled by the sentimentalism of the book.
In their judgements on the French Revolution Pitt and Burke stood
not far apart. Pitt knew France no better than the great Irishman, and
he distrusted theorizers and rash innovators fully as much, especially
when their symmetrical notions were carried out by mobs. But the two
men differed sharply as to the remedy. Burke came to believe more
and more in armed intervention; Pitt saw in it ruin for French royalists
and turmoil throughout the Continent. Here again the difference was
in the main one of temperament. In Burke’s nature the eagerness and
impulsiveness of the Celt was degenerating into sheer fussiness, which
drew him toward the camp of the émigrés who strutted and plotted at
Turin and Coblentz. Pitt’s coolness and reserve bade him distrust those
loud-tongued fanatics, whose political rhapsodies awoke a sympathetic
chord in no ruler save Gustavus of Sweden. True, Catharine of Russia
shrilly bade them Godspeed; but, as we shall see, her distant blessings
were the outcome of Muscovite diplomacy rather than of royalist zeal.
Pitt and Grenville, who saw other things in life besides the woes of
Marie Antoinette and Jacobin outrages, were resolved not to lead the
van of the monarchical crusade. They might approve Burke’s sage
production, the “Appeal from the New to the Old Whigs,” which won
the warm commendation of the King, as well as of Grenville, Camden,
and Dundas, but they were bent on maintaining strict neutrality on the
French Question. Pitt and his cousin met Burke more than once in the
summer and autumn of 1791; but they kept their thoughts veiled,
probably because Burke was working hard for the royalist league
which the French Princes hoped to form. The general impression
produced on Burke was that the Court of St. James would certainly not
act against the champions of monarchy, but would preserve a
benevolent neutrality. Other observers took a different view. The
Russian ambassador, Vorontzoff, declared that Pitt was a democrat at
heart, and kept up the naval armaments in order to intimidate the
royalists, while he sent Hugh Elliot to Paris to concert measures along
910
with Barnave. These stories are of value merely because they
illustrate Pitt’s power of holding back his trump cards and thereby
rehabilitating the national prestige, which had recently suffered at the
hands of the Czarina. At such a crisis silence is often a potent weapon.
The Arab “Book of Wisdom” asserts that wisdom consists in nine parts
of silence; while the tenth part is brevity of utterance. If Burke had
realized this truth, his political career would not have ended in
comparative failure. By acting on it, Pitt disconcerted his interviewers
and exasperated his biographers; but he helped to keep peace on the
Continent for nearly a year longer; and he assured that boon to his
country for nearly two years. Had Burke been in power, the coalesced
monarchs would have attacked France in the late summer of 1791.
CHAPTER XXV
THE DISPUTE WITH SPAIN
How curiously the wheels of human action act and interact! The
outrage on British sailors on the dimly known coast of Vancouver
Island furnished French democrats with a potent motive for driving
another nail into the coffin of the old monarchy. In any case the
right of Louis XVI to declare war and make peace would have been
challenged—for how can Democracy allow a Sovereign wholly to
control its policy at the most important of all crises—but now the
need was overwhelming. If the old prerogative held good, the rusty
link that bound together the fortunes of France and Spain would
compel free Frenchmen to fight their English neighbours whenever a
Spanish captain thought fit to clap in irons British voyagers to the
Pacific.
The question aroused gusts of passion at Paris. Enormous
crowds waited outside the Tuileries while the deputies hard by were
debating this question (16th and 22nd May). To the surprise of the
people the royal prerogative was upheld by Mirabeau. The great
orator descanted forcibly on the need of energy and secrecy in the
diplomacy of a great nation, and reminded those who ascribed all
wars to the intrigues of Courts that popular assemblies had often
declared war in a fit of passion. He remarked that members had all
applauded a speaker who advocated war against England if she
attacked Spain, and the expenditure of their last man and their last
926
crown in reducing London. Few of Mirabeau’s speeches were
more convincing. Nevertheless, on coming forth from the Chamber
he was threatened with violence; and a pamphlet, “Great Treason of
Count Mirabeau” was hawked about the streets. His reasoning,
however, ensured the carrying of a compromise on 22nd May. The
right of declaring war and making peace was vested in the King: and
war was to be decided only by a decree of the Legislature, on “the
formal and necessary proposition of the King, and afterwards
927
sanctioned by him.” The position was thus left far from clear; and
Camille Desmoulins, referring to the ups and downs of the debate,
summarized it thus: “The question was decided, firstly, in favour of
the nation, secondly, in favour of the King; thirdly, in favour of both.”
The royalists were highly displeased. Their best speaker, Cazalès,
declared that nothing was now left to the monarchy—an exclamation
which probably revealed his disgust at the passing away of the
opportunity of a war with England.
Meanwhile Pitt had worked hard to array his allies, Prussia and
Holland, against Spain. In this he succeeded. In particular, he
offered to the Dutch a considerable subsidy for arming a squadron
as if for war. To this topic he referred in a letter of 18th May 1790, to
Auckland. After informing him that the tellership of the Exchequer
would be reserved for him, or one of his sons, besides a pension of
£2,000 a year on retirement, he continued thus:
The efforts which the Court of Madrid then put forth at St.
Petersburg and Vienna showed its resolve to concert a league
against England in which Denmark was to be included. This scheme,
as visionary as the grandiose dreams of Alberoni, caused our
Ministers some concern, until they found that their Allies, Prussia
and Holland, were resolved to support them. On 20th May Hertzberg
assured Ewart, that Prussia would fulfil her engagements, if Spain
931
pushed matters to extremes.
Nevertheless, for a time everything portended war. Fitzherbert,
after reaching Aranjuez on 10th June, became convinced that
Floridablanca, for all his peaceful assurances, intended to force a
rupture at the first favourable opportunity. The Spanish Court
absolutely refused to grant satisfaction for the injury done to Meares
and Colnett, because that would imply the right of British subjects to
932
be at Nootka. For the very same reason the Pitt Cabinet pressed
its preliminary demand. It also brushed aside the Spanish
pretensions of sole sovereignty on the Nootka coasts, because
British and other seamen had for some little time traded there—an
933
assertion difficult to maintain.
The deadlock was therefore complete; and, if Spain could have
looked forward to help either from France, Russia, or Austria, war
would inevitably have ensued. It is of interest to observe that, as the
crisis became acute, Pitt adopted his usual habit of writing the drafts
of the most important despatches; and they were sent off without
alteration. He thus disposed of the suggestion of Floridablanca, that
the whole matter in dispute should be settled by arbitration. “Your
Excellency will not be surprised that they are such as cannot be
adopted. The idea of an arbitration upon a subject of this nature
must be entirely out of the question; and a reservation such as that
contained in the second proposal would render the satisfaction
nugatory, as it would refer to subsequent discussion the very ground
934
on which that satisfaction is demanded.”
The outlook was not brightened by the suggestion of
Floridablanca, that Spain should keep the whole of the coast from
California up to and including Nootka; that from that inlet
northwards to 61°, British and Spaniards should have conjointly the
right of trading and forming establishments; and that British sailors
should enjoy certain fishery rights in the South Sea on uninhabited
935
islands far removed from Spanish settlements. These proposals
seemed, as they doubtless were, a device to gain time until France,
Austria, or Russia could step forth and help Spain; and Pitt refused
to admit these “chimerical claims of exclusive sovereignty over the
American Continent and the seas adjacent,” which were to Spain
936
herself “rather matter of useless pride than of actual advantage.”
Towards the end of July more peaceful counsels prevailed at Madrid,
probably because the weak and luxurious King, Charles IV, disliked
war, and dreaded contact with Revolutionary France. Further it must
have transpired that Russia and Austria, owing to their war with
Turkey, were not likely to give more than good wishes to Spain.
Either for these reasons, or because he hoped that delay would tell
in favour of Spain, Floridablanca signed with Fitzherbert on 24th July
a Declaration that Spain would give satisfaction for the seizure of
British vessels and their cargoes at Nootka. On 5th August Grenville
937
informed the King of this auspicious turn of affairs.
But now, while the Court of Madrid abated its pretensions,
French patriots began to rattle the sword in the scabbard. For
reasons which are hard to fathom, the Spanish request for armed
assistance, which reached Paris on 16th June, was not presented to
the National Assembly until 2nd August. On that day Montmorin
informed the deputies of the continuance of naval preparations in
England, and declared that, unless French aid were accorded to
Spain, she would seek an ally elsewhere. The statement was well
calculated to awaken jealousy of England; and members came to the
conclusion that the islanders were seeking, in the temporary
weakness of France, to bully the Court of Madrid out of its just
rights. Consequently the whole matter was referred to the newly
appointed Diplomatic Committee which supervised the work of the
938
Foreign Office. As this body now practically controlled French
diplomacy, everything became uncertain; and it is not surprising that
Pitt and Leeds declined to disarm now that the question of peace or
war depended on an emotional Assembly and its delegates.
At the head of this new controlling body was Mirabeau. As
Reporter of the Committee he held a commanding position, which
was enhanced by his splendid eloquence, forceful personality, and
knowledge of the shady by-paths of diplomacy. The Report which he
presented to the Assembly on 25th August was, in effect, his. While
minimizing the importance of the Nootka dispute, scoffing at the old
diplomacy, and declaring that Europe would not need any diplomacy
when there were neither despots nor slaves, he yet proposed that,
pending the advent of that glorious age, France must not abrogate
her treaties but continue to respect them until they had been
subjected to revision. Further, in place of the Family Compact of the
Kings of France and Spain, he proposed to substitute a National
Compact, based on the needs of the two nations. On the following
day he continued his speech and moved that France and Spain
should form a national treaty in the interests of peace and
conformable to “the principles of justice which will ever form the
policy of the French.” What was far more significant, he himself
added a rider for the immediate armament of forty-five sail of the
line and a proportionate number of smaller vessels. This was carried
939
immediately.
Seeing that the Assembly passed this vote at the very time when
the terrible mutiny at Nancy was at its height, the feelings of the
deputies must have been of the bellicose order which Mirabeau had
previously deprecated. Despite the pressing need for peace, France
seemed to be heading straight for war. On ordinary grounds her
conduct is inexplicable. Everywhere her troops were clamouring for
arrears of pay; her sailors could scarcely be kept together; and the
virtual bankruptcy of the State was a week later to be quaintly
revealed by the flight of Necker to Switzerland. The King and his
Ministers disapproved the arming of so large a fleet; for Montmorin
confessed to Gower his surprise and regret, adding the comforting
assurance that it would be done as slowly as possible. The mystery
deepens when we know that Floridablanca continued to speak in
peaceful tones. On 19th August he admitted to Fitzherbert that he
desired help from Russia and Austria, but felt complete indifference
as to what France might do. Aid from her, he said, would lead to the
introduction of democratic principles, which he was determined to
keep out, if need arose, by a cordon along the frontier, as one would
940
exclude the plague.
Here probably we have the key to the enigma. The recent action
of Mirabeau (for the arming of the French naval force was his
proposal, not Montmorin’s) rested on the assumption that Spain did
not mean to draw the sword. His agents at the various Courts kept
him well abreast of events, and doubtless he foresaw that Charles
IV’s hatred of democracy would bar the way to an alliance of the two
peoples such as was now projected. Why, then, should Mirabeau
have threatened England with war? His reasons seem to have been
partly of a patriotic, partly of a private, nature. He desired to restore
the prestige of the French monarchy by throwing its sword into the
wavering balances of diplomacy. As to the expense, it was justifiable,
if it tended to revive the national spirit and to quell the mutinous
feelings of the sailors. Work, especially if directed against “the
natural enemy,” would be the best restorative of order at the
dockyards, and prevent the deterioration of the navy. But apart from
these motives Mirabeau may have been swayed by others of a lower
kind. His popularity had swiftly waned during the previous debates.
He might revive it by pandering to the dislike of England now widely
prevalent. Manufacturers who suffered by English competition and
Chauvinists who dreaded her supremacy at sea were joining in a hue
941
and cry against Pitt; and Mirabeau gained credit by posing as the
national champion. Further, by holding peace and war, as it were, in
the folds of his toga, he enhanced his value in the diplomatic
market. His corruptibility was notorious. Even the sums which he
drew from the King were far from meeting the yawning gulf of his
debts.
In the present case there was much to tempt him to political
auctioneering. There were present in Paris two political agents to
whom Pitt had confided the task of humouring the French democrats
and dissolving the Family Compact. These were William Augustus
Miles and Hugh Elliot. The former was a clever but opinionated man,
half statesman, half busy-body, capable of doing good work when
kept well in hand, but apt to take the bit into his teeth and bolt. He
had already looked into the affairs of Brabant, Liége, and Frankfurt
for Pitt; and as early as 4th March the Prime Minister summoned him
to Downing Street for the purpose of sending him to Paris; but not
till the middle of July did he finally entrust to him the task of
inducing French deputies to annul the Family Compact. That this was
to be done secretly appears from the order that he was to have no
942
dealings whatever with the British Embassy. Unfortunately the
letters which passed between Pitt and Miles at this time have all
943
been destroyed. But we know from other sources that Miles was
charged to prepare the way for an Anglo-French entente. He
certainly made overtures to Talleyrand, Mirabeau, and Lafayette; he
was also elected a member of the Jacobins Club, and worked hard to
remove the prejudices against England. These he found exceedingly
strong, all the troubles in the fleet being ascribed to her. By 11th
October he had fulfilled his mission, and informed George Rose that
Pitt might, if he chose, form a close working alliance with the French
nation. About the same time he conceived for Mirabeau the greatest
contempt, and asserted that it was “impossible to know him and not
944
to despise him.”
Elliot was a man of far higher stamp than Miles. As we have
seen, he had had a distinguished diplomatic career, and might be
termed the saviour of Gustavus III in the acute crisis of 1788. He
was brother of Sir Gilbert Elliot (first Earl of Minto), and of Lady
Auckland. In the summer of 1790 he was home on furlough. On 7th
August he wrote from Beckenham, Auckland’s residence,
congratulating Pitt on a favourable turn in the Spanish dispute.
When the outlook once more darkened he requested leave to go to
Paris in order to use his influence with his friend, Mirabeau, in the
interests of peace. Pitt must have referred the proposal to the King,
and received a very guarded reply, dated Windsor, 26th October.
George enjoined great caution, as we had hitherto held entirely aloof
from the French troubles, and must on no account be mixed up in
them. Yet, for the sake of peace, he did not object to this attempt,
so long as it was entirely unofficial; but he was “not sanguine that
Mr. H. Elliot and his French friend” would succeed where so much
945
caution and delicacy were necessary.
As this affair is wrapped in mystery, and concerns not only the
peace of the world, but also that most interesting personality,
Mirabeau, the draft of an undated letter of Pitt to the King must be
quoted in full:
The hints here given imply that Mirabeau, and probably other
patriots as well, accepted British money, but both our envoys were
discreet enough to give few details in writing. It is quite probable
that Mirabeau first accepted Spanish gold for procuring the vote for
the arming of forty-five French sail of the line, and then accepted an
equivalent sum from Miles or Elliot for the decree which rendered
that step innocuous. His control over the Assembly was scarcely less
951
than Montmorin’s; and that nervous Minister would certainly
welcome a course of action which enhanced the prestige of France,
and yet averted all risk of war. Nevertheless, Pitt did not set much
store by the help of Mirabeau. He decided to bring the whole dispute
to an immediate issue, without waiting for the issue of the golden
proposals of Elliot and Miles. Possibly he heard from other sources
that France would do no more than rattle the sword in the scabbard;
or else he was emboldened by the marked success and zeal
attending the British naval preparations, the mutinies in the French
fleet, the readiness of our Allies to play their part, and the
unreadiness of Spain. A brief survey of these considerations will
reveal the grounds of his confidence.
The chance of hostilities with the two Bourbon Courts was
threatening enough to call forth all the energies of the race. Through
the months of August, September, and October naval preparations
went on with the utmost vigour. Officers and men vied with one
another in zeal to equip and man the ships with all possible speed
and thoroughness. Sir John Jervis afterwards assured the House of
Commons that he had seen captains paying out their own money by
hundreds of pounds in order to expedite the equipment; others
sailed their ships down Channel with mere skeleton crews in order to
hasten the rally at Plymouth; and by dint of drills from sunrise to
952
sunset the crews were hardened to their work. In truth, the
dominant fact of the situation was England’s overwhelming
supremacy at sea over Spain, and possibly over Spain and France
together.
The Triple Alliance also proved to be a reality. The prospect of a
war with Spain was, of course, distasteful both at Berlin and The
Hague; but our Allies admitted that Spain was the aggressor, and
signified their readiness to support us. This should be noted, for it
imposed on Pitt a debt of honour to support Prussia when her
summons for help against the Czarina arrived at Whitehall in the
month of March following.
Further, the ambitions of the Czarina already threatened the
equilibrium of Europe; and in this fact we find the last, and perhaps
the most cogent, of the reasons why Pitt and his colleague resolved
to have done with the Spanish dispute before the Eastern Question
came to a crisis. This appears very clearly in Leeds’ despatch of 2nd
October to our ambassador at Madrid, which was in effect an
ultimatum to that Court. He warned Fitzherbert that the Spanish
proposals were quite inadmissible, and that “neither the
circumstances of the negotiation, nor the relative situation of the
two countries and of other Powers in Europe can allow of any further
delay”; he therefore pressed for the immediate acceptance of the
British demands. An explanatory note accompanied the ultimatum,
stating that Spain ought to desire the preservation of the existing
system in Europe, which was threatened solely by the Empress
Catharine, who spurned the counsels of moderation offered by the
953
Allies.
It appears, then, that the threatening aspect of affairs in the
East in part accounts for Pitt’s sudden and imperious demand. He
resolved to finish with Spain so as to have his hands free for the
Eastern Question. As appeared in an earlier chapter, the Czarina,
Catharine II, had recently concluded peace with Sweden; and,
despite the promised negotiations of the Viennese Court for peace
with the Turks, she seemed determined to press them hard, and to
wring from them a district then deemed necessary to the defence of
the Ottoman Power. Her dalliance with Spain was far from serious;
but she might, if allowed time, concert a formidable league against
England. The voice of prudence, therefore, counselled the immediate
coercion of Spain, while Russia was entangled in a still doubtful
strife. Machiavelli shrewdly remarked that “the Romans never
swallowed an injury to put off a war; for they knew that war was not
avoided but only deferred thereby, and commonly with advantage to
954
the enemy.”
But Pitt needed not to go to Machiavelli. Facts spoke more
convincingly than words to a nature like his; and the news from Paris
and Madrid called aloud for a display of energy. The insubordination
at the French dockyards and the news from Paris had told on the
nervous and pedantic King of Spain. On 16th September Fitzherbert
wrote to the Duke of Leeds that that monarch had very decidedly
expressed his resolve never to have an alliance with France on the
basis of a National Compact as proposed by Mirabeau. It appears,
then, that the great orator had a decisive effect in working on the
fears and scruples of His Catholic Majesty, and thus assuring the
isolation of Spain. If Mirabeau received British money from Miles and
Elliot a month or so later, he might claim it as payment for valuable
services already rendered. However that may be, it is certain that
Pitt, on receiving the glad news from Fitzherbert on 27th September,
decided to take vigorous action. Fitzherbert advised tact and
patience in dealing with that proud Court; but Pitt and Leeds waived
aside the advice and resolved to thrust their adversary into a corner.
In view of the more complaisant attitude of the Spanish
Government, their action was unchivalrous; but it was justified by
the tidings which had arrived of cruelties perpetrated by a Spanish
warship on the captain of a English merchantman in the Gulf of
955
Florida, who was set in the bilboes in the blazing sun. Public
opinion would certainly have supported Pitt in case of a rupture with
an enemy whose claims and customs were still those of the fifteenth
century; and he was resolved to end the dominion of Spain in the
North Pacific with as little ceremony as Cromwell had shown in his
expedition against Jamaica in 1654.
Now there was little fear of war. The pride of Charles IV centred
in trophies of the chase; and his weak and slothful nature revolted at
the thought of an alliance with France on Mirabeau’s terms.
Moreover, Russia and Austria had paid little heed to the recent
appeals of Floridablanca, and there was war with the Moors outside
Tangier. Was not this enough? For a few days the Council of
Ministers breathed threats of war. Floridablanca struggled hard
against the relentless grip which had closed around him. But he was
helpless, and he knew it. Therefore on Sunday, 24th October, the
Spanish Minister, after much angry remonstrance, gave way, and
agreed to the British terms.
Meanwhile, Pitt had allowed Fitzherbert to recede slightly on
some of the conditions, and urged that Spain should be invited to
frame an alliance with us, both political and commercial. As usual, in
affairs of great moment, he himself wrote the draft of this despatch,
956
which was sent off without alteration. This skilful angling was of
no avail. Spanish pride was too deeply wounded to admit of any
possibility of alliance, whether political or commercial, for many
years to come. In other respects Pitt gained his point; and the
following letter to Bishop Pretyman (Tomline) shows his relief at the
end to the long strain:
957
Thursday, Nov. 4, 1790.
Dear Bishop,
The decisive answer arrived this morning and is
perfectly satisfactory. The Spanish Minister at last agreed, on the
24th of October, to a projet of a Convention containing all we
wish, and it was settled that it should be actually signed in three
days from that time. The terms will be found to secure all that
we could demand in justice, or had any reason to desire.
Accordingly, on 28th October 1790 (after four days, not three),
the Court of Madrid signed the Convention which opened up a new
future for the North Pacific. By it Spain agreed to restore the
buildings and lands at Nootka to the British subjects whom Martinez
had dispossessed. Reparation was also to be made for any outrages
committed by the subjects of either Power against those of the other
958
since April 1789. Britons and Spaniards were to have full liberty
to trade in North-West America, that is, to the north of the Spanish
settlements; but of course all the coasts to the south of them were
to remain closed as heretofore. Spain, however, conceded entire
freedom of navigation and fishery in the Pacific Ocean and the South
Seas, except that, in order to preclude all intercourse with her
colonies, British ships were forbidden to approach within a limit of
ten maritime leagues.
The British public greeted this happy issue of events with
characteristic reserve. As Spain stood for commercial monopoly and
political reaction, the rebuff dealt to her ought to have pleased the
Whigs. But party rancour increased in proportion to Pitt’s success.
Hope deferred made the hearts of his opponents sick; and to this
cause we may attribute curiously acrid verdicts like that of
Auckland’s correspondent, Storer, who exclaimed on 22nd October,
with the jauntiness of ignorance: “Here we are, going to war, and for
what? A place, the name of which I can scarcely pronounce, never
heard of till lately, and which did not exist till t’other day. Pitt is tired
of peace. He bullied France so effectually three years ago that he is
determined to try the same thing with Spain.” Storer also says that
our officers were in high spirits at the idea of a voyage to Mexico,
and were buying Ulloa’s “Voyage” so as to study the South Sea
959
coasts. Whence it would appear that geography was not a strong
point with Storer, and that in his eyes wars were worth waging only
on behalf of well-known names. How curiously parochial is this habit
of mind. Yet Pitt was destined soon to find out its self-assertiveness
and tenacity in the case of another un-euphonious and dimly-known
place—Oczakoff.