diff --git a/docs/dev/virtualenvs.rst b/docs/dev/virtualenvs.rst index b4591e43b..fe6bd3f9e 100644 --- a/docs/dev/virtualenvs.rst +++ b/docs/dev/virtualenvs.rst @@ -156,7 +156,7 @@ when you share your project with others. You should get output similar to this Adding requests to Pipfile's [packages]... P.S. You have excellent taste! ✨ 🍰 ✨ -.. _Requests: http://docs.python-requests.org/en/master/ +.. _Requests: https://requests.readthedocs.io/en/latest/ Using installed packages diff --git a/docs/scenarios/admin.rst b/docs/scenarios/admin.rst index 07d263945..f6433c213 100644 --- a/docs/scenarios/admin.rst +++ b/docs/scenarios/admin.rst @@ -155,44 +155,42 @@ tests (net, CPU) fail, it will send an email. # Package for email services: import smtplib import string - MAX_NET_USAGE = 400000 + MAX_NET_USAGE = 400000 # bytes per seconds MAX_ATTACKS = 4 attack = 0 - counter = 0 while attack <= MAX_ATTACKS: sleep(4) - counter = counter + 1 - # Check the cpu usage - if cpu_percent(interval = 1) > 70: - attack = attack + 1 - # Check the net usage - neti1 = net_io_counters()[1] - neto1 = net_io_counters()[0] + + # Check the net usage wit named tuples + neti1 = net_io_counters().bytes_recv + neto1 = net_io_counters().bytes_sent sleep(1) - neti2 = net_io_counters()[1] - neto2 = net_io_counters()[0] + neti2 = net_io_counters().bytes_recv + neto2 = net_io_counters().bytes_sent + # Calculate the bytes per second net = ((neti2+neto2) - (neti1+neto1))/2 - if net > MAX_NET_USAGE: - attack = attack + 1 - if counter > 25: - attack = 0 - counter = 0 + + # Check the net and cpu usage + if (net > MAX_NET_USAGE) or (cpu_percent(interval = 1) > 70): + attack+=1 + elif attack > 1: + attack-=1 + # Write a very important email if attack is higher than 4 TO = "you@your_email.com" FROM = "webmaster@your_domain.com" SUBJECT = "Your domain is out of system resources!" text = "Go and fix your server!" - BODY = string.join(("From: %s" %FROM,"To: %s" %TO,"Subject: %s" %SUBJECT, "",text), "\r\n") + string="\r\n" + BODY = string.join(("From: %s" %FROM,"To: %s" %TO, + "Subject: %s" %SUBJECT, "",text)) server = smtplib.SMTP('127.0.0.1') server.sendmail(FROM, [TO], BODY) server.quit() -A full terminal application like a widely extended top which is based on -psutil and with the ability of a client-server monitoring is -`glance `_. - +A full terminal application like a widely extended top is `Glance `_, which is based on psutil and has the ability for client-server monitoring. ******* Ansible @@ -397,17 +395,3 @@ up. Buildout is primarily used to download and set up dependencies in `Python eggs `_ format of the software being developed or deployed. Recipes for build tasks in any environment can be created, and many are already available. - - -******* -Shinken -******* - -`Shinken `_ is a modern, Nagios compatible -monitoring framework written in Python. Its main goal is to give users a flexible -architecture for their monitoring system that is designed to scale to large -environments. - -Shinken is backwards-compatible with the Nagios configuration standard and -plugins. It works on any operating system and architecture that supports Python, -which includes Windows, Linux, and FreeBSD. diff --git a/docs/scenarios/client.rst b/docs/scenarios/client.rst index 1457fa479..c2d5c289b 100644 --- a/docs/scenarios/client.rst +++ b/docs/scenarios/client.rst @@ -28,7 +28,7 @@ your URLs, or to form-encode your POST data. Keep-alive and HTTP connection pooling are 100% automatic, powered by urllib3, which is embedded within Requests. -- `Documentation `_ +- `Documentation `_ - `PyPi `_ - `GitHub `_ diff --git a/docs/scenarios/imaging.rst b/docs/scenarios/imaging.rst index 7b0e71935..8fe7e08fe 100644 --- a/docs/scenarios/imaging.rst +++ b/docs/scenarios/imaging.rst @@ -62,7 +62,7 @@ Example exif_data There are more examples of the Pillow library in the -`Pillow tutorial `_. +`Pillow tutorial `_. *************************** @@ -109,4 +109,4 @@ Example There are more Python-implemented examples of OpenCV in this `collection of tutorials -`_. +`_. diff --git a/docs/scenarios/scrape.rst b/docs/scenarios/scrape.rst index 54747b295..527719200 100644 --- a/docs/scenarios/scrape.rst +++ b/docs/scenarios/scrape.rst @@ -28,7 +28,7 @@ lxml and Requests `lxml `_ is a pretty extensive library written for parsing XML and HTML documents very quickly, even handling messed up tags in the process. We will also be using the -`Requests `_ module instead of the +`Requests `_ module instead of the already built-in urllib2 module due to improvements in speed and readability. You can easily install both using ``pip install lxml`` and ``pip install requests``. diff --git a/docs/scenarios/xml.rst b/docs/scenarios/xml.rst index 3bdf15b6c..24dab5869 100644 --- a/docs/scenarios/xml.rst +++ b/docs/scenarios/xml.rst @@ -81,3 +81,30 @@ and then you can access elements, attributes, and values like this: xmltodict also lets you roundtrip back to XML with the unparse function, has a streaming mode suitable for handling files that don't fit in memory, and supports XML namespaces. + +********** +xmlschema +********** + +`xmlschema `_ provides support for using XSD-Schemas in Python. +Unlike other XML libraries, automatic type parsing is available, so f.e. if the schema defines an element to be of type ``int``, the parsed ``dict`` will contain also an ``int`` value for that element. +Moreover the library supports automatic and explicit validation of XML documents against a schema. + +.. code-block:: python + + from xmlschema import XMLSchema, etree_tostring + + # load a XSD schema file + schema = XMLSchema("your_schema.xsd") + + # validate against the schema + schema.validate("your_file.xml") + + # or + schema.is_valid("your_file.xml") + + # decode a file + data = schmema.decode("your_file.xml") + + # encode to string + s = etree_tostring(schema.encode(data)) diff --git a/docs/starting/install/osx.rst b/docs/starting/install/osx.rst index d0aa601aa..4a8a8e03b 100644 --- a/docs/starting/install/osx.rst +++ b/docs/starting/install/osx.rst @@ -10,9 +10,10 @@ Installing Python 2 on Mac OS X .. note:: Check out our :ref:`guide for installing Python 3 on OS X`. -**Mac OS X comes with Python 2.7 out of the box.** +**Mac OS X comes with Python 2.7 out of the box between versions 10.8 and 12.3.** -You do not need to install or configure anything else to use Python. Having said +If your Mac OS X version is between the above versions, +you do not need to install or configure anything else to use Python. Having said that, I would strongly recommend that you install the tools and libraries described in the next section before you start building Python applications for real-world use. In particular, you should always install Setuptools, as it makes diff --git a/docs/starting/install3/osx.rst b/docs/starting/install3/osx.rst index 37252d615..fa90fb93a 100644 --- a/docs/starting/install3/osx.rst +++ b/docs/starting/install3/osx.rst @@ -9,9 +9,10 @@ Installing Python 3 on Mac OS X .. image:: /_static/photos/34435689480_2e6f358510_k_d.jpg -**Mac OS X comes with Python 2.7 out of the box.** +**Mac OS X comes with Python 2.7 out of the box between versions 10.8 and 12.3.** -You do not need to install or configure anything else to use Python 2. These +If your Mac OS X version is between the above versions, +you do not need to install or configure anything else to use Python 2. These instructions document the installation of Python 3. The version of Python that ships with OS X is great for learning, but it's not diff --git a/docs/writing/reading.rst b/docs/writing/reading.rst index ad67ea3cb..1e03a4def 100644 --- a/docs/writing/reading.rst +++ b/docs/writing/reading.rst @@ -43,7 +43,7 @@ reading. Each one of these projects is a paragon of Python coding. Requests is an Apache2 Licensed HTTP library, written in Python, for human beings. -- `Tablib `_ +- `Tablib `_ Tablib is a format-agnostic tabular dataset library, written in Python. diff --git a/docs/writing/style.rst b/docs/writing/style.rst index 9858112de..d8c096a05 100644 --- a/docs/writing/style.rst +++ b/docs/writing/style.rst @@ -465,8 +465,7 @@ easy-to-read version of PEP 8 is also available at `pep8.org ` This is highly recommended reading. The entire Python community does their best to adhere to the guidelines laid out within this document. Some project -may sway from it from time to time, while others may -`amend its recommendations `_. +may sway from it from time to time, while others may amend its recommendations. That being said, conforming your Python code to PEP 8 is generally a good idea and helps make code more consistent when working on projects with other diff --git a/runtime.txt b/runtime.txt index 5a958026d..cc1923a40 100644 --- a/runtime.txt +++ b/runtime.txt @@ -1 +1 @@ -3.5 +3.8