gocept.country


Namegocept.country JSON
Version 3.0 PyPI version JSON
download
home_pagehttps://github.com/gocept/gocept.country
SummaryZope 3 sources for pycountry databases
upload_time2023-07-14 12:46:41
maintainer
docs_urlNone
authorgocept gmbh & co. kg
requires_python>=3.7
licenseZPL 2.1
keywords country subdivision language currency iso 3166 639 4217 15924 3166-2 zope pycountry
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            Copyright (c) 2008-2015 gocept gmbh & co. kg

All Rights Reserved.

This software is subject to the provisions of the Zope Public License,
Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
FOR A PARTICULAR PURPOSE.


==============
gocept.country
==============

.. image:: https://github.com/gocept/gocept.country/workflows/tests/badge.svg
    :target: https://github.com/gocept/gocept.country/actions?query=workflow%3Atests
.. image:: https://coveralls.io/repos/github/gocept/gocept.country/badge.svg?branch=master
    :target: https://coveralls.io/github/gocept/gocept.country?branch=master


This package lets you use the `pycountry database
<http://pypi.python.org/pypi/pycountry/>`_ within Zope 3.


In practice, this means e.g., that you can easily get a zope.schema.Choice
field to provide a full list of iso 3166 country codes.

For more information about the database please refer to the
`pycountry product <http://pypi.python.org/pypi/pycountry/>`_.

.. contents::


Introduction
============

`gocept.country` provides Zope 3 sources for the pycountry databases. You can
use it e.g. to get a ``zope.schema.Choice`` field with all ISO 3166 countries.

  >>> import gocept.country
  >>> import gocept.country.db
  >>> import zope.schema


ISO 3166 Countries
==================

To get a list of ISO 3166 countries in a web form, you can use the
``zope.schema.Choice`` field and provide the gocept.country.countries as
source:

  >>> countries_field = zope.schema.Choice(title=u'Country',
  ...                            source=gocept.country.countries)
  >>> countries_field
  <zope.schema._field.Choice object at 0x...>
  >>> countries = iter(countries_field.source)


The ``gocept.country.countries`` source factory returns Country objects as
values, which use the values from pycountry:

  >>> aruba = next(countries)
  >>> afghanistan = next(countries)
  >>> afghanistan
  <gocept.country.db.Country object at 0x...>
  >>> print(afghanistan.name)
  Afghanistan


Calling ``next()`` again returns the next country from the source:

  >>> angola = next(countries)
  >>> print(angola.name)
  Angola


There are all information available, which you can get from pycountry:

  >>> print(afghanistan.alpha_2)
  AF
  >>> print(afghanistan.alpha_3)
  AFG
  >>> print(afghanistan.numeric)
  004
  >>> print(afghanistan.official_name)
  Islamic Republic of Afghanistan


To reduce the amount of results you can provide a list or tuple of countries
you like to have in your source:

  >>> countries = gocept.country.CountrySource(alpha_2=['DE', 'US'])
  >>> print(*[countries.factory.getTitle(x) for x in countries], sep=', ')
  Germany, United States
  >>> print(*[countries.factory.getToken(x) for x in countries], sep=', ')
  DE, US

Please note, that the result items are sorted by *alpha_2* code. Please also
note, that you can provide alpha_3 and numeric codes and names resp.
official_names to reduce the amount of result items, too:

  >>> len(list(gocept.country.CountrySource())) > 200
  True
  >>> len(list(gocept.country.CountrySource(alpha_2=['DE', 'US', 'GB'])))
  3
  >>> len(list(gocept.country.CountrySource(alpha_3=['DEU', 'USA'])))
  2
  >>> len(list(gocept.country.CountrySource(numeric=['276', ])))
  1
  >>> countries_list = ['Germany', 'Italy', 'Poland', 'France']
  >>> len(list(gocept.country.CountrySource(name=countries_list)))
  4


Providing codes, which are not present, does not result in an exception but
in an empty list:

  >>> len(list(gocept.country.CountrySource(capital=['Berlin', 'Paris'])))
  0

ISO 3166-2 Country subdivisions
===============================

Context free source
-------------------

