python3 only: remove six.moves imports

This commit is contained in:
j 2020-05-29 12:17:18 +02:00
parent 844382b1e8
commit 548a73f121
33 changed files with 75 additions and 121 deletions

View file

@ -1,7 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import unicodedata import unicodedata
from six import string_types
from django.db.models import Q, Manager from django.db.models import Q, Manager
from oxdjango.query import QuerySet from oxdjango.query import QuerySet
@ -68,7 +67,7 @@ def parseCondition(condition, user):
else: else:
key = k + get_operator(op, 'istr' if k in case_insensitive_keys else 'str') key = k + get_operator(op, 'istr' if k in case_insensitive_keys else 'str')
key = str(key) key = str(key)
if isinstance(v, string_types): if isinstance(v, str):
v = unicodedata.normalize('NFKD', v) v = unicodedata.normalize('NFKD', v)
if k not in case_sensitive_keys: if k not in case_sensitive_keys:
v = v.lower() v = v.lower()

View file

@ -9,8 +9,8 @@ import sys
import time import time
from os.path import dirname, exists, join from os.path import dirname, exists, join
from glob import glob from glob import glob
import _thread as thread
from six.moves import _thread as thread
from django.conf import settings from django.conf import settings
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model

View file

@ -3,7 +3,6 @@
import copy import copy
from datetime import datetime from datetime import datetime
from six import string_types
from django.shortcuts import render, redirect from django.shortcuts import render, redirect
from django.conf import settings from django.conf import settings
from django.http import HttpResponse from django.http import HttpResponse
@ -113,7 +112,7 @@ def getPage(request, data):
} }
see: editPage see: editPage
''' '''
if isinstance(data, string_types): if isinstance(data, str):
name = data name = data
else: else:
name = data['name'] name = data['name']

View file

