Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def define_binding(db):
class ChannelPeer(db.Entity):
"""
This binding stores public keys of IPv8 peers that sent us some GigaChannel data. It is used by the
voting system.
"""
rowid = orm.PrimaryKey(int, size=64, auto=True)
public_key = orm.Required(database_blob, unique=True)
individual_votes = orm.Set("ChannelVote", reverse='voter')
added_on = orm.Optional(datetime, default=datetime.utcnow)
return ChannelPeer
name = orm.PrimaryKey(str)
display_name = orm.Optional(str)
description = orm.Optional(str, nullable=True)
created_at = orm.Required(datetime, default=datetime.now())
metadata = orm.Optional(orm.Json, nullable=True)
updated_at = orm.Optional(datetime)
# dataset - metadata
parameter = orm.Optional(orm.Json, nullable=True)
unit = orm.Optional(str)
datatype = orm.Optional(str)
file_format = orm.Optional(str)
source = orm.Optional(str)
options = orm.Optional(orm.Json, nullable=True)
status = orm.Optional(str)
message = orm.Optional(str)
file_path = orm.Optional(str, nullable=True)
visualization_path = orm.Optional(str)
# setup relationships
collection = orm.Required(Collection)
catalog_entry = orm.Required(str)
class Providers(db.Entity):
provider = orm.PrimaryKey(str)
username = orm.Required(str)
password = orm.Required(str)
class QuestCatalog(db.Entity):
service_id = orm.PrimaryKey(str)
created_at = orm.Required(datetime, default=datetime.now())
updated_at = orm.Optional(datetime)
# setup relationships
datasets = orm.Set('Dataset')
class Dataset(db.Entity):
name = orm.PrimaryKey(str)
display_name = orm.Optional(str)
description = orm.Optional(str, nullable=True)
created_at = orm.Required(datetime, default=datetime.now())
metadata = orm.Optional(orm.Json, nullable=True)
updated_at = orm.Optional(datetime)
# dataset - metadata
parameter = orm.Optional(orm.Json, nullable=True)
unit = orm.Optional(str)
datatype = orm.Optional(str)
file_format = orm.Optional(str)
source = orm.Optional(str)
options = orm.Optional(orm.Json, nullable=True)
status = orm.Optional(str)
message = orm.Optional(str)
file_path = orm.Optional(str, nullable=True)
visualization_path = orm.Optional(str)
# setup relationships
collection = orm.Required(Collection)
catalog_entry = orm.Required(str)
class Providers(db.Entity):
provider = orm.PrimaryKey(str)
username = orm.Required(str)
password = orm.Required(str)
user_id = orm.Required(int, default=1)
name = orm.Required(unicode, 80, unique=True)
urlname = orm.Required(unicode, 80, unique=True)
topic_count = orm.Required(int, default=0)
follow_count = orm.Required(int, default=0)
role = orm.Required(unicode, 10, default='node')
created_at = orm.Required(int, default=int(time.time()))
updated_at = orm.Required(int, default=int(time.time()))
active = orm.Required(int, default=int(time.time()))
description = orm.Optional(orm.LongUnicode)
summary = orm.Optional(orm.LongUnicode)
style = orm.Optional(unicode, 6000)
icon_img = orm.Optional(unicode, 400)
head_img = orm.Optional(unicode, 400)
background_img = orm.Optional(unicode, 400)
@property
def url(self):
return '/node/' + self.urlname
@property
def icon(self):
if self.icon_img:
return self.icon_img
else:
return config.node_icon_url
"""
This ORM binding represents Channel entries in the GigaChannel system. Each channel is a Collection that
additionally has Torrent properties, such as infohash, etc. The torrent properties are used to associate
a torrent that holds the contents of the channel dumped on the disk in the serialized form.
Methods for committing channels into the torrent form are implemented in this class.
"""
_discriminator_ = CHANNEL_TORRENT
# Serializable
start_timestamp = orm.Optional(int, size=64, default=0)
# Local
subscribed = orm.Optional(bool, default=False, index=True)
share = orm.Optional(bool, default=False, index=True)
votes = orm.Optional(float, default=0.0, index=True)
individual_votes = orm.Set("ChannelVote", reverse="channel")
local_version = orm.Optional(int, size=64, default=0)
votes_scaling = 1.0
# Special class-level properties
_payload_class = ChannelMetadataPayload
_channels_dir = None
_category_filter = None
_CHUNK_SIZE_LIMIT = 1 * 1024 * 1024 # We use 1MB chunks as a workaround for Python's lack of string pointers
payload_arguments = _payload_class.__init__.__code__.co_varnames[
: _payload_class.__init__.__code__.co_argcount
][1:]
# As channel metadata depends on the public key, we can't include the infohash in nonpersonal_attributes
nonpersonal_attributes = set(db.CollectionNode.nonpersonal_attributes)
class Collection(db.Entity):
name = orm.PrimaryKey(str)
display_name = orm.Optional(str)
description = orm.Optional(str)
created_at = orm.Required(datetime, default=datetime.now())
updated_at = orm.Optional(datetime)
metadata = orm.Optional(orm.Json, nullable=True)
# setup relationships
datasets = orm.Set('Dataset')
class Dataset(db.Entity):
name = orm.PrimaryKey(str)
display_name = orm.Optional(str)
description = orm.Optional(str, nullable=True)
created_at = orm.Required(datetime, default=datetime.now())
metadata = orm.Optional(orm.Json, nullable=True)
updated_at = orm.Optional(datetime)
# dataset - metadata
parameter = orm.Optional(orm.Json, nullable=True)
unit = orm.Optional(str)
datatype = orm.Optional(str)
file_format = orm.Optional(str)
source = orm.Optional(str)
options = orm.Optional(orm.Json, nullable=True)
status = orm.Optional(str)
message = orm.Optional(str)
file_path = orm.Optional(str, nullable=True)
visualization_path = orm.Optional(str)
class Image(db.Entity):
_table_ = "images"
REGULAR = 1080
SMALL = 400
THUMB = 200
url = PrimaryKey(str)
height = Optional(int)
width = Optional(int)
color = Optional(str, sql_default="''")
playlist = Optional("Playlist")
artist = Optional("Artist")
genre = Optional("Genre")
country = Optional("Country")
city = Optional("City")
user = Optional("User")
unsplash_id = Optional(str, index=True, sql_default="''")
unsplash_user_fullname = Optional(str, sql_default="''")
unsplash_user_username = Optional(str, sql_default="''")
# pylint: disable=no-self-use
@classmethod
def unsplash_url(cls):
return f"https://unsplash.com/?utm_source={config.unsplash.app_name}&utm_medium=referral"
@classmethod
def unsplash_user_url(cls, username):
return f"https://unsplash.com/@{username}?utm_source={config.unsplash.app_name}&utm_medium=referral"
@classmethod
def unsplash_credits(cls, user_fullname, username):
col_float3 = Required(float, default=2.2)
col_smallint3 = Required(int, size=16, default=2)
col_int3 = Required(int, size=32, default=2000000)
col_bigint3 = Required(int, size=64, default=99999999)
col_char3 = Required(str, max_len=255, default='value1')
col_text3 = Required(LongUnicode, default='Moo,Foo,Baa,Waa,Moo,Foo,Baa,Waa,Moo,Foo,Baa,Waa')
col_decimal3 = Required(Decimal, 12, 8, default=Decimal('2.2'))
col_json3 = Required(Json, default={'a':1, 'b':'b', 'c':[2], 'd':{'e': 3}, 'f': True})
col_float4 = Optional(float)
col_smallint4 = Optional(int, size=16)
col_int4 = Optional(int, size=32)
col_bigint4 = Optional(int, size=64)
col_char4 = Optional(str, max_len=255)
col_text4 = Optional(LongUnicode)
col_decimal4 = Optional(Decimal, 12, 8)
col_json4 = Optional(Json)
dbtype = os.environ.get('DBTYPE', '')
if dbtype == 'postgres':
db.bind(provider='postgres', user='postgres', password=None, host='127.0.0.1', database='tbench')
elif dbtype == 'mysql':
db.bind(provider='mysql', host='127.0.0.1', user='root', passwd='', db='tbench')
else:
db.bind(provider='sqlite', filename='/dev/shm/db.sqlite3', create_db=True)
db.generate_mapping(create_tables=True)
YEAR = 6
ALL = 7
INTRO = 8
id = PrimaryKey(str) # pylint: disable=redefined-builtin
collaborative = Required(bool)
name = Required(str)
description = Optional(str, sql_default="''")
owner = Required(SpotifyUser)
public = Required(bool)
snapshot_id = Required(str)
tracks = Required(int)
popularity = Optional(int, index=True, sql_default="0")
genre = Optional(Genre)
country = Optional(Country)
city = Optional(City)
date = Optional(date, index=True)
year = Optional(int)
women = Optional(bool, index=True, sql_default=SQL_DEFAULT.bool_false)
christmas = Optional(bool, index=True, sql_default=SQL_DEFAULT.bool_false)
meta = Optional(bool, index=True, sql_default=SQL_DEFAULT.bool_false)
images = Set(Image, cascade_delete=True)
def play(self, client, device=None):
return client.start_playback(playlist=self.uri, device=device)
@property
def uri(self):
return f"spotify:user:{self.owner.id}:playlist:{self.id}"
@property
def href(self):
# coding: utf-8
import time
from pony import orm
from ._base import db, BaseModel
from collipa import config
class Collect(db.Entity, BaseModel):
user_id = orm.Required(int)
created_at = orm.Required(int, default=int(time.time()))
collect_class_id = orm.Optional(int)
topic_id = orm.Optional(int)
reply_id = orm.Optional(int)
tweet_id = orm.Optional(int)
content = orm.Optional(orm.LongUnicode)
def __str__(self):
return self.id
def __repr__(self):
return '' % self.id
def save(self):
now = int(time.time())
self.created_at = now
if self.topic_id: