search_base = self.settings.get("ldap_search_base")
- try:
- results = self.ldap.search_ext_s(search_base, ldap.SCOPE_SUBTREE,
- query, attrlist=attrlist, sizelimit=limit)
- except:
- # Close current connection
- del self._ldap
-
- raise
+ try:
+ results = self.ldap.search_ext_s(search_base, ldap.SCOPE_SUBTREE,
+ query, attrlist=attrlist, sizelimit=limit)
+ except:
+ # Close current connection
+ del self._ldap
+
+ raise
return results
#!/usr/bin/python
# encoding: utf-8
-_ = lambda x: x.decode("utf-8")
+_ = lambda x: x
country_list = {
"AD" : _("Andorra"),
as torndb.
"""
-
-
import copy
import itertools
import logging
def _ensure_connected(self):
if self._db is None:
- logging.warning("Database connection was lost...")
+ logging.warning("Database connection was lost...")
self.reconnect()
self.close()
raise
- def transaction(self):
- return Transaction(self)
+ def transaction(self):
+ return Transaction(self)
class Row(dict):
class Transaction(object):
- def __init__(self, db):
- self.db = db
+ def __init__(self, db):
+ self.db = db
- self.db.execute("START TRANSACTION")
+ self.db.execute("START TRANSACTION")
- def __enter__(self):
- return self
+ def __enter__(self):
+ return self
- def __exit__(self, exctype, excvalue, traceback):
- if exctype is not None:
- self.db.execute("ROLLBACK")
- else:
- self.db.execute("COMMIT")
+ def __exit__(self, exctype, excvalue, traceback):
+ if exctype is not None:
+ self.db.execute("ROLLBACK")
+ else:
+ self.db.execute("COMMIT")
# Alias some common exceptions
def path(self):
return self._info.path
- @property
- def supports_https(self):
- return self._info.supports_https
+ @property
+ def supports_https(self):
+ return self._info.supports_https
@property
def address(self):
def torrent_hash(self):
return self.data.get("torrent_hash", None)
- @property
- def torrent_url(self):
- if self.torrent_hash:
- return "%s.torrent" % self.url
+ @property
+ def torrent_url(self):
+ if self.torrent_hash:
+ return "%s.torrent" % self.url
@property
def magnet_link(self):
s += "&dn=%s" % urllib.parse.quote(self.basename)
# Add our tracker.
- for tracker in TRACKERS:
- s += "&tr=%s" % tracker
+ for tracker in TRACKERS:
+ s += "&tr=%s" % tracker
- # Add web download URL
- s += "&as=%s" % urllib.parse.quote(self.url)
+ # Add web download URL
+ s += "&as=%s" % urllib.parse.quote(self.url)
return s
return self._process_cdr(res)
- def get_channels(self, account=None):
- channels = []
- for c in a.list_channels():
- if account and not account.sip_id in (c.caller, c.callee):
- continue
+ def get_channels(self, account=None):
+ channels = []
+ for c in a.list_channels():
+ if account and not account.sip_id in (c.caller, c.callee):
+ continue
- channels.append(c)
+ channels.append(c)
- return sorted(channels)
+ return sorted(channels)
- def get_channel(self, channel_id, account=None):
- channels = self.get_channels(account=account)
+ def get_channel(self, channel_id, account=None):
+ channels = self.get_channels(account=account)
- for channel in channels:
- if channel.id == channel_id:
- return channel
+ for channel in channels:
+ if channel.id == channel_id:
+ return channel
def get_ongoing_calls(self, account=None, sip_id=None):
if account and sip_id is None:
raise Exception("invalid bencoded value (data after valid prefix)")
return r
-from types import StringType, IntType, LongType, DictType, ListType, TupleType
-
-
-class Bencached(object):
-
- __slots__ = ['bencoded']
-
- def __init__(self, s):
- self.bencoded = s
-
def encode_bencached(x,r):
r.append(x.bencoded)
r.append('e')
encode_func = {}
-encode_func[Bencached] = encode_bencached
-encode_func[IntType] = encode_int
-encode_func[LongType] = encode_int
-encode_func[StringType] = encode_string
-encode_func[ListType] = encode_list
-encode_func[TupleType] = encode_list
-encode_func[DictType] = encode_dict
-
-try:
- from types import BooleanType
- encode_func[BooleanType] = encode_bool
-except ImportError:
- pass
+encode_func[int] = encode_int
+encode_func[str] = encode_string
+encode_func[list] = encode_list
+encode_func[tuple] = encode_list
+encode_func[dict] = encode_dict
+encode_func[bool] = encode_bool
def bencode(x):
r = []
else:
avatar = account.get_gravatar_url(size)
- if avatar.startswith("http://") or avatar.startswith("https://"):
- return self.redirect(avatar)
+ if avatar.startswith("http://") or avatar.startswith("https://"):
+ return self.redirect(avatar)
self.set_header("Cache-Control", "public,max-age=300")
self.set_header("Content-Disposition", "inline; filename=\"%s.jpg\"" % who)
import datetime
import dateutil.parser
import http.client
-import ipaddr
+import ipaddress
import logging
import time
import tornado.locale
for remote_ip in remote_ips:
try:
- addr = ipaddr.IPAddress(remote_ip)
+ addr = ipaddress.ip_address(remote_ip)
except ValueError:
# Skip invalid IP addresses.
continue
menu.gpxe
"""
def get(self):
- version = self.get_argument("version", None)
- if not version or version < LATEST_VERSION:
- return self.serve_update()
+ version = self.get_argument("version", None)
+ if not version or version < LATEST_VERSION:
+ return self.serve_update()
# Deliver content
self.set_header("Content-Type", "text/plain")
location = location.country
# Handle the profile.
- with self.db.transaction():
- try:
- self.fireinfo.handle_profile(public_id, profile_blob, location=location)
+ with self.db.transaction():
+ try:
+ self.fireinfo.handle_profile(public_id, profile_blob, location=location)
- except fireinfo.ProfileParserError:
- raise tornado.web.HTTPError(400)
+ except fireinfo.ProfileParserError:
+ raise tornado.web.HTTPError(400)
self.finish("Your profile was successfully saved to the database.")
class TalkDiagnosisHandler(BaseHandler):
@tornado.web.authenticated
def get(self):
- # Access only allowed for admins
- if not self.current_user.is_admin():
- raise tornado.web.HTTPError(403)
+ # Access only allowed for admins
+ if not self.current_user.is_admin():
+ raise tornado.web.HTTPError(403)
return self.render("talk/diagnosis.html")
class TalkHangupChannelHandler(BaseHandler):
- def _get_channel(self, channel_id):
- account = None if self.current_user.is_admin() else self.current_user
+ def _get_channel(self, channel_id):
+ account = None if self.current_user.is_admin() else self.current_user
- channel = self.talk.get_channel(channel_id, account=account)
- if not channel:
- raise tornado.web.HTTPError(404)
+ channel = self.talk.get_channel(channel_id, account=account)
+ if not channel:
+ raise tornado.web.HTTPError(404)
- return channel
+ return channel
- @tornado.web.authenticated
- def get(self, channel_id):
- channel = self._get_channel(channel_id)
+ @tornado.web.authenticated
+ def get(self, channel_id):
+ channel = self._get_channel(channel_id)
- self.render("talk/confirm-hangup.html", channel=channel)
+ self.render("talk/confirm-hangup.html", channel=channel)
- @tornado.web.authenticated
- def post(self, channel_id):
- channel = self._get_channel(channel_id)
+ @tornado.web.authenticated
+ def post(self, channel_id):
+ channel = self._get_channel(channel_id)
- # Hangup
- channel.hangup()
+ # Hangup
+ channel.hangup()
- self.redirect("/")
+ self.redirect("/")
class TalkConferencesHandler(BaseHandler):