@ -12,7 +12,6 @@ import shutil
from distutils.spawn import find_executable from distutils.spawn import find_executable
from glob import glob from glob import glob
from six import string_types
import numpy as np import numpy as np
import ox import ox
import ox.image import ox.image
@ -463,7 +462,7 @@ def timeline(video, prefix, modes=None, size=None):
modes = ['antialias', 'slitscan', 'keyframes', 'audio', 'data'] modes = ['antialias', 'slitscan', 'keyframes', 'audio', 'data']
if size is None: if size is None:
size = [64, 16] size = [64, 16]
if isinstance(video, string_types): if isinstance(video, str):
video = [video] video = [video]
cmd = ['../bin/oxtimelines', cmd = ['../bin/oxtimelines',
'-s', ','.join(map(str, reversed(sorted(size)))), '-s', ','.join(map(str, reversed(sorted(size)))),

View file

@ -6,7 +6,6 @@ import shutil
import tempfile import tempfile
import time import time
from six import string_types, PY2
from django.conf import settings from django.conf import settings
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.db import models from django.db import models
@ -28,9 +27,6 @@ from . import managers
User = get_user_model() User = get_user_model()
if not PY2:
unicode = str
def data_path(f, x): def data_path(f, x):
return f.get_path('data.bin') return f.get_path('data.bin')
@ -165,7 +161,7 @@ class File(models.Model):
if self.item: if self.item:
for key in self.ITEM_INFO: for key in self.ITEM_INFO:
data[key] = self.item.get(key) data[key] = self.item.get(key)
if isinstance(data[key], string_types): if isinstance(data[key], str):
data[key] = ox.decode_html(data[key]) data[key] = ox.decode_html(data[key])
elif isinstance(data[key], list): elif isinstance(data[key], list):
data[key] = [ox.decode_html(e) for e in data[key]] data[key] = [ox.decode_html(e) for e in data[key]]
@ -259,8 +255,8 @@ class File(models.Model):
data = self.get_path_info() data = self.get_path_info()
self.extension = data.get('extension') self.extension = data.get('extension')
self.language = data.get('language') self.language = data.get('language')
self.part = ox.sort_string(unicode(data.get('part') or '')) self.part = ox.sort_string(str(data.get('part') or ''))
self.part_title = ox.sort_string(unicode(data.get('partTitle')) or '') self.part_title = ox.sort_string(str(data.get('partTitle')) or '')
self.type = data.get('type') or 'unknown' self.type = data.get('type') or 'unknown'
self.version = data.get('version') self.version = data.get('version')

View file

@ -2,7 +2,6 @@
from glob import glob from glob import glob
from six import string_types
from celery.task import task from celery.task import task
from django.conf import settings from django.conf import settings
from django.db.models import Q from django.db.models import Q
@ -219,7 +218,7 @@ def move_media(data, user):
data['public_id'] = data.pop('item').strip() data['public_id'] = data.pop('item').strip()
if not is_imdb_id(data['public_id']): if not is_imdb_id(data['public_id']):
del data['public_id'] del data['public_id']
if 'director' in data and isinstance(data['director'], string_types): if 'director' in data and isinstance(data['director'], str):
if data['director'] == '': if data['director'] == '':
data['director'] = [] data['director'] = []
else: else:

View file

@ -7,7 +7,6 @@ from django.shortcuts import get_object_or_404, redirect, render
from django.conf import settings from django.conf import settings
from django.db.models import Count, Q from django.db.models import Count, Q
from six import string_types
from celery.utils import get_full_cls_name from celery.utils import get_full_cls_name
from celery._state import current_app from celery._state import current_app
import ox import ox
@ -555,7 +554,7 @@ def getPath(request, data):
''' '''
response = json_response() response = json_response()
ids = data['id'] ids = data['id']
if isinstance(ids, string_types): if isinstance(ids, str):
ids = [ids] ids = [ids]
for f in models.File.objects.filter(oshash__in=ids).values('path', 'oshash').order_by('sort_path'): for f in models.File.objects.filter(oshash__in=ids).values('path', 'oshash').order_by('sort_path'):
response['data'][f['oshash']] = f['path'] response['data'][f['oshash']] = f['path']

View file

@ -1,7 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import unicodedata import unicodedata
from six import string_types
from django.db.models import Q, Manager from django.db.models import Q, Manager
from django.conf import settings from django.conf import settings
@ -78,7 +77,7 @@ def parseCondition(condition, user):
else: else:
key = k + get_operator(op, 'istr' if k in case_insensitive_keys else 'str') key = k + get_operator(op, 'istr' if k in case_insensitive_keys else 'str')
key = str(key) key = str(key)
if isinstance(v, string_types) and op != '===': if isinstance(v, str) and op != '===':
v = unicodedata.normalize('NFKD', v).lower() v = unicodedata.normalize('NFKD', v).lower()
if exclude: if exclude:
q = ~Q(**{key: v}) q = ~Q(**{key: v})
@ -155,7 +154,7 @@ class ClipManager(Manager):
def parse(condition): def parse(condition):
key = 'findvalue' + get_operator(condition.get('operator', '')) key = 'findvalue' + get_operator(condition.get('operator', ''))
v = condition['value'] v = condition['value']
if isinstance(v, string_types): if isinstance(v, str):
v = unicodedata.normalize('NFKD', v).lower() v = unicodedata.normalize('NFKD', v).lower()
q = Q(**{key: v}) q = Q(**{key: v})
if condition['key'] in layer_ids: if condition['key'] in layer_ids:

View file

@ -1,7 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import unicodedata import unicodedata
from six import string_types
from django.db.models import Q, Manager from django.db.models import Q, Manager
from django.conf import settings from django.conf import settings
@ -152,7 +151,7 @@ def buildCondition(k, op, v, user, exclude=False, owner=None):
value_key = 'find__value' value_key = 'find__value'
else: else:
value_key = k value_key = k
if isinstance(v, string_types): if isinstance(v, str):
v = unicodedata.normalize('NFKD', v).lower() v = unicodedata.normalize('NFKD', v).lower()
if k in facet_keys: if k in facet_keys:
in_find = False in_find = False

View file

@ -1,12 +1,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from glob import glob
from urllib.parse import quote, unquote
import os import os
import re import re
from glob import glob
import unicodedata import unicodedata
from six import PY2, string_types
from six.moves.urllib.parse import quote, unquote
from django.db import models, transaction from django.db import models, transaction
from django.db.models import Q, Sum, Max from django.db.models import Q, Sum, Max
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
@ -34,9 +33,6 @@ from .fulltext import FulltextMixin
User = get_user_model() User = get_user_model()
if not PY2:
unicode = str
def get_path(f, x): def get_path(f, x):
return f.path(x) return f.path(x)
@ -88,7 +84,7 @@ class Document(models.Model, FulltextMixin):
if not current_values: if not current_values:
current_values = [] current_values = []
else: else:
current_values = [unicode(current_values)] current_values = [str(current_values)]
filter_map = utils.get_by_id(settings.CONFIG['documentKeys'], key).get('filterMap') filter_map = utils.get_by_id(settings.CONFIG['documentKeys'], key).get('filterMap')
if filter_map: if filter_map:
@ -139,7 +135,7 @@ class Document(models.Model, FulltextMixin):
f, created = Find.objects.get_or_create(document=self, key=key) f, created = Find.objects.get_or_create(document=self, key=key)
if isinstance(value, bool): if isinstance(value, bool):
value = value and 'true' or 'false' value = value and 'true' or 'false'
if isinstance(value, string_types): if isinstance(value, str):
value = ox.decode_html(ox.strip_tags(value.strip())) value = ox.decode_html(ox.strip_tags(value.strip()))
value = unicodedata.normalize('NFKD', value).lower() value = unicodedata.normalize('NFKD', value).lower()
f.value = value f.value = value
@ -197,7 +193,7 @@ class Document(models.Model, FulltextMixin):
return sort_value.lower() return sort_value.lower()
def set_value(s, name, value): def set_value(s, name, value):
if isinstance(value, string_types): if isinstance(value, str):
value = ox.decode_html(value.lower()) value = ox.decode_html(value.lower())
if not value: if not value:
value = None value = None
@ -259,7 +255,7 @@ class Document(models.Model, FulltextMixin):
set_value(s, name, value) set_value(s, name, value)
elif sort_type == 'date': elif sort_type == 'date':
value = self.get_value(source) value = self.get_value(source)
if isinstance(value, string_types): if isinstance(value, str):
value = datetime_safe.datetime.strptime(value, '%Y-%m-%d') value = datetime_safe.datetime.strptime(value, '%Y-%m-%d')
set_value(s, name, value) set_value(s, name, value)
s.save() s.save()
@ -370,11 +366,11 @@ class Document(models.Model, FulltextMixin):
self.data[key] = [ox.sanitize_html(t) for t in data[key]] self.data[key] = [ox.sanitize_html(t) for t in data[key]]
elif ktype == '[string]': elif ktype == '[string]':
self.data[key] = [ox.escape_html(t) for t in data[key]] self.data[key] = [ox.escape_html(t) for t in data[key]]
elif isinstance(data[key], string_types): elif isinstance(data[key], str):
self.data[key] = ox.escape_html(data[key]) self.data[key] = ox.escape_html(data[key])
elif isinstance(data[key], list): elif isinstance(data[key], list):
def cleanup(i): def cleanup(i):
if isinstance(i, string_types): if isinstance(i, str):
i = ox.escape_html(i) i = ox.escape_html(i)
return i return i
self.data[key] = [cleanup(i) for i in data[key]] self.data[key] = [cleanup(i) for i in data[key]]
@ -480,7 +476,7 @@ class Document(models.Model, FulltextMixin):
if self.extension == 'html': if self.extension == 'html':
response['text'] = self.data.get('text', '') response['text'] = self.data.get('text', '')
if item: if item:
if isinstance(item, string_types): if isinstance(item, str):
item = Item.objects.get(public_id=item) item = Item.objects.get(public_id=item)
d = self.descriptions.filter(item=item) d = self.descriptions.filter(item=item)
if d.exists(): if d.exists():

View file

@ -5,7 +5,6 @@ import re
from glob import glob from glob import glob
import unicodedata import unicodedata
from six import string_types
import ox import ox
from ox.utils import json from ox.utils import json
from oxdjango.api import actions from oxdjango.api import actions
@ -70,7 +69,7 @@ def addDocument(request, data):
else: else:
ids = [data['id']] ids = [data['id']]
if 'item' in data: if 'item' in data:
if isinstance(data['item'], string_types): if isinstance(data['item'], str):
item = Item.objects.get(public_id=data['item']) item = Item.objects.get(public_id=data['item'])
if item.editable(request.user): if item.editable(request.user):
for id in ids: for id in ids:
@ -87,7 +86,7 @@ def addDocument(request, data):
document.add(item) document.add(item)
add_changelog(request, data, data['item']) add_changelog(request, data, data['item'])
elif 'entity' in data: elif 'entity' in data:
if isinstance(data['entity'], string_types): if isinstance(data['entity'], str):
entity = Entity.get(data['entity']) entity = Entity.get(data['entity'])
if entity.editable(request.user): if entity.editable(request.user):
for id in ids: for id in ids:

View file

@ -1,13 +1,13 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import re
import os
import shutil
from glob import glob from glob import glob
from urllib.parse import quote
import os
import re
import shutil
import subprocess import subprocess
import tempfile import tempfile
from six.moves.urllib.parse import quote
import ox import ox
from django.conf import settings from django.conf import settings
from django.db import models, transaction from django.db import models, transaction

View file

@ -1,12 +1,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from glob import glob
from urllib.parse import quote, unquote
import os import os
import re import re
from glob import glob
import unicodedata import unicodedata
from six import string_types
from six.moves.urllib.parse import quote, unquote
from django.db import models, transaction from django.db import models, transaction
from django.db.models import Max from django.db.models import Max
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
@ -188,7 +187,7 @@ class Entity(models.Model):
.delete() .delete()
else: else:
#FIXME: more data validation #FIXME: more data validation
if isinstance(data[key], string_types): if isinstance(data[key], str):
self.data[key] = ox.sanitize_html(data[key]) self.data[key] = ox.sanitize_html(data[key])
else: else:
self.data[key] = data[key] self.data[key] = data[key]
@ -275,7 +274,7 @@ class Entity(models.Model):
f, created = Find.objects.get_or_create(entity=self, key=key) f, created = Find.objects.get_or_create(entity=self, key=key)
if isinstance(value, bool): if isinstance(value, bool):
value = value and 'true' or 'false' value = value and 'true' or 'false'
if isinstance(value, string_types): if isinstance(value, str):
value = ox.decode_html(ox.strip_tags(value.strip())) value = ox.decode_html(ox.strip_tags(value.strip()))
value = unicodedata.normalize('NFKD', value).lower() value = unicodedata.normalize('NFKD', value).lower()
f.value = value f.value = value

View file

@ -1,6 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from six import string_types
import ox import ox
from ox.utils import json from ox.utils import json
from oxdjango.api import actions from oxdjango.api import actions
@ -69,7 +68,7 @@ def addEntity(request, data):
for key in ('type', 'alternativeNames'): for key in ('type', 'alternativeNames'):
if key in data and data[key]: if key in data and data[key]:
value = data[key] value = data[key]
if isinstance(value, string_types): if isinstance(value, str):
value = ox.escape_html(value) value = ox.escape_html(value)
if key == 'alternativeNames': if key == 'alternativeNames':
value = tuple([ox.escape_html(v) for v in value]) value = tuple([ox.escape_html(v) for v in value])

View file

@ -1,7 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import unicodedata import unicodedata
from six import string_types
from django.db.models import Q, Manager from django.db.models import Q, Manager
from oxdjango.query import QuerySet from oxdjango.query import QuerySet
@ -30,7 +29,7 @@ def parseCondition(condition, user):
key = k + get_operator(op, 'istr') key = k + get_operator(op, 'istr')
key = str(key) key = str(key)
if isinstance(v, string_types): if isinstance(v, str):
v = unicodedata.normalize('NFKD', v).lower() v = unicodedata.normalize('NFKD', v).lower()
if exclude: if exclude:
q = ~Q(**{k: v}) q = ~Q(**{k: v})

View file

@ -3,7 +3,6 @@
from django.db.models import Count from django.db.models import Count
from django.conf import settings from django.conf import settings
from six import string_types
import ox import ox
from ox.utils import json from ox.utils import json
@ -47,7 +46,7 @@ def addEvent(request, data):
'type', 'alternativeNames'): 'type', 'alternativeNames'):
if key in data and data[key]: if key in data and data[key]:
value = data[key] value = data[key]
if isinstance(value, string_types): if isinstance(value, str):
value = ox.escape_html(value) value = ox.escape_html(value)
if key == 'alternativeNames': if key == 'alternativeNames':
value = tuple([ox.escape_html(v) for v in value]) value = tuple([ox.escape_html(v) for v in value])
@ -101,7 +100,7 @@ def editEvent(request, data):
'type', 'alternativeNames'): 'type', 'alternativeNames'):
if key in data: if key in data:
value = data[key] value = data[key]
if isinstance(value, string_types): if isinstance(value, str):
value = ox.escape_html(value) value = ox.escape_html(value)
if key == 'alternativeNames': if key == 'alternativeNames':
value = tuple([ox.escape_html(v) for v in value]) value = tuple([ox.escape_html(v) for v in value])

