1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
# Upgrading to PyGopherd v3.0
Notes for updating an existing PyGopherd server deployment to run on python 3.
## Server Version
Install PyGopherd v3.0+ from [michael-lazar/pygopherd](https://github.com/michael-lazar/pygopherd)
or another dependable source.
## Cached Files
PyGopherd will create cache files that start with ``.cache.pygopherd.*`` in
your gopher root directory. These files are used to index directories and zip
files for faster loading. Before launching the new server, clear out any
existing PyGopherd cache files from your system.
```
find /var/gopher -type f -name '.cache.pygopherd.*' -delete
```
## /etc/pygopherd/pygopherd.conf
Because the PyGopherd config file format uses evaluated python code, you will
need to make sure your config file is python 3 compatible.
There is one known spot where the default config file needed to be updated.
```
encoding = mimetypes.encodings_map.items() + \
{'.bz2' : 'bzip2',
'.tal': 'tal.TALFileHandler'
}.items()
```
must be changed to
```
encoding = list(mimetypes.encodings_map.items()) + \
list({'.bz2' : 'bzip2',
'.tal': 'tal.TALFileHandler'
}.items())
```
## PYG files
PyGopherd supports ``*.pyg`` files which use a special file handler to execute
python code directly. If you have written any custom PYG files for your server,
you will need to make sure that they are compatible with python 3.
The internal API has not changed, but some methods now expect bytes instead of
strings. An example PYG file is shown [here](testdata/testfile.pyg).
#### Before
```
def write(self, wfile):
wfile.write(self.definition)
```
#### After
```
def write(self, wfile):
wfile.write(self.definition.encode())
```
## Other Handlers
Some handler classes required major refactoring to support python 3. Notably
the ``mbox`` and ``ZIP`` handlers were significantly changed. Effort was made
to preserve the old behavior as closely as possible.
If you're using any of these handlers on your server, test them out and report
back with any issues!
|