prompt
large_stringlengths 72
9.34k
| completion
large_stringlengths 0
7.61k
|
---|---|
<|file_name|>382-linked-list-random-node.py<|end_file_name|><|fim▁begin|>import random
# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution(object):
_largesize = 300
def <|fim_middle|>(self, head):
self.head = head
self.lsize = 0
while head.next:
head = head.next
self.lsize += 1
self.m1_idx = None
self.m2_idx = None
if self.lsize > self._largesize:
self.m1_idx = self.lsize / 3 # start from 1/3
self.m1 = self._getN(self.m1_idx)
self.m2_idx = self.m1_idx * 2 # start from 2/3
self.m2 = self._getN(self.m2_idx)
def _getN(self, n):
n -= 1
p = self.head
while n:
p = p.next
n -= 1
return p
def getRandom(self):
def _get(delta, start):
p = start
while delta:
p = p.next
delta -= 1
return p.val
nextpos = random.randint(0, self.lsize)
if not self.m1_idx:
return _get(nextpos, self.head)
if nextpos < self.m1_idx:
val = _get(nextpos, self.head)
elif nextpos < self.m2_idx:
val = _get(nextpos - self.m1_idx, self.m1)
else:
val = _get(nextpos - self.m2_idx, self.m2)
return val
<|fim▁end|> | __init__ |
<|file_name|>382-linked-list-random-node.py<|end_file_name|><|fim▁begin|>import random
# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution(object):
_largesize = 300
def __init__(self, head):
self.head = head
self.lsize = 0
while head.next:
head = head.next
self.lsize += 1
self.m1_idx = None
self.m2_idx = None
if self.lsize > self._largesize:
self.m1_idx = self.lsize / 3 # start from 1/3
self.m1 = self._getN(self.m1_idx)
self.m2_idx = self.m1_idx * 2 # start from 2/3
self.m2 = self._getN(self.m2_idx)
def <|fim_middle|>(self, n):
n -= 1
p = self.head
while n:
p = p.next
n -= 1
return p
def getRandom(self):
def _get(delta, start):
p = start
while delta:
p = p.next
delta -= 1
return p.val
nextpos = random.randint(0, self.lsize)
if not self.m1_idx:
return _get(nextpos, self.head)
if nextpos < self.m1_idx:
val = _get(nextpos, self.head)
elif nextpos < self.m2_idx:
val = _get(nextpos - self.m1_idx, self.m1)
else:
val = _get(nextpos - self.m2_idx, self.m2)
return val
<|fim▁end|> | _getN |
<|file_name|>382-linked-list-random-node.py<|end_file_name|><|fim▁begin|>import random
# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution(object):
_largesize = 300
def __init__(self, head):
self.head = head
self.lsize = 0
while head.next:
head = head.next
self.lsize += 1
self.m1_idx = None
self.m2_idx = None
if self.lsize > self._largesize:
self.m1_idx = self.lsize / 3 # start from 1/3
self.m1 = self._getN(self.m1_idx)
self.m2_idx = self.m1_idx * 2 # start from 2/3
self.m2 = self._getN(self.m2_idx)
def _getN(self, n):
n -= 1
p = self.head
while n:
p = p.next
n -= 1
return p
def <|fim_middle|>(self):
def _get(delta, start):
p = start
while delta:
p = p.next
delta -= 1
return p.val
nextpos = random.randint(0, self.lsize)
if not self.m1_idx:
return _get(nextpos, self.head)
if nextpos < self.m1_idx:
val = _get(nextpos, self.head)
elif nextpos < self.m2_idx:
val = _get(nextpos - self.m1_idx, self.m1)
else:
val = _get(nextpos - self.m2_idx, self.m2)
return val
<|fim▁end|> | getRandom |
<|file_name|>382-linked-list-random-node.py<|end_file_name|><|fim▁begin|>import random
# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution(object):
_largesize = 300
def __init__(self, head):
self.head = head
self.lsize = 0
while head.next:
head = head.next
self.lsize += 1
self.m1_idx = None
self.m2_idx = None
if self.lsize > self._largesize:
self.m1_idx = self.lsize / 3 # start from 1/3
self.m1 = self._getN(self.m1_idx)
self.m2_idx = self.m1_idx * 2 # start from 2/3
self.m2 = self._getN(self.m2_idx)
def _getN(self, n):
n -= 1
p = self.head
while n:
p = p.next
n -= 1
return p
def getRandom(self):
def <|fim_middle|>(delta, start):
p = start
while delta:
p = p.next
delta -= 1
return p.val
nextpos = random.randint(0, self.lsize)
if not self.m1_idx:
return _get(nextpos, self.head)
if nextpos < self.m1_idx:
val = _get(nextpos, self.head)
elif nextpos < self.m2_idx:
val = _get(nextpos - self.m1_idx, self.m1)
else:
val = _get(nextpos - self.m2_idx, self.m2)
return val
<|fim▁end|> | _get |
<|file_name|>test_play_file.py<|end_file_name|><|fim▁begin|># coding: UTF-8
import unittest<|fim▁hole|>
class TestAssemblyReader(unittest.TestCase):
def test_version_reader(self):
assembly_reader = play_file.AssemblyReader()
version = assembly_reader.get_assembly_version('AssemblyInfo.cs')
self.assertEqual(version, '7.3.1.0210')
def test_version_writer(self):
new_version = '7.3.1.0228'
assembly_writer = play_file.AssemblyWriter()
version = assembly_writer.update_assembly_version('AssemblyInfo.cs', new_version)
self.assertEqual(version, new_version)<|fim▁end|> | import play_file
|
<|file_name|>test_play_file.py<|end_file_name|><|fim▁begin|># coding: UTF-8
import unittest
import play_file
class TestAssemblyReader(unittest.TestCase):
<|fim_middle|>
<|fim▁end|> | def test_version_reader(self):
assembly_reader = play_file.AssemblyReader()
version = assembly_reader.get_assembly_version('AssemblyInfo.cs')
self.assertEqual(version, '7.3.1.0210')
def test_version_writer(self):
new_version = '7.3.1.0228'
assembly_writer = play_file.AssemblyWriter()
version = assembly_writer.update_assembly_version('AssemblyInfo.cs', new_version)
self.assertEqual(version, new_version) |
<|file_name|>test_play_file.py<|end_file_name|><|fim▁begin|># coding: UTF-8
import unittest
import play_file
class TestAssemblyReader(unittest.TestCase):
def test_version_reader(self):
<|fim_middle|>
def test_version_writer(self):
new_version = '7.3.1.0228'
assembly_writer = play_file.AssemblyWriter()
version = assembly_writer.update_assembly_version('AssemblyInfo.cs', new_version)
self.assertEqual(version, new_version)
<|fim▁end|> | assembly_reader = play_file.AssemblyReader()
version = assembly_reader.get_assembly_version('AssemblyInfo.cs')
self.assertEqual(version, '7.3.1.0210') |
<|file_name|>test_play_file.py<|end_file_name|><|fim▁begin|># coding: UTF-8
import unittest
import play_file
class TestAssemblyReader(unittest.TestCase):
def test_version_reader(self):
assembly_reader = play_file.AssemblyReader()
version = assembly_reader.get_assembly_version('AssemblyInfo.cs')
self.assertEqual(version, '7.3.1.0210')
def test_version_writer(self):
<|fim_middle|>
<|fim▁end|> | new_version = '7.3.1.0228'
assembly_writer = play_file.AssemblyWriter()
version = assembly_writer.update_assembly_version('AssemblyInfo.cs', new_version)
self.assertEqual(version, new_version) |
<|file_name|>test_play_file.py<|end_file_name|><|fim▁begin|># coding: UTF-8
import unittest
import play_file
class TestAssemblyReader(unittest.TestCase):
def <|fim_middle|>(self):
assembly_reader = play_file.AssemblyReader()
version = assembly_reader.get_assembly_version('AssemblyInfo.cs')
self.assertEqual(version, '7.3.1.0210')
def test_version_writer(self):
new_version = '7.3.1.0228'
assembly_writer = play_file.AssemblyWriter()
version = assembly_writer.update_assembly_version('AssemblyInfo.cs', new_version)
self.assertEqual(version, new_version)
<|fim▁end|> | test_version_reader |
<|file_name|>test_play_file.py<|end_file_name|><|fim▁begin|># coding: UTF-8
import unittest
import play_file
class TestAssemblyReader(unittest.TestCase):
def test_version_reader(self):
assembly_reader = play_file.AssemblyReader()
version = assembly_reader.get_assembly_version('AssemblyInfo.cs')
self.assertEqual(version, '7.3.1.0210')
def <|fim_middle|>(self):
new_version = '7.3.1.0228'
assembly_writer = play_file.AssemblyWriter()
version = assembly_writer.update_assembly_version('AssemblyInfo.cs', new_version)
self.assertEqual(version, new_version)
<|fim▁end|> | test_version_writer |
<|file_name|>005_cleaner.py<|end_file_name|><|fim▁begin|># 005_cleaner.py
#####################################################################
##################################
# Import des modules et ajout du path de travail pour import relatif
import sys
sys.path.insert(0 , 'C:/Users/WILLROS/Perso/Shade/scripts/LocalWC-Shade-App/apis/')
from voca import AddLog , StringFormatter , OutFileCreate , OdditiesFinder
##################################
# Init des paths et noms de fichiers
<|fim▁hole|># Nom du fichier source
raw_file = 'src'
##################################
# retreiving raw string
raw_string_with_tabs = open(work_dir + raw_file , 'r').read()
# replacing tabs with carriage return
raw_string_with_cr = raw_string_with_tabs.replace( '\t', '\n' )
# turning the string into a list
raw_list = raw_string_with_cr.splitlines()
# going through oddities finder
AddLog('subtitle' , 'Début de la fonction OdditiesFinder')
list_without_oddities = OdditiesFinder( raw_list )
# going through string formatter
ref_list = []
AddLog('subtitle' , 'Début de la fonction StringFormatter')
for line in list_without_oddities:
ref_list.append( StringFormatter( line ) )
##################################
# Enregistrement des fichiers sortie
AddLog('subtitle' , 'Début de la fonction OutFileCreate')
OutFileCreate('C:/Users/WILLROS/Perso/Shade/scripts/LocalWC-Shade-App/apis/out/','{}_src'.format(missionName),ref_list,'prenoms masculins italiens')<|fim▁end|> | missionName = '005'
AddLog('title' , '{} : Début du nettoyage du fichier'.format(missionName))
work_dir = 'C:/Users/WILLROS/Perso/Shade/scripts/LocalWC-Shade-App/apis/raw/{}_raw/'.format(missionName)
|
<|file_name|>manage.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pigame.settings")
try:
from django.core.management import execute_from_command_line
except ImportError:
# The above import may fail for some other reason. Ensure that the
# issue is really that Django is missing to avoid masking other<|fim▁hole|> raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
)
raise
execute_from_command_line(sys.argv)<|fim▁end|> | # exceptions on Python 2.
try:
import django
except ImportError: |
<|file_name|>manage.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
<|fim_middle|>
<|fim▁end|> | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pigame.settings")
try:
from django.core.management import execute_from_command_line
except ImportError:
# The above import may fail for some other reason. Ensure that the
# issue is really that Django is missing to avoid masking other
# exceptions on Python 2.
try:
import django
except ImportError:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
)
raise
execute_from_command_line(sys.argv) |
<|file_name|>scribe.py<|end_file_name|><|fim▁begin|>import io
import sys
isPython3 = sys.version_info >= (3, 0)
class Scribe:
@staticmethod
def read(path):
with io.open(path, mode="rt", encoding="utf-8") as f:
s = f.read()
# go to beginning
f.seek(0)
return s
@staticmethod
def read_beginning(path, lines):
with io.open(path, mode="rt", encoding="utf-8") as f:
s = f.read(lines)
# go to beginning
f.seek(0)
return s
@staticmethod
def read_lines(path):
with io.open(path, mode="rt", encoding="utf-8") as f:
content = f.readlines()
return content
@staticmethod
def write(contents, path):
if isPython3:
with open(path, mode="wt", encoding="utf-8") as f:
# truncate previous contents
f.truncate()
f.write(contents)
else:
with io.open(path, mode="wt", encoding="utf-8") as f:
# truncate previous contents
f.truncate()
f.write(contents.decode("utf8"))
@staticmethod
def write_lines(lines, path):
if isPython3:
with open(path, mode="wt", encoding="utf-8") as f:
f.writelines([l + "\n" for l in lines])
else:
with io.open(path, mode="wt") as f:
for line in lines:
f.writelines(line.decode("utf8") + "\n")
<|fim▁hole|> with open(path, mode="a", encoding="utf-8") as f:
f.writelines(contents)
else:
with io.open(path, mode="a") as f:
f.writelines(contents.decode("utf8"))<|fim▁end|> | @staticmethod
def add_content(contents, path):
if isPython3:
|
<|file_name|>scribe.py<|end_file_name|><|fim▁begin|>import io
import sys
isPython3 = sys.version_info >= (3, 0)
class Scribe:
<|fim_middle|>
<|fim▁end|> | @staticmethod
def read(path):
with io.open(path, mode="rt", encoding="utf-8") as f:
s = f.read()
# go to beginning
f.seek(0)
return s
@staticmethod
def read_beginning(path, lines):
with io.open(path, mode="rt", encoding="utf-8") as f:
s = f.read(lines)
# go to beginning
f.seek(0)
return s
@staticmethod
def read_lines(path):
with io.open(path, mode="rt", encoding="utf-8") as f:
content = f.readlines()
return content
@staticmethod
def write(contents, path):
if isPython3:
with open(path, mode="wt", encoding="utf-8") as f:
# truncate previous contents
f.truncate()
f.write(contents)
else:
with io.open(path, mode="wt", encoding="utf-8") as f:
# truncate previous contents
f.truncate()
f.write(contents.decode("utf8"))
@staticmethod
def write_lines(lines, path):
if isPython3:
with open(path, mode="wt", encoding="utf-8") as f:
f.writelines([l + "\n" for l in lines])
else:
with io.open(path, mode="wt") as f:
for line in lines:
f.writelines(line.decode("utf8") + "\n")
@staticmethod
def add_content(contents, path):
if isPython3:
with open(path, mode="a", encoding="utf-8") as f:
f.writelines(contents)
else:
with io.open(path, mode="a") as f:
f.writelines(contents.decode("utf8")) |
<|file_name|>scribe.py<|end_file_name|><|fim▁begin|>import io
import sys
isPython3 = sys.version_info >= (3, 0)
class Scribe:
@staticmethod
def read(path):
<|fim_middle|>
@staticmethod
def read_beginning(path, lines):
with io.open(path, mode="rt", encoding="utf-8") as f:
s = f.read(lines)
# go to beginning
f.seek(0)
return s
@staticmethod
def read_lines(path):
with io.open(path, mode="rt", encoding="utf-8") as f:
content = f.readlines()
return content
@staticmethod
def write(contents, path):
if isPython3:
with open(path, mode="wt", encoding="utf-8") as f:
# truncate previous contents
f.truncate()
f.write(contents)
else:
with io.open(path, mode="wt", encoding="utf-8") as f:
# truncate previous contents
f.truncate()
f.write(contents.decode("utf8"))
@staticmethod
def write_lines(lines, path):
if isPython3:
with open(path, mode="wt", encoding="utf-8") as f:
f.writelines([l + "\n" for l in lines])
else:
with io.open(path, mode="wt") as f:
for line in lines:
f.writelines(line.decode("utf8") + "\n")
@staticmethod
def add_content(contents, path):
if isPython3:
with open(path, mode="a", encoding="utf-8") as f:
f.writelines(contents)
else:
with io.open(path, mode="a") as f:
f.writelines(contents.decode("utf8"))
<|fim▁end|> | with io.open(path, mode="rt", encoding="utf-8") as f:
s = f.read()
# go to beginning
f.seek(0)
return s |
<|file_name|>scribe.py<|end_file_name|><|fim▁begin|>import io
import sys
isPython3 = sys.version_info >= (3, 0)
class Scribe:
@staticmethod
def read(path):
with io.open(path, mode="rt", encoding="utf-8") as f:
s = f.read()
# go to beginning
f.seek(0)
return s
@staticmethod
def read_beginning(path, lines):
<|fim_middle|>
@staticmethod
def read_lines(path):
with io.open(path, mode="rt", encoding="utf-8") as f:
content = f.readlines()
return content
@staticmethod
def write(contents, path):
if isPython3:
with open(path, mode="wt", encoding="utf-8") as f:
# truncate previous contents
f.truncate()
f.write(contents)
else:
with io.open(path, mode="wt", encoding="utf-8") as f:
# truncate previous contents
f.truncate()
f.write(contents.decode("utf8"))
@staticmethod
def write_lines(lines, path):
if isPython3:
with open(path, mode="wt", encoding="utf-8") as f:
f.writelines([l + "\n" for l in lines])
else:
with io.open(path, mode="wt") as f:
for line in lines:
f.writelines(line.decode("utf8") + "\n")
@staticmethod
def add_content(contents, path):
if isPython3:
with open(path, mode="a", encoding="utf-8") as f:
f.writelines(contents)
else:
with io.open(path, mode="a") as f:
f.writelines(contents.decode("utf8"))
<|fim▁end|> | with io.open(path, mode="rt", encoding="utf-8") as f:
s = f.read(lines)
# go to beginning
f.seek(0)
return s |
<|file_name|>scribe.py<|end_file_name|><|fim▁begin|>import io
import sys
isPython3 = sys.version_info >= (3, 0)
class Scribe:
@staticmethod
def read(path):
with io.open(path, mode="rt", encoding="utf-8") as f:
s = f.read()
# go to beginning
f.seek(0)
return s
@staticmethod
def read_beginning(path, lines):
with io.open(path, mode="rt", encoding="utf-8") as f:
s = f.read(lines)
# go to beginning
f.seek(0)
return s
@staticmethod
def read_lines(path):
<|fim_middle|>
@staticmethod
def write(contents, path):
if isPython3:
with open(path, mode="wt", encoding="utf-8") as f:
# truncate previous contents
f.truncate()
f.write(contents)
else:
with io.open(path, mode="wt", encoding="utf-8") as f:
# truncate previous contents
f.truncate()
f.write(contents.decode("utf8"))
@staticmethod
def write_lines(lines, path):
if isPython3:
with open(path, mode="wt", encoding="utf-8") as f:
f.writelines([l + "\n" for l in lines])
else:
with io.open(path, mode="wt") as f:
for line in lines:
f.writelines(line.decode("utf8") + "\n")
@staticmethod
def add_content(contents, path):
if isPython3:
with open(path, mode="a", encoding="utf-8") as f:
f.writelines(contents)
else:
with io.open(path, mode="a") as f:
f.writelines(contents.decode("utf8"))
<|fim▁end|> | with io.open(path, mode="rt", encoding="utf-8") as f:
content = f.readlines()
return content |
<|file_name|>scribe.py<|end_file_name|><|fim▁begin|>import io
import sys
isPython3 = sys.version_info >= (3, 0)
class Scribe:
@staticmethod
def read(path):
with io.open(path, mode="rt", encoding="utf-8") as f:
s = f.read()
# go to beginning
f.seek(0)
return s
@staticmethod
def read_beginning(path, lines):
with io.open(path, mode="rt", encoding="utf-8") as f:
s = f.read(lines)
# go to beginning
f.seek(0)
return s
@staticmethod
def read_lines(path):
with io.open(path, mode="rt", encoding="utf-8") as f:
content = f.readlines()
return content
@staticmethod
def write(contents, path):
<|fim_middle|>
@staticmethod
def write_lines(lines, path):
if isPython3:
with open(path, mode="wt", encoding="utf-8") as f:
f.writelines([l + "\n" for l in lines])
else:
with io.open(path, mode="wt") as f:
for line in lines:
f.writelines(line.decode("utf8") + "\n")
@staticmethod
def add_content(contents, path):
if isPython3:
with open(path, mode="a", encoding="utf-8") as f:
f.writelines(contents)
else:
with io.open(path, mode="a") as f:
f.writelines(contents.decode("utf8"))
<|fim▁end|> | if isPython3:
with open(path, mode="wt", encoding="utf-8") as f:
# truncate previous contents
f.truncate()
f.write(contents)
else:
with io.open(path, mode="wt", encoding="utf-8") as f:
# truncate previous contents
f.truncate()
f.write(contents.decode("utf8")) |
<|file_name|>scribe.py<|end_file_name|><|fim▁begin|>import io
import sys
isPython3 = sys.version_info >= (3, 0)
class Scribe:
@staticmethod
def read(path):
with io.open(path, mode="rt", encoding="utf-8") as f:
s = f.read()
# go to beginning
f.seek(0)
return s
@staticmethod
def read_beginning(path, lines):
with io.open(path, mode="rt", encoding="utf-8") as f:
s = f.read(lines)
# go to beginning
f.seek(0)
return s
@staticmethod
def read_lines(path):
with io.open(path, mode="rt", encoding="utf-8") as f:
content = f.readlines()
return content
@staticmethod
def write(contents, path):
if isPython3:
with open(path, mode="wt", encoding="utf-8") as f:
# truncate previous contents
f.truncate()
f.write(contents)
else:
with io.open(path, mode="wt", encoding="utf-8") as f:
# truncate previous contents
f.truncate()
f.write(contents.decode("utf8"))
@staticmethod
def write_lines(lines, path):
<|fim_middle|>
@staticmethod
def add_content(contents, path):
if isPython3:
with open(path, mode="a", encoding="utf-8") as f:
f.writelines(contents)
else:
with io.open(path, mode="a") as f:
f.writelines(contents.decode("utf8"))
<|fim▁end|> | if isPython3:
with open(path, mode="wt", encoding="utf-8") as f:
f.writelines([l + "\n" for l in lines])
else:
with io.open(path, mode="wt") as f:
for line in lines:
f.writelines(line.decode("utf8") + "\n") |
<|file_name|>scribe.py<|end_file_name|><|fim▁begin|>import io
import sys
isPython3 = sys.version_info >= (3, 0)
class Scribe:
@staticmethod
def read(path):
with io.open(path, mode="rt", encoding="utf-8") as f:
s = f.read()
# go to beginning
f.seek(0)
return s
@staticmethod
def read_beginning(path, lines):
with io.open(path, mode="rt", encoding="utf-8") as f:
s = f.read(lines)
# go to beginning
f.seek(0)
return s
@staticmethod
def read_lines(path):
with io.open(path, mode="rt", encoding="utf-8") as f:
content = f.readlines()
return content
@staticmethod
def write(contents, path):
if isPython3:
with open(path, mode="wt", encoding="utf-8") as f:
# truncate previous contents
f.truncate()
f.write(contents)
else:
with io.open(path, mode="wt", encoding="utf-8") as f:
# truncate previous contents
f.truncate()
f.write(contents.decode("utf8"))
@staticmethod
def write_lines(lines, path):
if isPython3:
with open(path, mode="wt", encoding="utf-8") as f:
f.writelines([l + "\n" for l in lines])
else:
with io.open(path, mode="wt") as f:
for line in lines:
f.writelines(line.decode("utf8") + "\n")
@staticmethod
def add_content(contents, path):
<|fim_middle|>
<|fim▁end|> | if isPython3:
with open(path, mode="a", encoding="utf-8") as f:
f.writelines(contents)
else:
with io.open(path, mode="a") as f:
f.writelines(contents.decode("utf8")) |
<|file_name|>scribe.py<|end_file_name|><|fim▁begin|>import io
import sys
isPython3 = sys.version_info >= (3, 0)
class Scribe:
@staticmethod
def read(path):
with io.open(path, mode="rt", encoding="utf-8") as f:
s = f.read()
# go to beginning
f.seek(0)
return s
@staticmethod
def read_beginning(path, lines):
with io.open(path, mode="rt", encoding="utf-8") as f:
s = f.read(lines)
# go to beginning
f.seek(0)
return s
@staticmethod
def read_lines(path):
with io.open(path, mode="rt", encoding="utf-8") as f:
content = f.readlines()
return content
@staticmethod
def write(contents, path):
if isPython3:
<|fim_middle|>
else:
with io.open(path, mode="wt", encoding="utf-8") as f:
# truncate previous contents
f.truncate()
f.write(contents.decode("utf8"))
@staticmethod
def write_lines(lines, path):
if isPython3:
with open(path, mode="wt", encoding="utf-8") as f:
f.writelines([l + "\n" for l in lines])
else:
with io.open(path, mode="wt") as f:
for line in lines:
f.writelines(line.decode("utf8") + "\n")
@staticmethod
def add_content(contents, path):
if isPython3:
with open(path, mode="a", encoding="utf-8") as f:
f.writelines(contents)
else:
with io.open(path, mode="a") as f:
f.writelines(contents.decode("utf8"))
<|fim▁end|> | with open(path, mode="wt", encoding="utf-8") as f:
# truncate previous contents
f.truncate()
f.write(contents) |
<|file_name|>scribe.py<|end_file_name|><|fim▁begin|>import io
import sys
isPython3 = sys.version_info >= (3, 0)
class Scribe:
@staticmethod
def read(path):
with io.open(path, mode="rt", encoding="utf-8") as f:
s = f.read()
# go to beginning
f.seek(0)
return s
@staticmethod
def read_beginning(path, lines):
with io.open(path, mode="rt", encoding="utf-8") as f:
s = f.read(lines)
# go to beginning
f.seek(0)
return s
@staticmethod
def read_lines(path):
with io.open(path, mode="rt", encoding="utf-8") as f:
content = f.readlines()
return content
@staticmethod
def write(contents, path):
if isPython3:
with open(path, mode="wt", encoding="utf-8") as f:
# truncate previous contents
f.truncate()
f.write(contents)
else:
<|fim_middle|>
@staticmethod
def write_lines(lines, path):
if isPython3:
with open(path, mode="wt", encoding="utf-8") as f:
f.writelines([l + "\n" for l in lines])
else:
with io.open(path, mode="wt") as f:
for line in lines:
f.writelines(line.decode("utf8") + "\n")
@staticmethod
def add_content(contents, path):
if isPython3:
with open(path, mode="a", encoding="utf-8") as f:
f.writelines(contents)
else:
with io.open(path, mode="a") as f:
f.writelines(contents.decode("utf8"))
<|fim▁end|> | with io.open(path, mode="wt", encoding="utf-8") as f:
# truncate previous contents
f.truncate()
f.write(contents.decode("utf8")) |
<|file_name|>scribe.py<|end_file_name|><|fim▁begin|>import io
import sys
isPython3 = sys.version_info >= (3, 0)
class Scribe:
@staticmethod
def read(path):
with io.open(path, mode="rt", encoding="utf-8") as f:
s = f.read()
# go to beginning
f.seek(0)
return s
@staticmethod
def read_beginning(path, lines):
with io.open(path, mode="rt", encoding="utf-8") as f:
s = f.read(lines)
# go to beginning
f.seek(0)
return s
@staticmethod
def read_lines(path):
with io.open(path, mode="rt", encoding="utf-8") as f:
content = f.readlines()
return content
@staticmethod
def write(contents, path):
if isPython3:
with open(path, mode="wt", encoding="utf-8") as f:
# truncate previous contents
f.truncate()
f.write(contents)
else:
with io.open(path, mode="wt", encoding="utf-8") as f:
# truncate previous contents
f.truncate()
f.write(contents.decode("utf8"))
@staticmethod
def write_lines(lines, path):
if isPython3:
<|fim_middle|>
else:
with io.open(path, mode="wt") as f:
for line in lines:
f.writelines(line.decode("utf8") + "\n")
@staticmethod
def add_content(contents, path):
if isPython3:
with open(path, mode="a", encoding="utf-8") as f:
f.writelines(contents)
else:
with io.open(path, mode="a") as f:
f.writelines(contents.decode("utf8"))
<|fim▁end|> | with open(path, mode="wt", encoding="utf-8") as f:
f.writelines([l + "\n" for l in lines]) |
<|file_name|>scribe.py<|end_file_name|><|fim▁begin|>import io
import sys
isPython3 = sys.version_info >= (3, 0)
class Scribe:
@staticmethod
def read(path):
with io.open(path, mode="rt", encoding="utf-8") as f:
s = f.read()
# go to beginning
f.seek(0)
return s
@staticmethod
def read_beginning(path, lines):
with io.open(path, mode="rt", encoding="utf-8") as f:
s = f.read(lines)
# go to beginning
f.seek(0)
return s
@staticmethod
def read_lines(path):
with io.open(path, mode="rt", encoding="utf-8") as f:
content = f.readlines()
return content
@staticmethod
def write(contents, path):
if isPython3:
with open(path, mode="wt", encoding="utf-8") as f:
# truncate previous contents
f.truncate()
f.write(contents)
else:
with io.open(path, mode="wt", encoding="utf-8") as f:
# truncate previous contents
f.truncate()
f.write(contents.decode("utf8"))
@staticmethod
def write_lines(lines, path):
if isPython3:
with open(path, mode="wt", encoding="utf-8") as f:
f.writelines([l + "\n" for l in lines])
else:
<|fim_middle|>
@staticmethod
def add_content(contents, path):
if isPython3:
with open(path, mode="a", encoding="utf-8") as f:
f.writelines(contents)
else:
with io.open(path, mode="a") as f:
f.writelines(contents.decode("utf8"))
<|fim▁end|> | with io.open(path, mode="wt") as f:
for line in lines:
f.writelines(line.decode("utf8") + "\n") |
<|file_name|>scribe.py<|end_file_name|><|fim▁begin|>import io
import sys
isPython3 = sys.version_info >= (3, 0)
class Scribe:
@staticmethod
def read(path):
with io.open(path, mode="rt", encoding="utf-8") as f:
s = f.read()
# go to beginning
f.seek(0)
return s
@staticmethod
def read_beginning(path, lines):
with io.open(path, mode="rt", encoding="utf-8") as f:
s = f.read(lines)
# go to beginning
f.seek(0)
return s
@staticmethod
def read_lines(path):
with io.open(path, mode="rt", encoding="utf-8") as f:
content = f.readlines()
return content
@staticmethod
def write(contents, path):
if isPython3:
with open(path, mode="wt", encoding="utf-8") as f:
# truncate previous contents
f.truncate()
f.write(contents)
else:
with io.open(path, mode="wt", encoding="utf-8") as f:
# truncate previous contents
f.truncate()
f.write(contents.decode("utf8"))
@staticmethod
def write_lines(lines, path):
if isPython3:
with open(path, mode="wt", encoding="utf-8") as f:
f.writelines([l + "\n" for l in lines])
else:
with io.open(path, mode="wt") as f:
for line in lines:
f.writelines(line.decode("utf8") + "\n")
@staticmethod
def add_content(contents, path):
if isPython3:
<|fim_middle|>
else:
with io.open(path, mode="a") as f:
f.writelines(contents.decode("utf8"))
<|fim▁end|> | with open(path, mode="a", encoding="utf-8") as f:
f.writelines(contents) |
<|file_name|>scribe.py<|end_file_name|><|fim▁begin|>import io
import sys
isPython3 = sys.version_info >= (3, 0)
class Scribe:
@staticmethod
def read(path):
with io.open(path, mode="rt", encoding="utf-8") as f:
s = f.read()
# go to beginning
f.seek(0)
return s
@staticmethod
def read_beginning(path, lines):
with io.open(path, mode="rt", encoding="utf-8") as f:
s = f.read(lines)
# go to beginning
f.seek(0)
return s
@staticmethod
def read_lines(path):
with io.open(path, mode="rt", encoding="utf-8") as f:
content = f.readlines()
return content
@staticmethod
def write(contents, path):
if isPython3:
with open(path, mode="wt", encoding="utf-8") as f:
# truncate previous contents
f.truncate()
f.write(contents)
else:
with io.open(path, mode="wt", encoding="utf-8") as f:
# truncate previous contents
f.truncate()
f.write(contents.decode("utf8"))
@staticmethod
def write_lines(lines, path):
if isPython3:
with open(path, mode="wt", encoding="utf-8") as f:
f.writelines([l + "\n" for l in lines])
else:
with io.open(path, mode="wt") as f:
for line in lines:
f.writelines(line.decode("utf8") + "\n")
@staticmethod
def add_content(contents, path):
if isPython3:
with open(path, mode="a", encoding="utf-8") as f:
f.writelines(contents)
else:
<|fim_middle|>
<|fim▁end|> | with io.open(path, mode="a") as f:
f.writelines(contents.decode("utf8")) |
<|file_name|>scribe.py<|end_file_name|><|fim▁begin|>import io
import sys
isPython3 = sys.version_info >= (3, 0)
class Scribe:
@staticmethod
def <|fim_middle|>(path):
with io.open(path, mode="rt", encoding="utf-8") as f:
s = f.read()
# go to beginning
f.seek(0)
return s
@staticmethod
def read_beginning(path, lines):
with io.open(path, mode="rt", encoding="utf-8") as f:
s = f.read(lines)
# go to beginning
f.seek(0)
return s
@staticmethod
def read_lines(path):
with io.open(path, mode="rt", encoding="utf-8") as f:
content = f.readlines()
return content
@staticmethod
def write(contents, path):
if isPython3:
with open(path, mode="wt", encoding="utf-8") as f:
# truncate previous contents
f.truncate()
f.write(contents)
else:
with io.open(path, mode="wt", encoding="utf-8") as f:
# truncate previous contents
f.truncate()
f.write(contents.decode("utf8"))
@staticmethod
def write_lines(lines, path):
if isPython3:
with open(path, mode="wt", encoding="utf-8") as f:
f.writelines([l + "\n" for l in lines])
else:
with io.open(path, mode="wt") as f:
for line in lines:
f.writelines(line.decode("utf8") + "\n")
@staticmethod
def add_content(contents, path):
if isPython3:
with open(path, mode="a", encoding="utf-8") as f:
f.writelines(contents)
else:
with io.open(path, mode="a") as f:
f.writelines(contents.decode("utf8"))
<|fim▁end|> | read |
<|file_name|>scribe.py<|end_file_name|><|fim▁begin|>import io
import sys
isPython3 = sys.version_info >= (3, 0)
class Scribe:
@staticmethod
def read(path):
with io.open(path, mode="rt", encoding="utf-8") as f:
s = f.read()
# go to beginning
f.seek(0)
return s
@staticmethod
def <|fim_middle|>(path, lines):
with io.open(path, mode="rt", encoding="utf-8") as f:
s = f.read(lines)
# go to beginning
f.seek(0)
return s
@staticmethod
def read_lines(path):
with io.open(path, mode="rt", encoding="utf-8") as f:
content = f.readlines()
return content
@staticmethod
def write(contents, path):
if isPython3:
with open(path, mode="wt", encoding="utf-8") as f:
# truncate previous contents
f.truncate()
f.write(contents)
else:
with io.open(path, mode="wt", encoding="utf-8") as f:
# truncate previous contents
f.truncate()
f.write(contents.decode("utf8"))
@staticmethod
def write_lines(lines, path):
if isPython3:
with open(path, mode="wt", encoding="utf-8") as f:
f.writelines([l + "\n" for l in lines])
else:
with io.open(path, mode="wt") as f:
for line in lines:
f.writelines(line.decode("utf8") + "\n")
@staticmethod
def add_content(contents, path):
if isPython3:
with open(path, mode="a", encoding="utf-8") as f:
f.writelines(contents)
else:
with io.open(path, mode="a") as f:
f.writelines(contents.decode("utf8"))
<|fim▁end|> | read_beginning |
<|file_name|>scribe.py<|end_file_name|><|fim▁begin|>import io
import sys
isPython3 = sys.version_info >= (3, 0)
class Scribe:
@staticmethod
def read(path):
with io.open(path, mode="rt", encoding="utf-8") as f:
s = f.read()
# go to beginning
f.seek(0)
return s
@staticmethod
def read_beginning(path, lines):
with io.open(path, mode="rt", encoding="utf-8") as f:
s = f.read(lines)
# go to beginning
f.seek(0)
return s
@staticmethod
def <|fim_middle|>(path):
with io.open(path, mode="rt", encoding="utf-8") as f:
content = f.readlines()
return content
@staticmethod
def write(contents, path):
if isPython3:
with open(path, mode="wt", encoding="utf-8") as f:
# truncate previous contents
f.truncate()
f.write(contents)
else:
with io.open(path, mode="wt", encoding="utf-8") as f:
# truncate previous contents
f.truncate()
f.write(contents.decode("utf8"))
@staticmethod
def write_lines(lines, path):
if isPython3:
with open(path, mode="wt", encoding="utf-8") as f:
f.writelines([l + "\n" for l in lines])
else:
with io.open(path, mode="wt") as f:
for line in lines:
f.writelines(line.decode("utf8") + "\n")
@staticmethod
def add_content(contents, path):
if isPython3:
with open(path, mode="a", encoding="utf-8") as f:
f.writelines(contents)
else:
with io.open(path, mode="a") as f:
f.writelines(contents.decode("utf8"))
<|fim▁end|> | read_lines |
<|file_name|>scribe.py<|end_file_name|><|fim▁begin|>import io
import sys
isPython3 = sys.version_info >= (3, 0)
class Scribe:
@staticmethod
def read(path):
with io.open(path, mode="rt", encoding="utf-8") as f:
s = f.read()
# go to beginning
f.seek(0)
return s
@staticmethod
def read_beginning(path, lines):
with io.open(path, mode="rt", encoding="utf-8") as f:
s = f.read(lines)
# go to beginning
f.seek(0)
return s
@staticmethod
def read_lines(path):
with io.open(path, mode="rt", encoding="utf-8") as f:
content = f.readlines()
return content
@staticmethod
def <|fim_middle|>(contents, path):
if isPython3:
with open(path, mode="wt", encoding="utf-8") as f:
# truncate previous contents
f.truncate()
f.write(contents)
else:
with io.open(path, mode="wt", encoding="utf-8") as f:
# truncate previous contents
f.truncate()
f.write(contents.decode("utf8"))
@staticmethod
def write_lines(lines, path):
if isPython3:
with open(path, mode="wt", encoding="utf-8") as f:
f.writelines([l + "\n" for l in lines])
else:
with io.open(path, mode="wt") as f:
for line in lines:
f.writelines(line.decode("utf8") + "\n")
@staticmethod
def add_content(contents, path):
if isPython3:
with open(path, mode="a", encoding="utf-8") as f:
f.writelines(contents)
else:
with io.open(path, mode="a") as f:
f.writelines(contents.decode("utf8"))
<|fim▁end|> | write |
<|file_name|>scribe.py<|end_file_name|><|fim▁begin|>import io
import sys
isPython3 = sys.version_info >= (3, 0)
class Scribe:
@staticmethod
def read(path):
with io.open(path, mode="rt", encoding="utf-8") as f:
s = f.read()
# go to beginning
f.seek(0)
return s
@staticmethod
def read_beginning(path, lines):
with io.open(path, mode="rt", encoding="utf-8") as f:
s = f.read(lines)
# go to beginning
f.seek(0)
return s
@staticmethod
def read_lines(path):
with io.open(path, mode="rt", encoding="utf-8") as f:
content = f.readlines()
return content
@staticmethod
def write(contents, path):
if isPython3:
with open(path, mode="wt", encoding="utf-8") as f:
# truncate previous contents
f.truncate()
f.write(contents)
else:
with io.open(path, mode="wt", encoding="utf-8") as f:
# truncate previous contents
f.truncate()
f.write(contents.decode("utf8"))
@staticmethod
def <|fim_middle|>(lines, path):
if isPython3:
with open(path, mode="wt", encoding="utf-8") as f:
f.writelines([l + "\n" for l in lines])
else:
with io.open(path, mode="wt") as f:
for line in lines:
f.writelines(line.decode("utf8") + "\n")
@staticmethod
def add_content(contents, path):
if isPython3:
with open(path, mode="a", encoding="utf-8") as f:
f.writelines(contents)
else:
with io.open(path, mode="a") as f:
f.writelines(contents.decode("utf8"))
<|fim▁end|> | write_lines |
<|file_name|>scribe.py<|end_file_name|><|fim▁begin|>import io
import sys
isPython3 = sys.version_info >= (3, 0)
class Scribe:
@staticmethod
def read(path):
with io.open(path, mode="rt", encoding="utf-8") as f:
s = f.read()
# go to beginning
f.seek(0)
return s
@staticmethod
def read_beginning(path, lines):
with io.open(path, mode="rt", encoding="utf-8") as f:
s = f.read(lines)
# go to beginning
f.seek(0)
return s
@staticmethod
def read_lines(path):
with io.open(path, mode="rt", encoding="utf-8") as f:
content = f.readlines()
return content
@staticmethod
def write(contents, path):
if isPython3:
with open(path, mode="wt", encoding="utf-8") as f:
# truncate previous contents
f.truncate()
f.write(contents)
else:
with io.open(path, mode="wt", encoding="utf-8") as f:
# truncate previous contents
f.truncate()
f.write(contents.decode("utf8"))
@staticmethod
def write_lines(lines, path):
if isPython3:
with open(path, mode="wt", encoding="utf-8") as f:
f.writelines([l + "\n" for l in lines])
else:
with io.open(path, mode="wt") as f:
for line in lines:
f.writelines(line.decode("utf8") + "\n")
@staticmethod
def <|fim_middle|>(contents, path):
if isPython3:
with open(path, mode="a", encoding="utf-8") as f:
f.writelines(contents)
else:
with io.open(path, mode="a") as f:
f.writelines(contents.decode("utf8"))
<|fim▁end|> | add_content |
<|file_name|>list_property.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
"""
InaSAFE Disaster risk assessment tool developed by AusAid -
**metadata module.**
Contact : [email protected]
.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
__author__ = '[email protected]'
__revision__ = '$Format:%H$'
__date__ = '10/12/15'
__copyright__ = ('Copyright 2012, Australia Indonesia Facility for '
'Disaster Reduction')
import json
from types import NoneType
from safe.common.exceptions import MetadataCastError
from safe.metadata.property import BaseProperty
<|fim▁hole|>
# if you edit this you need to adapt accordingly xml_value and is_valid
_allowed_python_types = [list, NoneType]
def __init__(self, name, value, xml_path):
super(ListProperty, self).__init__(
name, value, xml_path, self._allowed_python_types)
@classmethod
def is_valid(cls, value):
return True
def cast_from_str(self, value):
try:
return json.loads(value)
except ValueError as e:
raise MetadataCastError(e)
@property
def xml_value(self):
if self.python_type is list:
return json.dumps(self.value)
elif self.python_type is NoneType:
return ''
else:
raise RuntimeError('self._allowed_python_types and self.xml_value'
'are out of sync. This should never happen')<|fim▁end|> |
class ListProperty(BaseProperty):
"""A property that accepts list input.""" |
<|file_name|>list_property.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
"""
InaSAFE Disaster risk assessment tool developed by AusAid -
**metadata module.**
Contact : [email protected]
.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
__author__ = '[email protected]'
__revision__ = '$Format:%H$'
__date__ = '10/12/15'
__copyright__ = ('Copyright 2012, Australia Indonesia Facility for '
'Disaster Reduction')
import json
from types import NoneType
from safe.common.exceptions import MetadataCastError
from safe.metadata.property import BaseProperty
class ListProperty(BaseProperty):
<|fim_middle|>
<|fim▁end|> | """A property that accepts list input."""
# if you edit this you need to adapt accordingly xml_value and is_valid
_allowed_python_types = [list, NoneType]
def __init__(self, name, value, xml_path):
super(ListProperty, self).__init__(
name, value, xml_path, self._allowed_python_types)
@classmethod
def is_valid(cls, value):
return True
def cast_from_str(self, value):
try:
return json.loads(value)
except ValueError as e:
raise MetadataCastError(e)
@property
def xml_value(self):
if self.python_type is list:
return json.dumps(self.value)
elif self.python_type is NoneType:
return ''
else:
raise RuntimeError('self._allowed_python_types and self.xml_value'
'are out of sync. This should never happen') |
<|file_name|>list_property.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
"""
InaSAFE Disaster risk assessment tool developed by AusAid -
**metadata module.**
Contact : [email protected]
.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
__author__ = '[email protected]'
__revision__ = '$Format:%H$'
__date__ = '10/12/15'
__copyright__ = ('Copyright 2012, Australia Indonesia Facility for '
'Disaster Reduction')
import json
from types import NoneType
from safe.common.exceptions import MetadataCastError
from safe.metadata.property import BaseProperty
class ListProperty(BaseProperty):
"""A property that accepts list input."""
# if you edit this you need to adapt accordingly xml_value and is_valid
_allowed_python_types = [list, NoneType]
def __init__(self, name, value, xml_path):
<|fim_middle|>
@classmethod
def is_valid(cls, value):
return True
def cast_from_str(self, value):
try:
return json.loads(value)
except ValueError as e:
raise MetadataCastError(e)
@property
def xml_value(self):
if self.python_type is list:
return json.dumps(self.value)
elif self.python_type is NoneType:
return ''
else:
raise RuntimeError('self._allowed_python_types and self.xml_value'
'are out of sync. This should never happen')
<|fim▁end|> | super(ListProperty, self).__init__(
name, value, xml_path, self._allowed_python_types) |
<|file_name|>list_property.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
"""
InaSAFE Disaster risk assessment tool developed by AusAid -
**metadata module.**
Contact : [email protected]
.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
__author__ = '[email protected]'
__revision__ = '$Format:%H$'
__date__ = '10/12/15'
__copyright__ = ('Copyright 2012, Australia Indonesia Facility for '
'Disaster Reduction')
import json
from types import NoneType
from safe.common.exceptions import MetadataCastError
from safe.metadata.property import BaseProperty
class ListProperty(BaseProperty):
"""A property that accepts list input."""
# if you edit this you need to adapt accordingly xml_value and is_valid
_allowed_python_types = [list, NoneType]
def __init__(self, name, value, xml_path):
super(ListProperty, self).__init__(
name, value, xml_path, self._allowed_python_types)
@classmethod
def is_valid(cls, value):
<|fim_middle|>
def cast_from_str(self, value):
try:
return json.loads(value)
except ValueError as e:
raise MetadataCastError(e)
@property
def xml_value(self):
if self.python_type is list:
return json.dumps(self.value)
elif self.python_type is NoneType:
return ''
else:
raise RuntimeError('self._allowed_python_types and self.xml_value'
'are out of sync. This should never happen')
<|fim▁end|> | return True |
<|file_name|>list_property.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
"""
InaSAFE Disaster risk assessment tool developed by AusAid -
**metadata module.**
Contact : [email protected]
.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
__author__ = '[email protected]'
__revision__ = '$Format:%H$'
__date__ = '10/12/15'
__copyright__ = ('Copyright 2012, Australia Indonesia Facility for '
'Disaster Reduction')
import json
from types import NoneType
from safe.common.exceptions import MetadataCastError
from safe.metadata.property import BaseProperty
class ListProperty(BaseProperty):
"""A property that accepts list input."""
# if you edit this you need to adapt accordingly xml_value and is_valid
_allowed_python_types = [list, NoneType]
def __init__(self, name, value, xml_path):
super(ListProperty, self).__init__(
name, value, xml_path, self._allowed_python_types)
@classmethod
def is_valid(cls, value):
return True
def cast_from_str(self, value):
<|fim_middle|>
@property
def xml_value(self):
if self.python_type is list:
return json.dumps(self.value)
elif self.python_type is NoneType:
return ''
else:
raise RuntimeError('self._allowed_python_types and self.xml_value'
'are out of sync. This should never happen')
<|fim▁end|> | try:
return json.loads(value)
except ValueError as e:
raise MetadataCastError(e) |
<|file_name|>list_property.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
"""
InaSAFE Disaster risk assessment tool developed by AusAid -
**metadata module.**
Contact : [email protected]
.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
__author__ = '[email protected]'
__revision__ = '$Format:%H$'
__date__ = '10/12/15'
__copyright__ = ('Copyright 2012, Australia Indonesia Facility for '
'Disaster Reduction')
import json
from types import NoneType
from safe.common.exceptions import MetadataCastError
from safe.metadata.property import BaseProperty
class ListProperty(BaseProperty):
"""A property that accepts list input."""
# if you edit this you need to adapt accordingly xml_value and is_valid
_allowed_python_types = [list, NoneType]
def __init__(self, name, value, xml_path):
super(ListProperty, self).__init__(
name, value, xml_path, self._allowed_python_types)
@classmethod
def is_valid(cls, value):
return True
def cast_from_str(self, value):
try:
return json.loads(value)
except ValueError as e:
raise MetadataCastError(e)
@property
def xml_value(self):
<|fim_middle|>
<|fim▁end|> | if self.python_type is list:
return json.dumps(self.value)
elif self.python_type is NoneType:
return ''
else:
raise RuntimeError('self._allowed_python_types and self.xml_value'
'are out of sync. This should never happen') |
<|file_name|>list_property.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
"""
InaSAFE Disaster risk assessment tool developed by AusAid -
**metadata module.**
Contact : [email protected]
.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
__author__ = '[email protected]'
__revision__ = '$Format:%H$'
__date__ = '10/12/15'
__copyright__ = ('Copyright 2012, Australia Indonesia Facility for '
'Disaster Reduction')
import json
from types import NoneType
from safe.common.exceptions import MetadataCastError
from safe.metadata.property import BaseProperty
class ListProperty(BaseProperty):
"""A property that accepts list input."""
# if you edit this you need to adapt accordingly xml_value and is_valid
_allowed_python_types = [list, NoneType]
def __init__(self, name, value, xml_path):
super(ListProperty, self).__init__(
name, value, xml_path, self._allowed_python_types)
@classmethod
def is_valid(cls, value):
return True
def cast_from_str(self, value):
try:
return json.loads(value)
except ValueError as e:
raise MetadataCastError(e)
@property
def xml_value(self):
if self.python_type is list:
<|fim_middle|>
elif self.python_type is NoneType:
return ''
else:
raise RuntimeError('self._allowed_python_types and self.xml_value'
'are out of sync. This should never happen')
<|fim▁end|> | return json.dumps(self.value) |
<|file_name|>list_property.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
"""
InaSAFE Disaster risk assessment tool developed by AusAid -
**metadata module.**
Contact : [email protected]
.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
__author__ = '[email protected]'
__revision__ = '$Format:%H$'
__date__ = '10/12/15'
__copyright__ = ('Copyright 2012, Australia Indonesia Facility for '
'Disaster Reduction')
import json
from types import NoneType
from safe.common.exceptions import MetadataCastError
from safe.metadata.property import BaseProperty
class ListProperty(BaseProperty):
"""A property that accepts list input."""
# if you edit this you need to adapt accordingly xml_value and is_valid
_allowed_python_types = [list, NoneType]
def __init__(self, name, value, xml_path):
super(ListProperty, self).__init__(
name, value, xml_path, self._allowed_python_types)
@classmethod
def is_valid(cls, value):
return True
def cast_from_str(self, value):
try:
return json.loads(value)
except ValueError as e:
raise MetadataCastError(e)
@property
def xml_value(self):
if self.python_type is list:
return json.dumps(self.value)
elif self.python_type is NoneType:
<|fim_middle|>
else:
raise RuntimeError('self._allowed_python_types and self.xml_value'
'are out of sync. This should never happen')
<|fim▁end|> | return '' |
<|file_name|>list_property.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
"""
InaSAFE Disaster risk assessment tool developed by AusAid -
**metadata module.**
Contact : [email protected]
.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
__author__ = '[email protected]'
__revision__ = '$Format:%H$'
__date__ = '10/12/15'
__copyright__ = ('Copyright 2012, Australia Indonesia Facility for '
'Disaster Reduction')
import json
from types import NoneType
from safe.common.exceptions import MetadataCastError
from safe.metadata.property import BaseProperty
class ListProperty(BaseProperty):
"""A property that accepts list input."""
# if you edit this you need to adapt accordingly xml_value and is_valid
_allowed_python_types = [list, NoneType]
def __init__(self, name, value, xml_path):
super(ListProperty, self).__init__(
name, value, xml_path, self._allowed_python_types)
@classmethod
def is_valid(cls, value):
return True
def cast_from_str(self, value):
try:
return json.loads(value)
except ValueError as e:
raise MetadataCastError(e)
@property
def xml_value(self):
if self.python_type is list:
return json.dumps(self.value)
elif self.python_type is NoneType:
return ''
else:
<|fim_middle|>
<|fim▁end|> | raise RuntimeError('self._allowed_python_types and self.xml_value'
'are out of sync. This should never happen') |
<|file_name|>list_property.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
"""
InaSAFE Disaster risk assessment tool developed by AusAid -
**metadata module.**
Contact : [email protected]
.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
__author__ = '[email protected]'
__revision__ = '$Format:%H$'
__date__ = '10/12/15'
__copyright__ = ('Copyright 2012, Australia Indonesia Facility for '
'Disaster Reduction')
import json
from types import NoneType
from safe.common.exceptions import MetadataCastError
from safe.metadata.property import BaseProperty
class ListProperty(BaseProperty):
"""A property that accepts list input."""
# if you edit this you need to adapt accordingly xml_value and is_valid
_allowed_python_types = [list, NoneType]
def <|fim_middle|>(self, name, value, xml_path):
super(ListProperty, self).__init__(
name, value, xml_path, self._allowed_python_types)
@classmethod
def is_valid(cls, value):
return True
def cast_from_str(self, value):
try:
return json.loads(value)
except ValueError as e:
raise MetadataCastError(e)
@property
def xml_value(self):
if self.python_type is list:
return json.dumps(self.value)
elif self.python_type is NoneType:
return ''
else:
raise RuntimeError('self._allowed_python_types and self.xml_value'
'are out of sync. This should never happen')
<|fim▁end|> | __init__ |
<|file_name|>list_property.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
"""
InaSAFE Disaster risk assessment tool developed by AusAid -
**metadata module.**
Contact : [email protected]
.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
__author__ = '[email protected]'
__revision__ = '$Format:%H$'
__date__ = '10/12/15'
__copyright__ = ('Copyright 2012, Australia Indonesia Facility for '
'Disaster Reduction')
import json
from types import NoneType
from safe.common.exceptions import MetadataCastError
from safe.metadata.property import BaseProperty
class ListProperty(BaseProperty):
"""A property that accepts list input."""
# if you edit this you need to adapt accordingly xml_value and is_valid
_allowed_python_types = [list, NoneType]
def __init__(self, name, value, xml_path):
super(ListProperty, self).__init__(
name, value, xml_path, self._allowed_python_types)
@classmethod
def <|fim_middle|>(cls, value):
return True
def cast_from_str(self, value):
try:
return json.loads(value)
except ValueError as e:
raise MetadataCastError(e)
@property
def xml_value(self):
if self.python_type is list:
return json.dumps(self.value)
elif self.python_type is NoneType:
return ''
else:
raise RuntimeError('self._allowed_python_types and self.xml_value'
'are out of sync. This should never happen')
<|fim▁end|> | is_valid |
<|file_name|>list_property.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
"""
InaSAFE Disaster risk assessment tool developed by AusAid -
**metadata module.**
Contact : [email protected]
.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
__author__ = '[email protected]'
__revision__ = '$Format:%H$'
__date__ = '10/12/15'
__copyright__ = ('Copyright 2012, Australia Indonesia Facility for '
'Disaster Reduction')
import json
from types import NoneType
from safe.common.exceptions import MetadataCastError
from safe.metadata.property import BaseProperty
class ListProperty(BaseProperty):
"""A property that accepts list input."""
# if you edit this you need to adapt accordingly xml_value and is_valid
_allowed_python_types = [list, NoneType]
def __init__(self, name, value, xml_path):
super(ListProperty, self).__init__(
name, value, xml_path, self._allowed_python_types)
@classmethod
def is_valid(cls, value):
return True
def <|fim_middle|>(self, value):
try:
return json.loads(value)
except ValueError as e:
raise MetadataCastError(e)
@property
def xml_value(self):
if self.python_type is list:
return json.dumps(self.value)
elif self.python_type is NoneType:
return ''
else:
raise RuntimeError('self._allowed_python_types and self.xml_value'
'are out of sync. This should never happen')
<|fim▁end|> | cast_from_str |
<|file_name|>list_property.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
"""
InaSAFE Disaster risk assessment tool developed by AusAid -
**metadata module.**
Contact : [email protected]
.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
__author__ = '[email protected]'
__revision__ = '$Format:%H$'
__date__ = '10/12/15'
__copyright__ = ('Copyright 2012, Australia Indonesia Facility for '
'Disaster Reduction')
import json
from types import NoneType
from safe.common.exceptions import MetadataCastError
from safe.metadata.property import BaseProperty
class ListProperty(BaseProperty):
"""A property that accepts list input."""
# if you edit this you need to adapt accordingly xml_value and is_valid
_allowed_python_types = [list, NoneType]
def __init__(self, name, value, xml_path):
super(ListProperty, self).__init__(
name, value, xml_path, self._allowed_python_types)
@classmethod
def is_valid(cls, value):
return True
def cast_from_str(self, value):
try:
return json.loads(value)
except ValueError as e:
raise MetadataCastError(e)
@property
def <|fim_middle|>(self):
if self.python_type is list:
return json.dumps(self.value)
elif self.python_type is NoneType:
return ''
else:
raise RuntimeError('self._allowed_python_types and self.xml_value'
'are out of sync. This should never happen')
<|fim▁end|> | xml_value |
<|file_name|>AvailabilityNodes.py<|end_file_name|><|fim▁begin|>from Child import Child
from Node import Node # noqa: I201
AVAILABILITY_NODES = [
# availability-spec-list -> availability-entry availability-spec-list?
Node('AvailabilitySpecList', kind='SyntaxCollection',
element='AvailabilityArgument'),
# Wrapper for all the different entries that may occur inside @available
# availability-entry -> '*' ','?
# | identifier ','?
# | availability-version-restriction ','?
# | availability-versioned-argument ','?
Node('AvailabilityArgument', kind='Syntax',
description='''
A single argument to an `@available` argument like `*`, `iOS 10.1`, \
or `message: "This has been deprecated"`.
''',<|fim▁hole|> Child('Star', kind='SpacedBinaryOperatorToken',
text_choices=['*']),
Child('IdentifierRestriction',
kind='IdentifierToken'),
Child('AvailabilityVersionRestriction',
kind='AvailabilityVersionRestriction'),
Child('AvailabilityLabeledArgument',
kind='AvailabilityLabeledArgument'),
]),
Child('TrailingComma', kind='CommaToken', is_optional=True,
description='''
A trailing comma if the argument is followed by another \
argument
'''),
]),
# Representation of 'deprecated: 2.3', 'message: "Hello world"' etc.
# availability-versioned-argument -> identifier ':' version-tuple
Node('AvailabilityLabeledArgument', kind='Syntax',
description='''
A argument to an `@available` attribute that consists of a label and \
a value, e.g. `message: "This has been deprecated"`.
''',
children=[
Child('Label', kind='IdentifierToken',
description='The label of the argument'),
Child('Colon', kind='ColonToken',
description='The colon separating label and value'),
Child('Value', kind='Syntax',
node_choices=[
Child('String', 'StringLiteralToken'),
Child('Version', 'VersionTuple'),
], description='The value of this labeled argument',),
]),
# Representation for 'iOS 10', 'swift 3.4' etc.
# availability-version-restriction -> identifier version-tuple
Node('AvailabilityVersionRestriction', kind='Syntax',
description='''
An argument to `@available` that restricts the availability on a \
certain platform to a version, e.g. `iOS 10` or `swift 3.4`.
''',
children=[
Child('Platform', kind='IdentifierToken',
classification='Keyword',
description='''
The name of the OS on which the availability should be \
restricted or 'swift' if the availability should be \
restricted based on a Swift version.
'''),
Child('Version', kind='VersionTuple'),
]),
# version-tuple -> integer-literal
# | float-literal
# | float-literal '.' integer-literal
Node('VersionTuple', kind='Syntax',
description='''
A version number of the form major.minor.patch in which the minor \
and patch part may be ommited.
''',
children=[
Child('MajorMinor', kind='Syntax',
node_choices=[
Child('Major', kind='IntegerLiteralToken'),
Child('MajorMinor', kind='FloatingLiteralToken')
], description='''
In case the version consists only of the major version, an \
integer literal that specifies the major version. In case \
the version consists of major and minor version number, a \
floating literal in which the decimal part is interpreted \
as the minor version.
'''),
Child('PatchPeriod', kind='PeriodToken', is_optional=True,
description='''
If the version contains a patch number, the period \
separating the minor from the patch number.
'''),
Child('PatchVersion', kind='IntegerLiteralToken',
is_optional=True, description='''
The patch version if specified.
'''),
]),
]<|fim▁end|> | children=[
Child('Entry', kind='Syntax',
description='The actual argument',
node_choices=[ |
<|file_name|>type_extras.py<|end_file_name|><|fim▁begin|>from collections.abc import Iterable
from django import template
from django.db.models import Model
register = template.Library()
<|fim▁hole|> return type(value)
@register.filter
def is_model(value):
return isinstance(value, Model)
@register.filter
def is_iterable(value):
return isinstance(value, Iterable)
@register.filter
def is_str(value):
return isinstance(value, str)
@register.filter
def is_bool(value):
return isinstance(value, bool)<|fim▁end|> |
@register.filter
def get_type(value):
# inspired by: https://stackoverflow.com/a/12028864 |
<|file_name|>type_extras.py<|end_file_name|><|fim▁begin|>from collections.abc import Iterable
from django import template
from django.db.models import Model
register = template.Library()
@register.filter
def get_type(value):
# inspired by: https://stackoverflow.com/a/12028864
<|fim_middle|>
@register.filter
def is_model(value):
return isinstance(value, Model)
@register.filter
def is_iterable(value):
return isinstance(value, Iterable)
@register.filter
def is_str(value):
return isinstance(value, str)
@register.filter
def is_bool(value):
return isinstance(value, bool)
<|fim▁end|> | return type(value) |
<|file_name|>type_extras.py<|end_file_name|><|fim▁begin|>from collections.abc import Iterable
from django import template
from django.db.models import Model
register = template.Library()
@register.filter
def get_type(value):
# inspired by: https://stackoverflow.com/a/12028864
return type(value)
@register.filter
def is_model(value):
<|fim_middle|>
@register.filter
def is_iterable(value):
return isinstance(value, Iterable)
@register.filter
def is_str(value):
return isinstance(value, str)
@register.filter
def is_bool(value):
return isinstance(value, bool)
<|fim▁end|> | return isinstance(value, Model) |
<|file_name|>type_extras.py<|end_file_name|><|fim▁begin|>from collections.abc import Iterable
from django import template
from django.db.models import Model
register = template.Library()
@register.filter
def get_type(value):
# inspired by: https://stackoverflow.com/a/12028864
return type(value)
@register.filter
def is_model(value):
return isinstance(value, Model)
@register.filter
def is_iterable(value):
<|fim_middle|>
@register.filter
def is_str(value):
return isinstance(value, str)
@register.filter
def is_bool(value):
return isinstance(value, bool)
<|fim▁end|> | return isinstance(value, Iterable) |
<|file_name|>type_extras.py<|end_file_name|><|fim▁begin|>from collections.abc import Iterable
from django import template
from django.db.models import Model
register = template.Library()
@register.filter
def get_type(value):
# inspired by: https://stackoverflow.com/a/12028864
return type(value)
@register.filter
def is_model(value):
return isinstance(value, Model)
@register.filter
def is_iterable(value):
return isinstance(value, Iterable)
@register.filter
def is_str(value):
<|fim_middle|>
@register.filter
def is_bool(value):
return isinstance(value, bool)
<|fim▁end|> | return isinstance(value, str) |
<|file_name|>type_extras.py<|end_file_name|><|fim▁begin|>from collections.abc import Iterable
from django import template
from django.db.models import Model
register = template.Library()
@register.filter
def get_type(value):
# inspired by: https://stackoverflow.com/a/12028864
return type(value)
@register.filter
def is_model(value):
return isinstance(value, Model)
@register.filter
def is_iterable(value):
return isinstance(value, Iterable)
@register.filter
def is_str(value):
return isinstance(value, str)
@register.filter
def is_bool(value):
<|fim_middle|>
<|fim▁end|> | return isinstance(value, bool) |
<|file_name|>type_extras.py<|end_file_name|><|fim▁begin|>from collections.abc import Iterable
from django import template
from django.db.models import Model
register = template.Library()
@register.filter
def <|fim_middle|>(value):
# inspired by: https://stackoverflow.com/a/12028864
return type(value)
@register.filter
def is_model(value):
return isinstance(value, Model)
@register.filter
def is_iterable(value):
return isinstance(value, Iterable)
@register.filter
def is_str(value):
return isinstance(value, str)
@register.filter
def is_bool(value):
return isinstance(value, bool)
<|fim▁end|> | get_type |
<|file_name|>type_extras.py<|end_file_name|><|fim▁begin|>from collections.abc import Iterable
from django import template
from django.db.models import Model
register = template.Library()
@register.filter
def get_type(value):
# inspired by: https://stackoverflow.com/a/12028864
return type(value)
@register.filter
def <|fim_middle|>(value):
return isinstance(value, Model)
@register.filter
def is_iterable(value):
return isinstance(value, Iterable)
@register.filter
def is_str(value):
return isinstance(value, str)
@register.filter
def is_bool(value):
return isinstance(value, bool)
<|fim▁end|> | is_model |
<|file_name|>type_extras.py<|end_file_name|><|fim▁begin|>from collections.abc import Iterable
from django import template
from django.db.models import Model
register = template.Library()
@register.filter
def get_type(value):
# inspired by: https://stackoverflow.com/a/12028864
return type(value)
@register.filter
def is_model(value):
return isinstance(value, Model)
@register.filter
def <|fim_middle|>(value):
return isinstance(value, Iterable)
@register.filter
def is_str(value):
return isinstance(value, str)
@register.filter
def is_bool(value):
return isinstance(value, bool)
<|fim▁end|> | is_iterable |
<|file_name|>type_extras.py<|end_file_name|><|fim▁begin|>from collections.abc import Iterable
from django import template
from django.db.models import Model
register = template.Library()
@register.filter
def get_type(value):
# inspired by: https://stackoverflow.com/a/12028864
return type(value)
@register.filter
def is_model(value):
return isinstance(value, Model)
@register.filter
def is_iterable(value):
return isinstance(value, Iterable)
@register.filter
def <|fim_middle|>(value):
return isinstance(value, str)
@register.filter
def is_bool(value):
return isinstance(value, bool)
<|fim▁end|> | is_str |
<|file_name|>type_extras.py<|end_file_name|><|fim▁begin|>from collections.abc import Iterable
from django import template
from django.db.models import Model
register = template.Library()
@register.filter
def get_type(value):
# inspired by: https://stackoverflow.com/a/12028864
return type(value)
@register.filter
def is_model(value):
return isinstance(value, Model)
@register.filter
def is_iterable(value):
return isinstance(value, Iterable)
@register.filter
def is_str(value):
return isinstance(value, str)
@register.filter
def <|fim_middle|>(value):
return isinstance(value, bool)
<|fim▁end|> | is_bool |
<|file_name|>data_import.py<|end_file_name|><|fim▁begin|># ~*~ encoding: utf-8 ~*~
from pymongo import MongoClient
from pandas import read_csv
from datetime import date
mongodb = MongoClient('192.168.178.82', 9999)<|fim▁hole|>db = mongodb['dev']
drug_collection = db['drug']
drugs = read_csv('~/Dokumente/bfarm_lieferenpass_meldung.csv', delimiter=';', encoding='iso8859_2').to_dict()
drugs.pop('Id', None)
drugs.pop('aktuelle Bescheidart', None)
drugs.pop('Meldungsart', None)
drugs.pop('aktuelle Bescheidart', None)
data = dict()
for x in range(drugs['Verkehrsfähig'].__len__()):
"""
if drugs['Ende Engpass'][x] == '-':
data['end'] = None
else:
day, month, year = drugs['Ende Engpass'][x].split('.')
data['end'] = date(int(year), int(month), int(day)).__str__()
if drugs['Beginn Engpass'][x] == '-':
data['initial_report'] = None
else:
day, month, year = drugs['Beginn Engpass'][x].split('.')
data['initial_report'] = date(int(year), int(month), int(day)).__str__()
if drugs['Datum der letzten Meldung'][x] == '-':
data['last_report'] = None
else:
day, month, year = drugs['Datum der letzten Meldung'][x].split('.')
data['last_report'] = date(int(year), int(month), int(day)).__str__()
"""
data['substance'] = drugs['Wirkstoffe'][x].replace(' ', '').split(';')
data['enr'] = int(drugs['Enr'][x])
data['marketability'] = True if drugs['Verkehrsfähig'][x] == 'ja' else False
data['atc_code'] = drugs['ATC-Code'][x]
data['pzn'] = int(drugs['PZN'][x].split(' ')[0].replace(';', '')) if drugs['PZN'][x] != '-' else None
data['drug_title'] = drugs['Arzneimittelbezeichnung'][x]
data['hospital'] = True if drugs['Krankenhausrelevant'][x] == 'ja' else False
drug_collection.update_one({'enr': data['enr']}, {'$set': data}, upsert=True)<|fim▁end|> | |
<|file_name|>check_query_file.py<|end_file_name|><|fim▁begin|>from django.core.management.base import BaseCommand, CommandError
from django.core import management
from django.db.models import Count
from scoping.models import *
class Command(BaseCommand):
help = 'check a query file - how many records'
def add_arguments(self, parser):
parser.add_argument('qid',type=int)
def handle(self, *args, **options):
qid = options['qid']
q = Query.objects.get(pk=qid)
p = 'TY - '
if q.query_file.name is not '':
fpath = q.query_file.path
else:
if q.database=="scopus":
fname = 's_results.txt'
else:
fname = 'results.txt'<|fim▁hole|>
print('\n{} documents in downloaded file\n'.format(c))
if q.doc_set.count() > 0:
yts = q.doc_set.values('PY').annotate(
n = Count('pk')
)
for y in yts:
print('{} documents in {}'.format(y['n'],y['PY']))<|fim▁end|> | fpath = f'{settings.QUERY_DIR}/{qid}/{fname}'
with open(fpath, 'r') as f:
c = f.read().count(p) |
<|file_name|>check_query_file.py<|end_file_name|><|fim▁begin|>from django.core.management.base import BaseCommand, CommandError
from django.core import management
from django.db.models import Count
from scoping.models import *
class Command(BaseCommand):
<|fim_middle|>
<|fim▁end|> | help = 'check a query file - how many records'
def add_arguments(self, parser):
parser.add_argument('qid',type=int)
def handle(self, *args, **options):
qid = options['qid']
q = Query.objects.get(pk=qid)
p = 'TY - '
if q.query_file.name is not '':
fpath = q.query_file.path
else:
if q.database=="scopus":
fname = 's_results.txt'
else:
fname = 'results.txt'
fpath = f'{settings.QUERY_DIR}/{qid}/{fname}'
with open(fpath, 'r') as f:
c = f.read().count(p)
print('\n{} documents in downloaded file\n'.format(c))
if q.doc_set.count() > 0:
yts = q.doc_set.values('PY').annotate(
n = Count('pk')
)
for y in yts:
print('{} documents in {}'.format(y['n'],y['PY'])) |
<|file_name|>check_query_file.py<|end_file_name|><|fim▁begin|>from django.core.management.base import BaseCommand, CommandError
from django.core import management
from django.db.models import Count
from scoping.models import *
class Command(BaseCommand):
help = 'check a query file - how many records'
def add_arguments(self, parser):
<|fim_middle|>
def handle(self, *args, **options):
qid = options['qid']
q = Query.objects.get(pk=qid)
p = 'TY - '
if q.query_file.name is not '':
fpath = q.query_file.path
else:
if q.database=="scopus":
fname = 's_results.txt'
else:
fname = 'results.txt'
fpath = f'{settings.QUERY_DIR}/{qid}/{fname}'
with open(fpath, 'r') as f:
c = f.read().count(p)
print('\n{} documents in downloaded file\n'.format(c))
if q.doc_set.count() > 0:
yts = q.doc_set.values('PY').annotate(
n = Count('pk')
)
for y in yts:
print('{} documents in {}'.format(y['n'],y['PY']))
<|fim▁end|> | parser.add_argument('qid',type=int) |
<|file_name|>check_query_file.py<|end_file_name|><|fim▁begin|>from django.core.management.base import BaseCommand, CommandError
from django.core import management
from django.db.models import Count
from scoping.models import *
class Command(BaseCommand):
help = 'check a query file - how many records'
def add_arguments(self, parser):
parser.add_argument('qid',type=int)
def handle(self, *args, **options):
<|fim_middle|>
<|fim▁end|> | qid = options['qid']
q = Query.objects.get(pk=qid)
p = 'TY - '
if q.query_file.name is not '':
fpath = q.query_file.path
else:
if q.database=="scopus":
fname = 's_results.txt'
else:
fname = 'results.txt'
fpath = f'{settings.QUERY_DIR}/{qid}/{fname}'
with open(fpath, 'r') as f:
c = f.read().count(p)
print('\n{} documents in downloaded file\n'.format(c))
if q.doc_set.count() > 0:
yts = q.doc_set.values('PY').annotate(
n = Count('pk')
)
for y in yts:
print('{} documents in {}'.format(y['n'],y['PY'])) |
<|file_name|>check_query_file.py<|end_file_name|><|fim▁begin|>from django.core.management.base import BaseCommand, CommandError
from django.core import management
from django.db.models import Count
from scoping.models import *
class Command(BaseCommand):
help = 'check a query file - how many records'
def add_arguments(self, parser):
parser.add_argument('qid',type=int)
def handle(self, *args, **options):
qid = options['qid']
q = Query.objects.get(pk=qid)
p = 'TY - '
if q.query_file.name is not '':
<|fim_middle|>
else:
if q.database=="scopus":
fname = 's_results.txt'
else:
fname = 'results.txt'
fpath = f'{settings.QUERY_DIR}/{qid}/{fname}'
with open(fpath, 'r') as f:
c = f.read().count(p)
print('\n{} documents in downloaded file\n'.format(c))
if q.doc_set.count() > 0:
yts = q.doc_set.values('PY').annotate(
n = Count('pk')
)
for y in yts:
print('{} documents in {}'.format(y['n'],y['PY']))
<|fim▁end|> | fpath = q.query_file.path |
<|file_name|>check_query_file.py<|end_file_name|><|fim▁begin|>from django.core.management.base import BaseCommand, CommandError
from django.core import management
from django.db.models import Count
from scoping.models import *
class Command(BaseCommand):
help = 'check a query file - how many records'
def add_arguments(self, parser):
parser.add_argument('qid',type=int)
def handle(self, *args, **options):
qid = options['qid']
q = Query.objects.get(pk=qid)
p = 'TY - '
if q.query_file.name is not '':
fpath = q.query_file.path
else:
<|fim_middle|>
print('\n{} documents in downloaded file\n'.format(c))
if q.doc_set.count() > 0:
yts = q.doc_set.values('PY').annotate(
n = Count('pk')
)
for y in yts:
print('{} documents in {}'.format(y['n'],y['PY']))
<|fim▁end|> | if q.database=="scopus":
fname = 's_results.txt'
else:
fname = 'results.txt'
fpath = f'{settings.QUERY_DIR}/{qid}/{fname}'
with open(fpath, 'r') as f:
c = f.read().count(p) |
<|file_name|>check_query_file.py<|end_file_name|><|fim▁begin|>from django.core.management.base import BaseCommand, CommandError
from django.core import management
from django.db.models import Count
from scoping.models import *
class Command(BaseCommand):
help = 'check a query file - how many records'
def add_arguments(self, parser):
parser.add_argument('qid',type=int)
def handle(self, *args, **options):
qid = options['qid']
q = Query.objects.get(pk=qid)
p = 'TY - '
if q.query_file.name is not '':
fpath = q.query_file.path
else:
if q.database=="scopus":
<|fim_middle|>
else:
fname = 'results.txt'
fpath = f'{settings.QUERY_DIR}/{qid}/{fname}'
with open(fpath, 'r') as f:
c = f.read().count(p)
print('\n{} documents in downloaded file\n'.format(c))
if q.doc_set.count() > 0:
yts = q.doc_set.values('PY').annotate(
n = Count('pk')
)
for y in yts:
print('{} documents in {}'.format(y['n'],y['PY']))
<|fim▁end|> | fname = 's_results.txt' |
<|file_name|>check_query_file.py<|end_file_name|><|fim▁begin|>from django.core.management.base import BaseCommand, CommandError
from django.core import management
from django.db.models import Count
from scoping.models import *
class Command(BaseCommand):
help = 'check a query file - how many records'
def add_arguments(self, parser):
parser.add_argument('qid',type=int)
def handle(self, *args, **options):
qid = options['qid']
q = Query.objects.get(pk=qid)
p = 'TY - '
if q.query_file.name is not '':
fpath = q.query_file.path
else:
if q.database=="scopus":
fname = 's_results.txt'
else:
<|fim_middle|>
fpath = f'{settings.QUERY_DIR}/{qid}/{fname}'
with open(fpath, 'r') as f:
c = f.read().count(p)
print('\n{} documents in downloaded file\n'.format(c))
if q.doc_set.count() > 0:
yts = q.doc_set.values('PY').annotate(
n = Count('pk')
)
for y in yts:
print('{} documents in {}'.format(y['n'],y['PY']))
<|fim▁end|> | fname = 'results.txt' |
<|file_name|>check_query_file.py<|end_file_name|><|fim▁begin|>from django.core.management.base import BaseCommand, CommandError
from django.core import management
from django.db.models import Count
from scoping.models import *
class Command(BaseCommand):
help = 'check a query file - how many records'
def add_arguments(self, parser):
parser.add_argument('qid',type=int)
def handle(self, *args, **options):
qid = options['qid']
q = Query.objects.get(pk=qid)
p = 'TY - '
if q.query_file.name is not '':
fpath = q.query_file.path
else:
if q.database=="scopus":
fname = 's_results.txt'
else:
fname = 'results.txt'
fpath = f'{settings.QUERY_DIR}/{qid}/{fname}'
with open(fpath, 'r') as f:
c = f.read().count(p)
print('\n{} documents in downloaded file\n'.format(c))
if q.doc_set.count() > 0:
<|fim_middle|>
<|fim▁end|> | yts = q.doc_set.values('PY').annotate(
n = Count('pk')
)
for y in yts:
print('{} documents in {}'.format(y['n'],y['PY'])) |
<|file_name|>check_query_file.py<|end_file_name|><|fim▁begin|>from django.core.management.base import BaseCommand, CommandError
from django.core import management
from django.db.models import Count
from scoping.models import *
class Command(BaseCommand):
help = 'check a query file - how many records'
def <|fim_middle|>(self, parser):
parser.add_argument('qid',type=int)
def handle(self, *args, **options):
qid = options['qid']
q = Query.objects.get(pk=qid)
p = 'TY - '
if q.query_file.name is not '':
fpath = q.query_file.path
else:
if q.database=="scopus":
fname = 's_results.txt'
else:
fname = 'results.txt'
fpath = f'{settings.QUERY_DIR}/{qid}/{fname}'
with open(fpath, 'r') as f:
c = f.read().count(p)
print('\n{} documents in downloaded file\n'.format(c))
if q.doc_set.count() > 0:
yts = q.doc_set.values('PY').annotate(
n = Count('pk')
)
for y in yts:
print('{} documents in {}'.format(y['n'],y['PY']))
<|fim▁end|> | add_arguments |
<|file_name|>check_query_file.py<|end_file_name|><|fim▁begin|>from django.core.management.base import BaseCommand, CommandError
from django.core import management
from django.db.models import Count
from scoping.models import *
class Command(BaseCommand):
help = 'check a query file - how many records'
def add_arguments(self, parser):
parser.add_argument('qid',type=int)
def <|fim_middle|>(self, *args, **options):
qid = options['qid']
q = Query.objects.get(pk=qid)
p = 'TY - '
if q.query_file.name is not '':
fpath = q.query_file.path
else:
if q.database=="scopus":
fname = 's_results.txt'
else:
fname = 'results.txt'
fpath = f'{settings.QUERY_DIR}/{qid}/{fname}'
with open(fpath, 'r') as f:
c = f.read().count(p)
print('\n{} documents in downloaded file\n'.format(c))
if q.doc_set.count() > 0:
yts = q.doc_set.values('PY').annotate(
n = Count('pk')
)
for y in yts:
print('{} documents in {}'.format(y['n'],y['PY']))
<|fim▁end|> | handle |
<|file_name|>test_jira_hook.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
import unittest
from mock import Mock
from mock import patch
from airflow import configuration
from airflow.contrib.hooks.jira_hook import JiraHook
from airflow import models
from airflow.utils import db
jira_client_mock = Mock(
name="jira_client"
)
class TestJiraHook(unittest.TestCase):
def setUp(self):
configuration.load_test_config()
db.merge_conn(
models.Connection(
conn_id='jira_default', conn_type='jira',
host='https://localhost/jira/', port=443,
extra='{"verify": "False", "project": "AIRFLOW"}'))
@patch("airflow.contrib.hooks.jira_hook.JIRA", autospec=True,
return_value=jira_client_mock)
def test_jira_client_connection(self, jira_mock):
jira_hook = JiraHook()
self.assertTrue(jira_mock.called)
self.assertIsInstance(jira_hook.client, Mock)
self.assertEqual(jira_hook.client.name, jira_mock.return_value.name)
<|fim▁hole|>if __name__ == '__main__':
unittest.main()<|fim▁end|> | |
<|file_name|>test_jira_hook.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
import unittest
from mock import Mock
from mock import patch
from airflow import configuration
from airflow.contrib.hooks.jira_hook import JiraHook
from airflow import models
from airflow.utils import db
jira_client_mock = Mock(
name="jira_client"
)
class TestJiraHook(unittest.TestCase):
<|fim_middle|>
if __name__ == '__main__':
unittest.main()
<|fim▁end|> | def setUp(self):
configuration.load_test_config()
db.merge_conn(
models.Connection(
conn_id='jira_default', conn_type='jira',
host='https://localhost/jira/', port=443,
extra='{"verify": "False", "project": "AIRFLOW"}'))
@patch("airflow.contrib.hooks.jira_hook.JIRA", autospec=True,
return_value=jira_client_mock)
def test_jira_client_connection(self, jira_mock):
jira_hook = JiraHook()
self.assertTrue(jira_mock.called)
self.assertIsInstance(jira_hook.client, Mock)
self.assertEqual(jira_hook.client.name, jira_mock.return_value.name) |
<|file_name|>test_jira_hook.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
import unittest
from mock import Mock
from mock import patch
from airflow import configuration
from airflow.contrib.hooks.jira_hook import JiraHook
from airflow import models
from airflow.utils import db
jira_client_mock = Mock(
name="jira_client"
)
class TestJiraHook(unittest.TestCase):
def setUp(self):
<|fim_middle|>
@patch("airflow.contrib.hooks.jira_hook.JIRA", autospec=True,
return_value=jira_client_mock)
def test_jira_client_connection(self, jira_mock):
jira_hook = JiraHook()
self.assertTrue(jira_mock.called)
self.assertIsInstance(jira_hook.client, Mock)
self.assertEqual(jira_hook.client.name, jira_mock.return_value.name)
if __name__ == '__main__':
unittest.main()
<|fim▁end|> | configuration.load_test_config()
db.merge_conn(
models.Connection(
conn_id='jira_default', conn_type='jira',
host='https://localhost/jira/', port=443,
extra='{"verify": "False", "project": "AIRFLOW"}')) |
<|file_name|>test_jira_hook.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
import unittest
from mock import Mock
from mock import patch
from airflow import configuration
from airflow.contrib.hooks.jira_hook import JiraHook
from airflow import models
from airflow.utils import db
jira_client_mock = Mock(
name="jira_client"
)
class TestJiraHook(unittest.TestCase):
def setUp(self):
configuration.load_test_config()
db.merge_conn(
models.Connection(
conn_id='jira_default', conn_type='jira',
host='https://localhost/jira/', port=443,
extra='{"verify": "False", "project": "AIRFLOW"}'))
@patch("airflow.contrib.hooks.jira_hook.JIRA", autospec=True,
return_value=jira_client_mock)
def test_jira_client_connection(self, jira_mock):
<|fim_middle|>
if __name__ == '__main__':
unittest.main()
<|fim▁end|> | jira_hook = JiraHook()
self.assertTrue(jira_mock.called)
self.assertIsInstance(jira_hook.client, Mock)
self.assertEqual(jira_hook.client.name, jira_mock.return_value.name) |
<|file_name|>test_jira_hook.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
import unittest
from mock import Mock
from mock import patch
from airflow import configuration
from airflow.contrib.hooks.jira_hook import JiraHook
from airflow import models
from airflow.utils import db
jira_client_mock = Mock(
name="jira_client"
)
class TestJiraHook(unittest.TestCase):
def setUp(self):
configuration.load_test_config()
db.merge_conn(
models.Connection(
conn_id='jira_default', conn_type='jira',
host='https://localhost/jira/', port=443,
extra='{"verify": "False", "project": "AIRFLOW"}'))
@patch("airflow.contrib.hooks.jira_hook.JIRA", autospec=True,
return_value=jira_client_mock)
def test_jira_client_connection(self, jira_mock):
jira_hook = JiraHook()
self.assertTrue(jira_mock.called)
self.assertIsInstance(jira_hook.client, Mock)
self.assertEqual(jira_hook.client.name, jira_mock.return_value.name)
if __name__ == '__main__':
<|fim_middle|>
<|fim▁end|> | unittest.main() |
<|file_name|>test_jira_hook.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
import unittest
from mock import Mock
from mock import patch
from airflow import configuration
from airflow.contrib.hooks.jira_hook import JiraHook
from airflow import models
from airflow.utils import db
jira_client_mock = Mock(
name="jira_client"
)
class TestJiraHook(unittest.TestCase):
def <|fim_middle|>(self):
configuration.load_test_config()
db.merge_conn(
models.Connection(
conn_id='jira_default', conn_type='jira',
host='https://localhost/jira/', port=443,
extra='{"verify": "False", "project": "AIRFLOW"}'))
@patch("airflow.contrib.hooks.jira_hook.JIRA", autospec=True,
return_value=jira_client_mock)
def test_jira_client_connection(self, jira_mock):
jira_hook = JiraHook()
self.assertTrue(jira_mock.called)
self.assertIsInstance(jira_hook.client, Mock)
self.assertEqual(jira_hook.client.name, jira_mock.return_value.name)
if __name__ == '__main__':
unittest.main()
<|fim▁end|> | setUp |
<|file_name|>test_jira_hook.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
import unittest
from mock import Mock
from mock import patch
from airflow import configuration
from airflow.contrib.hooks.jira_hook import JiraHook
from airflow import models
from airflow.utils import db
jira_client_mock = Mock(
name="jira_client"
)
class TestJiraHook(unittest.TestCase):
def setUp(self):
configuration.load_test_config()
db.merge_conn(
models.Connection(
conn_id='jira_default', conn_type='jira',
host='https://localhost/jira/', port=443,
extra='{"verify": "False", "project": "AIRFLOW"}'))
@patch("airflow.contrib.hooks.jira_hook.JIRA", autospec=True,
return_value=jira_client_mock)
def <|fim_middle|>(self, jira_mock):
jira_hook = JiraHook()
self.assertTrue(jira_mock.called)
self.assertIsInstance(jira_hook.client, Mock)
self.assertEqual(jira_hook.client.name, jira_mock.return_value.name)
if __name__ == '__main__':
unittest.main()
<|fim▁end|> | test_jira_client_connection |
<|file_name|>Roche.py<|end_file_name|><|fim▁begin|># We calculate the flatness with the Roche model
# calculate omk knowing omc and vice-versa
from numpy import *
from scipy.optimize import root
# we have to solve a cubic equation a-J2*a**3=1+J2+0.5*omk**2
def eps(omk):
return omk**2/(2+omk**2)
def om_k(omc):<|fim▁hole|>
omc=0.88
print 'omc=',omc,' omk=',om_k(omc)<|fim▁end|> | khi=arcsin(omc)
return sqrt(6*sin(khi/3)/omc-2) |
<|file_name|>Roche.py<|end_file_name|><|fim▁begin|># We calculate the flatness with the Roche model
# calculate omk knowing omc and vice-versa
from numpy import *
from scipy.optimize import root
# we have to solve a cubic equation a-J2*a**3=1+J2+0.5*omk**2
def eps(omk):
<|fim_middle|>
def om_k(omc):
khi=arcsin(omc)
return sqrt(6*sin(khi/3)/omc-2)
omc=0.88
print 'omc=',omc,' omk=',om_k(omc)
<|fim▁end|> | return omk**2/(2+omk**2) |
<|file_name|>Roche.py<|end_file_name|><|fim▁begin|># We calculate the flatness with the Roche model
# calculate omk knowing omc and vice-versa
from numpy import *
from scipy.optimize import root
# we have to solve a cubic equation a-J2*a**3=1+J2+0.5*omk**2
def eps(omk):
return omk**2/(2+omk**2)
def om_k(omc):
<|fim_middle|>
omc=0.88
print 'omc=',omc,' omk=',om_k(omc)
<|fim▁end|> | khi=arcsin(omc)
return sqrt(6*sin(khi/3)/omc-2) |
<|file_name|>Roche.py<|end_file_name|><|fim▁begin|># We calculate the flatness with the Roche model
# calculate omk knowing omc and vice-versa
from numpy import *
from scipy.optimize import root
# we have to solve a cubic equation a-J2*a**3=1+J2+0.5*omk**2
def <|fim_middle|>(omk):
return omk**2/(2+omk**2)
def om_k(omc):
khi=arcsin(omc)
return sqrt(6*sin(khi/3)/omc-2)
omc=0.88
print 'omc=',omc,' omk=',om_k(omc)
<|fim▁end|> | eps |
<|file_name|>Roche.py<|end_file_name|><|fim▁begin|># We calculate the flatness with the Roche model
# calculate omk knowing omc and vice-versa
from numpy import *
from scipy.optimize import root
# we have to solve a cubic equation a-J2*a**3=1+J2+0.5*omk**2
def eps(omk):
return omk**2/(2+omk**2)
def <|fim_middle|>(omc):
khi=arcsin(omc)
return sqrt(6*sin(khi/3)/omc-2)
omc=0.88
print 'omc=',omc,' omk=',om_k(omc)
<|fim▁end|> | om_k |
<|file_name|>test_financial_move.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
# Copyright 2017 KMEE
# Hendrix Costa <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp.addons.financial.tests.financial_test_classes import \
FinancialTestCase
class ManualFinancialProcess(FinancialTestCase):
def setUp(self):
self.financial_model = self.env['financial.move']
super(ManualFinancialProcess, self).setUp()
def test_01_check_return_views(self):
"""Check if view is correctly called for python code"""
<|fim▁hole|> self.assertEqual(
action.get('display_name'),
'financial.move.debt.2receive.form (in financial)')
self.assertEqual(
action.get('res_id'), financial_move_id.id)
action = financial_move_id.action_view_financial('2pay')
self.assertEqual(
action.get('display_name'),
'financial.move.debt.2pay.form (in financial)')
self.assertEqual(
action.get('res_id'), financial_move_id.id)
# test for len(financial.move) > 1
financial_move_id = self.financial_model.search([], limit=2)
action = financial_move_id.action_view_financial('2pay')
self.assertEqual(action.get('domain')[0][2], financial_move_id.ids)
# test for len(financial.move) < 1
action = self.financial_model.action_view_financial('2pay')
self.assertEqual(action.get('type'), 'ir.actions.act_window_close')<|fim▁end|> | # test for len(financial.move) == 1
financial_move_id = self.financial_model.search([], limit=1)
action = financial_move_id.action_view_financial('2receive') |
<|file_name|>test_financial_move.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
# Copyright 2017 KMEE
# Hendrix Costa <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp.addons.financial.tests.financial_test_classes import \
FinancialTestCase
class ManualFinancialProcess(FinancialTestCase):
<|fim_middle|>
<|fim▁end|> | def setUp(self):
self.financial_model = self.env['financial.move']
super(ManualFinancialProcess, self).setUp()
def test_01_check_return_views(self):
"""Check if view is correctly called for python code"""
# test for len(financial.move) == 1
financial_move_id = self.financial_model.search([], limit=1)
action = financial_move_id.action_view_financial('2receive')
self.assertEqual(
action.get('display_name'),
'financial.move.debt.2receive.form (in financial)')
self.assertEqual(
action.get('res_id'), financial_move_id.id)
action = financial_move_id.action_view_financial('2pay')
self.assertEqual(
action.get('display_name'),
'financial.move.debt.2pay.form (in financial)')
self.assertEqual(
action.get('res_id'), financial_move_id.id)
# test for len(financial.move) > 1
financial_move_id = self.financial_model.search([], limit=2)
action = financial_move_id.action_view_financial('2pay')
self.assertEqual(action.get('domain')[0][2], financial_move_id.ids)
# test for len(financial.move) < 1
action = self.financial_model.action_view_financial('2pay')
self.assertEqual(action.get('type'), 'ir.actions.act_window_close') |
<|file_name|>test_financial_move.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
# Copyright 2017 KMEE
# Hendrix Costa <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp.addons.financial.tests.financial_test_classes import \
FinancialTestCase
class ManualFinancialProcess(FinancialTestCase):
def setUp(self):
<|fim_middle|>
def test_01_check_return_views(self):
"""Check if view is correctly called for python code"""
# test for len(financial.move) == 1
financial_move_id = self.financial_model.search([], limit=1)
action = financial_move_id.action_view_financial('2receive')
self.assertEqual(
action.get('display_name'),
'financial.move.debt.2receive.form (in financial)')
self.assertEqual(
action.get('res_id'), financial_move_id.id)
action = financial_move_id.action_view_financial('2pay')
self.assertEqual(
action.get('display_name'),
'financial.move.debt.2pay.form (in financial)')
self.assertEqual(
action.get('res_id'), financial_move_id.id)
# test for len(financial.move) > 1
financial_move_id = self.financial_model.search([], limit=2)
action = financial_move_id.action_view_financial('2pay')
self.assertEqual(action.get('domain')[0][2], financial_move_id.ids)
# test for len(financial.move) < 1
action = self.financial_model.action_view_financial('2pay')
self.assertEqual(action.get('type'), 'ir.actions.act_window_close')
<|fim▁end|> | self.financial_model = self.env['financial.move']
super(ManualFinancialProcess, self).setUp() |
<|file_name|>test_financial_move.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
# Copyright 2017 KMEE
# Hendrix Costa <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp.addons.financial.tests.financial_test_classes import \
FinancialTestCase
class ManualFinancialProcess(FinancialTestCase):
def setUp(self):
self.financial_model = self.env['financial.move']
super(ManualFinancialProcess, self).setUp()
def test_01_check_return_views(self):
<|fim_middle|>
<|fim▁end|> | """Check if view is correctly called for python code"""
# test for len(financial.move) == 1
financial_move_id = self.financial_model.search([], limit=1)
action = financial_move_id.action_view_financial('2receive')
self.assertEqual(
action.get('display_name'),
'financial.move.debt.2receive.form (in financial)')
self.assertEqual(
action.get('res_id'), financial_move_id.id)
action = financial_move_id.action_view_financial('2pay')
self.assertEqual(
action.get('display_name'),
'financial.move.debt.2pay.form (in financial)')
self.assertEqual(
action.get('res_id'), financial_move_id.id)
# test for len(financial.move) > 1
financial_move_id = self.financial_model.search([], limit=2)
action = financial_move_id.action_view_financial('2pay')
self.assertEqual(action.get('domain')[0][2], financial_move_id.ids)
# test for len(financial.move) < 1
action = self.financial_model.action_view_financial('2pay')
self.assertEqual(action.get('type'), 'ir.actions.act_window_close') |
<|file_name|>test_financial_move.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
# Copyright 2017 KMEE
# Hendrix Costa <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp.addons.financial.tests.financial_test_classes import \
FinancialTestCase
class ManualFinancialProcess(FinancialTestCase):
def <|fim_middle|>(self):
self.financial_model = self.env['financial.move']
super(ManualFinancialProcess, self).setUp()
def test_01_check_return_views(self):
"""Check if view is correctly called for python code"""
# test for len(financial.move) == 1
financial_move_id = self.financial_model.search([], limit=1)
action = financial_move_id.action_view_financial('2receive')
self.assertEqual(
action.get('display_name'),
'financial.move.debt.2receive.form (in financial)')
self.assertEqual(
action.get('res_id'), financial_move_id.id)
action = financial_move_id.action_view_financial('2pay')
self.assertEqual(
action.get('display_name'),
'financial.move.debt.2pay.form (in financial)')
self.assertEqual(
action.get('res_id'), financial_move_id.id)
# test for len(financial.move) > 1
financial_move_id = self.financial_model.search([], limit=2)
action = financial_move_id.action_view_financial('2pay')
self.assertEqual(action.get('domain')[0][2], financial_move_id.ids)
# test for len(financial.move) < 1
action = self.financial_model.action_view_financial('2pay')
self.assertEqual(action.get('type'), 'ir.actions.act_window_close')
<|fim▁end|> | setUp |
<|file_name|>test_financial_move.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
# Copyright 2017 KMEE
# Hendrix Costa <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp.addons.financial.tests.financial_test_classes import \
FinancialTestCase
class ManualFinancialProcess(FinancialTestCase):
def setUp(self):
self.financial_model = self.env['financial.move']
super(ManualFinancialProcess, self).setUp()
def <|fim_middle|>(self):
"""Check if view is correctly called for python code"""
# test for len(financial.move) == 1
financial_move_id = self.financial_model.search([], limit=1)
action = financial_move_id.action_view_financial('2receive')
self.assertEqual(
action.get('display_name'),
'financial.move.debt.2receive.form (in financial)')
self.assertEqual(
action.get('res_id'), financial_move_id.id)
action = financial_move_id.action_view_financial('2pay')
self.assertEqual(
action.get('display_name'),
'financial.move.debt.2pay.form (in financial)')
self.assertEqual(
action.get('res_id'), financial_move_id.id)
# test for len(financial.move) > 1
financial_move_id = self.financial_model.search([], limit=2)
action = financial_move_id.action_view_financial('2pay')
self.assertEqual(action.get('domain')[0][2], financial_move_id.ids)
# test for len(financial.move) < 1
action = self.financial_model.action_view_financial('2pay')
self.assertEqual(action.get('type'), 'ir.actions.act_window_close')
<|fim▁end|> | test_01_check_return_views |
<|file_name|>sqlalchemy_util_test.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
#
# Copyright 2015-2021 Flavio Garcia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from firenado.util.sqlalchemy_util import Base, base_to_dict
from sqlalchemy import Column, String
from sqlalchemy.types import Integer, DateTime
from sqlalchemy.sql import text
import unittest
class TestBase(Base):
__tablename__ = "test"
id = Column("id", Integer, primary_key=True)
username = Column("username", String(150), nullable=False)
first_name = Column("first_name", String(150), nullable=False)
last_name = Column("last_name", String(150), nullable=False)
password = Column("password", String(150), nullable=False)<|fim▁hole|> server_default=text("now()"))
modified = Column("modified", DateTime, nullable=False,
server_default=text("now()"))
class BaseToDictTestCase(unittest.TestCase):
def setUp(self):
self.test_object = TestBase()
self.test_object.id = 1
self.test_object.username = "anusername"
self.test_object.password = "apassword"
self.test_object.first_name = "Test"
self.test_object.last_name = "Object"
self.test_object.email = "[email protected]"
def test_base_to_dict(self):
dict_from_base = base_to_dict(self.test_object)
self.assertEqual(dict_from_base['id'], self.test_object.id)
self.assertEqual(dict_from_base['username'], self.test_object.username)
self.assertEqual(dict_from_base['password'], self.test_object.password)
self.assertEqual(dict_from_base['first_name'],
self.test_object.first_name)
self.assertEqual(dict_from_base['last_name'],
self.test_object.last_name)
self.assertEqual(dict_from_base['email'], self.test_object.email)
self.assertEqual(dict_from_base['created'], self.test_object.created)
self.assertEqual(dict_from_base['modified'], self.test_object.modified)
def test_base_to_dict(self):
dict_from_base = base_to_dict(self.test_object,
["id", "username", "first_name"])
self.assertEqual(dict_from_base['id'], self.test_object.id)
self.assertEqual(dict_from_base['username'], self.test_object.username)
self.assertEqual(dict_from_base['first_name'],
self.test_object.first_name)
self.assertTrue("password" not in dict_from_base)
self.assertTrue("last_name" not in dict_from_base)
self.assertTrue("email" not in dict_from_base)
self.assertTrue("created" not in dict_from_base)
self.assertTrue("modified" not in dict_from_base)<|fim▁end|> | email = Column("email", String(150), nullable=False)
created = Column("created", DateTime, nullable=False, |
<|file_name|>sqlalchemy_util_test.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
#
# Copyright 2015-2021 Flavio Garcia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from firenado.util.sqlalchemy_util import Base, base_to_dict
from sqlalchemy import Column, String
from sqlalchemy.types import Integer, DateTime
from sqlalchemy.sql import text
import unittest
class TestBase(Base):
<|fim_middle|>
class BaseToDictTestCase(unittest.TestCase):
def setUp(self):
self.test_object = TestBase()
self.test_object.id = 1
self.test_object.username = "anusername"
self.test_object.password = "apassword"
self.test_object.first_name = "Test"
self.test_object.last_name = "Object"
self.test_object.email = "[email protected]"
def test_base_to_dict(self):
dict_from_base = base_to_dict(self.test_object)
self.assertEqual(dict_from_base['id'], self.test_object.id)
self.assertEqual(dict_from_base['username'], self.test_object.username)
self.assertEqual(dict_from_base['password'], self.test_object.password)
self.assertEqual(dict_from_base['first_name'],
self.test_object.first_name)
self.assertEqual(dict_from_base['last_name'],
self.test_object.last_name)
self.assertEqual(dict_from_base['email'], self.test_object.email)
self.assertEqual(dict_from_base['created'], self.test_object.created)
self.assertEqual(dict_from_base['modified'], self.test_object.modified)
def test_base_to_dict(self):
dict_from_base = base_to_dict(self.test_object,
["id", "username", "first_name"])
self.assertEqual(dict_from_base['id'], self.test_object.id)
self.assertEqual(dict_from_base['username'], self.test_object.username)
self.assertEqual(dict_from_base['first_name'],
self.test_object.first_name)
self.assertTrue("password" not in dict_from_base)
self.assertTrue("last_name" not in dict_from_base)
self.assertTrue("email" not in dict_from_base)
self.assertTrue("created" not in dict_from_base)
self.assertTrue("modified" not in dict_from_base)
<|fim▁end|> | __tablename__ = "test"
id = Column("id", Integer, primary_key=True)
username = Column("username", String(150), nullable=False)
first_name = Column("first_name", String(150), nullable=False)
last_name = Column("last_name", String(150), nullable=False)
password = Column("password", String(150), nullable=False)
email = Column("email", String(150), nullable=False)
created = Column("created", DateTime, nullable=False,
server_default=text("now()"))
modified = Column("modified", DateTime, nullable=False,
server_default=text("now()")) |
<|file_name|>sqlalchemy_util_test.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
#
# Copyright 2015-2021 Flavio Garcia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from firenado.util.sqlalchemy_util import Base, base_to_dict
from sqlalchemy import Column, String
from sqlalchemy.types import Integer, DateTime
from sqlalchemy.sql import text
import unittest
class TestBase(Base):
__tablename__ = "test"
id = Column("id", Integer, primary_key=True)
username = Column("username", String(150), nullable=False)
first_name = Column("first_name", String(150), nullable=False)
last_name = Column("last_name", String(150), nullable=False)
password = Column("password", String(150), nullable=False)
email = Column("email", String(150), nullable=False)
created = Column("created", DateTime, nullable=False,
server_default=text("now()"))
modified = Column("modified", DateTime, nullable=False,
server_default=text("now()"))
class BaseToDictTestCase(unittest.TestCase):
<|fim_middle|>
<|fim▁end|> | def setUp(self):
self.test_object = TestBase()
self.test_object.id = 1
self.test_object.username = "anusername"
self.test_object.password = "apassword"
self.test_object.first_name = "Test"
self.test_object.last_name = "Object"
self.test_object.email = "[email protected]"
def test_base_to_dict(self):
dict_from_base = base_to_dict(self.test_object)
self.assertEqual(dict_from_base['id'], self.test_object.id)
self.assertEqual(dict_from_base['username'], self.test_object.username)
self.assertEqual(dict_from_base['password'], self.test_object.password)
self.assertEqual(dict_from_base['first_name'],
self.test_object.first_name)
self.assertEqual(dict_from_base['last_name'],
self.test_object.last_name)
self.assertEqual(dict_from_base['email'], self.test_object.email)
self.assertEqual(dict_from_base['created'], self.test_object.created)
self.assertEqual(dict_from_base['modified'], self.test_object.modified)
def test_base_to_dict(self):
dict_from_base = base_to_dict(self.test_object,
["id", "username", "first_name"])
self.assertEqual(dict_from_base['id'], self.test_object.id)
self.assertEqual(dict_from_base['username'], self.test_object.username)
self.assertEqual(dict_from_base['first_name'],
self.test_object.first_name)
self.assertTrue("password" not in dict_from_base)
self.assertTrue("last_name" not in dict_from_base)
self.assertTrue("email" not in dict_from_base)
self.assertTrue("created" not in dict_from_base)
self.assertTrue("modified" not in dict_from_base) |
<|file_name|>sqlalchemy_util_test.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
#
# Copyright 2015-2021 Flavio Garcia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from firenado.util.sqlalchemy_util import Base, base_to_dict
from sqlalchemy import Column, String
from sqlalchemy.types import Integer, DateTime
from sqlalchemy.sql import text
import unittest
class TestBase(Base):
__tablename__ = "test"
id = Column("id", Integer, primary_key=True)
username = Column("username", String(150), nullable=False)
first_name = Column("first_name", String(150), nullable=False)
last_name = Column("last_name", String(150), nullable=False)
password = Column("password", String(150), nullable=False)
email = Column("email", String(150), nullable=False)
created = Column("created", DateTime, nullable=False,
server_default=text("now()"))
modified = Column("modified", DateTime, nullable=False,
server_default=text("now()"))
class BaseToDictTestCase(unittest.TestCase):
def setUp(self):
<|fim_middle|>
def test_base_to_dict(self):
dict_from_base = base_to_dict(self.test_object)
self.assertEqual(dict_from_base['id'], self.test_object.id)
self.assertEqual(dict_from_base['username'], self.test_object.username)
self.assertEqual(dict_from_base['password'], self.test_object.password)
self.assertEqual(dict_from_base['first_name'],
self.test_object.first_name)
self.assertEqual(dict_from_base['last_name'],
self.test_object.last_name)
self.assertEqual(dict_from_base['email'], self.test_object.email)
self.assertEqual(dict_from_base['created'], self.test_object.created)
self.assertEqual(dict_from_base['modified'], self.test_object.modified)
def test_base_to_dict(self):
dict_from_base = base_to_dict(self.test_object,
["id", "username", "first_name"])
self.assertEqual(dict_from_base['id'], self.test_object.id)
self.assertEqual(dict_from_base['username'], self.test_object.username)
self.assertEqual(dict_from_base['first_name'],
self.test_object.first_name)
self.assertTrue("password" not in dict_from_base)
self.assertTrue("last_name" not in dict_from_base)
self.assertTrue("email" not in dict_from_base)
self.assertTrue("created" not in dict_from_base)
self.assertTrue("modified" not in dict_from_base)
<|fim▁end|> | self.test_object = TestBase()
self.test_object.id = 1
self.test_object.username = "anusername"
self.test_object.password = "apassword"
self.test_object.first_name = "Test"
self.test_object.last_name = "Object"
self.test_object.email = "[email protected]" |
<|file_name|>sqlalchemy_util_test.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
#
# Copyright 2015-2021 Flavio Garcia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from firenado.util.sqlalchemy_util import Base, base_to_dict
from sqlalchemy import Column, String
from sqlalchemy.types import Integer, DateTime
from sqlalchemy.sql import text
import unittest
class TestBase(Base):
__tablename__ = "test"
id = Column("id", Integer, primary_key=True)
username = Column("username", String(150), nullable=False)
first_name = Column("first_name", String(150), nullable=False)
last_name = Column("last_name", String(150), nullable=False)
password = Column("password", String(150), nullable=False)
email = Column("email", String(150), nullable=False)
created = Column("created", DateTime, nullable=False,
server_default=text("now()"))
modified = Column("modified", DateTime, nullable=False,
server_default=text("now()"))
class BaseToDictTestCase(unittest.TestCase):
def setUp(self):
self.test_object = TestBase()
self.test_object.id = 1
self.test_object.username = "anusername"
self.test_object.password = "apassword"
self.test_object.first_name = "Test"
self.test_object.last_name = "Object"
self.test_object.email = "[email protected]"
def test_base_to_dict(self):
<|fim_middle|>
def test_base_to_dict(self):
dict_from_base = base_to_dict(self.test_object,
["id", "username", "first_name"])
self.assertEqual(dict_from_base['id'], self.test_object.id)
self.assertEqual(dict_from_base['username'], self.test_object.username)
self.assertEqual(dict_from_base['first_name'],
self.test_object.first_name)
self.assertTrue("password" not in dict_from_base)
self.assertTrue("last_name" not in dict_from_base)
self.assertTrue("email" not in dict_from_base)
self.assertTrue("created" not in dict_from_base)
self.assertTrue("modified" not in dict_from_base)
<|fim▁end|> | dict_from_base = base_to_dict(self.test_object)
self.assertEqual(dict_from_base['id'], self.test_object.id)
self.assertEqual(dict_from_base['username'], self.test_object.username)
self.assertEqual(dict_from_base['password'], self.test_object.password)
self.assertEqual(dict_from_base['first_name'],
self.test_object.first_name)
self.assertEqual(dict_from_base['last_name'],
self.test_object.last_name)
self.assertEqual(dict_from_base['email'], self.test_object.email)
self.assertEqual(dict_from_base['created'], self.test_object.created)
self.assertEqual(dict_from_base['modified'], self.test_object.modified) |
<|file_name|>sqlalchemy_util_test.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
#
# Copyright 2015-2021 Flavio Garcia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from firenado.util.sqlalchemy_util import Base, base_to_dict
from sqlalchemy import Column, String
from sqlalchemy.types import Integer, DateTime
from sqlalchemy.sql import text
import unittest
class TestBase(Base):
__tablename__ = "test"
id = Column("id", Integer, primary_key=True)
username = Column("username", String(150), nullable=False)
first_name = Column("first_name", String(150), nullable=False)
last_name = Column("last_name", String(150), nullable=False)
password = Column("password", String(150), nullable=False)
email = Column("email", String(150), nullable=False)
created = Column("created", DateTime, nullable=False,
server_default=text("now()"))
modified = Column("modified", DateTime, nullable=False,
server_default=text("now()"))
class BaseToDictTestCase(unittest.TestCase):
def setUp(self):
self.test_object = TestBase()
self.test_object.id = 1
self.test_object.username = "anusername"
self.test_object.password = "apassword"
self.test_object.first_name = "Test"
self.test_object.last_name = "Object"
self.test_object.email = "[email protected]"
def test_base_to_dict(self):
dict_from_base = base_to_dict(self.test_object)
self.assertEqual(dict_from_base['id'], self.test_object.id)
self.assertEqual(dict_from_base['username'], self.test_object.username)
self.assertEqual(dict_from_base['password'], self.test_object.password)
self.assertEqual(dict_from_base['first_name'],
self.test_object.first_name)
self.assertEqual(dict_from_base['last_name'],
self.test_object.last_name)
self.assertEqual(dict_from_base['email'], self.test_object.email)
self.assertEqual(dict_from_base['created'], self.test_object.created)
self.assertEqual(dict_from_base['modified'], self.test_object.modified)
def test_base_to_dict(self):
<|fim_middle|>
<|fim▁end|> | dict_from_base = base_to_dict(self.test_object,
["id", "username", "first_name"])
self.assertEqual(dict_from_base['id'], self.test_object.id)
self.assertEqual(dict_from_base['username'], self.test_object.username)
self.assertEqual(dict_from_base['first_name'],
self.test_object.first_name)
self.assertTrue("password" not in dict_from_base)
self.assertTrue("last_name" not in dict_from_base)
self.assertTrue("email" not in dict_from_base)
self.assertTrue("created" not in dict_from_base)
self.assertTrue("modified" not in dict_from_base) |
<|file_name|>sqlalchemy_util_test.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
#
# Copyright 2015-2021 Flavio Garcia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from firenado.util.sqlalchemy_util import Base, base_to_dict
from sqlalchemy import Column, String
from sqlalchemy.types import Integer, DateTime
from sqlalchemy.sql import text
import unittest
class TestBase(Base):
__tablename__ = "test"
id = Column("id", Integer, primary_key=True)
username = Column("username", String(150), nullable=False)
first_name = Column("first_name", String(150), nullable=False)
last_name = Column("last_name", String(150), nullable=False)
password = Column("password", String(150), nullable=False)
email = Column("email", String(150), nullable=False)
created = Column("created", DateTime, nullable=False,
server_default=text("now()"))
modified = Column("modified", DateTime, nullable=False,
server_default=text("now()"))
class BaseToDictTestCase(unittest.TestCase):
def <|fim_middle|>(self):
self.test_object = TestBase()
self.test_object.id = 1
self.test_object.username = "anusername"
self.test_object.password = "apassword"
self.test_object.first_name = "Test"
self.test_object.last_name = "Object"
self.test_object.email = "[email protected]"
def test_base_to_dict(self):
dict_from_base = base_to_dict(self.test_object)
self.assertEqual(dict_from_base['id'], self.test_object.id)
self.assertEqual(dict_from_base['username'], self.test_object.username)
self.assertEqual(dict_from_base['password'], self.test_object.password)
self.assertEqual(dict_from_base['first_name'],
self.test_object.first_name)
self.assertEqual(dict_from_base['last_name'],
self.test_object.last_name)
self.assertEqual(dict_from_base['email'], self.test_object.email)
self.assertEqual(dict_from_base['created'], self.test_object.created)
self.assertEqual(dict_from_base['modified'], self.test_object.modified)
def test_base_to_dict(self):
dict_from_base = base_to_dict(self.test_object,
["id", "username", "first_name"])
self.assertEqual(dict_from_base['id'], self.test_object.id)
self.assertEqual(dict_from_base['username'], self.test_object.username)
self.assertEqual(dict_from_base['first_name'],
self.test_object.first_name)
self.assertTrue("password" not in dict_from_base)
self.assertTrue("last_name" not in dict_from_base)
self.assertTrue("email" not in dict_from_base)
self.assertTrue("created" not in dict_from_base)
self.assertTrue("modified" not in dict_from_base)
<|fim▁end|> | setUp |
<|file_name|>sqlalchemy_util_test.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
#
# Copyright 2015-2021 Flavio Garcia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from firenado.util.sqlalchemy_util import Base, base_to_dict
from sqlalchemy import Column, String
from sqlalchemy.types import Integer, DateTime
from sqlalchemy.sql import text
import unittest
class TestBase(Base):
__tablename__ = "test"
id = Column("id", Integer, primary_key=True)
username = Column("username", String(150), nullable=False)
first_name = Column("first_name", String(150), nullable=False)
last_name = Column("last_name", String(150), nullable=False)
password = Column("password", String(150), nullable=False)
email = Column("email", String(150), nullable=False)
created = Column("created", DateTime, nullable=False,
server_default=text("now()"))
modified = Column("modified", DateTime, nullable=False,
server_default=text("now()"))
class BaseToDictTestCase(unittest.TestCase):
def setUp(self):
self.test_object = TestBase()
self.test_object.id = 1
self.test_object.username = "anusername"
self.test_object.password = "apassword"
self.test_object.first_name = "Test"
self.test_object.last_name = "Object"
self.test_object.email = "[email protected]"
def <|fim_middle|>(self):
dict_from_base = base_to_dict(self.test_object)
self.assertEqual(dict_from_base['id'], self.test_object.id)
self.assertEqual(dict_from_base['username'], self.test_object.username)
self.assertEqual(dict_from_base['password'], self.test_object.password)
self.assertEqual(dict_from_base['first_name'],
self.test_object.first_name)
self.assertEqual(dict_from_base['last_name'],
self.test_object.last_name)
self.assertEqual(dict_from_base['email'], self.test_object.email)
self.assertEqual(dict_from_base['created'], self.test_object.created)
self.assertEqual(dict_from_base['modified'], self.test_object.modified)
def test_base_to_dict(self):
dict_from_base = base_to_dict(self.test_object,
["id", "username", "first_name"])
self.assertEqual(dict_from_base['id'], self.test_object.id)
self.assertEqual(dict_from_base['username'], self.test_object.username)
self.assertEqual(dict_from_base['first_name'],
self.test_object.first_name)
self.assertTrue("password" not in dict_from_base)
self.assertTrue("last_name" not in dict_from_base)
self.assertTrue("email" not in dict_from_base)
self.assertTrue("created" not in dict_from_base)
self.assertTrue("modified" not in dict_from_base)
<|fim▁end|> | test_base_to_dict |
<|file_name|>sqlalchemy_util_test.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
#
# Copyright 2015-2021 Flavio Garcia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from firenado.util.sqlalchemy_util import Base, base_to_dict
from sqlalchemy import Column, String
from sqlalchemy.types import Integer, DateTime
from sqlalchemy.sql import text
import unittest
class TestBase(Base):
__tablename__ = "test"
id = Column("id", Integer, primary_key=True)
username = Column("username", String(150), nullable=False)
first_name = Column("first_name", String(150), nullable=False)
last_name = Column("last_name", String(150), nullable=False)
password = Column("password", String(150), nullable=False)
email = Column("email", String(150), nullable=False)
created = Column("created", DateTime, nullable=False,
server_default=text("now()"))
modified = Column("modified", DateTime, nullable=False,
server_default=text("now()"))
class BaseToDictTestCase(unittest.TestCase):
def setUp(self):
self.test_object = TestBase()
self.test_object.id = 1
self.test_object.username = "anusername"
self.test_object.password = "apassword"
self.test_object.first_name = "Test"
self.test_object.last_name = "Object"
self.test_object.email = "[email protected]"
def test_base_to_dict(self):
dict_from_base = base_to_dict(self.test_object)
self.assertEqual(dict_from_base['id'], self.test_object.id)
self.assertEqual(dict_from_base['username'], self.test_object.username)
self.assertEqual(dict_from_base['password'], self.test_object.password)
self.assertEqual(dict_from_base['first_name'],
self.test_object.first_name)
self.assertEqual(dict_from_base['last_name'],
self.test_object.last_name)
self.assertEqual(dict_from_base['email'], self.test_object.email)
self.assertEqual(dict_from_base['created'], self.test_object.created)
self.assertEqual(dict_from_base['modified'], self.test_object.modified)
def <|fim_middle|>(self):
dict_from_base = base_to_dict(self.test_object,
["id", "username", "first_name"])
self.assertEqual(dict_from_base['id'], self.test_object.id)
self.assertEqual(dict_from_base['username'], self.test_object.username)
self.assertEqual(dict_from_base['first_name'],
self.test_object.first_name)
self.assertTrue("password" not in dict_from_base)
self.assertTrue("last_name" not in dict_from_base)
self.assertTrue("email" not in dict_from_base)
self.assertTrue("created" not in dict_from_base)
self.assertTrue("modified" not in dict_from_base)
<|fim▁end|> | test_base_to_dict |
<|file_name|>regular_expression_matching.py<|end_file_name|><|fim▁begin|>class R:
def __init__(self, c):
self.c = c
self.is_star = False
def match(self, c):
return self.c == '.' or self.c == c
class Solution(object):
def isMatch(self, s, p):
"""
:type s: str
:type p: str
:rtype: bool
"""
rs = []
""":type: list[R]"""
for c in p:
if c == '*':
rs[-1].is_star = True
else:
rs.append(R(c))
lr = len(rs)
ls = len(s)
s += '\0'
dp = [[False] * (ls + 1) for _ in range(lr + 1)]
dp[0][0] = True
for i, r in enumerate(rs):
for j in range(ls + 1):
c = s[j - 1]
if r.is_star:
dp[i + 1][j] = dp[i][j]
if j and r.match(c):
dp[i + 1][j] |= dp[i + 1][j - 1]<|fim▁hole|> if j and r.match(c):
dp[i + 1][j] = dp[i][j - 1]
return dp[-1][-1]<|fim▁end|> | else: |
<|file_name|>regular_expression_matching.py<|end_file_name|><|fim▁begin|>class R:
<|fim_middle|>
class Solution(object):
def isMatch(self, s, p):
"""
:type s: str
:type p: str
:rtype: bool
"""
rs = []
""":type: list[R]"""
for c in p:
if c == '*':
rs[-1].is_star = True
else:
rs.append(R(c))
lr = len(rs)
ls = len(s)
s += '\0'
dp = [[False] * (ls + 1) for _ in range(lr + 1)]
dp[0][0] = True
for i, r in enumerate(rs):
for j in range(ls + 1):
c = s[j - 1]
if r.is_star:
dp[i + 1][j] = dp[i][j]
if j and r.match(c):
dp[i + 1][j] |= dp[i + 1][j - 1]
else:
if j and r.match(c):
dp[i + 1][j] = dp[i][j - 1]
return dp[-1][-1]
<|fim▁end|> | def __init__(self, c):
self.c = c
self.is_star = False
def match(self, c):
return self.c == '.' or self.c == c |
<|file_name|>regular_expression_matching.py<|end_file_name|><|fim▁begin|>class R:
def __init__(self, c):
<|fim_middle|>
def match(self, c):
return self.c == '.' or self.c == c
class Solution(object):
def isMatch(self, s, p):
"""
:type s: str
:type p: str
:rtype: bool
"""
rs = []
""":type: list[R]"""
for c in p:
if c == '*':
rs[-1].is_star = True
else:
rs.append(R(c))
lr = len(rs)
ls = len(s)
s += '\0'
dp = [[False] * (ls + 1) for _ in range(lr + 1)]
dp[0][0] = True
for i, r in enumerate(rs):
for j in range(ls + 1):
c = s[j - 1]
if r.is_star:
dp[i + 1][j] = dp[i][j]
if j and r.match(c):
dp[i + 1][j] |= dp[i + 1][j - 1]
else:
if j and r.match(c):
dp[i + 1][j] = dp[i][j - 1]
return dp[-1][-1]
<|fim▁end|> | self.c = c
self.is_star = False |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.