View file

@ -1,7 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from six import string_types from urllib.parse import quote
from six.moves.urllib.parse import quote
from django.db import models from django.db import models
from django.db.models import Max from django.db.models import Max
@ -43,7 +42,7 @@ class Item(models.Model):
len([d for d in data[key] if isinstance(d, int)]) == 4): len([d for d in data[key] if isinstance(d, int)]) == 4):
return False return False
else: else:
if not isinstance(data[key], string_types): if not isinstance(data[key], str):
return False return False
self.data[key] = data[key] self.data[key] = data[key]
if key == 'contentid' and self.data[key]: if key == 'contentid' and self.data[key]:

View file

@ -3,7 +3,6 @@
from datetime import datetime from datetime import datetime
import unicodedata import unicodedata
from six import string_types
from django.db.models import Q, Manager from django.db.models import Q, Manager
from django.conf import settings from django.conf import settings
@ -123,7 +122,7 @@ def parseCondition(condition, user, owner=None):
else: else:
value_key = k value_key = k
if not k.startswith('public_id'): if not k.startswith('public_id'):
if isinstance(v, string_types): if isinstance(v, str):
v = unicodedata.normalize('NFKD', v).lower() v = unicodedata.normalize('NFKD', v).lower()
if k in facet_keys: if k in facet_keys:
in_find = False in_find = False

