repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_documentation_string
stringlengths
1
47.2k
func_code_url
stringlengths
85
339
maxcountryman/atomos
atomos/multiprocessing/atomic.py
AtomicNumber.get_and_subtract
def get_and_subtract(self, delta): ''' Atomically subtracts `delta` from the current value and returns the old value. :param delta: The delta to subtract. ''' with self._reference.get_lock(): oldval = self._reference.value self._reference.value -=...
python
def get_and_subtract(self, delta): ''' Atomically subtracts `delta` from the current value and returns the old value. :param delta: The delta to subtract. ''' with self._reference.get_lock(): oldval = self._reference.value self._reference.value -=...
Atomically subtracts `delta` from the current value and returns the old value. :param delta: The delta to subtract.
https://github.com/maxcountryman/atomos/blob/418746c69134efba3c4f999405afe9113dee4827/atomos/multiprocessing/atomic.py#L200-L210
Pierre-Sassoulas/django-zxcvbn-password-validator
django_zxcvbn_password_validator/translate_zxcvbn_text.py
translate_zxcvbn_text
def translate_zxcvbn_text(text): """ This PR would make it cleaner, but it will also be very slow to be integrated in python-zxcvbn and we want this to work now : https://github.com/dropbox/zxcvbn/pull/124 """ i18n = { "Use a few words, avoid common phrases": _( "Use a few words, avo...
python
def translate_zxcvbn_text(text): """ This PR would make it cleaner, but it will also be very slow to be integrated in python-zxcvbn and we want this to work now : https://github.com/dropbox/zxcvbn/pull/124 """ i18n = { "Use a few words, avoid common phrases": _( "Use a few words, avo...
This PR would make it cleaner, but it will also be very slow to be integrated in python-zxcvbn and we want this to work now : https://github.com/dropbox/zxcvbn/pull/124
https://github.com/Pierre-Sassoulas/django-zxcvbn-password-validator/blob/4b73e0fae430b9f93485b7fbd7a132a78c2d8f15/django_zxcvbn_password_validator/translate_zxcvbn_text.py#L8-L88
codelv/enaml-native-cli
enamlnativecli/main.py
find_conda
def find_conda(): """ Try to find conda on the system """ USER_HOME = os.path.expanduser('~') CONDA_HOME = os.environ.get('CONDA_HOME', '') PROGRAMDATA = os.environ.get('PROGRAMDATA', '') # Search common install paths and sys path search_paths = [ # Windows join(PROGRAMDATA, 'mi...
python
def find_conda(): """ Try to find conda on the system """ USER_HOME = os.path.expanduser('~') CONDA_HOME = os.environ.get('CONDA_HOME', '') PROGRAMDATA = os.environ.get('PROGRAMDATA', '') # Search common install paths and sys path search_paths = [ # Windows join(PROGRAMDATA, 'mi...
Try to find conda on the system
https://github.com/codelv/enaml-native-cli/blob/81d6faa7e3dd437956f661c512031e49c0d44b63/enamlnativecli/main.py#L74-L103
codelv/enaml-native-cli
enamlnativecli/main.py
cp
def cp(src, dst): """ Like cp -R src dst """ print("[DEBUG]: -> copying {} to {}".format(src, dst)) if os.path.isfile(src): if not exists(dirname(dst)): os.makedirs(dirname(dst)) shutil.copy(src, dst) else: copy_tree(src, dst)
python
def cp(src, dst): """ Like cp -R src dst """ print("[DEBUG]: -> copying {} to {}".format(src, dst)) if os.path.isfile(src): if not exists(dirname(dst)): os.makedirs(dirname(dst)) shutil.copy(src, dst) else: copy_tree(src, dst)
Like cp -R src dst
https://github.com/codelv/enaml-native-cli/blob/81d6faa7e3dd437956f661c512031e49c0d44b63/enamlnativecli/main.py#L128-L136
codelv/enaml-native-cli
enamlnativecli/main.py
find_commands
def find_commands(cls): """ Finds commands by finding the subclasses of Command""" cmds = [] for subclass in cls.__subclasses__(): cmds.append(subclass) cmds.extend(find_commands(subclass)) return cmds
python
def find_commands(cls): """ Finds commands by finding the subclasses of Command""" cmds = [] for subclass in cls.__subclasses__(): cmds.append(subclass) cmds.extend(find_commands(subclass)) return cmds
Finds commands by finding the subclasses of Command
https://github.com/codelv/enaml-native-cli/blob/81d6faa7e3dd437956f661c512031e49c0d44b63/enamlnativecli/main.py#L1617-L1623
codelv/enaml-native-cli
enamlnativecli/main.py
Link.link
def link(self, path, pkg): """ Link the package in the current directory. """ # Check if a custom linker exists to handle linking this package #for ep in pkg_resources.iter_entry_points(group="enaml_native_linker"): # if ep.name.replace("-", '_') == pkg.replace("-", '_'): ...
python
def link(self, path, pkg): """ Link the package in the current directory. """ # Check if a custom linker exists to handle linking this package #for ep in pkg_resources.iter_entry_points(group="enaml_native_linker"): # if ep.name.replace("-", '_') == pkg.replace("-", '_'): ...
Link the package in the current directory.
https://github.com/codelv/enaml-native-cli/blob/81d6faa7e3dd437956f661c512031e49c0d44b63/enamlnativecli/main.py#L826-L846
codelv/enaml-native-cli
enamlnativecli/main.py
Link.is_settings_linked
def is_settings_linked(source, pkg): """ Returns true if the "include ':<project>'" line exists in the file """ for line in source.split("\n"): if re.search(r"include\s*['\"]:{}['\"]".format(pkg), line): return True return False
python
def is_settings_linked(source, pkg): """ Returns true if the "include ':<project>'" line exists in the file """ for line in source.split("\n"): if re.search(r"include\s*['\"]:{}['\"]".format(pkg), line): return True return False
Returns true if the "include ':<project>'" line exists in the file
https://github.com/codelv/enaml-native-cli/blob/81d6faa7e3dd437956f661c512031e49c0d44b63/enamlnativecli/main.py#L849-L855
codelv/enaml-native-cli
enamlnativecli/main.py
Link.is_build_linked
def is_build_linked(source, pkg): """ Returns true if the "compile project(':<project>')" line exists exists in the file """ for line in source.split("\n"): if re.search(r"(api|compile)\s+project\(['\"]:{}['\"]\)".format(pkg), line): retur...
python
def is_build_linked(source, pkg): """ Returns true if the "compile project(':<project>')" line exists exists in the file """ for line in source.split("\n"): if re.search(r"(api|compile)\s+project\(['\"]:{}['\"]\)".format(pkg), line): retur...
Returns true if the "compile project(':<project>')" line exists exists in the file
https://github.com/codelv/enaml-native-cli/blob/81d6faa7e3dd437956f661c512031e49c0d44b63/enamlnativecli/main.py#L858-L865
codelv/enaml-native-cli
enamlnativecli/main.py
Link.find_packages
def find_packages(path): """ Find all java files matching the "*Package.java" pattern within the given enaml package directory relative to the java source path. """ matches = [] root = join(path, 'src', 'main', 'java') for folder, dirnames, filenames in os.walk(root): ...
python
def find_packages(path): """ Find all java files matching the "*Package.java" pattern within the given enaml package directory relative to the java source path. """ matches = [] root = join(path, 'src', 'main', 'java') for folder, dirnames, filenames in os.walk(root): ...
Find all java files matching the "*Package.java" pattern within the given enaml package directory relative to the java source path.
https://github.com/codelv/enaml-native-cli/blob/81d6faa7e3dd437956f661c512031e49c0d44b63/enamlnativecli/main.py#L868-L881
codelv/enaml-native-cli
enamlnativecli/main.py
Link.is_app_linked
def is_app_linked(source, pkg, java_package): """ Returns true if the compile project line exists exists in the file """ for line in source.split("\n"): if java_package in line: return True return False
python
def is_app_linked(source, pkg, java_package): """ Returns true if the compile project line exists exists in the file """ for line in source.split("\n"): if java_package in line: return True return False
Returns true if the compile project line exists exists in the file
https://github.com/codelv/enaml-native-cli/blob/81d6faa7e3dd437956f661c512031e49c0d44b63/enamlnativecli/main.py#L884-L891
codelv/enaml-native-cli
enamlnativecli/main.py
Link.link_android
def link_android(self, path, pkg): """ Link's the android project to this library. 1. Includes this project's directory in the app's android/settings.gradle It adds: include ':<project-name>' project(':<project-name>').projectDir = new File( ...
python
def link_android(self, path, pkg): """ Link's the android project to this library. 1. Includes this project's directory in the app's android/settings.gradle It adds: include ':<project-name>' project(':<project-name>').projectDir = new File( ...
Link's the android project to this library. 1. Includes this project's directory in the app's android/settings.gradle It adds: include ':<project-name>' project(':<project-name>').projectDir = new File( rootProject.projectDir, '../package...
https://github.com/codelv/enaml-native-cli/blob/81d6faa7e3dd437956f661c512031e49c0d44b63/enamlnativecli/main.py#L893-L1044
codelv/enaml-native-cli
enamlnativecli/main.py
Unlink.run
def run(self, args=None): """ The name IS required here. """ print(Colors.BLUE+"[INFO] Unlinking {}...".format( args.names)+Colors.RESET) for name in args.names: self.unlink(Link.package_dir, name)
python
def run(self, args=None): """ The name IS required here. """ print(Colors.BLUE+"[INFO] Unlinking {}...".format( args.names)+Colors.RESET) for name in args.names: self.unlink(Link.package_dir, name)
The name IS required here.
https://github.com/codelv/enaml-native-cli/blob/81d6faa7e3dd437956f661c512031e49c0d44b63/enamlnativecli/main.py#L1073-L1078
codelv/enaml-native-cli
enamlnativecli/main.py
Unlink.unlink
def unlink(self, path, pkg): """ Unlink the package in the current directory. """ #: Check if a custom unlinker exists to handle unlinking this package for ep in pkg_resources.iter_entry_points( group="enaml_native_unlinker"): if ep.name.replace("-", '_') == p...
python
def unlink(self, path, pkg): """ Unlink the package in the current directory. """ #: Check if a custom unlinker exists to handle unlinking this package for ep in pkg_resources.iter_entry_points( group="enaml_native_unlinker"): if ep.name.replace("-", '_') == p...
Unlink the package in the current directory.
https://github.com/codelv/enaml-native-cli/blob/81d6faa7e3dd437956f661c512031e49c0d44b63/enamlnativecli/main.py#L1080-L1100
codelv/enaml-native-cli
enamlnativecli/main.py
Unlink.unlink_android
def unlink_android(self, path, pkg): """ Unlink's the android project to this library. 1. In the app's android/settings.gradle, it removes the following lines (if they exist): include ':<project-name>' project(':<project-name>').projectDir = new ...
python
def unlink_android(self, path, pkg): """ Unlink's the android project to this library. 1. In the app's android/settings.gradle, it removes the following lines (if they exist): include ':<project-name>' project(':<project-name>').projectDir = new ...
Unlink's the android project to this library. 1. In the app's android/settings.gradle, it removes the following lines (if they exist): include ':<project-name>' project(':<project-name>').projectDir = new File( rootProject.projectDir,...
https://github.com/codelv/enaml-native-cli/blob/81d6faa7e3dd437956f661c512031e49c0d44b63/enamlnativecli/main.py#L1102-L1249
codelv/enaml-native-cli
enamlnativecli/main.py
Server.run_tornado
def run_tornado(self, args): """ Tornado dev server implementation """ server = self import tornado.ioloop import tornado.web import tornado.websocket ioloop = tornado.ioloop.IOLoop.current() class DevWebSocketHandler(tornado.websocket.WebSocketHandler): ...
python
def run_tornado(self, args): """ Tornado dev server implementation """ server = self import tornado.ioloop import tornado.web import tornado.websocket ioloop = tornado.ioloop.IOLoop.current() class DevWebSocketHandler(tornado.websocket.WebSocketHandler): ...
Tornado dev server implementation
https://github.com/codelv/enaml-native-cli/blob/81d6faa7e3dd437956f661c512031e49c0d44b63/enamlnativecli/main.py#L1466-L1502
codelv/enaml-native-cli
enamlnativecli/main.py
Server.run_twisted
def run_twisted(self, args): """ Twisted dev server implementation """ server = self from twisted.internet import reactor from twisted.web import resource from twisted.web.static import File from twisted.web.server import Site from autobahn.twisted.websocket impo...
python
def run_twisted(self, args): """ Twisted dev server implementation """ server = self from twisted.internet import reactor from twisted.web import resource from twisted.web.static import File from twisted.web.server import Site from autobahn.twisted.websocket impo...
Twisted dev server implementation
https://github.com/codelv/enaml-native-cli/blob/81d6faa7e3dd437956f661c512031e49c0d44b63/enamlnativecli/main.py#L1504-L1547
codelv/enaml-native-cli
enamlnativecli/main.py
Server.on_message
def on_message(self, handler, msg): """ In remote debugging mode this simply acts as a forwarding proxy for the two clients. """ if self.remote_debugging: #: Forward to other clients for h in self.handlers: if h != handler: h.wr...
python
def on_message(self, handler, msg): """ In remote debugging mode this simply acts as a forwarding proxy for the two clients. """ if self.remote_debugging: #: Forward to other clients for h in self.handlers: if h != handler: h.wr...
In remote debugging mode this simply acts as a forwarding proxy for the two clients.
https://github.com/codelv/enaml-native-cli/blob/81d6faa7e3dd437956f661c512031e49c0d44b63/enamlnativecli/main.py#L1557-L1567
codelv/enaml-native-cli
enamlnativecli/main.py
Server.send_message
def send_message(self, msg): """ Send a message to the client. This should not be used in remote debugging mode. """ if not self.handlers: return #: Client not connected for h in self.handlers: h.write_message(msg)
python
def send_message(self, msg): """ Send a message to the client. This should not be used in remote debugging mode. """ if not self.handlers: return #: Client not connected for h in self.handlers: h.write_message(msg)
Send a message to the client. This should not be used in remote debugging mode.
https://github.com/codelv/enaml-native-cli/blob/81d6faa7e3dd437956f661c512031e49c0d44b63/enamlnativecli/main.py#L1569-L1577
codelv/enaml-native-cli
enamlnativecli/main.py
EnamlNativeCli._default_commands
def _default_commands(self): """ Build the list of CLI commands by finding subclasses of the Command class Also allows commands to be installed using the "enaml_native_command" entry point. This entry point should return a Command subclass """ commands = [c() for c in...
python
def _default_commands(self): """ Build the list of CLI commands by finding subclasses of the Command class Also allows commands to be installed using the "enaml_native_command" entry point. This entry point should return a Command subclass """ commands = [c() for c in...
Build the list of CLI commands by finding subclasses of the Command class Also allows commands to be installed using the "enaml_native_command" entry point. This entry point should return a Command subclass
https://github.com/codelv/enaml-native-cli/blob/81d6faa7e3dd437956f661c512031e49c0d44b63/enamlnativecli/main.py#L1648-L1668
codelv/enaml-native-cli
enamlnativecli/main.py
EnamlNativeCli._default_ctx
def _default_ctx(self): """ Return the package config or context and normalize some of the values """ if not self.in_app_directory: print("Warning: {} does not exist. Using the default.".format( self.package)) ctx = {} else: ...
python
def _default_ctx(self): """ Return the package config or context and normalize some of the values """ if not self.in_app_directory: print("Warning: {} does not exist. Using the default.".format( self.package)) ctx = {} else: ...
Return the package config or context and normalize some of the values
https://github.com/codelv/enaml-native-cli/blob/81d6faa7e3dd437956f661c512031e49c0d44b63/enamlnativecli/main.py#L1678-L1706
codelv/enaml-native-cli
enamlnativecli/main.py
EnamlNativeCli._default_parser
def _default_parser(self): """ Generate a parser using the command list """ parser = ArgumentParser(prog='enaml-native') #: Build commands by name cmds = {c.title: c for c in self.commands} #: Build parser, prepare commands subparsers = parser.add_subparsers() f...
python
def _default_parser(self): """ Generate a parser using the command list """ parser = ArgumentParser(prog='enaml-native') #: Build commands by name cmds = {c.title: c for c in self.commands} #: Build parser, prepare commands subparsers = parser.add_subparsers() f...
Generate a parser using the command list
https://github.com/codelv/enaml-native-cli/blob/81d6faa7e3dd437956f661c512031e49c0d44b63/enamlnativecli/main.py#L1708-L1727
codelv/enaml-native-cli
enamlnativecli/main.py
EnamlNativeCli.start
def start(self): """ Run the commands""" self.check_dependencies() self.args = self.parser.parse_args() # Python 3 doesn't set the cmd if no args are given if not hasattr(self.args, 'cmd'): self.parser.print_help() return cmd = self.args.cmd ...
python
def start(self): """ Run the commands""" self.check_dependencies() self.args = self.parser.parse_args() # Python 3 doesn't set the cmd if no args are given if not hasattr(self.args, 'cmd'): self.parser.print_help() return cmd = self.args.cmd ...
Run the commands
https://github.com/codelv/enaml-native-cli/blob/81d6faa7e3dd437956f661c512031e49c0d44b63/enamlnativecli/main.py#L1741-L1759
codelv/enaml-native-cli
setup.py
find_data
def find_data(folder): """ Include everything in the folder """ for (path, directories, filenames) in os.walk(folder): for filename in filenames: yield os.path.join('..', path, filename)
python
def find_data(folder): """ Include everything in the folder """ for (path, directories, filenames) in os.walk(folder): for filename in filenames: yield os.path.join('..', path, filename)
Include everything in the folder
https://github.com/codelv/enaml-native-cli/blob/81d6faa7e3dd437956f661c512031e49c0d44b63/setup.py#L16-L20
glyph/horsephrase
horsephrase/_implementation.py
generate
def generate(number=4, choice=SystemRandom().choice, words=words, joiner=" "): """ Generate a random passphrase from the GSL. """ return joiner.join(choice(words) for each in range(number))
python
def generate(number=4, choice=SystemRandom().choice, words=words, joiner=" "): """ Generate a random passphrase from the GSL. """ return joiner.join(choice(words) for each in range(number))
Generate a random passphrase from the GSL.
https://github.com/glyph/horsephrase/blob/f646094a40d69e01012e57e29d5eabb50ae481e3/horsephrase/_implementation.py#L11-L15
jtauber/sebastian
sebastian/midi/write_midi.py
Trk.write_meta_info
def write_meta_info(self, byte1, byte2, data): "Worker method for writing meta info" write_varlen(self.data, 0) # tick write_byte(self.data, byte1) write_byte(self.data, byte2) write_varlen(self.data, len(data)) write_chars(self.data, data)
python
def write_meta_info(self, byte1, byte2, data): "Worker method for writing meta info" write_varlen(self.data, 0) # tick write_byte(self.data, byte1) write_byte(self.data, byte2) write_varlen(self.data, len(data)) write_chars(self.data, data)
Worker method for writing meta info
https://github.com/jtauber/sebastian/blob/4e460c3aeab332b45c74fe78e65e76ec87d5cfa8/sebastian/midi/write_midi.py#L135-L141
glyph/horsephrase
horsephrase/_guess_guess.py
how_long
def how_long(length=4, choices=len(words), speed=1000 * 1000 * 1000 * 1000, optimism=2): """ How long might it take to guess a password? @param length: the number of words that we're going to choose. @type length: L{int} @param choice: the number of words we might choose between. ...
python
def how_long(length=4, choices=len(words), speed=1000 * 1000 * 1000 * 1000, optimism=2): """ How long might it take to guess a password? @param length: the number of words that we're going to choose. @type length: L{int} @param choice: the number of words we might choose between. ...
How long might it take to guess a password? @param length: the number of words that we're going to choose. @type length: L{int} @param choice: the number of words we might choose between. @type choice: L{int} @param speed: the speed of our hypothetical password guesser, in guesses per sec...
https://github.com/glyph/horsephrase/blob/f646094a40d69e01012e57e29d5eabb50ae481e3/horsephrase/_guess_guess.py#L9-L29
glyph/horsephrase
horsephrase/_guess_guess.py
redivmod
def redivmod(initial_value, factors): """ Chop up C{initial_value} according to the list of C{factors} and return a formatted string. """ result = [] value = initial_value for divisor, label in factors: if not divisor: remainder = value if not remainder: ...
python
def redivmod(initial_value, factors): """ Chop up C{initial_value} according to the list of C{factors} and return a formatted string. """ result = [] value = initial_value for divisor, label in factors: if not divisor: remainder = value if not remainder: ...
Chop up C{initial_value} according to the list of C{factors} and return a formatted string.
https://github.com/glyph/horsephrase/blob/f646094a40d69e01012e57e29d5eabb50ae481e3/horsephrase/_guess_guess.py#L33-L62
jtauber/sebastian
sebastian/core/elements.py
SeqBase.zip
def zip(self, other): """ zips two sequences unifying the corresponding points. """ return self.__class__(p1 % p2 for p1, p2 in zip(self, other))
python
def zip(self, other): """ zips two sequences unifying the corresponding points. """ return self.__class__(p1 % p2 for p1, p2 in zip(self, other))
zips two sequences unifying the corresponding points.
https://github.com/jtauber/sebastian/blob/4e460c3aeab332b45c74fe78e65e76ec87d5cfa8/sebastian/core/elements.py#L75-L79
jtauber/sebastian
sebastian/core/elements.py
SeqBase.display
def display(self, format="png"): """ Return an object that can be used to display this sequence. This is used for IPython Notebook. :param format: "png" or "svg" """ from sebastian.core.transforms import lilypond seq = HSeq(self) | lilypond() lily_output...
python
def display(self, format="png"): """ Return an object that can be used to display this sequence. This is used for IPython Notebook. :param format: "png" or "svg" """ from sebastian.core.transforms import lilypond seq = HSeq(self) | lilypond() lily_output...
Return an object that can be used to display this sequence. This is used for IPython Notebook. :param format: "png" or "svg"
https://github.com/jtauber/sebastian/blob/4e460c3aeab332b45c74fe78e65e76ec87d5cfa8/sebastian/core/elements.py#L84-L125
jtauber/sebastian
sebastian/core/elements.py
HSeq.append
def append(self, point): """ appends a copy of the given point to this sequence """ point = Point(point) self._elements.append(point)
python
def append(self, point): """ appends a copy of the given point to this sequence """ point = Point(point) self._elements.append(point)
appends a copy of the given point to this sequence
https://github.com/jtauber/sebastian/blob/4e460c3aeab332b45c74fe78e65e76ec87d5cfa8/sebastian/core/elements.py#L226-L231
jtauber/sebastian
sebastian/core/elements.py
HSeq.repeat
def repeat(self, count): """ repeat sequence given number of times to produce a new sequence """ x = HSeq() for i in range(count): x = x.concatenate(self) return x
python
def repeat(self, count): """ repeat sequence given number of times to produce a new sequence """ x = HSeq() for i in range(count): x = x.concatenate(self) return x
repeat sequence given number of times to produce a new sequence
https://github.com/jtauber/sebastian/blob/4e460c3aeab332b45c74fe78e65e76ec87d5cfa8/sebastian/core/elements.py#L239-L246
jtauber/sebastian
sebastian/core/elements.py
HSeq.subseq
def subseq(self, start_offset=0, end_offset=None): """ Return a subset of the sequence starting at start_offset (defaulting to the beginning) ending at end_offset (None representing the end, whih is the default) Raises ValueError if duration_64 is missing on any element "...
python
def subseq(self, start_offset=0, end_offset=None): """ Return a subset of the sequence starting at start_offset (defaulting to the beginning) ending at end_offset (None representing the end, whih is the default) Raises ValueError if duration_64 is missing on any element "...
Return a subset of the sequence starting at start_offset (defaulting to the beginning) ending at end_offset (None representing the end, whih is the default) Raises ValueError if duration_64 is missing on any element
https://github.com/jtauber/sebastian/blob/4e460c3aeab332b45c74fe78e65e76ec87d5cfa8/sebastian/core/elements.py#L248-L273
jtauber/sebastian
projects/mozart_k545/first_movement.py
arpeggio
def arpeggio(pattern, point): """ turns each subsequence into an arpeggio matching the given ``pattern``. """ point['sequence'] = HSeq(point['sequence'][i] for i in pattern) return point
python
def arpeggio(pattern, point): """ turns each subsequence into an arpeggio matching the given ``pattern``. """ point['sequence'] = HSeq(point['sequence'][i] for i in pattern) return point
turns each subsequence into an arpeggio matching the given ``pattern``.
https://github.com/jtauber/sebastian/blob/4e460c3aeab332b45c74fe78e65e76ec87d5cfa8/projects/mozart_k545/first_movement.py#L26-L31
jtauber/sebastian
projects/mozart_k545/first_movement.py
fill
def fill(duration, point): """ fills the subsequence of the point with repetitions of its subsequence and sets the ``duration`` of each point. """ point['sequence'] = point['sequence'] * (point[DURATION_64] / (8 * duration)) | add({DURATION_64: duration}) return point
python
def fill(duration, point): """ fills the subsequence of the point with repetitions of its subsequence and sets the ``duration`` of each point. """ point['sequence'] = point['sequence'] * (point[DURATION_64] / (8 * duration)) | add({DURATION_64: duration}) return point
fills the subsequence of the point with repetitions of its subsequence and sets the ``duration`` of each point.
https://github.com/jtauber/sebastian/blob/4e460c3aeab332b45c74fe78e65e76ec87d5cfa8/projects/mozart_k545/first_movement.py#L35-L41
jtauber/sebastian
projects/mozart_k545/first_movement.py
expand
def expand(sequence): """ expands a tree of sequences into a single, flat sequence, recursively. """ expanse = [] for point in sequence: if 'sequence' in point: expanse.extend(expand(point['sequence'])) else: expanse.append(point) return sequence.__class__...
python
def expand(sequence): """ expands a tree of sequences into a single, flat sequence, recursively. """ expanse = [] for point in sequence: if 'sequence' in point: expanse.extend(expand(point['sequence'])) else: expanse.append(point) return sequence.__class__...
expands a tree of sequences into a single, flat sequence, recursively.
https://github.com/jtauber/sebastian/blob/4e460c3aeab332b45c74fe78e65e76ec87d5cfa8/projects/mozart_k545/first_movement.py#L44-L54
jtauber/sebastian
projects/mozart_k545/first_movement.py
debug
def debug(sequence): """ adds information to the sequence for better debugging, currently only an index property on each point in the sequence. """ points = [] for i, p in enumerate(sequence): copy = Point(p) copy['index'] = i points.append(copy) return sequence.__cla...
python
def debug(sequence): """ adds information to the sequence for better debugging, currently only an index property on each point in the sequence. """ points = [] for i, p in enumerate(sequence): copy = Point(p) copy['index'] = i points.append(copy) return sequence.__cla...
adds information to the sequence for better debugging, currently only an index property on each point in the sequence.
https://github.com/jtauber/sebastian/blob/4e460c3aeab332b45c74fe78e65e76ec87d5cfa8/projects/mozart_k545/first_movement.py#L57-L67
jtauber/sebastian
sebastian/core/transforms.py
transform_sequence
def transform_sequence(f): """ A decorator to take a function operating on a point and turn it into a function returning a callable operating on a sequence. The functions passed to this decorator must define a kwarg called "point", or have point be the last positional argument """ @wraps(f) ...
python
def transform_sequence(f): """ A decorator to take a function operating on a point and turn it into a function returning a callable operating on a sequence. The functions passed to this decorator must define a kwarg called "point", or have point be the last positional argument """ @wraps(f) ...
A decorator to take a function operating on a point and turn it into a function returning a callable operating on a sequence. The functions passed to this decorator must define a kwarg called "point", or have point be the last positional argument
https://github.com/jtauber/sebastian/blob/4e460c3aeab332b45c74fe78e65e76ec87d5cfa8/sebastian/core/transforms.py#L8-L24
jtauber/sebastian
sebastian/core/transforms.py
subseq
def subseq(start_offset=0, end_offset=None): """ Return a portion of the input sequence """ def _(sequence): return sequence.subseq(start_offset, end_offset) return _
python
def subseq(start_offset=0, end_offset=None): """ Return a portion of the input sequence """ def _(sequence): return sequence.subseq(start_offset, end_offset) return _
Return a portion of the input sequence
https://github.com/jtauber/sebastian/blob/4e460c3aeab332b45c74fe78e65e76ec87d5cfa8/sebastian/core/transforms.py#L95-L101
jtauber/sebastian
sebastian/core/transforms.py
lilypond
def lilypond(point): """ Generate lilypond representation for a point """ #If lilypond already computed, leave as is if "lilypond" in point: return point #Defaults: pitch_string = "" octave_string = "" duration_string = "" preamble = "" dynamic_string = "" if "pi...
python
def lilypond(point): """ Generate lilypond representation for a point """ #If lilypond already computed, leave as is if "lilypond" in point: return point #Defaults: pitch_string = "" octave_string = "" duration_string = "" preamble = "" dynamic_string = "" if "pi...
Generate lilypond representation for a point
https://github.com/jtauber/sebastian/blob/4e460c3aeab332b45c74fe78e65e76ec87d5cfa8/sebastian/core/transforms.py#L131-L188
jtauber/sebastian
sebastian/core/transforms.py
dynamics
def dynamics(start, end=None): """ Apply dynamics to a sequence. If end is specified, it will crescendo or diminuendo linearly from start to end dynamics. You can pass any of these strings as dynamic markers: ['pppppp', 'ppppp', 'pppp', 'ppp', 'pp', 'p', 'mp', 'mf', 'f', 'ff', 'fff', ''ffff] Args: ...
python
def dynamics(start, end=None): """ Apply dynamics to a sequence. If end is specified, it will crescendo or diminuendo linearly from start to end dynamics. You can pass any of these strings as dynamic markers: ['pppppp', 'ppppp', 'pppp', 'ppp', 'pp', 'p', 'mp', 'mf', 'f', 'ff', 'fff', ''ffff] Args: ...
Apply dynamics to a sequence. If end is specified, it will crescendo or diminuendo linearly from start to end dynamics. You can pass any of these strings as dynamic markers: ['pppppp', 'ppppp', 'pppp', 'ppp', 'pp', 'p', 'mp', 'mf', 'f', 'ff', 'fff', ''ffff] Args: start: beginning dynamic marker, if no...
https://github.com/jtauber/sebastian/blob/4e460c3aeab332b45c74fe78e65e76ec87d5cfa8/sebastian/core/transforms.py#L206-L257
wikimedia/editquality
editquality/utilities/extract_damaging.py
user_blocks
def user_blocks(user_text, session): """ Returns a list of blocks for a single user """ logger.debug("Getting blocks for {0}".format(user_text)) doc = session.get(action='query', list='blocks', bkusers=user_text, bkprop=['id', 'timestamp']) return [mwtypes.Timestamp(b['time...
python
def user_blocks(user_text, session): """ Returns a list of blocks for a single user """ logger.debug("Getting blocks for {0}".format(user_text)) doc = session.get(action='query', list='blocks', bkusers=user_text, bkprop=['id', 'timestamp']) return [mwtypes.Timestamp(b['time...
Returns a list of blocks for a single user
https://github.com/wikimedia/editquality/blob/73bab7bdd0ef3dba9a000f91f2fd810b1772d1f0/editquality/utilities/extract_damaging.py#L139-L146
wikimedia/editquality
editquality/utilities/autolabel.py
get_user_blocks
def get_user_blocks(session, user_text): """ Returns a list of blocks for a single user """ logger.debug("Getting user_blocks for {0}".format(user_text)) doc = session.get(action='query', list='blocks', bkusers=user_text, bkprop=['id']) return doc['query']['blocks']
python
def get_user_blocks(session, user_text): """ Returns a list of blocks for a single user """ logger.debug("Getting user_blocks for {0}".format(user_text)) doc = session.get(action='query', list='blocks', bkusers=user_text, bkprop=['id']) return doc['query']['blocks']
Returns a list of blocks for a single user
https://github.com/wikimedia/editquality/blob/73bab7bdd0ef3dba9a000f91f2fd810b1772d1f0/editquality/utilities/autolabel.py#L306-L313
wikimedia/editquality
editquality/utilities/autolabel.py
query_revisions_by_revids
def query_revisions_by_revids(session, revids, **params): """ Gets a set of revisions by their IDs by repeatedly querying in batches. If an ID cannot be found, it is ignored. """ doc = session.get(action='query', prop='revisions', revids=revids, **params) for page_doc in d...
python
def query_revisions_by_revids(session, revids, **params): """ Gets a set of revisions by their IDs by repeatedly querying in batches. If an ID cannot be found, it is ignored. """ doc = session.get(action='query', prop='revisions', revids=revids, **params) for page_doc in d...
Gets a set of revisions by their IDs by repeatedly querying in batches. If an ID cannot be found, it is ignored.
https://github.com/wikimedia/editquality/blob/73bab7bdd0ef3dba9a000f91f2fd810b1772d1f0/editquality/utilities/autolabel.py#L316-L331
wikimedia/editquality
editquality/codegen/generate.py
generate
def generate(variables, templates_path, main_template): """ :Parameters: variables : dict Template parameters, passed through. templates_path : str Root directory for transclusions. main_template : str Contents of the main template. Returns the re...
python
def generate(variables, templates_path, main_template): """ :Parameters: variables : dict Template parameters, passed through. templates_path : str Root directory for transclusions. main_template : str Contents of the main template. Returns the re...
:Parameters: variables : dict Template parameters, passed through. templates_path : str Root directory for transclusions. main_template : str Contents of the main template. Returns the rendered output.
https://github.com/wikimedia/editquality/blob/73bab7bdd0ef3dba9a000f91f2fd810b1772d1f0/editquality/codegen/generate.py#L4-L33
PlaidWeb/Publ
publ/category.py
load_metafile
def load_metafile(filepath): """ Load a metadata file from the filesystem """ try: with open(filepath, 'r', encoding='utf-8') as file: return email.message_from_file(file) except FileNotFoundError: logger.warning("Category file %s not found", filepath) orm.delete(c for c ...
python
def load_metafile(filepath): """ Load a metadata file from the filesystem """ try: with open(filepath, 'r', encoding='utf-8') as file: return email.message_from_file(file) except FileNotFoundError: logger.warning("Category file %s not found", filepath) orm.delete(c for c ...
Load a metadata file from the filesystem
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/category.py#L30-L40
PlaidWeb/Publ
publ/category.py
scan_file
def scan_file(fullpath, relpath): """ scan a file and put it into the index """ load_metafile.cache_clear() meta = load_metafile(fullpath) if not meta: return True # update the category meta file mapping category = meta.get('Category', utils.get_category(relpath)) values = { ...
python
def scan_file(fullpath, relpath): """ scan a file and put it into the index """ load_metafile.cache_clear() meta = load_metafile(fullpath) if not meta: return True # update the category meta file mapping category = meta.get('Category', utils.get_category(relpath)) values = { ...
scan a file and put it into the index
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/category.py#L283-L314
PlaidWeb/Publ
publ/category.py
Category.name
def name(self): """ Get the display name of the category """ if self._meta and self._meta.get('name'): # get it from the meta file return self._meta.get('name') # infer it from the basename return self.basename.replace('_', ' ').title()
python
def name(self): """ Get the display name of the category """ if self._meta and self._meta.get('name'): # get it from the meta file return self._meta.get('name') # infer it from the basename return self.basename.replace('_', ' ').title()
Get the display name of the category
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/category.py#L118-L124
PlaidWeb/Publ
publ/category.py
Category.description
def description(self): """ Get the textual description of the category """ if self._meta and self._meta.get_payload(): return utils.TrueCallableProxy(self._description) return utils.CallableProxy(None)
python
def description(self): """ Get the textual description of the category """ if self._meta and self._meta.get_payload(): return utils.TrueCallableProxy(self._description) return utils.CallableProxy(None)
Get the textual description of the category
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/category.py#L127-L131
PlaidWeb/Publ
publ/category.py
Category.breadcrumb
def breadcrumb(self): """ Get the category hierarchy leading up to this category, including root and self. For example, path/to/long/category will return a list containing Category('path'), Category('path/to'), and Category('path/to/long'). """ ret = [] here = se...
python
def breadcrumb(self): """ Get the category hierarchy leading up to this category, including root and self. For example, path/to/long/category will return a list containing Category('path'), Category('path/to'), and Category('path/to/long'). """ ret = [] here = se...
Get the category hierarchy leading up to this category, including root and self. For example, path/to/long/category will return a list containing Category('path'), Category('path/to'), and Category('path/to/long').
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/category.py#L139-L151
PlaidWeb/Publ
publ/category.py
Category.sort_name
def sort_name(self): """ Get the sorting name of this category """ if self._record and self._record.sort_name: return self._record.sort_name return self.name
python
def sort_name(self): """ Get the sorting name of this category """ if self._record and self._record.sort_name: return self._record.sort_name return self.name
Get the sorting name of this category
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/category.py#L154-L158
PlaidWeb/Publ
publ/category.py
Category.parent
def parent(self): """ Get the parent category """ if self.path: return Category(os.path.dirname(self.path)) return None
python
def parent(self): """ Get the parent category """ if self.path: return Category(os.path.dirname(self.path)) return None
Get the parent category
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/category.py#L224-L228
PlaidWeb/Publ
publ/category.py
Category._get_subcats
def _get_subcats(self, recurse=False): """ Get the subcategories of this category recurse -- whether to include their subcategories as well """ if recurse: # No need to filter return sorted([Category(e) for e in self._subcats_recursive], ...
python
def _get_subcats(self, recurse=False): """ Get the subcategories of this category recurse -- whether to include their subcategories as well """ if recurse: # No need to filter return sorted([Category(e) for e in self._subcats_recursive], ...
Get the subcategories of this category recurse -- whether to include their subcategories as well
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/category.py#L237-L261
PlaidWeb/Publ
publ/category.py
Category._first
def _first(self, **spec): """ Get the earliest entry in this category, optionally including subcategories """ for record in self._entries(spec).order_by(model.Entry.local_date, model.Entry.id)[:1]: return entry.Entry(record) return N...
python
def _first(self, **spec): """ Get the earliest entry in this category, optionally including subcategories """ for record in self._entries(spec).order_by(model.Entry.local_date, model.Entry.id)[:1]: return entry.Entry(record) return N...
Get the earliest entry in this category, optionally including subcategories
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/category.py#L267-L272
PlaidWeb/Publ
publ/category.py
Category._last
def _last(self, **spec): """ Get the latest entry in this category, optionally including subcategories """ for record in self._entries(spec).order_by(orm.desc(model.Entry.local_date), orm.desc(model.Entry.id))[:1]: return entry.Entry(record)...
python
def _last(self, **spec): """ Get the latest entry in this category, optionally including subcategories """ for record in self._entries(spec).order_by(orm.desc(model.Entry.local_date), orm.desc(model.Entry.id))[:1]: return entry.Entry(record)...
Get the latest entry in this category, optionally including subcategories
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/category.py#L274-L279
PlaidWeb/Publ
publ/utils.py
parse_date
def parse_date(datestr): """ Parse a date expression into a tuple of: (start_date, span_type, span_format) Arguments: datestr -- A date specification, in the format of YYYY-MM-DD (dashes optional) """ match = re.match( r'([0-9]{4})(-?([0-9]{1,2}))?(-?([0-9]{1,2}))?(_w)?$', dat...
python
def parse_date(datestr): """ Parse a date expression into a tuple of: (start_date, span_type, span_format) Arguments: datestr -- A date specification, in the format of YYYY-MM-DD (dashes optional) """ match = re.match( r'([0-9]{4})(-?([0-9]{1,2}))?(-?([0-9]{1,2}))?(_w)?$', dat...
Parse a date expression into a tuple of: (start_date, span_type, span_format) Arguments: datestr -- A date specification, in the format of YYYY-MM-DD (dashes optional)
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/utils.py#L94-L123
PlaidWeb/Publ
publ/utils.py
find_file
def find_file(path, search_path): """ Find a file by relative path. Arguments: path -- the image's filename search_path -- a list of directories to check in Returns: the resolved file path """ if isinstance(search_path, str): search_path = [search_path] for relative in search_path...
python
def find_file(path, search_path): """ Find a file by relative path. Arguments: path -- the image's filename search_path -- a list of directories to check in Returns: the resolved file path """ if isinstance(search_path, str): search_path = [search_path] for relative in search_path...
Find a file by relative path. Arguments: path -- the image's filename search_path -- a list of directories to check in Returns: the resolved file path
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/utils.py#L126-L142
PlaidWeb/Publ
publ/utils.py
find_entry
def find_entry(rel_path, search_path): """ Find an entry by relative path. Arguments: path -- the entry's filename (or entry ID) search_path -- a list of directories to check in Returns: the resolved Entry object """ from . import entry # pylint:disable=cyclic-import try: entry_...
python
def find_entry(rel_path, search_path): """ Find an entry by relative path. Arguments: path -- the entry's filename (or entry ID) search_path -- a list of directories to check in Returns: the resolved Entry object """ from . import entry # pylint:disable=cyclic-import try: entry_...
Find an entry by relative path. Arguments: path -- the entry's filename (or entry ID) search_path -- a list of directories to check in Returns: the resolved Entry object
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/utils.py#L145-L173
PlaidWeb/Publ
publ/utils.py
static_url
def static_url(path, absolute=False): """ Shorthand for returning a URL for the requested static file. Arguments: path -- the path to the file (relative to the static files directory) absolute -- whether the link should be absolute or relative """ if os.sep != '/': path = '/'.join(pat...
python
def static_url(path, absolute=False): """ Shorthand for returning a URL for the requested static file. Arguments: path -- the path to the file (relative to the static files directory) absolute -- whether the link should be absolute or relative """ if os.sep != '/': path = '/'.join(pat...
Shorthand for returning a URL for the requested static file. Arguments: path -- the path to the file (relative to the static files directory) absolute -- whether the link should be absolute or relative
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/utils.py#L181-L193
PlaidWeb/Publ
publ/utils.py
make_tag
def make_tag(name, attrs, start_end=False): """ Build an HTML tag from the given name and attributes. Arguments: name -- the name of the tag (p, div, etc.) attrs -- a dict of attributes to apply to the tag start_end -- whether this tag should be self-closing """ text = '<' + name if ...
python
def make_tag(name, attrs, start_end=False): """ Build an HTML tag from the given name and attributes. Arguments: name -- the name of the tag (p, div, etc.) attrs -- a dict of attributes to apply to the tag start_end -- whether this tag should be self-closing """ text = '<' + name if ...
Build an HTML tag from the given name and attributes. Arguments: name -- the name of the tag (p, div, etc.) attrs -- a dict of attributes to apply to the tag start_end -- whether this tag should be self-closing
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/utils.py#L196-L222
PlaidWeb/Publ
publ/utils.py
file_fingerprint
def file_fingerprint(fullpath): """ Get a metadata fingerprint for a file """ stat = os.stat(fullpath) return ','.join([str(value) for value in [stat.st_ino, stat.st_mtime, stat.st_size] if value])
python
def file_fingerprint(fullpath): """ Get a metadata fingerprint for a file """ stat = os.stat(fullpath) return ','.join([str(value) for value in [stat.st_ino, stat.st_mtime, stat.st_size] if value])
Get a metadata fingerprint for a file
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/utils.py#L225-L228
PlaidWeb/Publ
publ/utils.py
remap_args
def remap_args(input_args, remap): """ Generate a new argument list by remapping keys. The 'remap' dict maps from destination key -> priority list of source keys """ out_args = input_args for dest_key, src_keys in remap.items(): remap_value = None if isinstance(src_keys, str): ...
python
def remap_args(input_args, remap): """ Generate a new argument list by remapping keys. The 'remap' dict maps from destination key -> priority list of source keys """ out_args = input_args for dest_key, src_keys in remap.items(): remap_value = None if isinstance(src_keys, str): ...
Generate a new argument list by remapping keys. The 'remap' dict maps from destination key -> priority list of source keys
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/utils.py#L231-L251
PlaidWeb/Publ
publ/utils.py
remap_link_target
def remap_link_target(path, absolute=False): """ remap a link target to a static URL if it's prefixed with @ """ if path.startswith('@'): # static resource return static_url(path[1:], absolute=absolute) if absolute: # absolute-ify whatever the URL is return urllib.parse.urlj...
python
def remap_link_target(path, absolute=False): """ remap a link target to a static URL if it's prefixed with @ """ if path.startswith('@'): # static resource return static_url(path[1:], absolute=absolute) if absolute: # absolute-ify whatever the URL is return urllib.parse.urlj...
remap a link target to a static URL if it's prefixed with @
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/utils.py#L254-L264
PlaidWeb/Publ
publ/utils.py
get_category
def get_category(filename): """ Get a default category name from a filename in a cross-platform manner """ return '/'.join(os.path.dirname(filename).split(os.sep))
python
def get_category(filename): """ Get a default category name from a filename in a cross-platform manner """ return '/'.join(os.path.dirname(filename).split(os.sep))
Get a default category name from a filename in a cross-platform manner
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/utils.py#L267-L269
PlaidWeb/Publ
publ/utils.py
CallableProxy._default
def _default(self): """ Get the default function return """ if self._default_args: return self._func( *self._default_args, **self._default_kwargs) return self._func(**self._default_kwargs)
python
def _default(self): """ Get the default function return """ if self._default_args: return self._func( *self._default_args, **self._default_kwargs) return self._func(**self._default_kwargs)
Get the default function return
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/utils.py#L35-L43
PlaidWeb/Publ
publ/model.py
setup
def setup(): """ Set up the database """ try: db.bind(**config.database_config) except OSError: # Attempted to connect to a file-based database where the file didn't # exist db.bind(**config.database_config, create_db=True) rebuild = True try: db.generate_ma...
python
def setup(): """ Set up the database """ try: db.bind(**config.database_config) except OSError: # Attempted to connect to a file-based database where the file didn't # exist db.bind(**config.database_config, create_db=True) rebuild = True try: db.generate_ma...
Set up the database
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/model.py#L126-L163
PlaidWeb/Publ
publ/model.py
Entry.visible
def visible(self): """ Returns true if the entry should be viewable """ return self.status not in (PublishStatus.DRAFT.value, PublishStatus.GONE.value)
python
def visible(self): """ Returns true if the entry should be viewable """ return self.status not in (PublishStatus.DRAFT.value, PublishStatus.GONE.value)
Returns true if the entry should be viewable
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/model.py#L78-L81
PlaidWeb/Publ
publ/cards.py
extract_card
def extract_card(text, config, image_search_path): """ Extract card data based on the provided texts. """ card = CardData() parser = CardParser(card, config, image_search_path) misaka.Markdown(parser, extensions=markdown.ENABLED_EXTENSIONS)(text) return card
python
def extract_card(text, config, image_search_path): """ Extract card data based on the provided texts. """ card = CardData() parser = CardParser(card, config, image_search_path) misaka.Markdown(parser, extensions=markdown.ENABLED_EXTENSIONS)(text) return card
Extract card data based on the provided texts.
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/cards.py#L90-L96
PlaidWeb/Publ
publ/cards.py
CardParser.paragraph
def paragraph(self, content): """ Turn the first paragraph of text into the summary text """ if not self._out.description: self._out.description = content return ' '
python
def paragraph(self, content): """ Turn the first paragraph of text into the summary text """ if not self._out.description: self._out.description = content return ' '
Turn the first paragraph of text into the summary text
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/cards.py#L33-L37
PlaidWeb/Publ
publ/cards.py
CardParser.image
def image(self, raw_url, title='', alt=''): ''' extract the images ''' max_images = self._config.get('count') if max_images is not None and len(self._out.images) >= max_images: # We already have enough images, so bail out return ' ' image_specs = raw_url ...
python
def image(self, raw_url, title='', alt=''): ''' extract the images ''' max_images = self._config.get('count') if max_images is not None and len(self._out.images) >= max_images: # We already have enough images, so bail out return ' ' image_specs = raw_url ...
extract the images
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/cards.py#L39-L62
PlaidWeb/Publ
publ/cards.py
CardParser._render_image
def _render_image(self, spec, alt=''): """ Given an image spec, try to turn it into a card image per the configuration """ # pylint: disable=unused-argument try: path, image_args, _ = image.parse_image_spec(spec) except Exception as err: # pylint: disable=broad-except ...
python
def _render_image(self, spec, alt=''): """ Given an image spec, try to turn it into a card image per the configuration """ # pylint: disable=unused-argument try: path, image_args, _ = image.parse_image_spec(spec) except Exception as err: # pylint: disable=broad-except ...
Given an image spec, try to turn it into a card image per the configuration
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/cards.py#L71-L87
PlaidWeb/Publ
publ/__init__.py
publ
def publ(name, cfg): """ Create a Flask app and configure it for use with Publ """ config.setup(cfg) app = _PublApp(name, template_folder=config.template_folder, static_folder=config.static_folder, static_url_path=config.static_url_path) for ro...
python
def publ(name, cfg): """ Create a Flask app and configure it for use with Publ """ config.setup(cfg) app = _PublApp(name, template_folder=config.template_folder, static_folder=config.static_folder, static_url_path=config.static_url_path) for ro...
Create a Flask app and configure it for use with Publ
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/__init__.py#L56-L135
PlaidWeb/Publ
publ/__init__.py
startup
def startup(): """ Startup routine for initiating the content indexer """ model.setup() index.scan_index(config.content_folder) index.background_scan(config.content_folder)
python
def startup(): """ Startup routine for initiating the content indexer """ model.setup() index.scan_index(config.content_folder) index.background_scan(config.content_folder)
Startup routine for initiating the content indexer
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/__init__.py#L141-L145
PlaidWeb/Publ
publ/__init__.py
set_cache_expiry
def set_cache_expiry(response): """ Set the cache control headers """ if response.cache_control.max_age is None and 'CACHE_DEFAULT_TIMEOUT' in config.cache: response.cache_control.max_age = config.cache['CACHE_DEFAULT_TIMEOUT'] return response
python
def set_cache_expiry(response): """ Set the cache control headers """ if response.cache_control.max_age is None and 'CACHE_DEFAULT_TIMEOUT' in config.cache: response.cache_control.max_age = config.cache['CACHE_DEFAULT_TIMEOUT'] return response
Set the cache control headers
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/__init__.py#L148-L152
PlaidWeb/Publ
publ/__init__.py
_PublApp.path_alias_regex
def path_alias_regex(self, regex): """ A decorator that adds a path-alias regular expression; calls add_path_regex """ def decorator(func): """ Adds the function to the regular expression alias list """ self.add_path_regex(regex, func) return decorator
python
def path_alias_regex(self, regex): """ A decorator that adds a path-alias regular expression; calls add_path_regex """ def decorator(func): """ Adds the function to the regular expression alias list """ self.add_path_regex(regex, func) return decorator
A decorator that adds a path-alias regular expression; calls add_path_regex
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/__init__.py#L24-L30
PlaidWeb/Publ
publ/__init__.py
_PublApp.get_path_regex
def get_path_regex(self, path): """ Evaluate the registered path-alias regular expressions """ for regex, func in self._regex_map: match = re.match(regex, path) if match: return func(match) return None, None
python
def get_path_regex(self, path): """ Evaluate the registered path-alias regular expressions """ for regex, func in self._regex_map: match = re.match(regex, path) if match: return func(match) return None, None
Evaluate the registered path-alias regular expressions
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/__init__.py#L46-L53
PlaidWeb/Publ
publ/entry.py
guess_title
def guess_title(basename): """ Attempt to guess the title from the filename """ base, _ = os.path.splitext(basename) return re.sub(r'[ _-]+', r' ', base).title()
python
def guess_title(basename): """ Attempt to guess the title from the filename """ base, _ = os.path.splitext(basename) return re.sub(r'[ _-]+', r' ', base).title()
Attempt to guess the title from the filename
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/entry.py#L374-L378
PlaidWeb/Publ
publ/entry.py
get_entry_id
def get_entry_id(entry, fullpath, assign_id): """ Get or generate an entry ID for an entry """ warn_duplicate = False if 'Entry-ID' in entry: entry_id = int(entry['Entry-ID']) else: entry_id = None # See if we've inadvertently duplicated an entry ID if entry_id: try: ...
python
def get_entry_id(entry, fullpath, assign_id): """ Get or generate an entry ID for an entry """ warn_duplicate = False if 'Entry-ID' in entry: entry_id = int(entry['Entry-ID']) else: entry_id = None # See if we've inadvertently duplicated an entry ID if entry_id: try: ...
Get or generate an entry ID for an entry
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/entry.py#L381-L434
PlaidWeb/Publ
publ/entry.py
save_file
def save_file(fullpath, entry): """ Save a message file out, without mangling the headers """ with tempfile.NamedTemporaryFile('w', delete=False) as file: tmpfile = file.name # we can't just use file.write(str(entry)) because otherwise the # headers "helpfully" do MIME encoding normaliza...
python
def save_file(fullpath, entry): """ Save a message file out, without mangling the headers """ with tempfile.NamedTemporaryFile('w', delete=False) as file: tmpfile = file.name # we can't just use file.write(str(entry)) because otherwise the # headers "helpfully" do MIME encoding normaliza...
Save a message file out, without mangling the headers
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/entry.py#L437-L449
PlaidWeb/Publ
publ/entry.py
scan_file
def scan_file(fullpath, relpath, assign_id): """ scan a file and put it into the index """ # pylint: disable=too-many-branches,too-many-statements,too-many-locals # Since a file has changed, the lrucache is invalid. load_message.cache_clear() try: entry = load_message(fullpath) except ...
python
def scan_file(fullpath, relpath, assign_id): """ scan a file and put it into the index """ # pylint: disable=too-many-branches,too-many-statements,too-many-locals # Since a file has changed, the lrucache is invalid. load_message.cache_clear() try: entry = load_message(fullpath) except ...
scan a file and put it into the index
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/entry.py#L453-L565
PlaidWeb/Publ
publ/entry.py
expire_file
def expire_file(filepath): """ Expire a record for a missing file """ load_message.cache_clear() orm.delete(pa for pa in model.PathAlias if pa.entry.file_path == filepath) orm.delete(item for item in model.Entry if item.file_path == filepath) orm.commit()
python
def expire_file(filepath): """ Expire a record for a missing file """ load_message.cache_clear() orm.delete(pa for pa in model.PathAlias if pa.entry.file_path == filepath) orm.delete(item for item in model.Entry if item.file_path == filepath) orm.commit()
Expire a record for a missing file
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/entry.py#L569-L574
PlaidWeb/Publ
publ/entry.py
expire_record
def expire_record(record): """ Expire a record for a missing entry """ load_message.cache_clear() # This entry no longer exists so delete it, and anything that references it # SQLite doesn't support cascading deletes so let's just clean up # manually orm.delete(pa for pa in model.PathAlias if p...
python
def expire_record(record): """ Expire a record for a missing entry """ load_message.cache_clear() # This entry no longer exists so delete it, and anything that references it # SQLite doesn't support cascading deletes so let's just clean up # manually orm.delete(pa for pa in model.PathAlias if p...
Expire a record for a missing entry
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/entry.py#L578-L587
PlaidWeb/Publ
publ/entry.py
Entry._link
def _link(self, *args, **kwargs): """ Returns a link, potentially pre-redirected """ if self._record.redirect_url: return links.resolve(self._record.redirect_url, self.search_path, kwargs.get('absolute')) return self._permalink(*args, **kwargs)
python
def _link(self, *args, **kwargs): """ Returns a link, potentially pre-redirected """ if self._record.redirect_url: return links.resolve(self._record.redirect_url, self.search_path, kwargs.get('absolute')) return self._permalink(*args, **kwargs)
Returns a link, potentially pre-redirected
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/entry.py#L147-L153
PlaidWeb/Publ
publ/entry.py
Entry._permalink
def _permalink(self, absolute=False, expand=True, **kwargs): """ Returns a canonical URL for the item """ return flask.url_for('entry', entry_id=self._record.id, category=self._record.category if expand else None, slu...
python
def _permalink(self, absolute=False, expand=True, **kwargs): """ Returns a canonical URL for the item """ return flask.url_for('entry', entry_id=self._record.id, category=self._record.category if expand else None, slu...
Returns a canonical URL for the item
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/entry.py#L155-L162
PlaidWeb/Publ
publ/entry.py
Entry.search_path
def search_path(self): """ The relative image search path for this entry """ return [os.path.dirname(self._record.file_path)] + self.category.search_path
python
def search_path(self): """ The relative image search path for this entry """ return [os.path.dirname(self._record.file_path)] + self.category.search_path
The relative image search path for this entry
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/entry.py#L201-L203
PlaidWeb/Publ
publ/entry.py
Entry._message
def _message(self): """ get the message payload """ filepath = self._record.file_path try: return load_message(filepath) except FileNotFoundError: expire_file(filepath) empty = email.message.Message() empty.set_payload('') retur...
python
def _message(self): """ get the message payload """ filepath = self._record.file_path try: return load_message(filepath) except FileNotFoundError: expire_file(filepath) empty = email.message.Message() empty.set_payload('') retur...
get the message payload
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/entry.py#L206-L215
PlaidWeb/Publ
publ/entry.py
Entry.body
def body(self): """ Get the above-the-fold entry body text """ body, _, is_markdown = self._entry_content return TrueCallableProxy( self._get_markup, body, is_markdown) if body else CallableProxy(None)
python
def body(self): """ Get the above-the-fold entry body text """ body, _, is_markdown = self._entry_content return TrueCallableProxy( self._get_markup, body, is_markdown) if body else CallableProxy(None)
Get the above-the-fold entry body text
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/entry.py#L233-L239
PlaidWeb/Publ
publ/entry.py
Entry.more
def more(self): """ Get the below-the-fold entry body text """ _, more, is_markdown = self._entry_content return TrueCallableProxy( self._get_markup, more, is_markdown) if more else CallableProxy(None)
python
def more(self): """ Get the below-the-fold entry body text """ _, more, is_markdown = self._entry_content return TrueCallableProxy( self._get_markup, more, is_markdown) if more else CallableProxy(None)
Get the below-the-fold entry body text
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/entry.py#L242-L248
PlaidWeb/Publ
publ/entry.py
Entry.card
def card(self): """ Get the entry's OpenGraph card """ body, more, is_markdown = self._entry_content return TrueCallableProxy( self._get_card, body or more) if is_markdown else CallableProxy(None)
python
def card(self): """ Get the entry's OpenGraph card """ body, more, is_markdown = self._entry_content return TrueCallableProxy( self._get_card, body or more) if is_markdown else CallableProxy(None)
Get the entry's OpenGraph card
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/entry.py#L251-L256
PlaidWeb/Publ
publ/entry.py
Entry.summary
def summary(self): """ Get the entry's summary text """ if self.get('Summary'): return self.get('Summary') body, more, is_markdown = self._entry_content return TrueCallableProxy( self._get_summary, body or more) if is_markdown else CallableProxy(None)
python
def summary(self): """ Get the entry's summary text """ if self.get('Summary'): return self.get('Summary') body, more, is_markdown = self._entry_content return TrueCallableProxy( self._get_summary, body or more) if is_markdown else CallableProxy(None)
Get the entry's summary text
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/entry.py#L259-L267
PlaidWeb/Publ
publ/entry.py
Entry.last_modified
def last_modified(self): """ Get the date of last file modification """ if self.get('Last-Modified'): return arrow.get(self.get('Last-Modified')) return self.date
python
def last_modified(self): """ Get the date of last file modification """ if self.get('Last-Modified'): return arrow.get(self.get('Last-Modified')) return self.date
Get the date of last file modification
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/entry.py#L270-L274
PlaidWeb/Publ
publ/entry.py
Entry._get_markup
def _get_markup(self, text, is_markdown, **kwargs): """ get the rendered markup for an entry is_markdown -- whether the entry is formatted as Markdown kwargs -- parameters to pass to the Markdown processor """ if is_markdown: return markdown.to_html( ...
python
def _get_markup(self, text, is_markdown, **kwargs): """ get the rendered markup for an entry is_markdown -- whether the entry is formatted as Markdown kwargs -- parameters to pass to the Markdown processor """ if is_markdown: return markdown.to_html( ...
get the rendered markup for an entry is_markdown -- whether the entry is formatted as Markdown kwargs -- parameters to pass to the Markdown processor
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/entry.py#L276-L291
PlaidWeb/Publ
publ/entry.py
Entry._get_card
def _get_card(self, text, **kwargs): """ Render out the tags for a Twitter/OpenGraph card for this entry. """ def og_tag(key, val): """ produce an OpenGraph tag with the given key and value """ return utils.make_tag('meta', {'property': key, 'content': val}, start_end=True) ...
python
def _get_card(self, text, **kwargs): """ Render out the tags for a Twitter/OpenGraph card for this entry. """ def og_tag(key, val): """ produce an OpenGraph tag with the given key and value """ return utils.make_tag('meta', {'property': key, 'content': val}, start_end=True) ...
Render out the tags for a Twitter/OpenGraph card for this entry.
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/entry.py#L293-L310
PlaidWeb/Publ
publ/entry.py
Entry._get_summary
def _get_summary(self, text, **kwargs): """ Render out just the summary """ card = cards.extract_card(text, kwargs, self.search_path) return flask.Markup((card.description or '').strip())
python
def _get_summary(self, text, **kwargs): """ Render out just the summary """ card = cards.extract_card(text, kwargs, self.search_path) return flask.Markup((card.description or '').strip())
Render out just the summary
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/entry.py#L312-L316
PlaidWeb/Publ
publ/entry.py
Entry._previous
def _previous(self, **kwargs): """ Get the previous item in any particular category """ spec = self._pagination_default_spec(kwargs) spec.update(kwargs) query = queries.build_query(spec) query = queries.where_before_entry(query, self._record) for record in query.order_b...
python
def _previous(self, **kwargs): """ Get the previous item in any particular category """ spec = self._pagination_default_spec(kwargs) spec.update(kwargs) query = queries.build_query(spec) query = queries.where_before_entry(query, self._record) for record in query.order_b...
Get the previous item in any particular category
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/entry.py#L333-L344
PlaidWeb/Publ
publ/entry.py
Entry._next
def _next(self, **kwargs): """ Get the next item in any particular category """ spec = self._pagination_default_spec(kwargs) spec.update(kwargs) query = queries.build_query(spec) query = queries.where_after_entry(query, self._record) for record in query.order_by(model.E...
python
def _next(self, **kwargs): """ Get the next item in any particular category """ spec = self._pagination_default_spec(kwargs) spec.update(kwargs) query = queries.build_query(spec) query = queries.where_after_entry(query, self._record) for record in query.order_by(model.E...
Get the next item in any particular category
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/entry.py#L346-L357
PlaidWeb/Publ
publ/config.py
setup
def setup(cfg): """ set up the global configuration from an object """ # copy the necessary configuration values over this_module = sys.modules[__name__] for name, value in cfg.items(): if hasattr(this_module, name): setattr(this_module, name, value)
python
def setup(cfg): """ set up the global configuration from an object """ # copy the necessary configuration values over this_module = sys.modules[__name__] for name, value in cfg.items(): if hasattr(this_module, name): setattr(this_module, name, value)
set up the global configuration from an object
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/config.py#L26-L33
PlaidWeb/Publ
publ/rendering.py
mime_type
def mime_type(template): """ infer the content-type from the extension """ _, ext = os.path.splitext(template.filename) return EXTENSION_MAP.get(ext, 'text/html; charset=utf-8')
python
def mime_type(template): """ infer the content-type from the extension """ _, ext = os.path.splitext(template.filename) return EXTENSION_MAP.get(ext, 'text/html; charset=utf-8')
infer the content-type from the extension
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/rendering.py#L37-L40
PlaidWeb/Publ
publ/rendering.py
map_template
def map_template(category, template_list): """ Given a file path and an acceptable list of templates, return the best-matching template's path relative to the configured template directory. Arguments: category -- The path to map template_list -- A template to look up (as a string), or a li...
python
def map_template(category, template_list): """ Given a file path and an acceptable list of templates, return the best-matching template's path relative to the configured template directory. Arguments: category -- The path to map template_list -- A template to look up (as a string), or a li...
Given a file path and an acceptable list of templates, return the best-matching template's path relative to the configured template directory. Arguments: category -- The path to map template_list -- A template to look up (as a string), or a list of templates.
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/rendering.py#L44-L71
PlaidWeb/Publ
publ/rendering.py
get_template
def get_template(template, relation): """ Given an entry or a category, return the path to a related template """ if isinstance(relation, Entry): path = relation.category.path elif isinstance(relation, Category): path = relation.path else: path = relation tmpl = map_template...
python
def get_template(template, relation): """ Given an entry or a category, return the path to a related template """ if isinstance(relation, Entry): path = relation.category.path elif isinstance(relation, Category): path = relation.path else: path = relation tmpl = map_template...
Given an entry or a category, return the path to a related template
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/rendering.py#L74-L84
PlaidWeb/Publ
publ/rendering.py
image_function
def image_function(template=None, entry=None, category=None): """ Get a function that gets an image """ path = [] if entry is not None: path += entry.search_path if category is not None: # Since the category might be different than the entry's category we add # this too ...
python
def image_function(template=None, entry=None, category=None): """ Get a function that gets an image """ path = [] if entry is not None: path += entry.search_path if category is not None: # Since the category might be different than the entry's category we add # this too ...
Get a function that gets an image
https://github.com/PlaidWeb/Publ/blob/ce7893632ddc3cb70b4978a41ffd7dd06fa13565/publ/rendering.py#L96-L112