Country subdivisions are similar to countries:

  >>> subdivisions_field = zope.schema.Choice(
  ...     title=u'Country subdivisions', source=gocept.country.subdivisions)
  >>> subdivisions = iter(subdivisions_field.source)

  >>> canillo = next(subdivisions)
  >>> print(canillo.name)
  Canillo
  >>> print(canillo.code)
  AD-02

  >>> encamp = next(subdivisions)
  >>> print(encamp.name)
  Encamp
  >>> print(encamp.code)
  AD-03
  >>> print(gocept.country.subdivisions.factory.getToken(encamp))
  AD-03

Please note, that the result items are sorted by their *code*. Please
also note, that you can provide names and numeric codes to reduce the
amount of result items, too.

  >>> len(list(gocept.country.SubdivisionSource())) > 4000
  True
  >>> len(list(gocept.country.SubdivisionSource(code=['DE-ST', 'US-WA'])))
  2
  >>> len(list(gocept.country.SubdivisionSource(country_code=['DE'])))
  16
  >>> print(*[x.name
  ...         for x in gocept.country.SubdivisionSource(country_code=['DE'])][3:5],
  ...       sep=', ')
  Bayern, Bremen
  >>> len(list(gocept.country.SubdivisionSource(name=[u'Bayern', u'Bremen'])))
  2

Contextual source
-----------------

There is also a contextual source for country subdivisions which
depends on a country. Let's set up a context object first:

  >>> import zope.interface
  >>> class IAddress(zope.interface.Interface):
  ...     country = zope.interface.Attribute("The country of the address.")
  ...     subdivision = zope.schema.Choice(
  ...         title=u'Country subdivisions',
  ...         source=gocept.country.contextual_subdivisions)

  >>> @zope.interface.implementer(IAddress)
  ... class Address(object):
  ...     pass
  >>> address = Address()
  >>> address.country = gocept.country.db.Country('DE')

The contextual source expects an adapter between the context and
``gocept.country.interfaces.ICountry``:

  >>> import zope.component
  >>> import gocept.country.interfaces
  >>> def get_country(context):
  ...     return context.country
  >>> zope.component.provideAdapter(
  ...    get_country, (IAddress, ), gocept.country.interfaces.ICountry)

  >>> print(gocept.country.interfaces.ICountry(address).name)
  Germany

So the source contains only the country subdivisions belonging to the
country:

  >>> len(list(iter(gocept.country.contextual_subdivisions(address))))
  16
  >>> print(*[x.name
  ...         for x in iter(gocept.country.contextual_subdivisions(address))][3:5],
  ...       sep=', ')
  Bayern, Bremen

Changing the country changes also the subdivisions:

  >>> address.country = gocept.country.db.Country('CH')
  >>> len(list(iter(gocept.country.contextual_subdivisions(address))))
  26
  >>> print(*[x.name
  ...         for x in iter(gocept.country.contextual_subdivisions(address))],
  ...       sep=', ')
  Aargau, Appenzell Innerrhoden, ...
  >>> print(*[x.code
  ...         for x in iter(gocept.country.contextual_subdivisions(address))],
  ...       sep=', ')
  CH-AG, CH-AI, ...
  >>> print(*[gocept.country.contextual_subdivisions.factory.getToken(address, x)
  ...         for x in iter(gocept.country.contextual_subdivisions(address))],
  ...       sep=', ')
  CH-AG, CH-AI, ...

  >>> print(gocept.country.contextual_subdivisions.factory.getTitle(
  ...     address, gocept.country.db.Subdivision('CH-AG')))
  Aargau

If the country is not set there are no subdivisions:

  >>> address.country = None
  >>> len(list(iter(gocept.country.contextual_subdivisions(address))))
  0
  >>> list(iter(gocept.country.contextual_subdivisions(address)))
  []


ISO 15924 Scripts
=================

Scripts are similar to countries:

  >>> scripts_field = zope.schema.Choice(title=u'Script',
  ...                            source=gocept.country.scripts)
  >>> scripts = iter(scripts_field.source)


  >>> adlam = next(scripts)
  >>> print(adlam.name)
  Adlam

  >>> afaka = next(scripts)
  >>> print(afaka.name)
  Afaka
  >>> print(gocept.country.scripts.factory.getToken(afaka))
  Afak


Please note, that the result items are sorted by *alpha_4* code. Please also
note, that you can provide names and numeric codes to smaller the amount of
result items, too.

  >>> len(list(gocept.country.ScriptSource())) > 130
  True
  >>> len(list(gocept.country.ScriptSource(alpha_4=['Arab', 'Latn'])))
  2
  >>> len(list(gocept.country.ScriptSource(numeric=['215', ])))
  1
  >>> len(list(gocept.country.ScriptSource(name=['Arabic', 'Latin'])))
  2