View file

@ -10,9 +10,7 @@ import unicodedata
import uuid import uuid
from datetime import datetime from datetime import datetime
from glob import glob from glob import glob
from urllib.parse import quote
from six import PY2, string_types
from six.moves.urllib.parse import quote
from django.conf import settings from django.conf import settings
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
@ -46,8 +44,6 @@ import archive.models
User = get_user_model() User = get_user_model()
if not PY2:
unicode = str
def get_id(info): def get_id(info):
q = Item.objects.all() q = Item.objects.all()
@ -284,11 +280,11 @@ class Item(models.Model):
self.data[key] = [ox.escape_html(t) for t in data[key]] self.data[key] = [ox.escape_html(t) for t in data[key]]
elif key in ('episodeTitle', 'seriesTitle', 'episodeDirector', 'seriesYear'): elif key in ('episodeTitle', 'seriesTitle', 'episodeDirector', 'seriesYear'):
self.data[key] = ox.escape_html(data[key]) self.data[key] = ox.escape_html(data[key])
elif isinstance(data[key], string_types): elif isinstance(data[key], str):
self.data[key] = ox.escape_html(data[key]) self.data[key] = ox.escape_html(data[key])
elif isinstance(data[key], list): elif isinstance(data[key], list):
def cleanup(i): def cleanup(i):
if isinstance(i, string_types): if isinstance(i, str):
i = ox.escape_html(i) i = ox.escape_html(i)
return i return i
self.data[key] = [cleanup(i) for i in data[key]] self.data[key] = [cleanup(i) for i in data[key]]
@ -329,7 +325,7 @@ class Item(models.Model):
if c: if c:
for t in list(c): for t in list(c):
if c[t]: if c[t]:
if isinstance(c[t][0], string_types): if isinstance(c[t][0], str):
c[t] = [{'id': i, 'title': None} for i in c[t]] c[t] = [{'id': i, 'title': None} for i in c[t]]
ids = [i['id'] for i in c[t]] ids = [i['id'] for i in c[t]]
known = {} known = {}
@ -626,7 +622,7 @@ class Item(models.Model):
if value: if value:
i[key] = value i[key] = value
if 'cast' in i and isinstance(i['cast'][0], string_types): if 'cast' in i and isinstance(i['cast'][0], str):
i['cast'] = [i['cast']] i['cast'] = [i['cast']]
if 'cast' in i and isinstance(i['cast'][0], list): if 'cast' in i and isinstance(i['cast'][0], list):
i['cast'] = [{'actor': x[0], 'character': x[1]} for x in i['cast']] i['cast'] = [{'actor': x[0], 'character': x[1]} for x in i['cast']]
@ -797,7 +793,7 @@ class Item(models.Model):
f, created = ItemFind.objects.get_or_create(item=self, key=key) f, created = ItemFind.objects.get_or_create(item=self, key=key)
if isinstance(value, bool): if isinstance(value, bool):
value = value and 'true' or 'false' value = value and 'true' or 'false'
if isinstance(value, string_types): if isinstance(value, str):
value = ox.decode_html(ox.strip_tags(value.strip())) value = ox.decode_html(ox.strip_tags(value.strip()))
value = unicodedata.normalize('NFKD', value).lower() value = unicodedata.normalize('NFKD', value).lower()
f.value = value f.value = value
@ -916,7 +912,7 @@ class Item(models.Model):
return sort_value.lower() return sort_value.lower()
def set_value(s, name, value): def set_value(s, name, value):
if isinstance(value, string_types): if isinstance(value, str):
value = ox.decode_html(value.lower()) value = ox.decode_html(value.lower())
if not value: if not value:
value = None value = None
@ -1052,7 +1048,7 @@ class Item(models.Model):
set_value(s, name, value) set_value(s, name, value)
elif sort_type == 'date': elif sort_type == 'date':
value = value_ = self.get(source) value = value_ = self.get(source)
if isinstance(value, string_types): if isinstance(value, str):
value_ = None value_ = None
for fmt in ('%Y-%m-%d', '%Y-%m', '%Y'): for fmt in ('%Y-%m-%d', '%Y-%m', '%Y'):
try: try:
@ -1091,7 +1087,7 @@ class Item(models.Model):
if not current_values: if not current_values:
current_values = [] current_values = []
else: else:
current_values = [unicode(current_values)] current_values = [str(current_values)]
filter_map = utils.get_by_id(settings.CONFIG['itemKeys'], key).get('filterMap') filter_map = utils.get_by_id(settings.CONFIG['itemKeys'], key).get('filterMap')
if filter_map: if filter_map:

