Skip to content

Commit

Permalink
Rename variable.
Browse files Browse the repository at this point in the history
  • Loading branch information
gareth-palmer committed Jul 6, 2021
1 parent 32efd20 commit f9ee6fc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 30 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/usecallmanagernz/services/python%20lint/master?label=python%20lint)](https://github.com/usecallmanagernz/services/actions/workflows/pylint.yml) [![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/usecallmanagernz/services?color=blue&label=version&sort=semver)](https://github.com/usecallmanagernz/services/releases)

# XML Services

This repository contains example phone XML services as a WSGI application
Expand Down
40 changes: 20 additions & 20 deletions directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from urllib.parse import quote_plus
from html import escape

from lxml import etree
import requests
from lxml import etree
from flask import Blueprint, Response, request, g
import config

Expand All @@ -21,20 +21,20 @@

@blueprint.route('/directory')
def directory_index():
content = '<?xml version="1.0" encoding="UTF-8"?>' \
xml = '<?xml version="1.0" encoding="UTF-8"?>' \
'<CiscoIPPhoneMenu>' \
'<Title>Local Directory</Title>'

for index in ('1', '2ABC', '3DEF', '4GHI', '5JKL', '6MNO', '7PRQS', '8TUV', '9WXYZ', '0'):
content += '<MenuItem>' \
xml += '<MenuItem>' \
'<Name>' + escape(index) + '</Name>' \
'<URL>' + request.url_root + 'directory/entries?name=' + quote_plus(g.device_name) + '&amp;index=' + quote_plus(index) + '</URL>' \
'</MenuItem>'

if g.is_79xx:
content += '<Prompt>Your current options</Prompt>'
xml += '<Prompt>Your current options</Prompt>'

content += '<SoftKeyItem>' \
xml += '<SoftKeyItem>' \
'<Name>Exit</Name>' \
'<Position>' + ('3' if g.is_79xx else '1') + '</Position>' \
'<URL>Init:Directories</URL>' \
Expand All @@ -51,7 +51,7 @@ def directory_index():
'</SoftKeyItem>' \
'</CiscoIPPhoneMenu>'

return Response(content, mimetype = 'text/xml'), 200
return Response(xml, mimetype = 'text/xml'), 200


@blueprint.route('/directory/entries')
Expand Down Expand Up @@ -100,20 +100,20 @@ def directory_entries():
except ValueError:
page = 1

content = '<?xml version="1.0" encoding="UTF-8"?>' \
xml = '<?xml version="1.0" encoding="UTF-8"?>' \
'<CiscoIPPhoneDirectory>' \
'<Title>' + escape(index) + (' ' + str(page) + '/' + str(pages) if pages > 1 else '') + '</Title>'

for extension, name in entries[(page - 1) * 10:page * 10]:
content += '<DirectoryEntry>' \
xml += '<DirectoryEntry>' \
'<Name>' + escape(name) + '</Name>' \
'<Telephone>' + quote_plus(extension) + '</Telephone>' \
'</DirectoryEntry>'

if g.is_79xx:
content += '<Prompt>Select entry</Prompt>'
xml += '<Prompt>Select entry</Prompt>'

content += '<SoftKeyItem>' \
xml += '<SoftKeyItem>' \
'<Name>Exit</Name>' \
'<Position>' + ('3' if g.is_79xx else '1') + '</Position>' \
'<URL>' + request.url_root + 'directory?name=' + quote_plus(g.device_name) + '</URL>' \
Expand All @@ -125,56 +125,56 @@ def directory_entries():
'</SoftKeyItem>'

if page < pages:
content += '<SoftKeyItem>' \
xml += '<SoftKeyItem>' \
'<Name>Next</Name>' \
'<URL>' + request.url_root + 'directory/entries?name=' + quote_plus(g.device_name) + '&amp;index=' + quote_plus(index) + '&amp;page=' + str(page + 1) + '</URL>' \
'<Position>' + ('2' if g.is_79xx else '3') + '</Position>' \
'</SoftKeyItem>'

if page > 1:
content += '<SoftKeyItem>' \
xml += '<SoftKeyItem>' \
'<Name>Previous</Name>' \
'<URL>' + request.url_root + 'directory/entries?name=' + quote_plus(g.device_name) + '&amp;index=' + quote_plus(index) + '&amp;page=' + str(page - 1) + '</URL>' \
'<Position>' + ('4' if g.is_79xx else '4') + '</Position>' \
'</SoftKeyItem>'

content += '</CiscoIPPhoneDirectory>'
xml += '</CiscoIPPhoneDirectory>'

return Response(content, mimetype = 'text/xml'), 200
return Response(xml, mimetype = 'text/xml'), 200


@blueprint.route('/directory/help')
def directory_help():
content = '<?xml version="1.0" encoding="UTF-8"?>' \
xml = '<?xml version="1.0" encoding="UTF-8"?>' \
'<CiscoIPPhoneText>' \
'<Title>How To Use</Title>' \
'<Text>Use the keypad or navigation key to select the first letter of the person\'s name.</Text>'

if g.is_79xx:
content += '<Prompt>Your current options</Prompt>'
xml += '<Prompt>Your current options</Prompt>'

content += '<SoftKeyItem>' \
xml += '<SoftKeyItem>' \
'<Name>Back</Name>' \
'<URL>SoftKey:Exit</URL>' \
'<Position>' + ('3' if g.is_79xx else '1') + '</Position>' \
'</SoftKeyItem>' \
'</CiscoIPPhoneText>'

return Response(content, mimetype = 'text/xml'), 200
return Response(xml, mimetype = 'text/xml'), 200


@blueprint.route('/directory/79xx')
def directory_menuitem():
# 79xx series need a menu item before the index
content = '<?xml version="1.0" encoding="UTF-8"?>' \
xml = '<?xml version="1.0" encoding="UTF-8"?>' \
'<CiscoIPPhoneMenu>' \
'<MenuItem>' \
'<Name>Local Directory</Name>' \
'<URL>' + request.url_root + 'directory?name=' + quote_plus(g.device_name) + '</URL>' \
'</MenuItem>' \
'</CiscoIPPhoneMenu>'

return Response(content, mimetype = 'text/xml'), 200
return Response(xml, mimetype = 'text/xml'), 200


@blueprint.before_request
Expand Down
20 changes: 10 additions & 10 deletions services.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from urllib.parse import quote_plus
from html import escape

from lxml import etree
import requests
from lxml import etree
from flask import Blueprint, Response, request, g
import config

Expand All @@ -20,7 +20,7 @@

@blueprint.route('/services')
def services_menu():
content = '<?xml version="1.0" encoding="UTF-8"?>' \
xml = '<?xml version="1.0" encoding="UTF-8"?>' \
'<CiscoIPPhoneMenu>' \
'<Title>Services</Title>' \
'<MenuItem>' \
Expand All @@ -29,9 +29,9 @@ def services_menu():
'</MenuItem>'

if g.is_79xx:
content += '<Prompt>Your current options</Prompt>'
xml += '<Prompt>Your current options</Prompt>'

content += '<SoftKeyItem>' \
xml += '<SoftKeyItem>' \
'<Name>Exit</Name>' \
'<Position>' + ('3' if g.is_79xx else '1') + '</Position>' \
'<URL>Init:Services</URL>' \
Expand All @@ -43,7 +43,7 @@ def services_menu():
'</SoftKeyItem>' \
'</CiscoIPPhoneMenu>'

return Response(content, mimetype = 'text/xml'), 200
return Response(xml, mimetype = 'text/xml'), 200


@blueprint.route('/services/parked-calls')
Expand Down Expand Up @@ -72,20 +72,20 @@ def parked_calls():
response = session.get(config.manager_url, timeout = 5, params = {'Action': 'Logoff'})
response.raise_for_status()

content = '<?xml version="1.0" encoding="UTF-8"?>' \
xml = '<?xml version="1.0" encoding="UTF-8"?>' \
'<CiscoIPPhoneDirectory>' \
'<Title>Parked Calls</Title>'

for extension, name in calls:
content += '<DirectoryEntry>' \
xml += '<DirectoryEntry>' \
'<Name>' + escape(name) + '</Name>' \
'<Telephone>' + quote_plus(extension) + '</Telephone>' \
'</DirectoryEntry>'

if g.is_79xx:
content += '<Prompt>Select call</Prompt>'
xml += '<Prompt>Select call</Prompt>'

content += '<SoftKeyItem>' \
xml += '<SoftKeyItem>' \
'<Name>Exit</Name>' \
'<Position>' + ('3' if g.is_79xx else '1') + '</Position>' \
'<URL>' + request.url_root + 'services?name=' + quote_plus(g.device_name) + '</URL>' \
Expand All @@ -102,7 +102,7 @@ def parked_calls():
'</SoftKeyItem>' \
'</CiscoIPPhoneDirectory>'

return Response(content, mimetype = 'text/xml'), 200
return Response(xml, mimetype = 'text/xml'), 200


@blueprint.before_request
Expand Down

0 comments on commit f9ee6fc

Please sign in to comment.