ISO 4217 Currencies
===================

Currencies are similar to the ones before:

  >>> currencies_field = zope.schema.Choice(title=u'Currency',
  ...                            source=gocept.country.currencies)

  >>> currencies = iter(currencies_field.source)

  >>> dirham = next(currencies)
  >>> print(dirham.name)
  UAE Dirham

  >>> afghani = next(currencies)
  >>> print(afghani.name)
  Afghani
  >>> print(gocept.country.currencies.factory.getToken(afghani))
  AFN

Please note, that the result items are sorted by *alpha_3* code. Please also
note, that you can provide names and numeric codes to reduce the amount of
result items, too.

  >>> len(list(gocept.country.CurrencySource())) >= 170
  True
  >>> len(list(gocept.country.CurrencySource(alpha_3=['ARS', 'AED', 'AFN'])))
  3
  >>> len(list(gocept.country.CurrencySource(numeric=['032', '784'])))
  2
  >>> len(list(gocept.country.CurrencySource(name=['Afghani', ])))
  1


ISO 639 Languages
=================

Languages are similar, too:

  >>> languages_field = zope.schema.Choice(title=u'Language',
  ...                            source=gocept.country.languages)

  >>> languages = iter(languages_field.source)

  >>> ghotuo = next(languages)
  >>> print(ghotuo.name)
  Ghotuo

  >>> alumu_tesu = next(languages)
  >>> print(alumu_tesu.name)
  Alumu-Tesu
  >>> print(gocept.country.languages.factory.getToken(alumu_tesu))
  aab

Please note, that the result items are sorted by *alpha_3*. Please also
note, that you can provide names to reduce the amount of result items, too.

  >>> len(list(gocept.country.LanguageSource())) > 480
  True
  >>> len(list(gocept.country.LanguageSource(alpha_3=['eng', 'deu'])))
  2
  >>> len(list(gocept.country.LanguageSource(name=['English', 'German'])))
  2


Translations
============


First we fetch a specific country:

  >>> countries = list(iter(countries_field.source))
  >>> germany = [x for x in countries if x.name == u'Germany'][0]


The i18n translate method translates 'Germany' into German:

  >>> print(zope.i18n.translate(germany.name, target_language='de'))
  Deutschland


There are also translations for scripts, currencies and languages.


Comparison
==========


Countries, scripts, currencies and languages can be compared to equality. To
test this, we will need another country object ``afghanistan``, which is not
the *same* object as retrieved before:


  >>> afghanistan = next(iter(gocept.country.CountrySource(alpha_2=['AF'])))
  >>> afghanistan2 = next(iter(gocept.country.CountrySource(alpha_2=['AF'])))

  >>> str(afghanistan) == str(afghanistan2)
  False


Comparing them will get the token for each and compare it:

  >>> afghanistan == afghanistan2
  True
  >>> afghanistan != afghanistan2
  False
  >>> afghanistan != germany
  True
  >>> afghanistan == germany
  False


Comparing with an instance of another class always returns False:

  >>> afghanistan == None
  False
  >>> afghanistan != None
  True
  >>> afghanistan == object()
  False
  >>> afghanistan != object()
  True


Pickling and unpickling
=======================


It should be possible to store "proxy objects" in a database (like the ZODB).
Therefore, they have to be pickleable:

  >>> from io import BytesIO
  >>> import pickle
  >>> f = BytesIO(b'')

Pickling a country should never raise an error...

  >>> pickle.dump(afghanistan, f)


... and results in storing the token in the pickle:

  >>> ignored = f.seek(0)
  >>> b'AF' in f.read()
  True


Reading the pickle again will return the same country which was pickled
before:

  >>> ignored = f.seek(0)
  >>> afghanistan2 = pickle.load(f)
  >>> afghanistan2 == afghanistan
  True
  >>> print(afghanistan2.name)
  Afghanistan


Changes
=======

3.0 (2023-07-14)
----------------

- Drop support for Python 2.7, 3.5, 3.6.

- Add support for Python 3.9, 3.10, 3.11.


2.1 (2019-09-30)
----------------