View file

@ -1,11 +1,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import os
from datetime import timedelta, datetime from datetime import timedelta, datetime
from urllib.parse import quote
import gzip import gzip
import os
import random import random
from six.moves.urllib.parse import quote
from celery.task import task, periodic_task from celery.task import task, periodic_task
from django.conf import settings from django.conf import settings
from django.db import connection, transaction from django.db import connection, transaction

View file

@ -6,7 +6,6 @@ import unicodedata
import ox import ox
from ox import sort_string from ox import sort_string
from six import PY2
def safe_filename(filename): def safe_filename(filename):
@ -92,11 +91,7 @@ def get_by_id(objects, id):
return get_by_key(objects, 'id', id) return get_by_key(objects, 'id', id)
def normalize_dict(encoding, data): def normalize_dict(encoding, data):
if PY2: if isinstance(data, str):
string_type = unicode
else:
string_type = str
if isinstance(data, string_type):
data = unicodedata.normalize(encoding, data) data = unicodedata.normalize(encoding, data)
elif isinstance(data, dict): elif isinstance(data, dict):
for key in data: for key in data:

View file

@ -1,13 +1,12 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import os.path from datetime import datetime, timedelta
from urllib.parse import quote, urlparse
import mimetypes import mimetypes
import os.path
import random import random
import time import time
from datetime import datetime, timedelta
from six import PY2
from six.moves.urllib.parse import quote, urlparse
from PIL import Image from PIL import Image
from django.db.models import Count, Sum from django.db.models import Count, Sum
from django.http import HttpResponse, HttpResponseForbidden, Http404 from django.http import HttpResponse, HttpResponseForbidden, Http404
@ -35,8 +34,6 @@ from changelog.models import add_changelog
from oxdjango.api import actions from oxdjango.api import actions
if not PY2:
unicode = str
def _order_query(qs, sort, prefix='sort__'): def _order_query(qs, sort, prefix='sort__'):
order_by = [] order_by = []
@ -1280,7 +1277,7 @@ def atom_xml(request):
}.get(key, key)) }.get(key, key))
if value and value != -1: if value and value != -1:
el = ET.SubElement(format, key) el = ET.SubElement(format, key)
el.text = unicode(value) el.text = str(value)
el = ET.SubElement(format, 'pixel_aspect_ratio') el = ET.SubElement(format, 'pixel_aspect_ratio')
el.text = "1:1" el.text = "1:1"
@ -1357,7 +1354,7 @@ def oembed(request):
oxml = ET.Element('oembed') oxml = ET.Element('oembed')
for key in oembed: for key in oembed:
e = ET.SubElement(oxml, key) e = ET.SubElement(oxml, key)
e.text = unicode(oembed[key]) e.text = str(oembed[key])
return HttpResponse( return HttpResponse(
'<?xml version="1.0" encoding="utf-8" standalone="yes"?>\n' + ET.tostring(oxml).decode(), '<?xml version="1.0" encoding="utf-8" standalone="yes"?>\n' + ET.tostring(oxml).decode(),
'application/xml' 'application/xml'
@ -1423,7 +1420,7 @@ def item_xml(request, id):
xmltree(root, k, data[k]) xmltree(root, k, data[k])
else: else:
e = ET.SubElement(root, key) e = ET.SubElement(root, key)
e.text = unicode(data) e.text = str(data)
oxml = ET.Element('item') oxml = ET.Element('item')
xmltree(oxml, 'item', j) xmltree(oxml, 'item', j)
@ -1483,7 +1480,7 @@ def item(request, id):
else: else:
title = key['title'] if key else k.capitalize() title = key['title'] if key else k.capitalize()
if isinstance(value, list): if isinstance(value, list):
value = value = ', '.join([unicode(v) for v in value]) value = value = ', '.join([str(v) for v in value])
elif key and key.get('type') == 'float': elif key and key.get('type') == 'float':
value = '%0.3f' % value value = '%0.3f' % value
elif key and key.get('type') == 'time': elif key and key.get('type') == 'time':

View file

@ -4,7 +4,6 @@ from __future__ import division, absolute_import
import inspect import inspect
import sys import sys
from six import PY2
from django.conf import settings from django.conf import settings
from ..shortcuts import render_to_json_response, json_response from ..shortcuts import render_to_json_response, json_response
@ -109,10 +108,6 @@ class ApiActions(dict):
if name != 'api' and hasattr(f, 'func_closure') and f.func_closure: if name != 'api' and hasattr(f, 'func_closure') and f.func_closure:
fc = list(filter(lambda c: hasattr(c.cell_contents, '__call__'), f.func_closure)) fc = list(filter(lambda c: hasattr(c.cell_contents, '__call__'), f.func_closure))
f = fc[len(fc)-1].cell_contents f = fc[len(fc)-1].cell_contents
if PY2:
info = f.func_code.co_filename[len(settings.PROJECT_ROOT)+1:]
info = '%s:%s' % (info, f.func_code.co_firstlineno)
else:
info = f.__code__.co_filename[len(settings.PROJECT_ROOT)+1:] info = f.__code__.co_filename[len(settings.PROJECT_ROOT)+1:]
info = '%s:%s' % (info, f.__code__.co_firstlineno) info = '%s:%s' % (info, f.__code__.co_firstlineno)
return info, trim(inspect.getsource(f)) return info, trim(inspect.getsource(f))

View file

@ -8,8 +8,6 @@ from django.utils import datetime_safe
import django.contrib.postgres.fields import django.contrib.postgres.fields
from django.core.serializers.json import DjangoJSONEncoder from django.core.serializers.json import DjangoJSONEncoder
from six import string_types
from ox.utils import json from ox.utils import json
class JSONField(django.contrib.postgres.fields.JSONField): class JSONField(django.contrib.postgres.fields.JSONField):
@ -74,7 +72,7 @@ class DictField(models.TextField):
except: except:
raise Exception('failed to parse value: %s' % value) raise Exception('failed to parse value: %s' % value)
if value is not None: if value is not None:
if isinstance(value, string_types): if isinstance(value, str):
value = json.loads(value) value = json.loads(value)
assert isinstance(value, self._type) assert isinstance(value, self._type)
return value return value
@ -83,7 +81,7 @@ class DictField(models.TextField):
if isinstance(value, self._type): if isinstance(value, self._type):
value = self.dumps(value) value = self.dumps(value)
if value is not None: if value is not None:
assert isinstance(value, string_types) assert isinstance(value, str)
value = models.TextField.get_prep_value(self, value) value = models.TextField.get_prep_value(self, value)
return value return value

View file

@ -1,8 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import os
import mimetypes
from datetime import datetime, timedelta from datetime import datetime, timedelta
from six.moves.urllib.parse import quote from urllib.parse import quote
import mimetypes
import os
from django.http import HttpResponse, Http404 from django.http import HttpResponse, Http404
from django.conf import settings from django.conf import settings

View file

@ -1,7 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import unicodedata import unicodedata
from six import string_types
from django.db.models import Q, Manager from django.db.models import Q, Manager
from item.utils import decode_id from item.utils import decode_id
@ -56,7 +55,7 @@ def parseCondition(condition, user):
else: else:
key = k + get_operator(op, 'istr') key = k + get_operator(op, 'istr')
key = str(key) key = str(key)
if isinstance(v, string_types): if isinstance(v, str):
v = unicodedata.normalize('NFKD', v).lower() v = unicodedata.normalize('NFKD', v).lower()
if exclude: if exclude:
q = ~Q(**{key: v}) q = ~Q(**{key: v})

View file

@ -1,7 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import unicodedata import unicodedata
from six import string_types
from django.db.models import Q, Manager from django.db.models import Q, Manager
from item.utils import decode_id from item.utils import decode_id
@ -55,7 +54,7 @@ def parseCondition(condition, user):
key = k + get_operator(op, 'istr') key = k + get_operator(op, 'istr')
key = str(key) key = str(key)
if isinstance(v, string_types): if isinstance(v, str):
v = unicodedata.normalize('NFKD', v).lower() v = unicodedata.normalize('NFKD', v).lower()
if exclude: if exclude:

View file

@ -3,7 +3,6 @@
from django.db.models import Max, Min, Count from django.db.models import Max, Min, Count
from django.conf import settings from django.conf import settings
from six import string_types
import ox import ox
from ox.utils import json from ox.utils import json
@ -115,7 +114,7 @@ def editPlace(request, data):
''' '''
place = get_object_or_404_json(models.Place, pk=ox.fromAZ(data['id'])) place = get_object_or_404_json(models.Place, pk=ox.fromAZ(data['id']))
names = data.get('name', []) names = data.get('name', [])
if isinstance(names, string_types): if isinstance(names, str):
names = [names] names = [names]
names = [ox.escape_html(n) for n in names] names = [ox.escape_html(n) for n in names]
alternative_names = [ox.escape_html(n) for n in data.get('alternativeNames', [])] alternative_names = [ox.escape_html(n) for n in data.get('alternativeNames', [])]
@ -144,7 +143,7 @@ def editPlace(request, data):
for key in data: for key in data:
if key != 'id': if key != 'id':
value = data[key] value = data[key]
if isinstance(value, string_types): if isinstance(value, str):
value = ox.escape_html(value) value = ox.escape_html(value)
if isinstance(value, list): if isinstance(value, list):
value = tuple(value) value = tuple(value)

View file

@ -1,6 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from six import string_types
from django.db import connection, transaction from django.db import connection, transaction
from celery.task import task from celery.task import task
@ -30,7 +29,7 @@ def get_sequences(public_id):
sequence['duration'] = sequence['end'] - sequence['start'] sequence['duration'] = sequence['end'] - sequence['start']
if not keys: if not keys:
keys = ', '.join(['"%s"'%k for k in sequence.keys()]) keys = ', '.join(['"%s"'%k for k in sequence.keys()])
v = ', '.join([isinstance(v, string_types) and "'%s'"%v or str(v) v = ', '.join([isinstance(v, str) and "'%s'"%v or str(v)
for v in sequence.values()]) for v in sequence.values()])
values.append('(%s)'%v) values.append('(%s)'%v)
if values: if values:

View file

@ -1,11 +1,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from glob import glob
from urllib.parse import quote
import os import os
import re import re
import subprocess import subprocess
from glob import glob
from six.moves.urllib.parse import quote
from django.db import models from django.db import models
from django.db.models import Max from django.db.models import Max
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model

View file

@ -1,7 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import unicodedata import unicodedata
from six import string_types
from django.db.models import Q, Manager from django.db.models import Q, Manager
from item.utils import decode_id from item.utils import decode_id
@ -47,7 +46,7 @@ def parseCondition(condition, user):
return q return q
if k == 'id': if k == 'id':
v = decode_id(v) v = decode_id(v)
elif isinstance(v, string_types): elif isinstance(v, str):
v = unicodedata.normalize('NFKD', v).lower() v = unicodedata.normalize('NFKD', v).lower()
if isinstance(v, bool): if isinstance(v, bool):
key = k key = k

View file

@ -1,8 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from urllib.parse import quote
import re import re
from six.moves.urllib.parse import quote
from django.shortcuts import get_object_or_404, redirect from django.shortcuts import get_object_or_404, redirect
import app.views import app.views

View file

@ -1,9 +1,9 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import json
from datetime import timedelta from datetime import timedelta
from itertools import zip_longest
import json
from six.moves import zip_longest
from celery.task import task, periodic_task from celery.task import task, periodic_task
from app.utils import limit_rate from app.utils import limit_rate