- Add support for Python 3.5 up to 3.8, PyPy and PyPy3.

- Replace test dependency on `zope.app.testing` by `zope.app.wsgi[testlayer]`.

- Migrate to Github.


2.0 (2017-01-21)
----------------

- Update to ``pycountry >= 16.x``.

- Drop support for Python 2.6.

- Bring test coverage to 100 %.

- Change testrunner to py.test.


1.0 (2015-08-05)
----------------

- Update to ``pycountry 1.12`` thus adding support for ISO 639 3, dropping the
  old ISO 639 support.


0.6.5 (2015-08-05)
------------------

- Move repos to https://bitbucket.org/gocept/gocept.country

0.6.4 (2008-10-21)
------------------

- Bugfix: declared namespace package in setup.py

0.6.3 (2008-10-14)
------------------

- Bugfix: added not-equal compare method for db objects

0.6.2 (2008-10-13)
------------------

- Added security declarations for token.
- Bugfix in comparison of db objects, where `isinstance` returns False
  for objects of the same type

0.6.1 (2008-09-13)
------------------

- Bugfix in countextual subdivision source: parameters of some methods
  where in wrong order.

0.6 (2008-09-12)
----------------

- Added contextual country subdivision source, so country subdivisions
  can depend on the country.


0.5 (2008-09-11)
----------------

- Added support for country subdivisions.

0.4.2 (2008-09-10)
------------------

- Added security declarations for tokens.

0.4.1 (2008-09-10)
------------------

- Fixed bug in token comparison.

0.4 (2008-06-10)
----------------

- added possibility to smaller the amount of results generated by the
  sourcefactory


0.3 (2008-05-21)
----------------

- added test for comparing the returned countries to equality
- added __reduce__ to data objects so that they can be pickled
- added tests for pickling and unpickling data objects


0.2 (2008-05-20)
----------------

- gocept.country now returns special data objects instead of pycountry
  objects for a better object-oriented purpose and flexibility in handling the
  result
- improved configure.zcml and added functional tests for the i18n translations
- improved test cases in general

0.1 (2008-05-20)
----------------

- initial release

Contributors
============

- Michael Howitz <mh at gocept dot com>

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/gocept/gocept.country",
    "name": "gocept.country",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "country subdivision language currency iso 3166 639 4217 15924 3166-2 zope pycountry",
    "author": "gocept gmbh & co. kg",
    "author_email": "mail@gocept.com",
    "download_url": "https://files.pythonhosted.org/packages/20/09/ed1e40c8dc6c37782d5675bba5481015856f77119dc0b53d07a5404a239c/gocept.country-3.0.tar.gz",
    "platform": null,
    "description": "Copyright (c) 2008-2015 gocept gmbh & co. kg\n\nAll Rights Reserved.\n\nThis software is subject to the provisions of the Zope Public License,\nVersion 2.1 (ZPL). A copy of the ZPL should accompany this distribution.\nTHIS SOFTWARE IS PROVIDED \"AS IS\" AND ANY AND ALL EXPRESS OR IMPLIED\nWARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS\nFOR A PARTICULAR PURPOSE.\n\n\n==============\ngocept.country\n==============\n\n.. image:: https://github.com/gocept/gocept.country/workflows/tests/badge.svg\n    :target: https://github.com/gocept/gocept.country/actions?query=workflow%3Atests\n.. image:: https://coveralls.io/repos/github/gocept/gocept.country/badge.svg?branch=master\n    :target: https://coveralls.io/github/gocept/gocept.country?branch=master\n\n\nThis package lets you use the `pycountry database\n<http://pypi.python.org/pypi/pycountry/>`_ within Zope 3.\n\n\nIn practice, this means e.g., that you can easily get a zope.schema.Choice\nfield to provide a full list of iso 3166 country codes.\n\nFor more information about the database please refer to the\n`pycountry product <http://pypi.python.org/pypi/pycountry/>`_.\n\n.. contents::\n\n\nIntroduction\n============\n\n`gocept.country` provides Zope 3 sources for the pycountry databases. You can\nuse it e.g. to get a ``zope.schema.Choice`` field with all ISO 3166 countries.\n\n  >>> import gocept.country\n  >>> import gocept.country.db\n  >>> import zope.schema\n\n\nISO 3166 Countries\n==================\n\nTo get a list of ISO 3166 countries in a web form, you can use the\n``zope.schema.Choice`` field and provide the gocept.country.countries as\nsource:\n\n  >>> countries_field = zope.schema.Choice(title=u'Country',\n  ...                            source=gocept.country.countries)\n  >>> countries_field\n  <zope.schema._field.Choice object at 0x...>\n  >>> countries = iter(countries_field.source)\n\n\nThe ``gocept.country.countries`` source factory returns Country objects as\nvalues, which use the values from pycountry:\n\n  >>> aruba = next(countries)\n  >>> afghanistan = next(countries)\n  >>> afghanistan\n  <gocept.country.db.Country object at 0x...>\n  >>> print(afghanistan.name)\n  Afghanistan\n\n\nCalling ``next()`` again returns the next country from the source:\n\n  >>> angola = next(countries)\n  >>> print(angola.name)\n  Angola\n\n\nThere are all information available, which you can get from pycountry:\n\n  >>> print(afghanistan.alpha_2)\n  AF\n  >>> print(afghanistan.alpha_3)\n  AFG\n  >>> print(afghanistan.numeric)\n  004\n  >>> print(afghanistan.official_name)\n  Islamic Republic of Afghanistan\n\n\nTo reduce the amount of results you can provide a list or tuple of countries\nyou like to have in your source:\n\n  >>> countries = gocept.country.CountrySource(alpha_2=['DE', 'US'])\n  >>> print(*[countries.factory.getTitle(x) for x in countries], sep=', ')\n  Germany, United States\n  >>> print(*[countries.factory.getToken(x) for x in countries], sep=', ')\n  DE, US\n\nPlease note, that the result items are sorted by *alpha_2* code. Please also\nnote, that you can provide alpha_3 and numeric codes and names resp.\nofficial_names to reduce the amount of result items, too:\n\n  >>> len(list(gocept.country.CountrySource())) > 200\n  True\n  >>> len(list(gocept.country.CountrySource(alpha_2=['DE', 'US', 'GB'])))\n  3\n  >>> len(list(gocept.country.CountrySource(alpha_3=['DEU', 'USA'])))\n  2\n  >>> len(list(gocept.country.CountrySource(numeric=['276', ])))\n  1\n  >>> countries_list = ['Germany', 'Italy', 'Poland', 'France']\n  >>> len(list(gocept.country.CountrySource(name=countries_list)))\n  4\n\n\nProviding codes, which are not present, does not result in an exception but\nin an empty list:\n\n  >>> len(list(gocept.country.CountrySource(capital=['Berlin', 'Paris'])))\n  0\n\nISO 3166-2 Country subdivisions\n===============================\n\nContext free source\n-------------------\n\nCountry subdivisions are similar to countries:\n\n  >>> subdivisions_field = zope.schema.Choice(\n  ...     title=u'Country subdivisions', source=gocept.country.subdivisions)\n  >>> subdivisions = iter(subdivisions_field.source)\n\n  >>> canillo = next(subdivisions)\n  >>> print(canillo.name)\n  Canillo\n  >>> print(canillo.code)\n  AD-02\n\n  >>> encamp = next(subdivisions)\n  >>> print(encamp.name)\n  Encamp\n  >>> print(encamp.code)\n  AD-03\n  >>> print(gocept.country.subdivisions.factory.getToken(encamp))\n  AD-03\n\nPlease note, that the result items are sorted by their *code*. Please\nalso note, that you can provide names and numeric codes to reduce the\namount of result items, too.\n\n  >>> len(list(gocept.country.SubdivisionSource())) > 4000\n  True\n  >>> len(list(gocept.country.SubdivisionSource(code=['DE-ST', 'US-WA'])))\n  2\n  >>> len(list(gocept.country.SubdivisionSource(country_code=['DE'])))\n  16\n  >>> print(*[x.name\n  ...         for x in gocept.country.SubdivisionSource(country_code=['DE'])][3:5],\n  ...       sep=', ')\n  Bayern, Bremen\n  >>> len(list(gocept.country.SubdivisionSource(name=[u'Bayern', u'Bremen'])))\n  2\n\nContextual source\n-----------------\n\nThere is also a contextual source for country subdivisions which\ndepends on a country. Let's set up a context object first:\n\n  >>> import zope.interface\n  >>> class IAddress(zope.interface.Interface):\n  ...     country = zope.interface.Attribute(\"The country of the address.\")\n  ...     subdivision = zope.schema.Choice(\n  ...         title=u'Country subdivisions',\n  ...         source=gocept.country.contextual_subdivisions)\n\n  >>> @zope.interface.implementer(IAddress)\n  ... class Address(object):\n  ...     pass\n  >>> address = Address()\n  >>> address.country = gocept.country.db.Country('DE')\n\nThe contextual source expects an adapter between the context and\n``gocept.country.interfaces.ICountry``:\n\n  >>> import zope.component\n  >>> import gocept.country.interfaces\n  >>> def get_country(context):\n  ...     return context.country\n  >>> zope.component.provideAdapter(\n  ...    get_country, (IAddress, ), gocept.country.interfaces.ICountry)\n\n  >>> print(gocept.country.interfaces.ICountry(address).name)\n  Germany\n\nSo the source contains only the country subdivisions belonging to the\ncountry:\n\n  >>> len(list(iter(gocept.country.contextual_subdivisions(address))))\n  16\n  >>> print(*[x.name\n  ...         for x in iter(gocept.country.contextual_subdivisions(address))][3:5],\n  ...       sep=', ')\n  Bayern, Bremen\n\nChanging the country changes also the subdivisions:\n\n  >>> address.country = gocept.country.db.Country('CH')\n  >>> len(list(iter(gocept.country.contextual_subdivisions(address))))\n  26\n  >>> print(*[x.name\n  ...         for x in iter(gocept.country.contextual_subdivisions(address))],\n  ...       sep=', ')\n  Aargau, Appenzell Innerrhoden, ...\n  >>> print(*[x.code\n  ...         for x in iter(gocept.country.contextual_subdivisions(address))],\n  ...       sep=', ')\n  CH-AG, CH-AI, ...\n  >>> print(*[gocept.country.contextual_subdivisions.factory.getToken(address, x)\n  ...         for x in iter(gocept.country.contextual_subdivisions(address))],\n  ...       sep=', ')\n  CH-AG, CH-AI, ...\n\n  >>> print(gocept.country.contextual_subdivisions.factory.getTitle(\n  ...     address, gocept.country.db.Subdivision('CH-AG')))\n  Aargau\n\nIf the country is not set there are no subdivisions:\n\n  >>> address.country = None\n  >>> len(list(iter(gocept.country.contextual_subdivisions(address))))\n  0\n  >>> list(iter(gocept.country.contextual_subdivisions(address)))\n  []\n\n\nISO 15924 Scripts\n=================\n\nScripts are similar to countries:\n\n  >>> scripts_field = zope.schema.Choice(title=u'Script',\n  ...                            source=gocept.country.scripts)\n  >>> scripts = iter(scripts_field.source)\n\n\n  >>> adlam = next(scripts)\n  >>> print(adlam.name)\n  Adlam\n\n  >>> afaka = next(scripts)\n  >>> print(afaka.name)\n  Afaka\n  >>> print(gocept.country.scripts.factory.getToken(afaka))\n  Afak\n\n\nPlease note, that the result items are sorted by *alpha_4* code. Please also\nnote, that you can provide names and numeric codes to smaller the amount of\nresult items, too.\n\n  >>> len(list(gocept.country.ScriptSource())) > 130\n  True\n  >>> len(list(gocept.country.ScriptSource(alpha_4=['Arab', 'Latn'])))\n  2\n  >>> len(list(gocept.country.ScriptSource(numeric=['215', ])))\n  1\n  >>> len(list(gocept.country.ScriptSource(name=['Arabic', 'Latin'])))\n  2\n\n\nISO 4217 Currencies\n===================\n\nCurrencies are similar to the ones before:\n\n  >>> currencies_field = zope.schema.Choice(title=u'Currency',\n  ...                            source=gocept.country.currencies)\n\n  >>> currencies = iter(currencies_field.source)\n\n  >>> dirham = next(currencies)\n  >>> print(dirham.name)\n  UAE Dirham\n\n  >>> afghani = next(currencies)\n  >>> print(afghani.name)\n  Afghani\n  >>> print(gocept.country.currencies.factory.getToken(afghani))\n  AFN\n\nPlease note, that the result items are sorted by *alpha_3* code. Please also\nnote, that you can provide names and numeric codes to reduce the amount of\nresult items, too.\n\n  >>> len(list(gocept.country.CurrencySource())) >= 170\n  True\n  >>> len(list(gocept.country.CurrencySource(alpha_3=['ARS', 'AED', 'AFN'])))\n  3\n  >>> len(list(gocept.country.CurrencySource(numeric=['032', '784'])))\n  2\n  >>> len(list(gocept.country.CurrencySource(name=['Afghani', ])))\n  1\n\n\nISO 639 Languages\n=================\n\nLanguages are similar, too:\n\n  >>> languages_field = zope.schema.Choice(title=u'Language',\n  ...                            source=gocept.country.languages)\n\n  >>> languages = iter(languages_field.source)\n\n  >>> ghotuo = next(languages)\n  >>> print(ghotuo.name)\n  Ghotuo\n\n  >>> alumu_tesu = next(languages)\n  >>> print(alumu_tesu.name)\n  Alumu-Tesu\n  >>> print(gocept.country.languages.factory.getToken(alumu_tesu))\n  aab\n\nPlease note, that the result items are sorted by *alpha_3*. Please also\nnote, that you can provide names to reduce the amount of result items, too.\n\n  >>> len(list(gocept.country.LanguageSource())) > 480\n  True\n  >>> len(list(gocept.country.LanguageSource(alpha_3=['eng', 'deu'])))\n  2\n  >>> len(list(gocept.country.LanguageSource(name=['English', 'German'])))\n  2\n\n\nTranslations\n============\n\n\nFirst we fetch a specific country:\n\n  >>> countries = list(iter(countries_field.source))\n  >>> germany = [x for x in countries if x.name == u'Germany'][0]\n\n\nThe i18n translate method translates 'Germany' into German:\n\n  >>> print(zope.i18n.translate(germany.name, target_language='de'))\n  Deutschland\n\n\nThere are also translations for scripts, currencies and languages.\n\n\nComparison\n==========\n\n\nCountries, scripts, currencies and languages can be compared to equality. To\ntest this, we will need another country object ``afghanistan``, which is not\nthe *same* object as retrieved before:\n\n\n  >>> afghanistan = next(iter(gocept.country.CountrySource(alpha_2=['AF'])))\n  >>> afghanistan2 = next(iter(gocept.country.CountrySource(alpha_2=['AF'])))\n\n  >>> str(afghanistan) == str(afghanistan2)\n  False\n\n\nComparing them will get the token for each and compare it:\n\n  >>> afghanistan == afghanistan2\n  True\n  >>> afghanistan != afghanistan2\n  False\n  >>> afghanistan != germany\n  True\n  >>> afghanistan == germany\n  False\n\n\nComparing with an instance of another class always returns False:\n\n  >>> afghanistan == None\n  False\n  >>> afghanistan != None\n  True\n  >>> afghanistan == object()\n  False\n  >>> afghanistan != object()\n  True\n\n\nPickling and unpickling\n=======================\n\n\nIt should be possible to store \"proxy objects\" in a database (like the ZODB).\nTherefore, they have to be pickleable:\n\n  >>> from io import BytesIO\n  >>> import pickle\n  >>> f = BytesIO(b'')\n\nPickling a country should never raise an error...\n\n  >>> pickle.dump(afghanistan, f)\n\n\n... and results in storing the token in the pickle:\n\n  >>> ignored = f.seek(0)\n  >>> b'AF' in f.read()\n  True\n\n\nReading the pickle again will return the same country which was pickled\nbefore:\n\n  >>> ignored = f.seek(0)\n  >>> afghanistan2 = pickle.load(f)\n  >>> afghanistan2 == afghanistan\n  True\n  >>> print(afghanistan2.name)\n  Afghanistan\n\n\nChanges\n=======\n\n3.0 (2023-07-14)\n----------------\n\n- Drop support for Python 2.7, 3.5, 3.6.\n\n- Add support for Python 3.9, 3.10, 3.11.\n\n\n2.1 (2019-09-30)\n----------------\n\n- Add support for Python 3.5 up to 3.8, PyPy and PyPy3.\n\n- Replace test dependency on `zope.app.testing` by `zope.app.wsgi[testlayer]`.\n\n- Migrate to Github.\n\n\n2.0 (2017-01-21)\n----------------\n\n- Update to ``pycountry >= 16.x``.\n\n- Drop support for Python 2.6.\n\n- Bring test coverage to 100 %.\n\n- Change testrunner to py.test.\n\n\n1.0 (2015-08-05)\n----------------\n\n- Update to ``pycountry 1.12`` thus adding support for ISO 639 3, dropping the\n  old ISO 639 support.\n\n\n0.6.5 (2015-08-05)\n------------------\n\n- Move repos to https://bitbucket.org/gocept/gocept.country\n\n0.6.4 (2008-10-21)\n------------------\n\n- Bugfix: declared namespace package in setup.py\n\n0.6.3 (2008-10-14)\n------------------\n\n- Bugfix: added not-equal compare method for db objects\n\n0.6.2 (2008-10-13)\n------------------\n\n- Added security declarations for token.\n- Bugfix in comparison of db objects, where `isinstance` returns False\n  for objects of the same type\n\n0.6.1 (2008-09-13)\n------------------\n\n- Bugfix in countextual subdivision source: parameters of some methods\n  where in wrong order.\n\n0.6 (2008-09-12)\n----------------\n\n- Added contextual country subdivision source, so country subdivisions\n  can depend on the country.\n\n\n0.5 (2008-09-11)\n----------------\n\n- Added support for country subdivisions.\n\n0.4.2 (2008-09-10)\n------------------\n\n- Added security declarations for tokens.\n\n0.4.1 (2008-09-10)\n------------------\n\n- Fixed bug in token comparison.\n\n0.4 (2008-06-10)\n----------------\n\n- added possibility to smaller the amount of results generated by the\n  sourcefactory\n\n\n0.3 (2008-05-21)\n----------------\n\n- added test for comparing the returned countries to equality\n- added __reduce__ to data objects so that they can be pickled\n- added tests for pickling and unpickling data objects\n\n\n0.2 (2008-05-20)\n----------------\n\n- gocept.country now returns special data objects instead of pycountry\n  objects for a better object-oriented purpose and flexibility in handling the\n  result\n- improved configure.zcml and added functional tests for the i18n translations\n- improved test cases in general\n\n0.1 (2008-05-20)\n----------------\n\n- initial release\n\nContributors\n============\n\n- Michael Howitz <mh at gocept dot com>\n",
    "bugtrack_url": null,
    "license": "ZPL 2.1",
    "summary": "Zope 3 sources for pycountry databases",
    "version": "3.0",
    "project_urls": {
        "Homepage": "https://github.com/gocept/gocept.country"
    },
    "split_keywords": [
        "country",
        "subdivision",
        "language",
        "currency",
        "iso",
        "3166",
        "639",
        "4217",
        "15924",
        "3166-2",
        "zope",
        "pycountry"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "61fed61a31fb39e59ac170d9deda2466c9523fb11e88500b3876b71abaeddf44",
                "md5": "6d32af16b2d8ce28428cd7f88e2459ca",
                "sha256": "4c4ea78da313ff6e926081285bd7d0dd5896ccf9edc5d60c147b21fcae251c71"
            },
            "downloads": -1,
            "filename": "gocept.country-3.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6d32af16b2d8ce28428cd7f88e2459ca",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=3.7",
            "size": 14388,
            "upload_time": "2023-07-14T12:46:39",
            "upload_time_iso_8601": "2023-07-14T12:46:39.833468Z",
            "url": "https://files.pythonhosted.org/packages/61/fe/d61a31fb39e59ac170d9deda2466c9523fb11e88500b3876b71abaeddf44/gocept.country-3.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2009ed1e40c8dc6c37782d5675bba5481015856f77119dc0b53d07a5404a239c",
                "md5": "4feb0d1196dcbc20af2b5ad3b31c441e",
                "sha256": "cc6e51a12ec4cad2b045d97571316e096099df24007b1654bd6f2514fc98fea7"
            },
            "downloads": -1,
            "filename": "gocept.country-3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "4feb0d1196dcbc20af2b5ad3b31c441e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 14235,
            "upload_time": "2023-07-14T12:46:41",
            "upload_time_iso_8601": "2023-07-14T12:46:41.554712Z",
            "url": "https://files.pythonhosted.org/packages/20/09/ed1e40c8dc6c37782d5675bba5481015856f77119dc0b53d07a5404a239c/gocept.country-3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-14 12:46:41",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "gocept",
    "github_project": "gocept.country",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "tox": true,
    "lcname": "gocept.country"
}
        
Elapsed time: 0.09113s